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