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');
91 } elseif ($discount->fk_soc != $socid) {
94 setEventMessages($langs->trans(
"ErrorRecordNotFound"),
null,
'errors');
96 if (empty($splitamounts)) {
98 setEventMessages($langs->trans(
"TotalOfDiscountMustEqualsOriginal"),
null,
'errors');
102 foreach ($splitamounts as $key => $value) {
103 $totalsplitted += (float) $value;
105 if ($totalsplitted != (
float) $discount->amount_ttc) {
107 setEventMessages($langs->trans(
"TotalOfDiscountMustEqualsOriginal"),
null,
'errors');
114 foreach ($splitamounts as $key => $value) {
115 if ((
float) $value == 0) {
120 $newdiscount->fk_facture_source = $discount->fk_facture_source;
121 $newdiscount->fk_facture = $discount->fk_facture;
122 $newdiscount->fk_facture_line = $discount->fk_facture_line;
123 $newdiscount->fk_invoice_supplier_source = $discount->fk_invoice_supplier_source;
124 $newdiscount->fk_invoice_supplier = $discount->fk_invoice_supplier;
125 $newdiscount->fk_invoice_supplier_line = $discount->fk_invoice_supplier_line;
126 if ($discount->description ==
'(CREDIT_NOTE)' || $discount->description ==
'(DEPOSIT)') {
127 $newdiscount->description = $discount->description;
129 $newdiscount->description = $discount->description.
' (1)';
131 $newdiscount->fk_user = $discount->fk_user;
132 $newdiscount->fk_soc = $discount->fk_soc;
133 $newdiscount->socid = $discount->socid;
134 $newdiscount->discount_type = $discount->discount_type;
135 $newdiscount->datec = $discount->datec;
136 $newdiscount->tva_tx = $discount->tva_tx;
137 $newdiscount->localtax1_tx = $discount->localtax1_tx;
138 $newdiscount->localtax1_type = $discount->localtax1_type;
139 $newdiscount->localtax2_tx = $discount->localtax2_tx;
140 $newdiscount->localtax2_type = $discount->localtax2_type;
141 $newdiscount->vat_src_code = $discount->vat_src_code;
142 $newdiscount->amount_ttc =
price2num($value);
145 $newdiscount->generateFromAmount($newdiscount->amount_ttc, 1, $newdiscount->tva_tx, $newdiscount->localtax1_tx, $newdiscount->localtax2_tx, $newdiscount->localtax1_type, $newdiscount->localtax2_type);
147 $newdiscount->multicurrency_amount_ttc = (float) $value * ($discount->multicurrency_amount_ttc / $discount->amount_ttc);
148 $newdiscount->multicurrency_amount_ht =
price2num($newdiscount->multicurrency_amount_ttc / (1 + $newdiscount->tva_tx / 100),
'MT');
149 $newdiscount->multicurrency_amount_tva =
price2num($newdiscount->multicurrency_amount_ttc - $newdiscount->multicurrency_amount_ht);
151 $newdiscountID = $newdiscount->create($user);
152 if (!$newdiscountID) {
158 $discount->fk_facture_source = 0;
159 $discount->fk_invoice_supplier_source = 0;
160 $res = $discount->delete($user);
163 $query = [
'id' =>
$id,
'backtopage' => $backtopage];
164 header(
"Location: " .
dolBuildUrl($_SERVER[
"PHP_SELF"], $query));
168 setEventMessages($discount->error, $discount->errors,
'errors');
176if ($action ==
'confirm_split' &&
GETPOST(
"confirm",
"alpha") ==
'yes' && $permissiontocreate) {
177 $amount_ttc_1 =
GETPOST(
'amount_ttc_1',
'alpha');
178 $amount_ttc_1 =
price2num($amount_ttc_1);
179 $amount_ttc_2 =
GETPOST(
'amount_ttc_2',
'alpha');
180 $amount_ttc_2 =
price2num($amount_ttc_2);
185 $res = $discount->fetch($remid);
188 setEventMessages($langs->trans(
"ErrorFailedToLoadDiscount"),
null,
'errors');
189 } elseif ($discount->fk_soc != $socid) {
192 setEventMessages($langs->trans(
"ErrorRecordNotFound"),
null,
'errors');
194 if (!$error &&
price2num((
float) $amount_ttc_1 + (
float) $amount_ttc_2,
'MT') != $discount->amount_ttc) {
196 setEventMessages($langs->trans(
"TotalOfTwoDiscountMustEqualsOriginal"),
null,
'errors');
198 if (!$error && $discount->fk_facture_line) {
200 setEventMessages($langs->trans(
"ErrorCantSplitAUsedDiscount"),
null,
'errors');
204 $newDiscounts = $discount->splitAmount((
float) $amount_ttc_1, (
float) $amount_ttc_2);
205 $newdiscount1 = $newDiscounts[0];
206 $newdiscount2 = $newDiscounts[1];
210 $discount->fk_facture_source = 0;
212 $discount->fk_invoice_supplier_source = 0;
213 $res = $discount->delete($user);
214 $newid1 = $newdiscount1->create($user);
215 $newid2 = $newdiscount2->create($user);
216 if ($res > 0 && $newid1 > 0 && $newid2 > 0) {
218 $query = [
'id' =>
$id,
'backtopage' => $backtopage];
219 header(
"Location: " .
dolBuildUrl($_SERVER[
"PHP_SELF"], $query));
224 setEventMessages($discount->error, $discount->errors,
'errors');
225 } elseif ($newid1 <= 0) {
226 setEventMessages($newdiscount1->error, $newdiscount1->errors,
'errors');
228 setEventMessages($newdiscount2->error, $newdiscount2->errors,
'errors');
234if ($action ==
'setremise' && $permissiontocreate) {
236 $desc =
GETPOST(
'desc',
'alpha');
237 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
239 $price_base_type =
GETPOST(
'price_base_type',
'alpha');
244 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReasonDiscount")),
null,
'errors');
251 $discountid = $soc->set_remise_except((
float) $amount, $user, $desc, $tva_tx, $discount_type, $price_base_type);
253 if ($discountid > 0) {
254 if (!empty($backtopage)) {
255 header(
"Location: ".$backtopage.
'&discountid='.((
int) $discountid));
258 header(
"Location: remx.php?id=".((
int) $id));
263 setEventMessages($soc->error, $soc->errors,
'errors');
267 setEventMessages($langs->trans(
"ErrorFieldFormat", $langs->transnoentitiesnoconv(
"AmountHT")),
null,
'errors');
271if (
GETPOST(
'action',
'aZ09') ==
'confirm_remove' &&
GETPOST(
"confirm") ==
'yes' && $permissiontocreate) {
275 $result = $discount->fetch(
GETPOSTINT(
"remid"));
276 if ($result > 0 && $discount->fk_soc == $socid) {
277 $result = $discount->delete($user);
281 setEventMessages($langs->trans(
"ErrorRecordNotFound"),
null,
'errors');
285 header(
"Location: " .
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
288 setEventMessages($discount->error, $discount->errors,
'errors');
298$form =
new Form($db);
299$facturestatic =
new Facture($db);
301$tmpuser =
new User($db);
303llxHeader(
'', $langs->trans(
"GlobalDiscount"));
311 $isSupplier =
$object->fournisseur == 1;
317 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'">';
318 print
'<input type="hidden" name="token" value="'.newToken().
'">';
319 print
'<input type="hidden" name="action" value="setremise">';
320 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
322 print
dol_get_fiche_head($head,
'absolutediscount', $langs->trans(
"ThirdParty"), -1,
'company');
324 $linkback =
'<a href="'.DOL_URL_ROOT.
'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
326 dol_banner_tab(
$object,
'socid', $linkback, ($user->socid ? 0 : 1),
'rowid',
'nom');
328 print
'<div class="fichecenter">';
330 print
'<div class="underbanner clearboth"></div>';
332 if (!$isCustomer && !$isSupplier) {
333 print
'<p class="opacitymedium">'.$langs->trans(
'ThirdpartyIsNeitherCustomerNorClientSoCannotHaveDiscounts').
'</p>';
345 print
'<div class="div-table-responsive-no-min">';
346 print
'<table class="border centpercent tableforfield borderbottom">';
349 $remise_all = $remise_user = 0;
350 $sql =
"SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
351 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
352 $sql .=
" WHERE rc.fk_soc = ".((int)
$object->id);
353 $sql .=
" AND rc.entity = ".((int)
$conf->entity);
354 $sql .=
" AND discount_type = 0";
355 $sql .=
" AND (fk_facture_line IS NULL AND fk_facture IS NULL)";
356 $sql .=
" GROUP BY rc.fk_user";
357 $resql = $db->query($sql);
359 while ($obj = $db->fetch_object($resql)) {
360 $remise_all += (!empty($obj->amount) ? $obj->amount : 0);
361 if (!empty($obj->fk_user) && $obj->fk_user == $user->id) {
362 $remise_user += (!empty($obj->amount) ? $obj->amount : 0);
366 dol_print_error($db);
369 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
"CustomerAbsoluteDiscountAllUsers").
'</td>';
370 print
'<td class="amount">'.price($remise_all, 1, $langs, 1, -1, -1,
$conf->currency).
' '.$langs->trans(
"HT");
371 if (empty($user->fk_soc)) {
372 print $form->textwithpicto(
'', $langs->trans(
"CustomerAbsoluteDiscountMy").
': '.
price($remise_user, 1, $langs, 1, -1, -1,
$conf->currency).
' '.$langs->trans(
"HT"));
379 $remise_all = $remise_user = 0;
380 $sql =
"SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
381 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
382 $sql .=
" WHERE rc.fk_soc = ".((int)
$object->id);
383 $sql .=
" AND rc.entity = ".((int)
$conf->entity);
384 $sql .=
" AND discount_type = 1";
385 $sql .=
" AND (fk_invoice_supplier_line IS NULL AND fk_invoice_supplier IS NULL)";
386 $sql .=
" GROUP BY rc.fk_user";
387 $resql = $db->query($sql);
389 while ($obj = $db->fetch_object($resql)) {
390 $remise_all += (!empty($obj->amount) ? $obj->amount : 0);
391 if (!empty($obj->fk_user) && $obj->fk_user == $user->id) {
392 $remise_user += (!empty($obj->amount) ? $obj->amount : 0);
396 dol_print_error($db);
399 print
'<tr><td class="titlefieldmiddle">'.$langs->trans(
"SupplierAbsoluteDiscountAllUsers").
'</td>';
400 print
'<td class="amount">'.price($remise_all, 1, $langs, 1, -1, -1,
$conf->currency).
' '.$langs->trans(
"HT");
401 if (empty($user->fk_soc)) {
402 print $form->textwithpicto(
'', $langs->trans(
"SupplierAbsoluteDiscountMy").
' : '.
price($remise_user, 1, $langs, 1, -1, -1,
$conf->currency).
' '.$langs->trans(
"HT"));
415 if ($action ==
'create_remise') {
416 if ($user->hasRight(
'societe',
'creer')) {
420 if ($isCustomer && $isSupplier) {
421 $discounttypelabel = $discount_type == 1 ?
'NewSupplierGlobalDiscount' :
'NewClientGlobalDiscount';
423 $discounttypelabel =
'NewGlobalDiscount';
428 if ($isSupplier && $discount_type == 1) {
429 print
'<input type="hidden" name="discount_type" value="1" />';
431 print
'<input type="hidden" name="discount_type" value="0" />';
437 print
'<div class="div-table-responsive-no-min">';
438 print
'<table class="border centpercent">';
447 print
'<tr><td class="titlefield fieldrequired">'.$langs->trans(
"Amount").
'</td>';
448 print
'<td><input type="text" size="5" name="amount" value="'.price2num(
GETPOST(
"amount")).
'" autofocus>';
449 print
'<span class="hideonsmartphone"> '.$langs->trans(
"Currency".
$conf->currency).
'</span></td></tr>';
452 print
'<tr><td class="titlefield">'.$langs->trans(
"PriceBase").
'</td>';
454 print $form->selectPriceBaseType(
GETPOST(
"price_base_type"),
"price_base_type");
458 print
'<tr><td>'.$langs->trans(
"VAT").
'</td>';
460 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);
462 print
'<tr><td class="fieldrequired" >'.$langs->trans(
"NoteReason").
'</td>';
463 print
'<td><input type="text" class="quatrevingtpercent" name="desc" value="'.GETPOST(
'desc',
'alphanohtml').
'"></td></tr>';
471 if ($user->hasRight(
'societe',
'creer')) {
472 print
'<div class="center">';
473 print
'<input type="submit" class="button" name="submit" value="'.$langs->trans(
"AddGlobalDiscount").
'">';
474 if (!empty($backtopage)) {
475 print
' ';
476 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
488 if ($action ==
'remove') {
489 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&remid='.
GETPOST(
'remid'), $langs->trans(
'RemoveDiscount'), $langs->trans(
'ConfirmRemoveDiscount'),
'confirm_remove',
'', 0, 1);
497 if ($isCustomer && !$isSupplier) {
498 $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());
499 } elseif (!$isCustomer && $isSupplier) {
500 $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());
505 print
load_fiche_titre($langs->trans(
"DiscountStillRemaining"), $newcardbutton);
508 $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());
510 print
'<div class="fichecenter">';
511 print
'<div class="fichehalfleft fichehalfleft-lg">';
512 print
load_fiche_titre($langs->trans(
"CustomerDiscounts"), $newcardbutton,
'');
515 $sql =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
516 $sql .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
517 $sql .=
" rc.datec as dc, rc.description,";
518 $sql .=
" rc.fk_facture_source,";
519 $sql .=
" u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
520 $sql .=
" fa.ref as ref, fa.type as type";
521 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u, ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
522 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as fa ON rc.fk_facture_source = fa.rowid";
523 $sql .=
" WHERE rc.fk_soc = ".((int)
$object->id);
524 $sql .=
" AND rc.entity = ".((int)
$conf->entity);
525 $sql .=
" AND u.rowid = rc.fk_user";
526 $sql .=
" AND rc.discount_type = 0";
527 $sql .=
" AND (rc.fk_facture_line IS NULL AND rc.fk_facture IS NULL)";
528 $sql .=
" ORDER BY rc.datec DESC";
530 $resql = $db->query($sql);
532 print
'<div class="div-table-responsive-no-min">';
533 print
'<table class="noborder centpercent">';
534 print
'<tr class="liste_titre">';
535 print
'<td class="widthdate">'.$langs->trans(
"Date").
'</td>';
536 print
'<td>'.$langs->trans(
"ReasonDiscount").
'</td>';
537 print
'<td class="nowrap">'.$langs->trans(
"ConsumedBy").
'</td>';
538 print
'<td class="right">'.$langs->trans(
"AmountHT").
'</td>';
540 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountHT")).
'">'.$langs->trans(
"MulticurrencyAmountHT").
'</td>';
542 print
'<td class="right">'.$langs->trans(
"VATRate").
'</td>';
543 print
'<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
545 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountTTC")).
'">'.$langs->trans(
"MulticurrencyAmountTTC").
'</td>';
547 print
'<td width="100" class="center">'.$langs->trans(
"DiscountOfferedBy").
'</td>';
548 print
'<td width="50"> </td>';
551 $showconfirminfo = array();
554 $num = $db->num_rows($resql);
557 $obj = $db->fetch_object($resql);
559 $tmpuser->id = $obj->user_id;
560 $tmpuser->login = $obj->login;
561 $tmpuser->firstname = $obj->firstname;
562 $tmpuser->lastname = $obj->lastname;
563 $tmpuser->photo = $obj->photo;
564 $tmpuser->status = $obj->status;
566 print
'<tr class="oddeven">';
568 print
'<td>'.dol_print_date($db->jdate($obj->dc),
'dayhour',
'tzuserrel').
'</td>';
570 if (preg_match(
'/\(CREDIT_NOTE\)/', $obj->description)) {
571 print
'<td class="tdoverflowmax100">';
572 $facturestatic->id = $obj->fk_facture_source;
573 $facturestatic->ref = $obj->ref;
574 $facturestatic->type = $obj->type;
575 print preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $obj->description).
'<br>'.$facturestatic->getNomURl(1);
577 } elseif (preg_match(
'/\(DEPOSIT\)/', $obj->description)) {
578 print
'<td class="tdoverflowmax100">';
579 $facturestatic->id = $obj->fk_facture_source;
580 $facturestatic->ref = $obj->ref;
581 $facturestatic->type = $obj->type;
582 print preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"InvoiceDeposit"), $obj->description).
'<br>'.$facturestatic->getNomURl(1);
584 } elseif (preg_match(
'/\(EXCESS RECEIVED\)/', $obj->description)) {
585 print
'<td class="tdoverflowmax100">';
586 $facturestatic->id = $obj->fk_facture_source;
587 $facturestatic->ref = $obj->ref;
588 $facturestatic->type = $obj->type;
589 print preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"ExcessReceived"), $obj->description).
'<br>'.$facturestatic->getNomURl(1);
592 print
'<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).
'">';
597 print
'<td class="nowrap"><span class="opacitymedium">'.$langs->trans(
"NotConsumed").
'</span></td>';
599 print
'<td class="right nowraponall amount">'.price($obj->amount_ht).
'</td>';
602 print
'<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).
'</td>';
604 print
'<td class="right nowraponall">'.vatrate($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''), true).
'</td>';
605 print
'<td class="right nowraponall amount">'.price($obj->amount_ttc).
'</td>';
607 print
'<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ttc).
'</td>';
609 print
'<td class="tdoverflowmax100">';
611 print $tmpuser->getNomUrl(-1);
614 if ($user->hasRight(
'societe',
'creer') || $user->hasRight(
'facture',
'creer')) {
615 print
'<td class="center nowraponall">';
616 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>';
617 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>';
620 print
'<td> </td>';
624 if ($action ==
'split' &&
GETPOST(
'remid') == $obj->rowid) {
625 $showconfirminfo[
'rowid'] = $obj->rowid;
626 $showconfirminfo[
'amount_ttc'] = $obj->amount_ttc;
635 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
641 if (count($showconfirminfo)) {
643 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&remid='.$showconfirminfo[
'rowid'].
'" id="formsplit" data-totaltosplit="'.$showconfirminfo[
'amount_ttc'].
'" data-remaintosplit="0">';
646 print
'<input type="hidden" name="action" value="confirm_split_more">';
647 print
'<input type="hidden" name="token" value="'.newToken().
'">';
649 print
'<div class="div-table-responsive-no-min">';
650 print
'<table class="valid centpercent">';
654 print
'<tr class="validtitre">';
655 print
'<td class="validtitre" colspan="4">'.img_picto(
'',
'split',
'', 0, 0, 0,
'',
'paddingright').
' '.$langs->trans(
'SplitDiscountTitle').
'</td>';
658 print
'<tr class="valid">';
659 print
'<td class="" colspan="4">'.$langs->trans(
'TypeAmountOfEachNewDiscountSplit').
'</td>';
663 if (empty($splitamounts)) {
664 $amount1 =
price2num($showconfirminfo[
'amount_ttc'] / 2,
'MT');
665 $amount2 = ($showconfirminfo[
'amount_ttc'] - (float) $amount1);
666 $remaintosplit = (float) $showconfirminfo[
'amount_ttc'] - ((
float) $amount1 + (float) $amount2);
668 print
'<tr class="valid splitline" id="splitline-1">';
669 print
'<td class="right bold">'.$langs->trans(
'AmountTTC').
' 1:</td>';
670 print
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts[1]" value="'.$amount1.
'"></td>';
671 print
'<td class="right delsplitline"></td>';
672 print
'<td class="right"></td>';
675 print
'<tr class="valid splitline" id="splitline-2">';
676 print
'<td class="right bold">'.$langs->trans(
'AmountTTC').
' 2:</td>';
677 print
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts[2]" value="'.$amount2.
'"></td>';
678 print
'<td class="right delsplitline"></td>';
679 print
'<td class="right"></td>';
682 $nbSplitLines = count($splitamounts);
683 $remaintosplit = $showconfirminfo[
'amount_ttc'];
684 foreach ($splitamounts as $numero => $value) {
685 $remaintosplit -= (float) $value;
686 print
'<tr class="valid splitline" id="splitline-'.$numero.
'">';
687 print
'<td class="right bold">'.$langs->trans(
'AmountTTC').
' '.$numero.
':</td>';
688 print
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts['.$numero.
']" value="'.$splitamounts[$numero].
'"></td>';
689 print
'<td class="right delsplitline"></td>';
690 print
'<td class="right"></td>';
695 print
'<tr class="valid">';
696 print
'<td class="right"></td>';
697 print
'<td class="right"><span class="fas fa-plus-circle" id="splitaddline" style="cursor:pointer;"></span></td>';
698 print
'<td class="right"></td>';
701 print
'<tr class="valid">';
702 print
'<td colspan="3"> </td>';
706 print
'<tr class="valid">';
707 print
'<td class="right bold">'.$langs->trans(
'RemainToSplit').
':</td>';
708 print
'<td class="right"><span id="remaintosplit">'.price($remaintosplit).
'</span> '.
$conf->currency.
'</td>';
709 print
'<td class="right"></td>';
712 print
'<tr class="valid">';
713 print
'<td class="right bold"></td>';
714 print
'<td class="right"><input type="submit" class="button valignmiddle confirmvalidatebutton small nomarginright"></td>';
715 print
'<td class="right"></td>';
724 <script nonce=
"<?php print getNonce(); ?>" type=
"text/javascript">
725 $(document).ready(
function () {
727 let formsplit = $(
'#formsplit');
728 let totaltosplit = formsplit.data(
'totaltosplit');
730 function calcRemainToPay(){
731 let items = formsplit.find(
'.splitinput');
732 let remaintosplit = totaltosplit;
734 items.each(
function(e){
735 var itemvalue = parseFloat($(
this).val().replace(
',',
'.'));
736 if (isNaN(itemvalue)) {
739 remaintosplit -= itemvalue;
742 let remaintosplitval = remaintosplit.toFixed(2);
743 console.log(remaintosplitval);
744 formsplit.data(
'remaintosplit', remaintosplitval);
745 formsplit.find(
'#remaintosplit').html(remaintosplitval.replace(
'.',
','));
746 formsplit.find(
'input[type=submit]').prop(
'disabled',
true);
747 if (remaintosplit == 0) {
748 formsplit.find(
'input[type=submit]').prop(
'disabled',
false);
753 $(document).on(
'click',
'#splitaddline',
function(){
754 let splitlines = formsplit.find(
'.splitline');
755 let numlines = splitlines.length;
756 let nextNum = numlines + 1;
757 let newInputValue = formsplit.data(
'remaintosplit');
758 $(
'#splitline-'+numlines).find(
'.delsplitline').html(
'');
759 var splitTemplate =
'<tr class="splitline" id="splitline-'+ nextNum +
'">';
760 splitTemplate +=
'<td class="right bold"><?php echo $langs->trans('AmountTTC
'); ?> '+ nextNum +
':</td>';
761 splitTemplate +=
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts['+ nextNum +
']" value="'+ parseFloat(newInputValue) +
'"></td>';
762 splitTemplate +=
'<td class="right delsplitline"><span class="fas fa-trash icon-delsplitline" data-splitline="'+ nextNum +
'" style="cursor:pointer;"></span></td>';
763 splitTemplate +=
'<td class="right"></td>';
764 splitTemplate +=
'</tr>';
765 $(
'#splitline-'+numlines).after(splitTemplate);
770 $(document).on(
'change',
'.splitinput',
function(){
775 $(document).on(
'click',
'.icon-delsplitline',
function(){
776 let num = parseInt($(
this).data(
'splitline'));
777 let numBefore = num - 1;
779 $(
'#splitline-'+numBefore).find(
'.delsplitline').html(
'<span class="fas fa-trash icon-delsplitline" data-splitline="'+ numBefore +
'"></span>');
781 $(
'#splitline-'+num).remove();
788 $amount1 =
price2num($showconfirminfo[
'amount_ttc'] / 2,
'MT');
789 $amount2 = ($showconfirminfo[
'amount_ttc'] - (float) $amount1);
790 $formquestion = array(
791 'text' => $langs->trans(
'TypeAmountOfEachNewDiscount'),
792 0 => array(
'type' =>
'text',
'name' =>
'amount_ttc_1',
'label' => $langs->trans(
"AmountTTC").
' 1',
'value' => $amount1,
'size' =>
'5'),
793 1 => array(
'type' =>
'text',
'name' =>
'amount_ttc_2',
'label' => $langs->trans(
"AmountTTC").
' 2',
'value' => $amount2,
'size' =>
'5')
795 $langs->load(
"dict");
796 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);
800 dol_print_error($db);
806 $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());
808 print
'<div class="fichehalfright fichehalfright-lg">';
809 print
load_fiche_titre($langs->trans(
"SupplierDiscounts"), $newcardbutton,
'');
815 $sql =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
816 $sql .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
817 $sql .=
" rc.datec as dc, rc.description,";
818 $sql .=
" rc.fk_invoice_supplier_source,";
819 $sql .=
" u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
820 $sql .=
" fa.ref, fa.type as type";
821 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u, ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
822 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
823 $sql .=
" WHERE rc.fk_soc = ".((int)
$object->id);
824 $sql .=
" AND rc.entity = ".((int)
$conf->entity);
825 $sql .=
" AND u.rowid = rc.fk_user";
826 $sql .=
" AND rc.discount_type = 1";
827 $sql .=
" AND (rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_line IS NULL)";
828 $sql .=
" ORDER BY rc.datec DESC";
830 $resql = $db->query($sql);
832 print
'<div class="div-table-responsive-no-min">';
833 print
'<table class="noborder centpercent">';
834 print
'<tr class="liste_titre">';
835 print
'<td class="widthdate">'.$langs->trans(
"Date").
'</td>';
836 print
'<td>'.$langs->trans(
"ReasonDiscount").
'</td>';
837 print
'<td class="nowrap">'.$langs->trans(
"ConsumedBy").
'</td>';
838 print
'<td class="right">'.$langs->trans(
"AmountHT").
'</td>';
840 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountHT")).
'">'.$langs->trans(
"MulticurrencyAmountHT").
'</td>';
842 print
'<td class="right">'.$langs->trans(
"VATRate").
'</td>';
843 print
'<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
845 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountTTC")).
'">'.$langs->trans(
"MulticurrencyAmountTTC").
'</td>';
847 print
'<td width="100" class="center">'.$langs->trans(
"DiscountOfferedBy").
'</td>';
848 print
'<td width="50"> </td>';
851 $showconfirminfo = array();
854 $num = $db->num_rows($resql);
857 $obj = $db->fetch_object($resql);
859 $tmpuser->id = $obj->user_id;
860 $tmpuser->login = $obj->login;
861 $tmpuser->firstname = $obj->firstname;
862 $tmpuser->lastname = $obj->lastname;
863 $tmpuser->photo = $obj->photo;
864 $tmpuser->status = $obj->status;
866 print
'<tr class="oddeven">';
867 print
'<td>'.dol_print_date($db->jdate($obj->dc),
'dayhour',
'tzuserrel').
'</td>';
868 if (preg_match(
'/\(CREDIT_NOTE\)/', $obj->description)) {
869 print
'<td class="tdoverflowmax100">';
870 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
871 $facturefournstatic->ref = $obj->ref;
872 $facturefournstatic->type = $obj->type;
873 print preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $obj->description).
'<br>'.$facturefournstatic->getNomURl(1);
875 } elseif (preg_match(
'/\(DEPOSIT\)/', $obj->description)) {
876 print
'<td class="tdoverflowmax100">';
877 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
878 $facturefournstatic->ref = $obj->ref;
879 $facturefournstatic->type = $obj->type;
880 print preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"InvoiceDeposit"), $obj->description).
'<br>'.$facturefournstatic->getNomURl(1);
882 } elseif (preg_match(
'/\(EXCESS PAID\)/', $obj->description)) {
883 print
'<td class="tdoverflowmax100">';
884 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
885 $facturefournstatic->ref = $obj->ref;
886 $facturefournstatic->type = $obj->type;
887 print preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"ExcessPaid"), $obj->description).
'<br>'.$facturefournstatic->getNomURl(1);
890 print
'<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).
'">';
894 print
'<td class="nowrap"><span class="opacitymedium">'.$langs->trans(
"NotConsumed").
'</span></td>';
895 print
'<td class="right nowraponall amount">'.price($obj->amount_ht).
'</td>';
897 print
'<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).
'</td>';
899 print
'<td class="right">'.vatrate($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''), true).
'</td>';
900 print
'<td class="right nowraponall amount">'.price($obj->amount_ttc).
'</td>';
902 print
'<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ttc).
'</td>';
904 print
'<td class="tdoverflowmax100">';
905 print $tmpuser->getNomUrl(-1);
908 if ($user->hasRight(
'societe',
'creer') || $user->hasRight(
'facture',
'creer')) {
909 print
'<td class="center nowraponall">';
910 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>';
911 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>';
914 print
'<td> </td>';
918 if ($action ==
'split' &&
GETPOST(
'remid') == $obj->rowid) {
919 $showconfirminfo[
'rowid'] = $obj->rowid;
920 $showconfirminfo[
'amount_ttc'] = $obj->amount_ttc;
929 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
935 if (count($showconfirminfo)) {
937 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&remid='.$showconfirminfo[
'rowid'].
'" id="formsplit" data-totaltosplit="'.$showconfirminfo[
'amount_ttc'].
'" data-remaintosplit="0">';
940 print
'<input type="hidden" name="action" value="confirm_split_more">';
941 print
'<input type="hidden" name="token" value="'.newToken().
'">';
943 print
'<div class="div-table-responsive-no-min">';
944 print
'<table class="valid centpercent">';
948 print
'<tr class="validtitre">';
949 print
'<td class="validtitre" colspan="4">'.img_picto(
'',
'split',
'', 0, 0, 0,
'',
'paddingright').
' '.$langs->trans(
'SplitDiscountTitle').
'</td>';
952 print
'<tr class="valid">';
953 print
'<td class="" colspan="4">'.$langs->trans(
'TypeAmountOfEachNewDiscountSplit').
'</td>';
957 if (empty($splitamounts)) {
958 $amount1 =
price2num($showconfirminfo[
'amount_ttc'] / 2,
'MT');
959 $amount2 = ($showconfirminfo[
'amount_ttc'] - (float) $amount1);
960 $remaintosplit = (float) $showconfirminfo[
'amount_ttc'] - ((
float) $amount1 + (float) $amount2);
962 print
'<tr class="valid splitline" id="splitline-1">';
963 print
'<td class="right bold">'.$langs->trans(
'AmountTTC').
' 1:</td>';
964 print
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts[1]" value="'.$amount1.
'"></td>';
965 print
'<td class="right delsplitline"></td>';
966 print
'<td class="right"></td>';
969 print
'<tr class="valid splitline" id="splitline-2">';
970 print
'<td class="right bold">'.$langs->trans(
'AmountTTC').
' 2:</td>';
971 print
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts[2]" value="'.$amount2.
'"></td>';
972 print
'<td class="right delsplitline"></td>';
973 print
'<td class="right"></td>';
976 $nbSplitLines = count($splitamounts);
977 $remaintosplit = $showconfirminfo[
'amount_ttc'];
978 foreach ($splitamounts as $numero => $value) {
979 $remaintosplit -= (float) $value;
980 print
'<tr class="valid splitline" id="splitline-'.$numero.
'">';
981 print
'<td class="right bold">'.$langs->trans(
'AmountTTC').
' '.$numero.
':</td>';
982 print
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts['.$numero.
']" value="'.$splitamounts[$numero].
'"></td>';
983 print
'<td class="right delsplitline"></td>';
984 print
'<td class="right"></td>';
989 print
'<tr class="valid">';
990 print
'<td class="right"></td>';
991 print
'<td class="right"><span class="fas fa-plus-circle" id="splitaddline" style="cursor:pointer;"></span></td>';
992 print
'<td class="right"></td>';
995 print
'<tr class="valid">';
996 print
'<td colspan="3"> </td>';
1000 print
'<tr class="valid">';
1001 print
'<td class="right bold">'.$langs->trans(
'RemainToSplit').
':</td>';
1002 print
'<td class="right"><span id="remaintosplit">'.price($remaintosplit).
'</span> '.
$conf->currency.
'</td>';
1003 print
'<td class="right"></td>';
1006 print
'<tr class="valid">';
1007 print
'<td class="right bold"></td>';
1008 print
'<td class="right"><input type="submit" class="button valignmiddle confirmvalidatebutton small nomarginright"></td>';
1009 print
'<td class="right"></td>';
1018 <script nonce=
"<?php print getNonce(); ?>" type=
"text/javascript">
1019 $(document).ready(
function () {
1021 let formsplit = $(
'#formsplit');
1022 let totaltosplit = formsplit.data(
'totaltosplit');
1024 function calcRemainToPay(){
1025 let items = formsplit.find(
'.splitinput');
1026 let remaintosplit = totaltosplit;
1028 items.each(
function(e){
1029 var itemvalue = parseFloat($(
this).val().replace(
',',
'.'));
1030 if (isNaN(itemvalue)) {
1033 remaintosplit -= itemvalue;
1036 let remaintosplitval = remaintosplit.toFixed(2);
1037 console.log(remaintosplitval);
1038 formsplit.data(
'remaintosplit', remaintosplitval);
1039 formsplit.find(
'#remaintosplit').html(remaintosplitval.replace(
'.',
','));
1040 formsplit.find(
'input[type=submit]').prop(
'disabled',
true);
1041 if (remaintosplit == 0) {
1042 formsplit.find(
'input[type=submit]').prop(
'disabled',
false);
1047 $(document).on(
'click',
'#splitaddline',
function(){
1048 let splitlines = formsplit.find(
'.splitline');
1049 let numlines = splitlines.length;
1050 let nextNum = numlines + 1;
1051 let newInputValue = formsplit.data(
'remaintosplit');
1052 $(
'#splitline-'+numlines).find(
'.delsplitline').html(
'');
1053 var splitTemplate =
'<tr class="splitline" id="splitline-'+ nextNum +
'">';
1054 splitTemplate +=
'<td class="right bold"><?php echo $langs->trans('AmountTTC
'); ?> '+ nextNum +
':</td>';
1055 splitTemplate +=
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts['+ nextNum +
']" value="'+ parseFloat(newInputValue) +
'"></td>';
1056 splitTemplate +=
'<td class="right delsplitline"><span class="fas fa-trash icon-delsplitline" data-splitline="'+ nextNum +
'" style="cursor:pointer;"></span></td>';
1057 splitTemplate +=
'<td class="right"></td>';
1058 splitTemplate +=
'</tr>';
1059 $(
'#splitline-'+numlines).after(splitTemplate);
1064 $(document).on(
'change',
'.splitinput',
function(){
1069 $(document).on(
'click',
'.icon-delsplitline',
function(){
1070 let num = parseInt($(
this).data(
'splitline'));
1071 let numBefore = num - 1;
1072 if (numBefore > 2) {
1073 $(
'#splitline-'+numBefore).find(
'.delsplitline').html(
'<span class="fas fa-trash icon-delsplitline" data-splitline="'+ numBefore +
'"></span>');
1075 $(
'#splitline-'+num).remove();
1082 $amount1 =
price2num($showconfirminfo[
'amount_ttc'] / 2,
'MT');
1083 $amount2 = ($showconfirminfo[
'amount_ttc'] - (float) $amount1);
1084 $formquestion = array(
1085 'text' => $langs->trans(
'TypeAmountOfEachNewDiscount'),
1086 0 => array(
'type' =>
'text',
'name' =>
'amount_ttc_1',
'label' => $langs->trans(
"AmountTTC").
' 1',
'value' => $amount1,
'size' =>
'5'),
1087 1 => array(
'type' =>
'text',
'name' =>
'amount_ttc_2',
'label' => $langs->trans(
"AmountTTC").
' 2',
'value' => $amount2,
'size' =>
'5')
1089 $langs->load(
"dict");
1090 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);
1094 dol_print_error($db);
1103 print
'<div class="clearboth"></div><br><br>';
1113 print
'<div class="fichecenter">';
1114 print
'<div class="fichehalfleft fichehalfleft-lg">';
1119 $sql =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
1120 $sql .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
1121 $sql .=
" rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture_source,";
1122 $sql .=
" u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
1123 $sql .=
" f.rowid as invoiceid, f.ref,";
1124 $sql .=
" fa.ref as invoice_source_ref, fa.type as type";
1125 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
1126 $sql .=
" , ".MAIN_DB_PREFIX.
"user as u";
1127 $sql .=
" , ".MAIN_DB_PREFIX.
"facturedet as fc";
1128 $sql .=
" , ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
1129 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as fa ON rc.fk_facture_source = fa.rowid";
1130 $sql .=
" WHERE rc.fk_soc = ".((int)
$object->id);
1131 $sql .=
" AND rc.fk_facture_line = fc.rowid";
1132 $sql .=
" AND fc.fk_facture = f.rowid";
1133 $sql .=
" AND rc.fk_user = u.rowid";
1134 $sql .=
" AND rc.discount_type = 0";
1135 $sql .=
" ORDER BY dc DESC";
1138 $sql2 =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
1139 $sql2 .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
1140 $sql2 .=
" rc.datec as dc, rc.description, rc.fk_facture, rc.fk_facture_source,";
1141 $sql2 .=
" u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
1142 $sql2 .=
" f.rowid as invoiceid, f.ref,";
1143 $sql2 .=
" fa.ref as invoice_source_ref, fa.type as type";
1144 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
1145 $sql2 .=
" , ".MAIN_DB_PREFIX.
"user as u";
1146 $sql2 .=
" , ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
1147 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as fa ON rc.fk_facture_source = fa.rowid";
1148 $sql2 .=
" WHERE rc.fk_soc = ".((int)
$object->id);
1149 $sql2 .=
" AND rc.fk_facture = f.rowid";
1150 $sql2 .=
" AND rc.fk_user = u.rowid";
1151 $sql2 .=
" AND rc.discount_type = 0";
1152 $sql2 .=
" ORDER BY dc DESC";
1154 $resql = $db->query($sql);
1157 $resql2 = $db->query($sql2);
1160 print
'<div class="div-table-responsive-no-min">';
1161 print
'<table class="noborder centpercent">';
1162 print
'<tr class="liste_titre">';
1163 print
'<td class="widthdate">'.$langs->trans(
"Date").
'</td>';
1164 print
'<td>'.$langs->trans(
"ReasonDiscount").
'</td>';
1165 print
'<td class="nowrap">'.$langs->trans(
"ConsumedBy").
'</td>';
1166 print
'<td class="right">'.$langs->trans(
"AmountHT").
'</td>';
1168 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountHT")).
'">'.$langs->trans(
"MulticurrencyAmountHT").
'</td>';
1170 print
'<td class="right">'.$langs->trans(
"VATRate").
'</td>';
1171 print
'<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
1173 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountTTC")).
'">'.$langs->trans(
"MulticurrencyAmountTTC").
'</td>';
1175 print
'<td width="100" class="center">'.$langs->trans(
"Author").
'</td>';
1176 print
'<td width="50"> </td>';
1179 $tab_sqlobj = array();
1180 $tab_sqlobjOrder = array();
1181 $num = $db->num_rows($resql);
1183 for ($i = 0; $i < $num; $i++) {
1184 $fetched_obj = $db->fetch_object($resql);
1185 $tab_sqlobj[] = $fetched_obj;
1186 $tab_sqlobjOrder[] = $db->jdate($fetched_obj->dc);
1191 $num = $db->num_rows($resql2);
1192 for ($i = 0; $i < $num; $i++) {
1193 $fetched_obj = $db->fetch_object($resql2);
1194 $tab_sqlobj[] = $fetched_obj;
1195 $tab_sqlobjOrder[] = $db->jdate($fetched_obj->dc);
1198 $array1_sort_order = SORT_DESC;
1199 array_multisort($tab_sqlobjOrder, $array1_sort_order, $tab_sqlobj);
1201 $num = count($tab_sqlobj);
1205 $obj = array_shift($tab_sqlobj);
1207 $tmpuser->id = $obj->user_id;
1208 $tmpuser->login = $obj->login;
1209 $tmpuser->firstname = $obj->firstname;
1210 $tmpuser->lastname = $obj->lastname;
1211 $tmpuser->photo = $obj->photo;
1212 $tmpuser->status = $obj->status;
1214 print
'<tr class="oddeven">';
1215 print
'<td>'.dol_print_date($db->jdate($obj->dc),
'dayhour').
'</td>';
1216 if (preg_match(
'/\(CREDIT_NOTE\)/', $obj->description)) {
1217 print
'<td class="tdoverflowmax100">';
1218 $facturestatic->id = $obj->fk_facture_source;
1219 $facturestatic->ref = $obj->invoice_source_ref;
1220 $facturestatic->type = $obj->type;
1221 print preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $obj->description).
'<br>'.$facturestatic->getNomURl(1);
1223 } elseif (preg_match(
'/\(DEPOSIT\)/', $obj->description)) {
1224 print
'<td class="tdoverflowmax100">';
1225 $facturestatic->id = $obj->fk_facture_source;
1226 $facturestatic->ref = $obj->invoice_source_ref;
1227 $facturestatic->type = $obj->type;
1228 print preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"InvoiceDeposit"), $obj->description).
'<br>'.$facturestatic->getNomURl(1);
1230 } elseif (preg_match(
'/\(EXCESS RECEIVED\)/', $obj->description)) {
1231 print
'<td class="tdoverflowmax100">';
1232 $facturestatic->id = $obj->fk_facture_source;
1233 $facturestatic->ref = $obj->invoice_source_ref;
1234 $facturestatic->type = $obj->type;
1235 print preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"Invoice"), $obj->description).
'<br>'.$facturestatic->getNomURl(1);
1238 print
'<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).
'">';
1242 print
'<td class="left nowrap">';
1243 if ($obj->invoiceid) {
1244 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$obj->invoiceid.
'">'.img_object($langs->trans(
"ShowBill"),
'bill').
' '.$obj->ref.
'</a>';
1247 print
'<td class="right nowraponall amount">'.price($obj->amount_ht).
'</td>';
1249 print
'<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).
'</td>';
1251 print
'<td class="right nowraponall">'.vatrate($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''), true).
'</td>';
1252 print
'<td class="right nowraponall amount">'.price($obj->amount_ttc).
'</td>';
1254 print
'<td class="right">'.price($obj->multicurrency_amount_ttc).
'</td>';
1256 print
'<td class="tdoverflowmax100">';
1257 print $tmpuser->getNomUrl(-1);
1260 print
'<td> </td>';
1269 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
1275 dol_print_error($db);
1282 print
'<div class="fichehalfright fichehalfright-lg">';
1287 $sql =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
1288 $sql .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
1289 $sql .=
" rc.datec as dc, rc.description, rc.fk_invoice_supplier_line,";
1290 $sql .=
" rc.fk_invoice_supplier_source,";
1291 $sql .=
" u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
1292 $sql .=
" f.rowid as invoiceid, f.ref as ref,";
1293 $sql .=
" fa.ref as invoice_source_ref, fa.type as type";
1294 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
1295 $sql .=
" , ".MAIN_DB_PREFIX.
"user as u";
1296 $sql .=
" , ".MAIN_DB_PREFIX.
"facture_fourn_det as fc";
1297 $sql .=
" , ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
1298 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
1299 $sql .=
" WHERE rc.fk_soc = ".((int)
$object->id);
1300 $sql .=
" AND rc.fk_invoice_supplier_line = fc.rowid";
1301 $sql .=
" AND fc.fk_facture_fourn = f.rowid";
1302 $sql .=
" AND rc.fk_user = u.rowid";
1303 $sql .=
" AND rc.discount_type = 1";
1304 $sql .=
" ORDER BY dc DESC";
1307 $sql2 =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
1308 $sql2 .=
" rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
1309 $sql2 .=
" rc.datec as dc, rc.description, rc.fk_invoice_supplier,";
1310 $sql2 .=
" rc.fk_invoice_supplier_source,";
1311 $sql2 .=
" u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
1312 $sql2 .=
" f.rowid as invoiceid, f.ref as ref,";
1313 $sql2 .=
" fa.ref as invoice_source_ref, fa.type as type";
1314 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
1315 $sql2 .=
" , ".MAIN_DB_PREFIX.
"user as u";
1316 $sql2 .=
" , ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
1317 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
1318 $sql2 .=
" WHERE rc.fk_soc = ".((int)
$object->id);
1319 $sql2 .=
" AND rc.fk_invoice_supplier = f.rowid";
1320 $sql2 .=
" AND rc.fk_user = u.rowid";
1321 $sql2 .=
" AND rc.discount_type = 1";
1322 $sql2 .=
" ORDER BY dc DESC";
1324 $resql = $db->query($sql);
1327 $resql2 = $db->query($sql2);
1330 print
'<div class="div-table-responsive-no-min">';
1331 print
'<table class="noborder centpercent">';
1332 print
'<tr class="liste_titre">';
1333 print
'<td class="widthdate">'.$langs->trans(
"Date").
'</td>';
1334 print
'<td>'.$langs->trans(
"ReasonDiscount").
'</td>';
1335 print
'<td class="nowrap">'.$langs->trans(
"ConsumedBy").
'</td>';
1336 print
'<td class="right">'.$langs->trans(
"AmountHT").
'</td>';
1338 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountHT")).
'">'.$langs->trans(
"MulticurrencyAmountHT").
'</td>';
1340 print
'<td class="right">'.$langs->trans(
"VATRate").
'</td>';
1341 print
'<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
1343 print
'<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans(
"MulticurrencyAmountTTC")).
'">'.$langs->trans(
"MulticurrencyAmountTTC").
'</td>';
1345 print
'<td width="100" class="center">'.$langs->trans(
"Author").
'</td>';
1346 print
'<td width="50"> </td>';
1349 $tab_sqlobj = array();
1350 $tab_sqlobjOrder = array();
1351 $num = $db->num_rows($resql);
1353 for ($i = 0; $i < $num; $i++) {
1354 $fetched_obj = $db->fetch_object($resql);
1355 $tab_sqlobj[] = $fetched_obj;
1356 $tab_sqlobjOrder[] = $db->jdate($fetched_obj->dc);
1361 $num = $db->num_rows($resql2);
1362 for ($i = 0; $i < $num; $i++) {
1363 $fetched_obj = $db->fetch_object($resql2);
1364 $tab_sqlobj[] = $fetched_obj;
1365 $tab_sqlobjOrder[] = $db->jdate($fetched_obj->dc);
1368 $array1_sort_order = SORT_DESC;
1369 array_multisort($tab_sqlobjOrder, $array1_sort_order, $tab_sqlobj);
1371 $num = count($tab_sqlobj);
1375 $obj = array_shift($tab_sqlobj);
1377 $tmpuser->id = $obj->user_id;
1378 $tmpuser->login = $obj->login;
1379 $tmpuser->firstname = $obj->firstname;
1380 $tmpuser->lastname = $obj->lastname;
1381 $tmpuser->photo = $obj->photo;
1382 $tmpuser->status = $obj->status;
1384 print
'<tr class="oddeven">';
1385 print
'<td>'.dol_print_date($db->jdate($obj->dc),
'dayhour').
'</td>';
1386 if (preg_match(
'/\(CREDIT_NOTE\)/', $obj->description)) {
1387 print
'<td class="tdoverflowmax100">';
1388 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
1389 $facturefournstatic->ref = $obj->invoice_source_ref;
1390 $facturefournstatic->type = $obj->type;
1391 print preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $obj->description).
'<br>'.$facturefournstatic->getNomURl(1);
1393 } elseif (preg_match(
'/\(DEPOSIT\)/', $obj->description)) {
1394 print
'<td class="tdoverflowmax100">';
1395 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
1396 $facturefournstatic->ref = $obj->invoice_source_ref;
1397 $facturefournstatic->type = $obj->type;
1398 print preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"InvoiceDeposit"), $obj->description).
'<br>'.$facturefournstatic->getNomURl(1);
1400 } elseif (preg_match(
'/\(EXCESS PAID\)/', $obj->description)) {
1401 print
'<td class="tdoverflowmax100">';
1402 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
1403 $facturefournstatic->ref = $obj->invoice_source_ref;
1404 $facturefournstatic->type = $obj->type;
1405 print preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"Invoice"), $obj->description).
'<br>'.$facturefournstatic->getNomURl(1);
1408 print
'<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).
'">';
1412 print
'<td class="left nowrap">';
1413 if ($obj->invoiceid) {
1414 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.$obj->invoiceid.
'">'.img_object($langs->trans(
"ShowBill"),
'bill').
' '.$obj->ref.
'</a>';
1417 print
'<td class="right nowraponall amount">'.price($obj->amount_ht).
'</td>';
1419 print
'<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).
'</td>';
1421 print
'<td class="right">'.vatrate($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''), true).
'</td>';
1422 print
'<td class="right nowraponall amount">'.price($obj->amount_ttc).
'</td>';
1424 print
'<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ttc).
'</td>';
1426 print
'<td class="tdoverflowmax100">';
1427 print $tmpuser->getNomUrl(-1);
1430 print
'<td> </td>';
1440 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
1446 dol_print_error($db);
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
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.
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.
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_split($titlealt='default', $other='class="pictosplit"')
Show split logo.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.