27 if (! defined(
'CSRFCHECK_WITH_TOKEN')) define(
'CSRFCHECK_WITH_TOKEN',
'1');
29 require
'../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
36 $langs->loadLangs(array(
'orders',
'bills',
'companies'));
40 $action =
GETPOST(
'action',
'aZ09');
41 $backtopage =
GETPOST(
'backtopage',
'alpha');
45 if ($user->socid > 0) {
46 $socid = $user->socid;
50 if ($user->socid > 0) {
53 $result =
restrictedArea($user,
'societe', $id,
'&societe',
'',
'fk_soc',
'rowid', 0);
60 if (
GETPOST(
'cancel',
'alpha') && !empty($backtopage)) {
61 header(
"Location: ".$backtopage);
65 if ($action ==
'confirm_split' &&
GETPOST(
"confirm",
"alpha") ==
'yes' && ($user->rights->societe->creer || $user->rights->facture->creer)) {
69 $amount_ttc_1 =
GETPOST(
'amount_ttc_1',
'alpha');
71 $amount_ttc_2 =
GETPOST(
'amount_ttc_2',
'alpha');
77 $res = $discount->fetch($remid);
80 setEventMessages($langs->trans(
"ErrorFailedToLoadDiscount"),
null,
'errors');
82 if (!$error &&
price2num($amount_ttc_1 + $amount_ttc_2) != $discount->amount_ttc) {
84 setEventMessages($langs->trans(
"TotalOfTwoDiscountMustEqualsOriginal"),
null,
'errors');
86 if (!$error && $discount->fk_facture_line) {
88 setEventMessages($langs->trans(
"ErrorCantSplitAUsedDiscount"),
null,
'errors');
93 $newdiscount1->fk_facture_source = $discount->fk_facture_source;
94 $newdiscount2->fk_facture_source = $discount->fk_facture_source;
95 $newdiscount1->fk_facture = $discount->fk_facture;
96 $newdiscount2->fk_facture = $discount->fk_facture;
97 $newdiscount1->fk_facture_line = $discount->fk_facture_line;
98 $newdiscount2->fk_facture_line = $discount->fk_facture_line;
99 $newdiscount1->fk_invoice_supplier_source = $discount->fk_invoice_supplier_source;
100 $newdiscount2->fk_invoice_supplier_source = $discount->fk_invoice_supplier_source;
101 $newdiscount1->fk_invoice_supplier = $discount->fk_invoice_supplier;
102 $newdiscount2->fk_invoice_supplier = $discount->fk_invoice_supplier;
103 $newdiscount1->fk_invoice_supplier_line = $discount->fk_invoice_supplier_line;
104 $newdiscount2->fk_invoice_supplier_line = $discount->fk_invoice_supplier_line;
105 if ($discount->description ==
'(CREDIT_NOTE)' || $discount->description ==
'(DEPOSIT)') {
106 $newdiscount1->description = $discount->description;
107 $newdiscount2->description = $discount->description;
109 $newdiscount1->description = $discount->description.
' (1)';
110 $newdiscount2->description = $discount->description.
' (2)';
113 $newdiscount1->fk_user = $discount->fk_user;
114 $newdiscount2->fk_user = $discount->fk_user;
115 $newdiscount1->fk_soc = $discount->fk_soc;
116 $newdiscount2->fk_soc = $discount->fk_soc;
117 $newdiscount1->discount_type = $discount->discount_type;
118 $newdiscount2->discount_type = $discount->discount_type;
119 $newdiscount1->datec = $discount->datec;
120 $newdiscount2->datec = $discount->datec;
121 $newdiscount1->tva_tx = $discount->tva_tx;
122 $newdiscount2->tva_tx = $discount->tva_tx;
123 $newdiscount1->vat_src_code = $discount->vat_src_code;
124 $newdiscount2->vat_src_code = $discount->vat_src_code;
125 $newdiscount1->amount_ttc = $amount_ttc_1;
126 $newdiscount2->amount_ttc =
price2num($discount->amount_ttc - $newdiscount1->amount_ttc);
127 $newdiscount1->amount_ht =
price2num($newdiscount1->amount_ttc / (1 + $newdiscount1->tva_tx / 100),
'MT');
128 $newdiscount2->amount_ht =
price2num($newdiscount2->amount_ttc / (1 + $newdiscount2->tva_tx / 100),
'MT');
129 $newdiscount1->amount_tva =
price2num($newdiscount1->amount_ttc - $newdiscount1->amount_ht);
130 $newdiscount2->amount_tva =
price2num($newdiscount2->amount_ttc - $newdiscount2->amount_ht);
132 $newdiscount1->multicurrency_amount_ttc = $amount_ttc_1 * ($discount->multicurrency_amount_ttc / $discount->amount_ttc);
133 $newdiscount2->multicurrency_amount_ttc =
price2num($discount->multicurrency_amount_ttc - $newdiscount1->multicurrency_amount_ttc);
134 $newdiscount1->multicurrency_amount_ht =
price2num($newdiscount1->multicurrency_amount_ttc / (1 + $newdiscount1->tva_tx / 100),
'MT');
135 $newdiscount2->multicurrency_amount_ht =
price2num($newdiscount2->multicurrency_amount_ttc / (1 + $newdiscount2->tva_tx / 100),
'MT');
136 $newdiscount1->multicurrency_amount_tva =
price2num($newdiscount1->multicurrency_amount_ttc - $newdiscount1->multicurrency_amount_ht);
137 $newdiscount2->multicurrency_amount_tva =
price2num($newdiscount2->multicurrency_amount_ttc - $newdiscount2->multicurrency_amount_ht);
140 $discount->fk_facture_source = 0;
142 $discount->fk_invoice_supplier_source = 0;
143 $res = $discount->delete($user);
144 $newid1 = $newdiscount1->create($user);
145 $newid2 = $newdiscount2->create($user);
146 if ($res > 0 && $newid1 > 0 && $newid2 > 0) {
148 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?id='.$id.($backtopage ?
'&backtopage='.urlencode($backtopage) :
''));
156 if ($action ==
'setremise' && ($user->rights->societe->creer || $user->rights->facture->creer)) {
161 $desc =
GETPOST(
'desc',
'alpha');
162 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
165 if ($amount_ht > 0) {
168 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReasonDiscount")),
null,
'errors');
175 $discountid = $soc->set_remise_except($amount_ht, $user, $desc, $tva_tx, $discount_type);
177 if ($discountid > 0) {
178 if (!empty($backtopage)) {
179 header(
"Location: ".$backtopage.
'&discountid='.$discountid);
182 header(
"Location: remx.php?id=".$id);
191 setEventMessages($langs->trans(
"ErrorFieldFormat", $langs->transnoentitiesnoconv(
"AmountHT")),
null,
'errors');
195 if (
GETPOST(
'action',
'aZ09') ==
'confirm_remove' &&
GETPOST(
"confirm") ==
'yes' && ($user->rights->societe->creer || $user->rights->facture->creer)) {
202 $result = $discount->fetch(
GETPOST(
"remid"));
203 $result = $discount->delete($user);
206 header(
"Location: ".$_SERVER[
"PHP_SELF"].
'?id='.$id);
220 $facturestatic =
new Facture($db);
223 llxHeader(
'', $langs->trans(
"GlobalDiscount"));
228 $object->fetch($socid);
230 $isCustomer = $object->client == 1 || $object->client == 3;
231 $isSupplier = $object->fournisseur == 1;
238 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'">';
239 print
'<input type="hidden" name="token" value="'.newToken().
'">';
240 print
'<input type="hidden" name="action" value="setremise">';
241 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
243 print
dol_get_fiche_head($head,
'absolutediscount', $langs->trans(
"ThirdParty"), -1,
'company');
245 dol_banner_tab($object,
'socid',
'', ($user->socid ? 0 : 1),
'rowid',
'nom');
247 print
'<div class="fichecenter">';
249 print
'<div class="underbanner clearboth"></div>';
251 if (!$isCustomer && !$isSupplier) {
252 print
'<p class="opacitymedium">'.$langs->trans(
'ThirdpartyIsNeitherCustomerNorClientSoCannotHaveDiscounts').
'</p>';
264 print
'<table class="border centpercent tableforfield borderbottom">';
267 $remise_all = $remise_user = 0;
268 $sql =
"SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
269 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
270 $sql .=
" WHERE rc.fk_soc = ".((int) $object->id);
271 $sql .=
" AND rc.entity = ".((int) $conf->entity);
272 $sql .=
" AND discount_type = 0";
273 $sql .=
" AND (fk_facture_line IS NULL AND fk_facture IS NULL)";
274 $sql .=
" GROUP BY rc.fk_user";
275 $resql = $db->query($sql);
277 $obj = $db->fetch_object(
$resql);
278 $remise_all += $obj->amount;
279 if ($obj->fk_user == $user->id) {
280 $remise_user += $obj->amount;
286 print
'<tr><td class="titlefield">'.$langs->trans(
"CustomerAbsoluteDiscountAllUsers").
'</td>';
287 print
'<td class="amount">'.price($remise_all, 1, $langs, 1, -1, -1, $conf->currency).
' '.$langs->trans(
"HT").
'</td></tr>';
289 if (!empty($user->fk_soc)) {
290 print
'<tr><td>'.$langs->trans(
"CustomerAbsoluteDiscountMy").
'</td>';
291 print
'<td class="amount">'.price($remise_user, 1, $langs, 1, -1, -1, $conf->currency).
' '.$langs->trans(
"HT").
'</td></tr>';
297 $remise_all = $remise_user = 0;
298 $sql =
"SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
299 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
300 $sql .=
" WHERE rc.fk_soc = ".((int) $object->id);
301 $sql .=
" AND rc.entity = ".((int) $conf->entity);
302 $sql .=
" AND discount_type = 1";
303 $sql .=
" AND (fk_invoice_supplier_line IS NULL AND fk_invoice_supplier IS NULL)";
304 $sql .=
" GROUP BY rc.fk_user";
305 $resql = $db->query($sql);
307 $obj = $db->fetch_object(
$resql);
308 $remise_all += $obj->amount;
309 if ($obj->fk_user == $user->id) {
310 $remise_user += $obj->amount;
316 print
'<tr><td class="titlefield">'.$langs->trans(
"SupplierAbsoluteDiscountAllUsers").
'</td>';
317 print
'<td class="amount">'.price($remise_all, 1, $langs, 1, -1, -1, $conf->currency).
' '.$langs->trans(
"HT").
'</td></tr>';
319 if (!empty($user->fk_soc)) {
320 print
'<tr><td>'.$langs->trans(
"SupplierAbsoluteDiscountMy").
'</td>';
321 print
'<td class="amount">'.price($remise_user, 1, $langs, 1, -1, -1, $conf->currency).
' '.$langs->trans(
"HT").
'</td></tr>';
332 if ($user->rights->societe->creer) {
338 if ($isCustomer && !$isSupplier) {
339 print
'<input type="hidden" name="discount_type" value="0" />';
342 if (!$isCustomer && $isSupplier) {
343 print
'<input type="hidden" name="discount_type" value="1" />';
348 print
'<table class="border centpercent">';
349 if ($isCustomer && $isSupplier) {
350 print
'<tr><td class="titlefield fieldrequired">'.$langs->trans(
'DiscountType').
'</td>';
351 print
'<td><input type="radio" name="discount_type" id="discount_type_0" checked="checked" value="0"/> <label for="discount_type_0">'.$langs->trans(
'Customer').
'</label>';
352 print
' <input type="radio" name="discount_type" id="discount_type_1" value="1"/> <label for="discount_type_1">'.$langs->trans(
'Supplier').
'</label>';
355 print
'<tr><td class="titlefield fieldrequired">'.$langs->trans(
"AmountHT").
'</td>';
356 print
'<td><input type="text" size="5" name="amount_ht" value="'.price2num(
GETPOST(
"amount_ht")).
'" autofocus>';
357 print
'<span class="hideonsmartphone"> '.$langs->trans(
"Currency".$conf->currency).
'</span></td></tr>';
358 print
'<tr><td>'.$langs->trans(
"VAT").
'</td>';
360 print
$form->load_tva(
'tva_tx',
GETPOSTISSET(
'tva_tx') ?
GETPOST(
'tva_tx',
'alpha') : 0, $mysoc, $object, 0, 0,
'', 0, 1);
362 print
'<tr><td class="fieldrequired" >'.$langs->trans(
"NoteReason").
'</td>';
363 print
'<td><input type="text" class="quatrevingtpercent" name="desc" value="'.GETPOST(
'desc',
'alphanohtml').
'"></td></tr>';
370 if ($user->rights->societe->creer) {
371 print
'<div class="center">';
372 print
'<input type="submit" class="button" name="submit" value="'.$langs->trans(
"AddGlobalDiscount").
'">';
373 if (!empty($backtopage)) {
374 print
' ';
375 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
385 if ($action ==
'remove') {
386 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&remid='.
GETPOST(
'remid'), $langs->trans(
'RemoveDiscount'), $langs->trans(
'ConfirmRemoveDiscount'),
'confirm_remove',
'', 0, 1);
398 print
'<div class="fichecenter">';
399 print
'<div class="fichehalfleft fichehalfleft-lg">';
403 $sql =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
404 $sql .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
405 $sql .=
" rc.datec as dc, rc.description,";
406 $sql .=
" rc.fk_facture_source,";
407 $sql .=
" u.login, u.rowid as user_id,";
408 $sql .=
" fa.ref as ref, fa.type as type";
409 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u, ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
410 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as fa ON rc.fk_facture_source = fa.rowid";
411 $sql .=
" WHERE rc.fk_soc = ".((int) $object->id);
412 $sql .=
" AND rc.entity = ".((int) $conf->entity);
413 $sql .=
" AND u.rowid = rc.fk_user";
414 $sql .=
" AND rc.discount_type = 0";
415 $sql .=
" AND (rc.fk_facture_line IS NULL AND rc.fk_facture IS NULL)";
416 $sql .=
" ORDER BY rc.datec DESC";
418 $resql = $db->query($sql);
420 print
'<div class="div-table-responsive-no-min">';
421 print
'<table width="100%" class="noborder">';
422 print
'<tr class="liste_titre">';
423 print
'<td class="widthdate">'.$langs->trans(
"Date").
'</td>';
424 print
'<td>'.$langs->trans(
"ReasonDiscount").
'</td>';
425 print
'<td class="nowrap">'.$langs->trans(
"ConsumedBy").
'</td>';
426 print
'<td class="right">'.$langs->trans(
"AmountHT").
'</td>';
427 if (!empty($conf->multicurrency->enabled)) {
428 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountHT")).
'">'.$langs->trans(
"MulticurrencyAmountHT").
'</td>';
430 print
'<td class="right">'.$langs->trans(
"VATRate").
'</td>';
431 print
'<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
432 if (!empty($conf->multicurrency->enabled)) {
433 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountTTC")).
'">'.$langs->trans(
"MulticurrencyAmountTTC").
'</td>';
435 print
'<td width="100" class="center">'.$langs->trans(
"DiscountOfferedBy").
'</td>';
436 print
'<td width="50"> </td>';
439 $showconfirminfo = array();
442 $num = $db->num_rows(
$resql);
445 $obj = $db->fetch_object(
$resql);
447 print
'<tr class="oddeven">';
448 print
'<td>'.dol_print_date($db->jdate($obj->dc),
'dayhour',
'tzuserrel').
'</td>';
449 if (preg_match(
'/\(CREDIT_NOTE\)/', $obj->description)) {
450 print
'<td class="minwidth100">';
451 $facturestatic->id = $obj->fk_facture_source;
452 $facturestatic->ref = $obj->ref;
453 $facturestatic->type = $obj->type;
454 print preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $obj->description).
' '.$facturestatic->getNomURl(1);
456 } elseif (preg_match(
'/\(DEPOSIT\)/', $obj->description)) {
457 print
'<td class="minwidth100">';
458 $facturestatic->id = $obj->fk_facture_source;
459 $facturestatic->ref = $obj->ref;
460 $facturestatic->type = $obj->type;
461 print preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"InvoiceDeposit"), $obj->description).
' '.$facturestatic->getNomURl(1);
463 } elseif (preg_match(
'/\(EXCESS RECEIVED\)/', $obj->description)) {
464 print
'<td class="minwidth100">';
465 $facturestatic->id = $obj->fk_facture_source;
466 $facturestatic->ref = $obj->ref;
467 $facturestatic->type = $obj->type;
468 print preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"ExcessReceived"), $obj->description).
' '.$facturestatic->getNomURl(1);
471 print
'<td class="minwidth100">';
472 print $obj->description;
475 print
'<td class="nowrap"><span class="opacitymedium">'.$langs->trans(
"NotConsumed").
'</span></td>';
476 print
'<td class="right amount">'.price($obj->amount_ht).
'</td>';
477 if (!empty($conf->multicurrency->enabled)) {
478 print
'<td class="right amount">'.price($obj->multicurrency_amount_ht).
'</td>';
480 print
'<td class="right">'.vatrate($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''),
true).
'</td>';
481 print
'<td class="right amount">'.price($obj->amount_ttc).
'</td>';
482 if (!empty($conf->multicurrency->enabled)) {
483 print
'<td class="right amount">'.price($obj->multicurrency_amount_ttc).
'</td>';
485 print
'<td class="center">';
486 print
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$obj->user_id.
'">'.
img_object($langs->trans(
"ShowUser"),
'user').
' '.$obj->login.
'</a>';
488 if ($user->rights->societe->creer || $user->rights->facture->creer) {
489 print
'<td class="center nowrap">';
490 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=split&token='.
newToken().
'&remid='.$obj->rowid.($backtopage ?
'&backtopage='.urlencode($backtopage) :
'').
'">'.
img_split($langs->trans(
"SplitDiscount")).
'</a>';
491 print
'<a class="reposition marginleftonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=remove&token='.
newToken().
'&remid='.$obj->rowid.($backtopage ?
'&backtopage='.urlencode($backtopage) :
'').
'">'.
img_delete($langs->trans(
"RemoveDiscount")).
'</a>';
494 print
'<td> </td>';
498 if ($_GET[
"action"] ==
'split' &&
GETPOST(
'remid') == $obj->rowid) {
499 $showconfirminfo[
'rowid'] = $obj->rowid;
500 $showconfirminfo[
'amount_ttc'] = $obj->amount_ttc;
506 if (!empty($conf->multicurrency->enabled)) {
509 print
'<tr><td colspan="'.$colspan.
'" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
515 if (count($showconfirminfo)) {
516 $amount1 =
price2num($showconfirminfo[
'amount_ttc'] / 2,
'MT');
517 $amount2 = ($showconfirminfo[
'amount_ttc'] - $amount1);
518 $formquestion = array(
519 'text' => $langs->trans(
'TypeAmountOfEachNewDiscount'),
520 array(
'type' =>
'text',
'name' =>
'amount_ttc_1',
'label' => $langs->trans(
"AmountTTC").
' 1',
'value' => $amount1,
'size' =>
'5'),
521 array(
'type' =>
'text',
'name' =>
'amount_ttc_2',
'label' => $langs->trans(
"AmountTTC").
' 2',
'value' => $amount2,
'size' =>
'5')
523 $langs->load(
"dict");
524 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&remid='.$showconfirminfo[
'rowid'].($backtopage ?
'&backtopage='.urlencode($backtopage) :
''), $langs->trans(
'SplitDiscount'), $langs->trans(
'ConfirmSplitDiscount',
price($showconfirminfo[
'amount_ttc']), $langs->transnoentities(
"Currency".$conf->currency)),
'confirm_split', $formquestion,
'', 0);
534 print
'<div class="fichehalfright fichehalfright-lg">';
541 $sql =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
542 $sql .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
543 $sql .=
" rc.datec as dc, rc.description,";
544 $sql .=
" rc.fk_invoice_supplier_source,";
545 $sql .=
" u.login, u.rowid as user_id,";
546 $sql .=
" fa.ref, fa.type as type";
547 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u, ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
548 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
549 $sql .=
" WHERE rc.fk_soc = ".((int) $object->id);
550 $sql .=
" AND rc.entity = ".((int) $conf->entity);
551 $sql .=
" AND u.rowid = rc.fk_user";
552 $sql .=
" AND rc.discount_type = 1";
553 $sql .=
" AND (rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_line IS NULL)";
554 $sql .=
" ORDER BY rc.datec DESC";
556 $resql = $db->query($sql);
558 print
'<div class="div-table-responsive-no-min">';
559 print
'<table width="100%" class="noborder">';
560 print
'<tr class="liste_titre">';
561 print
'<td class="widthdate">'.$langs->trans(
"Date").
'</td>';
562 print
'<td>'.$langs->trans(
"ReasonDiscount").
'</td>';
563 print
'<td class="nowrap">'.$langs->trans(
"ConsumedBy").
'</td>';
564 print
'<td class="right">'.$langs->trans(
"AmountHT").
'</td>';
565 if (!empty($conf->multicurrency->enabled)) {
566 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountHT")).
'">'.$langs->trans(
"MulticurrencyAmountHT").
'</td>';
568 print
'<td class="right">'.$langs->trans(
"VATRate").
'</td>';
569 print
'<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
570 if (!empty($conf->multicurrency->enabled)) {
571 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountTTC")).
'">'.$langs->trans(
"MulticurrencyAmountTTC").
'</td>';
573 print
'<td width="100" class="center">'.$langs->trans(
"DiscountOfferedBy").
'</td>';
574 print
'<td width="50"> </td>';
577 $showconfirminfo = array();
580 $num = $db->num_rows(
$resql);
583 $obj = $db->fetch_object(
$resql);
585 print
'<tr class="oddeven">';
586 print
'<td>'.dol_print_date($db->jdate($obj->dc),
'dayhour',
'tzuserrel').
'</td>';
587 if (preg_match(
'/\(CREDIT_NOTE\)/', $obj->description)) {
588 print
'<td class="minwidth100">';
589 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
590 $facturefournstatic->ref = $obj->ref;
591 $facturefournstatic->type = $obj->type;
592 print preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $obj->description).
' '.$facturefournstatic->getNomURl(1);
594 } elseif (preg_match(
'/\(DEPOSIT\)/', $obj->description)) {
595 print
'<td class="minwidth100">';
596 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
597 $facturefournstatic->ref = $obj->ref;
598 $facturefournstatic->type = $obj->type;
599 print preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"InvoiceDeposit"), $obj->description).
' '.$facturefournstatic->getNomURl(1);
601 } elseif (preg_match(
'/\(EXCESS PAID\)/', $obj->description)) {
602 print
'<td class="minwidth100">';
603 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
604 $facturefournstatic->ref = $obj->ref;
605 $facturefournstatic->type = $obj->type;
606 print preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"ExcessPaid"), $obj->description).
' '.$facturefournstatic->getNomURl(1);
609 print
'<td class="minwidth100">';
610 print $obj->description;
613 print
'<td class="nowrap"><span class="opacitymedium">'.$langs->trans(
"NotConsumed").
'</span></td>';
614 print
'<td class="right amount">'.price($obj->amount_ht).
'</td>';
615 if (!empty($conf->multicurrency->enabled)) {
616 print
'<td class="right amount">'.price($obj->multicurrency_amount_ht).
'</td>';
618 print
'<td class="right">'.vatrate($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''),
true).
'</td>';
619 print
'<td class="right amount">'.price($obj->amount_ttc).
'</td>';
620 if (!empty($conf->multicurrency->enabled)) {
621 print
'<td class="right amount">'.price($obj->multicurrency_amount_ttc).
'</td>';
623 print
'<td class="center">';
624 print
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$obj->user_id.
'">'.
img_object($langs->trans(
"ShowUser"),
'user').
' '.$obj->login.
'</a>';
626 if ($user->rights->societe->creer || $user->rights->facture->creer) {
627 print
'<td class="center nowrap">';
628 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=split&token='.
newToken().
'&remid='.$obj->rowid.($backtopage ?
'&backtopage='.urlencode($backtopage) :
'').
'">'.
img_split($langs->trans(
"SplitDiscount")).
'</a>';
629 print
'<a class="reposition marginleftonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=remove&token='.
newToken().
'&remid='.$obj->rowid.($backtopage ?
'&backtopage='.urlencode($backtopage) :
'').
'">'.
img_delete($langs->trans(
"RemoveDiscount")).
'</a>';
632 print
'<td> </td>';
636 if ($_GET[
"action"] ==
'split' &&
GETPOST(
'remid') == $obj->rowid) {
637 $showconfirminfo[
'rowid'] = $obj->rowid;
638 $showconfirminfo[
'amount_ttc'] = $obj->amount_ttc;
644 if (!empty($conf->multicurrency->enabled)) {
647 print
'<tr><td colspan="'.$colspan.
'" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
653 if (count($showconfirminfo)) {
654 $amount1 =
price2num($showconfirminfo[
'amount_ttc'] / 2,
'MT');
655 $amount2 = ($showconfirminfo[
'amount_ttc'] - $amount1);
656 $formquestion = array(
657 'text' => $langs->trans(
'TypeAmountOfEachNewDiscount'),
658 array(
'type' =>
'text',
'name' =>
'amount_ttc_1',
'label' => $langs->trans(
"AmountTTC").
' 1',
'value' => $amount1,
'size' =>
'5'),
659 array(
'type' =>
'text',
'name' =>
'amount_ttc_2',
'label' => $langs->trans(
"AmountTTC").
' 2',
'value' => $amount2,
'size' =>
'5')
661 $langs->load(
"dict");
662 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&remid='.$showconfirminfo[
'rowid'].($backtopage ?
'&backtopage='.urlencode($backtopage) :
''), $langs->trans(
'SplitDiscount'), $langs->trans(
'ConfirmSplitDiscount',
price($showconfirminfo[
'amount_ttc']), $langs->transnoentities(
"Currency".$conf->currency)),
'confirm_split', $formquestion, 0, 0);
674 print
'<div class="clearboth"></div><br>';
684 print
'<div class="fichecenter">';
685 print
'<div class="fichehalfleft fichehalfleft-lg">';
690 $sql =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
691 $sql .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
692 $sql .=
" rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture_source,";
693 $sql .=
" u.login, u.rowid as user_id,";
694 $sql .=
" f.rowid as invoiceid, f.ref,";
695 $sql .=
" fa.ref as invoice_source_ref, fa.type as type";
696 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
697 $sql .=
" , ".MAIN_DB_PREFIX.
"user as u";
698 $sql .=
" , ".MAIN_DB_PREFIX.
"facturedet as fc";
699 $sql .=
" , ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
700 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as fa ON rc.fk_facture_source = fa.rowid";
701 $sql .=
" WHERE rc.fk_soc = ".((int) $object->id);
702 $sql .=
" AND rc.fk_facture_line = fc.rowid";
703 $sql .=
" AND fc.fk_facture = f.rowid";
704 $sql .=
" AND rc.fk_user = u.rowid";
705 $sql .=
" AND rc.discount_type = 0";
706 $sql .=
" ORDER BY dc DESC";
709 $sql2 =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
710 $sql2 .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
711 $sql2 .=
" rc.datec as dc, rc.description, rc.fk_facture, rc.fk_facture_source,";
712 $sql2 .=
" u.login, u.rowid as user_id,";
713 $sql2 .=
" f.rowid as invoiceid, f.ref,";
714 $sql2 .=
" fa.ref as invoice_source_ref, fa.type as type";
715 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
716 $sql2 .=
" , ".MAIN_DB_PREFIX.
"user as u";
717 $sql2 .=
" , ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
718 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as fa ON rc.fk_facture_source = fa.rowid";
719 $sql2 .=
" WHERE rc.fk_soc = ".((int) $object->id);
720 $sql2 .=
" AND rc.fk_facture = f.rowid";
721 $sql2 .=
" AND rc.fk_user = u.rowid";
722 $sql2 .=
" AND rc.discount_type = 0";
723 $sql2 .=
" ORDER BY dc DESC";
725 $resql = $db->query($sql);
728 $resql2 = $db->query($sql2);
731 print
'<div class="div-table-responsive-no-min">';
732 print
'<table class="noborder centpercent">';
733 print
'<tr class="liste_titre">';
734 print
'<td class="widthdate">'.$langs->trans(
"Date").
'</td>';
735 print
'<td>'.$langs->trans(
"ReasonDiscount").
'</td>';
736 print
'<td class="nowrap">'.$langs->trans(
"ConsumedBy").
'</td>';
737 print
'<td class="right">'.$langs->trans(
"AmountHT").
'</td>';
738 if (!empty($conf->multicurrency->enabled)) {
739 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountHT")).
'">'.$langs->trans(
"MulticurrencyAmountHT").
'</td>';
741 print
'<td class="right">'.$langs->trans(
"VATRate").
'</td>';
742 print
'<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
743 if (!empty($conf->multicurrency->enabled)) {
744 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountTTC")).
'">'.$langs->trans(
"MulticurrencyAmountTTC").
'</td>';
746 print
'<td width="100" class="center">'.$langs->trans(
"Author").
'</td>';
747 print
'<td width="50"> </td>';
750 $tab_sqlobj = array();
751 $tab_sqlobjOrder = array();
752 $num = $db->num_rows(
$resql);
754 for ($i = 0; $i < $num; $i++) {
755 $sqlobj = $db->fetch_object(
$resql);
756 $tab_sqlobj[] = $sqlobj;
757 $tab_sqlobjOrder[] = $db->jdate($sqlobj->dc);
762 $num = $db->num_rows($resql2);
763 for ($i = 0; $i < $num; $i++) {
764 $sqlobj = $db->fetch_object($resql2);
765 $tab_sqlobj[] = $sqlobj;
766 $tab_sqlobjOrder[] = $db->jdate($sqlobj->dc);
769 $array1_sort_order = SORT_DESC;
770 array_multisort($tab_sqlobjOrder, $array1_sort_order, $tab_sqlobj);
772 $num = count($tab_sqlobj);
776 $obj = array_shift($tab_sqlobj);
777 print
'<tr class="oddeven">';
778 print
'<td>'.dol_print_date($db->jdate($obj->dc),
'dayhour').
'</td>';
779 if (preg_match(
'/\(CREDIT_NOTE\)/', $obj->description)) {
780 print
'<td class="minwidth100">';
781 $facturestatic->id = $obj->fk_facture_source;
782 $facturestatic->ref = $obj->invoice_source_ref;
783 $facturestatic->type = $obj->type;
784 print preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $obj->description).
' '.$facturestatic->getNomURl(1);
786 } elseif (preg_match(
'/\(DEPOSIT\)/', $obj->description)) {
787 print
'<td class="minwidth100">';
788 $facturestatic->id = $obj->fk_facture_source;
789 $facturestatic->ref = $obj->invoice_source_ref;
790 $facturestatic->type = $obj->type;
791 print preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"InvoiceDeposit"), $obj->description).
' '.$facturestatic->getNomURl(1);
793 } elseif (preg_match(
'/\(EXCESS RECEIVED\)/', $obj->description)) {
794 print
'<td class="minwidth100">';
795 $facturestatic->id = $obj->fk_facture_source;
796 $facturestatic->ref = $obj->invoice_source_ref;
797 $facturestatic->type = $obj->type;
798 print preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"Invoice"), $obj->description).
' '.$facturestatic->getNomURl(1);
801 print
'<td class="minwidth100">';
802 print $obj->description;
805 print
'<td class="left nowrap">';
806 if ($obj->invoiceid) {
807 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$obj->invoiceid.
'">'.
img_object($langs->trans(
"ShowBill"),
'bill').
' '.$obj->ref.
'</a>';
810 print
'<td class="right">'.price($obj->amount_ht).
'</td>';
811 if (!empty($conf->multicurrency->enabled)) {
812 print
'<td class="right">'.price($obj->multicurrency_amount_ht).
'</td>';
814 print
'<td class="right">'.vatrate($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''),
true).
'</td>';
815 print
'<td class="right">'.price($obj->amount_ttc).
'</td>';
816 if (!empty($conf->multicurrency->enabled)) {
817 print
'<td class="right">'.price($obj->multicurrency_amount_ttc).
'</td>';
819 print
'<td class="center">';
820 print
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$obj->user_id.
'">'.
img_object($langs->trans(
"ShowUser"),
'user').
' '.$obj->login.
'</a>';
822 print
'<td> </td>';
828 if (!empty($conf->multicurrency->enabled)) {
831 print
'<tr><td colspan="'.$colspan.
'" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
844 print
'<div class="fichehalfright fichehalfright-lg">';
849 $sql =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
850 $sql .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
851 $sql .=
" rc.datec as dc, rc.description, rc.fk_invoice_supplier_line,";
852 $sql .=
" rc.fk_invoice_supplier_source,";
853 $sql .=
" u.login, u.rowid as user_id,";
854 $sql .=
" f.rowid as invoiceid, f.ref as ref,";
855 $sql .=
" fa.ref as invoice_source_ref, fa.type as type";
856 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
857 $sql .=
" , ".MAIN_DB_PREFIX.
"user as u";
858 $sql .=
" , ".MAIN_DB_PREFIX.
"facture_fourn_det as fc";
859 $sql .=
" , ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
860 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
861 $sql .=
" WHERE rc.fk_soc = ".((int) $object->id);
862 $sql .=
" AND rc.fk_invoice_supplier_line = fc.rowid";
863 $sql .=
" AND fc.fk_facture_fourn = f.rowid";
864 $sql .=
" AND rc.fk_user = u.rowid";
865 $sql .=
" AND rc.discount_type = 1";
866 $sql .=
" ORDER BY dc DESC";
869 $sql2 =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
870 $sql2 .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
871 $sql2 .=
" rc.datec as dc, rc.description, rc.fk_invoice_supplier,";
872 $sql2 .=
" rc.fk_invoice_supplier_source,";
873 $sql2 .=
" u.login, u.rowid as user_id,";
874 $sql2 .=
" f.rowid as invoiceid, f.ref as ref,";
875 $sql2 .=
" fa.ref as invoice_source_ref, fa.type as type";
876 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
877 $sql2 .=
" , ".MAIN_DB_PREFIX.
"user as u";
878 $sql2 .=
" , ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
879 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
880 $sql2 .=
" WHERE rc.fk_soc = ".((int) $object->id);
881 $sql2 .=
" AND rc.fk_invoice_supplier = f.rowid";
882 $sql2 .=
" AND rc.fk_user = u.rowid";
883 $sql2 .=
" AND rc.discount_type = 1";
884 $sql2 .=
" ORDER BY dc DESC";
886 $resql = $db->query($sql);
889 $resql2 = $db->query($sql2);
892 print
'<div class="div-table-responsive-no-min">';
893 print
'<table class="noborder centpercent">';
894 print
'<tr class="liste_titre">';
895 print
'<td class="widthdate">'.$langs->trans(
"Date").
'</td>';
896 print
'<td>'.$langs->trans(
"ReasonDiscount").
'</td>';
897 print
'<td class="nowrap">'.$langs->trans(
"ConsumedBy").
'</td>';
898 print
'<td class="right">'.$langs->trans(
"AmountHT").
'</td>';
899 if (!empty($conf->multicurrency->enabled)) {
900 print
'<td class="right toverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountHT")).
'">'.$langs->trans(
"MulticurrencyAmountHT").
'</td>';
902 print
'<td class="right">'.$langs->trans(
"VATRate").
'</td>';
903 print
'<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
904 if (!empty($conf->multicurrency->enabled)) {
905 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountTTC")).
'">'.$langs->trans(
"MulticurrencyAmountTTC").
'</td>';
907 print
'<td width="100" class="center">'.$langs->trans(
"Author").
'</td>';
908 print
'<td width="50"> </td>';
911 $tab_sqlobj = array();
912 $tab_sqlobjOrder = array();
913 $num = $db->num_rows(
$resql);
915 for ($i = 0; $i < $num; $i++) {
916 $sqlobj = $db->fetch_object(
$resql);
917 $tab_sqlobj[] = $sqlobj;
918 $tab_sqlobjOrder[] = $db->jdate($sqlobj->dc);
923 $num = $db->num_rows($resql2);
924 for ($i = 0; $i < $num; $i++) {
925 $sqlobj = $db->fetch_object($resql2);
926 $tab_sqlobj[] = $sqlobj;
927 $tab_sqlobjOrder[] = $db->jdate($sqlobj->dc);
930 $array1_sort_order = SORT_DESC;
931 array_multisort($tab_sqlobjOrder, $array1_sort_order, $tab_sqlobj);
933 $num = count($tab_sqlobj);
937 $obj = array_shift($tab_sqlobj);
938 print
'<tr class="oddeven">';
939 print
'<td>'.dol_print_date($db->jdate($obj->dc),
'dayhour').
'</td>';
940 if (preg_match(
'/\(CREDIT_NOTE\)/', $obj->description)) {
941 print
'<td class="minwidth100">';
942 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
943 $facturefournstatic->ref = $obj->invoice_source_ref;
944 $facturefournstatic->type = $obj->type;
945 print preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $obj->description).
' '.$facturefournstatic->getNomURl(1);
947 } elseif (preg_match(
'/\(DEPOSIT\)/', $obj->description)) {
948 print
'<td class="minwidth100">';
949 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
950 $facturefournstatic->ref = $obj->invoice_source_ref;
951 $facturefournstatic->type = $obj->type;
952 print preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"InvoiceDeposit"), $obj->description).
' '.$facturefournstatic->getNomURl(1);
954 } elseif (preg_match(
'/\(EXCESS PAID\)/', $obj->description)) {
955 print
'<td class="minwidth100">';
956 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
957 $facturefournstatic->ref = $obj->invoice_source_ref;
958 $facturefournstatic->type = $obj->type;
959 print preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"Invoice"), $obj->description).
' '.$facturefournstatic->getNomURl(1);
962 print
'<td class="minwidth100">';
963 print $obj->description;
966 print
'<td class="left nowrap">';
967 if ($obj->invoiceid) {
968 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.$obj->invoiceid.
'">'.
img_object($langs->trans(
"ShowBill"),
'bill').
' '.$obj->ref.
'</a>';
971 print
'<td class="right">'.price($obj->amount_ht).
'</td>';
972 if (!empty($conf->multicurrency->enabled)) {
973 print
'<td class="right">'.price($obj->multicurrency_amount_ht).
'</td>';
975 print
'<td class="right">'.vatrate($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''),
true).
'</td>';
976 print
'<td class="right">'.price($obj->amount_ttc).
'</td>';
977 if (!empty($conf->multicurrency->enabled)) {
978 print
'<td class="right">'.price($obj->multicurrency_amount_ttc).
'</td>';
980 print
'<td class="center">';
981 print
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$obj->user_id.
'">'.
img_object($langs->trans(
"ShowUser"),
'user').
' '.$obj->login.
'</a>';
983 print
'<td> </td>';
989 if (!empty($conf->multicurrency->enabled)) {
992 print
'<tr><td colspan="'.$colspan.
'" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';