dolibarr 22.0.5
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-2024 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28if (! defined('CSRFCHECK_WITH_TOKEN')) {
29 define('CSRFCHECK_WITH_TOKEN', '1');
30} // Force use of CSRF protection with tokens even for GET
31
32// Load Dolibarr environment
33require '../main.inc.php';
34require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
35require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
36require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
38
48// Load translation files required by the page
49$langs->loadLangs(array('orders', 'bills', 'companies'));
50
51$id = GETPOSTINT('id');
52
53$action = GETPOST('action', 'aZ09');
54$backtopage = GETPOST('backtopage', 'alpha');
55
56// Security check
57$socid = GETPOSTINT('id') ? GETPOSTINT('id') : GETPOSTINT('socid');
59if ($user->socid > 0) {
60 $socid = $user->socid;
61}
62
63// Security check
64if ($user->socid > 0) {
65 $id = $user->socid;
66}
67$result = restrictedArea($user, 'societe', $id, '&societe', '', 'fk_soc', 'rowid', 0);
68
69$permissiontocreate = ($user->hasRight('societe', 'creer') || $user->hasRight('facture', 'creer'));
70
71
72
73/*
74 * Actions
75 */
76
77if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
78 header("Location: ".$backtopage);
79 exit;
80}
81
82if ($action == 'confirm_split' && GETPOST("confirm", "alpha") == 'yes' && $permissiontocreate) {
83 $amount_ttc_1 = GETPOST('amount_ttc_1', 'alpha');
84 $amount_ttc_1 = price2num($amount_ttc_1);
85 $amount_ttc_2 = GETPOST('amount_ttc_2', 'alpha');
86 $amount_ttc_2 = price2num($amount_ttc_2);
87
88 $error = 0;
89 $remid = (GETPOSTINT("remid") ? GETPOSTINT("remid") : 0);
90 $discount = new DiscountAbsolute($db);
91 $res = $discount->fetch($remid);
92 if (!($res > 0)) {
93 $error++;
94 setEventMessages($langs->trans("ErrorFailedToLoadDiscount"), null, 'errors');
95 }
96 if (!$error && price2num((float) $amount_ttc_1 + (float) $amount_ttc_2, 'MT') != $discount->amount_ttc) {
97 $error++;
98 setEventMessages($langs->trans("TotalOfTwoDiscountMustEqualsOriginal"), null, 'errors');
99 }
100 if (!$error && $discount->fk_facture_line) {
101 $error++;
102 setEventMessages($langs->trans("ErrorCantSplitAUsedDiscount"), null, 'errors');
103 }
104 if (!$error) {
105 $newdiscount1 = new DiscountAbsolute($db);
106 $newdiscount2 = new DiscountAbsolute($db);
107 $newdiscount1->fk_facture_source = $discount->fk_facture_source;
108 $newdiscount2->fk_facture_source = $discount->fk_facture_source;
109 $newdiscount1->fk_facture = $discount->fk_facture;
110 $newdiscount2->fk_facture = $discount->fk_facture;
111 $newdiscount1->fk_facture_line = $discount->fk_facture_line;
112 $newdiscount2->fk_facture_line = $discount->fk_facture_line;
113 $newdiscount1->fk_invoice_supplier_source = $discount->fk_invoice_supplier_source;
114 $newdiscount2->fk_invoice_supplier_source = $discount->fk_invoice_supplier_source;
115 $newdiscount1->fk_invoice_supplier = $discount->fk_invoice_supplier;
116 $newdiscount2->fk_invoice_supplier = $discount->fk_invoice_supplier;
117 $newdiscount1->fk_invoice_supplier_line = $discount->fk_invoice_supplier_line;
118 $newdiscount2->fk_invoice_supplier_line = $discount->fk_invoice_supplier_line;
119 if ($discount->description == '(CREDIT_NOTE)' || $discount->description == '(DEPOSIT)') {
120 $newdiscount1->description = $discount->description;
121 $newdiscount2->description = $discount->description;
122 } else {
123 $newdiscount1->description = $discount->description.' (1)';
124 $newdiscount2->description = $discount->description.' (2)';
125 }
126
127 $newdiscount1->fk_user = $discount->fk_user;
128 $newdiscount2->fk_user = $discount->fk_user;
129 $newdiscount1->fk_soc = $discount->fk_soc;
130 $newdiscount1->socid = $discount->socid;
131 $newdiscount2->fk_soc = $discount->fk_soc;
132 $newdiscount2->socid = $discount->socid;
133 $newdiscount1->discount_type = $discount->discount_type;
134 $newdiscount2->discount_type = $discount->discount_type;
135 $newdiscount1->datec = $discount->datec;
136 $newdiscount2->datec = $discount->datec;
137 $newdiscount1->tva_tx = $discount->tva_tx;
138 $newdiscount2->tva_tx = $discount->tva_tx;
139 $newdiscount1->vat_src_code = $discount->vat_src_code;
140 $newdiscount2->vat_src_code = $discount->vat_src_code;
141 $newdiscount1->amount_ttc = $amount_ttc_1;
142 $newdiscount2->amount_ttc = price2num($discount->amount_ttc - $newdiscount1->amount_ttc);
143 $newdiscount1->amount_ht = price2num($newdiscount1->amount_ttc / (1 + $newdiscount1->tva_tx / 100), 'MT');
144 $newdiscount2->amount_ht = price2num($newdiscount2->amount_ttc / (1 + $newdiscount2->tva_tx / 100), 'MT');
145 $newdiscount1->amount_tva = price2num($newdiscount1->amount_ttc - $newdiscount1->amount_ht);
146 $newdiscount2->amount_tva = price2num($newdiscount2->amount_ttc - $newdiscount2->amount_ht);
147
148 $newdiscount1->multicurrency_amount_ttc = (float) $amount_ttc_1 * ($discount->multicurrency_amount_ttc / $discount->amount_ttc);
149 $newdiscount2->multicurrency_amount_ttc = price2num($discount->multicurrency_amount_ttc - $newdiscount1->multicurrency_amount_ttc);
150 $newdiscount1->multicurrency_amount_ht = price2num($newdiscount1->multicurrency_amount_ttc / (1 + $newdiscount1->tva_tx / 100), 'MT');
151 $newdiscount2->multicurrency_amount_ht = price2num($newdiscount2->multicurrency_amount_ttc / (1 + $newdiscount2->tva_tx / 100), 'MT');
152 $newdiscount1->multicurrency_amount_tva = price2num($newdiscount1->multicurrency_amount_ttc - $newdiscount1->multicurrency_amount_ht);
153 $newdiscount2->multicurrency_amount_tva = price2num($newdiscount2->multicurrency_amount_ttc - $newdiscount2->multicurrency_amount_ht);
154
155 $db->begin();
156
157 $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
158 // 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
159 $discount->fk_invoice_supplier_source = 0;
160 $res = $discount->delete($user);
161 $newid1 = $newdiscount1->create($user);
162 $newid2 = $newdiscount2->create($user);
163 if ($res > 0 && $newid1 > 0 && $newid2 > 0) {
164 $db->commit();
165 header("Location: ".$_SERVER["PHP_SELF"].'?id='.$id.($backtopage ? '&backtopage='.urlencode($backtopage) : '')); // To avoid pb with back
166 exit;
167 } else {
168 $db->rollback();
169 }
170 }
171}
172
173if ($action == 'setremise' && $permissiontocreate) {
174 $amount = price2num(GETPOST('amount', 'alpha'), '', 2);
175 $desc = GETPOST('desc', 'alpha');
176 $tva_tx = GETPOST('tva_tx', 'alpha');
177 $discount_type = GETPOSTISSET('discount_type') ? GETPOST('discount_type', 'alpha') : 0;
178 $price_base_type = GETPOST('price_base_type', 'alpha');
179
180 if ($amount > 0) {
181 $error = 0;
182 if (empty($desc)) {
183 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ReasonDiscount")), null, 'errors');
184 $error++;
185 }
186
187 if (!$error) {
188 $soc = new Societe($db);
189 $soc->fetch($id);
190 $discountid = $soc->set_remise_except((float) $amount, $user, $desc, $tva_tx, $discount_type, $price_base_type);
191
192 if ($discountid > 0) {
193 if (!empty($backtopage)) {
194 header("Location: ".$backtopage.'&discountid='.((int) $discountid));
195 exit;
196 } else {
197 header("Location: remx.php?id=".((int) $id));
198 exit;
199 }
200 } else {
201 $error++;
202 setEventMessages($soc->error, $soc->errors, 'errors');
203 }
204 }
205 } else {
206 setEventMessages($langs->trans("ErrorFieldFormat", $langs->transnoentitiesnoconv("AmountHT")), null, 'errors');
207 }
208}
209
210if (GETPOST('action', 'aZ09') == 'confirm_remove' && GETPOST("confirm") == 'yes' && $permissiontocreate) {
211 $db->begin();
212
213 $discount = new DiscountAbsolute($db);
214 $result = $discount->fetch(GETPOSTINT("remid"));
215 $result = $discount->delete($user);
216 if ($result > 0) {
217 $db->commit();
218 header("Location: ".$_SERVER["PHP_SELF"].'?id='.$id); // To avoid pb with back
219 exit;
220 } else {
221 setEventMessages($discount->error, $discount->errors, 'errors');
222 $db->rollback();
223 }
224}
225
226
227/*
228 * View
229 */
230
231$form = new Form($db);
232$facturestatic = new Facture($db);
233$facturefournstatic = new FactureFournisseur($db);
234$tmpuser = new User($db);
235
236llxHeader('', $langs->trans("GlobalDiscount"));
237
238if ($socid > 0) {
239 // On recupere les donnees societes par l'objet
240 $object = new Societe($db);
241 $object->fetch($socid);
242
243 $isCustomer = $object->client == 1 || $object->client == 3;
244 $isSupplier = $object->fournisseur == 1;
245
246 // Display tabs
247
249
250 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
251 print '<input type="hidden" name="token" value="'.newToken().'">';
252 print '<input type="hidden" name="action" value="setremise">';
253 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
254
255 print dol_get_fiche_head($head, 'absolutediscount', $langs->trans("ThirdParty"), -1, 'company');
256
257 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
258
259 dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
260
261 print '<div class="fichecenter">';
262
263 print '<div class="underbanner clearboth"></div>';
264
265 if (!$isCustomer && !$isSupplier) {
266 print '<p class="opacitymedium">'.$langs->trans('ThirdpartyIsNeitherCustomerNorClientSoCannotHaveDiscounts').'</p>';
267
268 print dol_get_fiche_end();
269
270 print '</form>';
271
272 llxFooter();
273 $db->close();
274 exit;
275 }
276
277
278 print '<div class="div-table-responsive-no-min">';
279 print '<table class="border centpercent tableforfield borderbottom">';
280
281 if ($isCustomer) { // Calcul avoirs client en cours
282 $remise_all = $remise_user = 0;
283 $sql = "SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
284 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
285 $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
286 $sql .= " AND rc.entity = ".((int) $conf->entity);
287 $sql .= " AND discount_type = 0"; // Exclude supplier discounts
288 $sql .= " AND (fk_facture_line IS NULL AND fk_facture IS NULL)";
289 $sql .= " GROUP BY rc.fk_user";
290 $resql = $db->query($sql);
291 if ($resql) {
292 while ($obj = $db->fetch_object($resql)) {
293 $remise_all += (!empty($obj->amount) ? $obj->amount : 0);
294 if (!empty($obj->fk_user) && $obj->fk_user == $user->id) {
295 $remise_user += (!empty($obj->amount) ? $obj->amount : 0);
296 }
297 }
298 } else {
299 dol_print_error($db);
300 }
301
302 print '<tr><td class="titlefieldmiddle">'.$langs->trans("CustomerAbsoluteDiscountAllUsers").'</td>';
303 print '<td class="amount">'.price($remise_all, 1, $langs, 1, -1, -1, $conf->currency).' '.$langs->trans("HT");
304 if (empty($user->fk_soc)) { // No need to show this for external users
305 print $form->textwithpicto('', $langs->trans("CustomerAbsoluteDiscountMy").': '.price($remise_user, 1, $langs, 1, -1, -1, $conf->currency).' '.$langs->trans("HT"));
306 }
307 print '</td></tr>';
308 }
309
310 if ($isSupplier) {
311 // Calcul avoirs fournisseur en cours
312 $remise_all = $remise_user = 0;
313 $sql = "SELECT SUM(rc.amount_ht) as amount, rc.fk_user";
314 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc";
315 $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
316 $sql .= " AND rc.entity = ".((int) $conf->entity);
317 $sql .= " AND discount_type = 1"; // Exclude customer discounts
318 $sql .= " AND (fk_invoice_supplier_line IS NULL AND fk_invoice_supplier IS NULL)";
319 $sql .= " GROUP BY rc.fk_user";
320 $resql = $db->query($sql);
321 if ($resql) {
322 while ($obj = $db->fetch_object($resql)) {
323 $remise_all += (!empty($obj->amount) ? $obj->amount : 0);
324 if (!empty($obj->fk_user) && $obj->fk_user == $user->id) {
325 $remise_user += (!empty($obj->amount) ? $obj->amount : 0);
326 }
327 }
328 } else {
329 dol_print_error($db);
330 }
331
332 print '<tr><td class="titlefieldmiddle">'.$langs->trans("SupplierAbsoluteDiscountAllUsers").'</td>';
333 print '<td class="amount">'.price($remise_all, 1, $langs, 1, -1, -1, $conf->currency).' '.$langs->trans("HT");
334 if (empty($user->fk_soc)) { // No need to show this for external users
335 print $form->textwithpicto('', $langs->trans("SupplierAbsoluteDiscountMy").' : '.price($remise_user, 1, $langs, 1, -1, -1, $conf->currency).' '.$langs->trans("HT"));
336 }
337 print '</td></tr>';
338 }
339
340 print '</table>';
341 print '</div>';
342
343 print '</div>'; // close fichecenter
344
345 print dol_get_fiche_end();
346
347
348 if ($action == 'create_remise') {
349 if ($user->hasRight('societe', 'creer')) {
350 print '<br>';
351
352 $discount_type = GETPOSTISSET('discount_type') ? GETPOST('discount_type', 'alpha') : 0;
353 if ($isCustomer && $isSupplier) {
354 $discounttypelabel = $discount_type == 1 ? 'NewSupplierGlobalDiscount' : 'NewClientGlobalDiscount';
355 } else {
356 $discounttypelabel = 'NewGlobalDiscount';
357 }
358
359 print load_fiche_titre($langs->trans($discounttypelabel), '', '');
360
361 if ($isSupplier && $discount_type == 1) {
362 print '<input type="hidden" name="discount_type" value="1" />';
363 } else {
364 print '<input type="hidden" name="discount_type" value="0" />';
365 }
366
367 print dol_get_fiche_head();
368
369
370 print '<div class="div-table-responsive-no-min">';
371 print '<table class="border centpercent">';
372 /*if ($isCustomer && $isSupplier) {
373 print '<tr><td class="titlefield fieldrequired">'.$langs->trans('DiscountType').'</td>';
374 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>';
375 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>';
376 print '</td></tr>';
377 }*/
378
379 // Amount
380 print '<tr><td class="titlefield fieldrequired">'.$langs->trans("Amount").'</td>';
381 print '<td><input type="text" size="5" name="amount" value="'.price2num(GETPOST("amount")).'" autofocus>';
382 print '<span class="hideonsmartphone">&nbsp;'.$langs->trans("Currency".$conf->currency).'</span></td></tr>';
383
384 // Price base (HT / TTC)
385 print '<tr><td class="titlefield">'.$langs->trans("PriceBase").'</td>';
386 print '<td>';
387 print $form->selectPriceBaseType(GETPOST("price_base_type"), "price_base_type");
388 print '</td></tr>';
389
390 // VAT
391 print '<tr><td>'.$langs->trans("VAT").'</td>';
392 print '<td>';
393 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);
394 print '</td></tr>';
395 print '<tr><td class="fieldrequired" >'.$langs->trans("NoteReason").'</td>';
396 print '<td><input type="text" class="quatrevingtpercent" name="desc" value="'.GETPOST('desc', 'alphanohtml').'"></td></tr>';
397
398 print "</table>";
399 print '</div>';
400
401 print dol_get_fiche_end();
402 }
403
404 if ($user->hasRight('societe', 'creer')) {
405 print '<div class="center">';
406 print '<input type="submit" class="button" name="submit" value="'.$langs->trans("AddGlobalDiscount").'">';
407 if (!empty($backtopage)) {
408 print ' &nbsp; ';
409 print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
410 }
411 print '</div>';
412 print '<br>';
413 }
414 }
415
416 print '</form>';
417
418
419 print '<br>';
420
421 if ($action == 'remove') {
422 print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&remid='.GETPOST('remid'), $langs->trans('RemoveDiscount'), $langs->trans('ConfirmRemoveDiscount'), 'confirm_remove', '', 0, 1);
423 }
424
425
426 /*
427 * List not consumed available credits (= linked to no invoice and no invoice line)
428 */
429
430 if ($isCustomer && !$isSupplier) {
431 $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());
432 } elseif (!$isCustomer && $isSupplier) {
433 $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());
434 } else {
435 $newcardbutton = '';
436 }
437
438 print load_fiche_titre($langs->trans("DiscountStillRemaining"), $newcardbutton);
439
440 if ($isCustomer) {
441 $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());
442 if ($isSupplier) {
443 print '<div class="fichecenter">';
444 print '<div class="fichehalfleft fichehalfleft-lg">';
445 print load_fiche_titre($langs->trans("CustomerDiscounts"), $newcardbutton, '');
446 }
447
448 $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
449 $sql .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
450 $sql .= " rc.datec as dc, rc.description,";
451 $sql .= " rc.fk_facture_source,";
452 $sql .= " u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
453 $sql .= " fa.ref as ref, fa.type as type";
454 $sql .= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."societe_remise_except as rc";
455 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
456 $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
457 $sql .= " AND rc.entity = ".((int) $conf->entity);
458 $sql .= " AND u.rowid = rc.fk_user";
459 $sql .= " AND rc.discount_type = 0"; // Eliminate supplier discounts
460 $sql .= " AND (rc.fk_facture_line IS NULL AND rc.fk_facture IS NULL)";
461 $sql .= " ORDER BY rc.datec DESC";
462
463 $resql = $db->query($sql);
464 if ($resql) {
465 print '<div class="div-table-responsive-no-min">';
466 print '<table class="noborder centpercent">';
467 print '<tr class="liste_titre">';
468 print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
469 print '<td>'.$langs->trans("ReasonDiscount").'</td>';
470 print '<td class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
471 print '<td class="right">'.$langs->trans("AmountHT").'</td>';
472 if (isModEnabled('multicompany')) {
473 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountHT")).'">'.$langs->trans("MulticurrencyAmountHT").'</td>';
474 }
475 print '<td class="right">'.$langs->trans("VATRate").'</td>';
476 print '<td class="right">'.$langs->trans("AmountTTC").'</td>';
477 if (isModEnabled('multicompany')) {
478 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountTTC")).'">'.$langs->trans("MulticurrencyAmountTTC").'</td>';
479 }
480 print '<td width="100" class="center">'.$langs->trans("DiscountOfferedBy").'</td>';
481 print '<td width="50">&nbsp;</td>';
482 print '</tr>';
483
484 $showconfirminfo = array();
485
486 $i = 0;
487 $num = $db->num_rows($resql);
488 if ($num > 0) {
489 while ($i < $num) {
490 $obj = $db->fetch_object($resql);
491
492 $tmpuser->id = $obj->user_id;
493 $tmpuser->login = $obj->login;
494 $tmpuser->firstname = $obj->firstname;
495 $tmpuser->lastname = $obj->lastname;
496 $tmpuser->photo = $obj->photo;
497 $tmpuser->status = $obj->status;
498
499 print '<tr class="oddeven">';
500
501 print '<td>'.dol_print_date($db->jdate($obj->dc), 'dayhour', 'tzuserrel').'</td>';
502
503 if (preg_match('/\‍(CREDIT_NOTE\‍)/', $obj->description)) {
504 print '<td class="tdoverflowmax100">';
505 $facturestatic->id = $obj->fk_facture_source;
506 $facturestatic->ref = $obj->ref;
507 $facturestatic->type = $obj->type;
508 print preg_replace('/\‍(CREDIT_NOTE\‍)/', $langs->trans("CreditNote"), $obj->description).'<br>'.$facturestatic->getNomURl(1);
509 print '</td>';
510 } elseif (preg_match('/\‍(DEPOSIT\‍)/', $obj->description)) {
511 print '<td class="tdoverflowmax100">';
512 $facturestatic->id = $obj->fk_facture_source;
513 $facturestatic->ref = $obj->ref;
514 $facturestatic->type = $obj->type;
515 print preg_replace('/\‍(DEPOSIT\‍)/', $langs->trans("InvoiceDeposit"), $obj->description).'<br>'.$facturestatic->getNomURl(1);
516 print '</td>';
517 } elseif (preg_match('/\‍(EXCESS RECEIVED\‍)/', $obj->description)) {
518 print '<td class="tdoverflowmax100">';
519 $facturestatic->id = $obj->fk_facture_source;
520 $facturestatic->ref = $obj->ref;
521 $facturestatic->type = $obj->type;
522 print preg_replace('/\‍(EXCESS RECEIVED\‍)/', $langs->trans("ExcessReceived"), $obj->description).'<br>'.$facturestatic->getNomURl(1);
523 print '</td>';
524 } else {
525 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).'">';
526 print dol_escape_htmltag($obj->description);
527 print '</td>';
528 }
529
530 print '<td class="nowrap"><span class="opacitymedium">'.$langs->trans("NotConsumed").'</span></td>';
531
532 print '<td class="right nowraponall amount">'.price($obj->amount_ht).'</td>';
533
534 if (isModEnabled('multicompany')) {
535 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).'</td>';
536 }
537 print '<td class="right nowraponall">'.vatrate($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), true).'</td>';
538 print '<td class="right nowraponall amount">'.price($obj->amount_ttc).'</td>';
539 if (isModEnabled('multicompany')) {
540 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ttc).'</td>';
541 }
542 print '<td class="tdoverflowmax100">';
543 //print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"), 'user').' '.$obj->login.'</a>';
544 print $tmpuser->getNomUrl(-1);
545 print '</td>';
546
547 if ($user->hasRight('societe', 'creer') || $user->hasRight('facture', 'creer')) {
548 print '<td class="center nowraponall">';
549 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>';
550 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>';
551 print '</td>';
552 } else {
553 print '<td>&nbsp;</td>';
554 }
555 print '</tr>';
556
557 if ($action == 'split' && GETPOST('remid') == $obj->rowid) {
558 $showconfirminfo['rowid'] = $obj->rowid;
559 $showconfirminfo['amount_ttc'] = $obj->amount_ttc;
560 }
561 $i++;
562 }
563 } else {
564 $colspan = 8;
565 if (isModEnabled('multicompany')) {
566 $colspan += 2;
567 }
568 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
569 }
570 $db->free($resql);
571 print "</table>";
572 print '</div>';
573
574 if (count($showconfirminfo)) {
575 $amount1 = price2num($showconfirminfo['amount_ttc'] / 2, 'MT');
576 $amount2 = ($showconfirminfo['amount_ttc'] - (float) $amount1);
577 $formquestion = array(
578 'text' => $langs->trans('TypeAmountOfEachNewDiscount'),
579 0 => array('type' => 'text', 'name' => 'amount_ttc_1', 'label' => $langs->trans("AmountTTC").' 1', 'value' => $amount1, 'size' => '5'),
580 1 => array('type' => 'text', 'name' => 'amount_ttc_2', 'label' => $langs->trans("AmountTTC").' 2', 'value' => $amount2, 'size' => '5')
581 );
582 $langs->load("dict");
583 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);
584 }
585 } else {
586 dol_print_error($db);
587 }
588 }
589
590 if ($isSupplier) {
591 if ($isCustomer) {
592 $newcardbutton = dolGetButtonTitle($langs->trans("NewSupplierGlobalDiscount"), '', 'fa fa-plus-circle', $_SERVER['PHP_SELF'].'?action=create_remise&id='.$id.'&discount_type=1&backtopage='.$_SERVER["PHP_SELF"].'?id='.$id.'&token='.newToken());
593 print '</div>'; // class="fichehalfleft"
594 print '<div class="fichehalfright fichehalfright-lg">';
595 print load_fiche_titre($langs->trans("SupplierDiscounts"), $newcardbutton, '');
596 }
597
598 /*
599 * Liste remises fixes fournisseur restant en cours (= liees a aucune facture ni ligne de facture)
600 */
601 $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
602 $sql .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
603 $sql .= " rc.datec as dc, rc.description,";
604 $sql .= " rc.fk_invoice_supplier_source,";
605 $sql .= " u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
606 $sql .= " fa.ref, fa.type as type";
607 $sql .= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."societe_remise_except as rc";
608 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
609 $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
610 $sql .= " AND rc.entity = ".((int) $conf->entity);
611 $sql .= " AND u.rowid = rc.fk_user";
612 $sql .= " AND rc.discount_type = 1"; // Eliminate customer discounts
613 $sql .= " AND (rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_line IS NULL)";
614 $sql .= " ORDER BY rc.datec DESC";
615
616 $resql = $db->query($sql);
617 if ($resql) {
618 print '<div class="div-table-responsive-no-min">';
619 print '<table class="noborder centpercent">';
620 print '<tr class="liste_titre">';
621 print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
622 print '<td>'.$langs->trans("ReasonDiscount").'</td>';
623 print '<td class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
624 print '<td class="right">'.$langs->trans("AmountHT").'</td>';
625 if (isModEnabled('multicompany')) {
626 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountHT")).'">'.$langs->trans("MulticurrencyAmountHT").'</td>';
627 }
628 print '<td class="right">'.$langs->trans("VATRate").'</td>';
629 print '<td class="right">'.$langs->trans("AmountTTC").'</td>';
630 if (isModEnabled('multicompany')) {
631 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountTTC")).'">'.$langs->trans("MulticurrencyAmountTTC").'</td>';
632 }
633 print '<td width="100" class="center">'.$langs->trans("DiscountOfferedBy").'</td>';
634 print '<td width="50">&nbsp;</td>';
635 print '</tr>';
636
637 $showconfirminfo = array();
638
639 $i = 0;
640 $num = $db->num_rows($resql);
641 if ($num > 0) {
642 while ($i < $num) {
643 $obj = $db->fetch_object($resql);
644
645 $tmpuser->id = $obj->user_id;
646 $tmpuser->login = $obj->login;
647 $tmpuser->firstname = $obj->firstname;
648 $tmpuser->lastname = $obj->lastname;
649 $tmpuser->photo = $obj->photo;
650 $tmpuser->status = $obj->status;
651
652 print '<tr class="oddeven">';
653 print '<td>'.dol_print_date($db->jdate($obj->dc), 'dayhour', 'tzuserrel').'</td>';
654 if (preg_match('/\‍(CREDIT_NOTE\‍)/', $obj->description)) {
655 print '<td class="tdoverflowmax100">';
656 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
657 $facturefournstatic->ref = $obj->ref;
658 $facturefournstatic->type = $obj->type;
659 print preg_replace('/\‍(CREDIT_NOTE\‍)/', $langs->trans("CreditNote"), $obj->description).'<br>'.$facturefournstatic->getNomURl(1);
660 print '</td>';
661 } elseif (preg_match('/\‍(DEPOSIT\‍)/', $obj->description)) {
662 print '<td class="tdoverflowmax100">';
663 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
664 $facturefournstatic->ref = $obj->ref;
665 $facturefournstatic->type = $obj->type;
666 print preg_replace('/\‍(DEPOSIT\‍)/', $langs->trans("InvoiceDeposit"), $obj->description).'<br>'.$facturefournstatic->getNomURl(1);
667 print '</td>';
668 } elseif (preg_match('/\‍(EXCESS PAID\‍)/', $obj->description)) {
669 print '<td class="tdoverflowmax100">';
670 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
671 $facturefournstatic->ref = $obj->ref;
672 $facturefournstatic->type = $obj->type;
673 print preg_replace('/\‍(EXCESS PAID\‍)/', $langs->trans("ExcessPaid"), $obj->description).'<br>'.$facturefournstatic->getNomURl(1);
674 print '</td>';
675 } else {
676 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).'">';
677 print dol_escape_htmltag($obj->description);
678 print '</td>';
679 }
680 print '<td class="nowrap"><span class="opacitymedium">'.$langs->trans("NotConsumed").'</span></td>';
681 print '<td class="right nowraponall amount">'.price($obj->amount_ht).'</td>';
682 if (isModEnabled('multicompany')) {
683 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).'</td>';
684 }
685 print '<td class="right">'.vatrate($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), true).'</td>';
686 print '<td class="right nowraponall amount">'.price($obj->amount_ttc).'</td>';
687 if (isModEnabled('multicompany')) {
688 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ttc).'</td>';
689 }
690 print '<td class="tdoverflowmax100">';
691 print $tmpuser->getNomUrl(-1);
692 print '</td>';
693
694 if ($user->hasRight('societe', 'creer') || $user->hasRight('facture', 'creer')) {
695 print '<td class="center nowraponall">';
696 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>';
697 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>';
698 print '</td>';
699 } else {
700 print '<td>&nbsp;</td>';
701 }
702 print '</tr>';
703
704 if ($action == 'split' && GETPOST('remid') == $obj->rowid) {
705 $showconfirminfo['rowid'] = $obj->rowid;
706 $showconfirminfo['amount_ttc'] = $obj->amount_ttc;
707 }
708 $i++;
709 }
710 } else {
711 $colspan = 8;
712 if (isModEnabled('multicompany')) {
713 $colspan += 2;
714 }
715 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
716 }
717 $db->free($resql);
718 print "</table>";
719 print '</div>';
720
721 if (count($showconfirminfo)) {
722 $amount1 = price2num($showconfirminfo['amount_ttc'] / 2, 'MT');
723 $amount2 = ($showconfirminfo['amount_ttc'] - (float) $amount1);
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'),
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, 0, 0);
731 }
732 } else {
733 dol_print_error($db);
734 }
735
736 if ($isCustomer) {
737 print '</div>'; // class="fichehalfright"
738 print '</div>'; // class="fichecenter"
739 }
740 }
741
742 print '<div class="clearboth"></div><br><br>';
743
744 /*
745 * List discount consumed (=liees a une ligne de facture ou facture)
746 */
747
748 print load_fiche_titre($langs->trans("DiscountAlreadyCounted"));
749
750 if ($isCustomer) {
751 if ($isSupplier) {
752 print '<div class="fichecenter">';
753 print '<div class="fichehalfleft fichehalfleft-lg">';
754 print load_fiche_titre($langs->trans("CustomerDiscounts"), '', '');
755 }
756
757 // Discount linked to invoice lines
758 $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
759 $sql .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
760 $sql .= " rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture_source,";
761 $sql .= " u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
762 $sql .= " f.rowid as invoiceid, f.ref,";
763 $sql .= " fa.ref as invoice_source_ref, fa.type as type";
764 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
765 $sql .= " , ".MAIN_DB_PREFIX."user as u";
766 $sql .= " , ".MAIN_DB_PREFIX."facturedet as fc";
767 $sql .= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
768 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
769 $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
770 $sql .= " AND rc.fk_facture_line = fc.rowid";
771 $sql .= " AND fc.fk_facture = f.rowid";
772 $sql .= " AND rc.fk_user = u.rowid";
773 $sql .= " AND rc.discount_type = 0"; // Eliminate supplier discounts
774 $sql .= " ORDER BY dc DESC";
775 //$sql.= " UNION ";
776 // Discount linked to invoices
777 $sql2 = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
778 $sql2 .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
779 $sql2 .= " rc.datec as dc, rc.description, rc.fk_facture, rc.fk_facture_source,";
780 $sql2 .= " u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
781 $sql2 .= " f.rowid as invoiceid, f.ref,";
782 $sql2 .= " fa.ref as invoice_source_ref, fa.type as type";
783 $sql2 .= " FROM ".MAIN_DB_PREFIX."facture as f";
784 $sql2 .= " , ".MAIN_DB_PREFIX."user as u";
785 $sql2 .= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
786 $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
787 $sql2 .= " WHERE rc.fk_soc = ".((int) $object->id);
788 $sql2 .= " AND rc.fk_facture = f.rowid";
789 $sql2 .= " AND rc.fk_user = u.rowid";
790 $sql2 .= " AND rc.discount_type = 0"; // Eliminate supplier discounts
791 $sql2 .= " ORDER BY dc DESC";
792
793 $resql = $db->query($sql);
794 $resql2 = null;
795 if ($resql) {
796 $resql2 = $db->query($sql2);
797 }
798 if ($resql2) {
799 print '<div class="div-table-responsive-no-min">';
800 print '<table class="noborder centpercent">';
801 print '<tr class="liste_titre">';
802 print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
803 print '<td>'.$langs->trans("ReasonDiscount").'</td>';
804 print '<td class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
805 print '<td class="right">'.$langs->trans("AmountHT").'</td>';
806 if (isModEnabled('multicompany')) {
807 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountHT")).'">'.$langs->trans("MulticurrencyAmountHT").'</td>';
808 }
809 print '<td class="right">'.$langs->trans("VATRate").'</td>';
810 print '<td class="right">'.$langs->trans("AmountTTC").'</td>';
811 if (isModEnabled('multicompany')) {
812 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountTTC")).'">'.$langs->trans("MulticurrencyAmountTTC").'</td>';
813 }
814 print '<td width="100" class="center">'.$langs->trans("Author").'</td>';
815 print '<td width="50">&nbsp;</td>';
816 print '</tr>';
817
818 $tab_sqlobj = array();
819 $tab_sqlobjOrder = array();
820 $num = $db->num_rows($resql);
821 if ($num > 0) {
822 for ($i = 0; $i < $num; $i++) {
823 $sqlobj = $db->fetch_object($resql);
824 $tab_sqlobj[] = $sqlobj;
825 $tab_sqlobjOrder[] = $db->jdate($sqlobj->dc);
826 }
827 }
828 $db->free($resql);
829
830 $num = $db->num_rows($resql2);
831 for ($i = 0; $i < $num; $i++) {
832 $sqlobj = $db->fetch_object($resql2);
833 $tab_sqlobj[] = $sqlobj;
834 $tab_sqlobjOrder[] = $db->jdate($sqlobj->dc);
835 }
836 $db->free($resql2);
837 $array1_sort_order = SORT_DESC;
838 array_multisort($tab_sqlobjOrder, $array1_sort_order, $tab_sqlobj);
839
840 $num = count($tab_sqlobj);
841 if ($num > 0) {
842 $i = 0;
843 while ($i < $num) {
844 $obj = array_shift($tab_sqlobj);
845
846 $tmpuser->id = $obj->user_id;
847 $tmpuser->login = $obj->login;
848 $tmpuser->firstname = $obj->firstname;
849 $tmpuser->lastname = $obj->lastname;
850 $tmpuser->photo = $obj->photo;
851 $tmpuser->status = $obj->status;
852
853 print '<tr class="oddeven">';
854 print '<td>'.dol_print_date($db->jdate($obj->dc), 'dayhour').'</td>';
855 if (preg_match('/\‍(CREDIT_NOTE\‍)/', $obj->description)) {
856 print '<td class="tdoverflowmax100">';
857 $facturestatic->id = $obj->fk_facture_source;
858 $facturestatic->ref = $obj->invoice_source_ref;
859 $facturestatic->type = $obj->type;
860 print preg_replace('/\‍(CREDIT_NOTE\‍)/', $langs->trans("CreditNote"), $obj->description).'<br>'.$facturestatic->getNomURl(1);
861 print '</td>';
862 } elseif (preg_match('/\‍(DEPOSIT\‍)/', $obj->description)) {
863 print '<td class="tdoverflowmax100">';
864 $facturestatic->id = $obj->fk_facture_source;
865 $facturestatic->ref = $obj->invoice_source_ref;
866 $facturestatic->type = $obj->type;
867 print preg_replace('/\‍(DEPOSIT\‍)/', $langs->trans("InvoiceDeposit"), $obj->description).'<br>'.$facturestatic->getNomURl(1);
868 print '</td>';
869 } elseif (preg_match('/\‍(EXCESS RECEIVED\‍)/', $obj->description)) {
870 print '<td class="tdoverflowmax100">';
871 $facturestatic->id = $obj->fk_facture_source;
872 $facturestatic->ref = $obj->invoice_source_ref;
873 $facturestatic->type = $obj->type;
874 print preg_replace('/\‍(EXCESS RECEIVED\‍)/', $langs->trans("Invoice"), $obj->description).'<br>'.$facturestatic->getNomURl(1);
875 print '</td>';
876 } else {
877 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).'">';
878 print dol_escape_htmltag($obj->description);
879 print '</td>';
880 }
881 print '<td class="left nowrap">';
882 if ($obj->invoiceid) {
883 print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->invoiceid.'">'.img_object($langs->trans("ShowBill"), 'bill').' '.$obj->ref.'</a>';
884 }
885 print '</td>';
886 print '<td class="right nowraponall amount">'.price($obj->amount_ht).'</td>';
887 if (isModEnabled('multicompany')) {
888 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).'</td>';
889 }
890 print '<td class="right nowraponall">'.vatrate($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), true).'</td>';
891 print '<td class="right nowraponall amount">'.price($obj->amount_ttc).'</td>';
892 if (isModEnabled('multicompany')) {
893 print '<td class="right">'.price($obj->multicurrency_amount_ttc).'</td>';
894 }
895 print '<td class="tdoverflowmax100">';
896 print $tmpuser->getNomUrl(-1);
897 print '</td>';
898
899 print '<td>&nbsp;</td>';
900 print '</tr>';
901 $i++;
902 }
903 } else {
904 $colspan = 8;
905 if (isModEnabled('multicompany')) {
906 $colspan += 2;
907 }
908 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
909 }
910
911 print "</table>";
912 print '</div>';
913 } else {
914 dol_print_error($db);
915 }
916 }
917
918 if ($isSupplier) {
919 if ($isCustomer) {
920 print '</div>'; // class="fichehalfleft"
921 print '<div class="fichehalfright fichehalfright-lg">';
922 print load_fiche_titre($langs->trans("SupplierDiscounts"), '', '');
923 }
924
925 // Discount linked to invoice lines
926 $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
927 $sql .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
928 $sql .= " rc.datec as dc, rc.description, rc.fk_invoice_supplier_line,";
929 $sql .= " rc.fk_invoice_supplier_source,";
930 $sql .= " u.login, u.rowid as user_id, u.statut as user_status, u.firstname, u.lastname, u.photo,";
931 $sql .= " f.rowid as invoiceid, f.ref as ref,";
932 $sql .= " fa.ref as invoice_source_ref, fa.type as type";
933 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
934 $sql .= " , ".MAIN_DB_PREFIX."user as u";
935 $sql .= " , ".MAIN_DB_PREFIX."facture_fourn_det as fc";
936 $sql .= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
937 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
938 $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
939 $sql .= " AND rc.fk_invoice_supplier_line = fc.rowid";
940 $sql .= " AND fc.fk_facture_fourn = f.rowid";
941 $sql .= " AND rc.fk_user = u.rowid";
942 $sql .= " AND rc.discount_type = 1"; // Eliminate customer discounts
943 $sql .= " ORDER BY dc DESC";
944 //$sql.= " UNION ";
945 // Discount linked to invoices
946 $sql2 = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
947 $sql2 .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
948 $sql2 .= " rc.datec as dc, rc.description, rc.fk_invoice_supplier,";
949 $sql2 .= " rc.fk_invoice_supplier_source,";
950 $sql2 .= " u.login, u.rowid as user_id, u.statut as user_status, u.firstname, u.lastname, u.photo,";
951 $sql2 .= " f.rowid as invoiceid, f.ref as ref,";
952 $sql2 .= " fa.ref as invoice_source_ref, fa.type as type";
953 $sql2 .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
954 $sql2 .= " , ".MAIN_DB_PREFIX."user as u";
955 $sql2 .= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
956 $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
957 $sql2 .= " WHERE rc.fk_soc = ".((int) $object->id);
958 $sql2 .= " AND rc.fk_invoice_supplier = f.rowid";
959 $sql2 .= " AND rc.fk_user = u.rowid";
960 $sql2 .= " AND rc.discount_type = 1"; // Eliminate customer discounts
961 $sql2 .= " ORDER BY dc DESC";
962
963 $resql = $db->query($sql);
964 $resql2 = null;
965 if ($resql) {
966 $resql2 = $db->query($sql2);
967 }
968 if ($resql2) {
969 print '<div class="div-table-responsive-no-min">';
970 print '<table class="noborder centpercent">';
971 print '<tr class="liste_titre">';
972 print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
973 print '<td>'.$langs->trans("ReasonDiscount").'</td>';
974 print '<td class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
975 print '<td class="right">'.$langs->trans("AmountHT").'</td>';
976 if (isModEnabled('multicompany')) {
977 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountHT")).'">'.$langs->trans("MulticurrencyAmountHT").'</td>';
978 }
979 print '<td class="right">'.$langs->trans("VATRate").'</td>';
980 print '<td class="right">'.$langs->trans("AmountTTC").'</td>';
981 if (isModEnabled('multicompany')) {
982 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountTTC")).'">'.$langs->trans("MulticurrencyAmountTTC").'</td>';
983 }
984 print '<td width="100" class="center">'.$langs->trans("Author").'</td>';
985 print '<td width="50">&nbsp;</td>';
986 print '</tr>';
987
988 $tab_sqlobj = array();
989 $tab_sqlobjOrder = array();
990 $num = $db->num_rows($resql);
991 if ($num > 0) {
992 for ($i = 0; $i < $num; $i++) {
993 $sqlobj = $db->fetch_object($resql);
994 $tab_sqlobj[] = $sqlobj;
995 $tab_sqlobjOrder[] = $db->jdate($sqlobj->dc);
996 }
997 }
998 $db->free($resql);
999
1000 $num = $db->num_rows($resql2);
1001 for ($i = 0; $i < $num; $i++) {
1002 $sqlobj = $db->fetch_object($resql2);
1003 $tab_sqlobj[] = $sqlobj;
1004 $tab_sqlobjOrder[] = $db->jdate($sqlobj->dc);
1005 }
1006 $db->free($resql2);
1007 $array1_sort_order = SORT_DESC;
1008 array_multisort($tab_sqlobjOrder, $array1_sort_order, $tab_sqlobj);
1009
1010 $num = count($tab_sqlobj);
1011 if ($num > 0) {
1012 $i = 0;
1013 while ($i < $num) {
1014 $obj = array_shift($tab_sqlobj);
1015
1016 $tmpuser->id = $obj->user_id;
1017 $tmpuser->login = $obj->login;
1018 $tmpuser->firstname = $obj->firstname;
1019 $tmpuser->lastname = $obj->lastname;
1020 $tmpuser->photo = $obj->photo;
1021 $tmpuser->status = $obj->status;
1022
1023 print '<tr class="oddeven">';
1024 print '<td>'.dol_print_date($db->jdate($obj->dc), 'dayhour').'</td>';
1025 if (preg_match('/\‍(CREDIT_NOTE\‍)/', $obj->description)) {
1026 print '<td class="tdoverflowmax100">';
1027 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
1028 $facturefournstatic->ref = $obj->invoice_source_ref;
1029 $facturefournstatic->type = $obj->type;
1030 print preg_replace('/\‍(CREDIT_NOTE\‍)/', $langs->trans("CreditNote"), $obj->description).'<br>'.$facturefournstatic->getNomURl(1);
1031 print '</td>';
1032 } elseif (preg_match('/\‍(DEPOSIT\‍)/', $obj->description)) {
1033 print '<td class="tdoverflowmax100">';
1034 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
1035 $facturefournstatic->ref = $obj->invoice_source_ref;
1036 $facturefournstatic->type = $obj->type;
1037 print preg_replace('/\‍(DEPOSIT\‍)/', $langs->trans("InvoiceDeposit"), $obj->description).'<br>'.$facturefournstatic->getNomURl(1);
1038 print '</td>';
1039 } elseif (preg_match('/\‍(EXCESS PAID\‍)/', $obj->description)) {
1040 print '<td class="tdoverflowmax100">';
1041 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
1042 $facturefournstatic->ref = $obj->invoice_source_ref;
1043 $facturefournstatic->type = $obj->type;
1044 print preg_replace('/\‍(EXCESS PAID\‍)/', $langs->trans("Invoice"), $obj->description).'<br>'.$facturefournstatic->getNomURl(1);
1045 print '</td>';
1046 } else {
1047 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).'">';
1048 print dol_escape_htmltag($obj->description);
1049 print '</td>';
1050 }
1051 print '<td class="left nowrap">';
1052 if ($obj->invoiceid) {
1053 print '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$obj->invoiceid.'">'.img_object($langs->trans("ShowBill"), 'bill').' '.$obj->ref.'</a>';
1054 }
1055 print '</td>';
1056 print '<td class="right nowraponall amount">'.price($obj->amount_ht).'</td>';
1057 if (isModEnabled('multicompany')) {
1058 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).'</td>';
1059 }
1060 print '<td class="right">'.vatrate($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), true).'</td>';
1061 print '<td class="right nowraponall amount">'.price($obj->amount_ttc).'</td>';
1062 if (isModEnabled('multicompany')) {
1063 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ttc).'</td>';
1064 }
1065 print '<td class="tdoverflowmax100">';
1066 print $tmpuser->getNomUrl(-1);
1067 print '</td>';
1068
1069 print '<td>&nbsp;</td>';
1070
1071 print '</tr>';
1072 $i++;
1073 }
1074 } else {
1075 $colspan = 8;
1076 if (isModEnabled('multicompany')) {
1077 $colspan += 2;
1078 }
1079 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
1080 }
1081
1082 print "</table>";
1083 print '</div>';
1084 } else {
1085 dol_print_error($db);
1086 }
1087
1088 if ($isCustomer) {
1089 print '</div>'; // class="fichehalfright"
1090 print '</div>'; // class="fichecenter"
1091 }
1092 }
1093}
1094
1095// End of page
1096llxFooter();
1097$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage absolute discounts.
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage generation of HTML components Only common components must be here.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
societe_prepare_head(Societe $object)
Return array of tabs to used on pages for third parties cards.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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 '.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
img_split($titlealt='default', $other='class="pictosplit"')
Show split logo.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.