dolibarr 24.0.2
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-2025 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 }
169 } else {
170 $db->rollback();
171 }
172 }
173}
174
175if ($action == 'confirm_split' && GETPOST("confirm", "alpha") == 'yes' && $permissiontocreate) {
176 $amount_ttc_1 = GETPOST('amount_ttc_1', 'alpha');
177 $amount_ttc_1 = price2num($amount_ttc_1);
178 $amount_ttc_2 = GETPOST('amount_ttc_2', 'alpha');
179 $amount_ttc_2 = price2num($amount_ttc_2);
180
181 $error = 0;
182 $remid = (GETPOSTINT("remid") ? GETPOSTINT("remid") : 0);
183 $discount = new DiscountAbsolute($db);
184 $res = $discount->fetch($remid);
185 if (!($res > 0)) {
186 $error++;
187 setEventMessages($langs->trans("ErrorFailedToLoadDiscount"), null, 'errors');
188 } elseif ($discount->fk_soc != $socid) {
189 // The discount must belong to the thirdparty of the page
190 $error++;
191 setEventMessages($langs->trans("ErrorRecordNotFound"), null, 'errors');
192 }
193 if (!$error && price2num((float) $amount_ttc_1 + (float) $amount_ttc_2, 'MT') != $discount->amount_ttc) {
194 $error++;
195 setEventMessages($langs->trans("TotalOfTwoDiscountMustEqualsOriginal"), null, 'errors');
196 }
197 if (!$error && $discount->fk_facture_line) {
198 $error++;
199 setEventMessages($langs->trans("ErrorCantSplitAUsedDiscount"), null, 'errors');
200 }
201 if (!$error) {
202 // Split a discount in two
203 $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.
204 $newdiscount1 = $newDiscounts[0];
205 $newdiscount2 = $newDiscounts[1];
206
207 $db->begin();
208
209 $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
210 // 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
211 $discount->fk_invoice_supplier_source = 0;
212 $res = $discount->delete($user);
213 $newid1 = $newdiscount1->create($user);
214 $newid2 = $newdiscount2->create($user);
215 if ($res > 0 && $newid1 > 0 && $newid2 > 0) {
216 $db->commit();
217 $query = ['id' => $id, 'backtopage' => $backtopage];
218 header("Location: " . dolBuildUrl($_SERVER["PHP_SELF"], $query)); // To avoid pb with back
219 exit;
220 } else {
221 $db->rollback();
222 }
223 }
224}
225
226if ($action == 'setremise' && $permissiontocreate) {
227 $amount = price2num(GETPOST('amount', 'alpha'), '', 2);
228 $desc = GETPOST('desc', 'alpha');
229 $tva_tx = GETPOST('tva_tx', 'alpha');
230 $discount_type = GETPOSTISSET('discount_type') ? GETPOST('discount_type', 'alpha') : 0;
231 $price_base_type = GETPOST('price_base_type', 'alpha');
232
233 if ($amount > 0) {
234 $error = 0;
235 if (empty($desc)) {
236 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ReasonDiscount")), null, 'errors');
237 $error++;
238 }
239
240 if (!$error) {
241 $soc = new Societe($db);
242 $soc->fetch($id);
243 $discountid = $soc->set_remise_except((float) $amount, $user, $desc, $tva_tx, $discount_type, $price_base_type);
244
245 if ($discountid > 0) {
246 if (!empty($backtopage)) {
247 header("Location: ".$backtopage.'&discountid='.((int) $discountid));
248 exit;
249 } else {
250 header("Location: remx.php?id=".((int) $id));
251 exit;
252 }
253 } else {
254 $error++;
255 setEventMessages($soc->error, $soc->errors, 'errors');
256 }
257 }
258 } else {
259 setEventMessages($langs->trans("ErrorFieldFormat", $langs->transnoentitiesnoconv("AmountHT")), null, 'errors');
260 }
261}
262
263if (GETPOST('action', 'aZ09') == 'confirm_remove' && GETPOST("confirm") == 'yes' && $permissiontocreate) {
264 $db->begin();
265
266 $discount = new DiscountAbsolute($db);
267 $result = $discount->fetch(GETPOSTINT("remid"));
268 if ($result > 0 && $discount->fk_soc == $socid) {
269 $result = $discount->delete($user);
270 } else {
271 // The discount must belong to the thirdparty of the page
272 $result = -1;
273 setEventMessages($langs->trans("ErrorRecordNotFound"), null, 'errors');
274 }
275 if ($result > 0) {
276 $db->commit();
277 header("Location: " . dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $id])); // To avoid pb with back
278 exit;
279 } else {
280 setEventMessages($discount->error, $discount->errors, 'errors');
281 $db->rollback();
282 }
283}
284
285
286/*
287 * View
288 */
289
290$form = new Form($db);
291$facturestatic = new Facture($db);
292$facturefournstatic = new FactureFournisseur($db);
293$tmpuser = new User($db);
294
295llxHeader('', $langs->trans("GlobalDiscount"));
296
297if ($socid > 0) {
298 // On recupere les donnees societes par l'objet
299 $object = new Societe($db);
300 $object->fetch($socid);
301
302 $isCustomer = $object->client == 1 || $object->client == 3;
303 $isSupplier = $object->fournisseur == 1;
304
305 // Display tabs
306
308
309 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
310 print '<input type="hidden" name="token" value="'.newToken().'">';
311 print '<input type="hidden" name="action" value="setremise">';
312 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
313
314 print dol_get_fiche_head($head, 'absolutediscount', $langs->trans("ThirdParty"), -1, 'company');
315
316 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
317
318 dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
319
320 print '<div class="fichecenter">';
321
322 print '<div class="underbanner clearboth"></div>';
323
324 if (!$isCustomer && !$isSupplier) {
325 print '<p class="opacitymedium">'.$langs->trans('ThirdpartyIsNeitherCustomerNorClientSoCannotHaveDiscounts').'</p>';
326
327 print dol_get_fiche_end();
328
329 print '</form>';
330
331 llxFooter();
332 $db->close();
333 exit;
334 }
335
336
337 print '<div class="div-table-responsive-no-min">';
338 print '<table class="border centpercent tableforfield borderbottom">';
339
340 if ($isCustomer) { // Calcul avoirs client en cours
341 $remise_all = $remise_user = 0;
342 $sql = "SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
343 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
344 $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
345 $sql .= " AND rc.entity = ".((int) $conf->entity);
346 $sql .= " AND discount_type = 0"; // Exclude supplier discounts
347 $sql .= " AND (fk_facture_line IS NULL AND fk_facture IS NULL)";
348 $sql .= " GROUP BY rc.fk_user";
349 $resql = $db->query($sql);
350 if ($resql) {
351 while ($obj = $db->fetch_object($resql)) {
352 $remise_all += (!empty($obj->amount) ? $obj->amount : 0);
353 if (!empty($obj->fk_user) && $obj->fk_user == $user->id) {
354 $remise_user += (!empty($obj->amount) ? $obj->amount : 0);
355 }
356 }
357 } else {
359 }
360
361 print '<tr><td class="titlefieldmiddle">'.$langs->trans("CustomerAbsoluteDiscountAllUsers").'</td>';
362 print '<td class="amount">'.price($remise_all, 1, $langs, 1, -1, -1, $conf->currency).' '.$langs->trans("HT");
363 if (empty($user->fk_soc)) { // No need to show this for external users
364 print $form->textwithpicto('', $langs->trans("CustomerAbsoluteDiscountMy").': '.price($remise_user, 1, $langs, 1, -1, -1, $conf->currency).' '.$langs->trans("HT"));
365 }
366 print '</td></tr>';
367 }
368
369 if ($isSupplier) {
370 // Calcul avoirs fournisseur en cours
371 $remise_all = $remise_user = 0;
372 $sql = "SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
373 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
374 $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
375 $sql .= " AND rc.entity = ".((int) $conf->entity);
376 $sql .= " AND discount_type = 1"; // Exclude customer discounts
377 $sql .= " AND (fk_invoice_supplier_line IS NULL AND fk_invoice_supplier IS NULL)";
378 $sql .= " GROUP BY rc.fk_user";
379 $resql = $db->query($sql);
380 if ($resql) {
381 while ($obj = $db->fetch_object($resql)) {
382 $remise_all += (!empty($obj->amount) ? $obj->amount : 0);
383 if (!empty($obj->fk_user) && $obj->fk_user == $user->id) {
384 $remise_user += (!empty($obj->amount) ? $obj->amount : 0);
385 }
386 }
387 } else {
389 }
390
391 print '<tr><td class="titlefieldmiddle">'.$langs->trans("SupplierAbsoluteDiscountAllUsers").'</td>';
392 print '<td class="amount">'.price($remise_all, 1, $langs, 1, -1, -1, $conf->currency).' '.$langs->trans("HT");
393 if (empty($user->fk_soc)) { // No need to show this for external users
394 print $form->textwithpicto('', $langs->trans("SupplierAbsoluteDiscountMy").' : '.price($remise_user, 1, $langs, 1, -1, -1, $conf->currency).' '.$langs->trans("HT"));
395 }
396 print '</td></tr>';
397 }
398
399 print '</table>';
400 print '</div>';
401
402 print '</div>'; // close fichecenter
403
404 print dol_get_fiche_end();
405
406
407 if ($action == 'create_remise') {
408 if ($user->hasRight('societe', 'creer')) {
409 print '<br>';
410
411 $discount_type = GETPOSTISSET('discount_type') ? GETPOST('discount_type', 'alpha') : 0;
412 if ($isCustomer && $isSupplier) {
413 $discounttypelabel = $discount_type == 1 ? 'NewSupplierGlobalDiscount' : 'NewClientGlobalDiscount';
414 } else {
415 $discounttypelabel = 'NewGlobalDiscount';
416 }
417
418 print load_fiche_titre($langs->trans($discounttypelabel), '', '');
419
420 if ($isSupplier && $discount_type == 1) {
421 print '<input type="hidden" name="discount_type" value="1" />';
422 } else {
423 print '<input type="hidden" name="discount_type" value="0" />';
424 }
425
426 print dol_get_fiche_head();
427
428
429 print '<div class="div-table-responsive-no-min">';
430 print '<table class="border centpercent">';
431 /*if ($isCustomer && $isSupplier) {
432 print '<tr><td class="titlefield fieldrequired">'.$langs->trans('DiscountType').'</td>';
433 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>';
434 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>';
435 print '</td></tr>';
436 }*/
437
438 // Amount
439 print '<tr><td class="titlefield fieldrequired">'.$langs->trans("Amount").'</td>';
440 print '<td><input type="text" size="5" name="amount" value="'.price2num(GETPOST("amount")).'" autofocus>';
441 print '<span class="hideonsmartphone">&nbsp;'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
442
443 // Price base (HT / TTC)
444 print '<tr><td class="titlefield">'.$langs->trans("PriceBase").'</td>';
445 print '<td>';
446 print $form->selectPriceBaseType(GETPOST("price_base_type"), "price_base_type");
447 print '</td></tr>';
448
449 // VAT
450 print '<tr><td>'.$langs->trans("VAT").'</td>';
451 print '<td>';
452 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);
453 print '</td></tr>';
454 print '<tr><td class="fieldrequired" >'.$langs->trans("NoteReason").'</td>';
455 print '<td><input type="text" class="quatrevingtpercent" name="desc" value="'.GETPOST('desc', 'alphanohtml').'"></td></tr>';
456
457 print "</table>";
458 print '</div>';
459
460 print dol_get_fiche_end();
461 }
462
463 if ($user->hasRight('societe', 'creer')) {
464 print '<div class="center">';
465 print '<input type="submit" class="button" name="submit" value="'.$langs->trans("AddGlobalDiscount").'">';
466 if (!empty($backtopage)) {
467 print ' &nbsp; &nbsp; ';
468 print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
469 }
470 print '</div>';
471 print '<br>';
472 }
473 }
474
475 print '</form>';
476
477
478 print '<br>';
479
480 if ($action == 'remove') {
481 print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&remid='.GETPOST('remid'), $langs->trans('RemoveDiscount'), $langs->trans('ConfirmRemoveDiscount'), 'confirm_remove', '', 0, 1);
482 }
483
484
485 /*
486 * List not consumed available credits (= linked to no invoice and no invoice line)
487 */
488
489 if ($isCustomer && !$isSupplier) {
490 $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());
491 } elseif (!$isCustomer && $isSupplier) {
492 $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());
493 } else {
494 $newcardbutton = '';
495 }
496
497 print load_fiche_titre($langs->trans("DiscountStillRemaining"), $newcardbutton);
498
499 if ($isCustomer) {
500 $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());
501 if ($isSupplier) {
502 print '<div class="fichecenter">';
503 print '<div class="fichehalfleft fichehalfleft-lg">';
504 print load_fiche_titre($langs->trans("CustomerDiscounts"), $newcardbutton, '');
505 }
506
507 $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
508 $sql .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
509 $sql .= " rc.datec as dc, rc.description,";
510 $sql .= " rc.fk_facture_source,";
511 $sql .= " u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
512 $sql .= " fa.ref as ref, fa.type as type";
513 $sql .= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."societe_remise_except as rc";
514 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
515 $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
516 $sql .= " AND rc.entity = ".((int) $conf->entity);
517 $sql .= " AND u.rowid = rc.fk_user";
518 $sql .= " AND rc.discount_type = 0"; // Eliminate supplier discounts
519 $sql .= " AND (rc.fk_facture_line IS NULL AND rc.fk_facture IS NULL)";
520 $sql .= " ORDER BY rc.datec DESC";
521
522 $resql = $db->query($sql);
523 if ($resql) {
524 print '<div class="div-table-responsive-no-min">';
525 print '<table class="noborder centpercent">';
526 print '<tr class="liste_titre">';
527 print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
528 print '<td>'.$langs->trans("ReasonDiscount").'</td>';
529 print '<td class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
530 print '<td class="right">'.$langs->trans("AmountHT").'</td>';
531 if (isModEnabled('multicurrency')) {
532 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountHT")).'">'.$langs->trans("MulticurrencyAmountHT").'</td>';
533 }
534 print '<td class="right">'.$langs->trans("VATRate").'</td>';
535 print '<td class="right">'.$langs->trans("AmountTTC").'</td>';
536 if (isModEnabled('multicurrency')) {
537 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountTTC")).'">'.$langs->trans("MulticurrencyAmountTTC").'</td>';
538 }
539 print '<td width="100" class="center">'.$langs->trans("DiscountOfferedBy").'</td>';
540 print '<td width="50">&nbsp;</td>';
541 print '</tr>';
542
543 $showconfirminfo = array();
544
545 $i = 0;
546 $num = $db->num_rows($resql);
547 if ($num > 0) {
548 while ($i < $num) {
549 $obj = $db->fetch_object($resql);
550
551 $tmpuser->id = $obj->user_id;
552 $tmpuser->login = $obj->login;
553 $tmpuser->firstname = $obj->firstname;
554 $tmpuser->lastname = $obj->lastname;
555 $tmpuser->photo = $obj->photo;
556 $tmpuser->status = $obj->status;
557
558 print '<tr class="oddeven">';
559
560 print '<td>'.dol_print_date($db->jdate($obj->dc), 'dayhour', 'tzuserrel').'</td>';
561
562 if (preg_match('/\‍(CREDIT_NOTE\‍)/', $obj->description)) {
563 print '<td class="tdoverflowmax100">';
564 $facturestatic->id = $obj->fk_facture_source;
565 $facturestatic->ref = $obj->ref;
566 $facturestatic->type = $obj->type;
567 print preg_replace('/\‍(CREDIT_NOTE\‍)/', $langs->trans("CreditNote"), $obj->description).'<br>'.$facturestatic->getNomURl(1);
568 print '</td>';
569 } elseif (preg_match('/\‍(DEPOSIT\‍)/', $obj->description)) {
570 print '<td class="tdoverflowmax100">';
571 $facturestatic->id = $obj->fk_facture_source;
572 $facturestatic->ref = $obj->ref;
573 $facturestatic->type = $obj->type;
574 print preg_replace('/\‍(DEPOSIT\‍)/', $langs->trans("InvoiceDeposit"), $obj->description).'<br>'.$facturestatic->getNomURl(1);
575 print '</td>';
576 } elseif (preg_match('/\‍(EXCESS RECEIVED\‍)/', $obj->description)) {
577 print '<td class="tdoverflowmax100">';
578 $facturestatic->id = $obj->fk_facture_source;
579 $facturestatic->ref = $obj->ref;
580 $facturestatic->type = $obj->type;
581 print preg_replace('/\‍(EXCESS RECEIVED\‍)/', $langs->trans("ExcessReceived"), $obj->description).'<br>'.$facturestatic->getNomURl(1);
582 print '</td>';
583 } else {
584 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).'">';
585 print dol_escape_htmltag($obj->description);
586 print '</td>';
587 }
588
589 print '<td class="nowrap"><span class="opacitymedium">'.$langs->trans("NotConsumed").'</span></td>';
590
591 print '<td class="right nowraponall amount">'.price($obj->amount_ht).'</td>';
592
593 if (isModEnabled('multicurrency')) {
594 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).'</td>';
595 }
596 print '<td class="right nowraponall">'.vatrate($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), true).'</td>';
597 print '<td class="right nowraponall amount">'.price($obj->amount_ttc).'</td>';
598 if (isModEnabled('multicurrency')) {
599 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ttc).'</td>';
600 }
601 print '<td class="tdoverflowmax100">';
602 //print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"), 'user').' '.$obj->login.'</a>';
603 print $tmpuser->getNomUrl(-1);
604 print '</td>';
605
606 if ($user->hasRight('societe', 'creer') || $user->hasRight('facture', 'creer')) {
607 print '<td class="center nowraponall">';
608 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>';
609 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>';
610 print '</td>';
611 } else {
612 print '<td>&nbsp;</td>';
613 }
614 print '</tr>';
615
616 if ($action == 'split' && GETPOST('remid') == $obj->rowid) {
617 $showconfirminfo['rowid'] = $obj->rowid;
618 $showconfirminfo['amount_ttc'] = $obj->amount_ttc;
619 }
620 $i++;
621 }
622 } else {
623 $colspan = 8;
624 if (isModEnabled('multicurrency')) {
625 $colspan += 2;
626 }
627 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
628 }
629 $db->free($resql);
630 print "</table>";
631 print '</div>';
632
633 if (count($showconfirminfo)) {
634 if (getDolGlobalInt('DISCOUNT_SPLIT_MORE_THAN_TWO_PARTS') && !getDolGlobalInt('MAIN_DISABLE_JAVASCRIPT')) {
635 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&remid='.$showconfirminfo['rowid'].'" id="formsplit" data-totaltosplit="'.$showconfirminfo['amount_ttc'].'" data-remaintosplit="0">';
636
637 //
638 print '<input type="hidden" name="action" value="confirm_split_more">';
639 print '<input type="hidden" name="token" value="'.newToken().'">';
640
641 print '<div class="div-table-responsive-no-min">';
642 print '<table class="valid centpercent">';
643 print '<tbody>';
644
645 // Title
646 print '<tr class="validtitre">';
647 print '<td class="validtitre" colspan="4">'.img_picto('', 'split', '', 0, 0, 0, '', 'paddingright').' '.$langs->trans('SplitDiscountTitle').'</td>';
648 print '</tr>';
649
650 print '<tr class="valid">';
651 print '<td class="" colspan="4">'.$langs->trans('TypeAmountOfEachNewDiscountSplit').'</td>';
652 print '</tr>';
653
654 //
655 if (empty($splitamounts)) {
656 $amount1 = price2num($showconfirminfo['amount_ttc'] / 2, 'MT');
657 $amount2 = ($showconfirminfo['amount_ttc'] - (float) $amount1);
658 $remaintosplit = (float) $showconfirminfo['amount_ttc'] - ((float) $amount1 + (float) $amount2);
659
660 print '<tr class="valid splitline" id="splitline-1">';
661 print '<td class="right bold">'.$langs->trans('AmountTTC').' 1:</td>';
662 print '<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts[1]" value="'.$amount1.'"></td>';
663 print '<td class="right delsplitline"></td>';
664 print '<td class="right"></td>';
665 print '</tr>';
666
667 print '<tr class="valid splitline" id="splitline-2">';
668 print '<td class="right bold">'.$langs->trans('AmountTTC').' 2:</td>';
669 print '<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts[2]" value="'.$amount2.'"></td>';
670 print '<td class="right delsplitline"></td>';
671 print '<td class="right"></td>';
672 print '</tr>';
673 } else {
674 $nbSplitLines = count($splitamounts);
675 $remaintosplit = $showconfirminfo['amount_ttc'];
676 foreach ($splitamounts as $numero => $value) {
677 $remaintosplit -= (float) $value;
678 print '<tr class="valid splitline" id="splitline-'.$numero.'">';
679 print '<td class="right bold">'.$langs->trans('AmountTTC').' '.$numero.':</td>';
680 print '<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts['.$numero.']" value="'.$splitamounts[$numero].'"></td>';
681 print '<td class="right delsplitline"></td>';
682 print '<td class="right"></td>';
683 print '</tr>';
684 }
685 }
686
687 print '<tr class="valid">';
688 print '<td class="right"></td>';
689 print '<td class="right"><span class="fas fa-plus-circle" id="splitaddline" style="cursor:pointer;"></span></td>';
690 print '<td class="right"></td>';
691 print '</tr>';
692
693 print '<tr class="valid">';
694 print '<td colspan="3">&nbsp;</td>';
695 print '</tr>';
696
697 //
698 print '<tr class="valid">';
699 print '<td class="right bold">'.$langs->trans('RemainToSplit').':</td>';
700 print '<td class="right"><span id="remaintosplit">'.price($remaintosplit).'</span> '.$conf->currency.'</td>';
701 print '<td class="right"></td>';
702 print '</tr>';
703
704 print '<tr class="valid">';
705 print '<td class="right bold"></td>';
706 print '<td class="right"><input type="submit" class="button valignmiddle confirmvalidatebutton small nomarginright"></td>';
707 print '<td class="right"></td>';
708 print '</tr>';
709
710 print '</tbody>';
711 print '</table>';
712 print '</div>';
713 print '</form>';
714 print '<br>';
715 ?>
716 <script nonce="<?php print getNonce(); ?>" type="text/javascript">
717 $(document).ready(function () {
718
719 let formsplit = $('#formsplit');
720 let totaltosplit = formsplit.data('totaltosplit');
721
722 function calcRemainToPay(){
723 let items = formsplit.find('.splitinput');
724 let remaintosplit = totaltosplit;
725
726 items.each(function(e){
727 var itemvalue = parseFloat($(this).val().replace(',', '.'));
728 if (isNaN(itemvalue)) {
729 itemvalue = 0;
730 }
731 remaintosplit -= itemvalue;
732 });
733
734 let remaintosplitval = remaintosplit.toFixed(2);
735 console.log(remaintosplitval);
736 formsplit.data('remaintosplit', remaintosplitval);
737 formsplit.find('#remaintosplit').html(remaintosplitval.replace('.',','));
738 formsplit.find('input[type=submit]').prop('disabled', true);
739 if (remaintosplit == 0) {
740 formsplit.find('input[type=submit]').prop('disabled', false);
741 }
742 }
743
744 // Addline
745 $(document).on('click', '#splitaddline', function(){
746 let splitlines = formsplit.find('.splitline');
747 let numlines = splitlines.length;
748 let nextNum = numlines + 1;
749 let newInputValue = formsplit.data('remaintosplit');
750 $('#splitline-'+numlines).find('.delsplitline').html('');
751 var splitTemplate = '<tr class="splitline" id="splitline-'+ nextNum +'">';
752 splitTemplate += '<td class="right bold"><?php echo $langs->trans('AmountTTC'); ?> '+ nextNum +':</td>';
753 splitTemplate += '<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts['+ nextNum +']" value="'+ parseFloat(newInputValue) +'"></td>';
754 splitTemplate += '<td class="right delsplitline"><span class="fas fa-trash icon-delsplitline" data-splitline="'+ nextNum +'" style="cursor:pointer;"></span></td>';
755 splitTemplate += '<td class="right"></td>';
756 splitTemplate += '</tr>';
757 $('#splitline-'+numlines).after(splitTemplate);
758 calcRemainToPay();
759 });
760
761 // Update line
762 $(document).on('change', '.splitinput', function(){
763 calcRemainToPay();
764 });
765
766 // Delete line
767 $(document).on('click', '.icon-delsplitline', function(){
768 let num = parseInt($(this).data('splitline'));
769 let numBefore = num - 1;
770 if (numBefore > 2) {
771 $('#splitline-'+numBefore).find('.delsplitline').html('<span class="fas fa-trash icon-delsplitline" data-splitline="'+ numBefore +'"></span>');
772 }
773 $('#splitline-'+num).remove();
774 calcRemainToPay();
775 });
776 });
777 </script>
778 <?php
779 } else {
780 $amount1 = price2num($showconfirminfo['amount_ttc'] / 2, 'MT');
781 $amount2 = ($showconfirminfo['amount_ttc'] - (float) $amount1);
782 $formquestion = array(
783 'text' => $langs->trans('TypeAmountOfEachNewDiscount'),
784 0 => array('type' => 'text', 'name' => 'amount_ttc_1', 'label' => $langs->trans("AmountTTC").' 1', 'value' => $amount1, 'size' => '5'),
785 1 => array('type' => 'text', 'name' => 'amount_ttc_2', 'label' => $langs->trans("AmountTTC").' 2', 'value' => $amount2, 'size' => '5')
786 );
787 $langs->load("dict");
788 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);
789 }
790 }
791 } else {
793 }
794 }
795
796 if ($isSupplier) {
797 if ($isCustomer) {
798 $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());
799 print '</div>'; // class="fichehalfleft"
800 print '<div class="fichehalfright fichehalfright-lg">';
801 print load_fiche_titre($langs->trans("SupplierDiscounts"), $newcardbutton, '');
802 }
803
804 /*
805 * List of fixed supplier discounts still available (=not linked to any invoice nor invoice line)
806 */
807 $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
808 $sql .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
809 $sql .= " rc.datec as dc, rc.description,";
810 $sql .= " rc.fk_invoice_supplier_source,";
811 $sql .= " u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
812 $sql .= " fa.ref, fa.type as type";
813 $sql .= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."societe_remise_except as rc";
814 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
815 $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
816 $sql .= " AND rc.entity = ".((int) $conf->entity);
817 $sql .= " AND u.rowid = rc.fk_user";
818 $sql .= " AND rc.discount_type = 1"; // Eliminate customer discounts
819 $sql .= " AND (rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_line IS NULL)";
820 $sql .= " ORDER BY rc.datec DESC";
821
822 $resql = $db->query($sql);
823 if ($resql) {
824 print '<div class="div-table-responsive-no-min">';
825 print '<table class="noborder centpercent">';
826 print '<tr class="liste_titre">';
827 print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
828 print '<td>'.$langs->trans("ReasonDiscount").'</td>';
829 print '<td class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
830 print '<td class="right">'.$langs->trans("AmountHT").'</td>';
831 if (isModEnabled('multicurrency')) {
832 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountHT")).'">'.$langs->trans("MulticurrencyAmountHT").'</td>';
833 }
834 print '<td class="right">'.$langs->trans("VATRate").'</td>';
835 print '<td class="right">'.$langs->trans("AmountTTC").'</td>';
836 if (isModEnabled('multicurrency')) {
837 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountTTC")).'">'.$langs->trans("MulticurrencyAmountTTC").'</td>';
838 }
839 print '<td width="100" class="center">'.$langs->trans("DiscountOfferedBy").'</td>';
840 print '<td width="50">&nbsp;</td>';
841 print '</tr>';
842
843 $showconfirminfo = array();
844
845 $i = 0;
846 $num = $db->num_rows($resql);
847 if ($num > 0) {
848 while ($i < $num) {
849 $obj = $db->fetch_object($resql);
850
851 $tmpuser->id = $obj->user_id;
852 $tmpuser->login = $obj->login;
853 $tmpuser->firstname = $obj->firstname;
854 $tmpuser->lastname = $obj->lastname;
855 $tmpuser->photo = $obj->photo;
856 $tmpuser->status = $obj->status;
857
858 print '<tr class="oddeven">';
859 print '<td>'.dol_print_date($db->jdate($obj->dc), 'dayhour', 'tzuserrel').'</td>';
860 if (preg_match('/\‍(CREDIT_NOTE\‍)/', $obj->description)) {
861 print '<td class="tdoverflowmax100">';
862 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
863 $facturefournstatic->ref = $obj->ref;
864 $facturefournstatic->type = $obj->type;
865 print preg_replace('/\‍(CREDIT_NOTE\‍)/', $langs->trans("CreditNote"), $obj->description).'<br>'.$facturefournstatic->getNomURl(1);
866 print '</td>';
867 } elseif (preg_match('/\‍(DEPOSIT\‍)/', $obj->description)) {
868 print '<td class="tdoverflowmax100">';
869 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
870 $facturefournstatic->ref = $obj->ref;
871 $facturefournstatic->type = $obj->type;
872 print preg_replace('/\‍(DEPOSIT\‍)/', $langs->trans("InvoiceDeposit"), $obj->description).'<br>'.$facturefournstatic->getNomURl(1);
873 print '</td>';
874 } elseif (preg_match('/\‍(EXCESS PAID\‍)/', $obj->description)) {
875 print '<td class="tdoverflowmax100">';
876 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
877 $facturefournstatic->ref = $obj->ref;
878 $facturefournstatic->type = $obj->type;
879 print preg_replace('/\‍(EXCESS PAID\‍)/', $langs->trans("ExcessPaid"), $obj->description).'<br>'.$facturefournstatic->getNomURl(1);
880 print '</td>';
881 } else {
882 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).'">';
883 print dol_escape_htmltag($obj->description);
884 print '</td>';
885 }
886 print '<td class="nowrap"><span class="opacitymedium">'.$langs->trans("NotConsumed").'</span></td>';
887 print '<td class="right nowraponall amount">'.price($obj->amount_ht).'</td>';
888 if (isModEnabled('multicurrency')) {
889 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).'</td>';
890 }
891 print '<td class="right">'.vatrate($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), true).'</td>';
892 print '<td class="right nowraponall amount">'.price($obj->amount_ttc).'</td>';
893 if (isModEnabled('multicurrency')) {
894 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ttc).'</td>';
895 }
896 print '<td class="tdoverflowmax100">';
897 print $tmpuser->getNomUrl(-1);
898 print '</td>';
899
900 if ($user->hasRight('societe', 'creer') || $user->hasRight('facture', 'creer')) {
901 print '<td class="center nowraponall">';
902 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>';
903 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>';
904 print '</td>';
905 } else {
906 print '<td>&nbsp;</td>';
907 }
908 print '</tr>';
909
910 if ($action == 'split' && GETPOST('remid') == $obj->rowid) {
911 $showconfirminfo['rowid'] = $obj->rowid;
912 $showconfirminfo['amount_ttc'] = $obj->amount_ttc;
913 }
914 $i++;
915 }
916 } else {
917 $colspan = 8;
918 if (isModEnabled('multicurrency')) {
919 $colspan += 2;
920 }
921 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
922 }
923 $db->free($resql);
924 print "</table>";
925 print '</div>';
926
927 if (count($showconfirminfo)) {
928 if (getDolGlobalInt('DISCOUNT_SPLIT_MORE_THAN_TWO_PARTS') && !getDolGlobalInt('MAIN_DISABLE_JAVASCRIPT')) {
929 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&remid='.$showconfirminfo['rowid'].'" id="formsplit" data-totaltosplit="'.$showconfirminfo['amount_ttc'].'" data-remaintosplit="0">';
930
931 //
932 print '<input type="hidden" name="action" value="confirm_split_more">';
933 print '<input type="hidden" name="token" value="'.newToken().'">';
934
935 print '<div class="div-table-responsive-no-min">';
936 print '<table class="valid centpercent">';
937 print '<tbody>';
938
939 // Title
940 print '<tr class="validtitre">';
941 print '<td class="validtitre" colspan="4">'.img_picto('', 'split', '', 0, 0, 0, '', 'paddingright').' '.$langs->trans('SplitDiscountTitle').'</td>';
942 print '</tr>';
943
944 print '<tr class="valid">';
945 print '<td class="" colspan="4">'.$langs->trans('TypeAmountOfEachNewDiscountSplit').'</td>';
946 print '</tr>';
947
948 //
949 if (empty($splitamounts)) {
950 $amount1 = price2num($showconfirminfo['amount_ttc'] / 2, 'MT');
951 $amount2 = ($showconfirminfo['amount_ttc'] - (float) $amount1);
952 $remaintosplit = (float) $showconfirminfo['amount_ttc'] - ((float) $amount1 + (float) $amount2);
953
954 print '<tr class="valid splitline" id="splitline-1">';
955 print '<td class="right bold">'.$langs->trans('AmountTTC').' 1:</td>';
956 print '<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts[1]" value="'.$amount1.'"></td>';
957 print '<td class="right delsplitline"></td>';
958 print '<td class="right"></td>';
959 print '</tr>';
960
961 print '<tr class="valid splitline" id="splitline-2">';
962 print '<td class="right bold">'.$langs->trans('AmountTTC').' 2:</td>';
963 print '<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts[2]" value="'.$amount2.'"></td>';
964 print '<td class="right delsplitline"></td>';
965 print '<td class="right"></td>';
966 print '</tr>';
967 } else {
968 $nbSplitLines = count($splitamounts);
969 $remaintosplit = $showconfirminfo['amount_ttc'];
970 foreach ($splitamounts as $numero => $value) {
971 $remaintosplit -= (float) $value;
972 print '<tr class="valid splitline" id="splitline-'.$numero.'">';
973 print '<td class="right bold">'.$langs->trans('AmountTTC').' '.$numero.':</td>';
974 print '<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts['.$numero.']" value="'.$splitamounts[$numero].'"></td>';
975 print '<td class="right delsplitline"></td>';
976 print '<td class="right"></td>';
977 print '</tr>';
978 }
979 }
980
981 print '<tr class="valid">';
982 print '<td class="right"></td>';
983 print '<td class="right"><span class="fas fa-plus-circle" id="splitaddline" style="cursor:pointer;"></span></td>';
984 print '<td class="right"></td>';
985 print '</tr>';
986
987 print '<tr class="valid">';
988 print '<td colspan="3">&nbsp;</td>';
989 print '</tr>';
990
991 //
992 print '<tr class="valid">';
993 print '<td class="right bold">'.$langs->trans('RemainToSplit').':</td>';
994 print '<td class="right"><span id="remaintosplit">'.price($remaintosplit).'</span> '.$conf->currency.'</td>';
995 print '<td class="right"></td>';
996 print '</tr>';
997
998 print '<tr class="valid">';
999 print '<td class="right bold"></td>';
1000 print '<td class="right"><input type="submit" class="button valignmiddle confirmvalidatebutton small nomarginright"></td>';
1001 print '<td class="right"></td>';
1002 print '</tr>';
1003
1004 print '</tbody>';
1005 print '</table>';
1006 print '</div>';
1007 print '</form>';
1008 print '<br>';
1009 ?>
1010 <script nonce="<?php print getNonce(); ?>" type="text/javascript">
1011 $(document).ready(function () {
1012
1013 let formsplit = $('#formsplit');
1014 let totaltosplit = formsplit.data('totaltosplit');
1015
1016 function calcRemainToPay(){
1017 let items = formsplit.find('.splitinput');
1018 let remaintosplit = totaltosplit;
1019
1020 items.each(function(e){
1021 var itemvalue = parseFloat($(this).val().replace(',', '.'));
1022 if (isNaN(itemvalue)) {
1023 itemvalue = 0;
1024 }
1025 remaintosplit -= itemvalue;
1026 });
1027
1028 let remaintosplitval = remaintosplit.toFixed(2);
1029 console.log(remaintosplitval);
1030 formsplit.data('remaintosplit', remaintosplitval);
1031 formsplit.find('#remaintosplit').html(remaintosplitval.replace('.',','));
1032 formsplit.find('input[type=submit]').prop('disabled', true);
1033 if (remaintosplit == 0) {
1034 formsplit.find('input[type=submit]').prop('disabled', false);
1035 }
1036 }
1037
1038 // Addline
1039 $(document).on('click', '#splitaddline', function(){
1040 let splitlines = formsplit.find('.splitline');
1041 let numlines = splitlines.length;
1042 let nextNum = numlines + 1;
1043 let newInputValue = formsplit.data('remaintosplit');
1044 $('#splitline-'+numlines).find('.delsplitline').html('');
1045 var splitTemplate = '<tr class="splitline" id="splitline-'+ nextNum +'">';
1046 splitTemplate += '<td class="right bold"><?php echo $langs->trans('AmountTTC'); ?> '+ nextNum +':</td>';
1047 splitTemplate += '<td class="right"><input type="number" step="any" min="0" class="flat splitinput" name="splitamounts['+ nextNum +']" value="'+ parseFloat(newInputValue) +'"></td>';
1048 splitTemplate += '<td class="right delsplitline"><span class="fas fa-trash icon-delsplitline" data-splitline="'+ nextNum +'" style="cursor:pointer;"></span></td>';
1049 splitTemplate += '<td class="right"></td>';
1050 splitTemplate += '</tr>';
1051 $('#splitline-'+numlines).after(splitTemplate);
1052 calcRemainToPay();
1053 });
1054
1055 // Update line
1056 $(document).on('change', '.splitinput', function(){
1057 calcRemainToPay();
1058 });
1059
1060 // Delete line
1061 $(document).on('click', '.icon-delsplitline', function(){
1062 let num = parseInt($(this).data('splitline'));
1063 let numBefore = num - 1;
1064 if (numBefore > 2) {
1065 $('#splitline-'+numBefore).find('.delsplitline').html('<span class="fas fa-trash icon-delsplitline" data-splitline="'+ numBefore +'"></span>');
1066 }
1067 $('#splitline-'+num).remove();
1068 calcRemainToPay();
1069 });
1070 });
1071 </script>
1072 <?php
1073 } else {
1074 $amount1 = price2num($showconfirminfo['amount_ttc'] / 2, 'MT');
1075 $amount2 = ($showconfirminfo['amount_ttc'] - (float) $amount1);
1076 $formquestion = array(
1077 'text' => $langs->trans('TypeAmountOfEachNewDiscount'),
1078 0 => array('type' => 'text', 'name' => 'amount_ttc_1', 'label' => $langs->trans("AmountTTC").' 1', 'value' => $amount1, 'size' => '5'),
1079 1 => array('type' => 'text', 'name' => 'amount_ttc_2', 'label' => $langs->trans("AmountTTC").' 2', 'value' => $amount2, 'size' => '5')
1080 );
1081 $langs->load("dict");
1082 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);
1083 }
1084 }
1085 } else {
1087 }
1088
1089 if ($isCustomer) {
1090 print '</div>'; // class="fichehalfright"
1091 print '</div>'; // class="fichecenter"
1092 }
1093 }
1094
1095 print '<div class="clearboth"></div><br><br>';
1096
1097 /*
1098 * List discount consumed (=linked to an invoice line or invoice)
1099 */
1100
1101 print load_fiche_titre($langs->trans("DiscountAlreadyCounted"));
1102
1103 if ($isCustomer) {
1104 if ($isSupplier) {
1105 print '<div class="fichecenter">';
1106 print '<div class="fichehalfleft fichehalfleft-lg">';
1107 print load_fiche_titre($langs->trans("CustomerDiscounts"), '', '');
1108 }
1109
1110 // Discount linked to invoice lines
1111 $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
1112 $sql .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
1113 $sql .= " rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture_source,";
1114 $sql .= " u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
1115 $sql .= " f.rowid as invoiceid, f.ref,";
1116 $sql .= " fa.ref as invoice_source_ref, fa.type as type";
1117 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
1118 $sql .= " , ".MAIN_DB_PREFIX."user as u";
1119 $sql .= " , ".MAIN_DB_PREFIX."facturedet as fc";
1120 $sql .= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
1121 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
1122 $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
1123 $sql .= " AND rc.fk_facture_line = fc.rowid";
1124 $sql .= " AND fc.fk_facture = f.rowid";
1125 $sql .= " AND rc.fk_user = u.rowid";
1126 $sql .= " AND rc.discount_type = 0"; // Eliminate supplier discounts
1127 $sql .= " ORDER BY dc DESC";
1128 //$sql.= " UNION ";
1129 // Discount linked to invoices
1130 $sql2 = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
1131 $sql2 .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
1132 $sql2 .= " rc.datec as dc, rc.description, rc.fk_facture, rc.fk_facture_source,";
1133 $sql2 .= " u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
1134 $sql2 .= " f.rowid as invoiceid, f.ref,";
1135 $sql2 .= " fa.ref as invoice_source_ref, fa.type as type";
1136 $sql2 .= " FROM ".MAIN_DB_PREFIX."facture as f";
1137 $sql2 .= " , ".MAIN_DB_PREFIX."user as u";
1138 $sql2 .= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
1139 $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
1140 $sql2 .= " WHERE rc.fk_soc = ".((int) $object->id);
1141 $sql2 .= " AND rc.fk_facture = f.rowid";
1142 $sql2 .= " AND rc.fk_user = u.rowid";
1143 $sql2 .= " AND rc.discount_type = 0"; // Eliminate supplier discounts
1144 $sql2 .= " ORDER BY dc DESC";
1145
1146 $resql = $db->query($sql);
1147 $resql2 = null;
1148 if ($resql) {
1149 $resql2 = $db->query($sql2);
1150 }
1151 if ($resql2) {
1152 print '<div class="div-table-responsive-no-min">';
1153 print '<table class="noborder centpercent">';
1154 print '<tr class="liste_titre">';
1155 print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
1156 print '<td>'.$langs->trans("ReasonDiscount").'</td>';
1157 print '<td class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
1158 print '<td class="right">'.$langs->trans("AmountHT").'</td>';
1159 if (isModEnabled('multicurrency')) {
1160 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountHT")).'">'.$langs->trans("MulticurrencyAmountHT").'</td>';
1161 }
1162 print '<td class="right">'.$langs->trans("VATRate").'</td>';
1163 print '<td class="right">'.$langs->trans("AmountTTC").'</td>';
1164 if (isModEnabled('multicurrency')) {
1165 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountTTC")).'">'.$langs->trans("MulticurrencyAmountTTC").'</td>';
1166 }
1167 print '<td width="100" class="center">'.$langs->trans("Author").'</td>';
1168 print '<td width="50">&nbsp;</td>';
1169 print '</tr>';
1170
1171 $tab_sqlobj = array();
1172 $tab_sqlobjOrder = array();
1173 $num = $db->num_rows($resql);
1174 if ($num > 0) {
1175 for ($i = 0; $i < $num; $i++) {
1176 $fetched_obj = $db->fetch_object($resql);
1177 $tab_sqlobj[] = $fetched_obj;
1178 $tab_sqlobjOrder[] = $db->jdate($fetched_obj->dc);
1179 }
1180 }
1181 $db->free($resql);
1182
1183 $num = $db->num_rows($resql2);
1184 for ($i = 0; $i < $num; $i++) {
1185 $fetched_obj = $db->fetch_object($resql2);
1186 $tab_sqlobj[] = $fetched_obj;
1187 $tab_sqlobjOrder[] = $db->jdate($fetched_obj->dc);
1188 }
1189 $db->free($resql2);
1190 $array1_sort_order = SORT_DESC;
1191 array_multisort($tab_sqlobjOrder, $array1_sort_order, $tab_sqlobj);
1192
1193 $num = count($tab_sqlobj);
1194 if ($num > 0) {
1195 $i = 0;
1196 while ($i < $num) {
1197 $obj = array_shift($tab_sqlobj);
1198
1199 $tmpuser->id = $obj->user_id;
1200 $tmpuser->login = $obj->login;
1201 $tmpuser->firstname = $obj->firstname;
1202 $tmpuser->lastname = $obj->lastname;
1203 $tmpuser->photo = $obj->photo;
1204 $tmpuser->status = $obj->status;
1205
1206 print '<tr class="oddeven">';
1207 print '<td>'.dol_print_date($db->jdate($obj->dc), 'dayhour').'</td>';
1208 if (preg_match('/\‍(CREDIT_NOTE\‍)/', $obj->description)) {
1209 print '<td class="tdoverflowmax100">';
1210 $facturestatic->id = $obj->fk_facture_source;
1211 $facturestatic->ref = $obj->invoice_source_ref;
1212 $facturestatic->type = $obj->type;
1213 print preg_replace('/\‍(CREDIT_NOTE\‍)/', $langs->trans("CreditNote"), $obj->description).'<br>'.$facturestatic->getNomURl(1);
1214 print '</td>';
1215 } elseif (preg_match('/\‍(DEPOSIT\‍)/', $obj->description)) {
1216 print '<td class="tdoverflowmax100">';
1217 $facturestatic->id = $obj->fk_facture_source;
1218 $facturestatic->ref = $obj->invoice_source_ref;
1219 $facturestatic->type = $obj->type;
1220 print preg_replace('/\‍(DEPOSIT\‍)/', $langs->trans("InvoiceDeposit"), $obj->description).'<br>'.$facturestatic->getNomURl(1);
1221 print '</td>';
1222 } elseif (preg_match('/\‍(EXCESS RECEIVED\‍)/', $obj->description)) {
1223 print '<td class="tdoverflowmax100">';
1224 $facturestatic->id = $obj->fk_facture_source;
1225 $facturestatic->ref = $obj->invoice_source_ref;
1226 $facturestatic->type = $obj->type;
1227 print preg_replace('/\‍(EXCESS RECEIVED\‍)/', $langs->trans("Invoice"), $obj->description).'<br>'.$facturestatic->getNomURl(1);
1228 print '</td>';
1229 } else {
1230 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).'">';
1231 print dol_escape_htmltag($obj->description);
1232 print '</td>';
1233 }
1234 print '<td class="left nowrap">';
1235 if ($obj->invoiceid) {
1236 print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->invoiceid.'">'.img_object($langs->trans("ShowBill"), 'bill').' '.$obj->ref.'</a>';
1237 }
1238 print '</td>';
1239 print '<td class="right nowraponall amount">'.price($obj->amount_ht).'</td>';
1240 if (isModEnabled('multicurrency')) {
1241 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).'</td>';
1242 }
1243 print '<td class="right nowraponall">'.vatrate($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), true).'</td>';
1244 print '<td class="right nowraponall amount">'.price($obj->amount_ttc).'</td>';
1245 if (isModEnabled('multicurrency')) {
1246 print '<td class="right">'.price($obj->multicurrency_amount_ttc).'</td>';
1247 }
1248 print '<td class="tdoverflowmax100">';
1249 print $tmpuser->getNomUrl(-1);
1250 print '</td>';
1251
1252 print '<td>&nbsp;</td>';
1253 print '</tr>';
1254 $i++;
1255 }
1256 } else {
1257 $colspan = 8;
1258 if (isModEnabled('multicurrency')) {
1259 $colspan += 2;
1260 }
1261 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
1262 }
1263
1264 print "</table>";
1265 print '</div>';
1266 } else {
1268 }
1269 }
1270
1271 if ($isSupplier) {
1272 if ($isCustomer) {
1273 print '</div>'; // class="fichehalfleft"
1274 print '<div class="fichehalfright fichehalfright-lg">';
1275 print load_fiche_titre($langs->trans("SupplierDiscounts"), '', '');
1276 }
1277
1278 // Discount linked to invoice lines
1279 $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
1280 $sql .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
1281 $sql .= " rc.datec as dc, rc.description, rc.fk_invoice_supplier_line,";
1282 $sql .= " rc.fk_invoice_supplier_source,";
1283 $sql .= " u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
1284 $sql .= " f.rowid as invoiceid, f.ref as ref,";
1285 $sql .= " fa.ref as invoice_source_ref, fa.type as type";
1286 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
1287 $sql .= " , ".MAIN_DB_PREFIX."user as u";
1288 $sql .= " , ".MAIN_DB_PREFIX."facture_fourn_det as fc";
1289 $sql .= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
1290 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
1291 $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
1292 $sql .= " AND rc.fk_invoice_supplier_line = fc.rowid";
1293 $sql .= " AND fc.fk_facture_fourn = f.rowid";
1294 $sql .= " AND rc.fk_user = u.rowid";
1295 $sql .= " AND rc.discount_type = 1"; // Eliminate customer discounts
1296 $sql .= " ORDER BY dc DESC";
1297 //$sql.= " UNION ";
1298 // Discount linked to invoices
1299 $sql2 = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
1300 $sql2 .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
1301 $sql2 .= " rc.datec as dc, rc.description, rc.fk_invoice_supplier,";
1302 $sql2 .= " rc.fk_invoice_supplier_source,";
1303 $sql2 .= " u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
1304 $sql2 .= " f.rowid as invoiceid, f.ref as ref,";
1305 $sql2 .= " fa.ref as invoice_source_ref, fa.type as type";
1306 $sql2 .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
1307 $sql2 .= " , ".MAIN_DB_PREFIX."user as u";
1308 $sql2 .= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
1309 $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
1310 $sql2 .= " WHERE rc.fk_soc = ".((int) $object->id);
1311 $sql2 .= " AND rc.fk_invoice_supplier = f.rowid";
1312 $sql2 .= " AND rc.fk_user = u.rowid";
1313 $sql2 .= " AND rc.discount_type = 1"; // Eliminate customer discounts
1314 $sql2 .= " ORDER BY dc DESC";
1315
1316 $resql = $db->query($sql);
1317 $resql2 = null;
1318 if ($resql) {
1319 $resql2 = $db->query($sql2);
1320 }
1321 if ($resql2) {
1322 print '<div class="div-table-responsive-no-min">';
1323 print '<table class="noborder centpercent">';
1324 print '<tr class="liste_titre">';
1325 print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
1326 print '<td>'.$langs->trans("ReasonDiscount").'</td>';
1327 print '<td class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
1328 print '<td class="right">'.$langs->trans("AmountHT").'</td>';
1329 if (isModEnabled('multicurrency')) {
1330 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountHT")).'">'.$langs->trans("MulticurrencyAmountHT").'</td>';
1331 }
1332 print '<td class="right">'.$langs->trans("VATRate").'</td>';
1333 print '<td class="right">'.$langs->trans("AmountTTC").'</td>';
1334 if (isModEnabled('multicurrency')) {
1335 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountTTC")).'">'.$langs->trans("MulticurrencyAmountTTC").'</td>';
1336 }
1337 print '<td width="100" class="center">'.$langs->trans("Author").'</td>';
1338 print '<td width="50">&nbsp;</td>';
1339 print '</tr>';
1340
1341 $tab_sqlobj = array();
1342 $tab_sqlobjOrder = array();
1343 $num = $db->num_rows($resql);
1344 if ($num > 0) {
1345 for ($i = 0; $i < $num; $i++) {
1346 $fetched_obj = $db->fetch_object($resql);
1347 $tab_sqlobj[] = $fetched_obj;
1348 $tab_sqlobjOrder[] = $db->jdate($fetched_obj->dc);
1349 }
1350 }
1351 $db->free($resql);
1352
1353 $num = $db->num_rows($resql2);
1354 for ($i = 0; $i < $num; $i++) {
1355 $fetched_obj = $db->fetch_object($resql2);
1356 $tab_sqlobj[] = $fetched_obj;
1357 $tab_sqlobjOrder[] = $db->jdate($fetched_obj->dc);
1358 }
1359 $db->free($resql2);
1360 $array1_sort_order = SORT_DESC;
1361 array_multisort($tab_sqlobjOrder, $array1_sort_order, $tab_sqlobj);
1362
1363 $num = count($tab_sqlobj);
1364 if ($num > 0) {
1365 $i = 0;
1366 while ($i < $num) {
1367 $obj = array_shift($tab_sqlobj);
1368
1369 $tmpuser->id = $obj->user_id;
1370 $tmpuser->login = $obj->login;
1371 $tmpuser->firstname = $obj->firstname;
1372 $tmpuser->lastname = $obj->lastname;
1373 $tmpuser->photo = $obj->photo;
1374 $tmpuser->status = $obj->status;
1375
1376 print '<tr class="oddeven">';
1377 print '<td>'.dol_print_date($db->jdate($obj->dc), 'dayhour').'</td>';
1378 if (preg_match('/\‍(CREDIT_NOTE\‍)/', $obj->description)) {
1379 print '<td class="tdoverflowmax100">';
1380 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
1381 $facturefournstatic->ref = $obj->invoice_source_ref;
1382 $facturefournstatic->type = $obj->type;
1383 print preg_replace('/\‍(CREDIT_NOTE\‍)/', $langs->trans("CreditNote"), $obj->description).'<br>'.$facturefournstatic->getNomURl(1);
1384 print '</td>';
1385 } elseif (preg_match('/\‍(DEPOSIT\‍)/', $obj->description)) {
1386 print '<td class="tdoverflowmax100">';
1387 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
1388 $facturefournstatic->ref = $obj->invoice_source_ref;
1389 $facturefournstatic->type = $obj->type;
1390 print preg_replace('/\‍(DEPOSIT\‍)/', $langs->trans("InvoiceDeposit"), $obj->description).'<br>'.$facturefournstatic->getNomURl(1);
1391 print '</td>';
1392 } elseif (preg_match('/\‍(EXCESS PAID\‍)/', $obj->description)) {
1393 print '<td class="tdoverflowmax100">';
1394 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
1395 $facturefournstatic->ref = $obj->invoice_source_ref;
1396 $facturefournstatic->type = $obj->type;
1397 print preg_replace('/\‍(EXCESS PAID\‍)/', $langs->trans("Invoice"), $obj->description).'<br>'.$facturefournstatic->getNomURl(1);
1398 print '</td>';
1399 } else {
1400 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).'">';
1401 print dol_escape_htmltag($obj->description);
1402 print '</td>';
1403 }
1404 print '<td class="left nowrap">';
1405 if ($obj->invoiceid) {
1406 print '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$obj->invoiceid.'">'.img_object($langs->trans("ShowBill"), 'bill').' '.$obj->ref.'</a>';
1407 }
1408 print '</td>';
1409 print '<td class="right nowraponall amount">'.price($obj->amount_ht).'</td>';
1410 if (isModEnabled('multicurrency')) {
1411 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).'</td>';
1412 }
1413 print '<td class="right">'.vatrate($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), true).'</td>';
1414 print '<td class="right nowraponall amount">'.price($obj->amount_ttc).'</td>';
1415 if (isModEnabled('multicurrency')) {
1416 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ttc).'</td>';
1417 }
1418 print '<td class="tdoverflowmax100">';
1419 print $tmpuser->getNomUrl(-1);
1420 print '</td>';
1421
1422 print '<td>&nbsp;</td>';
1423
1424 print '</tr>';
1425 $i++;
1426 }
1427 } else {
1428 $colspan = 8;
1429 if (isModEnabled('multicurrency')) {
1430 $colspan += 2;
1431 }
1432 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
1433 }
1434
1435 print "</table>";
1436 print '</div>';
1437 } else {
1439 }
1440
1441 if ($isCustomer) {
1442 print '</div>'; // class="fichehalfright"
1443 print '</div>'; // class="fichecenter"
1444 }
1445 }
1446}
1447
1448// End of page
1449llxFooter();
1450$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
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:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
img_split($titlealt='default', $other='class="pictosplit"')
Show split logo.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition repair.php:137
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.