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