dolibarr  18.0.0
paiementfourn.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
7  * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
8  * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
9  * Copyright (C) 2018 Frédéric France <frederic.francenetlogic.fr>
10  * Copyright (C) 2023 Joachim Kueter <git-jk@bloxera.com>
11  * Copyright (C) 2023 Sylvain Legrand <technique@infras.fr>
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 <https://www.gnu.org/licenses/>.
25  */
26 
32 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
35 
39 class PaiementFourn extends Paiement
40 {
44  public $element = 'payment_supplier';
45 
49  public $table_element = 'paiementfourn';
50 
54  public $picto = 'payment';
55 
56  public $statut; //Status of payment. 0 = unvalidated; 1 = validated
57  // fk_paiement dans llx_paiement est l'id du type de paiement (7 pour CHQ, ...)
58  // fk_paiement dans llx_paiement_facture est le rowid du paiement
59 
64  public $type_label;
65 
70  public $type_code;
71 
75  public $id_prelevement;
76 
80  public $num_prelevement;
81 
82 
88  public function __construct($db)
89  {
90  $this->db = $db;
91  }
92 
101  public function fetch($id, $ref = '', $fk_bank = '')
102  {
103  $error = 0;
104 
105  $sql = 'SELECT p.rowid, p.ref, p.entity, p.datep as dp, p.amount, p.statut, p.fk_bank, p.multicurrency_amount,';
106  $sql .= ' c.code as payment_code, c.libelle as payment_type,';
107  $sql .= ' p.num_paiement as num_payment, p.note, b.fk_account, p.fk_paiement';
108  $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as p';
109  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id';
110  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
111  $sql .= ' WHERE p.entity IN ('.getEntity('facture_fourn').')';
112  if ($id > 0) {
113  $sql .= ' AND p.rowid = '.((int) $id);
114  } elseif ($ref) {
115  $sql .= " AND p.ref = '".$this->db->escape($ref)."'";
116  } elseif ($fk_bank > 0) {
117  $sql .= ' AND p.fk_bank = '.((int) $fk_bank);
118  }
119  //print $sql;
120 
121  $resql = $this->db->query($sql);
122  if ($resql) {
123  $num = $this->db->num_rows($resql);
124  if ($num > 0) {
125  $obj = $this->db->fetch_object($resql);
126 
127  $this->id = $obj->rowid;
128  $this->ref = $obj->ref;
129  $this->entity = $obj->entity;
130  $this->date = $this->db->jdate($obj->dp);
131  $this->datepaye = $this->db->jdate($obj->dp);
132  $this->num_payment = $obj->num_payment;
133  $this->numero = $obj->num_payment;
134  $this->bank_account = $obj->fk_account;
135  $this->fk_account = $obj->fk_account;
136  $this->bank_line = $obj->fk_bank;
137  $this->montant = $obj->amount; // deprecated
138  $this->amount = $obj->amount;
139  $this->multicurrency_amount = $obj->multicurrency_amount;
140  $this->note = $obj->note;
141  $this->note_private = $obj->note;
142  $this->type_code = $obj->payment_code;
143  $this->type_label = $obj->payment_type;
144  $this->fk_paiement = $obj->fk_paiement;
145  $this->statut = $obj->statut;
146 
147  $error = 1;
148  } else {
149  $error = -2; // TODO Use 0 instead
150  }
151  $this->db->free($resql);
152  } else {
153  dol_print_error($this->db);
154  $error = -1;
155  }
156  return $error;
157  }
158 
167  public function create($user, $closepaidinvoices = 0, $thirdparty = null)
168  {
169  global $langs, $conf;
170 
171  $error = 0;
172  $way = $this->getWay();
173 
174  $now = dol_now();
175 
176  // Clean parameters
177  $totalamount = 0;
178  $totalamount_converted = 0;
179  $atleastonepaymentnotnull = 0;
180 
181  if ($way == 'dolibarr') {
182  $amounts = &$this->amounts;
183  $amounts_to_update = &$this->multicurrency_amounts;
184  } else {
185  $amounts = &$this->multicurrency_amounts;
186  $amounts_to_update = &$this->amounts;
187  }
188 
189  $currencyofpayment = '';
190  $currencytxofpayment = '';
191 
192  foreach ($amounts as $key => $value) {
193  if (empty($value)) {
194  continue;
195  }
196  // $key is id of invoice, $value is amount, $way is a 'dolibarr' if amount is in main currency, 'customer' if in foreign currency
197  $value_converted = MultiCurrency::getAmountConversionFromInvoiceRate($key, $value ? $value : 0, $way, 'facture_fourn');
198  // Add controls of input validity
199  if ($value_converted === false) {
200  // We failed to find the conversion for one invoice
201  $this->error = 'FailedToFoundTheConversionRateForInvoice';
202  return -1;
203  }
204  if (empty($currencyofpayment)) {
205  $currencyofpayment = $this->multicurrency_code[$key];
206  }
207  if ($currencyofpayment != $this->multicurrency_code[$key]) {
208  // If we have invoices with different currencies in the payment, we stop here
209  $this->error = 'ErrorYouTryToPayInvoicesWithDifferentCurrenciesInSamePayment';
210  return -1;
211  }
212  if (empty($currencytxofpayment)) {
213  $currencytxofpayment = $this->multicurrency_tx[$key];
214  }
215 
216  $totalamount_converted += $value_converted;
217  $amounts_to_update[$key] = price2num($value_converted, 'MT');
218 
219  $newvalue = price2num($value, 'MT');
220  $amounts[$key] = $newvalue;
221  $totalamount += $newvalue;
222  if (!empty($newvalue)) {
223  $atleastonepaymentnotnull++;
224  }
225  }
226 
227  if (!empty($currencyofpayment)) {
228  // We must check that the currency of invoices is the same than the currency of the bank
229  $bankaccount = new Account($this->db);
230  $bankaccount->fetch($this->fk_account);
231  $bankcurrencycode = empty($bankaccount->currency_code) ? $conf->currency : $bankaccount->currency_code;
232  if ($currencyofpayment != $bankcurrencycode && $currencyofpayment != $conf->currency && $bankcurrencycode != $conf->currency) {
233  $langs->load("errors");
234  $this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofpayment, $bankcurrencycode);
235  return -1;
236  }
237  }
238 
239 
240  $totalamount = price2num($totalamount);
241  $totalamount_converted = price2num($totalamount_converted);
242 
243  dol_syslog(get_class($this)."::create", LOG_DEBUG);
244 
245  $this->db->begin();
246 
247  if ($totalamount <> 0) { // On accepte les montants negatifs
248  $ref = $this->getNextNumRef(is_object($thirdparty) ? $thirdparty : '');
249 
250  if ($way == 'dolibarr') {
251  $total = $totalamount;
252  $mtotal = $totalamount_converted; // Maybe use price2num with MT for the converted value
253  } else {
254  $total = $totalamount_converted; // Maybe use price2num with MT for the converted value
255  $mtotal = $totalamount;
256  }
257 
258  $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn (';
259  $sql .= 'ref, entity, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, fk_user_author, fk_bank)';
260  $sql .= " VALUES ('".$this->db->escape($ref)."', ".((int) $conf->entity).", '".$this->db->idate($now)."',";
261  $sql .= " '".$this->db->idate($this->datepaye)."', ".((float) $total).", ".((float) $mtotal).", ".((int) $this->paiementid).", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note_private)."', ".((int) $user->id).", 0)";
262 
263  $resql = $this->db->query($sql);
264  if ($resql) {
265  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiementfourn');
266 
267  // Insere tableau des montants / factures
268  foreach ($this->amounts as $key => $amount) {
269  $facid = $key;
270  if (is_numeric($amount) && $amount <> 0) {
271  $amount = price2num($amount);
272  $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount, multicurrency_amount, multicurrency_code, multicurrency_tx)';
273  $sql .= " VALUES (".((int) $facid).", ".((int) $this->id).", ".((float) $amount).', '.((float) $this->multicurrency_amounts[$key]).', '.($currencyofpayment ? "'".$this->db->escape($currencyofpayment)."'" : 'NULL').', '.(!empty($currencytxofpayment) ? (double) $currencytxofpayment : 1).')';
274  $resql = $this->db->query($sql);
275  if ($resql) {
276  $invoice = new FactureFournisseur($this->db);
277  $invoice->fetch($facid);
278 
279  // If we want to closed paid invoices
280  if ($closepaidinvoices) {
281  $paiement = $invoice->getSommePaiement();
282  $creditnotes=$invoice->getSumCreditNotesUsed();
283  //$creditnotes = 0;
284  $deposits=$invoice->getSumDepositsUsed();
285  //$deposits = 0;
286  $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
287  $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
288  if ($remaintopay == 0) {
289  // If invoice is a down payment, we also convert down payment to discount
290  if ($invoice->type == FactureFournisseur::TYPE_DEPOSIT) {
291  $amount_ht = $amount_tva = $amount_ttc = array();
292  $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
293 
294  // Insert one discount by VAT rate category
295  require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php';
296  $discount = new DiscountAbsolute($this->db);
297  $discount->fetch('', 0, $invoice->id);
298  if (empty($discount->id)) { // If the invoice was not yet converted into a discount (this may have been done manually before we come here)
299  $discount->discount_type = 1; // Supplier discount
300  $discount->description = '(DEPOSIT)';
301  $discount->fk_soc = $invoice->socid;
302  $discount->fk_invoice_supplier_source = $invoice->id;
303 
304  // Loop on each vat rate
305  $i = 0;
306  foreach ($invoice->lines as $line) {
307  if ($line->total_ht != 0) { // no need to create discount if amount is null
308  $amount_ht[$line->tva_tx] += $line->total_ht;
309  $amount_tva[$line->tva_tx] += $line->total_tva;
310  $amount_ttc[$line->tva_tx] += $line->total_ttc;
311  $multicurrency_amount_ht[$line->tva_tx] += $line->multicurrency_total_ht;
312  $multicurrency_amount_tva[$line->tva_tx] += $line->multicurrency_total_tva;
313  $multicurrency_amount_ttc[$line->tva_tx] += $line->multicurrency_total_ttc;
314  $i++;
315  }
316  }
317 
318  foreach ($amount_ht as $tva_tx => $xxx) {
319  $discount->amount_ht = abs($amount_ht[$tva_tx]);
320  $discount->amount_tva = abs($amount_tva[$tva_tx]);
321  $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
322  $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
323  $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
324  $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
325  $discount->tva_tx = abs($tva_tx);
326 
327  $result = $discount->create($user);
328  if ($result < 0) {
329  $error++;
330  break;
331  }
332  }
333  }
334 
335  if ($error) {
336  setEventMessages($discount->error, $discount->errors, 'errors');
337  $error++;
338  }
339  }
340 
341  // Set invoice to paid
342  if (!$error) {
343  $result = $invoice->setPaid($user, '', '');
344  if ($result < 0) {
345  $this->error = $invoice->error;
346  $error++;
347  }
348  }
349  } else {
350  // hook to have an option to automatically close a closable invoice with less payment than the total amount (e.g. agreed cash discount terms)
351  global $hookmanager;
352  $hookmanager->initHooks(array('payment_supplierdao'));
353  $parameters = array('facid' => $facid, 'invoice' => $invoice, 'remaintopay' => $remaintopay);
354  $action = 'CLOSEPAIDSUPPLIERINVOICE';
355  $reshook = $hookmanager->executeHooks('createPayment', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
356  if ($reshook < 0) {
357  $this->error = $hookmanager->error;
358  $error++;
359  } elseif ($reshook == 0) {
360  dol_syslog("Remain to pay for invoice " . $facid . " not null. We do nothing more.");
361  }
362  }
363  }
364 
365  // Regenerate documents of invoices
366  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
367  $newlang = '';
368  $outputlangs = $langs;
369  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
370  $invoice->fetch_thirdparty();
371  $newlang = $invoice->thirdparty->default_lang;
372  }
373  if (!empty($newlang)) {
374  $outputlangs = new Translate("", $conf);
375  $outputlangs->setDefaultLang($newlang);
376  }
377  $ret = $invoice->fetch($facid); // Reload to get new records
378  $result = $invoice->generateDocument($invoice->model_pdf, $outputlangs);
379  if ($result < 0) {
380  setEventMessages($invoice->error, $invoice->errors, 'errors');
381  $error++;
382  }
383  }
384  } else {
385  $this->error = $this->db->lasterror();
386  $error++;
387  }
388  } else {
389  dol_syslog(get_class($this).'::Create Amount line '.$key.' not a number. We discard it.');
390  }
391  }
392 
393  if (!$error) {
394  // Call trigger
395  $result = $this->call_trigger('PAYMENT_SUPPLIER_CREATE', $user);
396  if ($result < 0) {
397  $error++;
398  }
399  // End call triggers
400  }
401  } else {
402  $this->error = $this->db->lasterror();
403  $error++;
404  }
405  } else {
406  $this->error = "ErrorTotalIsNull";
407  dol_syslog('PaiementFourn::Create Error '.$this->error, LOG_ERR);
408  $error++;
409  }
410 
411  if ($totalamount <> 0 && $error == 0) { // On accepte les montants negatifs
412  $this->amount = $total;
413  $this->total = $total;
414  $this->multicurrency_amount = $mtotal;
415  $this->db->commit();
416  dol_syslog('PaiementFourn::Create Ok Total = '.$this->amount.', Total currency = '.$this->multicurrency_amount);
417  return $this->id;
418  } else {
419  $this->db->rollback();
420  return -1;
421  }
422  }
423 
424 
433  public function delete($notrigger = 0)
434  {
435  global $conf, $user, $langs;
436 
437  $bank_line_id = $this->bank_line;
438 
439  $this->db->begin();
440 
441  // Verifier si paiement porte pas sur une facture a l'etat payee
442  // Si c'est le cas, on refuse la suppression
443  $billsarray = $this->getBillsArray('paye=1');
444  if (is_array($billsarray)) {
445  if (count($billsarray)) {
446  $this->error = "ErrorCantDeletePaymentSharedWithPayedInvoice";
447  $this->db->rollback();
448  return -1;
449  }
450  } else {
451  $this->db->rollback();
452  return -2;
453  }
454 
455  // Verifier si paiement ne porte pas sur ecriture bancaire rapprochee
456  // Si c'est le cas, on refuse le delete
457  if ($bank_line_id) {
458  $accline = new AccountLine($this->db);
459  $accline->fetch($bank_line_id);
460  if ($accline->rappro) {
461  $this->error = "ErrorCantDeletePaymentReconciliated";
462  $this->db->rollback();
463  return -3;
464  }
465  }
466 
467  // Efface la ligne de paiement (dans paiement_facture et paiement)
468  $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn';
469  $sql .= ' WHERE fk_paiementfourn = '.((int) $this->id);
470  $resql = $this->db->query($sql);
471  if ($resql) {
472  $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiementfourn';
473  $sql .= " WHERE rowid = ".((int) $this->id);
474  $result = $this->db->query($sql);
475  if (!$result) {
476  $this->error = $this->db->error();
477  $this->db->rollback();
478  return -3;
479  }
480 
481  // Supprimer l'ecriture bancaire si paiement lie a ecriture
482  if ($bank_line_id) {
483  $accline = new AccountLine($this->db);
484  $result = $accline->fetch($bank_line_id);
485  if ($result > 0) { // If result = 0, record not found, we don't try to delete
486  $result = $accline->delete($user);
487  }
488  if ($result < 0) {
489  $this->error = $accline->error;
490  $this->db->rollback();
491  return -4;
492  }
493  }
494 
495  if (!$notrigger) {
496  // Appel des triggers
497  $result = $this->call_trigger('PAYMENT_SUPPLIER_DELETE', $user);
498  if ($result < 0) {
499  $this->db->rollback();
500  return -1;
501  }
502  // Fin appel triggers
503  }
504 
505  $this->db->commit();
506  return 1;
507  } else {
508  $this->error = $this->db->error;
509  $this->db->rollback();
510  return -5;
511  }
512  }
513 
520  public function info($id)
521  {
522  $sql = 'SELECT c.rowid, datec, fk_user_author as fk_user_creat, tms';
523  $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as c';
524  $sql .= ' WHERE c.rowid = '.((int) $id);
525 
526  $resql = $this->db->query($sql);
527  if ($resql) {
528  $num = $this->db->num_rows($resql);
529  if ($num) {
530  $obj = $this->db->fetch_object($resql);
531  $this->id = $obj->rowid;
532 
533  if ($obj->fk_user_creat) {
534  $cuser = new User($this->db);
535  $cuser->fetch($obj->fk_user_creat);
536  $this->user_creation = $cuser;
537  }
538  if ($obj->fk_user_modif) {
539  $muser = new User($this->db);
540  $muser->fetch($obj->fk_user_modif);
541  $this->user_modification = $muser;
542  }
543  $this->date_creation = $this->db->jdate($obj->datec);
544  $this->date_modification = $this->db->jdate($obj->tms);
545  }
546  $this->db->free($resql);
547  } else {
548  dol_print_error($this->db);
549  }
550  }
551 
558  public function getBillsArray($filter = '')
559  {
560  $sql = 'SELECT fk_facturefourn';
561  $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.'facture_fourn as f';
562  $sql .= ' WHERE pf.fk_facturefourn = f.rowid AND fk_paiementfourn = '.((int) $this->id);
563  if ($filter) {
564  $sql .= " AND ".$filter;
565  }
566 
567  dol_syslog(get_class($this).'::getBillsArray', LOG_DEBUG);
568  $resql = $this->db->query($sql);
569  if ($resql) {
570  $i = 0;
571  $num = $this->db->num_rows($resql);
572  $billsarray = array();
573 
574  while ($i < $num) {
575  $obj = $this->db->fetch_object($resql);
576  $billsarray[$i] = $obj->fk_facturefourn;
577  $i++;
578  }
579 
580  return $billsarray;
581  } else {
582  $this->error = $this->db->error();
583  dol_syslog(get_class($this).'::getBillsArray Error '.$this->error);
584  return -1;
585  }
586  }
587 
594  public function getLibStatut($mode = 0)
595  {
596  return $this->LibStatut($this->statut, $mode);
597  }
598 
599  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
607  public function LibStatut($status, $mode = 0)
608  {
609  // phpcs:enable
610  global $langs;
611 
612  $langs->load('compta');
613  /*if ($mode == 0)
614  {
615  if ($status == 0) return $langs->trans('ToValidate');
616  if ($status == 1) return $langs->trans('Validated');
617  }
618  if ($mode == 1)
619  {
620  if ($status == 0) return $langs->trans('ToValidate');
621  if ($status == 1) return $langs->trans('Validated');
622  }
623  if ($mode == 2)
624  {
625  if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
626  if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
627  }
628  if ($mode == 3)
629  {
630  if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
631  if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
632  }
633  if ($mode == 4)
634  {
635  if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
636  if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
637  }
638  if ($mode == 5)
639  {
640  if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
641  if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
642  }
643  if ($mode == 6)
644  {
645  if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
646  if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
647  }*/
648  return '';
649  }
650 
651 
662  public function getNomUrl($withpicto = 0, $option = '', $mode = 'withlistofinvoices', $notooltip = 0, $morecss = '')
663  {
664  global $langs, $conf, $hookmanager;
665 
666  if (!empty($conf->dol_no_mouse_hover)) {
667  $notooltip = 1; // Force disable tooltips
668  }
669 
670  $result = '';
671 
672  $text = $this->ref; // Sometimes ref contains label
673  $reg = array();
674  if (preg_match('/^\((.*)\)$/i', $text, $reg)) {
675  // Label generique car entre parentheses. On l'affiche en le traduisant
676  if ($reg[1] == 'paiement') {
677  $reg[1] = 'Payment';
678  }
679  $text = $langs->trans($reg[1]);
680  }
681 
682  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Payment").'</u><br>';
683  $label .= '<strong>'.$langs->trans("Ref").':</strong> '.$text;
684  $dateofpayment = ($this->datepaye ? $this->datepaye : $this->date);
685  if ($dateofpayment) {
686  $label .= '<br><strong>'.$langs->trans("Date").':</strong> '.dol_print_date($dateofpayment, 'dayhour', 'tzuser');
687  }
688  if ($this->amount) {
689  $label .= '<br><strong>'.$langs->trans("Amount").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
690  }
691 
692  $linkclose = '';
693  if (empty($notooltip)) {
694  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
695  $label = $langs->trans("Payment");
696  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
697  }
698  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
699  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
700  } else {
701  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
702  }
703 
704  $linkstart = '<a href="'.DOL_URL_ROOT.'/fourn/paiement/card.php?id='.$this->id.'"';
705  $linkstart .= $linkclose.'>';
706  $linkend = '</a>';
707 
708  $result .= $linkstart;
709  if ($withpicto) {
710  $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
711  }
712  if ($withpicto != 2) {
713  $result .= $this->ref;
714  }
715  $result .= $linkend;
716 
717  global $action;
718  $hookmanager->initHooks(array($this->element . 'dao'));
719  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
720  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
721  if ($reshook > 0) {
722  $result = $hookmanager->resPrint;
723  } else {
724  $result .= $hookmanager->resPrint;
725  }
726  return $result;
727  }
728 
737  public function initAsSpecimen($option = '')
738  {
739  global $user, $langs, $conf;
740 
741  $now = dol_now();
742  $arraynow = dol_getdate($now);
743  $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
744 
745  // Initialize parameters
746  $this->id = 0;
747  $this->ref = 'SPECIMEN';
748  $this->specimen = 1;
749  $this->facid = 1;
750  $this->socid = 1;
751  $this->datepaye = $nownotime;
752  }
753 
762  public function getNextNumRef($soc, $mode = 'next')
763  {
764  global $conf, $db, $langs;
765  $langs->load("bills");
766 
767  // Clean parameters (if not defined or using deprecated value)
768  if (empty($conf->global->SUPPLIER_PAYMENT_ADDON)) {
769  $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
770  } elseif ($conf->global->SUPPLIER_PAYMENT_ADDON == 'brodator') {
771  $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_brodator';
772  } elseif ($conf->global->SUPPLIER_PAYMENT_ADDON == 'bronan') {
773  $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan';
774  }
775 
776  if (!empty($conf->global->SUPPLIER_PAYMENT_ADDON)) {
777  $mybool = false;
778 
779  $file = $conf->global->SUPPLIER_PAYMENT_ADDON.".php";
780  $classname = $conf->global->SUPPLIER_PAYMENT_ADDON;
781 
782  // Include file with class
783  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
784 
785  foreach ($dirmodels as $reldir) {
786  $dir = dol_buildpath($reldir."core/modules/supplier_payment/");
787 
788  // Load file with numbering class (if found)
789  if (is_file($dir.$file) && is_readable($dir.$file)) {
790  $mybool |= include_once $dir.$file;
791  }
792  }
793 
794  // For compatibility
795  if ($mybool === false) {
796  $file = $conf->global->SUPPLIER_PAYMENT_ADDON.".php";
797  $classname = "mod_supplier_payment_".$conf->global->SUPPLIER_PAYMENT_ADDON;
798  $classname = preg_replace('/\-.*$/', '', $classname);
799  // Include file with class
800  foreach ($conf->file->dol_document_root as $dirroot) {
801  $dir = $dirroot."/core/modules/supplier_payment/";
802 
803  // Load file with numbering class (if found)
804  if (is_file($dir.$file) && is_readable($dir.$file)) {
805  $mybool |= include_once $dir.$file;
806  }
807  }
808  }
809 
810  if ($mybool === false) {
811  dol_print_error('', "Failed to include file ".$file);
812  return '';
813  }
814 
815  $obj = new $classname();
816  $numref = "";
817  $numref = $obj->getNextValue($soc, $this);
818 
823  if ($mode != 'last' && !$numref) {
824  dol_print_error($db, "SupplierPayment::getNextNumRef ".$obj->error);
825  return "";
826  }
827 
828  return $numref;
829  } else {
830  $langs->load("errors");
831  print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Supplier"));
832  return "";
833  }
834  }
835 
847  public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
848  {
849  global $conf, $user, $langs;
850 
851  $langs->load("suppliers");
852 
853  // Set the model on the model name to use
854  if (empty($modele)) {
855  if (!empty($conf->global->SUPPLIER_PAYMENT_ADDON_PDF)) {
856  $modele = $conf->global->SUPPLIER_PAYMENT_ADDON_PDF;
857  } else {
858  $modele = ''; // No default value. For supplier invoice, we allow to disable all PDF generation
859  }
860  }
861 
862  if (empty($modele)) {
863  return 0;
864  } else {
865  $modelpath = "core/modules/supplier_payment/doc/";
866 
867  return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
868  }
869  }
870 
871 
872 
878  public function getWay()
879  {
880  global $conf;
881 
882  $way = 'dolibarr';
883  if (isModEnabled("multicurrency")) {
884  foreach ($this->multicurrency_amounts as $value) {
885  if (!empty($value)) { // one value found then payment is in invoice currency
886  $way = 'customer';
887  break;
888  }
889  }
890  }
891 
892  return $way;
893  }
894 
895 
896  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
903  public function fetch_thirdparty($force_thirdparty_id = 0)
904  {
905  // phpcs:enable
906  require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
907 
908  if (empty($force_thirdparty_id)) {
909  $billsarray = $this->getBillsArray(); // From payment, the fk_soc isn't available, we should load the first supplier invoice to get him
910  if (!empty($billsarray)) {
911  $supplier_invoice = new FactureFournisseur($this->db);
912  if ($supplier_invoice->fetch($billsarray[0]) > 0) {
913  $force_thirdparty_id = $supplier_invoice->fk_soc;
914  }
915  }
916  }
917 
918  return parent::fetch_thirdparty($force_thirdparty_id);
919  }
920 }
dol_getdate
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Definition: functions.lib.php:2925
PaiementFourn\getBillsArray
getBillsArray($filter='')
Return list of supplier invoices the payment point to.
Definition: paiementfourn.class.php:558
FactureFournisseur
Class to manage suppliers invoices.
Definition: fournisseur.facture.class.php:51
PaiementFourn\getWay
getWay()
get the right way of payment
Definition: paiementfourn.class.php:878
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:5107
Translate
Class to manage translations.
Definition: translate.class.php:30
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1158
PaiementFourn\getNextNumRef
getNextNumRef($soc, $mode='next')
Return next reference of supplier invoice not already used (or last reference) according to numbering...
Definition: paiementfourn.class.php:762
MultiCurrency\getAmountConversionFromInvoiceRate
static getAmountConversionFromInvoiceRate($fk_facture, $amount, $way='dolibarr', $table='facture', $invoice_rate=null)
Get the conversion of amount with invoice rate.
Definition: multicurrency.class.php:571
PaiementFourn\getLibStatut
getLibStatut($mode=0)
Return the label of the status.
Definition: paiementfourn.class.php:594
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5955
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2675
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4135
CommonObject\commonGenerateDocument
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
Definition: commonobject.class.php:5361
PaiementFourn\LibStatut
LibStatut($status, $mode=0)
Return the label of a given status.
Definition: paiementfourn.class.php:607
PaiementFourn\fetch
fetch($id, $ref='', $fk_bank='')
Load payment object.
Definition: paiementfourn.class.php:101
PaiementFourn\generateDocument
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template model.
Definition: paiementfourn.class.php:847
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1741
DiscountAbsolute
Class to manage absolute discounts.
Definition: discount.class.php:29
Paiement\$total
$total
Definition: paiement.class.php:68
PaiementFourn\getNomUrl
getNomUrl($withpicto=0, $option='', $mode='withlistofinvoices', $notooltip=0, $morecss='')
Return clicable name (with picto eventually)
Definition: paiementfourn.class.php:662
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
Definition: functions.lib.php:8673
PaiementFourn\create
create($user, $closepaidinvoices=0, $thirdparty=null)
Create payment in database.
Definition: paiementfourn.class.php:167
PaiementFourn\info
info($id)
Information on object.
Definition: paiementfourn.class.php:520
$sql
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:207
ref
$object ref
Definition: info.php:78
PaiementFourn
Class to manage payments for supplier invoices.
Definition: paiementfourn.class.php:39
User
Class to manage Dolibarr users.
Definition: user.class.php:47
Paiement
Class to manage payments of customer invoices.
Definition: paiement.class.php:43
FactureFournisseur\TYPE_DEPOSIT
const TYPE_DEPOSIT
Deposit invoice.
Definition: fournisseur.facture.class.php:346
PaiementFourn\fetch_thirdparty
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id into this->thirdparty.
Definition: paiementfourn.class.php:903
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:4473
AccountLine
Class to manage bank transaction lines.
Definition: account.class.php:1880
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:3056
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:5829
PaiementFourn\__construct
__construct($db)
Constructor.
Definition: paiementfourn.class.php:88
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5770
PaiementFourn\initAsSpecimen
initAsSpecimen($option='')
Initialise an instance with random values.
Definition: paiementfourn.class.php:737
dol_mktime
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...
Definition: functions.lib.php:2968
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:156
Account
Class to manage bank accounts.
Definition: account.class.php:40
float
div float
Buy price without taxes.
Definition: style.css.php:921