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