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