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