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