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