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