dolibarr 25.0.0-alpha
remx.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
5 * Copyright (C) 2019-2026 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2025 Anthony Damhet <a.damhet@progiseize.fr>
8 * Copyright (C) 2026 Vincent de Grandpré <vincent@de-grandpre.quebec>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30if (! defined('CSRFCHECK_WITH_TOKEN')) {
31 define('CSRFCHECK_WITH_TOKEN', '1');
32} // Force use of CSRF protection with tokens even for GET
33
34// Load Dolibarr environment
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';
40
50// Load translation files required by the page
51$langs->loadLangs(array('orders', 'bills', 'companies'));
52
53$id = GETPOSTINT('id');
54
55$action = GETPOST('action', 'aZ09');
56$backtopage = GETPOST('backtopage', 'alpha');
57$splitamounts = GETPOST('splitamounts', 'array');
58
59// Security check
60$socid = GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('socid');
62if ($user->socid > 0) {
63 $socid = $user->socid;
64}
65
66// Security check
67if ($user->socid > 0) {
68 $id = $user->socid;
69}
70$result = restrictedArea($user, 'societe', $id, '&societe', '', 'fk_soc', 'rowid', 0);
71
72$permissiontocreate = ($user->hasRight('societe', 'creer') || $user->hasRight('facture', 'creer'));
73
74/*
75 * Actions
76 */
77
78if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
79 header("Location: ".$backtopage);
80 exit;
81}
82
83if ($action == 'confirm_split_more' && $permissiontocreate) {
84 $error = 0;
85 $remid = (GETPOSTINT("remid") ? GETPOSTINT("remid") : 0);
86 $discount = new DiscountAbsolute($db);
87 $res = $discount->fetch($remid);
88 if (!($res > 0)) {
89 $error++;
90 setEventMessages($langs->trans("ErrorFailedToLoadDiscount"), null, 'errors');
91 } elseif ($discount->fk_soc != $socid) {
92 // The discount must belong to the thirdparty of the page
93 $error++;
94 setEventMessages($langs->trans("ErrorRecordNotFound"), null, 'errors');
95 }
96 if (empty($splitamounts)) {
97 $error++;
98 setEventMessages($langs->trans("TotalOfDiscountMustEqualsOriginal"), null, 'errors');
99 }
100 if (!$error) {
101 $totalsplitted = 0;
102 foreach ($splitamounts as $key => $value) {
103 $totalsplitted += (float) $value;
104 }
105 if ($totalsplitted != (float) $discount->amount_ttc) {
106 $error++;
107 setEventMessages($langs->trans("TotalOfDiscountMustEqualsOriginal"), null, 'errors');
108 }
109 }
110
111 if (!$error) {
112 $db->begin();
113
114 foreach ($splitamounts as $key => $value) {
115 if ((float) $value == 0) {
116 continue;
117 }
118 //
119 $newdiscount = new DiscountAbsolute($db);
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;
128 } else {
129 $newdiscount->description = $discount->description.' (1)';
130 }
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);
143
144 // Calculate localtaxes and VAT amounts
145 $newdiscount->generateFromAmount($newdiscount->amount_ttc, 1, $newdiscount->tva_tx, $newdiscount->localtax1_tx, $newdiscount->localtax2_tx, $newdiscount->localtax1_type, $newdiscount->localtax2_type);
146
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);
150
151 $newdiscountID = $newdiscount->create($user);
152 if (!$newdiscountID) {
153 $error++;
154 }
155 }
156
157 if (!$error) {
158 $discount->fk_facture_source = 0;
159 $discount->fk_invoice_supplier_source = 0;
160 $res = $discount->delete($user);
161 if ($res > 0) {
162 $db->commit();
163 $query = ['id' => $id, 'backtopage' => $backtopage];
164 header("Location: " . dolBuildUrl($_SERVER["PHP_SELF"], $query)); // To avoid pb with backtopage
165 exit;
166 } else {
167 $db->rollback();
168 setEventMessages($discount->error, $discount->errors, 'errors');
169 }
170 } else {
171 $db->rollback();
172 }
173 }
174}
175
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);
181
182 $error = 0;
183 $remid = (GETPOSTINT("remid") ? GETPOSTINT("remid") : 0);
184 $discount = new DiscountAbsolute($db);
185 $res = $discount->fetch($remid);
186 if (!($res > 0)) {
187 $error++;
188 setEventMessages($langs->trans("ErrorFailedToLoadDiscount"), null, 'errors');
189 } elseif ($discount->fk_soc != $socid) {
190 // The discount must belong to the thirdparty of the page
191 $error++;
192 setEventMessages($langs->trans("ErrorRecordNotFound"), null, 'errors');
193 }
194 if (!$error && price2num((float) $amount_ttc_1 + (float) $amount_ttc_2, 'MT') != $discount->amount_ttc) {
195 $error++;
196 setEventMessages($langs->trans("TotalOfTwoDiscountMustEqualsOriginal"), null, 'errors');
197 }
198 if (!$error && $discount->fk_facture_line) {
199 $error++;
200 setEventMessages($langs->trans("ErrorCantSplitAUsedDiscount"), null, 'errors');
201 }
202 if (!$error) {
203 // Split a discount in two
204 $newDiscounts = $discount->splitAmount((float) $amount_ttc_1, (float) $amount_ttc_2); // Note: splitting this way will result of a total ttc similar to original but total ht and total taxes may differ.
205 $newdiscount1 = $newDiscounts[0];
206 $newdiscount2 = $newDiscounts[1];
207
208 $db->begin();
209
210 $discount->fk_facture_source = 0; // This is to delete only the require record (that we will recreate with two records) and not all family with same fk_facture_source
211 // This is to delete only the require record (that we will recreate with two records) and not all family with same fk_invoice_supplier_source
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) {
217 $db->commit();
218 $query = ['id' => $id, 'backtopage' => $backtopage];
219 header("Location: " . dolBuildUrl($_SERVER["PHP_SELF"], $query)); // To avoid pb with back
220 exit;
221 } else {
222 $db->rollback();
223 if ($res <= 0) {
224 setEventMessages($discount->error, $discount->errors, 'errors');
225 } elseif ($newid1 <= 0) {
226 setEventMessages($newdiscount1->error, $newdiscount1->errors, 'errors');
227 } else {
228 setEventMessages($newdiscount2->error, $newdiscount2->errors, 'errors');
229 }
230 }
231 }
232}
233
234if ($action == 'setremise' && $permissiontocreate) {
235 $amount = price2num(GETPOST('amount', 'alpha'), '', 2);
236 $desc = GETPOST('desc', 'alpha');
237 $tva_tx = GETPOST('tva_tx', 'alpha');
238 $discount_type = GETPOSTISSET('discount_type') ? GETPOST('discount_type', 'alpha') : 0;
239 $price_base_type = GETPOST('price_base_type', 'alpha');
240
241 if ($amount > 0) {
242 $error = 0;
243 if (empty($desc)) {
244 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ReasonDiscount")), null, 'errors');
245 $error++;
246 }
247
248 if (!$error) {
249 $soc = new Societe($db);
250 $soc->fetch($id);
251 $discountid = $soc->set_remise_except((float) $amount, $user, $desc, $tva_tx, $discount_type, $price_base_type);
252
253 if ($discountid > 0) {
254 if (!empty($backtopage)) {
255 header("Location: ".$backtopage.'&discountid='.((int) $discountid));
256 exit;
257 } else {
258 header("Location: remx.php?id=".((int) $id));
259 exit;
260 }
261 } else {
262 $error++;
263 setEventMessages($soc->error, $soc->errors, 'errors');
264 }
265 }
266 } else {
267 setEventMessages($langs->trans("ErrorFieldFormat", $langs->transnoentitiesnoconv("AmountHT")), null, 'errors');
268 }
269}
270
271if (GETPOST('action', 'aZ09') == 'confirm_remove' && GETPOST("confirm") == 'yes' && $permissiontocreate) {
272 $db->begin();
273
274 $discount = new DiscountAbsolute($db);
275 $result = $discount->fetch(GETPOSTINT("remid"));
276 if ($result > 0 && $discount->fk_soc == $socid) {
277 $result = $discount->delete($user);
278 } else {
279 // The discount must belong to the thirdparty of the page
280 $result = -1;
281 setEventMessages($langs->trans("ErrorRecordNotFound"), null, 'errors');
282 }
283 if ($result > 0) {
284 $db->commit();
285 header("Location: " . dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $id])); // To avoid pb with back
286 exit;
287 } else {
288 setEventMessages($discount->error, $discount->errors, 'errors');
289 $db->rollback();
290 }
291}
292
293
294/*
295 * View
296 */
297
298$form = new Form($db);
299$facturestatic = new Facture($db);
300$facturefournstatic = new FactureFournisseur($db);
301$tmpuser = new User($db);
302
303llxHeader('', $langs->trans("GlobalDiscount"));
304
305if ($socid > 0) {
306 // Retrieve third-party data via the object
307 $object = new Societe($db);
308 $object->fetch($socid);
309
310 $isCustomer = $object->client == 1 || $object->client == 3;
311 $isSupplier = $object->fournisseur == 1;
312
313 // Display tabs
314
316
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.'">';
321
322 print dol_get_fiche_head($head, 'absolutediscount', $langs->trans("ThirdParty"), -1, 'company');
323
324 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
325
326 dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
327
328 print '<div class="fichecenter">';
329
330 print '<div class="underbanner clearboth"></div>';
331
332 if (!$isCustomer && !$isSupplier) {
333 print '<p class="opacitymedium">'.$langs->trans('ThirdpartyIsNeitherCustomerNorClientSoCannotHaveDiscounts').'</p>';
334
335 print dol_get_fiche_end();
336
337 print '</form>';
338
339 llxFooter();
340 $db->close();
341 exit;
342 }
343
344
345 print '<div class="div-table-responsive-no-min">';
346 print '<table class="border centpercent tableforfield borderbottom">';
347
348 if ($isCustomer) { // Calcul avoirs client en cours
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"; // Exclude supplier discounts
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);
358 if ($resql) {
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);
363 }
364 }
365 } else {
366 dol_print_error($db);
367 }
368
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)) { // No need to show this for external users
372 print $form->textwithpicto('', $langs->trans("CustomerAbsoluteDiscountMy").': '.price($remise_user, 1, $langs, 1, -1, -1, $conf->currency).' '.$langs->trans("HT"));
373 }
374 print '</td></tr>';
375 }
376
377 if ($isSupplier) {
378 // Calcul avoirs fournisseur en cours
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"; // Exclude customer discounts
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);
388 if ($resql) {
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);
393 }
394 }
395 } else {
396 dol_print_error($db);
397 }
398
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)) { // No need to show this for external users
402 print $form->textwithpicto('', $langs->trans("SupplierAbsoluteDiscountMy").' : '.price($remise_user, 1, $langs, 1, -1, -1, $conf->currency).' '.$langs->trans("HT"));
403 }
404 print '</td></tr>';
405 }
406
407 print '</table>';
408 print '</div>';
409
410 print '</div>'; // close fichecenter
411
412 print dol_get_fiche_end();
413
414
415 if ($action == 'create_remise') {
416 if ($user->hasRight('societe', 'creer')) {
417 print '<br>';
418
419 $discount_type = GETPOSTISSET('discount_type') ? GETPOST('discount_type', 'alpha') : 0;
420 if ($isCustomer && $isSupplier) {
421 $discounttypelabel = $discount_type == 1 ? 'NewSupplierGlobalDiscount' : 'NewClientGlobalDiscount';
422 } else {
423 $discounttypelabel = 'NewGlobalDiscount';
424 }
425
426 print load_fiche_titre($langs->trans($discounttypelabel), '', '');
427
428 if ($isSupplier && $discount_type == 1) {
429 print '<input type="hidden" name="discount_type" value="1" />';
430 } else {
431 print '<input type="hidden" name="discount_type" value="0" />';
432 }
433
434 print dol_get_fiche_head();
435
436
437 print '<div class="div-table-responsive-no-min">';
438 print '<table class="border centpercent">';
439 /*if ($isCustomer && $isSupplier) {
440 print '<tr><td class="titlefield fieldrequired">'.$langs->trans('DiscountType').'</td>';
441 print '<td><input type="radio" name="discount_type" id="discount_type_0" '.($discount_type != 1 ? 'checked="checked" ' : '').'value="0"/> <label for="discount_type_0">'.$langs->trans('Customer').'</label>';
442 print ' &nbsp; <input type="radio" name="discount_type" id="discount_type_1" '.($discount_type == 1 ? 'checked="checked" ' : '').'value="1"/> <label for="discount_type_1">'.$langs->trans('Supplier').'</label>';
443 print '</td></tr>';
444 }*/
445
446 // Amount
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">&nbsp;'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
450
451 // Price base (HT / TTC)
452 print '<tr><td class="titlefield">'.$langs->trans("PriceBase").'</td>';
453 print '<td>';
454 print $form->selectPriceBaseType(GETPOST("price_base_type"), "price_base_type");
455 print '</td></tr>';
456
457 // VAT
458 print '<tr><td>'.$langs->trans("VAT").'</td>';
459 print '<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);
461 print '</td></tr>';
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>';
464
465 print "</table>";
466 print '</div>';
467
468 print dol_get_fiche_end();
469 }
470
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 ' &nbsp; &nbsp; ';
476 print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
477 }
478 print '</div>';
479 print '<br>';
480 }
481 }
482
483 print '</form>';
484
485
486 print '<br>';
487
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);
490 }
491
492
493 /*
494 * List not consumed available credits (= linked to no invoice and no invoice line)
495 */
496
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());
501 } else {
502 $newcardbutton = '';
503 }
504
505 print load_fiche_titre($langs->trans("DiscountStillRemaining"), $newcardbutton);
506
507 if ($isCustomer) {
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());
509 if ($isSupplier) {
510 print '<div class="fichecenter">';
511 print '<div class="fichehalfleft fichehalfleft-lg">';
512 print load_fiche_titre($langs->trans("CustomerDiscounts"), $newcardbutton, '');
513 }
514
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"; // Eliminate supplier discounts
527 $sql .= " AND (rc.fk_facture_line IS NULL AND rc.fk_facture IS NULL)";
528 $sql .= " ORDER BY rc.datec DESC";
529
530 $resql = $db->query($sql);
531 if ($resql) {
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>'; // Need 120+ for format with AM/PM
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>';
539 if (isModEnabled('multicurrency')) {
540 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountHT")).'">'.$langs->trans("MulticurrencyAmountHT").'</td>';
541 }
542 print '<td class="right">'.$langs->trans("VATRate").'</td>';
543 print '<td class="right">'.$langs->trans("AmountTTC").'</td>';
544 if (isModEnabled('multicurrency')) {
545 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountTTC")).'">'.$langs->trans("MulticurrencyAmountTTC").'</td>';
546 }
547 print '<td width="100" class="center">'.$langs->trans("DiscountOfferedBy").'</td>';
548 print '<td width="50">&nbsp;</td>';
549 print '</tr>';
550
551 $showconfirminfo = array();
552
553 $i = 0;
554 $num = $db->num_rows($resql);
555 if ($num > 0) {
556 while ($i < $num) {
557 $obj = $db->fetch_object($resql);
558
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;
565
566 print '<tr class="oddeven">';
567
568 print '<td>'.dol_print_date($db->jdate($obj->dc), 'dayhour', 'tzuserrel').'</td>';
569
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);
576 print '</td>';
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);
583 print '</td>';
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);
590 print '</td>';
591 } else {
592 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).'">';
593 print dol_escape_htmltag($obj->description);
594 print '</td>';
595 }
596
597 print '<td class="nowrap"><span class="opacitymedium">'.$langs->trans("NotConsumed").'</span></td>';
598
599 print '<td class="right nowraponall amount">'.price($obj->amount_ht).'</td>';
600
601 if (isModEnabled('multicurrency')) {
602 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).'</td>';
603 }
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>';
606 if (isModEnabled('multicurrency')) {
607 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ttc).'</td>';
608 }
609 print '<td class="tdoverflowmax100">';
610 //print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"), 'user').' '.$obj->login.'</a>';
611 print $tmpuser->getNomUrl(-1);
612 print '</td>';
613
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>';
618 print '</td>';
619 } else {
620 print '<td>&nbsp;</td>';
621 }
622 print '</tr>';
623
624 if ($action == 'split' && GETPOST('remid') == $obj->rowid) {
625 $showconfirminfo['rowid'] = $obj->rowid;
626 $showconfirminfo['amount_ttc'] = $obj->amount_ttc;
627 }
628 $i++;
629 }
630 } else {
631 $colspan = 8;
632 if (isModEnabled('multicurrency')) {
633 $colspan += 2;
634 }
635 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
636 }
637 $db->free($resql);
638 print "</table>";
639 print '</div>';
640
641 if (count($showconfirminfo)) {
642 if (getDolGlobalInt('DISCOUNT_SPLIT_MORE_THAN_TWO_PARTS') && !getDolGlobalInt('MAIN_DISABLE_JAVASCRIPT')) {
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">';
644
645 //
646 print '<input type="hidden" name="action" value="confirm_split_more">';
647 print '<input type="hidden" name="token" value="'.newToken().'">';
648
649 print '<div class="div-table-responsive-no-min">';
650 print '<table class="valid centpercent">';
651 print '<tbody>';
652
653 // Title
654 print '<tr class="validtitre">';
655 print '<td class="validtitre" colspan="4">'.img_picto('', 'split', '', 0, 0, 0, '', 'paddingright').' '.$langs->trans('SplitDiscountTitle').'</td>';
656 print '</tr>';
657
658 print '<tr class="valid">';
659 print '<td class="" colspan="4">'.$langs->trans('TypeAmountOfEachNewDiscountSplit').'</td>';
660 print '</tr>';
661
662 //
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);
667
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>';
673 print '</tr>';
674
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>';
680 print '</tr>';
681 } else {
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>';
691 print '</tr>';
692 }
693 }
694
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>';
699 print '</tr>';
700
701 print '<tr class="valid">';
702 print '<td colspan="3">&nbsp;</td>';
703 print '</tr>';
704
705 //
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>';
710 print '</tr>';
711
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>';
716 print '</tr>';
717
718 print '</tbody>';
719 print '</table>';
720 print '</div>';
721 print '</form>';
722 print '<br>';
723 ?>
724 <script nonce="<?php print getNonce(); ?>" type="text/javascript">
725 $(document).ready(function () {
726
727 let formsplit = $('#formsplit');
728 let totaltosplit = formsplit.data('totaltosplit');
729
730 function calcRemainToPay(){
731 let items = formsplit.find('.splitinput');
732 let remaintosplit = totaltosplit;
733
734 items.each(function(e){
735 var itemvalue = parseFloat($(this).val().replace(',', '.'));
736 if (isNaN(itemvalue)) {
737 itemvalue = 0;
738 }
739 remaintosplit -= itemvalue;
740 });
741
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);
749 }
750 }
751
752 // Addline
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);
766 calcRemainToPay();
767 });
768
769 // Update line
770 $(document).on('change', '.splitinput', function(){
771 calcRemainToPay();
772 });
773
774 // Delete line
775 $(document).on('click', '.icon-delsplitline', function(){
776 let num = parseInt($(this).data('splitline'));
777 let numBefore = num - 1;
778 if (numBefore > 2) {
779 $('#splitline-'+numBefore).find('.delsplitline').html('<span class="fas fa-trash icon-delsplitline" data-splitline="'+ numBefore +'"></span>');
780 }
781 $('#splitline-'+num).remove();
782 calcRemainToPay();
783 });
784 });
785 </script>
786 <?php
787 } else {
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')
794 );
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);
797 }
798 }
799 } else {
800 dol_print_error($db);
801 }
802 }
803
804 if ($isSupplier) {
805 if ($isCustomer) {
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());
807 print '</div>'; // class="fichehalfleft"
808 print '<div class="fichehalfright fichehalfright-lg">';
809 print load_fiche_titre($langs->trans("SupplierDiscounts"), $newcardbutton, '');
810 }
811
812 /*
813 * List of fixed supplier discounts still available (=not linked to any invoice nor invoice line)
814 */
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"; // Eliminate customer discounts
827 $sql .= " AND (rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_line IS NULL)";
828 $sql .= " ORDER BY rc.datec DESC";
829
830 $resql = $db->query($sql);
831 if ($resql) {
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>'; // Need 120+ for format with AM/PM
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>';
839 if (isModEnabled('multicurrency')) {
840 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountHT")).'">'.$langs->trans("MulticurrencyAmountHT").'</td>';
841 }
842 print '<td class="right">'.$langs->trans("VATRate").'</td>';
843 print '<td class="right">'.$langs->trans("AmountTTC").'</td>';
844 if (isModEnabled('multicurrency')) {
845 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountTTC")).'">'.$langs->trans("MulticurrencyAmountTTC").'</td>';
846 }
847 print '<td width="100" class="center">'.$langs->trans("DiscountOfferedBy").'</td>';
848 print '<td width="50">&nbsp;</td>';
849 print '</tr>';
850
851 $showconfirminfo = array();
852
853 $i = 0;
854 $num = $db->num_rows($resql);
855 if ($num > 0) {
856 while ($i < $num) {
857 $obj = $db->fetch_object($resql);
858
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;
865
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);
874 print '</td>';
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);
881 print '</td>';
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);
888 print '</td>';
889 } else {
890 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).'">';
891 print dol_escape_htmltag($obj->description);
892 print '</td>';
893 }
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>';
896 if (isModEnabled('multicurrency')) {
897 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).'</td>';
898 }
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>';
901 if (isModEnabled('multicurrency')) {
902 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ttc).'</td>';
903 }
904 print '<td class="tdoverflowmax100">';
905 print $tmpuser->getNomUrl(-1);
906 print '</td>';
907
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>';
912 print '</td>';
913 } else {
914 print '<td>&nbsp;</td>';
915 }
916 print '</tr>';
917
918 if ($action == 'split' && GETPOST('remid') == $obj->rowid) {
919 $showconfirminfo['rowid'] = $obj->rowid;
920 $showconfirminfo['amount_ttc'] = $obj->amount_ttc;
921 }
922 $i++;
923 }
924 } else {
925 $colspan = 8;
926 if (isModEnabled('multicurrency')) {
927 $colspan += 2;
928 }
929 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
930 }
931 $db->free($resql);
932 print "</table>";
933 print '</div>';
934
935 if (count($showconfirminfo)) {
936 if (getDolGlobalInt('DISCOUNT_SPLIT_MORE_THAN_TWO_PARTS') && !getDolGlobalInt('MAIN_DISABLE_JAVASCRIPT')) {
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">';
938
939 //
940 print '<input type="hidden" name="action" value="confirm_split_more">';
941 print '<input type="hidden" name="token" value="'.newToken().'">';
942
943 print '<div class="div-table-responsive-no-min">';
944 print '<table class="valid centpercent">';
945 print '<tbody>';
946
947 // Title
948 print '<tr class="validtitre">';
949 print '<td class="validtitre" colspan="4">'.img_picto('', 'split', '', 0, 0, 0, '', 'paddingright').' '.$langs->trans('SplitDiscountTitle').'</td>';
950 print '</tr>';
951
952 print '<tr class="valid">';
953 print '<td class="" colspan="4">'.$langs->trans('TypeAmountOfEachNewDiscountSplit').'</td>';
954 print '</tr>';
955
956 //
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);
961
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>';
967 print '</tr>';
968
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>';
974 print '</tr>';
975 } else {
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>';
985 print '</tr>';
986 }
987 }
988
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>';
993 print '</tr>';
994
995 print '<tr class="valid">';
996 print '<td colspan="3">&nbsp;</td>';
997 print '</tr>';
998
999 //
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>';
1004 print '</tr>';
1005
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>';
1010 print '</tr>';
1011
1012 print '</tbody>';
1013 print '</table>';
1014 print '</div>';
1015 print '</form>';
1016 print '<br>';
1017 ?>
1018 <script nonce="<?php print getNonce(); ?>" type="text/javascript">
1019 $(document).ready(function () {
1020
1021 let formsplit = $('#formsplit');
1022 let totaltosplit = formsplit.data('totaltosplit');
1023
1024 function calcRemainToPay(){
1025 let items = formsplit.find('.splitinput');
1026 let remaintosplit = totaltosplit;
1027
1028 items.each(function(e){
1029 var itemvalue = parseFloat($(this).val().replace(',', '.'));
1030 if (isNaN(itemvalue)) {
1031 itemvalue = 0;
1032 }
1033 remaintosplit -= itemvalue;
1034 });
1035
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);
1043 }
1044 }
1045
1046 // Addline
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);
1060 calcRemainToPay();
1061 });
1062
1063 // Update line
1064 $(document).on('change', '.splitinput', function(){
1065 calcRemainToPay();
1066 });
1067
1068 // Delete line
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>');
1074 }
1075 $('#splitline-'+num).remove();
1076 calcRemainToPay();
1077 });
1078 });
1079 </script>
1080 <?php
1081 } else {
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')
1088 );
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);
1091 }
1092 }
1093 } else {
1094 dol_print_error($db);
1095 }
1096
1097 if ($isCustomer) {
1098 print '</div>'; // class="fichehalfright"
1099 print '</div>'; // class="fichecenter"
1100 }
1101 }
1102
1103 print '<div class="clearboth"></div><br><br>';
1104
1105 /*
1106 * List discount consumed (=linked to an invoice line or invoice)
1107 */
1108
1109 print load_fiche_titre($langs->trans("DiscountAlreadyCounted"));
1110
1111 if ($isCustomer) {
1112 if ($isSupplier) {
1113 print '<div class="fichecenter">';
1114 print '<div class="fichehalfleft fichehalfleft-lg">';
1115 print load_fiche_titre($langs->trans("CustomerDiscounts"), '', '');
1116 }
1117
1118 // Discount linked to invoice lines
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"; // Eliminate supplier discounts
1135 $sql .= " ORDER BY dc DESC";
1136 //$sql.= " UNION ";
1137 // Discount linked to invoices
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"; // Eliminate supplier discounts
1152 $sql2 .= " ORDER BY dc DESC";
1153
1154 $resql = $db->query($sql);
1155 $resql2 = null;
1156 if ($resql) {
1157 $resql2 = $db->query($sql2);
1158 }
1159 if ($resql2) {
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>'; // Need 120+ for format with AM/PM
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>';
1167 if (isModEnabled('multicurrency')) {
1168 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountHT")).'">'.$langs->trans("MulticurrencyAmountHT").'</td>';
1169 }
1170 print '<td class="right">'.$langs->trans("VATRate").'</td>';
1171 print '<td class="right">'.$langs->trans("AmountTTC").'</td>';
1172 if (isModEnabled('multicurrency')) {
1173 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountTTC")).'">'.$langs->trans("MulticurrencyAmountTTC").'</td>';
1174 }
1175 print '<td width="100" class="center">'.$langs->trans("Author").'</td>';
1176 print '<td width="50">&nbsp;</td>';
1177 print '</tr>';
1178
1179 $tab_sqlobj = array();
1180 $tab_sqlobjOrder = array();
1181 $num = $db->num_rows($resql);
1182 if ($num > 0) {
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);
1187 }
1188 }
1189 $db->free($resql);
1190
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);
1196 }
1197 $db->free($resql2);
1198 $array1_sort_order = SORT_DESC;
1199 array_multisort($tab_sqlobjOrder, $array1_sort_order, $tab_sqlobj);
1200
1201 $num = count($tab_sqlobj);
1202 if ($num > 0) {
1203 $i = 0;
1204 while ($i < $num) {
1205 $obj = array_shift($tab_sqlobj);
1206
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;
1213
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);
1222 print '</td>';
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);
1229 print '</td>';
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);
1236 print '</td>';
1237 } else {
1238 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).'">';
1239 print dol_escape_htmltag($obj->description);
1240 print '</td>';
1241 }
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>';
1245 }
1246 print '</td>';
1247 print '<td class="right nowraponall amount">'.price($obj->amount_ht).'</td>';
1248 if (isModEnabled('multicurrency')) {
1249 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).'</td>';
1250 }
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>';
1253 if (isModEnabled('multicurrency')) {
1254 print '<td class="right">'.price($obj->multicurrency_amount_ttc).'</td>';
1255 }
1256 print '<td class="tdoverflowmax100">';
1257 print $tmpuser->getNomUrl(-1);
1258 print '</td>';
1259
1260 print '<td>&nbsp;</td>';
1261 print '</tr>';
1262 $i++;
1263 }
1264 } else {
1265 $colspan = 8;
1266 if (isModEnabled('multicurrency')) {
1267 $colspan += 2;
1268 }
1269 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
1270 }
1271
1272 print "</table>";
1273 print '</div>';
1274 } else {
1275 dol_print_error($db);
1276 }
1277 }
1278
1279 if ($isSupplier) {
1280 if ($isCustomer) {
1281 print '</div>'; // class="fichehalfleft"
1282 print '<div class="fichehalfright fichehalfright-lg">';
1283 print load_fiche_titre($langs->trans("SupplierDiscounts"), '', '');
1284 }
1285
1286 // Discount linked to invoice lines
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"; // Eliminate customer discounts
1304 $sql .= " ORDER BY dc DESC";
1305 //$sql.= " UNION ";
1306 // Discount linked to invoices
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"; // Eliminate customer discounts
1322 $sql2 .= " ORDER BY dc DESC";
1323
1324 $resql = $db->query($sql);
1325 $resql2 = null;
1326 if ($resql) {
1327 $resql2 = $db->query($sql2);
1328 }
1329 if ($resql2) {
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>'; // Need 120+ for format with AM/PM
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>';
1337 if (isModEnabled('multicurrency')) {
1338 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountHT")).'">'.$langs->trans("MulticurrencyAmountHT").'</td>';
1339 }
1340 print '<td class="right">'.$langs->trans("VATRate").'</td>';
1341 print '<td class="right">'.$langs->trans("AmountTTC").'</td>';
1342 if (isModEnabled('multicurrency')) {
1343 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountTTC")).'">'.$langs->trans("MulticurrencyAmountTTC").'</td>';
1344 }
1345 print '<td width="100" class="center">'.$langs->trans("Author").'</td>';
1346 print '<td width="50">&nbsp;</td>';
1347 print '</tr>';
1348
1349 $tab_sqlobj = array();
1350 $tab_sqlobjOrder = array();
1351 $num = $db->num_rows($resql);
1352 if ($num > 0) {
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);
1357 }
1358 }
1359 $db->free($resql);
1360
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);
1366 }
1367 $db->free($resql2);
1368 $array1_sort_order = SORT_DESC;
1369 array_multisort($tab_sqlobjOrder, $array1_sort_order, $tab_sqlobj);
1370
1371 $num = count($tab_sqlobj);
1372 if ($num > 0) {
1373 $i = 0;
1374 while ($i < $num) {
1375 $obj = array_shift($tab_sqlobj);
1376
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;
1383
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);
1392 print '</td>';
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);
1399 print '</td>';
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);
1406 print '</td>';
1407 } else {
1408 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).'">';
1409 print dol_escape_htmltag($obj->description);
1410 print '</td>';
1411 }
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>';
1415 }
1416 print '</td>';
1417 print '<td class="right nowraponall amount">'.price($obj->amount_ht).'</td>';
1418 if (isModEnabled('multicurrency')) {
1419 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).'</td>';
1420 }
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>';
1423 if (isModEnabled('multicurrency')) {
1424 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ttc).'</td>';
1425 }
1426 print '<td class="tdoverflowmax100">';
1427 print $tmpuser->getNomUrl(-1);
1428 print '</td>';
1429
1430 print '<td>&nbsp;</td>';
1431
1432 print '</tr>';
1433 $i++;
1434 }
1435 } else {
1436 $colspan = 8;
1437 if (isModEnabled('multicurrency')) {
1438 $colspan += 2;
1439 }
1440 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
1441 }
1442
1443 print "</table>";
1444 print '</div>';
1445 } else {
1446 dol_print_error($db);
1447 }
1448
1449 if ($isCustomer) {
1450 print '</div>'; // class="fichehalfright"
1451 print '</div>'; // class="fichecenter"
1452 }
1453 }
1454}
1455
1456// End of page
1457llxFooter();
1458$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:280
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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.
Definition wrapper.php:73
Class to manage absolute discounts.
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage generation of HTML components Only common components must be here.
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.
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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.
Definition html.lib.php:540
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.
Definition html.lib.php:738
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)
Definition html.lib.php:181
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.