2004-11-09 16:16:17 +01:00
< ? PHP
2008-06-20 20:30:04 +02:00
/* Copyright ( C ) 2001 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2009-02-24 03:41:21 +01:00
* Copyright ( C ) 2004 - 2009 Laurent Destailleur < eldy @ users . sourceforge . net >
2008-06-20 20:30:04 +02:00
* Copyright ( C ) 2008 Raphael Bertrand ( Resultic ) < raphael . bertrand @ resultic . fr >
2009-02-24 03:41:21 +01:00
*
2004-11-09 16:16:17 +01:00
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*/
2005-07-10 04:05:09 +02:00
/**
2008-08-09 00:12:27 +02:00
* \file htdocs / comm / remx . php
2009-07-08 12:10:35 +02:00
* \ingroup societe
2009-02-24 03:41:21 +01:00
* \brief Page to edit absolute discounts for a customer
2008-08-09 00:12:27 +02:00
* \version $Id $
*/
2005-07-10 04:05:09 +02:00
require_once ( " ./pre.inc.php " );
2006-04-09 00:47:51 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /lib/company.lib.php " );
2007-04-03 01:45:50 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /facture.class.php " );
2009-08-07 02:49:43 +02:00
require_once ( DOL_DOCUMENT_ROOT . " /discount.class.php " );
2004-11-09 16:16:17 +01:00
$langs -> load ( " orders " );
2005-08-11 20:54:59 +02:00
$langs -> load ( " bills " );
2004-11-09 16:16:17 +01:00
$langs -> load ( " companies " );
2009-08-07 02:49:43 +02:00
// Security check
2006-04-02 14:15:56 +02:00
$_socid = $_GET [ " id " ];
2009-02-24 03:41:21 +01:00
if ( $user -> societe_id > 0 )
2004-11-09 16:16:17 +01:00
{
2006-04-02 14:15:56 +02:00
$_socid = $user -> societe_id ;
2004-11-09 16:16:17 +01:00
}
2006-04-02 14:15:56 +02:00
/*
* Actions
*/
2009-08-07 02:49:43 +02:00
if ( $_REQUEST [ " action " ] == 'confirm_split' && $_REQUEST [ " confirm " ] == 'yes' )
{
//if ($user->rights->societe->creer)
//if ($user->rights->facture->creer)
$error = 0 ;
$remid = isset ( $_REQUEST [ " remid " ]) ? $_REQUEST [ " remid " ] : 0 ;
$discount = new DiscountAbsolute ( $db );
$res = $discount -> fetch ( $remid );
if ( ! $res > 0 )
{
$error ++ ;
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFailedToLoadDiscount " ) . '</div>' ;
}
if ( ! $error && price2num ( $_POST [ " amount_ttc_1 " ] + $_POST [ " amount_ttc_2 " ]) != $discount -> amount_ttc )
{
$error ++ ;
$mesg = '<div class="error">' . $langs -> trans ( " TotalOfTwoDiscountMustEqualsOriginal " ) . '</div>' ;
}
if ( ! $error && $discount -> fk_facture_line )
{
$error ++ ;
$mesg = '<div class="error">' . $langs -> trans ( " ErrorCantSplitAUsedDiscount " ) . '</div>' ;
}
if ( ! $error )
{
$newdiscount1 = new DiscountAbsolute ( $db );
$newdiscount2 = new DiscountAbsolute ( $db );
$newdiscount1 -> fk_facture_source = $discount -> fk_facture_source ;
$newdiscount2 -> fk_facture_source = $discount -> fk_facture_source ;
$newdiscount1 -> fk_facture = $discount -> fk_facture ;
$newdiscount2 -> fk_facture = $discount -> fk_facture ;
$newdiscount1 -> fk_facture_line = $discount -> fk_facture_line ;
$newdiscount2 -> fk_facture_line = $discount -> fk_facture_line ;
if ( $discount -> description == '(CREDIT_NOTE)' )
{
$newdiscount1 -> description = $discount -> description ;
$newdiscount2 -> description = $discount -> description ;
}
else
{
$newdiscount1 -> description = $discount -> description . ' (1)' ;
$newdiscount2 -> description = $discount -> description . ' (2)' ;
}
$newdiscount1 -> fk_user = $discount -> fk_user ;
$newdiscount2 -> fk_user = $discount -> fk_user ;
$newdiscount1 -> fk_soc = $discount -> fk_soc ;
$newdiscount2 -> fk_soc = $discount -> fk_soc ;
$newdiscount1 -> datec = $discount -> datec ;
$newdiscount2 -> datec = $discount -> datec ;
$newdiscount1 -> tva_tx = $discount -> tva_tx ;
$newdiscount2 -> tva_tx = $discount -> tva_tx ;
$newdiscount1 -> amount_ttc = $_POST [ " amount_ttc_1 " ];
$newdiscount2 -> amount_ttc = price2num ( $discount -> amount_ttc - $newdiscount1 -> amount_ttc );
$newdiscount1 -> amount_ht = price2num ( $newdiscount1 -> amount_ttc / ( 1 + $newdiscount1 -> tva_tx / 100 ), 'MT' );
$newdiscount2 -> amount_ht = price2num ( $newdiscount2 -> amount_ttc / ( 1 + $newdiscount2 -> tva_tx / 100 ), 'MT' );
$newdiscount1 -> amount_tva = price2num ( $newdiscount1 -> amount_ttc - $newdiscount2 -> amount_ht );
$newdiscount2 -> amount_tva = price2num ( $newdiscount2 -> amount_ttc - $newdiscount2 -> amount_ht );
$db -> begin ();
$discount -> fk_facture_source = 0 ; // This is to delete only the require record (that we will recreate with two records) and not all family with same fk_facture_source
$res = $discount -> delete ( $user );
$newid1 = $newdiscount1 -> create ( $user );
$newid2 = $newdiscount2 -> create ( $user );
if ( $res > 0 && $newid1 > 0 && $newid2 > 0 )
{
$db -> commit ();
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . '?id=' . $_REQUEST [ 'id' ]); // To avoid pb whith back
exit ;
}
else
{
$db -> rollback ();
}
}
}
2004-11-09 16:16:17 +01:00
2006-04-02 14:15:56 +02:00
if ( $_POST [ " action " ] == 'setremise' )
{
2009-08-07 02:49:43 +02:00
//if ($user->rights->societe->creer)
//if ($user->rights->facture->creer)
2007-04-05 11:16:20 +02:00
if ( price2num ( $_POST [ " amount_ht " ]) > 0 )
2006-04-02 14:15:56 +02:00
{
2009-05-07 14:17:28 +02:00
$error = 0 ;
if ( empty ( $_POST [ " desc " ]))
2007-04-05 11:16:20 +02:00
{
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldRequired " , $langs -> trans ( " ReasonDiscount " )) . '</div>' ;
2009-05-07 14:17:28 +02:00
$error ++ ;
2007-04-05 11:16:20 +02:00
}
2009-05-07 14:17:28 +02:00
if ( ! $error )
2006-06-03 13:32:51 +02:00
{
2009-05-07 14:17:28 +02:00
$soc = new Societe ( $db );
$soc -> fetch ( $_GET [ " id " ]);
$soc -> set_remise_except ( $_POST [ " amount_ht " ], $user , $_POST [ " desc " ], $_POST [ " tva_tx " ]);
if ( $result > 0 )
{
Header ( " Location: remx.php?id= " . $_GET [ " id " ]);
exit ;
}
else
{
$error ++ ;
$mesg = '<div class="error">' . $soc -> error . '</div>' ;
}
2006-06-03 13:32:51 +02:00
}
2006-04-02 14:15:56 +02:00
}
2007-04-05 11:16:20 +02:00
else
{
$mesg = '<div class="error">' . $langs -> trans ( " ErrorFieldFormat " , $langs -> trans ( " NewGlobalDiscount " )) . '</div>' ;
}
2006-04-02 14:15:56 +02:00
}
2005-08-11 20:54:59 +02:00
2009-08-07 02:49:43 +02:00
if ( $_REQUEST [ " action " ] == 'confirm_remove' && $_REQUEST [ " confirm " ] == 'yes' )
2004-11-09 16:16:17 +01:00
{
2009-08-07 02:49:43 +02:00
//if ($user->rights->societe->creer)
//if ($user->rights->facture->creer)
2009-02-24 03:41:21 +01:00
2009-08-07 02:49:43 +02:00
$db -> begin ();
2006-04-02 14:15:56 +02:00
2009-08-07 02:49:43 +02:00
$discount = new DiscountAbsolute ( $db );
$result = $discount -> fetch ( $_REQUEST [ " remid " ]);
$result = $discount -> delete ( $user );
2006-04-02 14:15:56 +02:00
if ( $result > 0 )
{
2007-12-02 18:59:06 +01:00
$db -> commit ();
2009-08-07 02:49:43 +02:00
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . '?id=' . $_REQUEST [ 'id' ]); // To avoid pb whith back
exit ;
2006-04-02 14:15:56 +02:00
}
else
{
2009-08-07 02:49:43 +02:00
$mesg = '<div class="error">' . $discount -> error . '</div>' ;
2007-12-02 18:59:06 +01:00
$db -> rollback ();
2006-04-02 14:15:56 +02:00
}
2004-11-09 16:16:17 +01:00
}
2005-08-11 20:54:59 +02:00
2006-04-02 14:15:56 +02:00
/*
2008-08-09 00:12:27 +02:00
* View
2006-04-02 14:15:56 +02:00
*/
2007-04-03 01:45:50 +02:00
$form = new Form ( $db );
$facturestatic = new Facture ( $db );
2009-02-24 03:41:21 +01:00
2006-04-02 14:15:56 +02:00
llxHeader ();
2004-11-09 16:16:17 +01:00
if ( $_socid > 0 )
{
2008-06-20 20:27:00 +02:00
if ( $mesg ) print $mesg . " <br> " ;
2009-02-24 03:41:21 +01:00
2006-04-09 00:47:51 +02:00
// On recupere les donnees societes par l'objet
$objsoc = new Societe ( $db );
$objsoc -> id = $_socid ;
$objsoc -> fetch ( $_socid , $to );
2009-02-24 03:41:21 +01:00
2006-04-09 00:47:51 +02:00
/*
* Affichage onglets
*/
$head = societe_prepare_head ( $objsoc );
2009-08-05 19:19:55 +02:00
dol_fiche_head ( $head , 'absolutediscount' , $langs -> trans ( " ThirdParty " ), 0 , 'company' );
2004-11-09 16:16:17 +01:00
2007-12-02 20:26:00 +01:00
2009-08-07 02:49:43 +02:00
print '<form method="POST" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $objsoc -> id . '">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2004-11-09 16:16:17 +01:00
print '<input type="hidden" name="action" value="setremise">' ;
2005-08-11 20:54:59 +02:00
print '<table class="border" width="100%">' ;
2004-11-09 16:16:17 +01:00
2009-03-02 19:17:19 +01:00
// Name
print '<tr><td width="38%">' . $langs -> trans ( 'Name' ) . '</td>' ;
print '<td>' ;
print $form -> showrefnav ( $objsoc , 'id' , '' , 1 , 'rowid' , 'nom' );
print '</td></tr>' ;
2006-04-02 14:15:56 +02:00
// Calcul avoirs en cours
2005-08-13 02:39:43 +02:00
$remise_all = $remise_user = 0 ;
2006-04-02 14:15:56 +02:00
$sql = " SELECT SUM(rc.amount_ht) as amount, rc.fk_user " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " societe_remise_except as rc " ;
$sql .= " WHERE rc.fk_soc = " . $objsoc -> id ;
2007-12-02 20:26:00 +01:00
$sql .= " AND (fk_facture_line IS NULL AND fk_facture IS NULL) " ;
2006-04-02 14:15:56 +02:00
$sql .= " GROUP BY rc.fk_user " ;
2005-08-11 20:54:59 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
$obj = $db -> fetch_object ( $resql );
2006-04-02 14:15:56 +02:00
$remise_all += $obj -> amount ;
if ( $obj -> fk_user == $user -> id ) $remise_user += $obj -> amount ;
}
else
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2005-08-11 20:54:59 +02:00
}
2004-11-09 16:16:17 +01:00
2006-05-25 14:10:44 +02:00
print '<tr><td width="38%">' . $langs -> trans ( " CustomerAbsoluteDiscountAllUsers " ) . '</td>' ;
2005-08-11 20:54:59 +02:00
print '<td>' . $remise_all . ' ' . $langs -> trans ( " Currency " . $conf -> monnaie ) . '</td></tr>' ;
2004-11-09 16:16:17 +01:00
2006-05-25 14:10:44 +02:00
print '<tr><td>' . $langs -> trans ( " CustomerAbsoluteDiscountMy " ) . '</td>' ;
2005-08-11 20:54:59 +02:00
print '<td>' . $remise_user . ' ' . $langs -> trans ( " Currency " . $conf -> monnaie ) . '</td></tr>' ;
2009-08-07 02:49:43 +02:00
print '</table>' ;
2006-04-02 14:15:56 +02:00
print '<br>' ;
2009-02-24 03:41:21 +01:00
2009-08-07 02:49:43 +02:00
print_fiche_titre ( $langs -> trans ( " NewGlobalDiscount " ), '' , '' );
2006-04-02 14:15:56 +02:00
print '<table class="border" width="100%">' ;
2009-08-07 02:49:43 +02:00
print '<tr><td width="38%">' . $langs -> trans ( " AmountHT " ) . '</td>' ;
2007-04-03 01:45:50 +02:00
print '<td><input type="text" size="5" name="amount_ht" value="' . $_POST [ " amount_ht " ] . '"> ' . $langs -> trans ( " Currency " . $conf -> monnaie ) . '</td></tr>' ;
print '<tr><td width="38%">' . $langs -> trans ( " VAT " ) . '</td>' ;
print '<td>' ;
$form -> select_tva ( 'tva_tx' , '0' , '' , $mysoc , '' );
print '</td></tr>' ;
2006-05-25 14:10:44 +02:00
print '<tr><td>' . $langs -> trans ( " NoteReason " ) . '</td>' ;
2006-04-02 14:15:56 +02:00
print '<td><input type="text" size="60" name="desc" value="' . $_POST [ " desc " ] . '"></td></tr>' ;
2009-02-24 03:41:21 +01:00
2006-04-02 14:15:56 +02:00
print '<tr><td align="center" colspan="2"><input type="submit" class="button" value="' . $langs -> trans ( " AddGlobalDiscount " ) . '"></td></tr>' ;
2009-02-24 03:41:21 +01:00
2004-11-09 16:16:17 +01:00
print " </table></form> " ;
2009-02-24 03:41:21 +01:00
print " </div> \n " ;
2005-08-11 20:54:59 +02:00
2009-02-24 03:41:21 +01:00
print '<br>' ;
2005-08-11 20:54:59 +02:00
2009-08-07 02:49:43 +02:00
if ( $_GET [ 'action' ] == 'remove' )
{
$ret = $form -> form_confirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $objsoc -> id . '&remid=' . $_GET [ " remid " ], $langs -> trans ( 'RemoveDiscount' ), $langs -> trans ( 'ConfirmRemoveDiscount' ), 'confirm_remove' , '' , 0 , 1 );
}
2006-04-02 14:15:56 +02:00
2004-11-09 16:16:17 +01:00
/*
2007-12-02 20:26:00 +01:00
* Liste remises fixes restant en cours ( = liees a acune facture ni ligne de facture )
2004-11-09 16:16:17 +01:00
*/
2007-04-03 01:45:50 +02:00
$sql = " SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, " ;
$sql .= $db -> pdate ( " rc.datec " ) . " as dc, rc.description, " ;
$sql .= " rc.fk_facture_source, " ;
$sql .= " u.login, u.rowid as user_id, " ;
$sql .= " fa.facnumber as ref, fa.type as type " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " user as u, " . MAIN_DB_PREFIX . " societe_remise_except as rc " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " facture as fa ON rc.fk_facture_source = fa.rowid " ;
$sql .= " WHERE rc.fk_soc = " . $objsoc -> id ;
2007-12-02 20:26:00 +01:00
$sql .= " AND u.rowid = rc.fk_user " ;
$sql .= " AND (rc.fk_facture_line IS NULL AND rc.fk_facture IS NULL) " ;
2006-04-02 14:15:56 +02:00
$sql .= " ORDER BY rc.datec DESC " ;
2004-11-09 16:16:17 +01:00
2005-08-11 20:54:59 +02:00
$resql = $db -> query ( $sql );
if ( $resql )
{
2006-04-08 16:51:58 +02:00
print_titre ( $langs -> trans ( " DiscountStillRemaining " ));
2005-08-11 20:54:59 +02:00
print '<table width="100%" class="noborder">' ;
2009-03-02 19:17:19 +01:00
print '<tr class="liste_titre">' ;
2009-08-22 05:09:52 +02:00
print '<td width="120" align="left">' . $langs -> trans ( " Date " ) . '</td>' ; // Need 120+ for format with AM/PM
2009-05-07 14:13:34 +02:00
print '<td width="150" align="left">' . $langs -> trans ( " ReasonDiscount " ) . '</td>' ;
2009-03-02 19:17:19 +01:00
print '<td align="left" nowrap="nowrap">' . $langs -> trans ( " ConsumedBy " ) . '</td>' ;
2007-04-03 01:45:50 +02:00
print '<td width="120" align="right">' . $langs -> trans ( " AmountHT " ) . '</td>' ;
print '<td width="80" align="right">' . $langs -> trans ( " VATRate " ) . '</td>' ;
print '<td width="120" align="right">' . $langs -> trans ( " AmountTTC " ) . '</td>' ;
2009-03-02 19:17:19 +01:00
print '<td width="100" align="center">' . $langs -> trans ( " DiscountOfferedBy " ) . '</td>' ;
2006-04-02 14:15:56 +02:00
print '<td width="20"> </td>' ;
print '</tr>' ;
2005-08-11 20:54:59 +02:00
$var = true ;
$i = 0 ;
$num = $db -> num_rows ( $resql );
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
$var = ! $var ;
print " <tr $bc[$var] > " ;
2009-02-20 23:53:15 +01:00
print '<td>' . dol_print_date ( $obj -> dc , 'dayhour' ) . '</td>' ;
2007-04-03 01:45:50 +02:00
if ( $obj -> description == '(CREDIT_NOTE)' )
{
2009-03-02 19:17:19 +01:00
print '<td nowrap="nowrap">' ;
2007-04-03 01:45:50 +02:00
$facturestatic -> id = $obj -> fk_facture_source ;
$facturestatic -> ref = $obj -> ref ;
$facturestatic -> type = $obj -> type ;
print $langs -> trans ( " CreditNote " ) . ' ' . $facturestatic -> getNomURl ( 1 );
2009-03-02 19:17:19 +01:00
print '</td>' ;
2007-04-03 01:45:50 +02:00
}
2009-02-24 03:41:21 +01:00
elseif ( $obj -> description == '(DEPOSIT)' )
{
2009-03-02 19:17:19 +01:00
print '<td nowrap="nowrap">' ;
2009-02-24 03:41:21 +01:00
$facturestatic -> id = $obj -> fk_facture_source ;
$facturestatic -> ref = $obj -> ref ;
$facturestatic -> type = $obj -> type ;
print $langs -> trans ( " InvoiceDeposit " ) . ' ' . $facturestatic -> getNomURl ( 1 );
2009-03-02 19:17:19 +01:00
print '</td>' ;
2009-02-24 03:41:21 +01:00
}
2007-04-03 01:45:50 +02:00
else
{
2009-03-02 19:17:19 +01:00
print '<td>' ;
2007-04-03 01:45:50 +02:00
print $obj -> description ;
2009-03-02 19:17:19 +01:00
print '</td>' ;
2007-04-03 01:45:50 +02:00
}
2009-03-02 19:17:19 +01:00
print '<td align="left" nowrap="nowrap">' . $langs -> trans ( " NotConsumed " ) . '</td>' ;
print '<td align="right">' . price ( $obj -> amount_ht ) . '</td>' ;
2007-07-05 00:07:53 +02:00
print '<td align="right">' . price2num ( $obj -> tva_tx , 'MU' ) . '%</td>' ;
2007-04-03 01:45:50 +02:00
print '<td align="right">' . price ( $obj -> amount_ttc ) . '</td>' ;
print '<td align="center">' ;
2009-03-02 19:17:19 +01:00
print '<a href="' . DOL_URL_ROOT . '/user/fiche.php?id=' . $obj -> user_id . '">' . img_object ( $langs -> trans ( " ShowUser " ), 'user' ) . ' ' . $obj -> login . '</a>' ;
2007-04-03 01:45:50 +02:00
print '</td>' ;
2009-08-07 02:49:43 +02:00
if ( $user -> rights -> societe -> creer || $user -> rights -> facture -> creer )
{
print '<td nowrap="nowrap">' ;
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $objsoc -> id . '&action=split&remid=' . $obj -> rowid . '">' . img_picto ( $langs -> trans ( " SplitDiscount " ), 'split' ) . '</a>' ;
print ' ' ;
print '<a href="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $objsoc -> id . '&action=remove&remid=' . $obj -> rowid . '">' . img_delete ( $langs -> trans ( " RemoveDiscount " )) . '</a>' ;
print '</td>' ;
}
2006-04-02 14:15:56 +02:00
else print '<td> </td>' ;
print '</tr>' ;
2009-08-07 02:49:43 +02:00
if ( $_GET [ " action " ] == 'split' && $_GET [ 'remid' ] == $obj -> rowid )
{
print " <tr $bc[$var] > " ;
print '<td colspan="8">' ;
$amount1 = price2num ( $obj -> amount_ttc / 2 , 'MT' );
$amount2 = ( $obj -> amount_ttc - $amount1 );
$formquestion = array (
'text' => $langs -> trans ( 'TypeAmountOfEachNewDiscount' ),
array ( 'type' => 'text' , 'name' => 'amount_ttc_1' , 'label' => $langs -> trans ( " AmountTTC " ) . ' 1' , 'value' => $amount1 , 'size' => '5' ),
array ( 'type' => 'text' , 'name' => 'amount_ttc_2' , 'label' => $langs -> trans ( " AmountTTC " ) . ' 2' , 'value' => $amount2 , 'size' => '5' )
);
$langs -> load ( " dict " );
$ret = $form -> form_confirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $objsoc -> id . '&remid=' . $obj -> rowid , $langs -> trans ( 'SplitDiscount' ), $langs -> trans ( 'ConfirmSplitDiscount' , price ( $obj -> amount_ttc ), $langs -> transnoentities ( " Currency " . $conf -> monnaie )), 'confirm_split' , $formquestion , 0 , 0 );
print '</td>' ;
print '</tr>' ;
}
2005-08-11 20:54:59 +02:00
$i ++ ;
}
$db -> free ( $resql );
print " </table> " ;
}
2004-11-09 16:16:17 +01:00
else
2005-08-11 20:54:59 +02:00
{
2009-02-20 23:53:15 +01:00
dol_print_error ( $db );
2005-08-11 20:54:59 +02:00
}
2004-11-09 16:16:17 +01:00
2008-06-20 20:27:00 +02:00
print '<br>' ;
2004-11-09 16:16:17 +01:00
/*
2009-03-02 19:17:19 +01:00
* Liste ristournes appliquees ( = liees a une ligne de facture ou facture )
2004-11-09 16:16:17 +01:00
*/
2009-03-02 19:17:19 +01:00
2007-12-02 20:26:00 +01:00
// Remises liees a lignes de factures
2008-06-20 20:30:04 +02:00
$sql = " SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, " ;
2007-12-02 20:26:00 +01:00
$sql .= $db -> pdate ( " rc.datec " ) . " as dc, rc.description, rc.fk_facture_line, rc.fk_facture, " ;
2007-04-03 01:45:50 +02:00
$sql .= " rc.fk_facture_source, " ;
$sql .= " u.login, u.rowid as user_id, " ;
$sql .= " f.rowid, f.facnumber, " ;
$sql .= " fa.facnumber as ref, fa.type as type " ;
$sql .= " FROM " . MAIN_DB_PREFIX . " facture as f " ;
2005-09-07 23:27:05 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " user as u " ;
2006-08-20 05:27:11 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " facturedet as fc " ;
2007-04-03 01:45:50 +02:00
$sql .= " , " . MAIN_DB_PREFIX . " societe_remise_except as rc " ;
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . " facture as fa ON rc.fk_facture_source = fa.rowid " ;
2005-09-07 23:27:05 +02:00
$sql .= " WHERE rc.fk_soc = " . $objsoc -> id ;
2007-12-02 20:26:00 +01:00
$sql .= " AND rc.fk_facture_line = fc.rowid " ;
2006-08-20 05:27:11 +02:00
$sql .= " AND fc.fk_facture = f.rowid " ;
2008-06-20 20:30:04 +02:00
$sql .= " AND rc.fk_user = u.rowid " ;
$sql .= " ORDER BY dc DESC " ;
//$sql.= " UNION ";
2007-12-02 20:26:00 +01:00
// Remises liees a factures
2008-06-20 20:30:04 +02:00
$sql2 = " SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, " ;
$sql2 .= $db -> pdate ( " rc.datec " ) . " as dc, rc.description, rc.fk_facture_line, rc.fk_facture, " ;
$sql2 .= " rc.fk_facture_source, " ;
$sql2 .= " u.login, u.rowid as user_id, " ;
$sql2 .= " f.rowid, f.facnumber, " ;
$sql2 .= " fa.facnumber as ref, fa.type as type " ;
$sql2 .= " FROM " . MAIN_DB_PREFIX . " facture as f " ;
$sql2 .= " , " . MAIN_DB_PREFIX . " user as u " ;
$sql2 .= " , " . MAIN_DB_PREFIX . " societe_remise_except as rc " ;
$sql2 .= " LEFT JOIN " . MAIN_DB_PREFIX . " facture as fa ON rc.fk_facture_source = fa.rowid " ;
$sql2 .= " WHERE rc.fk_soc = " . $objsoc -> id ;
$sql2 .= " AND rc.fk_facture = f.rowid " ;
$sql2 .= " AND rc.fk_user = u.rowid " ;
2009-02-24 03:41:21 +01:00
2008-06-20 20:30:04 +02:00
$sql2 .= " ORDER BY dc DESC " ;
2004-11-09 16:16:17 +01:00
2005-08-11 20:54:59 +02:00
$resql = $db -> query ( $sql );
2008-06-20 20:30:04 +02:00
$resql2 = null ;
if ( $resql ) $resql2 = $db -> query ( $sql2 );
if ( $resql2 )
2009-02-24 03:41:21 +01:00
{
2006-04-08 16:51:58 +02:00
print_titre ( $langs -> trans ( " DiscountAlreadyCounted " ));
2005-08-11 20:54:59 +02:00
print '<table class="noborder" width="100%">' ;
2009-03-02 19:17:19 +01:00
print '<tr class="liste_titre">' ;
2009-08-22 05:09:52 +02:00
print '<td width="120" align="left">' . $langs -> trans ( " Date " ) . '</td>' ; // Need 120+ for format with AM/PM
2009-05-07 14:13:34 +02:00
print '<td width="150" align="left">' . $langs -> trans ( " ReasonDiscount " ) . '</td>' ;
2009-03-02 19:17:19 +01:00
print '<td align="left" nowrap="nowrap">' . $langs -> trans ( " ConsumedBy " ) . '</td>' ;
2007-04-03 01:45:50 +02:00
print '<td width="120" align="right">' . $langs -> trans ( " AmountHT " ) . '</td>' ;
print '<td width="80" align="right">' . $langs -> trans ( " VATRate " ) . '</td>' ;
print '<td width="120" align="right">' . $langs -> trans ( " AmountTTC " ) . '</td>' ;
2009-03-02 19:17:19 +01:00
print '<td width="100" align="center">' . $langs -> trans ( " Author " ) . '</td>' ;
2006-04-02 14:15:56 +02:00
print '<td width="20"> </td>' ;
print '</tr>' ;
2005-08-11 20:54:59 +02:00
$var = true ;
2008-06-20 20:30:04 +02:00
$tab_sqlobj = array ();
$tab_sqlobjOrder = array ();
2005-08-11 20:54:59 +02:00
$num = $db -> num_rows ( $resql );
2008-06-20 20:30:04 +02:00
for ( $i = 0 ; $i < $num ; $i ++ )
{
$sqlobj = $db -> fetch_object ( $resql );
$tab_sqlobj [] = $sqlobj ;
$tab_sqlobjOrder [] = $sqlobj -> dc ;
}
2009-02-24 03:41:21 +01:00
$db -> free ( $resql );
2008-06-20 20:30:04 +02:00
$num = $db -> num_rows ( $resql2 );
for ( $i = 0 ; $i < $num ; $i ++ )
{
$sqlobj = $db -> fetch_object ( $resql2 );
$tab_sqlobj [] = $sqlobj ;
$tab_sqlobjOrder [] = $sqlobj -> dc ;
}
$db -> free ( $resql2 );
array_multisort ( $tab_sqlobjOrder , SORT_DESC , $tab_sqlobj );
2009-02-24 03:41:21 +01:00
2008-06-20 20:30:04 +02:00
$num = sizeOf ( $tab_sqlobj );
$i = 0 ;
2005-08-11 20:54:59 +02:00
while ( $i < $num )
{
2008-06-20 20:30:04 +02:00
$obj = array_shift ( $tab_sqlobj );
2005-08-11 20:54:59 +02:00
$var = ! $var ;
print " <tr $bc[$var] > " ;
2009-02-20 23:53:15 +01:00
print '<td>' . dol_print_date ( $obj -> dc , 'dayhour' ) . '</td>' ;
2007-04-03 01:45:50 +02:00
if ( $obj -> description == '(CREDIT_NOTE)' )
{
2009-03-02 19:17:19 +01:00
print '<td nowrap="nowrap">' ;
2007-04-03 01:45:50 +02:00
$facturestatic -> id = $obj -> fk_facture_source ;
$facturestatic -> ref = $obj -> ref ;
$facturestatic -> type = $obj -> type ;
print $langs -> trans ( " CreditNote " ) . ' ' . $facturestatic -> getNomURl ( 1 );
2009-03-02 19:17:19 +01:00
print '</td>' ;
2007-04-03 01:45:50 +02:00
}
2009-03-02 17:06:52 +01:00
elseif ( $obj -> description == '(DEPOSIT)' )
{
2009-03-02 19:17:19 +01:00
print '<td nowrap="nowrap">' ;
2009-03-02 17:06:52 +01:00
$facturestatic -> id = $obj -> fk_facture_source ;
$facturestatic -> ref = $obj -> ref ;
$facturestatic -> type = $obj -> type ;
print $langs -> trans ( " InvoiceDeposit " ) . ' ' . $facturestatic -> getNomURl ( 1 );
2009-03-02 19:17:19 +01:00
print '</td>' ;
2009-03-02 17:06:52 +01:00
}
2007-04-03 01:45:50 +02:00
else
{
2009-03-02 19:17:19 +01:00
print '<td>' ;
2007-04-03 01:45:50 +02:00
print $obj -> description ;
2009-03-02 19:17:19 +01:00
print '</td>' ;
2007-04-03 01:45:50 +02:00
}
2009-03-02 19:17:19 +01:00
print '<td align="left" nowrap="nowrap"><a href="' . DOL_URL_ROOT . '/compta/facture.php?facid=' . $obj -> rowid . '">' . img_object ( $langs -> trans ( " ShowBill " ), 'bill' ) . ' ' . $obj -> facnumber . '</a></td>' ;
2006-04-02 20:57:50 +02:00
print '<td align="right">' . price ( $obj -> amount_ht ) . '</td>' ;
2007-07-05 00:07:53 +02:00
print '<td align="right">' . price2num ( $obj -> tva_tx , 'MU' ) . '%</td>' ;
2007-04-03 01:45:50 +02:00
print '<td align="right">' . price ( $obj -> amount_ttc ) . '</td>' ;
print '<td align="center">' ;
2009-03-02 19:17:19 +01:00
print '<a href="' . DOL_URL_ROOT . '/user/fiche.php?id=' . $obj -> user_id . '">' . img_object ( $langs -> trans ( " ShowUser " ), 'user' ) . ' ' . $obj -> login . '</a>' ;
2007-04-03 01:45:50 +02:00
print '</td>' ;
2006-04-02 14:15:56 +02:00
print '<td> </td>' ;
print '</tr>' ;
2005-08-11 20:54:59 +02:00
$i ++ ;
}
print " </table> " ;
}
2004-11-09 16:16:17 +01:00
else
2005-08-11 20:54:59 +02:00
{
2009-02-20 23:53:15 +01:00
print dol_print_error ( $db );
2005-08-11 20:54:59 +02:00
}
2004-11-09 16:16:17 +01:00
}
$db -> close ();
2005-08-11 20:54:59 +02:00
llxFooter ( '$Date$ - $Revision$' );
2004-11-09 16:16:17 +01:00
?>