dolibarr  7.0.0-beta
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-2016 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@capnetworks.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@zendsi.com>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <http://www.gnu.org/licenses/>.
25  */
26 
33 require '../../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
39 
40 $langs->load('companies');
41 $langs->load('bills');
42 $langs->load('banks');
43 $langs->load('compta');
44 
45 // Security check
46 $action = GETPOST('action','alpha');
47 $confirm = GETPOST('confirm');
48 $facid = GETPOST('facid','int');
49 $socid = GETPOST('socid','int');
50 $accountid = GETPOST('accountid');
51 $day = GETPOST('day','int');
52 $month = GETPOST('month','int');
53 $year = GETPOST('year','int');
54 
55 $search_ref=GETPOST("search_ref","int");
56 $search_account=GETPOST("search_account","int");
57 $search_paymenttype=GETPOST("search_paymenttype");
58 $search_amount=GETPOST("search_amount",'alpha'); // alpha because we must be able to search on "< x"
59 $search_company=GETPOST("search_company",'alpha');
60 $search_payment_num=GETPOST('search_payment_num','alpha');
61 
62 $sortfield = GETPOST("sortfield",'alpha');
63 $sortorder = GETPOST("sortorder",'alpha');
64 $page = GETPOST("page",'int');
65 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
66 $offset = $conf->liste_limit * $page;
67 $pageprev = $page - 1;
68 $pagenext = $page + 1;
69 $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
70 if (! $sortorder) $sortorder="DESC";
71 if (! $sortfield) $sortfield="p.rowid";
72 $optioncss = GETPOST('optioncss','alpha');
73 
74 $amounts = array();array();
75 $amountsresttopay=array();
76 $addwarning=0;
77 
78 $multicurrency_amounts=array();
79 $multicurrency_amountsresttopay=array();
80 
81 // Security check
82 if ($user->societe_id > 0)
83 {
84  $socid = $user->societe_id;
85 }
86 
87 
88 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
89 $hookmanager->initHooks(array('paymentsupplier'));
90 $extrafields = new ExtraFields($db);
91 
92 // fetch optionals attributes and labels
93 $extralabels = $extrafields->fetch_name_optionals_label('paymentsupplier');
94 $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
95 
96 $arrayfields=array();
97 
98 
99 
100 /*
101  * Actions
102  */
103 
104 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
105 {
106  $search_ref="";
107  $search_account="";
108  $search_amount="";
109  $search_paymenttype="";
110  $search_payment_num="";
111  $search_company="";
112  $day='';
113  $year='';
114  $month='';
115  $search_array_options=array();
116 }
117 
118 $parameters=array('socid'=>$socid);
119 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
120 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
121 
122 if (empty($reshook))
123 {
124  if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='yes'))
125  {
126  $error = 0;
127 
128  $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
129  $paiement_id = 0;
130  $totalpayment = 0;
131  $atleastonepaymentnotnull = 0;
132 
133  // Generate payment array and check if there is payment higher than invoice and payment date before invoice date
134  $tmpinvoice=new FactureFournisseur($db);
135  foreach ($_POST as $key => $value)
136  {
137  if (substr($key,0,7) == 'amount_')
138  {
139  $cursorfacid = substr($key,7);
140  $amounts[$cursorfacid] = price2num(trim(GETPOST($key)));
141  $totalpayment = $totalpayment + $amounts[$cursorfacid];
142  if (! empty($amounts[$cursorfacid])) $atleastonepaymentnotnull++;
143  $result=$tmpinvoice->fetch($cursorfacid);
144  if ($result <= 0) dol_print_error($db);
145  $amountsresttopay[$cursorfacid]=price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement());
146  if ($amounts[$cursorfacid])
147  {
148  // Check amount
149  if ($amounts[$cursorfacid] && (abs($amounts[$cursorfacid]) > abs($amountsresttopay[$cursorfacid])))
150  {
151  $addwarning=1;
152  $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPaySupplier")).' '.$langs->trans("HelpPaymentHigherThanReminderToPaySupplier");
153  }
154  // Check date
155  if ($datepaye && ($datepaye < $tmpinvoice->date))
156  {
157  $langs->load("errors");
158  //$error++;
159  setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye,'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings');
160  }
161  }
162 
163  $formquestion[$i++]=array('type' => 'hidden','name' => $key, 'value' => $_POST[$key]);
164  }
165  elseif (substr($key,0,21) == 'multicurrency_amount_')
166  {
167  $cursorfacid = substr($key,21);
168  $multicurrency_amounts[$cursorfacid] = price2num(trim(GETPOST($key)));
169  $multicurrency_totalpayment += $multicurrency_amounts[$cursorfacid];
170  if (! empty($multicurrency_amounts[$cursorfacid])) $atleastonepaymentnotnull++;
171  $result=$tmpinvoice->fetch($cursorfacid);
172  if ($result <= 0) dol_print_error($db);
173  $multicurrency_amountsresttopay[$cursorfacid]=price2num($tmpinvoice->total_ttc - $tmpinvoice->getSommePaiement(1));
174  if ($multicurrency_amounts[$cursorfacid])
175  {
176  // Check amount
177  if ($multicurrency_amounts[$cursorfacid] && (abs($multicurrency_amounts[$cursorfacid]) > abs($multicurrency_amountsresttopay[$cursorfacid])))
178  {
179  $addwarning=1;
180  $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPaySupplier")).' '.$langs->trans("HelpPaymentHigherThanReminderToPaySupplier");
181  }
182  // Check date
183  if ($datepaye && ($datepaye < $tmpinvoice->date))
184  {
185  $langs->load("errors");
186  //$error++;
187  setEventMessages($langs->transnoentities("WarningPaymentDateLowerThanInvoiceDate", dol_print_date($datepaye,'day'), dol_print_date($tmpinvoice->date, 'day'), $tmpinvoice->ref), null, 'warnings');
188  }
189  }
190 
191  $formquestion[$i++]=array('type' => 'hidden','name' => $key, 'value' => GETPOST($key, 'int'));
192  }
193  }
194 
195  // Check parameters
196  if ($_POST['paiementid'] <= 0)
197  {
198  setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('PaymentMode')), null, 'errors');
199  $error++;
200  }
201 
202  if (! empty($conf->banque->enabled))
203  {
204  // If bank module is on, account is required to enter a payment
205  if (GETPOST('accountid') <= 0)
206  {
207  setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')), null, 'errors');
208  $error++;
209  }
210  }
211 
212  if (empty($totalpayment) && empty($multicurrency_totalpayment) && empty($atleastonepaymentnotnull))
213  {
214  setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')), null, 'errors');
215  $error++;
216  }
217 
218  if (empty($datepaye))
219  {
220  setEventMessages($langs->transnoentities('ErrorFieldRequired',$langs->transnoentities('Date')), null, 'errors');
221  $error++;
222  }
223 
224  // Check if payments in both currency
225  if ($totalpayment > 0 && $multicurrency_totalpayment > 0)
226  {
227  setEventMessages($langs->transnoentities('ErrorPaymentInBothCurrency'), null, 'errors');
228  $error++;
229  }
230  }
231 
232  /*
233  * Action add_paiement
234  */
235  if ($action == 'add_paiement')
236  {
237  if ($error)
238  {
239  $action = 'create';
240  }
241  // Le reste propre a cette action s'affiche en bas de page.
242  }
243 
244 
245  /*
246  * Action confirm_paiement
247  */
248  if ($action == 'confirm_paiement' && $confirm == 'yes')
249  {
250  $error=0;
251 
252  $datepaye = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
253 
254  if (! $error)
255  {
256  $db->begin();
257 
258  // Creation de la ligne paiement
259  $paiement = new PaiementFourn($db);
260  $paiement->datepaye = $datepaye;
261  $paiement->amounts = $amounts; // Array of amounts
262  $paiement->multicurrency_amounts = $multicurrency_amounts;
263  $paiement->paiementid = $_POST['paiementid'];
264  $paiement->num_paiement = $_POST['num_paiement'];
265  $paiement->note = $_POST['comment'];
266  if (! $error)
267  {
268  $paiement_id = $paiement->create($user,(GETPOST('closepaidinvoices')=='on'?1:0));
269  if ($paiement_id < 0)
270  {
271  setEventMessages($paiement->error, $paiement->errors, 'errors');
272  $error++;
273  }
274  }
275 
276  if (! $error)
277  {
278  $result=$paiement->addPaymentToBank($user,'payment_supplier','(SupplierInvoicePayment)',$accountid,'','');
279  if ($result < 0)
280  {
281  setEventMessages($paiement->error, $paiement->errors, 'errors');
282  $error++;
283  }
284  }
285 
286  if (! $error)
287  {
288  $db->commit();
289 
290  // If payment dispatching on more than one invoice, we keep on summary page, otherwise go on invoice card
291  $invoiceid=0;
292  foreach ($paiement->amounts as $key => $amount)
293  {
294  $facid = $key;
295  if (is_numeric($amount) && $amount <> 0)
296  {
297  if ($invoiceid != 0) $invoiceid=-1; // There is more than one invoice payed by this payment
298  else $invoiceid=$facid;
299  }
300  }
301  if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$invoiceid;
302  else $loc = DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$paiement_id;
303  header('Location: '.$loc);
304  exit;
305  }
306  else
307  {
308  $db->rollback();
309  }
310  }
311  }
312 }
313 
314 
315 /*
316  * View
317  */
318 
319 $supplierstatic=new Societe($db);
320 $invoicesupplierstatic = new FactureFournisseur($db);
321 
322 llxHeader('',$langs->trans('ListPayment'));
323 
324 $form=new Form($db);
325 $formother=new FormOther($db);
326 
327 if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paiement')
328 {
329  $object = new FactureFournisseur($db);
330  $result = $object->fetch($facid);
331 
332  $datefacture=dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
333  $dateinvoice=($datefacture==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:''):$datefacture);
334 
335  $sql = 'SELECT s.nom as name, s.rowid as socid,';
336  $sql.= ' f.rowid, f.ref, f.ref_supplier, f.amount, f.total_ttc as total, f.fk_mode_reglement, f.fk_account';
337  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
338  $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'facture_fourn as f';
339  if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
340  $sql.= ' WHERE f.fk_soc = s.rowid';
341  $sql.= ' AND f.rowid = '.$facid;
342  if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
343  $resql = $db->query($sql);
344  if ($resql)
345  {
346  $num = $db->num_rows($resql);
347  if ($num)
348  {
349  $obj = $db->fetch_object($resql);
350  $total = $obj->total;
351 
352  print load_fiche_titre($langs->trans('DoPayment'));
353 
354  // Add realtime total information
355  if (! empty($conf->use_javascript_ajax))
356  {
357  print "\n".'<script type="text/javascript" language="javascript">';
358  print '$(document).ready(function () {
359 
360  function _elemToJson(selector)
361  {
362  var subJson = {};
363  $.map(selector.serializeArray(), function(n,i)
364  {
365  subJson[n["name"]] = n["value"];
366  });
367 
368  return subJson;
369  }
370  function callForResult(imgId)
371  {
372  var json = {};
373  var form = $("#payment_form");
374 
375  json["invoice_type"] = $("#invoice_type").val();
376  json["amountPayment"] = $("#amountpayment").attr("value");
377  json["amounts"] = _elemToJson(form.find("input.amount"));
378  json["remains"] = _elemToJson(form.find("input.remain"));
379 
380  if (imgId != null) {
381  json["imgClicked"] = imgId;
382  }
383 
384  $.post("'.DOL_URL_ROOT.'/compta/ajaxpayment.php", json, function(data)
385  {
386  json = $.parseJSON(data);
387 
388  form.data(json);
389 
390  for (var key in json)
391  {
392  if (key == "result") {
393  if (json["makeRed"]) {
394  $("#"+key).addClass("error");
395  } else {
396  $("#"+key).removeClass("error");
397  }
398  json[key]=json["label"]+" "+json[key];
399  $("#"+key).text(json[key]);
400  } else {console.log(key);
401  form.find("input[name*=\""+key+"\"]").each(function() {
402  $(this).attr("value", json[key]);
403  });
404  }
405  }
406  });
407  }
408  $("#payment_form").find("input.amount").change(function() {
409  callForResult();
410  });
411  $("#payment_form").find("input.amount").keyup(function() {
412  callForResult();
413  });
414  ';
415 
416  print ' });'."\n";
417 
418  //Add js for AutoFill
419  print ' $(document).ready(function () {';
420  print ' $(".AutoFillAmout").on(\'click touchstart\', function(){
421  $("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value")).trigger("change");
422  });';
423  print ' });'."\n";
424 
425  print ' </script>'."\n";
426  }
427 
428  print '<form id="payment_form" name="addpaiement" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
429  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
430  print '<input type="hidden" name="action" value="add_paiement">';
431  print '<input type="hidden" name="facid" value="'.$facid.'">';
432  print '<input type="hidden" name="ref_supplier" value="'.$obj->ref_supplier.'">';
433  print '<input type="hidden" name="socid" value="'.$obj->socid.'">';
434  print '<input type="hidden" name="societe" value="'.$obj->name.'">';
435 
436  dol_fiche_head(null);
437 
438  print '<table class="border" width="100%">';
439 
440  print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans('Company').'</td><td>';
441  $supplierstatic->id=$obj->socid;
442  $supplierstatic->name=$obj->name;
443  print $supplierstatic->getNomUrl(1,'supplier');
444  print '</td></tr>';
445  print '<tr><td class="fieldrequired">'.$langs->trans('Date').'</td><td>';
446  $form->select_date($dateinvoice,'','','','',"addpaiement",1,1,0,0,'','',$object->date);
447  print '</td></tr>';
448  print '<tr><td class="fieldrequired">'.$langs->trans('PaymentMode').'</td><td>';
449  $form->select_types_paiements(empty($_POST['paiementid'])?$obj->fk_mode_reglement:$_POST['paiementid'],'paiementid');
450  print '</td>';
451  if (! empty($conf->banque->enabled))
452  {
453  print '<tr><td class="fieldrequired">'.$langs->trans('Account').'</td><td>';
454  $form->select_comptes(empty($accountid)?$obj->fk_account:$accountid,'accountid',0,'',2);
455  print '</td></tr>';
456  }
457  else
458  {
459  print '<tr><td>&nbsp;</td></tr>';
460  }
461  print '<tr><td>'.$langs->trans('Numero').'</td><td><input name="num_paiement" type="text" value="'.(empty($_POST['num_paiement'])?'':$_POST['num_paiement']).'"></td></tr>';
462  print '<tr><td>'.$langs->trans('Comments').'</td>';
463  print '<td class="tdtop">';
464  print '<textarea name="comment" wrap="soft" class="quatrevingtpercent" rows="'.ROWS_3.'">'.(empty($_POST['comment'])?'':$_POST['comment']).'</textarea></td></tr>';
465  print '</table>';
466  dol_fiche_end();
467 
468 
469  $parameters=array('facid'=>$facid, 'ref'=>$ref, 'objcanvas'=>$objcanvas);
470  $reshook=$hookmanager->executeHooks('paymentsupplierinvoices',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
471  $error=$hookmanager->error; $errors=$hookmanager->errors;
472  if (empty($reshook))
473  {
474  /*
475  * Autres factures impayees
476  */
477  $sql = 'SELECT f.rowid as facid, f.ref, f.ref_supplier, f.total_ht, f.total_ttc, f.multicurrency_total_ttc, f.datef as df,';
478  $sql.= ' SUM(pf.amount) as am, SUM(pf.multicurrency_amount) as multicurrency_am';
479  $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f';
480  $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
481  $sql.= " WHERE f.entity = ".$conf->entity;
482  $sql.= ' AND f.fk_soc = '.$object->socid;
483  $sql.= ' AND f.paye = 0';
484  $sql.= ' AND f.fk_statut = 1'; // Statut=0 => non validee, Statut=2 => annulee
485  $sql.= ' GROUP BY f.rowid, f.ref, f.ref_supplier, f.total_ht, f.total_ttc, f.multicurrency_total_ttc, f.datef';
486  $resql = $db->query($sql);
487  if ($resql)
488  {
489  $num = $db->num_rows($resql);
490  if ($num > 0)
491  {
492  $sign=1;
493  if ($object->type == 2) $sign=-1;
494 
495  $i = 0;
496  print '<br>';
497 
498  if (!empty($conf->use_javascript_ajax)){
499  //Add js for AutoFill
500  print "\n".'<script type="text/javascript" language="javascript">';
501  print ' $(document).ready(function () {';
502  print ' $(".AutoFillAmout").on(\'click touchstart\', function(){
503  $("input[name="+$(this).data(\'rowname\')+"]").val($(this).data("value"));
504  });';
505  print ' });'."\n";
506  print ' </script>'."\n";
507  }
508 
509  print '<div class="div-table-responsive-no-min">';
510  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
511 
512  print '<tr class="liste_titre">';
513  print '<td>'.$langs->trans('Invoice').'</td>';
514  print '<td>'.$langs->trans('RefSupplier').'</td>';
515  print '<td align="center">'.$langs->trans('Date').'</td>';
516  if (!empty($conf->multicurrency->enabled)) print '<td>'.$langs->trans('Currency').'</td>';
517  if (!empty($conf->multicurrency->enabled)) print '<td align="right">'.$langs->trans('MulticurrencyAmountTTC').'</td>';
518  if (!empty($conf->multicurrency->enabled)) print '<td align="right">'.$langs->trans('MulticurrencyAlreadyPaid').'</td>';
519  if (!empty($conf->multicurrency->enabled)) print '<td align="right">'.$langs->trans('MulticurrencyRemainderToPay').'</td>';
520  print '<td align="right">'.$langs->trans('AmountTTC').'</td>';
521  print '<td align="right">'.$langs->trans('AlreadyPaid').'</td>';
522  print '<td align="right">'.$langs->trans('RemainderToPay').'</td>';
523  print '<td align="center">'.$langs->trans('PaymentAmount').'</td>';
524  if (!empty($conf->multicurrency->enabled)) print '<td align="center">'.$langs->trans('MulticurrencyPaymentAmount').'</td>';
525  print '</tr>';
526 
527  $var=True;
528  $total=0;
529  $total_ttc=0;
530  $totalrecu=0;
531  while ($i < $num)
532  {
533  $objp = $db->fetch_object($resql);
534 
535  $invoice=new FactureFournisseur($db);
536  $invoice->fetch($objp->facid);
537  $paiement = $invoice->getSommePaiement();
538  $creditnotes=$invoice->getSumCreditNotesUsed();
539  $deposits=$invoice->getSumDepositsUsed();
540  $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
541  $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
542 
543  // Multicurrency Price
544  if (!empty($conf->multicurrency->enabled))
545  {
546  $multicurrency_payment = $invoice->getSommePaiement(1);
547  $multicurrency_creditnotes=$invoice->getSumCreditNotesUsed(1);
548  $multicurrency_deposits=$invoice->getSumDepositsUsed(1);
549  $multicurrency_alreadypayed=price2num($multicurrency_payment + $multicurrency_creditnotes + $multicurrency_deposits,'MT');
550  $multicurrency_remaintopay=price2num($invoice->multicurrency_total_ttc - $multicurrency_payment - $multicurrency_creditnotes - $multicurrency_deposits,'MT');
551  }
552 
553  print '<tr class="oddeven">';
554 
555  // Ref
556  print '<td>';
557  $invoicesupplierstatic->ref=$objp->ref;
558  $invoicesupplierstatic->id=$objp->facid;
559  print $invoicesupplierstatic->getNomUrl(1);
560  print '</td>';
561 
562  // Ref supplier
563  print '<td>'.$objp->ref_supplier.'</td>';
564 
565  // Date
566  if ($objp->df > 0 )
567  {
568  print '<td align="center">';
569  print dol_print_date($db->jdate($objp->df), 'day').'</td>';
570  }
571  else
572  {
573  print '<td align="center"><b>!!!</b></td>';
574  }
575 
576  // Multicurrency
577  if (!empty($conf->multicurrency->enabled))
578  {
579  // Currency
580  print '<td align="center">'.$objp->multicurrency_code."</td>\n";
581 
582  print '<td align="right">';
583  if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
584  {
585  print price($objp->multicurrency_total_ttc);
586  }
587  print '</td>';
588 
589  print '<td align="right">';
590  if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
591  {
592  print price($objp->multicurrency_am);
593  }
594  print '</td>';
595 
596  print '<td align="right">';
597  if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
598  {
599  print price($objp->multicurrency_total_ttc - $objp->multicurrency_am);
600  }
601  print '</td>';
602  }
603 
604  print '<td align="right">'.price($objp->total_ttc).'</td>';
605 
606  print '<td align="right">'.price($objp->am).'</td>';
607 
608  print '<td align="right">'.price($remaintopay).'</td>';
609 
610  // Amount
611  print '<td align="center">';
612 
613  $namef = 'amount_'.$objp->facid;
614  $nameRemain = 'remain_'.$objp->facid;
615 
616  if ($action != 'add_paiement')
617  {
618  if (!empty($conf->use_javascript_ajax))
619  print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $remaintopay)."'");
620  print '<input type="hidden" class="remain" name="'.$nameRemain.'" value="'.$remaintopay.'">';
621  print '<input type="text" size="8" class="amount" name="'.$namef.'" value="'.dol_escape_htmltag(GETPOST($namef)).'">';
622  }
623  else
624  {
625  print '<input type="text" size="8" name="'.$namef.'_disabled" value="'.dol_escape_htmltag(GETPOST($namef)).'" disabled>';
626  print '<input type="hidden" name="'.$namef.'" value="'.dol_escape_htmltag(GETPOST($namef)).'">';
627  }
628  print "</td>";
629 
630  // Multicurrency Price
631  if (! empty($conf->multicurrency->enabled))
632  {
633  print '<td align="right">';
634 
635  // Add remind multicurrency amount
636  $namef = 'multicurrency_amount_'.$objp->facid;
637  $nameRemain = 'multicurrency_remain_'.$objp->facid;
638 
639  if ($objp->multicurrency_code && $objp->multicurrency_code != $conf->currency)
640  {
641  if ($action != 'add_paiement')
642  {
643  if (!empty($conf->use_javascript_ajax))
644  print img_picto("Auto fill",'rightarrow', "class='AutoFillAmout' data-rowname='".$namef."' data-value='".($sign * $multicurrency_remaintopay)."'");
645  print '<input type=hidden class="multicurrency_remain" name="'.$nameRemain.'" value="'.$multicurrency_remaintopay.'">';
646  print '<input type="text" size="8" class="multicurrency_amount" name="'.$namef.'" value="'.$_POST[$namef].'">';
647  }
648  else
649  {
650  print '<input type="text" size="8" name="'.$namef.'_disabled" value="'.$_POST[$namef].'" disabled>';
651  print '<input type="hidden" name="'.$namef.'" value="'.$_POST[$namef].'">';
652  }
653  }
654  print "</td>";
655  }
656 
657  print "</tr>\n";
658  $total+=$objp->total_ht;
659  $total_ttc+=$objp->total_ttc;
660  $totalrecu+=$objp->am;
661  $i++;
662  }
663  if ($i > 1)
664  {
665  // Print total
666  print '<tr class="liste_total">';
667  print '<td colspan="3" align="left">'.$langs->trans('TotalTTC').':</td>';
668  if (!empty($conf->multicurrency->enabled)) print '<td>&nbsp;</td>';
669  if (!empty($conf->multicurrency->enabled)) print '<td>&nbsp;</td>';
670  if (!empty($conf->multicurrency->enabled)) print '<td>&nbsp;</td>';
671  if (!empty($conf->multicurrency->enabled)) print '<td>&nbsp;</td>';
672  print '<td align="right"><b>'.price($total_ttc).'</b></td>';
673  print '<td align="right"><b>'.price($totalrecu).'</b></td>';
674  print '<td align="right"><b>'.price($total_ttc - $totalrecu).'</b></td>';
675  print '<td align="center" id="result" style="font-weight: bold;"></td>'; // Autofilled
676  if (!empty($conf->multicurrency->enabled)) print '<td align="right" id="multicurrency_result" style="font-weight: bold;"></td>';
677  print "</tr>\n";
678  }
679  print "</table>\n";
680 
681  print "</div>";
682  }
683  $db->free($resql);
684  }
685  else
686  {
687  dol_print_error($db);
688  }
689  }
690 
691  // Bouton Enregistrer
692  if ($action != 'add_paiement')
693  {
694  print '<br><div class="center"><input type="checkbox" checked name="closepaidinvoices"> '.$langs->trans("ClosePaidInvoicesAutomatically");
695  print '<br><input type="submit" class="button" value="'.$langs->trans('ToMakePayment').'"></div>';
696  }
697 
698  // Form to confirm payment
699  if ($action == 'add_paiement')
700  {
701  $preselectedchoice=$addwarning?'no':'yes';
702 
703  print '<br>';
704  if (!empty($totalpayment)) $text=$langs->trans('ConfirmSupplierPayment',price($totalpayment),$langs->trans("Currency".$conf->currency));
705  if (!empty($multicurrency_totalpayment))
706  {
707  $text.='<br>'.$langs->trans('ConfirmSupplierPayment',price($multicurrency_totalpayment),$langs->trans("paymentInInvoiceCurrency"));
708  }
709  if (GETPOST('closepaidinvoices'))
710  {
711  $text.='<br>'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed");
712  print '<input type="hidden" name="closepaidinvoices" value="'.GETPOST('closepaidinvoices').'">';
713  }
714  print $form->formconfirm($_SERVER['PHP_SELF'].'?facid='.$facture->id.'&socid='.$facture->socid.'&type='.$facture->type,$langs->trans('PayedSuppliersPayments'),$text,'confirm_paiement',$formquestion,$preselectedchoice);
715  }
716 
717  print '</form>';
718  }
719  }
720  else dol_print_error($db);
721 }
722 
723 /*
724  * Show list
725  */
726 if (empty($action))
727 {
728  $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
729  $sortfield = GETPOST("sortfield",'alpha');
730  $sortorder = GETPOST("sortorder",'alpha');
731  $page=GETPOST("page",'int');
732  if ($page == -1 || $page == null) { $page = 0 ; }
733  $offset = $limit * $page ;
734  $pageprev = $page - 1;
735  $pagenext = $page + 1;
736  if (! $sortorder) $sortorder='DESC';
737  if (! $sortfield) $sortfield='p.datep';
738 
739  $sql = 'SELECT p.rowid as pid, p.datep as dp, p.amount as pamount, p.num_paiement,';
740  $sql.= ' s.rowid as socid, s.nom as name,';
741  $sql.= ' c.code as paiement_type, c.libelle as paiement_libelle,';
742  $sql.= ' ba.rowid as bid, ba.label,';
743  if (!$user->rights->societe->client->voir) $sql .= ' sc.fk_soc, sc.fk_user,';
744  $sql.= ' SUM(f.amount)';
745  $sql.= ' FROM '.MAIN_DB_PREFIX.'paiementfourn AS p';
746  $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn AS pf ON p.rowid=pf.fk_paiementfourn';
747  $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn AS f ON f.rowid=pf.fk_facturefourn';
748  $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement AS c ON p.fk_paiement = c.id AND c.entity IN ('.getEntity('c_paiement').')';
749  $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON s.rowid = f.fk_soc';
750  $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
751  $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
752  if (!$user->rights->societe->client->voir) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
753  $sql.= " WHERE f.entity = ".$conf->entity;
754  if (!$user->rights->societe->client->voir) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
755  if ($socid > 0) $sql .= ' AND f.fk_soc = '.$socid;
756  // Search criteria
757  if ($month > 0)
758  {
759  if ($year > 0 && empty($day))
760  $sql.= " AND p.datep BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
761  else if ($year > 0 && ! empty($day))
762  $sql.= " AND p.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
763  else
764  $sql.= " AND date_format(p.datep, '%m') = '".$month."'";
765  }
766  else if ($year > 0)
767  {
768  $sql.= " AND p.datep BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
769  }
770  if ($search_ref) $sql .= natural_search('p.rowid', $search_ref);
771  if ($search_account > 0) $sql .=" AND b.fk_account=".$search_account;
772  if ($search_paymenttype != "") $sql .=" AND c.code='".$db->escape($search_paymenttype)."'";
773  if ($search_payment_num != '') $sql .= natural_search('p.num_paiement', $search_payment_num);
774  if ($search_amount) $sql .= natural_search('p.amount', $search_amount, 1);
775  if ($search_company) $sql .= natural_search('s.nom', $search_company);
776  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
777  $sql.= " GROUP BY p.rowid, p.datep, p.amount, p.num_paiement, s.rowid, s.nom, c.code, c.libelle, ba.rowid, ba.label";
778  if (!$user->rights->societe->client->voir) $sql .= ", sc.fk_soc, sc.fk_user";
779  // Add where from extra fields
780 
781  $sql.= $db->order($sortfield,$sortorder);
782 
783  $nbtotalofrecords = '';
784  if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
785  {
786  $result = $db->query($sql);
787  $nbtotalofrecords = $db->num_rows($result);
788  }
789 
790  $sql.= $db->plimit($limit+1, $offset);
791 
792  $resql = $db->query($sql);
793  if ($resql)
794  {
795  $num = $db->num_rows($resql);
796  $i = 0;
797  $var=True;
798 
799  $param='';
800  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
801  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
802  if ($day) $param.=($day?"&day=".urlencode($day):"");
803  if ($month) $param.=($month?"&month=".urlencode($month):"");
804  if ($year) $param.=($year?"&year=".urlencode($year):"");
805  if ($search_ref) $param.=($search_ref?"&search_ref=".urlencode($search_ref):"");
806  if ($search_company) $param.=($search_company?"&search_company=".urlencode($search_company):"");
807  if ($search_amount != '') $param.=($search_amount?"&search_amount=".urlencode($search_amount):"");
808  if ($search_payment_num) $param.=($search_payment_num?"&search_payment_num=".urlencode($search_payment_num):"");
809  if ($optioncss != '') $param.='&optioncss='.$optioncss;
810  // Add $param from extra fields
811  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
812 
813  $massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
814 
815  print_barre_liste($langs->trans('SupplierPayments'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_accountancy.png', 0, '', '', $limit);
816 
817  print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
818  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
819  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
820  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
821  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
822  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
823  print '<input type="hidden" name="page" value="'.$page.'">';
824 
825  $moreforfilter='';
826 
827  $parameters=array();
828  $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
829  if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
830  else $moreforfilter = $hookmanager->resPrint;
831 
832  if ($moreforfilter)
833  {
834  print '<div class="liste_titre liste_titre_bydiv centpercent">';
835  print $moreforfilter;
836  print '</div>';
837  }
838 
839  $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
840  $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
841 
842  print '<div class="div-table-responsive">';
843  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
844 
845  // Lines for filters fields
846  print '<tr class="liste_titre_filter">';
847  print '<td class="liste_titre" align="left">';
848  print '<input class="flat" type="text" size="4" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
849  print '</td>';
850  print '<td class="liste_titre" align="center">';
851  if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
852  print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
853  $formother->select_year($year?$year:-1,'year',1, 20, 5);
854  print '</td>';
855  print '<td class="liste_titre" align="left">';
856  print '<input class="flat" type="text" size="6" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
857  print '</td>';
858  print '<td class="liste_titre">';
859  $form->select_types_paiements($search_paymenttype,'search_paymenttype','',2,1,1);
860  print '</td>';
861  print '<td class="liste_titre" align="left">';
862  print '<input class="flat" type="text" size="4" name="search_payment_num" value="'.dol_escape_htmltag($search_payment_num).'">';
863  print '</td>';
864  print '<td class="liste_titre">';
865  $form->select_comptes($search_account,'search_account',0,'',1);
866  print '</td>';
867  print '<td class="liste_titre" align="right">';
868  print '<input class="flat" type="text" size="4" name="search_amount" value="'.dol_escape_htmltag($search_amount).'">';
869  print '</td>';
870  print '<td class="liste_titre" align="right">';
871  $searchpicto=$form->showFilterAndCheckAddButtons(0);
872  print $searchpicto;
873  print '</td>';
874  print "</tr>\n";
875 
876  print '<tr class="liste_titre">';
877  print_liste_field_titre("RefPayment",$_SERVER["PHP_SELF"],'p.rowid','',$param,'',$sortfield,$sortorder);
878  print_liste_field_titre("Date",$_SERVER["PHP_SELF"],'dp','',$param,'align="center"',$sortfield,$sortorder);
879  print_liste_field_titre("ThirdParty",$_SERVER["PHP_SELF"],'s.nom','',$param,'',$sortfield,$sortorder);
880  print_liste_field_titre("Type",$_SERVER["PHP_SELF"],'c.libelle','',$param,'',$sortfield,$sortorder);
881  print_liste_field_titre("Numero",$_SERVER["PHP_SELF"],"p.num_paiement","",$param,"",$sortfield,$sortorder);
882  print_liste_field_titre("Account",$_SERVER["PHP_SELF"],'ba.label','',$param,'',$sortfield,$sortorder);
883  print_liste_field_titre("Amount",$_SERVER["PHP_SELF"],'p.amount','',$param,'align="right"',$sortfield,$sortorder);
884  //print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],'ref_supplier','',$param,'',$sortfield,$sortorder);
886  print "</tr>\n";
887 
888  while ($i < min($num,$limit))
889  {
890  $objp = $db->fetch_object($resql);
891 
892  print '<tr class="oddeven">';
893 
894  // Ref payment
895  print '<td class="nowrap"><a href="'.DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$objp->pid.'">'.img_object($langs->trans('ShowPayment'),'payment').' '.$objp->pid.'</a></td>';
896 
897  // Date
898  print '<td class="nowrap" align="center">'.dol_print_date($db->jdate($objp->dp),'day')."</td>\n";
899 
900  // Thirdparty
901  print '<td>';
902  if ($objp->socid) print '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$objp->socid.'">'.img_object($langs->trans('ShowCompany'),'company').' '.dol_trunc($objp->name,32).'</a>';
903  else print '&nbsp;';
904  print '</td>';
905 
906  // Type
907  $payment_type = $langs->trans("PaymentType".$objp->paiement_type)!=("PaymentType".$objp->paiement_type)?$langs->trans("PaymentType".$objp->paiement_type):$objp->paiement_libelle;
908  print '<td>'.$payment_type.' '.dol_trunc($objp->num_paiement,32)."</td>\n";
909 
910  // Payment number
911  print '<td>'.$objp->num_paiement.'</td>';
912 
913  print '<td>';
914  if ($objp->bid) print '<a href="'.DOL_URL_ROOT.'/compta/bank/bankentries_list.php?account='.$objp->bid.'">'.img_object($langs->trans("ShowAccount"),'account').' '.dol_trunc($objp->label,24).'</a>';
915  else print '&nbsp;';
916  print '</td>';
917 
918  print '<td align="right">'.price($objp->pamount).'</td>';
919 
920  // Ref invoice
921  /*$invoicesupplierstatic->ref=$objp->ref_supplier;
922  $invoicesupplierstatic->id=$objp->facid;
923  print '<td class="nowrap">';
924  print $invoicesupplierstatic->getNomUrl(1);
925  print '</td>';*/
926 
927  print '<td>&nbsp;</td>';
928  print '</tr>';
929  $i++;
930  }
931  print "</table>";
932  print "</div>";
933  print "</form>\n";
934  }
935  else
936  {
937  dol_print_error($db);
938  }
939 }
940 
941 llxFooter();
942 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:445
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage suppliers invoices.
if(empty($reshook)) $form
View.
Definition: perms.php:103
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
Class to manage third parties objects (customers, suppliers, prospects...)
img_warning($titlealt= 'default', $moreatt= '')
Show warning logo.
dol_fiche_end($notab=0)
Show tab footer of a card.
Classe permettant la generation de composants html autre Only common components are here...
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
getEntity($element, $shared=1, $forceentity=null)
Get list of entity id to use.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
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...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:459
print
Draft customers invoices.
Definition: index.php:91
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->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)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
Class to manage payments for supplier invoices.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...