30if (! defined(
'CSRFCHECK_WITH_TOKEN')) {
31 define(
'CSRFCHECK_WITH_TOKEN',
'1');
35require
'../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
37require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
51$langs->loadLangs(array(
'orders',
'bills',
'companies'));
55$action =
GETPOST(
'action',
'aZ09');
56$backtopage =
GETPOST(
'backtopage',
'alpha');
57$splitamounts =
GETPOST(
'splitamounts',
'array');
62if ($user->socid > 0) {
63 $socid = $user->socid;
67if ($user->socid > 0) {
70$result =
restrictedArea($user,
'societe', $id,
'&societe',
'',
'fk_soc',
'rowid', 0);
72$permissiontocreate = ($user->hasRight(
'societe',
'creer') || $user->hasRight(
'facture',
'creer'));
78if (
GETPOST(
'cancel',
'alpha') && !empty($backtopage)) {
79 header(
"Location: ".$backtopage);
83if ($action ==
'confirm_split_more' && $permissiontocreate) {
87 $res = $discount->fetch($remid);
90 setEventMessages($langs->trans(
"ErrorFailedToLoadDiscount"),
null,
'errors');
92 if (empty($splitamounts)) {
94 setEventMessages($langs->trans(
"TotalOfDiscountMustEqualsOriginal"),
null,
'errors');
98 foreach ($splitamounts as $key => $value) {
99 $totalsplitted += (float) $value;
101 if ($totalsplitted != (
float) $discount->amount_ttc) {
103 setEventMessages($langs->trans(
"TotalOfDiscountMustEqualsOriginal"),
null,
'errors');
110 foreach ($splitamounts as $key => $value) {
111 if ((
float) $value == 0) {
116 $newdiscount->fk_facture_source = $discount->fk_facture_source;
117 $newdiscount->fk_facture = $discount->fk_facture;
118 $newdiscount->fk_facture_line = $discount->fk_facture_line;
119 $newdiscount->fk_invoice_supplier_source = $discount->fk_invoice_supplier_source;
120 $newdiscount->fk_invoice_supplier = $discount->fk_invoice_supplier;
121 $newdiscount->fk_invoice_supplier_line = $discount->fk_invoice_supplier_line;
122 if ($discount->description ==
'(CREDIT_NOTE)' || $discount->description ==
'(DEPOSIT)') {
123 $newdiscount->description = $discount->description;
125 $newdiscount->description = $discount->description.
' (1)';
127 $newdiscount->fk_user = $discount->fk_user;
128 $newdiscount->fk_soc = $discount->fk_soc;
129 $newdiscount->socid = $discount->socid;
130 $newdiscount->discount_type = $discount->discount_type;
131 $newdiscount->datec = $discount->datec;
132 $newdiscount->tva_tx = $discount->tva_tx;
133 $newdiscount->localtax1_tx = $discount->localtax1_tx;
134 $newdiscount->localtax1_type = $discount->localtax1_type;
135 $newdiscount->localtax2_tx = $discount->localtax2_tx;
136 $newdiscount->localtax2_type = $discount->localtax2_type;
137 $newdiscount->vat_src_code = $discount->vat_src_code;
138 $newdiscount->amount_ttc =
price2num($value);
141 $newdiscount->generateFromAmount($newdiscount->amount_ttc, 1, $newdiscount->tva_tx, $newdiscount->localtax1_tx, $newdiscount->localtax2_tx, $newdiscount->localtax1_type, $newdiscount->localtax2_type);
143 $newdiscount->multicurrency_amount_ttc = (float) $value * ($discount->multicurrency_amount_ttc / $discount->amount_ttc);
144 $newdiscount->multicurrency_amount_ht =
price2num($newdiscount->multicurrency_amount_ttc / (1 + $newdiscount->tva_tx / 100),
'MT');
145 $newdiscount->multicurrency_amount_tva =
price2num($newdiscount->multicurrency_amount_ttc - $newdiscount->multicurrency_amount_ht);
147 $newdiscountID = $newdiscount->create($user);
148 if (!$newdiscountID) {
154 $discount->fk_facture_source = 0;
155 $discount->fk_invoice_supplier_source = 0;
156 $res = $discount->delete($user);
159 $query = [
'id' =>
$id,
'backtopage' => $backtopage];
160 header(
"Location: " .
dolBuildUrl($_SERVER[
"PHP_SELF"], $query));
171if ($action ==
'confirm_split' &&
GETPOST(
"confirm",
"alpha") ==
'yes' && $permissiontocreate) {
172 $amount_ttc_1 =
GETPOST(
'amount_ttc_1',
'alpha');
173 $amount_ttc_1 =
price2num($amount_ttc_1);
174 $amount_ttc_2 =
GETPOST(
'amount_ttc_2',
'alpha');
175 $amount_ttc_2 =
price2num($amount_ttc_2);
180 $res = $discount->fetch($remid);
183 setEventMessages($langs->trans(
"ErrorFailedToLoadDiscount"),
null,
'errors');
185 if (!$error &&
price2num((
float) $amount_ttc_1 + (
float) $amount_ttc_2,
'MT') != $discount->amount_ttc) {
187 setEventMessages($langs->trans(
"TotalOfTwoDiscountMustEqualsOriginal"),
null,
'errors');
189 if (!$error && $discount->fk_facture_line) {
191 setEventMessages($langs->trans(
"ErrorCantSplitAUsedDiscount"),
null,
'errors');
195 $newDiscounts = $discount->splitAmount((
float) $amount_ttc_1, (
float) $amount_ttc_2);
196 $newdiscount1 = $newDiscounts[0];
197 $newdiscount2 = $newDiscounts[1];
201 $discount->fk_facture_source = 0;
203 $discount->fk_invoice_supplier_source = 0;
204 $res = $discount->delete($user);
205 $newid1 = $newdiscount1->create($user);
206 $newid2 = $newdiscount2->create($user);
207 if ($res > 0 && $newid1 > 0 && $newid2 > 0) {
209 $query = [
'id' =>
$id,
'backtopage' => $backtopage];
210 header(
"Location: " .
dolBuildUrl($_SERVER[
"PHP_SELF"], $query));
218if ($action ==
'setremise' && $permissiontocreate) {
220 $desc =
GETPOST(
'desc',
'alpha');
221 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
222 $discount_type = GETPOSTISSET(
'discount_type') ?
GETPOST(
'discount_type',
'alpha') : 0;
223 $price_base_type =
GETPOST(
'price_base_type',
'alpha');
228 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReasonDiscount")),
null,
'errors');
235 $discountid = $soc->set_remise_except((
float) $amount, $user, $desc, $tva_tx, $discount_type, $price_base_type);
237 if ($discountid > 0) {
238 if (!empty($backtopage)) {
239 header(
"Location: ".$backtopage.
'&discountid='.((
int) $discountid));
242 header(
"Location: remx.php?id=".((
int) $id));
251 setEventMessages($langs->trans(
"ErrorFieldFormat", $langs->transnoentitiesnoconv(
"AmountHT")),
null,
'errors');
255if (
GETPOST(
'action',
'aZ09') ==
'confirm_remove' &&
GETPOST(
"confirm") ==
'yes' && $permissiontocreate) {
259 $result = $discount->fetch(
GETPOSTINT(
"remid"));
260 $result = $discount->delete($user);
263 header(
"Location: " .
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
281llxHeader(
'', $langs->trans(
"GlobalDiscount"));
289 $isSupplier =
$object->fournisseur == 1;
295 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'">';
296 print
'<input type="hidden" name="token" value="'.newToken().
'">';
297 print
'<input type="hidden" name="action" value="setremise">';
298 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
300 print
dol_get_fiche_head($head,
'absolutediscount', $langs->trans(
"ThirdParty"), -1,
'company');
302 $linkback =
'<a href="'.DOL_URL_ROOT.
'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
304 dol_banner_tab(
$object,
'socid', $linkback, ($user->socid ? 0 : 1),
'rowid',
'nom');
306 print
'<div class="fichecenter">';
308 print
'<div class="underbanner clearboth"></div>';
310 if (!$isCustomer && !$isSupplier) {
311 print
'<p class="opacitymedium">'.$langs->trans(
'ThirdpartyIsNeitherCustomerNorClientSoCannotHaveDiscounts').
'</p>';
323 print
'<div class="div-table-responsive-no-min">';
324 print
'<table class="border centpercent tableforfield borderbottom">';
327 $remise_all = $remise_user = 0;
328 $sql =
"SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
329 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
330 $sql .=
" WHERE rc.fk_soc = ".((int)
$object->id);
331 $sql .=
" AND rc.entity = ".((int)
$conf->entity);
332 $sql .=
" AND discount_type = 0";
333 $sql .=
" AND (fk_facture_line IS NULL AND fk_facture IS NULL)";
334 $sql .=
" GROUP BY rc.fk_user";
335 $resql =
$db->query($sql);
337 while ($obj =
$db->fetch_object($resql)) {
338 $remise_all += (!empty($obj->amount) ? $obj->amount : 0);
339 if (!empty($obj->fk_user) && $obj->fk_user == $user->id) {
340 $remise_user += (!empty($obj->amount) ? $obj->amount : 0);
347 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
"CustomerAbsoluteDiscountAllUsers").
'</td>';
348 print
'<td class="amount">'.price($remise_all, 1, $langs, 1, -1, -1,
$conf->currency).
' '.$langs->trans(
"HT");
349 if (empty($user->fk_soc)) {
350 print $form->textwithpicto(
'', $langs->trans(
"CustomerAbsoluteDiscountMy").
': '.
price($remise_user, 1, $langs, 1, -1, -1,
$conf->currency).
' '.$langs->trans(
"HT"));
357 $remise_all = $remise_user = 0;
358 $sql =
"SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
359 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
360 $sql .=
" WHERE rc.fk_soc = ".((int)
$object->id);
361 $sql .=
" AND rc.entity = ".((int)
$conf->entity);
362 $sql .=
" AND discount_type = 1";
363 $sql .=
" AND (fk_invoice_supplier_line IS NULL AND fk_invoice_supplier IS NULL)";
364 $sql .=
" GROUP BY rc.fk_user";
365 $resql =
$db->query($sql);
367 while ($obj =
$db->fetch_object($resql)) {
368 $remise_all += (!empty($obj->amount) ? $obj->amount : 0);
369 if (!empty($obj->fk_user) && $obj->fk_user == $user->id) {
370 $remise_user += (!empty($obj->amount) ? $obj->amount : 0);
377 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
"SupplierAbsoluteDiscountAllUsers").
'</td>';
378 print
'<td class="amount">'.price($remise_all, 1, $langs, 1, -1, -1,
$conf->currency).
' '.$langs->trans(
"HT");
379 if (empty($user->fk_soc)) {
380 print $form->textwithpicto(
'', $langs->trans(
"SupplierAbsoluteDiscountMy").
' : '.
price($remise_user, 1, $langs, 1, -1, -1,
$conf->currency).
' '.$langs->trans(
"HT"));
393 if ($action ==
'create_remise') {
394 if ($user->hasRight(
'societe',
'creer')) {
397 $discount_type = GETPOSTISSET(
'discount_type') ?
GETPOST(
'discount_type',
'alpha') : 0;
398 if ($isCustomer && $isSupplier) {
399 $discounttypelabel = $discount_type == 1 ?
'NewSupplierGlobalDiscount' :
'NewClientGlobalDiscount';
401 $discounttypelabel =
'NewGlobalDiscount';
406 if ($isSupplier && $discount_type == 1) {
407 print
'<input type="hidden" name="discount_type" value="1" />';
409 print
'<input type="hidden" name="discount_type" value="0" />';
415 print
'<div class="div-table-responsive-no-min">';
416 print
'<table class="border centpercent">';
425 print
'<tr><td class="titlefield fieldrequired">'.$langs->trans(
"Amount").
'</td>';
426 print
'<td><input type="text" size="5" name="amount" value="'.price2num(
GETPOST(
"amount")).
'" autofocus>';
427 print
'<span class="hideonsmartphone"> '.$langs->trans(
"Currency".
$conf->currency).
'</span></td></tr>';
430 print
'<tr><td class="titlefield">'.$langs->trans(
"PriceBase").
'</td>';
432 print $form->selectPriceBaseType(
GETPOST(
"price_base_type"),
"price_base_type");
436 print
'<tr><td>'.$langs->trans(
"VAT").
'</td>';
438 print $form->load_tva(
'tva_tx', (GETPOSTISSET(
'tva_tx') ?
GETPOST(
'tva_tx',
'alpha') :
getDolGlobalString(
'MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS', 0)),
$mysoc,
$object, 0, 0,
'', false, 1);
440 print
'<tr><td class="fieldrequired" >'.$langs->trans(
"NoteReason").
'</td>';
441 print
'<td><input type="text" class="quatrevingtpercent" name="desc" value="'.GETPOST(
'desc',
'alphanohtml').
'"></td></tr>';
449 if ($user->hasRight(
'societe',
'creer')) {
450 print
'<div class="center">';
451 print
'<input type="submit" class="button" name="submit" value="'.$langs->trans(
"AddGlobalDiscount").
'">';
452 if (!empty($backtopage)) {
453 print
' ';
454 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
466 if ($action ==
'remove') {
467 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&remid='.
GETPOST(
'remid'), $langs->trans(
'RemoveDiscount'), $langs->trans(
'ConfirmRemoveDiscount'),
'confirm_remove',
'', 0, 1);
475 if ($isCustomer && !$isSupplier) {
476 $newcardbutton = dolGetButtonTitle($langs->trans(
"NewGlobalDiscount"),
'',
'fa fa-plus-circle', $_SERVER[
'PHP_SELF'].
'?action=create_remise&id='.
$id.
'&discount_type=0&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?id='.$id).
'&token='.newToken());
477 } elseif (!$isCustomer && $isSupplier) {
478 $newcardbutton = dolGetButtonTitle($langs->trans(
"NewGlobalDiscount"),
'',
'fa fa-plus-circle', $_SERVER[
'PHP_SELF'].
'?action=create_remise&id='.
$id.
'&discount_type=1&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?id='.$id).
'&token='.newToken());
483 print
load_fiche_titre($langs->trans(
"DiscountStillRemaining"), $newcardbutton);
486 $newcardbutton = dolGetButtonTitle($langs->trans(
"NewClientGlobalDiscount"),
'',
'fa fa-plus-circle', $_SERVER[
'PHP_SELF'].
'?action=create_remise&id='.
$id.
'&discount_type=0&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?id='.$id).
'&token='.newToken());
488 print
'<div class="fichecenter">';
489 print
'<div class="fichehalfleft fichehalfleft-lg">';
490 print
load_fiche_titre($langs->trans(
"CustomerDiscounts"), $newcardbutton,
'');
493 $sql =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
494 $sql .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
495 $sql .=
" rc.datec as dc, rc.description,";
496 $sql .=
" rc.fk_facture_source,";
497 $sql .=
" u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
498 $sql .=
" fa.ref as ref, fa.type as type";
499 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u, ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
500 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as fa ON rc.fk_facture_source = fa.rowid";
501 $sql .=
" WHERE rc.fk_soc = ".((int)
$object->id);
502 $sql .=
" AND rc.entity = ".((int)
$conf->entity);
503 $sql .=
" AND u.rowid = rc.fk_user";
504 $sql .=
" AND rc.discount_type = 0";
505 $sql .=
" AND (rc.fk_facture_line IS NULL AND rc.fk_facture IS NULL)";
506 $sql .=
" ORDER BY rc.datec DESC";
508 $resql =
$db->query($sql);
510 print
'<div class="div-table-responsive-no-min">';
511 print
'<table class="noborder centpercent">';
512 print
'<tr class="liste_titre">';
513 print
'<td class="widthdate">'.$langs->trans(
"Date").
'</td>';
514 print
'<td>'.$langs->trans(
"ReasonDiscount").
'</td>';
515 print
'<td class="nowrap">'.$langs->trans(
"ConsumedBy").
'</td>';
516 print
'<td class="right">'.$langs->trans(
"AmountHT").
'</td>';
518 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountHT")).
'">'.$langs->trans(
"MulticurrencyAmountHT").
'</td>';
520 print
'<td class="right">'.$langs->trans(
"VATRate").
'</td>';
521 print
'<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
523 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountTTC")).
'">'.$langs->trans(
"MulticurrencyAmountTTC").
'</td>';
525 print
'<td width="100" class="center">'.$langs->trans(
"DiscountOfferedBy").
'</td>';
526 print
'<td width="50"> </td>';
529 $showconfirminfo = array();
532 $num =
$db->num_rows($resql);
535 $obj =
$db->fetch_object($resql);
537 $tmpuser->id = $obj->user_id;
538 $tmpuser->login = $obj->login;
539 $tmpuser->firstname = $obj->firstname;
540 $tmpuser->lastname = $obj->lastname;
541 $tmpuser->photo = $obj->photo;
542 $tmpuser->status = $obj->status;
544 print
'<tr class="oddeven">';
546 print
'<td>'.dol_print_date(
$db->jdate($obj->dc),
'dayhour',
'tzuserrel').
'</td>';
548 if (preg_match(
'/\(CREDIT_NOTE\)/', $obj->description)) {
549 print
'<td class="tdoverflowmax100">';
550 $facturestatic->id = $obj->fk_facture_source;
551 $facturestatic->ref = $obj->ref;
552 $facturestatic->type = $obj->type;
553 print preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $obj->description).
'<br>'.$facturestatic->getNomURl(1);
555 } elseif (preg_match(
'/\(DEPOSIT\)/', $obj->description)) {
556 print
'<td class="tdoverflowmax100">';
557 $facturestatic->id = $obj->fk_facture_source;
558 $facturestatic->ref = $obj->ref;
559 $facturestatic->type = $obj->type;
560 print preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"InvoiceDeposit"), $obj->description).
'<br>'.$facturestatic->getNomURl(1);
562 } elseif (preg_match(
'/\(EXCESS RECEIVED\)/', $obj->description)) {
563 print
'<td class="tdoverflowmax100">';
564 $facturestatic->id = $obj->fk_facture_source;
565 $facturestatic->ref = $obj->ref;
566 $facturestatic->type = $obj->type;
567 print preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"ExcessReceived"), $obj->description).
'<br>'.$facturestatic->getNomURl(1);
570 print
'<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).
'">';
575 print
'<td class="nowrap"><span class="opacitymedium">'.$langs->trans(
"NotConsumed").
'</span></td>';
577 print
'<td class="right nowraponall amount">'.price($obj->amount_ht).
'</td>';
580 print
'<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).
'</td>';
582 print
'<td class="right nowraponall">'.vatrate($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''), true).
'</td>';
583 print
'<td class="right nowraponall amount">'.price($obj->amount_ttc).
'</td>';
585 print
'<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ttc).
'</td>';
587 print
'<td class="tdoverflowmax100">';
589 print $tmpuser->getNomUrl(-1);
592 if ($user->hasRight(
'societe',
'creer') || $user->hasRight(
'facture',
'creer')) {
593 print
'<td class="center nowraponall">';
594 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>';
595 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>';
598 print
'<td> </td>';
602 if ($action ==
'split' &&
GETPOST(
'remid') == $obj->rowid) {
603 $showconfirminfo[
'rowid'] = $obj->rowid;
604 $showconfirminfo[
'amount_ttc'] = $obj->amount_ttc;
613 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
619 if (count($showconfirminfo)) {
621 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&remid='.$showconfirminfo[
'rowid'].
'" id="formsplit" data-totaltosplit="'.$showconfirminfo[
'amount_ttc'].
'" data-remaintosplit="0">';
624 print
'<input type="hidden" name="action" value="confirm_split_more">';
625 print
'<input type="hidden" name="token" value="'.newToken().
'">';
627 print
'<div class="div-table-responsive-no-min">';
628 print
'<table class="valid centpercent">';
632 print
'<tr class="validtitre">';
633 print
'<td class="validtitre" colspan="4">'.img_picto(
'',
'split',
'', 0, 0, 0,
'',
'paddingright').
' '.$langs->trans(
'SplitDiscountTitle').
'</td>';
636 print
'<tr class="valid">';
637 print
'<td class="" colspan="4">'.$langs->trans(
'TypeAmountOfEachNewDiscountSplit').
'</td>';
641 if (empty($splitamounts)) {
642 $amount1 =
price2num($showconfirminfo[
'amount_ttc'] / 2,
'MT');
643 $amount2 = ($showconfirminfo[
'amount_ttc'] - (float) $amount1);
644 $remaintosplit = (float) $showconfirminfo[
'amount_ttc'] - ((
float) $amount1 + (float) $amount2);
646 print
'<tr class="valid splitline" id="splitline-1">';
647 print
'<td class="right bold">'.$langs->trans(
'AmountTTC').
' 1:</td>';
648 print
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts[1]" value="'.$amount1.
'"></td>';
649 print
'<td class="right delsplitline"></td>';
650 print
'<td class="right"></td>';
653 print
'<tr class="valid splitline" id="splitline-2">';
654 print
'<td class="right bold">'.$langs->trans(
'AmountTTC').
' 2:</td>';
655 print
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts[2]" value="'.$amount2.
'"></td>';
656 print
'<td class="right delsplitline"></td>';
657 print
'<td class="right"></td>';
660 $nbSplitLines = count($splitamounts);
661 $remaintosplit = $showconfirminfo[
'amount_ttc'];
662 foreach ($splitamounts as $numero => $value) {
663 $remaintosplit -= (float) $value;
664 print
'<tr class="valid splitline" id="splitline-'.$numero.
'">';
665 print
'<td class="right bold">'.$langs->trans(
'AmountTTC').
' '.$numero.
':</td>';
666 print
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts['.$numero.
']" value="'.$splitamounts[$numero].
'"></td>';
667 print
'<td class="right delsplitline"></td>';
668 print
'<td class="right"></td>';
673 print
'<tr class="valid">';
674 print
'<td class="right"></td>';
675 print
'<td class="right"><span class="fas fa-plus-circle" id="splitaddline" style="cursor:pointer;"></span></td>';
676 print
'<td class="right"></td>';
679 print
'<tr class="valid">';
680 print
'<td colspan="3"> </td>';
684 print
'<tr class="valid">';
685 print
'<td class="right bold">'.$langs->trans(
'RemainToSplit').
':</td>';
686 print
'<td class="right"><span id="remaintosplit">'.price($remaintosplit).
'</span> '.
$conf->currency.
'</td>';
687 print
'<td class="right"></td>';
690 print
'<tr class="valid">';
691 print
'<td class="right bold"></td>';
692 print
'<td class="right"><input type="submit" class="button valignmiddle confirmvalidatebutton small nomarginright"></td>';
693 print
'<td class="right"></td>';
702 <script nonce=
"<?php print getNonce(); ?>" type=
"text/javascript">
703 $(document).ready(
function () {
705 let formsplit = $(
'#formsplit');
706 let totaltosplit = formsplit.data(
'totaltosplit');
708 function calcRemainToPay(){
709 let items = formsplit.find(
'.splitinput');
710 let remaintosplit = totaltosplit;
712 items.each(
function(e){
713 var itemvalue = parseFloat($(
this).val().replace(
',',
'.'));
714 if (isNaN(itemvalue)) {
717 remaintosplit -= itemvalue;
720 let remaintosplitval = remaintosplit.toFixed(2);
721 console.log(remaintosplitval);
722 formsplit.data(
'remaintosplit', remaintosplitval);
723 formsplit.find(
'#remaintosplit').html(remaintosplitval.replace(
'.',
','));
724 formsplit.find(
'input[type=submit]').prop(
'disabled',
true);
725 if (remaintosplit == 0) {
726 formsplit.find(
'input[type=submit]').prop(
'disabled',
false);
731 $(document).on(
'click',
'#splitaddline',
function(){
732 let splitlines = formsplit.find(
'.splitline');
733 let numlines = splitlines.length;
734 let nextNum = numlines + 1;
735 let newInputValue = formsplit.data(
'remaintosplit');
736 $(
'#splitline-'+numlines).find(
'.delsplitline').html(
'');
737 var splitTemplate =
'<tr class="splitline" id="splitline-'+ nextNum +
'">';
738 splitTemplate +=
'<td class="right bold"><?php echo $langs->trans('AmountTTC
'); ?> '+ nextNum +
':</td>';
739 splitTemplate +=
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts['+ nextNum +
']" value="'+ parseFloat(newInputValue) +
'"></td>';
740 splitTemplate +=
'<td class="right delsplitline"><span class="fas fa-trash icon-delsplitline" data-splitline="'+ nextNum +
'" style="cursor:pointer;"></span></td>';
741 splitTemplate +=
'<td class="right"></td>';
742 splitTemplate +=
'</tr>';
743 $(
'#splitline-'+numlines).after(splitTemplate);
748 $(document).on(
'change',
'.splitinput',
function(){
753 $(document).on(
'click',
'.icon-delsplitline',
function(){
754 let num = parseInt($(
this).data(
'splitline'));
755 let numBefore = num - 1;
757 $(
'#splitline-'+numBefore).find(
'.delsplitline').html(
'<span class="fas fa-trash icon-delsplitline" data-splitline="'+ numBefore +
'"></span>');
759 $(
'#splitline-'+num).remove();
766 $amount1 =
price2num($showconfirminfo[
'amount_ttc'] / 2,
'MT');
767 $amount2 = ($showconfirminfo[
'amount_ttc'] - (float) $amount1);
768 $formquestion = array(
769 'text' => $langs->trans(
'TypeAmountOfEachNewDiscount'),
770 0 => array(
'type' =>
'text',
'name' =>
'amount_ttc_1',
'label' => $langs->trans(
"AmountTTC").
' 1',
'value' => $amount1,
'size' =>
'5'),
771 1 => array(
'type' =>
'text',
'name' =>
'amount_ttc_2',
'label' => $langs->trans(
"AmountTTC").
' 2',
'value' => $amount2,
'size' =>
'5')
773 $langs->load(
"dict");
774 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);
784 $newcardbutton = dolGetButtonTitle($langs->trans(
"NewSupplierGlobalDiscount"),
'',
'fa fa-plus-circle', $_SERVER[
'PHP_SELF'].
'?action=create_remise&id='.
$id.
'&discount_type=1&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?id='.$id).
'&token='.newToken());
786 print
'<div class="fichehalfright fichehalfright-lg">';
787 print
load_fiche_titre($langs->trans(
"SupplierDiscounts"), $newcardbutton,
'');
793 $sql =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
794 $sql .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
795 $sql .=
" rc.datec as dc, rc.description,";
796 $sql .=
" rc.fk_invoice_supplier_source,";
797 $sql .=
" u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
798 $sql .=
" fa.ref, fa.type as type";
799 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u, ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
800 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
801 $sql .=
" WHERE rc.fk_soc = ".((int)
$object->id);
802 $sql .=
" AND rc.entity = ".((int)
$conf->entity);
803 $sql .=
" AND u.rowid = rc.fk_user";
804 $sql .=
" AND rc.discount_type = 1";
805 $sql .=
" AND (rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_line IS NULL)";
806 $sql .=
" ORDER BY rc.datec DESC";
808 $resql =
$db->query($sql);
810 print
'<div class="div-table-responsive-no-min">';
811 print
'<table class="noborder centpercent">';
812 print
'<tr class="liste_titre">';
813 print
'<td class="widthdate">'.$langs->trans(
"Date").
'</td>';
814 print
'<td>'.$langs->trans(
"ReasonDiscount").
'</td>';
815 print
'<td class="nowrap">'.$langs->trans(
"ConsumedBy").
'</td>';
816 print
'<td class="right">'.$langs->trans(
"AmountHT").
'</td>';
818 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountHT")).
'">'.$langs->trans(
"MulticurrencyAmountHT").
'</td>';
820 print
'<td class="right">'.$langs->trans(
"VATRate").
'</td>';
821 print
'<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
823 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountTTC")).
'">'.$langs->trans(
"MulticurrencyAmountTTC").
'</td>';
825 print
'<td width="100" class="center">'.$langs->trans(
"DiscountOfferedBy").
'</td>';
826 print
'<td width="50"> </td>';
829 $showconfirminfo = array();
832 $num =
$db->num_rows($resql);
835 $obj =
$db->fetch_object($resql);
837 $tmpuser->id = $obj->user_id;
838 $tmpuser->login = $obj->login;
839 $tmpuser->firstname = $obj->firstname;
840 $tmpuser->lastname = $obj->lastname;
841 $tmpuser->photo = $obj->photo;
842 $tmpuser->status = $obj->status;
844 print
'<tr class="oddeven">';
845 print
'<td>'.dol_print_date(
$db->jdate($obj->dc),
'dayhour',
'tzuserrel').
'</td>';
846 if (preg_match(
'/\(CREDIT_NOTE\)/', $obj->description)) {
847 print
'<td class="tdoverflowmax100">';
848 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
849 $facturefournstatic->ref = $obj->ref;
850 $facturefournstatic->type = $obj->type;
851 print preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $obj->description).
'<br>'.$facturefournstatic->getNomURl(1);
853 } elseif (preg_match(
'/\(DEPOSIT\)/', $obj->description)) {
854 print
'<td class="tdoverflowmax100">';
855 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
856 $facturefournstatic->ref = $obj->ref;
857 $facturefournstatic->type = $obj->type;
858 print preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"InvoiceDeposit"), $obj->description).
'<br>'.$facturefournstatic->getNomURl(1);
860 } elseif (preg_match(
'/\(EXCESS PAID\)/', $obj->description)) {
861 print
'<td class="tdoverflowmax100">';
862 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
863 $facturefournstatic->ref = $obj->ref;
864 $facturefournstatic->type = $obj->type;
865 print preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"ExcessPaid"), $obj->description).
'<br>'.$facturefournstatic->getNomURl(1);
868 print
'<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).
'">';
872 print
'<td class="nowrap"><span class="opacitymedium">'.$langs->trans(
"NotConsumed").
'</span></td>';
873 print
'<td class="right nowraponall amount">'.price($obj->amount_ht).
'</td>';
875 print
'<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).
'</td>';
877 print
'<td class="right">'.vatrate($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''), true).
'</td>';
878 print
'<td class="right nowraponall amount">'.price($obj->amount_ttc).
'</td>';
880 print
'<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ttc).
'</td>';
882 print
'<td class="tdoverflowmax100">';
883 print $tmpuser->getNomUrl(-1);
886 if ($user->hasRight(
'societe',
'creer') || $user->hasRight(
'facture',
'creer')) {
887 print
'<td class="center nowraponall">';
888 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>';
889 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>';
892 print
'<td> </td>';
896 if ($action ==
'split' &&
GETPOST(
'remid') == $obj->rowid) {
897 $showconfirminfo[
'rowid'] = $obj->rowid;
898 $showconfirminfo[
'amount_ttc'] = $obj->amount_ttc;
907 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
913 if (count($showconfirminfo)) {
915 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&remid='.$showconfirminfo[
'rowid'].
'" id="formsplit" data-totaltosplit="'.$showconfirminfo[
'amount_ttc'].
'" data-remaintosplit="0">';
918 print
'<input type="hidden" name="action" value="confirm_split_more">';
919 print
'<input type="hidden" name="token" value="'.newToken().
'">';
921 print
'<div class="div-table-responsive-no-min">';
922 print
'<table class="valid centpercent">';
926 print
'<tr class="validtitre">';
927 print
'<td class="validtitre" colspan="4">'.img_picto(
'',
'split',
'', 0, 0, 0,
'',
'paddingright').
' '.$langs->trans(
'SplitDiscountTitle').
'</td>';
930 print
'<tr class="valid">';
931 print
'<td class="" colspan="4">'.$langs->trans(
'TypeAmountOfEachNewDiscountSplit').
'</td>';
935 if (empty($splitamounts)) {
936 $amount1 =
price2num($showconfirminfo[
'amount_ttc'] / 2,
'MT');
937 $amount2 = ($showconfirminfo[
'amount_ttc'] - (float) $amount1);
938 $remaintosplit = (float) $showconfirminfo[
'amount_ttc'] - ((
float) $amount1 + (float) $amount2);
940 print
'<tr class="valid splitline" id="splitline-1">';
941 print
'<td class="right bold">'.$langs->trans(
'AmountTTC').
' 1:</td>';
942 print
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts[1]" value="'.$amount1.
'"></td>';
943 print
'<td class="right delsplitline"></td>';
944 print
'<td class="right"></td>';
947 print
'<tr class="valid splitline" id="splitline-2">';
948 print
'<td class="right bold">'.$langs->trans(
'AmountTTC').
' 2:</td>';
949 print
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts[2]" value="'.$amount2.
'"></td>';
950 print
'<td class="right delsplitline"></td>';
951 print
'<td class="right"></td>';
954 $nbSplitLines = count($splitamounts);
955 $remaintosplit = $showconfirminfo[
'amount_ttc'];
956 foreach ($splitamounts as $numero => $value) {
957 $remaintosplit -= (float) $value;
958 print
'<tr class="valid splitline" id="splitline-'.$numero.
'">';
959 print
'<td class="right bold">'.$langs->trans(
'AmountTTC').
' '.$numero.
':</td>';
960 print
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts['.$numero.
']" value="'.$splitamounts[$numero].
'"></td>';
961 print
'<td class="right delsplitline"></td>';
962 print
'<td class="right"></td>';
967 print
'<tr class="valid">';
968 print
'<td class="right"></td>';
969 print
'<td class="right"><span class="fas fa-plus-circle" id="splitaddline" style="cursor:pointer;"></span></td>';
970 print
'<td class="right"></td>';
973 print
'<tr class="valid">';
974 print
'<td colspan="3"> </td>';
978 print
'<tr class="valid">';
979 print
'<td class="right bold">'.$langs->trans(
'RemainToSplit').
':</td>';
980 print
'<td class="right"><span id="remaintosplit">'.price($remaintosplit).
'</span> '.
$conf->currency.
'</td>';
981 print
'<td class="right"></td>';
984 print
'<tr class="valid">';
985 print
'<td class="right bold"></td>';
986 print
'<td class="right"><input type="submit" class="button valignmiddle confirmvalidatebutton small nomarginright"></td>';
987 print
'<td class="right"></td>';
996 <script nonce=
"<?php print getNonce(); ?>" type=
"text/javascript">
997 $(document).ready(
function () {
999 let formsplit = $(
'#formsplit');
1000 let totaltosplit = formsplit.data(
'totaltosplit');
1002 function calcRemainToPay(){
1003 let items = formsplit.find(
'.splitinput');
1004 let remaintosplit = totaltosplit;
1006 items.each(
function(e){
1007 var itemvalue = parseFloat($(
this).val().replace(
',',
'.'));
1008 if (isNaN(itemvalue)) {
1011 remaintosplit -= itemvalue;
1014 let remaintosplitval = remaintosplit.toFixed(2);
1015 console.log(remaintosplitval);
1016 formsplit.data(
'remaintosplit', remaintosplitval);
1017 formsplit.find(
'#remaintosplit').html(remaintosplitval.replace(
'.',
','));
1018 formsplit.find(
'input[type=submit]').prop(
'disabled',
true);
1019 if (remaintosplit == 0) {
1020 formsplit.find(
'input[type=submit]').prop(
'disabled',
false);
1025 $(document).on(
'click',
'#splitaddline',
function(){
1026 let splitlines = formsplit.find(
'.splitline');
1027 let numlines = splitlines.length;
1028 let nextNum = numlines + 1;
1029 let newInputValue = formsplit.data(
'remaintosplit');
1030 $(
'#splitline-'+numlines).find(
'.delsplitline').html(
'');
1031 var splitTemplate =
'<tr class="splitline" id="splitline-'+ nextNum +
'">';
1032 splitTemplate +=
'<td class="right bold"><?php echo $langs->trans('AmountTTC
'); ?> '+ nextNum +
':</td>';
1033 splitTemplate +=
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts['+ nextNum +
']" value="'+ parseFloat(newInputValue) +
'"></td>';
1034 splitTemplate +=
'<td class="right delsplitline"><span class="fas fa-trash icon-delsplitline" data-splitline="'+ nextNum +
'" style="cursor:pointer;"></span></td>';
1035 splitTemplate +=
'<td class="right"></td>';
1036 splitTemplate +=
'</tr>';
1037 $(
'#splitline-'+numlines).after(splitTemplate);
1042 $(document).on(
'change',
'.splitinput',
function(){
1047 $(document).on(
'click',
'.icon-delsplitline',
function(){
1048 let num = parseInt($(
this).data(
'splitline'));
1049 let numBefore = num - 1;
1050 if (numBefore > 2) {
1051 $(
'#splitline-'+numBefore).find(
'.delsplitline').html(
'<span class="fas fa-trash icon-delsplitline" data-splitline="'+ numBefore +
'"></span>');
1053 $(
'#splitline-'+num).remove();
1060 $amount1 =
price2num($showconfirminfo[
'amount_ttc'] / 2,
'MT');
1061 $amount2 = ($showconfirminfo[
'amount_ttc'] - (float) $amount1);
1062 $formquestion = array(
1063 'text' => $langs->trans(
'TypeAmountOfEachNewDiscount'),
1064 0 => array(
'type' =>
'text',
'name' =>
'amount_ttc_1',
'label' => $langs->trans(
"AmountTTC").
' 1',
'value' => $amount1,
'size' =>
'5'),
1065 1 => array(
'type' =>
'text',
'name' =>
'amount_ttc_2',
'label' => $langs->trans(
"AmountTTC").
' 2',
'value' => $amount2,
'size' =>
'5')
1067 $langs->load(
"dict");
1068 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);
1081 print
'<div class="clearboth"></div><br><br>';
1091 print
'<div class="fichecenter">';
1092 print
'<div class="fichehalfleft fichehalfleft-lg">';
1097 $sql =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
1098 $sql .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
1099 $sql .=
" rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture_source,";
1100 $sql .=
" u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
1101 $sql .=
" f.rowid as invoiceid, f.ref,";
1102 $sql .=
" fa.ref as invoice_source_ref, fa.type as type";
1103 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
1104 $sql .=
" , ".MAIN_DB_PREFIX.
"user as u";
1105 $sql .=
" , ".MAIN_DB_PREFIX.
"facturedet as fc";
1106 $sql .=
" , ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
1107 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as fa ON rc.fk_facture_source = fa.rowid";
1108 $sql .=
" WHERE rc.fk_soc = ".((int)
$object->id);
1109 $sql .=
" AND rc.fk_facture_line = fc.rowid";
1110 $sql .=
" AND fc.fk_facture = f.rowid";
1111 $sql .=
" AND rc.fk_user = u.rowid";
1112 $sql .=
" AND rc.discount_type = 0";
1113 $sql .=
" ORDER BY dc DESC";
1116 $sql2 =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
1117 $sql2 .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
1118 $sql2 .=
" rc.datec as dc, rc.description, rc.fk_facture, rc.fk_facture_source,";
1119 $sql2 .=
" u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
1120 $sql2 .=
" f.rowid as invoiceid, f.ref,";
1121 $sql2 .=
" fa.ref as invoice_source_ref, fa.type as type";
1122 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
1123 $sql2 .=
" , ".MAIN_DB_PREFIX.
"user as u";
1124 $sql2 .=
" , ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
1125 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as fa ON rc.fk_facture_source = fa.rowid";
1126 $sql2 .=
" WHERE rc.fk_soc = ".((int)
$object->id);
1127 $sql2 .=
" AND rc.fk_facture = f.rowid";
1128 $sql2 .=
" AND rc.fk_user = u.rowid";
1129 $sql2 .=
" AND rc.discount_type = 0";
1130 $sql2 .=
" ORDER BY dc DESC";
1132 $resql =
$db->query($sql);
1135 $resql2 =
$db->query($sql2);
1138 print
'<div class="div-table-responsive-no-min">';
1139 print
'<table class="noborder centpercent">';
1140 print
'<tr class="liste_titre">';
1141 print
'<td class="widthdate">'.$langs->trans(
"Date").
'</td>';
1142 print
'<td>'.$langs->trans(
"ReasonDiscount").
'</td>';
1143 print
'<td class="nowrap">'.$langs->trans(
"ConsumedBy").
'</td>';
1144 print
'<td class="right">'.$langs->trans(
"AmountHT").
'</td>';
1146 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountHT")).
'">'.$langs->trans(
"MulticurrencyAmountHT").
'</td>';
1148 print
'<td class="right">'.$langs->trans(
"VATRate").
'</td>';
1149 print
'<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
1151 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountTTC")).
'">'.$langs->trans(
"MulticurrencyAmountTTC").
'</td>';
1153 print
'<td width="100" class="center">'.$langs->trans(
"Author").
'</td>';
1154 print
'<td width="50"> </td>';
1157 $tab_sqlobj = array();
1158 $tab_sqlobjOrder = array();
1159 $num =
$db->num_rows($resql);
1161 for ($i = 0; $i < $num; $i++) {
1162 $sqlobj =
$db->fetch_object($resql);
1163 $tab_sqlobj[] = $sqlobj;
1164 $tab_sqlobjOrder[] =
$db->jdate($sqlobj->dc);
1169 $num =
$db->num_rows($resql2);
1170 for ($i = 0; $i < $num; $i++) {
1171 $sqlobj =
$db->fetch_object($resql2);
1172 $tab_sqlobj[] = $sqlobj;
1173 $tab_sqlobjOrder[] =
$db->jdate($sqlobj->dc);
1176 $array1_sort_order = SORT_DESC;
1177 array_multisort($tab_sqlobjOrder, $array1_sort_order, $tab_sqlobj);
1179 $num = count($tab_sqlobj);
1183 $obj = array_shift($tab_sqlobj);
1185 $tmpuser->id = $obj->user_id;
1186 $tmpuser->login = $obj->login;
1187 $tmpuser->firstname = $obj->firstname;
1188 $tmpuser->lastname = $obj->lastname;
1189 $tmpuser->photo = $obj->photo;
1190 $tmpuser->status = $obj->status;
1192 print
'<tr class="oddeven">';
1193 print
'<td>'.dol_print_date(
$db->jdate($obj->dc),
'dayhour').
'</td>';
1194 if (preg_match(
'/\(CREDIT_NOTE\)/', $obj->description)) {
1195 print
'<td class="tdoverflowmax100">';
1196 $facturestatic->id = $obj->fk_facture_source;
1197 $facturestatic->ref = $obj->invoice_source_ref;
1198 $facturestatic->type = $obj->type;
1199 print preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $obj->description).
'<br>'.$facturestatic->getNomURl(1);
1201 } elseif (preg_match(
'/\(DEPOSIT\)/', $obj->description)) {
1202 print
'<td class="tdoverflowmax100">';
1203 $facturestatic->id = $obj->fk_facture_source;
1204 $facturestatic->ref = $obj->invoice_source_ref;
1205 $facturestatic->type = $obj->type;
1206 print preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"InvoiceDeposit"), $obj->description).
'<br>'.$facturestatic->getNomURl(1);
1208 } elseif (preg_match(
'/\(EXCESS RECEIVED\)/', $obj->description)) {
1209 print
'<td class="tdoverflowmax100">';
1210 $facturestatic->id = $obj->fk_facture_source;
1211 $facturestatic->ref = $obj->invoice_source_ref;
1212 $facturestatic->type = $obj->type;
1213 print preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"Invoice"), $obj->description).
'<br>'.$facturestatic->getNomURl(1);
1216 print
'<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).
'">';
1220 print
'<td class="left nowrap">';
1221 if ($obj->invoiceid) {
1222 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$obj->invoiceid.
'">'.
img_object($langs->trans(
"ShowBill"),
'bill').
' '.$obj->ref.
'</a>';
1225 print
'<td class="right nowraponall amount">'.price($obj->amount_ht).
'</td>';
1227 print
'<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).
'</td>';
1229 print
'<td class="right nowraponall">'.vatrate($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''), true).
'</td>';
1230 print
'<td class="right nowraponall amount">'.price($obj->amount_ttc).
'</td>';
1232 print
'<td class="right">'.price($obj->multicurrency_amount_ttc).
'</td>';
1234 print
'<td class="tdoverflowmax100">';
1235 print $tmpuser->getNomUrl(-1);
1238 print
'<td> </td>';
1247 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
1260 print
'<div class="fichehalfright fichehalfright-lg">';
1265 $sql =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
1266 $sql .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
1267 $sql .=
" rc.datec as dc, rc.description, rc.fk_invoice_supplier_line,";
1268 $sql .=
" rc.fk_invoice_supplier_source,";
1269 $sql .=
" u.login, u.rowid as user_id, u.statut as user_status, u.firstname, u.lastname, u.photo,";
1270 $sql .=
" f.rowid as invoiceid, f.ref as ref,";
1271 $sql .=
" fa.ref as invoice_source_ref, fa.type as type";
1272 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
1273 $sql .=
" , ".MAIN_DB_PREFIX.
"user as u";
1274 $sql .=
" , ".MAIN_DB_PREFIX.
"facture_fourn_det as fc";
1275 $sql .=
" , ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
1276 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
1277 $sql .=
" WHERE rc.fk_soc = ".((int)
$object->id);
1278 $sql .=
" AND rc.fk_invoice_supplier_line = fc.rowid";
1279 $sql .=
" AND fc.fk_facture_fourn = f.rowid";
1280 $sql .=
" AND rc.fk_user = u.rowid";
1281 $sql .=
" AND rc.discount_type = 1";
1282 $sql .=
" ORDER BY dc DESC";
1285 $sql2 =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
1286 $sql2 .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
1287 $sql2 .=
" rc.datec as dc, rc.description, rc.fk_invoice_supplier,";
1288 $sql2 .=
" rc.fk_invoice_supplier_source,";
1289 $sql2 .=
" u.login, u.rowid as user_id, u.statut as user_status, u.firstname, u.lastname, u.photo,";
1290 $sql2 .=
" f.rowid as invoiceid, f.ref as ref,";
1291 $sql2 .=
" fa.ref as invoice_source_ref, fa.type as type";
1292 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
1293 $sql2 .=
" , ".MAIN_DB_PREFIX.
"user as u";
1294 $sql2 .=
" , ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
1295 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
1296 $sql2 .=
" WHERE rc.fk_soc = ".((int)
$object->id);
1297 $sql2 .=
" AND rc.fk_invoice_supplier = f.rowid";
1298 $sql2 .=
" AND rc.fk_user = u.rowid";
1299 $sql2 .=
" AND rc.discount_type = 1";
1300 $sql2 .=
" ORDER BY dc DESC";
1302 $resql =
$db->query($sql);
1305 $resql2 =
$db->query($sql2);
1308 print
'<div class="div-table-responsive-no-min">';
1309 print
'<table class="noborder centpercent">';
1310 print
'<tr class="liste_titre">';
1311 print
'<td class="widthdate">'.$langs->trans(
"Date").
'</td>';
1312 print
'<td>'.$langs->trans(
"ReasonDiscount").
'</td>';
1313 print
'<td class="nowrap">'.$langs->trans(
"ConsumedBy").
'</td>';
1314 print
'<td class="right">'.$langs->trans(
"AmountHT").
'</td>';
1316 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountHT")).
'">'.$langs->trans(
"MulticurrencyAmountHT").
'</td>';
1318 print
'<td class="right">'.$langs->trans(
"VATRate").
'</td>';
1319 print
'<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
1321 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountTTC")).
'">'.$langs->trans(
"MulticurrencyAmountTTC").
'</td>';
1323 print
'<td width="100" class="center">'.$langs->trans(
"Author").
'</td>';
1324 print
'<td width="50"> </td>';
1327 $tab_sqlobj = array();
1328 $tab_sqlobjOrder = array();
1329 $num =
$db->num_rows($resql);
1331 for ($i = 0; $i < $num; $i++) {
1332 $sqlobj =
$db->fetch_object($resql);
1333 $tab_sqlobj[] = $sqlobj;
1334 $tab_sqlobjOrder[] =
$db->jdate($sqlobj->dc);
1339 $num =
$db->num_rows($resql2);
1340 for ($i = 0; $i < $num; $i++) {
1341 $sqlobj =
$db->fetch_object($resql2);
1342 $tab_sqlobj[] = $sqlobj;
1343 $tab_sqlobjOrder[] =
$db->jdate($sqlobj->dc);
1346 $array1_sort_order = SORT_DESC;
1347 array_multisort($tab_sqlobjOrder, $array1_sort_order, $tab_sqlobj);
1349 $num = count($tab_sqlobj);
1353 $obj = array_shift($tab_sqlobj);
1355 $tmpuser->id = $obj->user_id;
1356 $tmpuser->login = $obj->login;
1357 $tmpuser->firstname = $obj->firstname;
1358 $tmpuser->lastname = $obj->lastname;
1359 $tmpuser->photo = $obj->photo;
1360 $tmpuser->status = $obj->status;
1362 print
'<tr class="oddeven">';
1363 print
'<td>'.dol_print_date(
$db->jdate($obj->dc),
'dayhour').
'</td>';
1364 if (preg_match(
'/\(CREDIT_NOTE\)/', $obj->description)) {
1365 print
'<td class="tdoverflowmax100">';
1366 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
1367 $facturefournstatic->ref = $obj->invoice_source_ref;
1368 $facturefournstatic->type = $obj->type;
1369 print preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $obj->description).
'<br>'.$facturefournstatic->getNomURl(1);
1371 } elseif (preg_match(
'/\(DEPOSIT\)/', $obj->description)) {
1372 print
'<td class="tdoverflowmax100">';
1373 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
1374 $facturefournstatic->ref = $obj->invoice_source_ref;
1375 $facturefournstatic->type = $obj->type;
1376 print preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"InvoiceDeposit"), $obj->description).
'<br>'.$facturefournstatic->getNomURl(1);
1378 } elseif (preg_match(
'/\(EXCESS PAID\)/', $obj->description)) {
1379 print
'<td class="tdoverflowmax100">';
1380 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
1381 $facturefournstatic->ref = $obj->invoice_source_ref;
1382 $facturefournstatic->type = $obj->type;
1383 print preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"Invoice"), $obj->description).
'<br>'.$facturefournstatic->getNomURl(1);
1386 print
'<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).
'">';
1390 print
'<td class="left nowrap">';
1391 if ($obj->invoiceid) {
1392 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.$obj->invoiceid.
'">'.
img_object($langs->trans(
"ShowBill"),
'bill').
' '.$obj->ref.
'</a>';
1395 print
'<td class="right nowraponall amount">'.price($obj->amount_ht).
'</td>';
1397 print
'<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).
'</td>';
1399 print
'<td class="right">'.vatrate($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''), true).
'</td>';
1400 print
'<td class="right nowraponall amount">'.price($obj->amount_ttc).
'</td>';
1402 print
'<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ttc).
'</td>';
1404 print
'<td class="tdoverflowmax100">';
1405 print $tmpuser->getNomUrl(-1);
1408 print
'<td> </td>';
1418 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage absolute discounts.
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
societe_prepare_head(Societe $object, $subtabs='')
Return array of tabs to used on pages for third parties cards.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_split($titlealt='default', $other='class="pictosplit"')
Show split logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.