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