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'));
53 $langs->load(
'multicurrency');
58$action =
GETPOST(
'action',
'aZ09');
59$backtopage =
GETPOST(
'backtopage',
'alpha');
60$splitamounts =
GETPOST(
'splitamounts',
'array');
65if ($user->socid > 0) {
66 $socid = $user->socid;
70if ($user->socid > 0) {
73$result =
restrictedArea($user,
'societe', $id,
'&societe',
'',
'fk_soc',
'rowid', 0);
75$permissiontocreate = ($user->hasRight(
'societe',
'creer') || $user->hasRight(
'facture',
'creer'));
81if (
GETPOST(
'cancel',
'alpha') && !empty($backtopage)) {
82 header(
"Location: ".$backtopage);
86if ($action ==
'confirm_split_more' && $permissiontocreate) {
90 $res = $discount->fetch($remid);
93 setEventMessages($langs->trans(
"ErrorFailedToLoadDiscount"),
null,
'errors');
94 } elseif ($discount->fk_soc != $socid) {
97 setEventMessages($langs->trans(
"ErrorRecordNotFound"),
null,
'errors');
100 if (!$error && ($discount->fk_facture_line || $discount->fk_facture || $discount->fk_invoice_supplier_line || $discount->fk_invoice_supplier)) {
102 setEventMessages($langs->trans(
"ErrorCantSplitAUsedDiscount"),
null,
'errors');
104 if (!$error && empty($splitamounts)) {
106 setEventMessages($langs->trans(
"TotalOfDiscountMustEqualsOriginal"),
null,
'errors');
110 foreach ($splitamounts as $key => $value) {
114 setEventMessages($langs->trans(
"AmountMustBePositive"),
null,
'errors');
117 $totalsplitted += (float)
price2num($value);
119 if (!$error &&
price2num($totalsplitted,
'MT') !=
price2num($discount->amount_ttc,
'MT')) {
121 setEventMessages($langs->trans(
"TotalOfDiscountMustEqualsOriginal"),
null,
'errors');
129 foreach ($splitamounts as $key => $value) {
136 $newdiscount->fk_facture_source = $discount->fk_facture_source;
137 $newdiscount->fk_facture = $discount->fk_facture;
138 $newdiscount->fk_facture_line = $discount->fk_facture_line;
139 $newdiscount->fk_invoice_supplier_source = $discount->fk_invoice_supplier_source;
140 $newdiscount->fk_invoice_supplier = $discount->fk_invoice_supplier;
141 $newdiscount->fk_invoice_supplier_line = $discount->fk_invoice_supplier_line;
142 if ($discount->description ==
'(CREDIT_NOTE)' || $discount->description ==
'(DEPOSIT)') {
143 $newdiscount->description = $discount->description;
145 $newdiscount->description = $discount->description.
' ('.$discountnumber.
')';
147 $newdiscount->fk_user = $discount->fk_user;
148 $newdiscount->fk_soc = $discount->fk_soc;
149 $newdiscount->socid = $discount->socid;
150 $newdiscount->discount_type = $discount->discount_type;
151 $newdiscount->datec = $discount->datec;
152 $newdiscount->tva_tx = $discount->tva_tx;
153 $newdiscount->localtax1_tx = $discount->localtax1_tx;
154 $newdiscount->localtax1_type = $discount->localtax1_type;
155 $newdiscount->localtax2_tx = $discount->localtax2_tx;
156 $newdiscount->localtax2_type = $discount->localtax2_type;
157 $newdiscount->vat_src_code = $discount->vat_src_code;
158 $newdiscount->amount_ttc =
price2num($value);
161 $newdiscount->generateFromAmount($newdiscount->amount_ttc, 1, $newdiscount->tva_tx, $newdiscount->localtax1_tx, $newdiscount->localtax2_tx, $newdiscount->localtax1_type, $newdiscount->localtax2_type);
163 $newdiscount->multicurrency_amount_ttc = (float)
price2num($value) * ($discount->multicurrency_amount_ttc / $discount->amount_ttc);
164 $newdiscount->multicurrency_amount_ht =
price2num($newdiscount->multicurrency_amount_ttc / (1 + $newdiscount->tva_tx / 100),
'MT');
165 $newdiscount->multicurrency_amount_tva =
price2num($newdiscount->multicurrency_amount_ttc - $newdiscount->multicurrency_amount_ht);
167 $newdiscountID = $newdiscount->create($user);
168 if (!$newdiscountID) {
174 $discount->fk_facture_source = 0;
175 $discount->fk_invoice_supplier_source = 0;
176 $res = $discount->delete($user);
179 $query = [
'id' =>
$id,
'backtopage' => $backtopage];
180 header(
"Location: " .
dolBuildUrl($_SERVER[
"PHP_SELF"], $query));
184 setEventMessages($discount->error, $discount->errors,
'errors');
192if ($action ==
'confirm_split' &&
GETPOST(
"confirm",
"alpha") ==
'yes' && $permissiontocreate) {
193 $amount_ttc_1 =
GETPOST(
'amount_ttc_1',
'alpha');
194 $amount_ttc_1 =
price2num($amount_ttc_1);
195 $amount_ttc_2 =
GETPOST(
'amount_ttc_2',
'alpha');
196 $amount_ttc_2 =
price2num($amount_ttc_2);
201 $res = $discount->fetch($remid);
204 setEventMessages($langs->trans(
"ErrorFailedToLoadDiscount"),
null,
'errors');
205 } elseif ($discount->fk_soc != $socid) {
208 setEventMessages($langs->trans(
"ErrorRecordNotFound"),
null,
'errors');
211 if (!$error && ((
float) $amount_ttc_1 <= 0 || (
float) $amount_ttc_2 <= 0)) {
213 setEventMessages($langs->trans(
"AmountMustBePositive"),
null,
'errors');
215 if (!$error &&
price2num((
float) $amount_ttc_1 + (
float) $amount_ttc_2,
'MT') != $discount->amount_ttc) {
217 setEventMessages($langs->trans(
"TotalOfTwoDiscountMustEqualsOriginal"),
null,
'errors');
219 if (!$error && ($discount->fk_facture_line || $discount->fk_facture || $discount->fk_invoice_supplier_line || $discount->fk_invoice_supplier)) {
221 setEventMessages($langs->trans(
"ErrorCantSplitAUsedDiscount"),
null,
'errors');
225 $newDiscounts = $discount->splitAmount((
float) $amount_ttc_1, (
float) $amount_ttc_2);
226 $newdiscount1 = $newDiscounts[0];
227 $newdiscount2 = $newDiscounts[1];
231 $discount->fk_facture_source = 0;
233 $discount->fk_invoice_supplier_source = 0;
234 $res = $discount->delete($user);
235 $newid1 = $newdiscount1->create($user);
236 $newid2 = $newdiscount2->create($user);
237 if ($res > 0 && $newid1 > 0 && $newid2 > 0) {
239 $query = [
'id' =>
$id,
'backtopage' => $backtopage];
240 header(
"Location: " .
dolBuildUrl($_SERVER[
"PHP_SELF"], $query));
245 setEventMessages($discount->error, $discount->errors,
'errors');
246 } elseif ($newid1 <= 0) {
247 setEventMessages($newdiscount1->error, $newdiscount1->errors,
'errors');
249 setEventMessages($newdiscount2->error, $newdiscount2->errors,
'errors');
255if ($action ==
'setremise' && $permissiontocreate) {
257 $desc =
GETPOST(
'desc',
'alpha');
258 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
260 $price_base_type =
GETPOST(
'price_base_type',
'alpha');
265 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ReasonDiscount")),
null,
'errors');
272 $discountid = $soc->set_remise_except((
float) $amount, $user, $desc, $tva_tx, $discount_type, $price_base_type);
274 if ($discountid > 0) {
275 if (!empty($backtopage)) {
276 header(
"Location: ".$backtopage.
'&discountid='.((
int) $discountid));
279 header(
"Location: remx.php?id=".((
int) $id));
284 setEventMessages($soc->error, $soc->errors,
'errors');
288 setEventMessages($langs->trans(
"ErrorFieldFormat", $langs->transnoentitiesnoconv(
"AmountHT")),
null,
'errors');
292if (
GETPOST(
'action',
'aZ09') ==
'confirm_remove' &&
GETPOST(
"confirm") ==
'yes' && $permissiontocreate) {
296 $result = $discount->fetch(
GETPOSTINT(
"remid"));
297 if ($result > 0 && $discount->fk_soc == $socid) {
298 $result = $discount->delete($user);
302 setEventMessages($langs->trans(
"ErrorRecordNotFound"),
null,
'errors');
306 header(
"Location: " .
dolBuildUrl($_SERVER[
"PHP_SELF"], [
'id' => $id]));
309 setEventMessages($discount->error, $discount->errors,
'errors');
319$form =
new Form($db);
320$facturestatic =
new Facture($db);
322$tmpuser =
new User($db);
324llxHeader(
'', $langs->trans(
"GlobalDiscount"));
332 $isSupplier =
$object->fournisseur == 1;
338 print
'<form method="POST" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'">';
339 print
'<input type="hidden" name="token" value="'.newToken().
'">';
340 print
'<input type="hidden" name="action" value="setremise">';
341 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
343 print
dol_get_fiche_head($head,
'absolutediscount', $langs->trans(
"ThirdParty"), -1,
'company');
345 $linkback =
'<a href="'.DOL_URL_ROOT.
'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
347 dol_banner_tab(
$object,
'socid', $linkback, ($user->socid ? 0 : 1),
'rowid',
'nom');
349 print
'<div class="underbanner clearboth"></div>';
351 if (!$isCustomer && !$isSupplier) {
352 print
'<p class="opacitymedium">'.$langs->trans(
'ThirdpartyIsNeitherCustomerNorClientSoCannotHaveDiscounts').
'</p>';
366 if ($action ==
'create_remise') {
367 if ($user->hasRight(
'societe',
'creer')) {
369 if ($isCustomer && $isSupplier) {
370 $discounttypelabel = $discount_type == 1 ?
'NewSupplierGlobalDiscount' :
'NewClientGlobalDiscount';
372 $discounttypelabel =
'NewGlobalDiscount';
383 $formquestion = array(
384 0 => array(
'type' =>
'text',
'name' =>
'amount',
'tdclass' =>
'fieldrequired',
'label' => $langs->trans(
"Amount").
' ('.$langs->transnoentitiesnoconv(
"Currency".$conf->currency).
')',
'value' =>
price2num(
GETPOST(
"amount")),
'morecss' =>
'minwidth100'),
385 1 => array(
'type' =>
'other',
'name' =>
'price_base_type',
'label' => $langs->trans(
"PriceBase"),
'value' => $form->selectPriceBaseType(
GETPOST(
"price_base_type"),
"price_base_type")),
386 2 => array(
'type' =>
'other',
'name' =>
'tva_tx',
'label' => $langs->trans(
"VAT"),
'value' => $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)),
387 3 => array(
'type' =>
'text',
'name' =>
'desc',
'tdclass' =>
'fieldrequired',
'label' => $langs->trans(
"NoteReason"),
'value' =>
GETPOST(
'desc',
'alphanohtml'),
'morecss' =>
'minwidth300'),
388 4 => array(
'type' =>
'hidden',
'name' =>
'discount_type',
'value' => (($isSupplier && $discount_type == 1) ? 1 : 0))
391 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.($backtopage ?
'&backtopage='.urlencode($backtopage) :
''), $langs->trans($discounttypelabel),
'',
'setremise', $formquestion,
'', 1, 0, 600, 0,
'Add',
'Cancel');
398 if ($action ==
'remove') {
399 print $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&remid='.
GETPOST(
'remid'), $langs->trans(
'RemoveDiscount'), $langs->trans(
'ConfirmRemoveDiscount'),
'confirm_remove',
'', 0, 1);
407 if ($isCustomer && !$isSupplier) {
408 $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());
409 } elseif (!$isCustomer && $isSupplier) {
410 $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());
415 print
load_fiche_titre($langs->trans(
"DiscountStillRemaining"), $newcardbutton);
418 $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());
420 print
'<div class="fichecenter">';
421 print
'<div class="fichehalfleft fichehalfleft-lg">';
422 print
load_fiche_titre($langs->trans(
"CustomerDiscounts"), $newcardbutton,
'');
425 $sql =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
426 $sql .=
" rc.multicurrency_code, rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
427 $sql .=
" rc.datec as dc, rc.description,";
428 $sql .=
" rc.fk_facture_source,";
429 $sql .=
" u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
430 $sql .=
" fa.ref as ref, fa.type as type";
431 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u, ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
432 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as fa ON rc.fk_facture_source = fa.rowid";
433 $sql .=
" WHERE rc.fk_soc = ".((int)
$object->id);
434 $sql .=
" AND rc.entity = ".((int)
$conf->entity);
435 $sql .=
" AND u.rowid = rc.fk_user";
436 $sql .=
" AND rc.discount_type = 0";
437 $sql .=
" AND (rc.fk_facture_line IS NULL AND rc.fk_facture IS NULL)";
438 $sql .=
" ORDER BY rc.datec DESC";
440 $resql = $db->query($sql);
442 print
'<div class="div-table-responsive-no-min">';
443 print
'<table class="noborder centpercent">';
444 print
'<tr class="liste_titre">';
445 print
'<td class="widthdate">'.$langs->trans(
"Date").
'</td>';
446 print
'<td>'.$langs->trans(
"ReasonDiscount").
'</td>';
447 print
'<td class="nowrap">'.$langs->trans(
"ConsumedBy").
'</td>';
448 print
'<td class="right">'.$langs->trans(
"AmountHT").
'</td>';
449 print
'<td class="right">'.$langs->trans(
"VATRate").
'</td>';
450 print
'<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
452 print
'<td><br><br></td>';
454 print
'<td width="50"> </td>';
457 $showconfirminfo = array();
460 $total_amount_ht = 0;
461 $num = $db->num_rows($resql);
464 $obj = $db->fetch_object($resql);
466 $tmpuser->id = $obj->user_id;
467 $tmpuser->login = $obj->login;
468 $tmpuser->firstname = $obj->firstname;
469 $tmpuser->lastname = $obj->lastname;
470 $tmpuser->photo = $obj->photo;
471 $tmpuser->status = $obj->status;
473 print
'<tr class="oddeven">';
475 print
'<td>'.dol_print_date($db->jdate($obj->dc),
'dayhourreduceformat',
'tzuserrel').
'</td>';
477 if (preg_match(
'/\(CREDIT_NOTE\)/', $obj->description)) {
478 print
'<td class="tdoverflowmax150 tdlineheightsmall">';
479 $facturestatic->id = $obj->fk_facture_source;
480 $facturestatic->ref = $obj->ref;
481 $facturestatic->type = $obj->type;
482 print preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $obj->description).
'<br>'.$facturestatic->getNomURl(1);
484 } elseif (preg_match(
'/\(DEPOSIT\)/', $obj->description)) {
485 print
'<td class="tdoverflowmax150 tdlineheightsmall">';
486 $facturestatic->id = $obj->fk_facture_source;
487 $facturestatic->ref = $obj->ref;
488 $facturestatic->type = $obj->type;
489 print preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"InvoiceDeposit"), $obj->description).
'<br>'.$facturestatic->getNomURl(1);
491 } elseif (preg_match(
'/\(EXCESS RECEIVED\)/', $obj->description)) {
492 print
'<td class="tdoverflowmax150 tdlineheightsmall">';
493 $facturestatic->id = $obj->fk_facture_source;
494 $facturestatic->ref = $obj->ref;
495 $facturestatic->type = $obj->type;
496 print preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"ExcessReceived"), $obj->description).
'<br>'.$facturestatic->getNomURl(1);
499 print
'<td class="tdoverflowmax150 tdlineheightsmall" title="'.dol_escape_htmltag($obj->description).
'">';
504 print
'<td class="nowrap"><span class="opacitymedium">'.$langs->trans(
"NotConsumed").
'</span></td>';
506 print
'<td class="right nowraponall amount">'.price($obj->amount_ht).
'</td>';
508 print
'<td class="right nowraponall">'.vatrate($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''), true).
'</td>';
509 print
'<td class="right nowraponall amount">'.price($obj->amount_ttc).
'</td>';
511 $discounttooltip = $langs->trans(
"DiscountOfferedBy").
': '.$tmpuser->getNomUrl(-1,
'nolink');
512 $discounttooltip .=
'<br>'.$langs->trans(
"AmountHT").
' ('.$langs->trans(
"MulticurrencyOriginalCurrency").
'): '.
price($obj->multicurrency_amount_ht, 0, $langs, 1, -1, -1, $obj->multicurrency_code);
513 $discounttooltip .=
'<br>'.$langs->trans(
"AmountTTC").
' ('.$langs->trans(
"MulticurrencyOriginalCurrency").
'): '.
price($obj->multicurrency_amount_ttc, 0, $langs, 1, -1, -1, $obj->multicurrency_code);
514 print
'<td class="center nowraponall">'.$form->textwithpicto(
'', $discounttooltip, 1,
'info').
'</td>';
517 if ($user->hasRight(
'societe',
'creer') || $user->hasRight(
'facture',
'creer')) {
518 print
'<td class="center nowraponall">';
519 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>';
520 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>';
523 print
'<td> </td>';
527 if ($action ==
'split' &&
GETPOST(
'remid') == $obj->rowid) {
528 $showconfirminfo[
'rowid'] = $obj->rowid;
529 $showconfirminfo[
'amount_ttc'] = $obj->amount_ttc;
532 $total_amount_ht += (float) $obj->amount_ht;
537 print
'<tr class="liste_total">';
538 print
'<td colspan="3">'.$langs->trans(
"Total").
'</td>';
539 print
'<td class="right nowraponall amount">'.price($total_amount_ht).
'</td>';
540 print
'<td class="right"></td>';
541 print
'<td class="right"></td>';
553 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
559 if (count($showconfirminfo)) {
561 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&remid='.$showconfirminfo[
'rowid'].
'" id="formsplit" data-totaltosplit="'.$showconfirminfo[
'amount_ttc'].
'" data-remaintosplit="0">';
564 print
'<input type="hidden" name="action" value="confirm_split_more">';
565 print
'<input type="hidden" name="token" value="'.newToken().
'">';
567 print
'<div class="div-table-responsive-no-min">';
568 print
'<table class="centpercent">';
572 print
'<td class="" colspan="4">'.$langs->trans(
'TypeAmountOfEachNewDiscountSplit').
'</td>';
576 if (empty($splitamounts)) {
577 $amount1 =
price2num($showconfirminfo[
'amount_ttc'] / 2,
'MT');
578 $amount2 = ($showconfirminfo[
'amount_ttc'] - (float) $amount1);
579 $remaintosplit = (float) $showconfirminfo[
'amount_ttc'] - ((
float) $amount1 + (float) $amount2);
581 print
'<tr class="splitline" id="splitline-1">';
582 print
'<td class="right bold">'.$langs->trans(
'AmountTTC').
' 1:</td>';
583 print
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts[1]" value="'.$amount1.
'"></td>';
584 print
'<td class="right delsplitline"></td>';
585 print
'<td class="right"></td>';
588 print
'<tr class="splitline" id="splitline-2">';
589 print
'<td class="right bold">'.$langs->trans(
'AmountTTC').
' 2:</td>';
590 print
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts[2]" value="'.$amount2.
'"></td>';
591 print
'<td class="right delsplitline"></td>';
592 print
'<td class="right"></td>';
595 $nbSplitLines = count($splitamounts);
596 $remaintosplit = $showconfirminfo[
'amount_ttc'];
597 foreach ($splitamounts as $numero => $value) {
598 $remaintosplit -= (float) $value;
599 print
'<tr class="splitline" id="splitline-'.$numero.
'">';
600 print
'<td class="right bold">'.$langs->trans(
'AmountTTC').
' '.$numero.
':</td>';
601 print
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts['.$numero.
']" value="'.$splitamounts[$numero].
'"></td>';
602 print
'<td class="right delsplitline"></td>';
603 print
'<td class="right"></td>';
609 print
'<td class="right"></td>';
610 print
'<td class="right"><span class="fas fa-plus-circle" id="splitaddline" style="cursor:pointer;"></span></td>';
611 print
'<td class="right"></td>';
615 print
'<td colspan="3"> </td>';
620 print
'<td class="right bold">'.$langs->trans(
'RemainToSplit').
':</td>';
621 print
'<td class="right"><span id="remaintosplit">'.price($remaintosplit).
'</span> '.
$conf->currency.
'</td>';
622 print
'<td class="right"></td>';
630 <script nonce=
"<?php print getNonce(); ?>" type=
"text/javascript">
631 $(document).ready(
function () {
633 let formsplit = $(
'#formsplit');
634 let totaltosplit = formsplit.data(
'totaltosplit');
638 title:
'<?php print dol_escape_js($langs->transnoentities('SplitDiscountTitle
')); ?>',
645 text:
'<?php print dol_escape_js($langs->transnoentities('Split
')); ?>',
646 class:
'ui-split-confirm',
648 $(
this).trigger(
'submit');
652 text:
'<?php print dol_escape_js($langs->transnoentities('Cancel
')); ?>',
654 $(
this).dialog(
'close');
660 let splitconfirmbutton = formsplit.closest(
'.ui-dialog').find(
'.ui-split-confirm');
663 function calcRemainToPay(){
664 let items = formsplit.find(
'.splitinput');
665 let remaintosplit = totaltosplit;
667 items.each(
function(e){
668 var itemvalue = parseFloat($(
this).val().replace(
',',
'.'));
669 if (isNaN(itemvalue)) {
672 remaintosplit -= itemvalue;
675 let remaintosplitval = remaintosplit.toFixed(2);
676 console.log(remaintosplitval);
677 formsplit.data(
'remaintosplit', remaintosplitval);
678 formsplit.find(
'#remaintosplit').html(remaintosplitval.replace(
'.',
','));
679 splitconfirmbutton.prop(
'disabled',
true);
680 if (remaintosplit == 0) {
681 splitconfirmbutton.prop(
'disabled',
false);
686 $(document).on(
'click',
'#splitaddline',
function(){
687 let splitlines = formsplit.find(
'.splitline');
688 let numlines = splitlines.length;
689 let nextNum = numlines + 1;
690 let newInputValue = formsplit.data(
'remaintosplit');
691 $(
'#splitline-'+numlines).find(
'.delsplitline').html(
'');
692 var splitTemplate =
'<tr class="splitline" id="splitline-'+ nextNum +
'">';
693 splitTemplate +=
'<td class="right bold"><?php echo $langs->trans('AmountTTC
'); ?> '+ nextNum +
':</td>';
694 splitTemplate +=
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts['+ nextNum +
']" value="'+ parseFloat(newInputValue) +
'"></td>';
695 splitTemplate +=
'<td class="right delsplitline"><span class="fas fa-trash icon-delsplitline" data-splitline="'+ nextNum +
'" style="cursor:pointer;"></span></td>';
696 splitTemplate +=
'<td class="right"></td>';
697 splitTemplate +=
'</tr>';
698 $(
'#splitline-'+numlines).after(splitTemplate);
703 $(document).on(
'change',
'.splitinput',
function(){
708 $(document).on(
'click',
'.icon-delsplitline',
function(){
709 let num = parseInt($(
this).data(
'splitline'));
710 let numBefore = num - 1;
712 $(
'#splitline-'+numBefore).find(
'.delsplitline').html(
'<span class="fas fa-trash icon-delsplitline" data-splitline="'+ numBefore +
'"></span>');
714 $(
'#splitline-'+num).remove();
721 $amount1 =
price2num($showconfirminfo[
'amount_ttc'] / 2,
'MT');
722 $amount2 = ($showconfirminfo[
'amount_ttc'] - (float) $amount1);
723 $splittotalattr =
'data-total="'.dol_escape_htmltag(
price2num($showconfirminfo[
'amount_ttc'])).
'" data-decimals="'.((
int)
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT', 2)).
'"';
724 $formquestion = array(
725 'text' => $langs->trans(
'TypeAmountOfEachNewDiscount'),
726 0 => array(
'type' =>
'text',
'name' =>
'amount_ttc_1',
'label' => $langs->trans(
"AmountTTC").
' 1',
'value' => $amount1,
'size' =>
'5',
'moreattr' => $splittotalattr),
727 1 => array(
'type' =>
'text',
'name' =>
'amount_ttc_2',
'label' => $langs->trans(
"AmountTTC").
' 2',
'value' => $amount2,
'size' =>
'5')
729 $langs->load(
"dict");
730 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,
'', 1, 0, 600, 0,
'Split',
'Cancel');
734 dol_print_error($db);
740 $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());
742 print
'<div class="fichehalfright fichehalfright-lg">';
743 print
load_fiche_titre($langs->trans(
"SupplierDiscounts"), $newcardbutton,
'');
749 $sql =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
750 $sql .=
" rc.multicurrency_code, rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
751 $sql .=
" rc.datec as dc, rc.description,";
752 $sql .=
" rc.fk_invoice_supplier_source,";
753 $sql .=
" u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
754 $sql .=
" fa.ref, fa.type as type";
755 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u, ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
756 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
757 $sql .=
" WHERE rc.fk_soc = ".((int)
$object->id);
758 $sql .=
" AND rc.entity = ".((int)
$conf->entity);
759 $sql .=
" AND u.rowid = rc.fk_user";
760 $sql .=
" AND rc.discount_type = 1";
761 $sql .=
" AND (rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_line IS NULL)";
762 $sql .=
" ORDER BY rc.datec DESC";
764 $resql = $db->query($sql);
766 print
'<div class="div-table-responsive-no-min">';
767 print
'<table class="noborder centpercent">';
768 print
'<tr class="liste_titre">';
769 print
'<td class="widthdate">'.$langs->trans(
"Date").
'</td>';
770 print
'<td>'.$langs->trans(
"ReasonDiscount").
'</td>';
771 print
'<td class="nowrap">'.$langs->trans(
"ConsumedBy").
'</td>';
772 print
'<td class="right">'.$langs->trans(
"AmountHT").
'</td>';
773 print
'<td class="right">'.$langs->trans(
"VATRate").
'</td>';
774 print
'<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
776 print
'<td><br><br></td>';
778 print
'<td width="50"> </td>';
781 $showconfirminfo = array();
784 $total_amount_ht = 0;
785 $num = $db->num_rows($resql);
788 $obj = $db->fetch_object($resql);
790 $tmpuser->id = $obj->user_id;
791 $tmpuser->login = $obj->login;
792 $tmpuser->firstname = $obj->firstname;
793 $tmpuser->lastname = $obj->lastname;
794 $tmpuser->photo = $obj->photo;
795 $tmpuser->status = $obj->status;
797 print
'<tr class="oddeven">';
798 print
'<td>'.dol_print_date($db->jdate($obj->dc),
'dayhourreduceformat',
'tzuserrel').
'</td>';
799 if (preg_match(
'/\(CREDIT_NOTE\)/', $obj->description)) {
800 print
'<td class="tdoverflowmax150 tdlineheightsmall">';
801 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
802 $facturefournstatic->ref = $obj->ref;
803 $facturefournstatic->type = $obj->type;
804 print preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $obj->description).
'<br>'.$facturefournstatic->getNomURl(1);
806 } elseif (preg_match(
'/\(DEPOSIT\)/', $obj->description)) {
807 print
'<td class="tdoverflowmax150 tdlineheightsmall">';
808 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
809 $facturefournstatic->ref = $obj->ref;
810 $facturefournstatic->type = $obj->type;
811 print preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"InvoiceDeposit"), $obj->description).
'<br>'.$facturefournstatic->getNomURl(1);
813 } elseif (preg_match(
'/\(EXCESS PAID\)/', $obj->description)) {
814 print
'<td class="tdoverflowmax150 tdlineheightsmall">';
815 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
816 $facturefournstatic->ref = $obj->ref;
817 $facturefournstatic->type = $obj->type;
818 print preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"ExcessPaid"), $obj->description).
'<br>'.$facturefournstatic->getNomURl(1);
821 print
'<td class="tdoverflowmax150 tdlineheightsmall" title="'.dol_escape_htmltag($obj->description).
'">';
825 print
'<td class="nowrap"><span class="opacitymedium">'.$langs->trans(
"NotConsumed").
'</span></td>';
826 print
'<td class="right nowraponall amount">'.price($obj->amount_ht).
'</td>';
827 print
'<td class="right">'.vatrate($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''), true).
'</td>';
828 print
'<td class="right nowraponall amount">'.price($obj->amount_ttc).
'</td>';
830 $discounttooltip = $langs->trans(
"DiscountOfferedBy").
': '.$tmpuser->getNomUrl(-1,
'nolink');
831 $discounttooltip .=
'<br>'.$langs->trans(
"AmountHT").
' ('.$langs->trans(
"MulticurrencyOriginalCurrency").
'): '.
price($obj->multicurrency_amount_ht, 0, $langs, 1, -1, -1, $obj->multicurrency_code);
832 $discounttooltip .=
'<br>'.$langs->trans(
"AmountTTC").
' ('.$langs->trans(
"MulticurrencyOriginalCurrency").
'): '.
price($obj->multicurrency_amount_ttc, 0, $langs, 1, -1, -1, $obj->multicurrency_code);
833 print
'<td class="center nowraponall">'.$form->textwithpicto(
'', $discounttooltip, 1,
'info').
'</td>';
836 if ($user->hasRight(
'societe',
'creer') || $user->hasRight(
'facture',
'creer')) {
837 print
'<td class="center nowraponall">';
838 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>';
839 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>';
842 print
'<td> </td>';
846 if ($action ==
'split' &&
GETPOST(
'remid') == $obj->rowid) {
847 $showconfirminfo[
'rowid'] = $obj->rowid;
848 $showconfirminfo[
'amount_ttc'] = $obj->amount_ttc;
851 $total_amount_ht += (float) $obj->amount_ht;
856 print
'<tr class="liste_total">';
857 print
'<td colspan="3">'.$langs->trans(
"Total").
'</td>';
858 print
'<td class="right nowraponall amount">'.price($total_amount_ht).
'</td>';
859 print
'<td class="right"></td>';
860 print
'<td class="right"></td>';
872 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
878 if (count($showconfirminfo)) {
880 print
'<form method="POST" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&remid='.$showconfirminfo[
'rowid'].
'" id="formsplit" data-totaltosplit="'.$showconfirminfo[
'amount_ttc'].
'" data-remaintosplit="0">';
883 print
'<input type="hidden" name="action" value="confirm_split_more">';
884 print
'<input type="hidden" name="token" value="'.newToken().
'">';
886 print
'<div class="div-table-responsive-no-min">';
887 print
'<table class="centpercent">';
891 print
'<td class="" colspan="4">'.$langs->trans(
'TypeAmountOfEachNewDiscountSplit').
'</td>';
895 if (empty($splitamounts)) {
896 $amount1 =
price2num($showconfirminfo[
'amount_ttc'] / 2,
'MT');
897 $amount2 = ($showconfirminfo[
'amount_ttc'] - (float) $amount1);
898 $remaintosplit = (float) $showconfirminfo[
'amount_ttc'] - ((
float) $amount1 + (float) $amount2);
900 print
'<tr class="splitline" id="splitline-1">';
901 print
'<td class="right bold">'.$langs->trans(
'AmountTTC').
' 1:</td>';
902 print
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts[1]" value="'.$amount1.
'"></td>';
903 print
'<td class="right delsplitline"></td>';
904 print
'<td class="right"></td>';
907 print
'<tr class="splitline" id="splitline-2">';
908 print
'<td class="right bold">'.$langs->trans(
'AmountTTC').
' 2:</td>';
909 print
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts[2]" value="'.$amount2.
'"></td>';
910 print
'<td class="right delsplitline"></td>';
911 print
'<td class="right"></td>';
914 $nbSplitLines = count($splitamounts);
915 $remaintosplit = $showconfirminfo[
'amount_ttc'];
916 foreach ($splitamounts as $numero => $value) {
917 $remaintosplit -= (float) $value;
918 print
'<tr class="splitline" id="splitline-'.$numero.
'">';
919 print
'<td class="right bold">'.$langs->trans(
'AmountTTC').
' '.$numero.
':</td>';
920 print
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts['.$numero.
']" value="'.$splitamounts[$numero].
'"></td>';
921 print
'<td class="right delsplitline"></td>';
922 print
'<td class="right"></td>';
928 print
'<td class="right"></td>';
929 print
'<td class="right"><span class="fas fa-plus-circle" id="splitaddline" style="cursor:pointer;"></span></td>';
930 print
'<td class="right"></td>';
934 print
'<td colspan="3"> </td>';
939 print
'<td class="right bold">'.$langs->trans(
'RemainToSplit').
':</td>';
940 print
'<td class="right"><span id="remaintosplit">'.price($remaintosplit).
'</span> '.
$conf->currency.
'</td>';
941 print
'<td class="right"></td>';
949 <script nonce=
"<?php print getNonce(); ?>" type=
"text/javascript">
950 $(document).ready(
function () {
952 let formsplit = $(
'#formsplit');
953 let totaltosplit = formsplit.data(
'totaltosplit');
957 title:
'<?php print dol_escape_js($langs->transnoentities('SplitDiscountTitle
')); ?>',
964 text:
'<?php print dol_escape_js($langs->transnoentities('Split
')); ?>',
965 class:
'ui-split-confirm',
967 $(
this).trigger(
'submit');
971 text:
'<?php print dol_escape_js($langs->transnoentities('Cancel
')); ?>',
973 $(
this).dialog(
'close');
979 let splitconfirmbutton = formsplit.closest(
'.ui-dialog').find(
'.ui-split-confirm');
982 function calcRemainToPay(){
983 let items = formsplit.find(
'.splitinput');
984 let remaintosplit = totaltosplit;
986 items.each(
function(e){
987 var itemvalue = parseFloat($(
this).val().replace(
',',
'.'));
988 if (isNaN(itemvalue)) {
991 remaintosplit -= itemvalue;
994 let remaintosplitval = remaintosplit.toFixed(2);
995 console.log(remaintosplitval);
996 formsplit.data(
'remaintosplit', remaintosplitval);
997 formsplit.find(
'#remaintosplit').html(remaintosplitval.replace(
'.',
','));
998 splitconfirmbutton.prop(
'disabled',
true);
999 if (remaintosplit == 0) {
1000 splitconfirmbutton.prop(
'disabled',
false);
1005 $(document).on(
'click',
'#splitaddline',
function(){
1006 let splitlines = formsplit.find(
'.splitline');
1007 let numlines = splitlines.length;
1008 let nextNum = numlines + 1;
1009 let newInputValue = formsplit.data(
'remaintosplit');
1010 $(
'#splitline-'+numlines).find(
'.delsplitline').html(
'');
1011 var splitTemplate =
'<tr class="splitline" id="splitline-'+ nextNum +
'">';
1012 splitTemplate +=
'<td class="right bold"><?php echo $langs->trans('AmountTTC
'); ?> '+ nextNum +
':</td>';
1013 splitTemplate +=
'<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts['+ nextNum +
']" value="'+ parseFloat(newInputValue) +
'"></td>';
1014 splitTemplate +=
'<td class="right delsplitline"><span class="fas fa-trash icon-delsplitline" data-splitline="'+ nextNum +
'" style="cursor:pointer;"></span></td>';
1015 splitTemplate +=
'<td class="right"></td>';
1016 splitTemplate +=
'</tr>';
1017 $(
'#splitline-'+numlines).after(splitTemplate);
1022 $(document).on(
'change',
'.splitinput',
function(){
1027 $(document).on(
'click',
'.icon-delsplitline',
function(){
1028 let num = parseInt($(
this).data(
'splitline'));
1029 let numBefore = num - 1;
1030 if (numBefore > 2) {
1031 $(
'#splitline-'+numBefore).find(
'.delsplitline').html(
'<span class="fas fa-trash icon-delsplitline" data-splitline="'+ numBefore +
'"></span>');
1033 $(
'#splitline-'+num).remove();
1040 $amount1 =
price2num($showconfirminfo[
'amount_ttc'] / 2,
'MT');
1041 $amount2 = ($showconfirminfo[
'amount_ttc'] - (float) $amount1);
1042 $splittotalattr =
'data-total="'.dol_escape_htmltag(
price2num($showconfirminfo[
'amount_ttc'])).
'" data-decimals="'.((
int)
getDolGlobalInt(
'MAIN_MAX_DECIMALS_TOT', 2)).
'"';
1043 $formquestion = array(
1044 'text' => $langs->trans(
'TypeAmountOfEachNewDiscount'),
1045 0 => array(
'type' =>
'text',
'name' =>
'amount_ttc_1',
'label' => $langs->trans(
"AmountTTC").
' 1',
'value' => $amount1,
'size' =>
'5',
'moreattr' => $splittotalattr),
1046 1 => array(
'type' =>
'text',
'name' =>
'amount_ttc_2',
'label' => $langs->trans(
"AmountTTC").
' 2',
'value' => $amount2,
'size' =>
'5')
1048 $langs->load(
"dict");
1049 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, 1, 0, 600, 0,
'Split',
'Cancel');
1053 dol_print_error($db);
1062 print
'<div class="clearboth"></div><br><br>';
1072 print
'<div class="fichecenter">';
1073 print
'<div class="fichehalfleft fichehalfleft-lg">';
1078 $sql =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
1079 $sql .=
" rc.multicurrency_code, rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
1080 $sql .=
" rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture_source,";
1081 $sql .=
" u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
1082 $sql .=
" f.rowid as invoiceid, f.ref,";
1083 $sql .=
" fa.ref as invoice_source_ref, fa.type as type";
1084 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
1085 $sql .=
" , ".MAIN_DB_PREFIX.
"user as u";
1086 $sql .=
" , ".MAIN_DB_PREFIX.
"facturedet as fc";
1087 $sql .=
" , ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
1088 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as fa ON rc.fk_facture_source = fa.rowid";
1089 $sql .=
" WHERE rc.fk_soc = ".((int)
$object->id);
1090 $sql .=
" AND rc.fk_facture_line = fc.rowid";
1091 $sql .=
" AND fc.fk_facture = f.rowid";
1092 $sql .=
" AND rc.fk_user = u.rowid";
1093 $sql .=
" AND rc.discount_type = 0";
1094 $sql .=
" ORDER BY dc DESC";
1097 $sql2 =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
1098 $sql2 .=
" rc.multicurrency_code, rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
1099 $sql2 .=
" rc.datec as dc, rc.description, rc.fk_facture, rc.fk_facture_source,";
1100 $sql2 .=
" u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
1101 $sql2 .=
" f.rowid as invoiceid, f.ref,";
1102 $sql2 .=
" fa.ref as invoice_source_ref, fa.type as type";
1103 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
1104 $sql2 .=
" , ".MAIN_DB_PREFIX.
"user as u";
1105 $sql2 .=
" , ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
1106 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture as fa ON rc.fk_facture_source = fa.rowid";
1107 $sql2 .=
" WHERE rc.fk_soc = ".((int)
$object->id);
1108 $sql2 .=
" AND rc.fk_facture = f.rowid";
1109 $sql2 .=
" AND rc.fk_user = u.rowid";
1110 $sql2 .=
" AND rc.discount_type = 0";
1111 $sql2 .=
" ORDER BY dc DESC";
1113 $resql = $db->query($sql);
1116 $resql2 = $db->query($sql2);
1119 print
'<div class="div-table-responsive-no-min">';
1120 print
'<table class="noborder centpercent">';
1121 print
'<tr class="liste_titre">';
1122 print
'<td class="widthdate">'.$langs->trans(
"Date").
'</td>';
1123 print
'<td>'.$langs->trans(
"ReasonDiscount").
'</td>';
1124 print
'<td class="nowrap">'.$langs->trans(
"ConsumedBy").
'</td>';
1125 print
'<td class="right">'.$langs->trans(
"AmountHT").
'</td>';
1126 print
'<td class="right">'.$langs->trans(
"VATRate").
'</td>';
1127 print
'<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
1129 print
'<td><br><br></td>';
1131 print
'<td width="50"> </td>';
1134 $tab_sqlobj = array();
1135 $tab_sqlobjOrder = array();
1136 $num = $db->num_rows($resql);
1138 for ($i = 0; $i < $num; $i++) {
1139 $fetched_obj = $db->fetch_object($resql);
1140 $tab_sqlobj[] = $fetched_obj;
1141 $tab_sqlobjOrder[] = $db->jdate($fetched_obj->dc);
1146 $num = $db->num_rows($resql2);
1147 for ($i = 0; $i < $num; $i++) {
1148 $fetched_obj = $db->fetch_object($resql2);
1149 $tab_sqlobj[] = $fetched_obj;
1150 $tab_sqlobjOrder[] = $db->jdate($fetched_obj->dc);
1153 $array1_sort_order = SORT_DESC;
1154 array_multisort($tab_sqlobjOrder, $array1_sort_order, $tab_sqlobj);
1156 $num = count($tab_sqlobj);
1160 $obj = array_shift($tab_sqlobj);
1162 $tmpuser->id = $obj->user_id;
1163 $tmpuser->login = $obj->login;
1164 $tmpuser->firstname = $obj->firstname;
1165 $tmpuser->lastname = $obj->lastname;
1166 $tmpuser->photo = $obj->photo;
1167 $tmpuser->status = $obj->status;
1169 print
'<tr class="oddeven">';
1170 print
'<td>'.dol_print_date($db->jdate($obj->dc),
'dayhourreduceformat').
'</td>';
1171 if (preg_match(
'/\(CREDIT_NOTE\)/', $obj->description)) {
1172 print
'<td class="tdoverflowmax150 tdlineheightsmall">';
1173 $facturestatic->id = $obj->fk_facture_source;
1174 $facturestatic->ref = $obj->invoice_source_ref;
1175 $facturestatic->type = $obj->type;
1176 print preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $obj->description).
'<br>'.$facturestatic->getNomURl(1);
1178 } elseif (preg_match(
'/\(DEPOSIT\)/', $obj->description)) {
1179 print
'<td class="tdoverflowmax150 tdlineheightsmall">';
1180 $facturestatic->id = $obj->fk_facture_source;
1181 $facturestatic->ref = $obj->invoice_source_ref;
1182 $facturestatic->type = $obj->type;
1183 print preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"InvoiceDeposit"), $obj->description).
'<br>'.$facturestatic->getNomURl(1);
1185 } elseif (preg_match(
'/\(EXCESS RECEIVED\)/', $obj->description)) {
1186 print
'<td class="tdoverflowmax150 tdlineheightsmall">';
1187 $facturestatic->id = $obj->fk_facture_source;
1188 $facturestatic->ref = $obj->invoice_source_ref;
1189 $facturestatic->type = $obj->type;
1190 print preg_replace(
'/\(EXCESS RECEIVED\)/', $langs->trans(
"Invoice"), $obj->description).
'<br>'.$facturestatic->getNomURl(1);
1193 print
'<td class="tdoverflowmax150 tdlineheightsmall" title="'.dol_escape_htmltag($obj->description).
'">';
1197 print
'<td class="left nowrap">';
1198 if ($obj->invoiceid) {
1199 print
'<a href="'.DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$obj->invoiceid.
'">'.img_object($langs->trans(
"ShowBill"),
'bill').
' '.$obj->ref.
'</a>';
1202 print
'<td class="right nowraponall amount">'.price($obj->amount_ht).
'</td>';
1203 print
'<td class="right nowraponall">'.vatrate($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''), true).
'</td>';
1204 print
'<td class="right nowraponall amount">'.price($obj->amount_ttc).
'</td>';
1206 $discounttooltip = $langs->trans(
"DiscountOfferedBy").
': '.$tmpuser->getNomUrl(-1,
'nolink');
1207 $discounttooltip .=
'<br>'.$langs->trans(
"AmountHT").
' ('.$langs->trans(
"MulticurrencyOriginalCurrency").
'): '.
price($obj->multicurrency_amount_ht, 0, $langs, 1, -1, -1, $obj->multicurrency_code);
1208 $discounttooltip .=
'<br>'.$langs->trans(
"AmountTTC").
' ('.$langs->trans(
"MulticurrencyOriginalCurrency").
'): '.
price($obj->multicurrency_amount_ttc, 0, $langs, 1, -1, -1, $obj->multicurrency_code);
1209 print
'<td class="center nowraponall">'.$form->textwithpicto(
'', $discounttooltip, 1,
'info').
'</td>';
1212 print
'<td> </td>';
1221 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
1227 dol_print_error($db);
1234 print
'<div class="fichehalfright fichehalfright-lg">';
1239 $sql =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
1240 $sql .=
" rc.multicurrency_code, rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
1241 $sql .=
" rc.datec as dc, rc.description, rc.fk_invoice_supplier_line,";
1242 $sql .=
" rc.fk_invoice_supplier_source,";
1243 $sql .=
" u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
1244 $sql .=
" f.rowid as invoiceid, f.ref as ref,";
1245 $sql .=
" fa.ref as invoice_source_ref, fa.type as type";
1246 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
1247 $sql .=
" , ".MAIN_DB_PREFIX.
"user as u";
1248 $sql .=
" , ".MAIN_DB_PREFIX.
"facture_fourn_det as fc";
1249 $sql .=
" , ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
1250 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
1251 $sql .=
" WHERE rc.fk_soc = ".((int)
$object->id);
1252 $sql .=
" AND rc.fk_invoice_supplier_line = fc.rowid";
1253 $sql .=
" AND fc.fk_facture_fourn = f.rowid";
1254 $sql .=
" AND rc.fk_user = u.rowid";
1255 $sql .=
" AND rc.discount_type = 1";
1256 $sql .=
" ORDER BY dc DESC";
1259 $sql2 =
"SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
1260 $sql2 .=
" rc.multicurrency_code, rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
1261 $sql2 .=
" rc.datec as dc, rc.description, rc.fk_invoice_supplier,";
1262 $sql2 .=
" rc.fk_invoice_supplier_source,";
1263 $sql2 .=
" u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
1264 $sql2 .=
" f.rowid as invoiceid, f.ref as ref,";
1265 $sql2 .=
" fa.ref as invoice_source_ref, fa.type as type";
1266 $sql2 .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
1267 $sql2 .=
" , ".MAIN_DB_PREFIX.
"user as u";
1268 $sql2 .=
" , ".MAIN_DB_PREFIX.
"societe_remise_except as rc";
1269 $sql2 .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
1270 $sql2 .=
" WHERE rc.fk_soc = ".((int)
$object->id);
1271 $sql2 .=
" AND rc.fk_invoice_supplier = f.rowid";
1272 $sql2 .=
" AND rc.fk_user = u.rowid";
1273 $sql2 .=
" AND rc.discount_type = 1";
1274 $sql2 .=
" ORDER BY dc DESC";
1276 $resql = $db->query($sql);
1279 $resql2 = $db->query($sql2);
1282 print
'<div class="div-table-responsive-no-min">';
1283 print
'<table class="noborder centpercent">';
1284 print
'<tr class="liste_titre">';
1285 print
'<td class="widthdate">'.$langs->trans(
"Date").
'</td>';
1286 print
'<td>'.$langs->trans(
"ReasonDiscount").
'</td>';
1287 print
'<td class="nowrap">'.$langs->trans(
"ConsumedBy").
'</td>';
1288 print
'<td class="right">'.$langs->trans(
"AmountHT").
'</td>';
1289 print
'<td class="right">'.$langs->trans(
"VATRate").
'</td>';
1290 print
'<td class="right">'.$langs->trans(
"AmountTTC").
'</td>';
1292 print
'<td><br><br></td>';
1294 print
'<td width="50"> </td>';
1297 $tab_sqlobj = array();
1298 $tab_sqlobjOrder = array();
1299 $num = $db->num_rows($resql);
1301 for ($i = 0; $i < $num; $i++) {
1302 $fetched_obj = $db->fetch_object($resql);
1303 $tab_sqlobj[] = $fetched_obj;
1304 $tab_sqlobjOrder[] = $db->jdate($fetched_obj->dc);
1309 $num = $db->num_rows($resql2);
1310 for ($i = 0; $i < $num; $i++) {
1311 $fetched_obj = $db->fetch_object($resql2);
1312 $tab_sqlobj[] = $fetched_obj;
1313 $tab_sqlobjOrder[] = $db->jdate($fetched_obj->dc);
1316 $array1_sort_order = SORT_DESC;
1317 array_multisort($tab_sqlobjOrder, $array1_sort_order, $tab_sqlobj);
1319 $num = count($tab_sqlobj);
1323 $obj = array_shift($tab_sqlobj);
1325 $tmpuser->id = $obj->user_id;
1326 $tmpuser->login = $obj->login;
1327 $tmpuser->firstname = $obj->firstname;
1328 $tmpuser->lastname = $obj->lastname;
1329 $tmpuser->photo = $obj->photo;
1330 $tmpuser->status = $obj->status;
1332 print
'<tr class="oddeven">';
1333 print
'<td>'.dol_print_date($db->jdate($obj->dc),
'dayhourreduceformat').
'</td>';
1334 if (preg_match(
'/\(CREDIT_NOTE\)/', $obj->description)) {
1335 print
'<td class="tdoverflowmax150 tdlineheightsmall">';
1336 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
1337 $facturefournstatic->ref = $obj->invoice_source_ref;
1338 $facturefournstatic->type = $obj->type;
1339 print preg_replace(
'/\(CREDIT_NOTE\)/', $langs->trans(
"CreditNote"), $obj->description).
'<br>'.$facturefournstatic->getNomURl(1);
1341 } elseif (preg_match(
'/\(DEPOSIT\)/', $obj->description)) {
1342 print
'<td class="tdoverflowmax150 tdlineheightsmall">';
1343 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
1344 $facturefournstatic->ref = $obj->invoice_source_ref;
1345 $facturefournstatic->type = $obj->type;
1346 print preg_replace(
'/\(DEPOSIT\)/', $langs->trans(
"InvoiceDeposit"), $obj->description).
'<br>'.$facturefournstatic->getNomURl(1);
1348 } elseif (preg_match(
'/\(EXCESS PAID\)/', $obj->description)) {
1349 print
'<td class="tdoverflowmax150 tdlineheightsmall">';
1350 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
1351 $facturefournstatic->ref = $obj->invoice_source_ref;
1352 $facturefournstatic->type = $obj->type;
1353 print preg_replace(
'/\(EXCESS PAID\)/', $langs->trans(
"Invoice"), $obj->description).
'<br>'.$facturefournstatic->getNomURl(1);
1356 print
'<td class="tdoverflowmax150 tdlineheightsmall" title="'.dol_escape_htmltag($obj->description).
'">';
1360 print
'<td class="left nowrap">';
1361 if ($obj->invoiceid) {
1362 print
'<a href="'.DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.$obj->invoiceid.
'">'.img_object($langs->trans(
"ShowBill"),
'bill').
' '.$obj->ref.
'</a>';
1365 print
'<td class="right nowraponall amount">'.price($obj->amount_ht).
'</td>';
1366 print
'<td class="right">'.vatrate($obj->tva_tx.($obj->vat_src_code ?
' ('.$obj->vat_src_code.
')' :
''), true).
'</td>';
1367 print
'<td class="right nowraponall amount">'.price($obj->amount_ttc).
'</td>';
1369 $discounttooltip = $langs->trans(
"DiscountOfferedBy").
': '.$tmpuser->getNomUrl(-1,
'nolink');
1370 $discounttooltip .=
'<br>'.$langs->trans(
"AmountHT").
' ('.$langs->trans(
"MulticurrencyOriginalCurrency").
'): '.
price($obj->multicurrency_amount_ht, 0, $langs, 1, -1, -1, $obj->multicurrency_code);
1371 $discounttooltip .=
'<br>'.$langs->trans(
"AmountTTC").
' ('.$langs->trans(
"MulticurrencyOriginalCurrency").
'): '.
price($obj->multicurrency_amount_ttc, 0, $langs, 1, -1, -1, $obj->multicurrency_code);
1372 print
'<td class="center nowraponall">'.$form->textwithpicto(
'', $discounttooltip, 1,
'info').
'</td>';
1375 print
'<td> </td>';
1385 print
'<tr><td colspan="'.$colspan.
'"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
1391 dol_print_error($db);
1402if ($action ==
'split' && !
getDolGlobalInt(
'MAIN_DISABLE_JAVASCRIPT') && !empty(
$conf->use_javascript_ajax)) {
1403 print
'<script nonce="'.dol_escape_htmltag(
getNonce()).
'" type="text/javascript">'.
"\n";
1406 var input1 = jQuery(
'#amount_ttc_1');
1407 var input2 = jQuery(
'#amount_ttc_2');
1408 if (!input1.length || !input2.length) {
1411 var total = parseFloat(String(input1.attr(
'data-total')).replace(
',',
'.'));
1412 var decimals = parseInt(input1.attr(
'data-decimals'), 10);
1413 if (!isFinite(total) || !(total > 0)) {
1416 if (!isFinite(decimals) || decimals < 0) {
1419 var factor = Math.pow(10, decimals);
1421 function readAmount(raw) {
1422 if (raw ===
null || raw === undefined) {
1425 raw = String(raw).trim().replace(
',',
'.');
1426 if (raw ===
'' || raw ===
'-' || raw ===
'.' || raw ===
'-.') {
1429 var value = parseFloat(raw);
1430 if (!isFinite(value)) {
1436 function formatAmount(value) {
1437 var text = value.toFixed(decimals);
1439 text = text.replace(/(\.\d*?[1-9])0+$/,
'$1').replace(/\.0+$/,
'');
1444 function updateSibling(source, target) {
1445 var value = readAmount(source.val());
1446 if (value ===
null) {
1449 var remain = Math.round((total - value) * factor) / factor;
1450 target.val(formatAmount(remain));
1453 input1.on(
'input',
function () {
1454 updateSibling(input1, input2);
1456 input2.on(
'input',
function () {
1457 updateSibling(input2, input1);
1461 print
"\n</script>\n";
$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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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, $currencycode='')
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.
getNonce()
Return a random string to be used as a nonce value for js.
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.