dolibarr  17.0.4
paiement.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-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5  * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
6  * Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
7  * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
8  * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
9  * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
10  * Copyright (C) 2018 Thibault FOUCART <support@ptibogxiv.net>
11  * Copyright (C) 2018-2022 Frédéric France <frederic.france@netlogic.fr>
12  * Copyright (C) 2020 Andreu Bisquerra Gaya <jove@bisquerra.com>
13  * Copyright (C) 2021 OpenDsi <support@open-dsi.fr>
14  * Copyright (C) 2023 Joachim Kueter <git-jk@bloxera.com>
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program. If not, see <https://www.gnu.org/licenses/>.
28  */
29 
35 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
37 
38 
42 class Paiement extends CommonObject
43 {
47  public $element = 'payment';
48 
52  public $table_element = 'paiement';
53 
57  public $picto = 'payment';
58 
59  public $facid;
60  public $datepaye;
61  public $date; // same than $datepaye
62 
67  public $total;
68 
73  public $montant;
74 
75  public $amount; // Total amount of payment (in the main currency)
76  public $multicurrency_amount; // Total amount of payment (in the currency of the bank account)
77  public $amounts = array(); // array: invoice ID => amount for that invoice (in the main currency)
78  public $multicurrency_amounts = array(); // array: invoice ID => amount for that invoice (in the invoice's currency)
79  public $multicurrency_code = array(); // array: invoice ID => currency code for that invoice
80 
81  public $pos_change = 0; // Excess received in TakePOS cash payment
82 
83  public $author;
84  public $paiementid; // ID of mode of payment. Is saved into fields fk_paiement on llx_paiement = id of llx_c_paiement
85  public $paiementcode; // Code of mode of payment.
86 
90  public $type_label;
91 
95  public $type_code;
96 
102  public $num_paiement;
103 
107  public $num_payment;
108 
112  public $ext_payment_id;
113 
117  public $id_prelevement;
118 
122  public $num_prelevement;
123 
127  public $ext_payment_site;
128 
134  public $bank_account;
135 
139  public $fk_account;
140 
144  public $bank_line;
145 
146  // fk_paiement dans llx_paiement est l'id du type de paiement (7 pour CHQ, ...)
147  // fk_paiement dans llx_paiement_facture est le rowid du paiement
151  public $fk_paiement; // Type of payment
152 
156  public $ref_ext;
157 
158 
164  public function __construct($db)
165  {
166  $this->db = $db;
167  }
168 
177  public function fetch($id, $ref = '', $fk_bank = '')
178  {
179  $sql = 'SELECT p.rowid, p.ref, p.ref_ext, p.datep as dp, p.amount, p.statut, p.ext_payment_id, p.ext_payment_site, p.fk_bank, p.multicurrency_amount,';
180  $sql .= ' c.code as type_code, c.libelle as type_label,';
181  $sql .= ' p.num_paiement as num_payment, p.note,';
182  $sql .= ' b.fk_account';
183  $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id';
184  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
185  $sql .= ' WHERE p.entity IN ('.getEntity('invoice').')';
186  if ($id > 0) {
187  $sql .= ' AND p.rowid = '.((int) $id);
188  } elseif ($ref) {
189  $sql .= " AND p.ref = '".$this->db->escape($ref)."'";
190  } elseif ($fk_bank) {
191  $sql .= ' AND p.fk_bank = '.((int) $fk_bank);
192  }
193 
194  $resql = $this->db->query($sql);
195  if ($resql) {
196  if ($this->db->num_rows($resql)) {
197  $obj = $this->db->fetch_object($resql);
198 
199  $this->id = $obj->rowid;
200  $this->ref = $obj->ref ? $obj->ref : $obj->rowid;
201  $this->ref_ext = $obj->ref_ext;
202  $this->date = $this->db->jdate($obj->dp);
203  $this->datepaye = $this->db->jdate($obj->dp);
204  $this->num_payment = $obj->num_payment;
205  $this->montant = $obj->amount; // deprecated
206  $this->amount = $obj->amount;
207  $this->multicurrency_amount = $obj->multicurrency_amount;
208  $this->note = $obj->note;
209  $this->note_private = $obj->note;
210  $this->type_label = $obj->type_label;
211  $this->type_code = $obj->type_code;
212  $this->statut = $obj->statut;
213  $this->ext_payment_id = $obj->ext_payment_id;
214  $this->ext_payment_site = $obj->ext_payment_site;
215 
216  $this->bank_account = $obj->fk_account; // deprecated
217  $this->fk_account = $obj->fk_account;
218  $this->bank_line = $obj->fk_bank;
219 
220  $this->db->free($resql);
221  return 1;
222  } else {
223  $this->db->free($resql);
224  return 0;
225  }
226  } else {
227  dol_print_error($this->db);
228  return -1;
229  }
230  }
231 
242  public function create($user, $closepaidinvoices = 0, $thirdparty = null)
243  {
244  global $conf, $langs;
245 
246  $error = 0;
247  $way = $this->getWay(); // 'dolibarr' to use amount, 'customer' to use foreign multicurrency amount
248 
249  $now = dol_now();
250 
251  // Clean parameters
252  $totalamount = 0;
253  $totalamount_converted = 0;
254  $atleastonepaymentnotnull = 0;
255 
256  if ($way == 'dolibarr') { // Payments were entered into the column of main currency
257  $amounts = &$this->amounts;
258  $amounts_to_update = &$this->multicurrency_amounts;
259  } else { // Payments were entered into the column of foreign currency
260  $amounts = &$this->multicurrency_amounts;
261  $amounts_to_update = &$this->amounts;
262  }
263 
264  $currencyofpayment = '';
265 
266  foreach ($amounts as $key => $value) { // How payment is dispatch
267  if (empty($value)) {
268  continue;
269  }
270  // $key is id of invoice, $value is amount, $way is a 'dolibarr' if amount is in main currency, 'customer' if in foreign currency
271  $value_converted = Multicurrency::getAmountConversionFromInvoiceRate($key, $value, $way);
272  // Add controls of input validity
273  if ($value_converted === false) {
274  // We failed to find the conversion for one invoice
275  $this->error = $langs->trans('FailedToFoundTheConversionRateForInvoice');
276  return -1;
277  }
278  if (empty($currencyofpayment)) {
279  $currencyofpayment = $this->multicurrency_code[$key];
280  }
281  if ($currencyofpayment != $this->multicurrency_code[$key]) {
282  // If we have invoices with different currencies in the payment, we stop here
283  $this->error = 'ErrorYouTryToPayInvoicesWithDifferentCurrenciesInSamePayment';
284  return -1;
285  }
286 
287  $totalamount_converted += $value_converted;
288  $amounts_to_update[$key] = price2num($value_converted, 'MT');
289 
290  $newvalue = price2num($value, 'MT');
291  $amounts[$key] = $newvalue;
292  $totalamount += $newvalue;
293  if (!empty($newvalue)) {
294  $atleastonepaymentnotnull++;
295  }
296  }
297 
298  if (!empty($currencyofpayment)) {
299  // We must check that the currency of invoices is the same than the currency of the bank
300  $bankaccount = new Account($this->db);
301  $bankaccount->fetch($this->fk_account);
302  $bankcurrencycode = empty($bankaccount->currency_code) ? $conf->currency : $bankaccount->currency_code;
303  if ($currencyofpayment != $bankcurrencycode && $currencyofpayment != $conf->currency && $bankcurrencycode != $conf->currency) {
304  $langs->load("errors");
305  $this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofpayment, $bankcurrencycode);
306  return -1;
307  }
308  }
309 
310 
311  $totalamount = price2num($totalamount);
312  $totalamount_converted = price2num($totalamount_converted);
313 
314  // Check parameters
315  if (empty($totalamount) && empty($atleastonepaymentnotnull)) { // We accept negative amounts for withdraw reject but not empty arrays
316  $this->errors[] = 'TotalAmountEmpty';
317  $this->error = $langs->trans('TotalAmountEmpty');
318  return -1;
319  }
320 
321  dol_syslog(get_class($this)."::create insert paiement", LOG_DEBUG);
322 
323  $this->db->begin();
324 
325  $this->ref = $this->getNextNumRef(is_object($thirdparty) ? $thirdparty : '');
326 
327  if (empty($this->ref_ext)) {
328  $this->ref_ext = '';
329  }
330 
331  if ($way == 'dolibarr') {
332  $total = $totalamount;
333  $mtotal = $totalamount_converted; // Maybe use price2num with MT for the converted value
334  } else {
335  $total = $totalamount_converted; // Maybe use price2num with MT for the converted value
336  $mtotal = $totalamount;
337  }
338 
339  $num_payment = $this->num_payment;
340  $note = ($this->note_private ? $this->note_private : $this->note);
341 
342  $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (entity, ref, ref_ext, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, ext_payment_id, ext_payment_site, fk_user_creat, pos_change)";
343  $sql .= " VALUES (".((int) $conf->entity).", '".$this->db->escape($this->ref)."', '".$this->db->escape($this->ref_ext)."', '".$this->db->idate($now)."', '".$this->db->idate($this->datepaye)."', ".((float) $total).", ".((float) $mtotal).", ".((int) $this->paiementid).", ";
344  $sql .= "'".$this->db->escape($num_payment)."', '".$this->db->escape($note)."', ".($this->ext_payment_id ? "'".$this->db->escape($this->ext_payment_id)."'" : "null").", ".($this->ext_payment_site ? "'".$this->db->escape($this->ext_payment_site)."'" : "null").", ".((int) $user->id).", ".((float) $this->pos_change).")";
345 
346  $resql = $this->db->query($sql);
347  if ($resql) {
348  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiement');
349 
350  // Insert links amount / invoices
351  foreach ($this->amounts as $key => $amount) {
352  $facid = $key;
353  if (is_numeric($amount) && $amount <> 0) {
354  $amount = price2num($amount);
355  $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount, multicurrency_amount)";
356  // TODO Add multicurrency_code and multicurrency_tx
357  $sql .= " VALUES (".((int) $facid).", ".((int) $this->id).", ".((float) $amount).", ".((float) $this->multicurrency_amounts[$key]).")";
358 
359  dol_syslog(get_class($this).'::create Amount line '.$key.' insert paiement_facture', LOG_DEBUG);
360  $resql = $this->db->query($sql);
361  if ($resql) {
362  $invoice = new Facture($this->db);
363  $invoice->fetch($facid);
364 
365  // If we want to closed payed invoices
366  if ($closepaidinvoices) {
367  $paiement = $invoice->getSommePaiement();
368  $creditnotes = $invoice->getSumCreditNotesUsed();
369  $deposits = $invoice->getSumDepositsUsed();
370  $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
371  $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
372 
373  //var_dump($invoice->total_ttc.' - '.$paiement.' -'.$creditnotes.' - '.$deposits.' - '.$remaintopay);exit;
374 
375  //Invoice types that are eligible for changing status to paid
376  $affected_types = array(
382  );
383 
384  if (!in_array($invoice->type, $affected_types)) {
385  dol_syslog("Invoice ".$facid." is not a standard, nor replacement invoice, nor credit note, nor deposit invoice, nor situation invoice. We do nothing more.");
386  } elseif ($remaintopay) {
387  // hook to have an option to automatically close a closable invoice with less payment than the total amount (e.g. agreed cash discount terms)
388  global $hookmanager;
389  $hookmanager->initHooks(array('paymentdao'));
390  $parameters = array('facid' => $facid, 'invoice' => $invoice, 'remaintopay' => $remaintopay);
391  $action = 'CLOSEPAIDINVOICE';
392  $reshook = $hookmanager->executeHooks('createPayment', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
393  if ($reshook < 0) {
394  $this->errors[] = $hookmanager->error;
395  $this->error = $hookmanager->error;
396  $error++;
397  } elseif ($reshook == 0) {
398  dol_syslog("Remain to pay for invoice " . $facid . " not null. We do nothing more.");
399  }
400  // } else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more.");
401  } else {
402  // If invoice is a down payment, we also convert down payment to discount
403  if ($invoice->type == Facture::TYPE_DEPOSIT) {
404  $amount_ht = $amount_tva = $amount_ttc = array();
405  $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
406 
407  // Insert one discount by VAT rate category
408  $discount = new DiscountAbsolute($this->db);
409  $discount->fetch('', $invoice->id);
410  if (empty($discount->id)) { // If the invoice was not yet converted into a discount (this may have been done manually before we come here)
411  $discount->description = '(DEPOSIT)';
412  $discount->fk_soc = $invoice->socid;
413  $discount->fk_facture_source = $invoice->id;
414 
415  // Loop on each vat rate
416  $i = 0;
417  foreach ($invoice->lines as $line) {
418  if ($line->total_ht != 0) { // no need to create discount if amount is null
419  $amount_ht[$line->tva_tx] += $line->total_ht;
420  $amount_tva[$line->tva_tx] += $line->total_tva;
421  $amount_ttc[$line->tva_tx] += $line->total_ttc;
422  $multicurrency_amount_ht[$line->tva_tx] += $line->multicurrency_total_ht;
423  $multicurrency_amount_tva[$line->tva_tx] += $line->multicurrency_total_tva;
424  $multicurrency_amount_ttc[$line->tva_tx] += $line->multicurrency_total_ttc;
425  $i++;
426  }
427  }
428 
429  foreach ($amount_ht as $tva_tx => $xxx) {
430  $discount->amount_ht = abs($amount_ht[$tva_tx]);
431  $discount->amount_tva = abs($amount_tva[$tva_tx]);
432  $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
433  $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
434  $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
435  $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
436  $discount->tva_tx = abs($tva_tx);
437 
438  $result = $discount->create($user);
439  if ($result < 0) {
440  $error++;
441  break;
442  }
443  }
444  }
445 
446  if ($error) {
447  $this->error = $discount->error;
448  $this->errors = $discount->errors;
449  $error++;
450  }
451  }
452 
453  // Set invoice to paid
454  if (!$error) {
455  $result = $invoice->setPaid($user, '', '');
456  if ($result < 0) {
457  $this->error = $invoice->error;
458  $this->errors = $invoice->errors;
459  $error++;
460  }
461  }
462  }
463  }
464 
465  // Regenerate documents of invoices
466  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
467  dol_syslog(get_class($this).'::create Regenerate the document after inserting payment for thirdparty default_lang='.(is_object($invoice->thirdparty) ? $invoice->thirdparty->default_lang : 'null'), LOG_DEBUG);
468 
469  $newlang = '';
470  $outputlangs = $langs;
471  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
472  $invoice->fetch_thirdparty();
473  $newlang = $invoice->thirdparty->default_lang;
474  }
475  if (!empty($newlang)) {
476  $outputlangs = new Translate("", $conf);
477  $outputlangs->setDefaultLang($newlang);
478  }
479 
480  $hidedetails = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0;
481  $hidedesc = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0;
482  $hideref = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0;
483 
484  $ret = $invoice->fetch($facid); // Reload to get new records
485 
486  $result = $invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
487 
488  if ($result < 0) {
489  $this->error = $invoice->error;
490  $this->errors = $invoice->errors;
491  $error++;
492  }
493  }
494  } else {
495  $this->error = $this->db->lasterror();
496  $error++;
497  }
498  } else {
499  dol_syslog(get_class($this).'::Create Amount line '.$key.' not a number. We discard it.');
500  }
501  }
502 
503  if (!$error) { // All payments into $this->amounts were recorded without errors
504  // Appel des triggers
505  $result = $this->call_trigger('PAYMENT_CUSTOMER_CREATE', $user);
506  if ($result < 0) {
507  $error++;
508  }
509  // Fin appel triggers
510  }
511  } else {
512  $this->error = $this->db->lasterror();
513  $error++;
514  }
515 
516  if (!$error) {
517  $this->amount = $total;
518  $this->total = $total; // deprecated
519  $this->multicurrency_amount = $mtotal;
520  $this->db->commit();
521  return $this->id;
522  } else {
523  $this->db->rollback();
524  return -1;
525  }
526  }
527 
528 
537  public function delete($notrigger = 0)
538  {
539  global $conf, $user, $langs;
540 
541  $error = 0;
542 
543  $bank_line_id = $this->bank_line;
544 
545  $this->db->begin();
546 
547  // Verifier si paiement porte pas sur une facture classee
548  // Si c'est le cas, on refuse la suppression
549  $billsarray = $this->getBillsArray('f.fk_statut > 1');
550  if (is_array($billsarray)) {
551  if (count($billsarray)) {
552  $this->error = "ErrorDeletePaymentLinkedToAClosedInvoiceNotPossible";
553  $this->db->rollback();
554  return -1;
555  }
556  } else {
557  $this->db->rollback();
558  return -2;
559  }
560 
561  // Delete bank urls. If payment is on a conciliated line, return error.
562  if ($bank_line_id > 0) {
563  $accline = new AccountLine($this->db);
564 
565  $result = $accline->fetch($bank_line_id);
566  if ($result == 0) {
567  $accline->id = $accline->rowid = $bank_line_id; // If not found, we set artificially rowid to allow delete of llx_bank_url
568  }
569 
570  // Delete bank account url lines linked to payment
571  $result = $accline->delete_urls($user);
572  if ($result < 0) {
573  $this->error = $accline->error;
574  $this->db->rollback();
575  return -3;
576  }
577 
578  // Delete bank account lines linked to payment
579  $result = $accline->delete($user);
580  if ($result < 0) {
581  $this->error = $accline->error;
582  $this->db->rollback();
583  return -4;
584  }
585  }
586 
587  if (!$notrigger) {
588  // Call triggers
589  $result = $this->call_trigger('PAYMENT_CUSTOMER_DELETE', $user);
590  if ($result < 0) {
591  $this->db->rollback();
592  return -1;
593  }
594  // End call triggers
595  }
596 
597  // Delete payment (into paiement_facture and paiement)
598  $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement_facture';
599  $sql .= ' WHERE fk_paiement = '.((int) $this->id);
600  dol_syslog($sql);
601  $result = $this->db->query($sql);
602  if ($result) {
603  $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement';
604  $sql .= " WHERE rowid = ".((int) $this->id);
605  dol_syslog($sql);
606  $result = $this->db->query($sql);
607  if (!$result) {
608  $this->error = $this->db->lasterror();
609  $this->db->rollback();
610  return -3;
611  }
612 
613  $this->db->commit();
614  return 1;
615  } else {
616  $this->error = $this->db->error;
617  $this->db->rollback();
618  return -5;
619  }
620  }
621 
622 
637  public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque, $notrigger = 0, $accountancycode = '')
638  {
639  global $conf, $langs, $user;
640 
641  $error = 0;
642  $bank_line_id = 0;
643 
644  if (isModEnabled("banque")) {
645  if ($accountid <= 0) {
646  $this->error = 'Bad value for parameter accountid='.$accountid;
647  dol_syslog(get_class($this).'::addPaymentToBank '.$this->error, LOG_ERR);
648  return -1;
649  }
650 
651  $this->fk_account = $accountid;
652 
653  dol_syslog("addPaymentToBank ".$user->id.", ".$mode.", ".$label.", ".$this->fk_account.", ".$emetteur_nom.", ".$emetteur_banque);
654 
655  include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
656  $acc = new Account($this->db);
657  $result = $acc->fetch($this->fk_account);
658  if ($result < 0) {
659  $error++;
660  return -1;
661  }
662 
663  $this->db->begin();
664 
665  $totalamount = $this->amount;
666  $totalamount_main_currency = null;
667  if (empty($totalamount)) {
668  $totalamount = $this->total; // For backward compatibility
669  }
670 
671  // if dolibarr currency != bank currency then we received an amount in customer currency (currently I don't manage the case : my currency is USD, the customer currency is EUR and he paid me in GBP. Seems no sense for me)
672  if (isModEnabled('multicurrency') && $conf->currency != $acc->currency_code) {
673  $totalamount = $this->multicurrency_amount; // We will insert into llx_bank.amount in foreign currency
674  $totalamount_main_currency = $this->amount; // We will also save the amount in main currency into column llx_bank.amount_main_currency
675  }
676 
677  if ($mode == 'payment_supplier') {
678  $totalamount = -$totalamount;
679  if (isset($totalamount_main_currency)) {
680  $totalamount_main_currency = -$totalamount_main_currency;
681  }
682  }
683 
684  // Insert payment into llx_bank
685  $bank_line_id = $acc->addline(
686  $this->datepaye,
687  $this->paiementcode ? $this->paiementcode : $this->paiementid, // Payment mode code ('CB', 'CHQ' or 'VIR' for example). Use payment id if not defined for backward compatibility.
688  $label,
689  $totalamount, // Sign must be positive when we receive money (customer payment), negative when you give money (supplier invoice or credit note)
690  $this->num_payment,
691  '',
692  $user,
693  $emetteur_nom,
694  $emetteur_banque,
695  $accountancycode,
696  null,
697  '',
698  $totalamount_main_currency
699  );
700 
701  // Mise a jour fk_bank dans llx_paiement
702  // On connait ainsi le paiement qui a genere l'ecriture bancaire
703  if ($bank_line_id > 0) {
704  $result = $this->update_fk_bank($bank_line_id);
705  if ($result <= 0) {
706  $error++;
707  dol_print_error($this->db);
708  }
709 
710  // Add link 'payment', 'payment_supplier' in bank_url between payment and bank transaction
711  if (!$error) {
712  $url = '';
713  if ($mode == 'payment') {
714  $url = DOL_URL_ROOT.'/compta/paiement/card.php?id=';
715  }
716  if ($mode == 'payment_supplier') {
717  $url = DOL_URL_ROOT.'/fourn/paiement/card.php?id=';
718  }
719  if ($url) {
720  $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
721  if ($result <= 0) {
722  $error++;
723  dol_print_error($this->db);
724  }
725  }
726  }
727 
728  // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
729  //if (! $error && $label != '(WithdrawalPayment)')
730  if (!$error) {
731  $linkaddedforthirdparty = array();
732  foreach ($this->amounts as $key => $value) { // We should have invoices always for same third party but we loop in case of.
733  if ($mode == 'payment') {
734  $fac = new Facture($this->db);
735  $fac->fetch($key);
736  $fac->fetch_thirdparty();
737  if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) { // Not yet done for this thirdparty
738  $result = $acc->add_url_line(
739  $bank_line_id,
740  $fac->thirdparty->id,
741  DOL_URL_ROOT.'/comm/card.php?socid=',
742  $fac->thirdparty->name,
743  'company'
744  );
745  if ($result <= 0) {
746  dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
747  }
748  $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
749  }
750  }
751  if ($mode == 'payment_supplier') {
752  $fac = new FactureFournisseur($this->db);
753  $fac->fetch($key);
754  $fac->fetch_thirdparty();
755  if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) { // Not yet done for this thirdparty
756  $result = $acc->add_url_line(
757  $bank_line_id,
758  $fac->thirdparty->id,
759  DOL_URL_ROOT.'/fourn/card.php?socid=',
760  $fac->thirdparty->name,
761  'company'
762  );
763  if ($result <= 0) {
764  dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
765  }
766  $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
767  }
768  }
769  }
770  }
771 
772  // Add link 'WithdrawalPayment' in bank_url
773  if (!$error && $label == '(WithdrawalPayment)') {
774  $result = $acc->add_url_line(
775  $bank_line_id,
776  $this->id_prelevement,
777  DOL_URL_ROOT.'/compta/prelevement/card.php?id=',
778  $this->num_payment,
779  'withdraw'
780  );
781  }
782 
783  // Add link 'InvoiceRefused' in bank_url
784  if (! $error && $label == '(InvoiceRefused)') {
785  $result=$acc->add_url_line(
786  $bank_line_id,
787  $this->id_prelevement,
788  DOL_URL_ROOT.'/compta/prelevement/card.php?id=',
789  $this->num_prelevement,
790  'withdraw'
791  );
792  }
793 
794  if (!$error && !$notrigger) {
795  // Appel des triggers
796  $result = $this->call_trigger('PAYMENT_ADD_TO_BANK', $user);
797  if ($result < 0) {
798  $error++;
799  }
800  // Fin appel triggers
801  }
802  } else {
803  $this->error = $acc->error;
804  $error++;
805  }
806 
807  if (!$error) {
808  $this->db->commit();
809  } else {
810  $this->db->rollback();
811  }
812  }
813 
814  if (!$error) {
815  return $bank_line_id;
816  } else {
817  return -1;
818  }
819  }
820 
821 
822  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
829  public function update_fk_bank($id_bank)
830  {
831  // phpcs:enable
832  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' set fk_bank = '.((int) $id_bank);
833  $sql .= " WHERE rowid = ".((int) $this->id);
834 
835  dol_syslog(get_class($this).'::update_fk_bank', LOG_DEBUG);
836  $result = $this->db->query($sql);
837  if ($result) {
838  return 1;
839  } else {
840  $this->error = $this->db->lasterror();
841  dol_syslog(get_class($this).'::update_fk_bank '.$this->error);
842  return -1;
843  }
844  }
845 
846  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
853  public function update_date($date)
854  {
855  // phpcs:enable
856  $error = 0;
857 
858  if (!empty($date) && $this->statut != 1) {
859  $this->db->begin();
860 
861  dol_syslog(get_class($this)."::update_date with date = ".$date, LOG_DEBUG);
862 
863  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
864  $sql .= " SET datep = '".$this->db->idate($date)."'";
865  $sql .= " WHERE rowid = ".((int) $this->id);
866 
867  $result = $this->db->query($sql);
868  if (!$result) {
869  $error++;
870  $this->error = 'Error -1 '.$this->db->error();
871  }
872 
873  $type = $this->element;
874 
875  $sql = "UPDATE ".MAIN_DB_PREFIX.'bank';
876  $sql .= " SET dateo = '".$this->db->idate($date)."', datev = '".$this->db->idate($date)."'";
877  $sql .= " WHERE rowid IN (SELECT fk_bank FROM ".MAIN_DB_PREFIX."bank_url WHERE type = '".$this->db->escape($type)."' AND url_id = ".((int) $this->id).")";
878  $sql .= " AND rappro = 0";
879 
880  $result = $this->db->query($sql);
881  if (!$result) {
882  $error++;
883  $this->error = 'Error -1 '.$this->db->error();
884  }
885 
886  if (!$error) {
887  }
888 
889  if (!$error) {
890  $this->datepaye = $date;
891  $this->date = $date;
892 
893  $this->db->commit();
894  return 0;
895  } else {
896  $this->db->rollback();
897  return -2;
898  }
899  }
900  return -1; //no date given or already validated
901  }
902 
903  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
910  public function update_num($num)
911  {
912  // phpcs:enable
913  if (!empty($num) && $this->statut != 1) {
914  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
915  $sql .= " SET num_paiement = '".$this->db->escape($num)."'";
916  $sql .= " WHERE rowid = ".((int) $this->id);
917 
918  dol_syslog(get_class($this)."::update_num", LOG_DEBUG);
919  $result = $this->db->query($sql);
920  if ($result) {
921  $this->num_payment = $this->db->escape($num);
922  return 0;
923  } else {
924  $this->error = 'Error -1 '.$this->db->error();
925  return -2;
926  }
927  }
928  return -1; //no num given or already validated
929  }
930 
938  public function valide(User $user = null)
939  {
940  return $this->validate($user);
941  }
942 
949  public function validate(User $user = null)
950  {
951  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET statut = 1 WHERE rowid = '.((int) $this->id);
952 
953  dol_syslog(get_class($this).'::valide', LOG_DEBUG);
954  $result = $this->db->query($sql);
955  if ($result) {
956  return 1;
957  } else {
958  $this->error = $this->db->lasterror();
959  dol_syslog(get_class($this).'::valide '.$this->error);
960  return -1;
961  }
962  }
963 
970  public function reject(User $user = null)
971  {
972  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET statut = 2 WHERE rowid = '.((int) $this->id);
973 
974  dol_syslog(get_class($this).'::reject', LOG_DEBUG);
975  $result = $this->db->query($sql);
976  if ($result) {
977  return 1;
978  } else {
979  $this->error = $this->db->lasterror();
980  dol_syslog(get_class($this).'::reject '.$this->error);
981  return -1;
982  }
983  }
984 
991  public function info($id)
992  {
993  $sql = 'SELECT p.rowid, p.datec, p.fk_user_creat, p.fk_user_modif, p.tms';
994  $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p';
995  $sql .= ' WHERE p.rowid = '.((int) $id);
996 
997  dol_syslog(get_class($this).'::info', LOG_DEBUG);
998  $result = $this->db->query($sql);
999 
1000  if ($result) {
1001  if ($this->db->num_rows($result)) {
1002  $obj = $this->db->fetch_object($result);
1003  $this->id = $obj->rowid;
1004  if ($obj->fk_user_creat) {
1005  $cuser = new User($this->db);
1006  $cuser->fetch($obj->fk_user_creat);
1007  $this->user_creation = $cuser;
1008  }
1009  if ($obj->fk_user_modif) {
1010  $muser = new User($this->db);
1011  $muser->fetch($obj->fk_user_modif);
1012  $this->user_modification = $muser;
1013  }
1014  $this->date_creation = $this->db->jdate($obj->datec);
1015  $this->date_modification = $this->db->jdate($obj->tms);
1016  }
1017  $this->db->free($result);
1018  } else {
1019  dol_print_error($this->db);
1020  }
1021  }
1022 
1030  public function getBillsArray($filter = '')
1031  {
1032  $sql = 'SELECT pf.fk_facture';
1033  $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf, '.MAIN_DB_PREFIX.'facture as f'; // We keep link on invoice to allow use of some filters on invoice
1034  $sql .= ' WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = '.((int) $this->id);
1035  if ($filter) {
1036  $sql .= ' AND '.$filter;
1037  }
1038  $resql = $this->db->query($sql);
1039  if ($resql) {
1040  $i = 0;
1041  $num = $this->db->num_rows($resql);
1042  $billsarray = array();
1043 
1044  while ($i < $num) {
1045  $obj = $this->db->fetch_object($resql);
1046  $billsarray[$i] = $obj->fk_facture;
1047  $i++;
1048  }
1049 
1050  return $billsarray;
1051  } else {
1052  $this->error = $this->db->error();
1053  dol_syslog(get_class($this).'::getBillsArray Error '.$this->error.' -', LOG_DEBUG);
1054  return -1;
1055  }
1056  }
1057 
1064  public function getAmountsArray()
1065  {
1066  $sql = 'SELECT pf.fk_facture, pf.amount';
1067  $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
1068  $sql .= ' WHERE pf.fk_paiement = '.((int) $this->id);
1069  $resql = $this->db->query($sql);
1070  if ($resql) {
1071  $i = 0;
1072  $num = $this->db->num_rows($resql);
1073  $amounts = array();
1074 
1075  while ($i < $num) {
1076  $obj = $this->db->fetch_object($resql);
1077  $amounts[$obj->fk_facture] = $obj->amount;
1078  $i++;
1079  }
1080 
1081  return $amounts;
1082  } else {
1083  $this->error = $this->db->error();
1084  dol_syslog(get_class($this).'::getAmountsArray Error '.$this->error.' -', LOG_DEBUG);
1085  return -1;
1086  }
1087  }
1088 
1097  public function getNextNumRef($soc, $mode = 'next')
1098  {
1099  global $conf, $db, $langs;
1100  $langs->load("bills");
1101 
1102  // Clean parameters (if not defined or using deprecated value)
1103  if (empty($conf->global->PAYMENT_ADDON)) {
1104  $conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
1105  } elseif ($conf->global->PAYMENT_ADDON == 'ant') {
1106  $conf->global->PAYMENT_ADDON = 'mod_payment_ant';
1107  } elseif ($conf->global->PAYMENT_ADDON == 'cicada') {
1108  $conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
1109  }
1110 
1111  if (!empty($conf->global->PAYMENT_ADDON)) {
1112  $mybool = false;
1113 
1114  $file = $conf->global->PAYMENT_ADDON.".php";
1115  $classname = $conf->global->PAYMENT_ADDON;
1116 
1117  // Include file with class
1118  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1119 
1120  foreach ($dirmodels as $reldir) {
1121  $dir = dol_buildpath($reldir."core/modules/payment/");
1122 
1123  // Load file with numbering class (if found)
1124  if (is_file($dir.$file) && is_readable($dir.$file)) {
1125  $mybool |= include_once $dir.$file;
1126  }
1127  }
1128 
1129  // For compatibility
1130  if (!$mybool) {
1131  $file = $conf->global->PAYMENT_ADDON.".php";
1132  $classname = "mod_payment_".$conf->global->PAYMENT_ADDON;
1133  $classname = preg_replace('/\-.*$/', '', $classname);
1134  // Include file with class
1135  foreach ($conf->file->dol_document_root as $dirroot) {
1136  $dir = $dirroot."/core/modules/payment/";
1137 
1138  // Load file with numbering class (if found)
1139  if (is_file($dir.$file) && is_readable($dir.$file)) {
1140  $mybool |= include_once $dir.$file;
1141  }
1142  }
1143  }
1144 
1145  if (!$mybool) {
1146  dol_print_error('', "Failed to include file ".$file);
1147  return '';
1148  }
1149 
1150  $obj = new $classname();
1151  $numref = "";
1152  $numref = $obj->getNextValue($soc, $this);
1153 
1158  if ($mode != 'last' && !$numref) {
1159  dol_print_error($db, "Payment::getNextNumRef ".$obj->error);
1160  return "";
1161  }
1162 
1163  return $numref;
1164  } else {
1165  $langs->load("errors");
1166  print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Invoice"));
1167  return "";
1168  }
1169  }
1170 
1176  public function getWay()
1177  {
1178  global $conf;
1179 
1180  $way = 'dolibarr';
1181  if (isModEnabled('multicurrency')) {
1182  foreach ($this->multicurrency_amounts as $value) {
1183  if (!empty($value)) { // one value found then payment is in invoice currency
1184  $way = 'customer';
1185  break;
1186  }
1187  }
1188  }
1189 
1190  return $way;
1191  }
1192 
1201  public function initAsSpecimen($option = '')
1202  {
1203  global $user, $langs, $conf;
1204 
1205  $now = dol_now();
1206  $arraynow = dol_getdate($now);
1207  $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
1208 
1209  // Initialize parameters
1210  $this->id = 0;
1211  $this->ref = 'SPECIMEN';
1212  $this->specimen = 1;
1213  $this->facid = 1;
1214  $this->datepaye = $nownotime;
1215  }
1216 
1217 
1228  public function getNomUrl($withpicto = 0, $option = '', $mode = 'withlistofinvoices', $notooltip = 0, $morecss = '')
1229  {
1230  global $conf, $langs, $hookmanager;
1231 
1232  if (!empty($conf->dol_no_mouse_hover)) {
1233  $notooltip = 1; // Force disable tooltips
1234  }
1235 
1236  $result = '';
1237 
1238  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Payment").'</u><br>';
1239  $label .= '<strong>'.$langs->trans("Ref").':</strong> '.$this->ref;
1240  $dateofpayment = ($this->datepaye ? $this->datepaye : $this->date);
1241  if ($dateofpayment) {
1242  $label .= '<br><strong>'.$langs->trans("Date").':</strong> ';
1243  $tmparray = dol_getdate($dateofpayment);
1244  if ($tmparray['seconds'] == 0 && $tmparray['minutes'] == 0 && ($tmparray['hours'] == 0 || $tmparray['hours'] == 12)) { // We set hours to 0:00 or 12:00 because we don't know it
1245  $label .= dol_print_date($dateofpayment, 'day');
1246  } else { // Hours was set to real date of payment (special case for POS for example)
1247  $label .= dol_print_date($dateofpayment, 'dayhour', 'tzuser');
1248  }
1249  }
1250  if ($this->amount) {
1251  $label .= '<br><strong>'.$langs->trans("Amount").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
1252  }
1253  if ($mode == 'withlistofinvoices') {
1254  $arraybill = $this->getBillsArray();
1255  if (is_array($arraybill) && count($arraybill) > 0) {
1256  include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1257  $facturestatic = new Facture($this->db);
1258  foreach ($arraybill as $billid) {
1259  $facturestatic->fetch($billid);
1260  $label .= '<br> '.$facturestatic->getNomUrl(1, '', 0, 0, '', 1).' '.$facturestatic->getLibStatut(2, 1);
1261  }
1262  }
1263  }
1264 
1265  $linkclose = '';
1266  if (empty($notooltip)) {
1267  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1268  $label = $langs->trans("Payment");
1269  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1270  }
1271  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
1272  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
1273  } else {
1274  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1275  }
1276 
1277  $url = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$this->id;
1278 
1279  $linkstart = '<a href="'.$url.'"';
1280  $linkstart .= $linkclose.'>';
1281  $linkend = '</a>';
1282 
1283  $result .= $linkstart;
1284  if ($withpicto) {
1285  $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);
1286  }
1287  if ($withpicto && $withpicto != 2) {
1288  $result .= ($this->ref ? $this->ref : $this->id);
1289  }
1290  $result .= $linkend;
1291  global $action;
1292  $hookmanager->initHooks(array($this->element . 'dao'));
1293  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
1294  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1295  if ($reshook > 0) {
1296  $result = $hookmanager->resPrint;
1297  } else {
1298  $result .= $hookmanager->resPrint;
1299  }
1300  return $result;
1301  }
1302 
1309  public function getLibStatut($mode = 0)
1310  {
1311  return $this->LibStatut($this->statut, $mode);
1312  }
1313 
1314  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1322  public function LibStatut($status, $mode = 0)
1323  {
1324  // phpcs:enable
1325  global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage
1326 
1327  $langs->load('compta');
1328  /*if ($mode == 0)
1329  {
1330  if ($status == 0) return $langs->trans('ToValidate');
1331  if ($status == 1) return $langs->trans('Validated');
1332  }
1333  if ($mode == 1)
1334  {
1335  if ($status == 0) return $langs->trans('ToValidate');
1336  if ($status == 1) return $langs->trans('Validated');
1337  }
1338  if ($mode == 2)
1339  {
1340  if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
1341  if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
1342  }
1343  if ($mode == 3)
1344  {
1345  if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
1346  if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
1347  }
1348  if ($mode == 4)
1349  {
1350  if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
1351  if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
1352  }
1353  if ($mode == 5)
1354  {
1355  if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
1356  if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
1357  }
1358  if ($mode == 6)
1359  {
1360  if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
1361  if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
1362  }*/
1363  return '';
1364  }
1365 
1366  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1374  public function fetch_thirdparty($force_thirdparty_id = 0)
1375  {
1376  // phpcs:enable
1377  include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1378 
1379  if (empty($force_thirdparty_id)) {
1380  $billsarray = $this->getBillsArray(); // From payment, the fk_soc isn't available, we should load the first supplier invoice to get him
1381  if (!empty($billsarray)) {
1382  $invoice = new Facture($this->db);
1383  if ($invoice->fetch($billsarray[0]) > 0) {
1384  $force_thirdparty_id = $invoice->socid;
1385  }
1386  }
1387  }
1388 
1389  return parent::fetch_thirdparty($force_thirdparty_id);
1390  }
1391 }
$object ref
Definition: info.php:78
Class to manage bank accounts.
Class to manage bank transaction lines.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage absolute discounts.
Class to manage suppliers invoices.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const TYPE_STANDARD
Standard invoice.
const TYPE_SITUATION
Situation invoice.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
Class to manage payments of customer invoices.
addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque, $notrigger=0, $accountancycode='')
Add a record into bank for payment + links between this bank record and sources of payment.
__construct($db)
Constructor.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id into this->thirdparty.
create($user, $closepaidinvoices=0, $thirdparty=null)
Create payment of invoices into database.
validate(User $user=null)
Validate payment.
reject(User $user=null)
Reject payment.
getAmountsArray()
Return list of amounts of payments.
getNomUrl($withpicto=0, $option='', $mode='withlistofinvoices', $notooltip=0, $morecss='')
Return clicable name (with picto eventually)
update_num($num)
Updates the payment number.
update_fk_bank($id_bank)
Mise a jour du lien entre le paiement et la ligne generee dans llx_bank.
getWay()
get the right way of payment
valide(User $user=null)
Validate payment.
initAsSpecimen($option='')
Initialise an instance with random values.
fetch($id, $ref='', $fk_bank='')
Load payment from database.
LibStatut($status, $mode=0)
Renvoi le libelle d'un statut donne.
update_date($date)
Updates the payment date.
getNextNumRef($soc, $mode='next')
Return next reference of customer invoice not already used (or last reference) according to numbering...
getBillsArray($filter='')
Return list of invoices the payment is related to.
info($id)
Information sur l'objet.
getLibStatut($mode=0)
Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee)
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)
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