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