dolibarr 20.0.0
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;&nbsp;&nbsp;&nbsp;&nbsp;';
398 print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
399 }
400 print '</div>';
401 }
402 }
403
404 print '</form>';
405
406
407 print '<br>';
408
409 if ($action == 'remove') {
410 print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&remid='.GETPOST('remid'), $langs->trans('RemoveDiscount'), $langs->trans('ConfirmRemoveDiscount'), 'confirm_remove', '', 0, 1);
411 }
412
413
414 /*
415 * List not consumed available credits (= linked to no invoice and no invoice line)
416 */
417
418 if ($isCustomer && !$isSupplier) {
419 $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());
420 } elseif (!$isCustomer && $isSupplier) {
421 $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());
422 } else {
423 $newcardbutton = '';
424 }
425
426 print load_fiche_titre($langs->trans("DiscountStillRemaining"), $newcardbutton);
427
428 if ($isCustomer) {
429 $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());
430 if ($isSupplier) {
431 print '<div class="fichecenter">';
432 print '<div class="fichehalfleft fichehalfleft-lg">';
433 print load_fiche_titre($langs->trans("CustomerDiscounts"), $newcardbutton, '');
434 }
435
436 $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
437 $sql .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
438 $sql .= " rc.datec as dc, rc.description,";
439 $sql .= " rc.fk_facture_source,";
440 $sql .= " u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
441 $sql .= " fa.ref as ref, fa.type as type";
442 $sql .= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."societe_remise_except as rc";
443 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
444 $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
445 $sql .= " AND rc.entity = ".((int) $conf->entity);
446 $sql .= " AND u.rowid = rc.fk_user";
447 $sql .= " AND rc.discount_type = 0"; // Eliminate supplier discounts
448 $sql .= " AND (rc.fk_facture_line IS NULL AND rc.fk_facture IS NULL)";
449 $sql .= " ORDER BY rc.datec DESC";
450
451 $resql = $db->query($sql);
452 if ($resql) {
453 print '<div class="div-table-responsive-no-min">';
454 print '<table class="noborder centpercent">';
455 print '<tr class="liste_titre">';
456 print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
457 print '<td>'.$langs->trans("ReasonDiscount").'</td>';
458 print '<td class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
459 print '<td class="right">'.$langs->trans("AmountHT").'</td>';
460 if (isModEnabled('multicompany')) {
461 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountHT")).'">'.$langs->trans("MulticurrencyAmountHT").'</td>';
462 }
463 print '<td class="right">'.$langs->trans("VATRate").'</td>';
464 print '<td class="right">'.$langs->trans("AmountTTC").'</td>';
465 if (isModEnabled('multicompany')) {
466 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountTTC")).'">'.$langs->trans("MulticurrencyAmountTTC").'</td>';
467 }
468 print '<td width="100" class="center">'.$langs->trans("DiscountOfferedBy").'</td>';
469 print '<td width="50">&nbsp;</td>';
470 print '</tr>';
471
472 $showconfirminfo = array();
473
474 $i = 0;
475 $num = $db->num_rows($resql);
476 if ($num > 0) {
477 while ($i < $num) {
478 $obj = $db->fetch_object($resql);
479
480 $tmpuser->id = $obj->user_id;
481 $tmpuser->login = $obj->login;
482 $tmpuser->firstname = $obj->firstname;
483 $tmpuser->lastname = $obj->lastname;
484 $tmpuser->photo = $obj->photo;
485 $tmpuser->status = $obj->status;
486
487 print '<tr class="oddeven">';
488
489 print '<td>'.dol_print_date($db->jdate($obj->dc), 'dayhour', 'tzuserrel').'</td>';
490
491 if (preg_match('/\‍(CREDIT_NOTE\‍)/', $obj->description)) {
492 print '<td class="tdoverflowmax100">';
493 $facturestatic->id = $obj->fk_facture_source;
494 $facturestatic->ref = $obj->ref;
495 $facturestatic->type = $obj->type;
496 print preg_replace('/\‍(CREDIT_NOTE\‍)/', $langs->trans("CreditNote"), $obj->description).' '.$facturestatic->getNomURl(1);
497 print '</td>';
498 } elseif (preg_match('/\‍(DEPOSIT\‍)/', $obj->description)) {
499 print '<td class="tdoverflowmax100">';
500 $facturestatic->id = $obj->fk_facture_source;
501 $facturestatic->ref = $obj->ref;
502 $facturestatic->type = $obj->type;
503 print preg_replace('/\‍(DEPOSIT\‍)/', $langs->trans("InvoiceDeposit"), $obj->description).' '.$facturestatic->getNomURl(1);
504 print '</td>';
505 } elseif (preg_match('/\‍(EXCESS RECEIVED\‍)/', $obj->description)) {
506 print '<td class="tdoverflowmax100">';
507 $facturestatic->id = $obj->fk_facture_source;
508 $facturestatic->ref = $obj->ref;
509 $facturestatic->type = $obj->type;
510 print preg_replace('/\‍(EXCESS RECEIVED\‍)/', $langs->trans("ExcessReceived"), $obj->description).' '.$facturestatic->getNomURl(1);
511 print '</td>';
512 } else {
513 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).'">';
514 print dol_escape_htmltag($obj->description);
515 print '</td>';
516 }
517
518 print '<td class="nowrap"><span class="opacitymedium">'.$langs->trans("NotConsumed").'</span></td>';
519
520 print '<td class="right nowraponall amount">'.price($obj->amount_ht).'</td>';
521
522 if (isModEnabled('multicompany')) {
523 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).'</td>';
524 }
525 print '<td class="right nowraponall">'.vatrate($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), true).'</td>';
526 print '<td class="right nowraponall amount">'.price($obj->amount_ttc).'</td>';
527 if (isModEnabled('multicompany')) {
528 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ttc).'</td>';
529 }
530 print '<td class="tdoverflowmax100">';
531 //print '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$obj->user_id.'">'.img_object($langs->trans("ShowUser"), 'user').' '.$obj->login.'</a>';
532 print $tmpuser->getNomUrl(-1);
533 print '</td>';
534
535 if ($user->hasRight('societe', 'creer') || $user->hasRight('facture', 'creer')) {
536 print '<td class="center nowrap">';
537 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>';
538 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>';
539 print '</td>';
540 } else {
541 print '<td>&nbsp;</td>';
542 }
543 print '</tr>';
544
545 if ($action == 'split' && GETPOST('remid') == $obj->rowid) {
546 $showconfirminfo['rowid'] = $obj->rowid;
547 $showconfirminfo['amount_ttc'] = $obj->amount_ttc;
548 }
549 $i++;
550 }
551 } else {
552 $colspan = 8;
553 if (isModEnabled('multicompany')) {
554 $colspan += 2;
555 }
556 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
557 }
558 $db->free($resql);
559 print "</table>";
560 print '</div>';
561
562 if (count($showconfirminfo)) {
563 $amount1 = price2num($showconfirminfo['amount_ttc'] / 2, 'MT');
564 $amount2 = ($showconfirminfo['amount_ttc'] - (float) $amount1);
565 $formquestion = array(
566 'text' => $langs->trans('TypeAmountOfEachNewDiscount'),
567 0 => array('type' => 'text', 'name' => 'amount_ttc_1', 'label' => $langs->trans("AmountTTC").' 1', 'value' => $amount1, 'size' => '5'),
568 1 => array('type' => 'text', 'name' => 'amount_ttc_2', 'label' => $langs->trans("AmountTTC").' 2', 'value' => $amount2, 'size' => '5')
569 );
570 $langs->load("dict");
571 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);
572 }
573 } else {
574 dol_print_error($db);
575 }
576 }
577
578 if ($isSupplier) {
579 if ($isCustomer) {
580 $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());
581 print '</div>'; // class="fichehalfleft"
582 print '<div class="fichehalfright fichehalfright-lg">';
583 print load_fiche_titre($langs->trans("SupplierDiscounts"), $newcardbutton, '');
584 }
585
586 /*
587 * Liste remises fixes fournisseur restant en cours (= liees a aucune facture ni ligne de facture)
588 */
589 $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
590 $sql .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
591 $sql .= " rc.datec as dc, rc.description,";
592 $sql .= " rc.fk_invoice_supplier_source,";
593 $sql .= " u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
594 $sql .= " fa.ref, fa.type as type";
595 $sql .= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."societe_remise_except as rc";
596 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
597 $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
598 $sql .= " AND rc.entity = ".((int) $conf->entity);
599 $sql .= " AND u.rowid = rc.fk_user";
600 $sql .= " AND rc.discount_type = 1"; // Eliminate customer discounts
601 $sql .= " AND (rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_line IS NULL)";
602 $sql .= " ORDER BY rc.datec DESC";
603
604 $resql = $db->query($sql);
605 if ($resql) {
606 print '<div class="div-table-responsive-no-min">';
607 print '<table class="noborder centpercent">';
608 print '<tr class="liste_titre">';
609 print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
610 print '<td>'.$langs->trans("ReasonDiscount").'</td>';
611 print '<td class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
612 print '<td class="right">'.$langs->trans("AmountHT").'</td>';
613 if (isModEnabled('multicompany')) {
614 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountHT")).'">'.$langs->trans("MulticurrencyAmountHT").'</td>';
615 }
616 print '<td class="right">'.$langs->trans("VATRate").'</td>';
617 print '<td class="right">'.$langs->trans("AmountTTC").'</td>';
618 if (isModEnabled('multicompany')) {
619 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountTTC")).'">'.$langs->trans("MulticurrencyAmountTTC").'</td>';
620 }
621 print '<td width="100" class="center">'.$langs->trans("DiscountOfferedBy").'</td>';
622 print '<td width="50">&nbsp;</td>';
623 print '</tr>';
624
625 $showconfirminfo = array();
626
627 $i = 0;
628 $num = $db->num_rows($resql);
629 if ($num > 0) {
630 while ($i < $num) {
631 $obj = $db->fetch_object($resql);
632
633 $tmpuser->id = $obj->user_id;
634 $tmpuser->login = $obj->login;
635 $tmpuser->firstname = $obj->firstname;
636 $tmpuser->lastname = $obj->lastname;
637 $tmpuser->photo = $obj->photo;
638 $tmpuser->status = $obj->status;
639
640 print '<tr class="oddeven">';
641 print '<td>'.dol_print_date($db->jdate($obj->dc), 'dayhour', 'tzuserrel').'</td>';
642 if (preg_match('/\‍(CREDIT_NOTE\‍)/', $obj->description)) {
643 print '<td class="tdoverflowmax100">';
644 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
645 $facturefournstatic->ref = $obj->ref;
646 $facturefournstatic->type = $obj->type;
647 print preg_replace('/\‍(CREDIT_NOTE\‍)/', $langs->trans("CreditNote"), $obj->description).' '.$facturefournstatic->getNomURl(1);
648 print '</td>';
649 } elseif (preg_match('/\‍(DEPOSIT\‍)/', $obj->description)) {
650 print '<td class="tdoverflowmax100">';
651 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
652 $facturefournstatic->ref = $obj->ref;
653 $facturefournstatic->type = $obj->type;
654 print preg_replace('/\‍(DEPOSIT\‍)/', $langs->trans("InvoiceDeposit"), $obj->description).' '.$facturefournstatic->getNomURl(1);
655 print '</td>';
656 } elseif (preg_match('/\‍(EXCESS PAID\‍)/', $obj->description)) {
657 print '<td class="tdoverflowmax100">';
658 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
659 $facturefournstatic->ref = $obj->ref;
660 $facturefournstatic->type = $obj->type;
661 print preg_replace('/\‍(EXCESS PAID\‍)/', $langs->trans("ExcessPaid"), $obj->description).' '.$facturefournstatic->getNomURl(1);
662 print '</td>';
663 } else {
664 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).'">';
665 print dol_escape_htmltag($obj->description);
666 print '</td>';
667 }
668 print '<td class="nowrap"><span class="opacitymedium">'.$langs->trans("NotConsumed").'</span></td>';
669 print '<td class="right nowraponall amount">'.price($obj->amount_ht).'</td>';
670 if (isModEnabled('multicompany')) {
671 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).'</td>';
672 }
673 print '<td class="right">'.vatrate($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), true).'</td>';
674 print '<td class="right nowraponall amount">'.price($obj->amount_ttc).'</td>';
675 if (isModEnabled('multicompany')) {
676 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ttc).'</td>';
677 }
678 print '<td class="tdoverflowmax100">';
679 print $tmpuser->getNomUrl(-1);
680 print '</td>';
681
682 if ($user->hasRight('societe', 'creer') || $user->hasRight('facture', 'creer')) {
683 print '<td class="center nowrap">';
684 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>';
685 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>';
686 print '</td>';
687 } else {
688 print '<td>&nbsp;</td>';
689 }
690 print '</tr>';
691
692 if ($action == 'split' && GETPOST('remid') == $obj->rowid) {
693 $showconfirminfo['rowid'] = $obj->rowid;
694 $showconfirminfo['amount_ttc'] = $obj->amount_ttc;
695 }
696 $i++;
697 }
698 } else {
699 $colspan = 8;
700 if (isModEnabled('multicompany')) {
701 $colspan += 2;
702 }
703 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
704 }
705 $db->free($resql);
706 print "</table>";
707 print '</div>';
708
709 if (count($showconfirminfo)) {
710 $amount1 = price2num($showconfirminfo['amount_ttc'] / 2, 'MT');
711 $amount2 = ($showconfirminfo['amount_ttc'] - (float) $amount1);
712 $formquestion = array(
713 'text' => $langs->trans('TypeAmountOfEachNewDiscount'),
714 0 => array('type' => 'text', 'name' => 'amount_ttc_1', 'label' => $langs->trans("AmountTTC").' 1', 'value' => $amount1, 'size' => '5'),
715 1 => array('type' => 'text', 'name' => 'amount_ttc_2', 'label' => $langs->trans("AmountTTC").' 2', 'value' => $amount2, 'size' => '5')
716 );
717 $langs->load("dict");
718 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);
719 }
720 } else {
721 dol_print_error($db);
722 }
723
724 if ($isCustomer) {
725 print '</div>'; // class="fichehalfright"
726 print '</div>'; // class="fichecenter"
727 }
728 }
729
730 print '<div class="clearboth"></div><br><br>';
731
732 /*
733 * List discount consumed (=liees a une ligne de facture ou facture)
734 */
735
736 print load_fiche_titre($langs->trans("DiscountAlreadyCounted"));
737
738 if ($isCustomer) {
739 if ($isSupplier) {
740 print '<div class="fichecenter">';
741 print '<div class="fichehalfleft fichehalfleft-lg">';
742 print load_fiche_titre($langs->trans("CustomerDiscounts"), '', '');
743 }
744
745 // Discount linked to invoice lines
746 $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
747 $sql .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
748 $sql .= " rc.datec as dc, rc.description, rc.fk_facture_line, rc.fk_facture_source,";
749 $sql .= " u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
750 $sql .= " f.rowid as invoiceid, f.ref,";
751 $sql .= " fa.ref as invoice_source_ref, fa.type as type";
752 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
753 $sql .= " , ".MAIN_DB_PREFIX."user as u";
754 $sql .= " , ".MAIN_DB_PREFIX."facturedet as fc";
755 $sql .= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
756 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
757 $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
758 $sql .= " AND rc.fk_facture_line = fc.rowid";
759 $sql .= " AND fc.fk_facture = f.rowid";
760 $sql .= " AND rc.fk_user = u.rowid";
761 $sql .= " AND rc.discount_type = 0"; // Eliminate supplier discounts
762 $sql .= " ORDER BY dc DESC";
763 //$sql.= " UNION ";
764 // Discount linked to invoices
765 $sql2 = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
766 $sql2 .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
767 $sql2 .= " rc.datec as dc, rc.description, rc.fk_facture, rc.fk_facture_source,";
768 $sql2 .= " u.login, u.rowid as user_id, u.statut as status, u.firstname, u.lastname, u.photo,";
769 $sql2 .= " f.rowid as invoiceid, f.ref,";
770 $sql2 .= " fa.ref as invoice_source_ref, fa.type as type";
771 $sql2 .= " FROM ".MAIN_DB_PREFIX."facture as f";
772 $sql2 .= " , ".MAIN_DB_PREFIX."user as u";
773 $sql2 .= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
774 $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid";
775 $sql2 .= " WHERE rc.fk_soc = ".((int) $object->id);
776 $sql2 .= " AND rc.fk_facture = f.rowid";
777 $sql2 .= " AND rc.fk_user = u.rowid";
778 $sql2 .= " AND rc.discount_type = 0"; // Eliminate supplier discounts
779 $sql2 .= " ORDER BY dc DESC";
780
781 $resql = $db->query($sql);
782 $resql2 = null;
783 if ($resql) {
784 $resql2 = $db->query($sql2);
785 }
786 if ($resql2) {
787 print '<div class="div-table-responsive-no-min">';
788 print '<table class="noborder centpercent">';
789 print '<tr class="liste_titre">';
790 print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
791 print '<td>'.$langs->trans("ReasonDiscount").'</td>';
792 print '<td class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
793 print '<td class="right">'.$langs->trans("AmountHT").'</td>';
794 if (isModEnabled('multicompany')) {
795 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountHT")).'">'.$langs->trans("MulticurrencyAmountHT").'</td>';
796 }
797 print '<td class="right">'.$langs->trans("VATRate").'</td>';
798 print '<td class="right">'.$langs->trans("AmountTTC").'</td>';
799 if (isModEnabled('multicompany')) {
800 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountTTC")).'">'.$langs->trans("MulticurrencyAmountTTC").'</td>';
801 }
802 print '<td width="100" class="center">'.$langs->trans("Author").'</td>';
803 print '<td width="50">&nbsp;</td>';
804 print '</tr>';
805
806 $tab_sqlobj = array();
807 $tab_sqlobjOrder = array();
808 $num = $db->num_rows($resql);
809 if ($num > 0) {
810 for ($i = 0; $i < $num; $i++) {
811 $sqlobj = $db->fetch_object($resql);
812 $tab_sqlobj[] = $sqlobj;
813 $tab_sqlobjOrder[] = $db->jdate($sqlobj->dc);
814 }
815 }
816 $db->free($resql);
817
818 $num = $db->num_rows($resql2);
819 for ($i = 0; $i < $num; $i++) {
820 $sqlobj = $db->fetch_object($resql2);
821 $tab_sqlobj[] = $sqlobj;
822 $tab_sqlobjOrder[] = $db->jdate($sqlobj->dc);
823 }
824 $db->free($resql2);
825 $array1_sort_order = SORT_DESC;
826 array_multisort($tab_sqlobjOrder, $array1_sort_order, $tab_sqlobj);
827
828 $num = count($tab_sqlobj);
829 if ($num > 0) {
830 $i = 0;
831 while ($i < $num) {
832 $obj = array_shift($tab_sqlobj);
833
834 $tmpuser->id = $obj->user_id;
835 $tmpuser->login = $obj->login;
836 $tmpuser->firstname = $obj->firstname;
837 $tmpuser->lastname = $obj->lastname;
838 $tmpuser->photo = $obj->photo;
839 $tmpuser->status = $obj->status;
840
841 print '<tr class="oddeven">';
842 print '<td>'.dol_print_date($db->jdate($obj->dc), 'dayhour').'</td>';
843 if (preg_match('/\‍(CREDIT_NOTE\‍)/', $obj->description)) {
844 print '<td class="tdoverflowmax100">';
845 $facturestatic->id = $obj->fk_facture_source;
846 $facturestatic->ref = $obj->invoice_source_ref;
847 $facturestatic->type = $obj->type;
848 print preg_replace('/\‍(CREDIT_NOTE\‍)/', $langs->trans("CreditNote"), $obj->description).' '.$facturestatic->getNomURl(1);
849 print '</td>';
850 } elseif (preg_match('/\‍(DEPOSIT\‍)/', $obj->description)) {
851 print '<td class="tdoverflowmax100">';
852 $facturestatic->id = $obj->fk_facture_source;
853 $facturestatic->ref = $obj->invoice_source_ref;
854 $facturestatic->type = $obj->type;
855 print preg_replace('/\‍(DEPOSIT\‍)/', $langs->trans("InvoiceDeposit"), $obj->description).' '.$facturestatic->getNomURl(1);
856 print '</td>';
857 } elseif (preg_match('/\‍(EXCESS RECEIVED\‍)/', $obj->description)) {
858 print '<td class="tdoverflowmax100">';
859 $facturestatic->id = $obj->fk_facture_source;
860 $facturestatic->ref = $obj->invoice_source_ref;
861 $facturestatic->type = $obj->type;
862 print preg_replace('/\‍(EXCESS RECEIVED\‍)/', $langs->trans("Invoice"), $obj->description).' '.$facturestatic->getNomURl(1);
863 print '</td>';
864 } else {
865 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).'">';
866 print dol_escape_htmltag($obj->description);
867 print '</td>';
868 }
869 print '<td class="left nowrap">';
870 if ($obj->invoiceid) {
871 print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->invoiceid.'">'.img_object($langs->trans("ShowBill"), 'bill').' '.$obj->ref.'</a>';
872 }
873 print '</td>';
874 print '<td class="right nowraponall amount">'.price($obj->amount_ht).'</td>';
875 if (isModEnabled('multicompany')) {
876 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).'</td>';
877 }
878 print '<td class="right nowraponall">'.vatrate($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), true).'</td>';
879 print '<td class="right nowraponall amount">'.price($obj->amount_ttc).'</td>';
880 if (isModEnabled('multicompany')) {
881 print '<td class="right">'.price($obj->multicurrency_amount_ttc).'</td>';
882 }
883 print '<td class="tdoverflowmax100">';
884 print $tmpuser->getNomUrl(-1);
885 print '</td>';
886
887 print '<td>&nbsp;</td>';
888 print '</tr>';
889 $i++;
890 }
891 } else {
892 $colspan = 8;
893 if (isModEnabled('multicompany')) {
894 $colspan += 2;
895 }
896 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
897 }
898
899 print "</table>";
900 print '</div>';
901 } else {
902 dol_print_error($db);
903 }
904 }
905
906 if ($isSupplier) {
907 if ($isCustomer) {
908 print '</div>'; // class="fichehalfleft"
909 print '<div class="fichehalfright fichehalfright-lg">';
910 print load_fiche_titre($langs->trans("SupplierDiscounts"), '', '');
911 }
912
913 // Discount linked to invoice lines
914 $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
915 $sql .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
916 $sql .= " rc.datec as dc, rc.description, rc.fk_invoice_supplier_line,";
917 $sql .= " rc.fk_invoice_supplier_source,";
918 $sql .= " u.login, u.rowid as user_id, u.statut as user_status, u.firstname, u.lastname, u.photo,";
919 $sql .= " f.rowid as invoiceid, f.ref as ref,";
920 $sql .= " fa.ref as invoice_source_ref, fa.type as type";
921 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
922 $sql .= " , ".MAIN_DB_PREFIX."user as u";
923 $sql .= " , ".MAIN_DB_PREFIX."facture_fourn_det as fc";
924 $sql .= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
925 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
926 $sql .= " WHERE rc.fk_soc = ".((int) $object->id);
927 $sql .= " AND rc.fk_invoice_supplier_line = fc.rowid";
928 $sql .= " AND fc.fk_facture_fourn = f.rowid";
929 $sql .= " AND rc.fk_user = u.rowid";
930 $sql .= " AND rc.discount_type = 1"; // Eliminate customer discounts
931 $sql .= " ORDER BY dc DESC";
932 //$sql.= " UNION ";
933 // Discount linked to invoices
934 $sql2 = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx, rc.vat_src_code,";
935 $sql2 .= " rc.multicurrency_amount_ht, rc.multicurrency_amount_tva, rc.multicurrency_amount_ttc,";
936 $sql2 .= " rc.datec as dc, rc.description, rc.fk_invoice_supplier,";
937 $sql2 .= " rc.fk_invoice_supplier_source,";
938 $sql2 .= " u.login, u.rowid as user_id, u.statut as user_status, u.firstname, u.lastname, u.photo,";
939 $sql2 .= " f.rowid as invoiceid, f.ref as ref,";
940 $sql2 .= " fa.ref as invoice_source_ref, fa.type as type";
941 $sql2 .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
942 $sql2 .= " , ".MAIN_DB_PREFIX."user as u";
943 $sql2 .= " , ".MAIN_DB_PREFIX."societe_remise_except as rc";
944 $sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as fa ON rc.fk_invoice_supplier_source = fa.rowid";
945 $sql2 .= " WHERE rc.fk_soc = ".((int) $object->id);
946 $sql2 .= " AND rc.fk_invoice_supplier = f.rowid";
947 $sql2 .= " AND rc.fk_user = u.rowid";
948 $sql2 .= " AND rc.discount_type = 1"; // Eliminate customer discounts
949 $sql2 .= " ORDER BY dc DESC";
950
951 $resql = $db->query($sql);
952 $resql2 = null;
953 if ($resql) {
954 $resql2 = $db->query($sql2);
955 }
956 if ($resql2) {
957 print '<div class="div-table-responsive-no-min">';
958 print '<table class="noborder centpercent">';
959 print '<tr class="liste_titre">';
960 print '<td class="widthdate">'.$langs->trans("Date").'</td>'; // Need 120+ for format with AM/PM
961 print '<td>'.$langs->trans("ReasonDiscount").'</td>';
962 print '<td class="nowrap">'.$langs->trans("ConsumedBy").'</td>';
963 print '<td class="right">'.$langs->trans("AmountHT").'</td>';
964 if (isModEnabled('multicompany')) {
965 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountHT")).'">'.$langs->trans("MulticurrencyAmountHT").'</td>';
966 }
967 print '<td class="right">'.$langs->trans("VATRate").'</td>';
968 print '<td class="right">'.$langs->trans("AmountTTC").'</td>';
969 if (isModEnabled('multicompany')) {
970 print '<td class="right tdoverflowmax125" title="'.dol_escape_htmltag($langs->trans("MulticurrencyAmountTTC")).'">'.$langs->trans("MulticurrencyAmountTTC").'</td>';
971 }
972 print '<td width="100" class="center">'.$langs->trans("Author").'</td>';
973 print '<td width="50">&nbsp;</td>';
974 print '</tr>';
975
976 $tab_sqlobj = array();
977 $tab_sqlobjOrder = array();
978 $num = $db->num_rows($resql);
979 if ($num > 0) {
980 for ($i = 0; $i < $num; $i++) {
981 $sqlobj = $db->fetch_object($resql);
982 $tab_sqlobj[] = $sqlobj;
983 $tab_sqlobjOrder[] = $db->jdate($sqlobj->dc);
984 }
985 }
986 $db->free($resql);
987
988 $num = $db->num_rows($resql2);
989 for ($i = 0; $i < $num; $i++) {
990 $sqlobj = $db->fetch_object($resql2);
991 $tab_sqlobj[] = $sqlobj;
992 $tab_sqlobjOrder[] = $db->jdate($sqlobj->dc);
993 }
994 $db->free($resql2);
995 $array1_sort_order = SORT_DESC;
996 array_multisort($tab_sqlobjOrder, $array1_sort_order, $tab_sqlobj);
997
998 $num = count($tab_sqlobj);
999 if ($num > 0) {
1000 $i = 0;
1001 while ($i < $num) {
1002 $obj = array_shift($tab_sqlobj);
1003
1004 $tmpuser->id = $obj->user_id;
1005 $tmpuser->login = $obj->login;
1006 $tmpuser->firstname = $obj->firstname;
1007 $tmpuser->lastname = $obj->lastname;
1008 $tmpuser->photo = $obj->photo;
1009 $tmpuser->status = $obj->status;
1010
1011 print '<tr class="oddeven">';
1012 print '<td>'.dol_print_date($db->jdate($obj->dc), 'dayhour').'</td>';
1013 if (preg_match('/\‍(CREDIT_NOTE\‍)/', $obj->description)) {
1014 print '<td class="tdoverflowmax100">';
1015 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
1016 $facturefournstatic->ref = $obj->invoice_source_ref;
1017 $facturefournstatic->type = $obj->type;
1018 print preg_replace('/\‍(CREDIT_NOTE\‍)/', $langs->trans("CreditNote"), $obj->description).' '.$facturefournstatic->getNomURl(1);
1019 print '</td>';
1020 } elseif (preg_match('/\‍(DEPOSIT\‍)/', $obj->description)) {
1021 print '<td class="tdoverflowmax100">';
1022 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
1023 $facturefournstatic->ref = $obj->invoice_source_ref;
1024 $facturefournstatic->type = $obj->type;
1025 print preg_replace('/\‍(DEPOSIT\‍)/', $langs->trans("InvoiceDeposit"), $obj->description).' '.$facturefournstatic->getNomURl(1);
1026 print '</td>';
1027 } elseif (preg_match('/\‍(EXCESS PAID\‍)/', $obj->description)) {
1028 print '<td class="tdoverflowmax100">';
1029 $facturefournstatic->id = $obj->fk_invoice_supplier_source;
1030 $facturefournstatic->ref = $obj->invoice_source_ref;
1031 $facturefournstatic->type = $obj->type;
1032 print preg_replace('/\‍(EXCESS PAID\‍)/', $langs->trans("Invoice"), $obj->description).' '.$facturefournstatic->getNomURl(1);
1033 print '</td>';
1034 } else {
1035 print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->description).'">';
1036 print dol_escape_htmltag($obj->description);
1037 print '</td>';
1038 }
1039 print '<td class="left nowrap">';
1040 if ($obj->invoiceid) {
1041 print '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$obj->invoiceid.'">'.img_object($langs->trans("ShowBill"), 'bill').' '.$obj->ref.'</a>';
1042 }
1043 print '</td>';
1044 print '<td class="right nowraponall amount">'.price($obj->amount_ht).'</td>';
1045 if (isModEnabled('multicompany')) {
1046 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ht).'</td>';
1047 }
1048 print '<td class="right">'.vatrate($obj->tva_tx.($obj->vat_src_code ? ' ('.$obj->vat_src_code.')' : ''), true).'</td>';
1049 print '<td class="right nowraponall amount">'.price($obj->amount_ttc).'</td>';
1050 if (isModEnabled('multicompany')) {
1051 print '<td class="right nowraponall amount">'.price($obj->multicurrency_amount_ttc).'</td>';
1052 }
1053 print '<td class="tdoverflowmax100">';
1054 print $tmpuser->getNomUrl(-1);
1055 print '</td>';
1056
1057 print '<td>&nbsp;</td>';
1058
1059 print '</tr>';
1060 $i++;
1061 }
1062 } else {
1063 $colspan = 8;
1064 if (isModEnabled('multicompany')) {
1065 $colspan += 2;
1066 }
1067 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
1068 }
1069
1070 print "</table>";
1071 print '</div>';
1072 } else {
1073 dol_print_error($db);
1074 }
1075
1076 if ($isCustomer) {
1077 print '</div>'; // class="fichehalfright"
1078 print '</div>'; // class="fichecenter"
1079 }
1080 }
1081}
1082
1083// End of page
1084llxFooter();
1085$db->close();
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()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 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.