27 require
'../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
29 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
34 $langs->loadLangs(array(
'orders',
'bills',
'companies'));
38 $action =
GETPOST(
'action',
'aZ09');
39 $backtopage =
GETPOST(
'backtopage',
'alpha');
45 $socid = $user->socid;
53 if (
GETPOST(
'cancel',
'alpha') && !empty($backtopage))
55 header(
"Location: ".$backtopage);
59 if ($action ==
'confirm_split' &&
GETPOST(
"confirm",
"alpha") ==
'yes')
64 $amount_ttc_1 =
GETPOST(
'amount_ttc_1',
'alpha');
66 $amount_ttc_2 =
GETPOST(
'amount_ttc_2',
'alpha');
72 $res = $discount->fetch($remid);
76 setEventMessages($langs->trans(
"ErrorFailedToLoadDiscount"), null,
'errors');
78 if (!$error &&
price2num($amount_ttc_1 + $amount_ttc_2) != $discount->amount_ttc)
81 setEventMessages($langs->trans(
"TotalOfTwoDiscountMustEqualsOriginal"), null,
'errors');
83 if (!$error && $discount->fk_facture_line)
86 setEventMessages($langs->trans(
"ErrorCantSplitAUsedDiscount"), null,
'errors');
92 $newdiscount1->fk_facture_source = $discount->fk_facture_source;
93 $newdiscount2->fk_facture_source = $discount->fk_facture_source;
94 $newdiscount1->fk_facture = $discount->fk_facture;
95 $newdiscount2->fk_facture = $discount->fk_facture;
96 $newdiscount1->fk_facture_line = $discount->fk_facture_line;
97 $newdiscount2->fk_facture_line = $discount->fk_facture_line;
98 $newdiscount1->fk_invoice_supplier_source = $discount->fk_invoice_supplier_source;
99 $newdiscount2->fk_invoice_supplier_source = $discount->fk_invoice_supplier_source;
100 $newdiscount1->fk_invoice_supplier = $discount->fk_invoice_supplier;
101 $newdiscount2->fk_invoice_supplier = $discount->fk_invoice_supplier;
102 $newdiscount1->fk_invoice_supplier_line = $discount->fk_invoice_supplier_line;
103 $newdiscount2->fk_invoice_supplier_line = $discount->fk_invoice_supplier_line;
104 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)
149 header(
"Location: ".
$_SERVER[
"PHP_SELF"].
'?id='.$id.($backtopage ?
'&backtopage='.urlencode($backtopage) :
''));
157 if ($action ==
'setremise' && $user->rights->societe->creer)
163 $desc =
GETPOST(
'desc',
'alpha');
164 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
165 $discount_type = !empty($_POST[
'discount_type']) ?
GETPOST(
'discount_type',
'alpha') : 0;
172 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReasonDiscount")), null,
'errors');
180 $discountid = $soc->set_remise_except($amount_ht, $user, $desc, $tva_tx, $discount_type);
184 if (!empty($backtopage))
186 header(
"Location: ".$backtopage.
'&discountid='.$discountid);
189 header(
"Location: remx.php?id=".$id);
198 setEventMessages($langs->trans(
"ErrorFieldFormat", $langs->transnoentitiesnoconv(
"AmountHT")), null,
'errors');
202 if (
GETPOST(
'action',
'aZ09') ==
'confirm_remove' &&
GETPOST(
"confirm") ==
'yes')
210 $result = $discount->fetch(
GETPOST(
"remid"));
211 $result = $discount->delete($user);
215 header(
"Location: ".
$_SERVER[
"PHP_SELF"].
'?id='.$id);
228 $form =
new Form($db);
229 $facturestatic =
new Facture($db);
232 llxHeader(
'', $langs->trans(
"GlobalDiscount"));
238 $object->fetch($socid);
240 $isCustomer = $object->client == 1 || $object->client == 3;
241 $isSupplier = $object->fournisseur == 1;
248 print '<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'">';
249 print '<input type="hidden" name="token" value="'.newToken().
'">';
250 print '<input type="hidden" name="action" value="setremise">';
251 print '<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
255 dol_banner_tab($object,
'socid',
'', ($user->socid ? 0 : 1),
'rowid',
'nom');
257 print '<div class="fichecenter">';
259 print '<div class="underbanner clearboth"></div>';
261 if (!$isCustomer && !$isSupplier) {
262 print '<p class="opacitymedium">'.$langs->trans(
'ThirdpartyIsNeitherCustomerNorClientSoCannotHaveDiscounts').
'</p>';
274 print '<table class="border centpercent tableforfield borderbottom">';
277 $remise_all = $remise_user = 0;
278 $sql =
"SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
279 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
280 $sql .=
" WHERE rc.fk_soc = ".$object->id;
281 $sql .=
" AND rc.entity = ".$conf->entity;
282 $sql .=
" AND discount_type = 0";
283 $sql .=
" AND (fk_facture_line IS NULL AND fk_facture IS NULL)";
284 $sql .=
" GROUP BY rc.fk_user";
285 $resql = $db->query($sql);
288 $obj = $db->fetch_object(
$resql);
289 $remise_all += $obj->amount;
290 if ($obj->fk_user == $user->id) $remise_user += $obj->amount;
295 print '<tr><td class="titlefield">'.$langs->trans(
"CustomerAbsoluteDiscountAllUsers").
'</td>';
296 print '<td>'.$remise_all.
' '.$langs->trans(
"Currency".$conf->currency).
' '.$langs->trans(
"HT").
'</td></tr>';
298 if (!empty($user->fk_soc))
300 print '<tr><td>'.$langs->trans(
"CustomerAbsoluteDiscountMy").
'</td>';
301 print '<td>'.$remise_user.
' '.$langs->trans(
"Currency".$conf->currency).
' '.$langs->trans(
"HT").
'</td></tr>';
307 $remise_all = $remise_user = 0;
308 $sql =
"SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
309 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
310 $sql .=
" WHERE rc.fk_soc = ".$object->id;
311 $sql .=
" AND rc.entity = ".$conf->entity;
312 $sql .=
" AND discount_type = 1";
313 $sql .=
" AND (fk_invoice_supplier_line IS NULL AND fk_invoice_supplier IS NULL)";
314 $sql .=
" GROUP BY rc.fk_user";
315 $resql = $db->query($sql);
318 $obj = $db->fetch_object(
$resql);
319 $remise_all += $obj->amount;
320 if ($obj->fk_user == $user->id) $remise_user += $obj->amount;
325 print '<tr><td class="titlefield">'.$langs->trans(
"SupplierAbsoluteDiscountAllUsers").
'</td>';
326 print '<td>'.$remise_all.
' '.$langs->trans(
"Currency".$conf->currency).
' '.$langs->trans(
"HT").
'</td></tr>';
328 if (!empty($user->fk_soc))
330 print '<tr><td>'.$langs->trans(
"SupplierAbsoluteDiscountMy").
'</td>';
331 print '<td>'.$remise_user.
' '.$langs->trans(
"Currency".$conf->currency).
' '.$langs->trans(
"HT").
'</td></tr>';
342 if ($user->rights->societe->creer)
349 if ($isCustomer && !$isSupplier) {
350 print '<input type="hidden" name="discount_type" value="0" />';
353 if (!$isCustomer && $isSupplier) {
354 print '<input type="hidden" name="discount_type" value="1" />';
359 print '<table class="border centpercent">';
360 if ($isCustomer && $isSupplier) {
361 print '<tr><td class="titlefield fieldrequired">'.$langs->trans(
'DiscountType').
'</td>';
362 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>';
363 print ' <input type="radio" name="discount_type" id="discount_type_1" value="1"/> <label for="discount_type_1">'.$langs->trans(
'Supplier').
'</label>';
366 print '<tr><td class="titlefield fieldrequired">'.$langs->trans(
"AmountHT").
'</td>';
367 print '<td><input type="text" size="5" name="amount_ht" value="'.price2num(
GETPOST(
"amount_ht")).
'">';
368 print '<span class="hideonsmartphone"> '.$langs->trans(
"Currency".$conf->currency).
'</span></td></tr>';
369 print '<tr><td>'.$langs->trans(
"VAT").
'</td>';
371 print $form->load_tva(
'tva_tx',
GETPOSTISSET(
'tva_tx') ?
GETPOST(
'tva_tx',
'alpha') : 0, $mysoc, $object, 0, 0,
'', 0, 1);
373 print '<tr><td class="fieldrequired" >'.$langs->trans(
"NoteReason").
'</td>';
374 print '<td><input type="text" class="quatrevingtpercent" name="desc" value="'.GETPOST(
'desc',
'alphanohtml').
'"></td></tr>';
381 if ($user->rights->societe->creer)
383 print '<div class="center">';
384 print '<input type="submit" class="button" name="submit" value="'.$langs->trans(
"AddGlobalDiscount").
'">';
385 if (!empty($backtopage))
387 print ' ';
388 print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
398 if ($_GET[
'action'] ==
'remove')
400 print $form->formconfirm(
$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&remid='.
GETPOST(
'remid'), $langs->trans(
'RemoveDiscount'), $langs->trans(
'ConfirmRemoveDiscount'),
'confirm_remove',
'', 0, 1);
412 print '<div class="fichecenter">';
413 print '<div class="fichehalfleft fichehalfleft-lg">';
417 $sql =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
418 $sql .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
419 $sql .=
" rc.datec as dc, rc.description,";
420 $sql .=
" rc.fk_facture_source,";
421 $sql .=
" u.login, u.rowid as user_id,";
422 $sql .=
" fa.ref as ref, fa.type as type";
423 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u, ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
424 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as fa ON rc.fk_facture_source = fa.rowid";
425 $sql .=
" WHERE rc.fk_soc = ".$object->id;
426 $sql .=
" AND rc.entity = ".$conf->entity;
427 $sql .=
" AND u.rowid = rc.fk_user";
428 $sql .=
" AND rc.discount_type = 0";
429 $sql .=
" AND (rc.fk_facture_line IS NULL AND rc.fk_facture IS NULL)";
430 $sql .=
" ORDER BY rc.datec DESC";
432 $resql = $db->query($sql);
435 print '<div class="div-table-responsive-no-min">';
436 print '<table width="100%" class="noborder">';
437 print '<tr class="liste_titre">';
438 print '<td class="widthdate">'.$langs->trans(
"Date").
'</td>';
439 print '<td>'.$langs->trans(
"ReasonDiscount").
'</td>';
440 print '<td class="nowrap">'.$langs->trans(
"ConsumedBy").
'</td>';
441 print '<td class="right">'.$langs->trans(
"AmountHT").
'</td>';
442 if (!empty($conf->multicurrency->enabled))
444 print '<td class="right">'.$langs->trans(
"MulticurrencyAmountHT").
'</td>';
446 print '<td class="right">'.$langs->trans(
"VATRate").
'</td>';
447 print '<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
448 if (!empty($conf->multicurrency->enabled))
450 print '<td class="right">'.$langs->trans(
"MulticurrencyAmountTTC").
'</td>';
452 print '<td width="100" class="center">'.$langs->trans(
"DiscountOfferedBy").
'</td>';
453 print '<td width="50"> </td>';
456 $showconfirminfo = array();
459 $num = $db->num_rows(
$resql);
464 $obj = $db->fetch_object(
$resql);
466 print '<tr class="oddeven">';
467 print '<td>'.dol_print_date($db->jdate($obj->dc),
'dayhour').
'</td>';
468 if (preg_match(
'/\(CREDIT_NOTE\)/', $obj->description))
470 print '<td class="minwidth100">';
471 $facturestatic->id = $obj->fk_facture_source;
472 $facturestatic->ref = $obj->ref;
473 $facturestatic->type = $obj->type;
474 print preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $obj->description).
' '.$facturestatic->getNomURl(1);
476 } elseif (preg_match(
'/\(DEPOSIT\)/', $obj->description))
478 print '<td class="minwidth100">';
479 $facturestatic->id = $obj->fk_facture_source;
480 $facturestatic->ref = $obj->ref;
481 $facturestatic->type = $obj->type;
482 print preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"InvoiceDeposit"), $obj->description).
' '.$facturestatic->getNomURl(1);
484 } elseif (preg_match(
'/\(EXCESS RECEIVED\)/', $obj->description))
486 print '<td class="minwidth100">';
487 $facturestatic->id = $obj->fk_facture_source;
488 $facturestatic->ref = $obj->ref;
489 $facturestatic->type = $obj->type;
490 print preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"ExcessReceived"), $obj->description).
' '.$facturestatic->getNomURl(1);
493 print '<td class="minwidth100">';
494 print $obj->description;
497 print '<td class="nowrap">'.$langs->trans(
"NotConsumed").
'</td>';
498 print '<td class="right">'.price($obj->amount_ht).
'</td>';
499 if (!empty($conf->multicurrency->enabled))
501 print '<td class="right">'.price($obj->multicurrency_amount_ht).
'</td>';
503 print '<td class="right">'.vatrate($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''),
true).
'</td>';
504 print '<td class="right">'.price($obj->amount_ttc).
'</td>';
505 if (!empty($conf->multicurrency->enabled))
507 print '<td class="right">'.price($obj->multicurrency_amount_ttc).
'</td>';
509 print '<td class="center">';
510 print '<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$obj->user_id.
'">'.
img_object($langs->trans(
"ShowUser"),
'user').
' '.$obj->login.
'</a>';
512 if ($user->rights->societe->creer || $user->rights->facture->creer)
514 print '<td class="center nowrap">';
515 print '<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=split&remid='.$obj->rowid.($backtopage ?
'&backtopage='.urlencode($backtopage) :
'').
'">'.
img_split($langs->trans(
"SplitDiscount")).
'</a>';
516 print '<a class="reposition marginleftonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=remove&remid='.$obj->rowid.($backtopage ?
'&backtopage='.urlencode($backtopage) :
'').
'">'.
img_delete($langs->trans(
"RemoveDiscount")).
'</a>';
518 }
else print '<td> </td>';
521 if ($_GET[
"action"] ==
'split' &&
GETPOST(
'remid') == $obj->rowid)
523 $showconfirminfo[
'rowid'] = $obj->rowid;
524 $showconfirminfo[
'amount_ttc'] = $obj->amount_ttc;
530 if (!empty($conf->multicurrency->enabled)) $colspan += 2;
531 print '<tr><td colspan="'.$colspan.
'" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
537 if (count($showconfirminfo))
539 $amount1 =
price2num($showconfirminfo[
'amount_ttc'] / 2,
'MT');
540 $amount2 = ($showconfirminfo[
'amount_ttc'] - $amount1);
541 $formquestion = array(
542 'text' => $langs->trans(
'TypeAmountOfEachNewDiscount'),
543 array(
'type' =>
'text',
'name' =>
'amount_ttc_1',
'label' => $langs->trans(
"AmountTTC").
' 1',
'value' => $amount1,
'size' =>
'5'),
544 array(
'type' =>
'text',
'name' =>
'amount_ttc_2',
'label' => $langs->trans(
"AmountTTC").
' 2',
'value' => $amount2,
'size' =>
'5')
546 $langs->load(
"dict");
547 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);
557 print '<div class="fichehalfright fichehalfright-lg">';
558 print '<div class="ficheaddleft">';
565 $sql =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
566 $sql .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
567 $sql .=
" rc.datec as dc, rc.description,";
568 $sql .=
" rc.fk_invoice_supplier_source,";
569 $sql .=
" u.login, u.rowid as user_id,";
570 $sql .=
" fa.ref, fa.type as type";
571 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u, ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
572 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
573 $sql .=
" WHERE rc.fk_soc = ".$object->id;
574 $sql .=
" AND rc.entity = ".$conf->entity;
575 $sql .=
" AND u.rowid = rc.fk_user";
576 $sql .=
" AND rc.discount_type = 1";
577 $sql .=
" AND (rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_line IS NULL)";
578 $sql .=
" ORDER BY rc.datec DESC";
580 $resql = $db->query($sql);
583 print '<div class="div-table-responsive-no-min">';
584 print '<table width="100%" class="noborder">';
585 print '<tr class="liste_titre">';
586 print '<td class="widthdate">'.$langs->trans(
"Date").
'</td>';
587 print '<td>'.$langs->trans(
"ReasonDiscount").
'</td>';
588 print '<td class="nowrap">'.$langs->trans(
"ConsumedBy").
'</td>';
589 print '<td class="right">'.$langs->trans(
"AmountHT").
'</td>';
590 if (!empty($conf->multicurrency->enabled))
592 print '<td class="right">'.$langs->trans(
"MulticurrencyAmountHT").
'</td>';
594 print '<td class="right">'.$langs->trans(
"VATRate").
'</td>';
595 print '<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
596 if (!empty($conf->multicurrency->enabled))
598 print '<td class="right">'.$langs->trans(
"MulticurrencyAmountTTC").
'</td>';
600 print '<td width="100" class="center">'.$langs->trans(
"DiscountOfferedBy").
'</td>';
601 print '<td width="50"> </td>';
604 $showconfirminfo = array();
607 $num = $db->num_rows(
$resql);
612 $obj = $db->fetch_object(
$resql);
614 print '<tr class="oddeven">';
615 print '<td>'.dol_print_date($db->jdate($obj->dc),
'dayhour').
'</td>';
616 if (preg_match(
'/\(CREDIT_NOTE\)/', $obj->description))
618 print '<td class="minwidth100">';
619 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
620 $facturefournstatic->ref = $obj->ref;
621 $facturefournstatic->type = $obj->type;
622 print preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $obj->description).
' '.$facturefournstatic->getNomURl(1);
624 } elseif (preg_match(
'/\(DEPOSIT\)/', $obj->description))
626 print '<td class="minwidth100">';
627 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
628 $facturefournstatic->ref = $obj->ref;
629 $facturefournstatic->type = $obj->type;
630 print preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"InvoiceDeposit"), $obj->description).
' '.$facturefournstatic->getNomURl(1);
632 } elseif (preg_match(
'/\(EXCESS PAID\)/', $obj->description))
634 print '<td class="minwidth100">';
635 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
636 $facturefournstatic->ref = $obj->ref;
637 $facturefournstatic->type = $obj->type;
638 print preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"ExcessPaid"), $obj->description).
' '.$facturefournstatic->getNomURl(1);
641 print '<td class="minwidth100">';
642 print $obj->description;
645 print '<td class="nowrap">'.$langs->trans(
"NotConsumed").
'</td>';
646 print '<td class="right">'.price($obj->amount_ht).
'</td>';
647 if (!empty($conf->multicurrency->enabled))
649 print '<td class="right">'.price($obj->multicurrency_amount_ht).
'</td>';
651 print '<td class="right">'.vatrate($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''),
true).
'</td>';
652 print '<td class="right">'.price($obj->amount_ttc).
'</td>';
653 if (!empty($conf->multicurrency->enabled))
655 print '<td class="right">'.price($obj->multicurrency_amount_ttc).
'</td>';
657 print '<td class="center">';
658 print '<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$obj->user_id.
'">'.
img_object($langs->trans(
"ShowUser"),
'user').
' '.$obj->login.
'</a>';
660 if ($user->rights->societe->creer || $user->rights->facture->creer)
662 print '<td class="center nowrap">';
663 print '<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=split&remid='.$obj->rowid.($backtopage ?
'&backtopage='.urlencode($backtopage) :
'').
'">'.
img_split($langs->trans(
"SplitDiscount")).
'</a>';
664 print '<a class="reposition marginleftonly" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=remove&remid='.$obj->rowid.($backtopage ?
'&backtopage='.urlencode($backtopage) :
'').
'">'.
img_delete($langs->trans(
"RemoveDiscount")).
'</a>';
666 }
else print '<td> </td>';
669 if ($_GET[
"action"] ==
'split' &&
GETPOST(
'remid') == $obj->rowid)
671 $showconfirminfo[
'rowid'] = $obj->rowid;
672 $showconfirminfo[
'amount_ttc'] = $obj->amount_ttc;
678 if (!empty($conf->multicurrency->enabled)) $colspan += 2;
679 print '<tr><td colspan="'.$colspan.
'" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
685 if (count($showconfirminfo))
687 $amount1 =
price2num($showconfirminfo[
'amount_ttc'] / 2,
'MT');
688 $amount2 = ($showconfirminfo[
'amount_ttc'] - $amount1);
689 $formquestion = array(
690 'text' => $langs->trans(
'TypeAmountOfEachNewDiscount'),
691 array(
'type' =>
'text',
'name' =>
'amount_ttc_1',
'label' => $langs->trans(
"AmountTTC").
' 1',
'value' => $amount1,
'size' =>
'5'),
692 array(
'type' =>
'text',
'name' =>
'amount_ttc_2',
'label' => $langs->trans(
"AmountTTC").
' 2',
'value' => $amount2,
'size' =>
'5')
694 $langs->load(
"dict");
695 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);
708 print '<div class="clearboth"></div><br>';
718 print '<div class="fichecenter">';
719 print '<div class="fichehalfleft fichehalfleft-lg">';
724 $sql =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
725 $sql .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
726 $sql .=
" rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture_source,";
727 $sql .=
" u.login, u.rowid as user_id,";
728 $sql .=
" f.rowid as invoiceid, f.ref,";
729 $sql .=
" fa.ref as invoice_source_ref, fa.type as type";
730 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
731 $sql .=
" , ".MAIN_DB_PREFIX.
"user as u";
732 $sql .=
" , ".MAIN_DB_PREFIX.
"facturedet as fc";
733 $sql .=
" , ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
734 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as fa ON rc.fk_facture_source = fa.rowid";
735 $sql .=
" WHERE rc.fk_soc =".$object->id;
736 $sql .=
" AND rc.fk_facture_line = fc.rowid";
737 $sql .=
" AND fc.fk_facture = f.rowid";
738 $sql .=
" AND rc.fk_user = u.rowid";
739 $sql .=
" AND rc.discount_type = 0";
740 $sql .=
" ORDER BY dc DESC";
743 $sql2 =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
744 $sql2 .=
" rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture,";
745 $sql2 .=
" rc.fk_facture_source,";
746 $sql2 .=
" u.login, u.rowid as user_id,";
747 $sql2 .=
" f.rowid as invoiceid, f.ref,";
748 $sql2 .=
" fa.ref as invoice_source_ref, fa.type as type";
749 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
750 $sql2 .=
" , ".MAIN_DB_PREFIX.
"user as u";
751 $sql2 .=
" , ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
752 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as fa ON rc.fk_facture_source = fa.rowid";
753 $sql2 .=
" WHERE rc.fk_soc =".$object->id;
754 $sql2 .=
" AND rc.fk_facture = f.rowid";
755 $sql2 .=
" AND rc.fk_user = u.rowid";
756 $sql2 .=
" AND rc.discount_type = 0";
757 $sql2 .=
" ORDER BY dc DESC";
759 $resql = $db->query($sql);
761 if (
$resql) $resql2 = $db->query($sql2);
764 print '<div class="div-table-responsive-no-min">';
765 print '<table class="noborder centpercent">';
766 print '<tr class="liste_titre">';
767 print '<td class="widthdate">'.$langs->trans(
"Date").
'</td>';
768 print '<td>'.$langs->trans(
"ReasonDiscount").
'</td>';
769 print '<td class="nowrap">'.$langs->trans(
"ConsumedBy").
'</td>';
770 print '<td class="right">'.$langs->trans(
"AmountHT").
'</td>';
771 if (!empty($conf->multicurrency->enabled))
773 print '<td class="right">'.$langs->trans(
"MulticurrencyAmountHT").
'</td>';
775 print '<td class="right">'.$langs->trans(
"VATRate").
'</td>';
776 print '<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
777 if (!empty($conf->multicurrency->enabled))
779 print '<td class="right">'.$langs->trans(
"MulticurrencyAmountTTC").
'</td>';
781 print '<td width="100" class="center">'.$langs->trans(
"Author").
'</td>';
782 print '<td width="50"> </td>';
785 $tab_sqlobj = array();
786 $tab_sqlobjOrder = array();
787 $num = $db->num_rows(
$resql);
790 for ($i = 0; $i < $num; $i++)
792 $sqlobj = $db->fetch_object(
$resql);
793 $tab_sqlobj[] = $sqlobj;
794 $tab_sqlobjOrder[] = $db->jdate($sqlobj->dc);
799 $num = $db->num_rows($resql2);
800 for ($i = 0; $i < $num; $i++)
802 $sqlobj = $db->fetch_object($resql2);
803 $tab_sqlobj[] = $sqlobj;
804 $tab_sqlobjOrder[] = $db->jdate($sqlobj->dc);
807 array_multisort($tab_sqlobjOrder, SORT_DESC, $tab_sqlobj);
809 $num = count($tab_sqlobj);
815 $obj = array_shift($tab_sqlobj);
816 print '<tr class="oddeven">';
817 print '<td>'.dol_print_date($db->jdate($obj->dc),
'dayhour').
'</td>';
818 if (preg_match(
'/\(CREDIT_NOTE\)/', $obj->description))
820 print '<td class="minwidth100">';
821 $facturestatic->id = $obj->fk_facture_source;
822 $facturestatic->ref = $obj->invoice_source_ref;
823 $facturestatic->type = $obj->type;
824 print preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $obj->description).
' '.$facturestatic->getNomURl(1);
826 } elseif (preg_match(
'/\(DEPOSIT\)/', $obj->description))
828 print '<td class="minwidth100">';
829 $facturestatic->id = $obj->fk_facture_source;
830 $facturestatic->ref = $obj->invoice_source_ref;
831 $facturestatic->type = $obj->type;
832 print preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"InvoiceDeposit"), $obj->description).
' '.$facturestatic->getNomURl(1);
834 } elseif (preg_match(
'/\(EXCESS RECEIVED\)/', $obj->description))
836 print '<td class="minwidth100">';
837 $facturestatic->id = $obj->fk_facture_source;
838 $facturestatic->ref = $obj->invoice_source_ref;
839 $facturestatic->type = $obj->type;
840 print preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"Invoice"), $obj->description).
' '.$facturestatic->getNomURl(1);
843 print '<td class="minwidth100">';
844 print $obj->description;
847 print '<td class="left nowrap">';
850 print '<a href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$obj->invoiceid.
'">'.
img_object($langs->trans(
"ShowBill"),
'bill').
' '.$obj->ref.
'</a>';
853 print '<td class="right">'.price($obj->amount_ht).
'</td>';
854 if (!empty($conf->multicurrency->enabled))
856 print '<td class="right">'.price($obj->multicurrency_amount_ht).
'</td>';
858 print '<td class="right">'.vatrate($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''),
true).
'</td>';
859 print '<td class="right">'.price($obj->amount_ttc).
'</td>';
860 if (!empty($conf->multicurrency->enabled))
862 print '<td class="right">'.price($obj->multicurrency_amount_ttc).
'</td>';
864 print '<td class="center">';
865 print '<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$obj->user_id.
'">'.
img_object($langs->trans(
"ShowUser"),
'user').
' '.$obj->login.
'</a>';
867 print '<td> </td>';
873 if (!empty($conf->multicurrency->enabled)) $colspan += 2;
874 print '<tr><td colspan="'.$colspan.
'" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
887 print '<div class="fichehalfright fichehalfright-lg">';
888 print '<div class="ficheaddleft">';
893 $sql =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
894 $sql .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
895 $sql .=
" rc.datec as dc, rc.description, rc.fk_invoice_supplier_line, rc.fk_invoice_supplier,";
896 $sql .=
" rc.fk_invoice_supplier_source,";
897 $sql .=
" u.login, u.rowid as user_id,";
898 $sql .=
" f.rowid as invoiceid, f.ref as ref,";
899 $sql .=
" fa.ref as invoice_source_ref, fa.type as type";
900 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
901 $sql .=
" , ".MAIN_DB_PREFIX.
"user as u";
902 $sql .=
" , ".MAIN_DB_PREFIX.
"facture_fourn_det as fc";
903 $sql .=
" , ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
904 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
905 $sql .=
" WHERE rc.fk_soc =".$object->id;
906 $sql .=
" AND rc.fk_invoice_supplier_line = fc.rowid";
907 $sql .=
" AND fc.fk_facture_fourn = f.rowid";
908 $sql .=
" AND rc.fk_user = u.rowid";
909 $sql .=
" AND rc.discount_type = 1";
910 $sql .=
" ORDER BY dc DESC";
913 $sql2 =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
914 $sql2 .=
" rc.datec as dc, rc.description, rc.fk_invoice_supplier_line, rc.fk_invoice_supplier,";
915 $sql2 .=
" rc.fk_invoice_supplier_source,";
916 $sql2 .=
" u.login, u.rowid as user_id,";
917 $sql2 .=
" f.rowid as invoiceid, f.ref as ref,";
918 $sql2 .=
" fa.ref as invoice_source_ref, fa.type as type";
919 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
920 $sql2 .=
" , ".MAIN_DB_PREFIX.
"user as u";
921 $sql2 .=
" , ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
922 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
923 $sql2 .=
" WHERE rc.fk_soc =".$object->id;
924 $sql2 .=
" AND rc.fk_invoice_supplier = f.rowid";
925 $sql2 .=
" AND rc.fk_user = u.rowid";
926 $sql2 .=
" AND rc.discount_type = 1";
927 $sql2 .=
" ORDER BY dc DESC";
929 $resql = $db->query($sql);
931 if (
$resql) $resql2 = $db->query($sql2);
934 print '<div class="div-table-responsive-no-min">';
935 print '<table class="noborder centpercent">';
936 print '<tr class="liste_titre">';
937 print '<td class="widthdate">'.$langs->trans(
"Date").
'</td>';
938 print '<td>'.$langs->trans(
"ReasonDiscount").
'</td>';
939 print '<td class="nowrap">'.$langs->trans(
"ConsumedBy").
'</td>';
940 print '<td class="right">'.$langs->trans(
"AmountHT").
'</td>';
941 if (!empty($conf->multicurrency->enabled))
943 print '<td class="right">'.$langs->trans(
"MulticurrencyAmountHT").
'</td>';
945 print '<td class="right">'.$langs->trans(
"VATRate").
'</td>';
946 print '<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
947 if (!empty($conf->multicurrency->enabled))
949 print '<td class="right">'.$langs->trans(
"MulticurrencyAmountTTC").
'</td>';
951 print '<td width="100" class="center">'.$langs->trans(
"Author").
'</td>';
952 print '<td width="50"> </td>';
955 $tab_sqlobj = array();
956 $tab_sqlobjOrder = array();
957 $num = $db->num_rows(
$resql);
960 for ($i = 0; $i < $num; $i++)
962 $sqlobj = $db->fetch_object(
$resql);
963 $tab_sqlobj[] = $sqlobj;
964 $tab_sqlobjOrder[] = $db->jdate($sqlobj->dc);
969 $num = $db->num_rows($resql2);
970 for ($i = 0; $i < $num; $i++)
972 $sqlobj = $db->fetch_object($resql2);
973 $tab_sqlobj[] = $sqlobj;
974 $tab_sqlobjOrder[] = $db->jdate($sqlobj->dc);
977 array_multisort($tab_sqlobjOrder, SORT_DESC, $tab_sqlobj);
979 $num = count($tab_sqlobj);
985 $obj = array_shift($tab_sqlobj);
986 print '<tr class="oddeven">';
987 print '<td>'.dol_print_date($db->jdate($obj->dc),
'dayhour').
'</td>';
988 if (preg_match(
'/\(CREDIT_NOTE\)/', $obj->description))
990 print '<td class="minwidth100">';
991 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
992 $facturefournstatic->ref = $obj->invoice_source_ref;
993 $facturefournstatic->type = $obj->type;
994 print preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $obj->description).
' '.$facturefournstatic->getNomURl(1);
996 } elseif (preg_match(
'/\(DEPOSIT\)/', $obj->description))
998 print '<td class="minwidth100">';
999 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
1000 $facturefournstatic->ref = $obj->invoice_source_ref;
1001 $facturefournstatic->type = $obj->type;
1002 print preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"InvoiceDeposit"), $obj->description).
' '.$facturefournstatic->getNomURl(1);
1004 } elseif (preg_match(
'/\(EXCESS PAID\)/', $obj->description))
1006 print '<td class="minwidth100">';
1007 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
1008 $facturefournstatic->ref = $obj->invoice_source_ref;
1009 $facturefournstatic->type = $obj->type;
1010 print preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"Invoice"), $obj->description).
' '.$facturefournstatic->getNomURl(1);
1013 print '<td class="minwidth100">';
1014 print $obj->description;
1017 print '<td class="left nowrap">';
1018 if ($obj->invoiceid) {
1019 print '<a href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.$obj->invoiceid.
'">'.
img_object($langs->trans(
"ShowBill"),
'bill').
' '.$obj->ref.
'</a>';
1022 print '<td class="right">'.price($obj->amount_ht).
'</td>';
1023 if (!empty($conf->multicurrency->enabled))
1025 print '<td class="right">'.price($obj->multicurrency_amount_ht).
'</td>';
1027 print '<td class="right">'.vatrate($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''),
true).
'</td>';
1028 print '<td class="right">'.price($obj->amount_ttc).
'</td>';
1029 if (!empty($conf->multicurrency->enabled))
1031 print '<td class="right">'.price($obj->multicurrency_amount_ttc).
'</td>';
1033 print '<td class="center">';
1034 print '<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$obj->user_id.
'">'.
img_object($langs->trans(
"ShowUser"),
'user').
' '.$obj->login.
'</a>';
1036 print '<td> </td>';
1042 if (!empty($conf->multicurrency->enabled)) $colspan += 2;
1043 print '<tr><td colspan="'.$colspan.
'" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage suppliers invoices.
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Class to manage absolute discounts.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage invoices.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
img_split($titlealt= 'default', $other= 'class="pictosplit"')
Show split logo.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.