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