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