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