2012-08-22 23:27:53 +02:00
< ? php
2008-06-20 20:30:04 +02:00
/* Copyright ( C ) 2001 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2012-09-03 09:45:26 +02:00
* Copyright ( C ) 2004 - 2012 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
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2004-11-09 16:16:17 +01:00
* ( 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
2011-08-03 02:45:22 +02:00
* along with this program . If not , see < http :// www . gnu . org / licenses />.
2004-11-09 16:16:17 +01:00
*/
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
*/
2005-07-10 04:05:09 +02:00
2012-08-22 23:24:21 +02:00
require '../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/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 " );
2012-02-27 17:02:56 +01:00
$action = GETPOST ( 'action' , 'alpha' );
$backtopage = GETPOST ( 'backtopage' , 'alpha' );
2011-11-13 00:49:40 +01:00
2009-08-07 02:49:43 +02:00
// Security check
2012-02-27 22:26:22 +01:00
$socid = GETPOST ( 'id' , 'int' );
2009-02-24 03:41:21 +01:00
if ( $user -> societe_id > 0 )
2004-11-09 16:16:17 +01:00
{
2011-09-10 19:52:21 +02:00
$socid = $user -> societe_id ;
2004-11-09 16:16:17 +01:00
}
2006-04-02 14:15:56 +02:00
/*
* Actions
*/
2011-02-19 13:15:17 +01:00
2012-02-27 17:02:56 +01:00
if ( GETPOST ( 'cancel' ) && ! empty ( $backtopage ))
2011-02-19 13:15:17 +01:00
{
2012-08-31 05:58:38 +02:00
header ( " Location: " . $backtopage );
2011-02-19 13:15:17 +01:00
exit ;
}
2011-11-13 00:49:40 +01:00
if ( $action == 'confirm_split' && GETPOST ( " confirm " ) == 'yes' )
2009-08-07 02:49:43 +02:00
{
//if ($user->rights->societe->creer)
//if ($user->rights->facture->creer)
$error = 0 ;
2011-02-19 13:15:17 +01:00
$remid = GETPOST ( " remid " ) ? GETPOST ( " remid " ) : 0 ;
2009-08-07 02:49:43 +02:00
$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
2011-11-13 00:49:40 +01:00
if ( $action == 'setremise' )
2006-04-02 14:15:56 +02:00
{
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 " ]);
2011-11-13 00:49:40 +01:00
$discountid = $soc -> set_remise_except ( $_POST [ " amount_ht " ], $user , $_POST [ " desc " ], $_POST [ " tva_tx " ]);
2009-05-07 14:17:28 +02:00
2011-11-13 00:49:40 +01:00
if ( $discountid > 0 )
2009-05-07 14:17:28 +02:00
{
2012-02-27 17:02:56 +01:00
if ( ! empty ( $backtopage ))
2011-02-19 13:15:17 +01:00
{
2012-08-31 05:58:38 +02:00
header ( " Location: " . $backtopage . '&discountid=' . $discountid );
2011-02-19 13:15:17 +01:00
exit ;
}
else
{
2012-08-31 05:58:38 +02:00
header ( " Location: remx.php?id= " . $_GET [ " id " ]);
2011-02-19 13:15:17 +01:00
exit ;
}
2009-05-07 14:17:28 +02:00
}
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
2011-02-19 13:15:17 +01:00
if ( GETPOST ( " action " ) == 'confirm_remove' && GETPOST ( " 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 );
2011-02-19 13:15:17 +01:00
$result = $discount -> fetch ( GETPOST ( " remid " ));
2009-08-07 02:49:43 +02:00
$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 ();
2012-02-27 22:26:22 +01:00
header ( " Location: " . $_SERVER [ " PHP_SELF " ] . '?id=' . GETPOST ( 'id' , 'int' )); // To avoid pb whith back
2009-08-07 02:49:43 +02:00
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
2011-09-10 19:52:21 +02:00
llxHeader ( '' , $langs -> trans ( " GlobalDiscount " ));
2006-04-02 14:15:56 +02:00
2011-09-10 19:52:21 +02:00
if ( $socid > 0 )
2004-11-09 16:16:17 +01:00
{
2011-07-17 22:02:10 +02:00
dol_htmloutput_mesg ( $mesg );
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 );
2011-09-10 19:52:21 +02:00
$objsoc -> id = $socid ;
$objsoc -> fetch ( $socid );
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
2010-05-08 22:47:12 +02:00
print '<form method="POST" action="' . $_SERVER [ " PHP_SELF " ] . '?id=' . $objsoc -> id . '">' ;
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
print '<input type="hidden" name="action" value="setremise">' ;
2012-02-27 17:02:56 +01:00
print '<input type="hidden" name="backtopage" value="' . $backtopage . '">' ;
2004-11-09 16:16:17 +01:00
2010-05-08 22:47:12 +02:00
print '<table class="border" width="100%">' ;
2004-11-09 16:16:17 +01:00
2010-05-08 22:47:12 +02:00
// Name
2009-03-02 19:17:19 +01:00
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
2010-05-08 22:47:12 +02:00
$remise_all = $remise_user = 0 ;
$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 ;
$sql .= " AND (fk_facture_line IS NULL AND fk_facture IS NULL) " ;
$sql .= " GROUP BY rc.fk_user " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
$obj = $db -> fetch_object ( $resql );
$remise_all += $obj -> amount ;
if ( $obj -> fk_user == $user -> id ) $remise_user += $obj -> amount ;
}
else
{
dol_print_error ( $db );
}
print '<tr><td width="38%">' . $langs -> trans ( " CustomerAbsoluteDiscountAllUsers " ) . '</td>' ;
2011-11-23 14:55:36 +01:00
print '<td>' . $remise_all . ' ' . $langs -> trans ( " Currency " . $conf -> currency ) . ' ' . $langs -> trans ( " HT " ) . '</td></tr>' ;
2010-05-08 22:47:12 +02:00
print '<tr><td>' . $langs -> trans ( " CustomerAbsoluteDiscountMy " ) . '</td>' ;
2011-11-23 14:55:36 +01:00
print '<td>' . $remise_user . ' ' . $langs -> trans ( " Currency " . $conf -> currency ) . ' ' . $langs -> trans ( " HT " ) . '</td></tr>' ;
2010-05-08 22:47:12 +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 " ), '' , '' );
2010-05-08 22:47:12 +02:00
print '<table class="border" width="100%">' ;
print '<tr><td width="38%">' . $langs -> trans ( " AmountHT " ) . '</td>' ;
2013-04-16 01:13:20 +02:00
print '<td><input type="text" size="5" name="amount_ht" value="' . $_POST [ " amount_ht " ] . '">' ;
print '<span class="hideonsmartphone"> ' . $langs -> trans ( " Currency " . $conf -> currency ) . '</span></td></tr>' ;
2010-05-08 22:47:12 +02:00
print '<tr><td width="38%">' . $langs -> trans ( " VAT " ) . '</td>' ;
print '<td>' ;
2012-09-03 09:45:26 +02:00
print $form -> load_tva ( 'tva_tx' , GETPOST ( 'tva_tx' ), $mysoc , $objsoc );
2007-04-03 01:45:50 +02:00
print '</td></tr>' ;
2010-05-08 22:47:12 +02:00
print '<tr><td>' . $langs -> trans ( " NoteReason " ) . '</td>' ;
print '<td><input type="text" size="60" name="desc" value="' . $_POST [ " desc " ] . '"></td></tr>' ;
2009-02-24 03:41:21 +01:00
2011-09-08 23:28:57 +02:00
print " </table> " ;
print '<center>' ;
2011-02-19 13:15:17 +01:00
print '<input type="submit" class="button" name="submit" value="' . $langs -> trans ( " AddGlobalDiscount " ) . '">' ;
2012-02-27 17:02:56 +01:00
if ( ! empty ( $backtopage ))
2011-02-19 13:15:17 +01:00
{
print ' ' ;
print '<input type="submit" class="button" name="cancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
}
2011-09-08 23:28:57 +02:00
print '</center>' ;
2009-02-24 03:41:21 +01:00
2011-09-08 23:28:57 +02:00
print '</form>' ;
2004-11-09 16:16:17 +01:00
2011-09-08 23:28:57 +02:00
dol_fiche_end ();
2005-08-11 20:54:59 +02:00
2010-05-08 22:47:12 +02:00
print '<br>' ;
2005-08-11 20:54:59 +02:00
2010-05-08 22:47:12 +02:00
if ( $_GET [ 'action' ] == 'remove' )
{
2013-09-06 12:10:09 +02:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $objsoc -> id . '&remid=' . $_GET [ " remid " ], $langs -> trans ( 'RemoveDiscount' ), $langs -> trans ( 'ConfirmRemoveDiscount' ), 'confirm_remove' , '' , 0 , 1 );
2010-05-08 22:47:12 +02:00
}
/*
* Liste remises fixes restant en cours ( = liees a acune facture ni ligne de facture )
*/
$sql = " SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, " ;
$sql .= " rc.datec as dc, rc.description, " ;
$sql .= " rc.fk_facture_source, " ;
$sql .= " u.login, u.rowid as user_id, " ;
2007-04-03 01:45:50 +02:00
$sql .= " fa.facnumber as ref, fa.type as type " ;
2010-05-08 22:47:12 +02:00
$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 " ;
2007-04-03 01:45:50 +02:00
$sql .= " WHERE rc.fk_soc = " . $objsoc -> id ;
2010-05-08 22:47:12 +02:00
$sql .= " AND u.rowid = rc.fk_user " ;
2007-12-02 20:26:00 +01:00
$sql .= " AND (rc.fk_facture_line IS NULL AND rc.fk_facture IS NULL) " ;
2010-05-08 22:47:12 +02:00
$sql .= " ORDER BY rc.datec DESC " ;
$resql = $db -> query ( $sql );
if ( $resql )
{
print_titre ( $langs -> trans ( " DiscountStillRemaining " ));
print '<table width="100%" class="noborder">' ;
print '<tr class="liste_titre">' ;
print '<td width="120" align="left">' . $langs -> trans ( " Date " ) . '</td>' ; // Need 120+ for format with AM/PM
2011-02-19 13:50:31 +01:00
print '<td align="left">' . $langs -> trans ( " ReasonDiscount " ) . '</td>' ;
2013-04-25 01:13:13 +02:00
print '<td width="150" class="nowrap">' . $langs -> trans ( " ConsumedBy " ) . '</td>' ;
2010-05-08 22:47:12 +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>' ;
print '<td width="100" align="center">' . $langs -> trans ( " DiscountOfferedBy " ) . '</td>' ;
2011-02-19 13:50:31 +01:00
print '<td width="50"> </td>' ;
2010-05-08 22:47:12 +02:00
print '</tr>' ;
$var = true ;
$i = 0 ;
$num = $db -> num_rows ( $resql );
while ( $i < $num )
{
$obj = $db -> fetch_object ( $resql );
$var = ! $var ;
2013-06-20 09:18:12 +02:00
print " <tr " . $bc [ $var ] . " > " ;
2010-05-08 22:47:12 +02:00
print '<td>' . dol_print_date ( $db -> jdate ( $obj -> dc ), 'dayhour' ) . '</td>' ;
2007-04-03 01:45:50 +02:00
if ( $obj -> description == '(CREDIT_NOTE)' )
{
2013-04-25 01:13:13 +02:00
print '<td class="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)' )
{
2013-04-25 01:13:13 +02:00
print '<td class="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
{
2010-05-08 22:47:12 +02: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
}
2013-04-25 01:13:13 +02:00
print '<td class="nowrap">' . $langs -> trans ( " NotConsumed " ) . '</td>' ;
2009-03-02 19:17:19 +01:00
print '<td align="right">' . price ( $obj -> amount_ht ) . '</td>' ;
2010-05-08 22:47:12 +02:00
print '<td align="right">' . price2num ( $obj -> tva_tx , 'MU' ) . '%</td>' ;
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 )
{
2013-04-25 01:13:13 +02:00
print '<td class="nowrap">' ;
2009-08-07 02:49:43 +02:00
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>' ;
}
2010-05-08 22:47:12 +02:00
else print '<td> </td>' ;
print '</tr>' ;
2009-08-07 02:49:43 +02:00
2010-05-08 22:47:12 +02:00
if ( $_GET [ " action " ] == 'split' && $_GET [ 'remid' ] == $obj -> rowid )
{
2013-06-20 09:18:12 +02:00
print " <tr " . $bc [ $var ] . " > " ;
2009-08-07 02:49:43 +02:00
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 " );
2013-09-06 12:10:09 +02:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?id=' . $objsoc -> id . '&remid=' . $obj -> rowid , $langs -> trans ( 'SplitDiscount' ), $langs -> trans ( 'ConfirmSplitDiscount' , price ( $obj -> amount_ttc ), $langs -> transnoentities ( " Currency " . $conf -> currency )), 'confirm_split' , $formquestion , 0 , 0 );
2009-08-07 02:49:43 +02:00
print '</td>' ;
print '</tr>' ;
2010-05-08 22:47:12 +02:00
}
$i ++ ;
}
$db -> free ( $resql );
print " </table> " ;
}
else
{
dol_print_error ( $db );
}
print '<br>' ;
/*
* Liste ristournes appliquees ( = liees a une ligne de facture ou facture )
*/
// Remises liees a lignes de factures
$sql = " SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, " ;
$sql .= " rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture, " ;
$sql .= " rc.fk_facture_source, " ;
2007-04-03 01:45:50 +02:00
$sql .= " u.login, u.rowid as user_id, " ;
2010-05-08 22:47:12 +02:00
$sql .= " f.rowid, f.facnumber, " ;
2007-04-03 01:45:50 +02:00
$sql .= " fa.facnumber as ref, fa.type as type " ;
2010-05-08 22:47:12 +02:00
$sql .= " FROM " . MAIN_DB_PREFIX . " facture as f " ;
$sql .= " , " . MAIN_DB_PREFIX . " user as u " ;
$sql .= " , " . MAIN_DB_PREFIX . " facturedet as fc " ;
$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 " ;
$sql .= " WHERE rc.fk_soc = " . $objsoc -> id ;
$sql .= " AND rc.fk_facture_line = fc.rowid " ;
$sql .= " AND fc.fk_facture = f.rowid " ;
$sql .= " AND rc.fk_user = u.rowid " ;
2008-06-20 20:30:04 +02:00
$sql .= " ORDER BY dc DESC " ;
//$sql.= " UNION ";
2010-05-08 22:47:12 +02:00
// Remises liees a factures
$sql2 = " SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, " ;
$sql2 .= " rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture, " ;
$sql2 .= " rc.fk_facture_source, " ;
2008-06-20 20:30:04 +02:00
$sql2 .= " u.login, u.rowid as user_id, " ;
2010-05-08 22:47:12 +02:00
$sql2 .= " f.rowid, f.facnumber, " ;
2008-06-20 20:30:04 +02:00
$sql2 .= " fa.facnumber as ref, fa.type as type " ;
2010-05-08 22:47:12 +02:00
$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
2010-05-08 22:47:12 +02:00
$resql = $db -> query ( $sql );
2008-06-20 20:30:04 +02:00
$resql2 = null ;
2010-05-08 22:47:12 +02:00
if ( $resql ) $resql2 = $db -> query ( $sql2 );
2008-06-20 20:30:04 +02:00
if ( $resql2 )
2010-05-08 22:47:12 +02:00
{
print_titre ( $langs -> trans ( " DiscountAlreadyCounted " ));
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<td width="120" align="left">' . $langs -> trans ( " Date " ) . '</td>' ; // Need 120+ for format with AM/PM
2011-02-19 13:50:31 +01:00
print '<td align="left">' . $langs -> trans ( " ReasonDiscount " ) . '</td>' ;
2013-04-25 01:13:13 +02:00
print '<td width="150" class="nowrap">' . $langs -> trans ( " ConsumedBy " ) . '</td>' ;
2010-05-08 22:47:12 +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>' ;
print '<td width="100" align="center">' . $langs -> trans ( " Author " ) . '</td>' ;
2011-02-19 13:50:31 +01:00
print '<td width="50"> </td>' ;
2010-05-08 22:47:12 +02:00
print '</tr>' ;
$var = true ;
2008-06-20 20:30:04 +02:00
$tab_sqlobj = array ();
$tab_sqlobjOrder = array ();
2010-05-08 22:47:12 +02:00
$num = $db -> num_rows ( $resql );
2008-06-20 20:30:04 +02:00
for ( $i = 0 ; $i < $num ; $i ++ )
2010-05-08 22:47:12 +02:00
{
2008-06-20 20:30:04 +02:00
$sqlobj = $db -> fetch_object ( $resql );
$tab_sqlobj [] = $sqlobj ;
2010-05-08 22:47:12 +02:00
$tab_sqlobjOrder [] = $db -> jdate ( $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 ++ )
2010-05-08 22:47:12 +02:00
{
2008-06-20 20:30:04 +02:00
$sqlobj = $db -> fetch_object ( $resql2 );
$tab_sqlobj [] = $sqlobj ;
2010-05-08 22:47:12 +02:00
$tab_sqlobjOrder [] = $db -> jdate ( $sqlobj -> dc );
}
2008-06-20 20:30:04 +02:00
$db -> free ( $resql2 );
2011-07-08 20:39:14 +02:00
array_multisort ( $tab_sqlobjOrder , SORT_DESC , $tab_sqlobj );
2009-02-24 03:41:21 +01:00
2011-07-08 20:39:14 +02:00
$num = count ( $tab_sqlobj );
2008-06-20 20:30:04 +02:00
$i = 0 ;
2010-05-08 22:47:12 +02:00
while ( $i < $num )
{
$obj = array_shift ( $tab_sqlobj );
$var = ! $var ;
2013-06-20 09:18:12 +02:00
print " <tr " . $bc [ $var ] . " > " ;
2010-05-08 22:47:12 +02:00
print '<td>' . dol_print_date ( $db -> jdate ( $obj -> dc ), 'dayhour' ) . '</td>' ;
2007-04-03 01:45:50 +02:00
if ( $obj -> description == '(CREDIT_NOTE)' )
{
2013-04-25 01:13:13 +02:00
print '<td class="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)' )
{
2013-04-25 01:13:13 +02:00
print '<td class="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
{
2010-05-08 22:47:12 +02: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
}
2013-04-25 01:13:13 +02:00
print '<td align="left" class="nowrap"><a href="' . DOL_URL_ROOT . '/compta/facture.php?facid=' . $obj -> rowid . '">' . img_object ( $langs -> trans ( " ShowBill " ), 'bill' ) . ' ' . $obj -> facnumber . '</a></td>' ;
2010-05-08 22:47:12 +02:00
print '<td align="right">' . price ( $obj -> amount_ht ) . '</td>' ;
print '<td align="right">' . price2num ( $obj -> tva_tx , 'MU' ) . '%</td>' ;
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>' ;
2010-05-08 22:47:12 +02:00
print '<td> </td>' ;
print '</tr>' ;
$i ++ ;
}
print " </table> " ;
}
else
{
print dol_print_error ( $db );
}
2004-11-09 16:16:17 +01:00
}
$db -> close ();
2011-08-27 16:24:16 +02:00
llxFooter ();
2004-11-09 16:16:17 +01:00
?>