dolibarr  13.0.2
paiement.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
4  * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2004 Christophe Combelles <ccomb@free.fr>
6  * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
7  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
8  * Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com>
9  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
10  * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
11  * Copyright (C) 2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
12  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program. If not, see <https://www.gnu.org/licenses/>.
26  */
27 
34 require '../../main.inc.php';
35 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
41 
42 // Load translation files required by the page
43 $langs->loadLangs(array('companies', 'bills', 'banks', 'compta'));
44 
45 $action = GETPOST('action', 'alpha');
46 $confirm = GETPOST('confirm', 'alpha');
47 $optioncss = GETPOST('optioncss', 'alpha');
48 
49 $facid = GETPOST('facid', 'int');
50 $socid = GETPOST('socid', 'int');
51 $accountid = GETPOST('accountid', 'int');
52 $day = GETPOST('day', 'int');
53 $month = GETPOST('month', 'int');
54 $year = GETPOST('year', 'int');
55 
56 $search_ref = GETPOST("search_ref", "alpha");
57 $search_account = GETPOST("search_account", "int");
58 $search_paymenttype = GETPOST("search_paymenttype");
59 $search_amount = GETPOST("search_amount", 'alpha'); // alpha because we must be able to search on "< x"
60 $search_company = GETPOST("search_company", 'alpha');
61 $search_payment_num = GETPOST('search_payment_num', 'alpha');
62 
63 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
64 $sortfield = GETPOST("sortfield", 'alpha');
65 $sortorder = GETPOST("sortorder", 'alpha');
66 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
67 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
68 $offset = $limit * $page;
69 $pageprev = $page - 1;
70 $pagenext = $page + 1;
71 if (!$sortorder) $sortorder = "DESC";
72 if (!$sortfield) $sortfield = "p.rowid";
73 
74 $amounts = array();
75 $amountsresttopay = array();
76 $addwarning = 0;
77 
78 $multicurrency_amounts = array();
79 $multicurrency_amountsresttopay = array();
80 
81 // Security check
82 if ($user->socid > 0)
83 {
84  $socid = $user->socid;
85 }
86 
87 $object = new PaiementFourn($db);
88 
89 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
90 $hookmanager->initHooks(array('paymentsupplierlist'));
91 $extrafields = new ExtraFields($db);
92 
93 // fetch optionals attributes and labels
94 $extrafields->fetch_name_optionals_label($object->table_element);
95 
96 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
97 
98 $arrayfields = array();
99 
100 
101 
102 /*
103  * Actions
104  */
105 
106 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
107 {
108  $search_ref = "";
109  $search_account = "";
110  $search_amount = "";
111  $search_paymenttype = "";
112  $search_payment_num = "";
113  $search_company = "";
114  $day = '';
115  $year = '';
116  $month = '';
117  $search_array_options = array();
118 }
119 
120 $parameters = array('socid'=>$socid);
121 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
122 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
123 
124 if (empty($reshook))
125 {
126  if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm == 'yes'))
127  {
128  $error = 0;
129 
130  $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
131  $paiement_id = 0;
132  $totalpayment = 0;
133  $atleastonepaymentnotnull = 0;
134  $multicurrency_totalpayment = 0;
135 
136  // Generate payment array and check if there is payment higher than invoice and payment date before invoice date
137  $tmpinvoice = new FactureFournisseur($db);
138  foreach ($_POST as $key => $value)
139  {
140  if (substr($key, 0, 7) == 'amount_')
141  {
142  $cursorfacid = substr($key, 7);
143  $amounts[$cursorfacid] = price2num(GETPOST($key));
144  if (!empty($amounts[$cursorfacid])) {
145  $atleastonepaymentnotnull++;
146  if (is_numeric($amounts[$cursorfacid])) {
147  $totalpayment = $totalpayment + $amounts[$cursorfacid];
148  } else {
149  setEventMessages($langs->transnoentities("InputValueIsNotAnNumber", GETPOST($key)), null, 'warnings');
150  }
151  }
152  $result = $tmpinvoice->fetch($cursorfacid);
153  if ($result <= 0) dol_print_error($db);
154  $amountsresttopay[$cursorfacid] = price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement());
155  if ($amounts[$cursorfacid])
156  {
157  // Check amount
158  if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid])))
159  {
160  $addwarning = 1;
161  $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPaySupplier")).' '.$langs->trans("HelpPaymentHigherThanReminderToPaySupplier");
162  }
163  // Check date
164  if ($datepaye && ($datepaye < $tmpinvoice->date))
165  {
166  $langs->load("errors");
167  //$error++;
168  setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye, 'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings');
169  }
170  }
171 
172  $formquestion[$i++] = array('type' => 'hidden', 'name' => $key, 'value' => $_POST[$key]);
173  } elseif (substr($key, 0, 21) == 'multicurrency_amount_')
174  {
175  $cursorfacid = substr($key, 21);
176  $multicurrency_amounts[$cursorfacid] = (GETPOST($key) ? price2num(GETPOST($key)) : 0);
177  $multicurrency_totalpayment += $multicurrency_amounts[$cursorfacid];
178  if (!empty($multicurrency_amounts[$cursorfacid])) $atleastonepaymentnotnull++;
179  $result = $tmpinvoice->fetch($cursorfacid);
180  if ($result <= 0) dol_print_error($db);
181  $multicurrency_amountsresttopay[$cursorfacid] = price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement(1));
182  if ($multicurrency_amounts[$cursorfacid])
183  {
184  // Check amount
185  if ($multicurrency_amounts[$cursorfacid] && (abs($multicurrency_amounts[$cursorfacid]) > abs($multicurrency_amountsresttopay[$cursorfacid])))
186  {
187  $addwarning = 1;
188  $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPaySupplier")).' '.$langs->trans("HelpPaymentHigherThanReminderToPaySupplier");
189  }
190  // Check date
191  if ($datepaye && ($datepaye < $tmpinvoice->date))
192  {
193  $langs->load("errors");
194  //$error++;
195  setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye, 'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings');
196  }
197  }
198 
199  $formquestion[$i++] = array('type' => 'hidden', 'name' => $key, 'value' => GETPOST($key, 'int'));
200  }
201  }
202 
203  // Check parameters
204  if ($_POST['paiementid'] <= 0)
205  {
206  setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('PaymentMode')), null, 'errors');
207  $error++;
208  }
209 
210  if (!empty($conf->banque->enabled))
211  {
212  // If bank module is on, account is required to enter a payment
213  if (GETPOST('accountid') <= 0)
214  {
215  setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('AccountToCredit')), null, 'errors');
216  $error++;
217  }
218  }
219 
220  if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull))
221  {
222  setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->trans('PaymentAmount')), null, 'errors');
223  $error++;
224  }
225 
226  if (empty($datepaye))
227  {
228  setEventMessages($langs->transnoentities('ErrorFieldRequired', $langs->transnoentities('Date')), null, 'errors');
229  $error++;
230  }
231 
232  // Check if payments in both currency
233  if ($totalpayment > 0 && $multicurrency_totalpayment > 0)
234  {
235  setEventMessages($langs->transnoentities('ErrorPaymentInBothCurrency'), null, 'errors');
236  $error++;
237  }
238  }
239 
240  /*
241  * Action add_paiement
242  */
243  if ($action == 'add_paiement')
244  {
245  if ($error)
246  {
247  $action = 'create';
248  }
249  // All the next of this action is displayed at the page's bottom.
250  }
251 
252 
253  /*
254  * Action confirm_paiement
255  */
256  if ($action == 'confirm_paiement' && $confirm == 'yes')
257  {
258  $error = 0;
259 
260  $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
261 
262  // Clean parameters amount if payment is for a credit note
263  foreach ($amounts as $key => $value) // How payment is dispatched
264  {
265  $tmpinvoice = new FactureFournisseur($db);
266  $tmpinvoice->fetch($key);
267  if ($tmpinvoice->type == FactureFournisseur::TYPE_CREDIT_NOTE)
268  {
269  $newvalue = price2num($value, 'MT');
270  $amounts[$key] = - abs($newvalue);
271  }
272  }
273 
274  foreach ($multicurrency_amounts as $key => $value) // How payment is dispatched
275  {
276  $tmpinvoice = new FactureFournisseur($db);
277  $tmpinvoice->fetch($key);
278  if ($tmpinvoice->type == FactureFournisseur::TYPE_CREDIT_NOTE)
279  {
280  $newvalue = price2num($value, 'MT');
281  $multicurrency_amounts[$key] = - abs($newvalue);
282  }
283  }
284 
285  //var_dump($amounts);
286  //var_dump($multicurrency_amounts);
287  //exit;
288 
289  if (!$error)
290  {
291  $db->begin();
292 
293  $thirdparty = new Societe($db);
294  if ($socid > 0) $thirdparty->fetch($socid);
295 
296  // Creation of payment line
297  $paiement = new PaiementFourn($db);
298  $paiement->datepaye = $datepaye;
299  $paiement->amounts = $amounts; // Array of amounts
300  $paiement->multicurrency_amounts = $multicurrency_amounts;
301  $paiement->paiementid = GETPOST('paiementid', 'int');
302 
303  $paiement->num_payment = GETPOST('num_paiement', 'alphanohtml');
304  $paiement->note_private = GETPOST('comment', 'alpha');
305  $paiement->num_payment = $paiement->num_payment;
306  $paiement->note_private = $paiement->note_private;
307 
308  if (!$error)
309  {
310  $paiement_id = $paiement->create($user, (GETPOST('closepaidinvoices') == 'on' ? 1 : 0), $thirdparty);
311  if ($paiement_id < 0)
312  {
313  setEventMessages($paiement->error, $paiement->errors, 'errors');
314  $error++;
315  }
316  }
317 
318  if (!$error)
319  {
320  $result = $paiement->addPaymentToBank($user, 'payment_supplier', '(SupplierInvoicePayment)', $accountid, '', '');
321  if ($result < 0)
322  {
323  setEventMessages($paiement->error, $paiement->errors, 'errors');
324  $error++;
325  }
326  }
327 
328  if (!$error)
329  {
330  $db->commit();
331 
332  // If payment dispatching on more than one invoice, we stay on summary page, otherwise go on invoice card
333  $invoiceid = 0;
334  foreach ($paiement->amounts as $key => $amount)
335  {
336  $facid = $key;
337  if (is_numeric($amount) && $amount <> 0)
338  {
339  if ($invoiceid != 0) $invoiceid = -1; // There is more than one invoice payed by this payment
340  else $invoiceid = $facid;
341  }
342  }
343  if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$invoiceid;
344  else $loc = DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$paiement_id;
345  header('Location: '.$loc);
346  exit;
347  } else {
348  $db->rollback();
349  }
350  }
351  }
352 }
353 
354 
355 /*
356  * View
357  */
358 
359 $form = new Form($db);
360 $formother = new FormOther($db);
361 
362 $supplierstatic = new Societe($db);
363 $invoicesupplierstatic = new FactureFournisseur($db);
364 
365 llxHeader('', $langs->trans('ListPayment'));
366 
367 if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paiement')
368 {
369  $object = new FactureFournisseur($db);
370  $result = $object->fetch($facid);
371 
372  $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
373  $dateinvoice = ($datefacture == '' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 : '') : $datefacture);
374 
375  $sql = 'SELECT s.nom as name, s.rowid as socid,';
376  $sql .= ' f.rowid, f.ref, f.ref_supplier, f.total_ttc as total, f.fk_mode_reglement, f.fk_account';
377  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
378  $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'facture_fourn as f';
379  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
380  $sql .= ' WHERE f.fk_soc = s.rowid';
381  $sql .= ' AND f.rowid = '.$facid;
382  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
383  $resql = $db->query($sql);
384  if ($resql)
385  {
386  $num = $db->num_rows($resql);
387  if ($num)
388  {
389  $obj = $db->fetch_object($resql);
390  $total = $obj->total;
391 
392  print load_fiche_titre($langs->trans('DoPayment'));
393 
394  // Add realtime total information
395  if (!empty($conf->use_javascript_ajax))
396  {
397  print "\n".'<script type="text/javascript" language="javascript">';
398  print '$(document).ready(function () {
399 
400  function _elemToJson(selector)
401  {
402  var subJson = {};
403  $.map(selector.serializeArray(), function(n,i)
404  {
405  subJson[n["name"]] = n["value"];
406  });
407 
408  return subJson;
409  }
410  function callForResult(imgId)
411  {
412  var json = {};
413  var form = $("#payment_form");
414 
415  json["invoice_type"] = $("#invoice_type").val();
416  json["amountPayment"] = $("#amountpayment").attr("value");
417  json["amounts"] = _elemToJson(form.find("input.amount"));
418  json["remains"] = _elemToJson(form.find("input.remain"));
419 
420  if (imgId != null) {
421  json["imgClicked"] = imgId;
422  }
423 
424  $.post("'.DOL_URL_ROOT.'/compta/ajaxpayment.php", json, function(data)
425  {
426  json = $.parseJSON(data);
427 
428  form.data(json);
429 
430  for (var key in json)
431  {
432  if (key == "result") {
433  if (json["makeRed"]) {
434  $("#"+key).addClass("error");
435  } else {
436  $("#"+key).removeClass("error");
437  }
438  json[key]=json["label"]+" "+json[key];
439  $("#"+key).text(json[key]);
440  } else {console.log(key);
441  form.find("input[name*=\""+key+"\"]").each(function() {
442  $(this).attr("value", json[key]);
443  });
444  }
445  }
446  });
447  }
448  $("#payment_form").find("input.amount").change(function() {
449  callForResult();
450  });
451  $("#payment_form").find("input.amount").keyup(function() {
452  callForResult();
453  });
454  ';
455 
456  print ' });'."\n";
457 
458  //Add js for AutoFill
459  print ' $(document).ready(function () {';
460  print ' $(".AutoFillAmout").on(\'click touchstart\', function(){
461  $("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value")).trigger("change");
462  });';
463  print ' });'."\n";
464 
465  print ' </script>'."\n";
466  }
467 
468  print '<form id="payment_form" name="addpaiement" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
469  print '<input type="hidden" name="token" value="'.newToken().'">';
470  print '<input type="hidden" name="action" value="add_paiement">';
471  print '<input type="hidden" name="facid" value="'.$facid.'">';
472  print '<input type="hidden" name="ref_supplier" value="'.$obj->ref_supplier.'">';
473  print '<input type="hidden" name="socid" value="'.$obj->socid.'">';
474  print '<input type="hidden" name="type" id="invoice_type" value="'.$object->type.'">';
475  print '<input type="hidden" name="societe" value="'.$obj->name.'">';
476 
478 
479  print '<table class="border centpercent">';
480 
481  print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans('Company').'</td><td>';
482  $supplierstatic->id = $obj->socid;
483  $supplierstatic->name = $obj->name;
484  print $supplierstatic->getNomUrl(1, 'supplier');
485  print '</td></tr>';
486  print '<tr><td class="fieldrequired">'.$langs->trans('Date').'</td><td>';
487  print $form->selectDate($dateinvoice, '', '', '', 0, "addpaiement", 1, 1, 0, '', '', $object->date);
488  print '</td></tr>';
489  print '<tr><td class="fieldrequired">'.$langs->trans('PaymentMode').'</td><td>';
490  $form->select_types_paiements(empty($_POST['paiementid']) ? $obj->fk_mode_reglement : $_POST['paiementid'], 'paiementid');
491  print '</td>';
492  if (!empty($conf->banque->enabled))
493  {
494  print '<tr><td class="fieldrequired">'.$langs->trans('Account').'</td><td>';
495  $form->select_comptes(empty($accountid) ? $obj->fk_account : $accountid, 'accountid', 0, '', 2);
496  print '</td></tr>';
497  } else {
498  print '<tr><td>&nbsp;</td></tr>';
499  }
500  print '<tr><td>'.$langs->trans('Numero').'</td><td><input name="num_paiement" type="text" value="'.(empty($_POST['num_paiement']) ? '' : $_POST['num_paiement']).'"></td></tr>';
501  print '<tr><td>'.$langs->trans('Comments').'</td>';
502  print '<td class="tdtop">';
503  print '<textarea name="comment" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.'">'.(empty($_POST['comment']) ? '' : $_POST['comment']).'</textarea></td></tr>';
504  print '</table>';
506 
507 
508  $parameters = array('facid'=>$facid, 'ref'=>$ref, 'objcanvas'=>$objcanvas);
509  $reshook = $hookmanager->executeHooks('paymentsupplierinvoices', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
510  $error = $hookmanager->error; $errors = $hookmanager->errors;
511  if (empty($reshook))
512  {
513  /*
514  * All unpaid supplier invoices
515  */
516  $sql = 'SELECT f.rowid as facid, f.ref, f.ref_supplier, f.type, f.total_ht, f.total_ttc,';
517  $sql .= ' f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc,';
518  $sql .= ' f.datef as df, f.date_lim_reglement as dlr,';
519  $sql .= ' SUM(pf.amount) as am, SUM(pf.multicurrency_amount) as multicurrency_am';
520  $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f';
521  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
522  $sql .= " WHERE f.entity = ".$conf->entity;
523  $sql .= ' AND f.fk_soc = '.$object->socid;
524  $sql .= ' AND f.paye = 0';
525  $sql .= ' AND f.fk_statut = 1'; // Status=0 => unvalidated, Status=2 => canceled
526  if ($object->type != FactureFournisseur::TYPE_CREDIT_NOTE)
527  {
528  $sql .= ' AND f.type IN (0,1,3,5)'; // Standard invoice, replacement, deposit, situation
529  } else {
530  $sql .= ' AND f.type = 2'; // If paying back a credit note, we show all credit notes
531  }
532  // Group by because we have a total
533  $sql .= ' GROUP BY f.datef, f.ref, f.ref_supplier, f.rowid, f.type, f.total_ht, f.total_ttc, f.multicurrency_total_ttc, f.datef, f.date_lim_reglement';
534  // Sort invoices by date and serial number: the older one comes first
535  $sql .= ' ORDER BY f.datef ASC, f.ref ASC';
536 
537  $resql = $db->query($sql);
538  if ($resql)
539  {
540  $num = $db->num_rows($resql);
541  if ($num > 0)
542  {
543  $i = 0;
544  print '<br>';
545 
546  if (!empty($conf->use_javascript_ajax)) {
547  //Add js for AutoFill
548  print "\n".'<script type="text/javascript" language="javascript">';
549  print ' $(document).ready(function () {';
550  print ' $(".AutoFillAmout").on(\'click touchstart\', function(){
551  $("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value"));
552  });';
553  print ' });'."\n";
554  print ' </script>'."\n";
555  }
556 
557  print '<div class="div-table-responsive-no-min">';
558  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
559 
560  print '<tr class="liste_titre">';
561  print '<td>'.$langs->trans('Invoice').'</td>';
562  print '<td>'.$langs->trans('RefSupplier').'</td>';
563  print '<td class="center">'.$langs->trans('Date').'</td>';
564  print '<td class="center">'.$langs->trans('DateMaxPayment').'</td>';
565  if (!empty($conf->multicurrency->enabled)) print '<td>'.$langs->trans('Currency').'</td>';
566  if (!empty($conf->multicurrency->enabled)) print '<td class="right">'.$langs->trans('MulticurrencyAmountTTC').'</td>';
567  if (!empty($conf->multicurrency->enabled)) print '<td class="right">'.$langs->trans('MulticurrencyAlreadyPaid').'</td>';
568  if (!empty($conf->multicurrency->enabled)) print '<td class="right">'.$langs->trans('MulticurrencyRemainderToPay').'</td>';
569  print '<td class="right">'.$langs->trans('AmountTTC').'</td>';
570  print '<td class="right">'.$langs->trans('AlreadyPaid').'</td>';
571  print '<td class="right">'.$langs->trans('RemainderToPay').'</td>';
572  print '<td class="center">'.$langs->trans('PaymentAmount').'</td>';
573  if (!empty($conf->multicurrency->enabled)) print '<td class="center">'.$langs->trans('MulticurrencyPaymentAmount').'</td>';
574  print '</tr>';
575 
576  $total = 0;
577  $total_ttc = 0;
578  $totalrecu = 0;
579  while ($i < $num)
580  {
581  $objp = $db->fetch_object($resql);
582 
583  $sign = 1;
584  if ($objp->type == FactureFournisseur::TYPE_CREDIT_NOTE) $sign = -1;
585 
586  $invoice = new FactureFournisseur($db);
587  $invoice->fetch($objp->facid);
588 
589  $invoicesupplierstatic->ref = $objp->ref;
590  $invoicesupplierstatic->id = $objp->facid;
591 
592  $paiement = $invoice->getSommePaiement();
593  $creditnotes = $invoice->getSumCreditNotesUsed();
594  $deposits = $invoice->getSumDepositsUsed();
595  $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
596  $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
597 
598  // Multicurrency Price
599  if (!empty($conf->multicurrency->enabled))
600  {
601  $multicurrency_payment = $invoice->getSommePaiement(1);
602  $multicurrency_creditnotes = $invoice->getSumCreditNotesUsed(1);
603  $multicurrency_deposits = $invoice->getSumDepositsUsed(1);
604  $multicurrency_alreadypayed = price2num($multicurrency_payment + $multicurrency_creditnotes + $multicurrency_deposits, 'MT');
605  $multicurrency_remaintopay = price2num($invoice->multicurrency_total_ttc - $multicurrency_payment - $multicurrency_creditnotes - $multicurrency_deposits, 'MT');
606  }
607 
608  print '<tr class="oddeven'.(($invoice->id == $facid) ? ' highlight' : '').'">';
609 
610  // Ref
611  print '<td class="nowraponall">';
612  print $invoicesupplierstatic->getNomUrl(1);
613  print '</td>';
614 
615  // Ref supplier
616  print '<td>'.$objp->ref_supplier.'</td>';
617 
618  // Date
619  if ($objp->df > 0)
620  {
621  print '<td class="center nowraponall">';
622  print dol_print_date($db->jdate($objp->df), 'day').'</td>';
623  } else {
624  print '<td class="center"><b>!!!</b></td>';
625  }
626 
627  // Date Max Payment
628  if ($objp->dlr > 0)
629  {
630  print '<td class="center nowraponall">';
631  print dol_print_date($db->jdate($objp->dlr), 'day');
632 
633  if ($invoice->hasDelay())
634  {
635  print img_warning($langs->trans('Late'));
636  }
637 
638  print '</td>';
639  } else {
640  print '<td class="center"><b>--</b></td>';
641  }
642 
643  // Multicurrency
644  if (!empty($conf->multicurrency->enabled))
645  {
646  // Currency
647  print '<td class="center">'.$objp->multicurrency_code."</td>\n";
648 
649  print '<td class="right">';
650  if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
651  {
652  print price($objp->multicurrency_total_ttc);
653  }
654  print '</td>';
655 
656  print '<td class="right">';
657  if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
658  {
659  print price($objp->multicurrency_am);
660  }
661  print '</td>';
662 
663  print '<td class="right">';
664  if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
665  {
666  print price($objp->multicurrency_total_ttc - $objp->multicurrency_am);
667  }
668  print '</td>';
669  }
670 
671  print '<td class="right">'.price($sign * $objp->total_ttc).'</td>';
672 
673  print '<td class="right">'.price($sign * $objp->am);
674  if ($creditnotes) print '+'.price($creditnotes);
675  if ($deposits) print '+'.price($deposits);
676  print '</td>';
677 
678  print '<td class="right">'.price($sign * $remaintopay).'</td>';
679 
680  // Amount
681  print '<td class="center nowraponall">';
682 
683  $namef = 'amount_'.$objp->facid;
684  $nameRemain = 'remain_'.$objp->facid;
685 
686  if ($action != 'add_paiement')
687  {
688  if (!empty($conf->use_javascript_ajax))
689  print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $remaintopay)."'");
690  print '<input type="hidden" class="remain" name="'.$nameRemain.'" value="'.$remaintopay.'">';
691  print '<input type="text" size="8" class="amount" name="'.$namef.'" value="'.dol_escape_htmltag(GETPOST($namef)).'">';
692  } else {
693  print '<input type="text" size="8" name="'.$namef.'_disabled" value="'.dol_escape_htmltag(GETPOST($namef)).'" disabled>';
694  print '<input type="hidden" name="'.$namef.'" value="'.dol_escape_htmltag(GETPOST($namef)).'">';
695  }
696  print "</td>";
697 
698  // Multicurrency Price
699  if (!empty($conf->multicurrency->enabled))
700  {
701  print '<td class="right">';
702 
703  // Add remind multicurrency amount
704  $namef = 'multicurrency_amount_'.$objp->facid;
705  $nameRemain = 'multicurrency_remain_'.$objp->facid;
706 
707  if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
708  {
709  if ($action != 'add_paiement')
710  {
711  if (!empty($conf->use_javascript_ajax))
712  print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $multicurrency_remaintopay)."'");
713  print '<input type=hidden class="multicurrency_remain" name="'.$nameRemain.'" value="'.$multicurrency_remaintopay.'">';
714  print '<input type="text" size="8" class="multicurrency_amount" name="'.$namef.'" value="'.$_POST[$namef].'">';
715  } else {
716  print '<input type="text" size="8" name="'.$namef.'_disabled" value="'.$_POST[$namef].'" disabled>';
717  print '<input type="hidden" name="'.$namef.'" value="'.$_POST[$namef].'">';
718  }
719  }
720  print "</td>";
721  }
722 
723  print "</tr>\n";
724  $total += $objp->total_ht;
725  $total_ttc += $objp->total_ttc;
726  $totalrecu += $objp->am;
727  $totalrecucreditnote += $creditnotes;
728  $totalrecudeposits += $deposits;
729  $i++;
730  }
731  if ($i > 1)
732  {
733  // Print total
734  print '<tr class="liste_total">';
735  print '<td colspan="4" class="left">'.$langs->trans('TotalTTC').':</td>';
736  if (!empty($conf->multicurrency->enabled)) print '<td>&nbsp;</td>';
737  if (!empty($conf->multicurrency->enabled)) print '<td>&nbsp;</td>';
738  if (!empty($conf->multicurrency->enabled)) print '<td>&nbsp;</td>';
739  if (!empty($conf->multicurrency->enabled)) print '<td>&nbsp;</td>';
740  print '<td class="right"><b>'.price($sign * $total_ttc).'</b></td>';
741  print '<td class="right"><b>'.price($sign * $totalrecu);
742  if ($totalrecucreditnote) print '+'.price($totalrecucreditnote);
743  if ($totalrecudeposits) print '+'.price($totalrecudeposits);
744  print '</b></td>';
745  print '<td class="right"><b>'.price($sign * price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits, 'MT')).'</b></td>';
746  print '<td class="center" id="result" style="font-weight: bold;"></td>'; // Autofilled
747  if (!empty($conf->multicurrency->enabled)) print '<td class="right" id="multicurrency_result" style="font-weight: bold;"></td>';
748  print "</tr>\n";
749  }
750  print "</table>\n";
751 
752  print "</div>";
753  }
754  $db->free($resql);
755  } else {
756  dol_print_error($db);
757  }
758  }
759 
760  // Save Button
761  if ($action != 'add_paiement')
762  {
763  print '<br><div class="center"><input type="checkbox" checked name="closepaidinvoices"> '.$langs->trans("ClosePaidInvoicesAutomatically");
764  print '<br><input type="submit" class="button" value="'.$langs->trans('ToMakePayment').'"></div>';
765  }
766 
767  // Form to confirm payment
768  if ($action == 'add_paiement')
769  {
770  $preselectedchoice = $addwarning ? 'no' : 'yes';
771 
772  print '<br>';
773  if (!empty($totalpayment)) $text = $langs->trans('ConfirmSupplierPayment', price($totalpayment), $langs->trans("Currency".$conf->currency));
774  if (!empty($multicurrency_totalpayment))
775  {
776  $text .= '<br>'.$langs->trans('ConfirmSupplierPayment', price($multicurrency_totalpayment), $langs->trans("paymentInInvoiceCurrency"));
777  }
778  if (GETPOST('closepaidinvoices'))
779  {
780  $text .= '<br>'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed");
781  print '<input type="hidden" name="closepaidinvoices" value="'.GETPOST('closepaidinvoices').'">';
782  }
783  print $form->formconfirm($_SERVER['PHP_SELF'].'?facid='.$facture->id.'&socid='.$facture->socid.'&type='.$facture->type, $langs->trans('PayedSuppliersPayments'), $text, 'confirm_paiement', $formquestion, $preselectedchoice);
784  }
785 
786  print '</form>';
787  }
788  } else dol_print_error($db);
789 }
790 
791 // End of page
792 llxFooter();
793 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Class to manage suppliers invoices.
img_warning($titlealt= 'default', $moreatt= '', $morecss= 'pictowarning')
Show warning logo.
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
Class to manage third parties objects (customers, suppliers, prospects...)
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
Classe permettant la generation de composants html autre Only common components are here...
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
const TYPE_CREDIT_NOTE
Credit note invoice.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Class to manage payments for supplier invoices.
llxFooter()
Empty footer.
Definition: wrapper.php:59
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...