dolibarr  16.0.5
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 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  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program. If not, see <https://www.gnu.org/licenses/>.
27  */
28 
34 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
36 
37 
41 class Paiement extends CommonObject
42 {
46  public $element = 'payment';
47 
51  public $table_element = 'paiement';
52 
56  public $picto = 'payment';
57 
58  public $facid;
59  public $datepaye;
60  public $date; // same than $datepaye
61 
66  public $total;
67 
72  public $montant;
73 
74  public $amount; // Total amount of payment (in the main currency)
75  public $multicurrency_amount; // Total amount of payment (in the currency of the bank account)
76  public $amounts = array(); // array: invoice ID => amount for that invoice (in the main currency)
77  public $multicurrency_amounts = array(); // array: invoice ID => amount for that invoice (in the invoice's currency)
78  public $multicurrency_code = array(); // array: invoice ID => currency code for that invoice
79 
80  public $pos_change = 0; // Excess received in TakePOS cash payment
81 
82  public $author;
83  public $paiementid; // ID of mode of payment. Is saved into fields fk_paiement on llx_paiement = id of llx_c_paiement
84  public $paiementcode; // Code of mode of payment.
85 
89  public $type_label;
90 
94  public $type_code;
95 
101  public $num_paiement;
102 
106  public $num_payment;
107 
111  public $ext_payment_id;
112 
116  public $id_prelevement;
117 
121  public $num_prelevement;
122 
126  public $ext_payment_site;
127 
133  public $bank_account;
134 
138  public $fk_account;
139 
143  public $bank_line;
144 
145  // fk_paiement dans llx_paiement est l'id du type de paiement (7 pour CHQ, ...)
146  // fk_paiement dans llx_paiement_facture est le rowid du paiement
150  public $fk_paiement; // Type of payment
151 
155  public $ref_ext;
156 
157 
163  public function __construct($db)
164  {
165  $this->db = $db;
166  }
167 
176  public function fetch($id, $ref = '', $fk_bank = '')
177  {
178  $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,';
179  $sql .= ' c.code as type_code, c.libelle as type_label,';
180  $sql .= ' p.num_paiement as num_payment, p.note,';
181  $sql .= ' b.fk_account';
182  $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id';
183  $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
184  $sql .= ' WHERE p.entity IN ('.getEntity('invoice').')';
185  if ($id > 0) {
186  $sql .= ' AND p.rowid = '.((int) $id);
187  } elseif ($ref) {
188  $sql .= " AND p.ref = '".$this->db->escape($ref)."'";
189  } elseif ($fk_bank) {
190  $sql .= ' AND p.fk_bank = '.((int) $fk_bank);
191  }
192 
193  $resql = $this->db->query($sql);
194  if ($resql) {
195  if ($this->db->num_rows($resql)) {
196  $obj = $this->db->fetch_object($resql);
197 
198  $this->id = $obj->rowid;
199  $this->ref = $obj->ref ? $obj->ref : $obj->rowid;
200  $this->ref_ext = $obj->ref_ext;
201  $this->date = $this->db->jdate($obj->dp);
202  $this->datepaye = $this->db->jdate($obj->dp);
203  $this->num_payment = $obj->num_payment;
204  $this->montant = $obj->amount; // deprecated
205  $this->amount = $obj->amount;
206  $this->multicurrency_amount = $obj->multicurrency_amount;
207  $this->note = $obj->note;
208  $this->note_private = $obj->note;
209  $this->type_label = $obj->type_label;
210  $this->type_code = $obj->type_code;
211  $this->statut = $obj->statut;
212  $this->ext_payment_id = $obj->ext_payment_id;
213  $this->ext_payment_site = $obj->ext_payment_site;
214 
215  $this->bank_account = $obj->fk_account; // deprecated
216  $this->fk_account = $obj->fk_account;
217  $this->bank_line = $obj->fk_bank;
218 
219  $this->db->free($resql);
220  return 1;
221  } else {
222  $this->db->free($resql);
223  return 0;
224  }
225  } else {
226  dol_print_error($this->db);
227  return -1;
228  }
229  }
230 
241  public function create($user, $closepaidinvoices = 0, $thirdparty = null)
242  {
243  global $conf, $langs;
244 
245  $error = 0;
246  $way = $this->getWay(); // 'dolibarr' to use amount, 'customer' to use foreign multicurrency amount
247 
248  $now = dol_now();
249 
250  // Clean parameters
251  $totalamount = 0;
252  $totalamount_converted = 0;
253  $atleastonepaymentnotnull = 0;
254 
255  if ($way == 'dolibarr') { // Payments were entered into the column of main currency
256  $amounts = &$this->amounts;
257  $amounts_to_update = &$this->multicurrency_amounts;
258  } else { // Payments were entered into the column of foreign currency
259  $amounts = &$this->multicurrency_amounts;
260  $amounts_to_update = &$this->amounts;
261  }
262 
263  $currencyofpayment = '';
264 
265  foreach ($amounts as $key => $value) { // How payment is dispatch
266  if (empty($value)) {
267  continue;
268  }
269  // $key is id of invoice, $value is amount, $way is a 'dolibarr' if amount is in main currency, 'customer' if in foreign currency
270  $value_converted = Multicurrency::getAmountConversionFromInvoiceRate($key, $value, $way);
271  // Add controls of input validity
272  if ($value_converted === false) {
273  // We failed to find the conversion for one invoice
274  $this->error = 'FailedToFoundTheConversionRateForInvoice';
275  return -1;
276  }
277  if (empty($currencyofpayment)) {
278  $currencyofpayment = $this->multicurrency_code[$key];
279  }
280  if ($currencyofpayment != $this->multicurrency_code[$key]) {
281  // If we have invoices with different currencies in the payment, we stop here
282  $this->error = 'ErrorYouTryToPayInvoicesWithDifferentCurrenciesInSamePayment';
283  return -1;
284  }
285 
286  $totalamount_converted += $value_converted;
287  $amounts_to_update[$key] = price2num($value_converted, 'MT');
288 
289  $newvalue = price2num($value, 'MT');
290  $amounts[$key] = $newvalue;
291  $totalamount += $newvalue;
292  if (!empty($newvalue)) {
293  $atleastonepaymentnotnull++;
294  }
295  }
296 
297  if (!empty($currencyofpayment)) {
298  // We must check that the currency of invoices is the same than the currency of the bank
299  $bankaccount = new Account($this->db);
300  $bankaccount->fetch($this->fk_account);
301  $bankcurrencycode = empty($bankaccount->currency_code) ? $conf->currency : $bankaccount->currency_code;
302  if ($currencyofpayment != $bankcurrencycode && $currencyofpayment != $conf->currency && $bankcurrencycode != $conf->currency) {
303  $langs->load("errors");
304  $this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofpayment, $bankcurrencycode);
305  return -1;
306  }
307  }
308 
309 
310  $totalamount = price2num($totalamount);
311  $totalamount_converted = price2num($totalamount_converted);
312 
313  // Check parameters
314  if (empty($totalamount) && empty($atleastonepaymentnotnull)) { // We accept negative amounts for withdraw reject but not empty arrays
315  $this->errors[] = 'TotalAmountEmpty';
316  $this->error = 'TotalAmountEmpty';
317  return -1;
318  }
319 
320  dol_syslog(get_class($this)."::create insert paiement", LOG_DEBUG);
321 
322  $this->db->begin();
323 
324  $this->ref = $this->getNextNumRef(is_object($thirdparty) ? $thirdparty : '');
325 
326  if (empty($this->ref_ext)) {
327  $this->ref_ext = '';
328  }
329 
330  if ($way == 'dolibarr') {
331  $total = $totalamount;
332  $mtotal = $totalamount_converted; // Maybe use price2num with MT for the converted value
333  } else {
334  $total = $totalamount_converted; // Maybe use price2num with MT for the converted value
335  $mtotal = $totalamount;
336  }
337 
338  $num_payment = $this->num_payment;
339  $note = ($this->note_private ? $this->note_private : $this->note);
340 
341  $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)";
342  $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).", ";
343  $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).")";
344 
345  $resql = $this->db->query($sql);
346  if ($resql) {
347  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiement');
348 
349  // Insert links amount / invoices
350  foreach ($this->amounts as $key => $amount) {
351  $facid = $key;
352  if (is_numeric($amount) && $amount <> 0) {
353  $amount = price2num($amount);
354  $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount, multicurrency_amount)";
355  // TODO Add multicurrency_code and multicurrency_tx
356  $sql .= " VALUES (".((int) $facid).", ".((int) $this->id).", ".((float) $amount).", ".((float) $this->multicurrency_amounts[$key]).")";
357 
358  dol_syslog(get_class($this).'::create Amount line '.$key.' insert paiement_facture', LOG_DEBUG);
359  $resql = $this->db->query($sql);
360  if ($resql) {
361  $invoice = new Facture($this->db);
362  $invoice->fetch($facid);
363 
364  // If we want to closed payed invoices
365  if ($closepaidinvoices) {
366  $paiement = $invoice->getSommePaiement();
367  $creditnotes = $invoice->getSumCreditNotesUsed();
368  $deposits = $invoice->getSumDepositsUsed();
369  $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
370  $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
371 
372  //var_dump($invoice->total_ttc.' - '.$paiement.' -'.$creditnotes.' - '.$deposits.' - '.$remaintopay);exit;
373 
374  //Invoice types that are eligible for changing status to paid
375  $affected_types = array(
381  );
382 
383  if (!in_array($invoice->type, $affected_types)) {
384  dol_syslog("Invoice ".$facid." is not a standard, nor replacement invoice, nor credit note, nor deposit invoice, nor situation invoice. We do nothing more.");
385  } elseif ($remaintopay) {
386  dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing more.");
387  // } else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more.");
388  } else {
389  // If invoice is a down payment, we also convert down payment to discount
390  if ($invoice->type == Facture::TYPE_DEPOSIT) {
391  $amount_ht = $amount_tva = $amount_ttc = array();
392  $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
393 
394  // Insert one discount by VAT rate category
395  $discount = new DiscountAbsolute($this->db);
396  $discount->fetch('', $invoice->id);
397  if (empty($discount->id)) { // If the invoice was not yet converted into a discount (this may have been done manually before we come here)
398  $discount->description = '(DEPOSIT)';
399  $discount->fk_soc = $invoice->socid;
400  $discount->fk_facture_source = $invoice->id;
401 
402  // Loop on each vat rate
403  $i = 0;
404  foreach ($invoice->lines as $line) {
405  if ($line->total_ht != 0) { // no need to create discount if amount is null
406  $amount_ht[$line->tva_tx] += $line->total_ht;
407  $amount_tva[$line->tva_tx] += $line->total_tva;
408  $amount_ttc[$line->tva_tx] += $line->total_ttc;
409  $multicurrency_amount_ht[$line->tva_tx] += $line->multicurrency_total_ht;
410  $multicurrency_amount_tva[$line->tva_tx] += $line->multicurrency_total_tva;
411  $multicurrency_amount_ttc[$line->tva_tx] += $line->multicurrency_total_ttc;
412  $i++;
413  }
414  }
415 
416  foreach ($amount_ht as $tva_tx => $xxx) {
417  $discount->amount_ht = abs($amount_ht[$tva_tx]);
418  $discount->amount_tva = abs($amount_tva[$tva_tx]);
419  $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
420  $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
421  $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
422  $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
423  $discount->tva_tx = abs($tva_tx);
424 
425  $result = $discount->create($user);
426  if ($result < 0) {
427  $error++;
428  break;
429  }
430  }
431  }
432 
433  if ($error) {
434  $this->error = $discount->error;
435  $this->errors = $discount->errors;
436  $error++;
437  }
438  }
439 
440  // Set invoice to paid
441  if (!$error) {
442  $result = $invoice->setPaid($user, '', '');
443  if ($result < 0) {
444  $this->error = $invoice->error;
445  $this->errors = $invoice->errors;
446  $error++;
447  }
448  }
449  }
450  }
451 
452  // Regenerate documents of invoices
453  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
454  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);
455 
456  $newlang = '';
457  $outputlangs = $langs;
458  if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
459  $invoice->fetch_thirdparty();
460  $newlang = $invoice->thirdparty->default_lang;
461  }
462  if (!empty($newlang)) {
463  $outputlangs = new Translate("", $conf);
464  $outputlangs->setDefaultLang($newlang);
465  }
466 
467  $hidedetails = ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0;
468  $hidedesc = ! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0;
469  $hideref = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0;
470 
471  $ret = $invoice->fetch($facid); // Reload to get new records
472 
473  $result = $invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
474 
475  if ($result < 0) {
476  $this->error = $invoice->error;
477  $this->errors = $invoice->errors;
478  $error++;
479  }
480  }
481  } else {
482  $this->error = $this->db->lasterror();
483  $error++;
484  }
485  } else {
486  dol_syslog(get_class($this).'::Create Amount line '.$key.' not a number. We discard it.');
487  }
488  }
489 
490  if (!$error) { // All payments into $this->amounts were recorded without errors
491  // Appel des triggers
492  $result = $this->call_trigger('PAYMENT_CUSTOMER_CREATE', $user);
493  if ($result < 0) {
494  $error++;
495  }
496  // Fin appel triggers
497  }
498  } else {
499  $this->error = $this->db->lasterror();
500  $error++;
501  }
502 
503  if (!$error) {
504  $this->amount = $total;
505  $this->total = $total; // deprecated
506  $this->multicurrency_amount = $mtotal;
507  $this->db->commit();
508  return $this->id;
509  } else {
510  $this->db->rollback();
511  return -1;
512  }
513  }
514 
515 
524  public function delete($notrigger = 0)
525  {
526  global $conf, $user, $langs;
527 
528  $error = 0;
529 
530  $bank_line_id = $this->bank_line;
531 
532  $this->db->begin();
533 
534  // Verifier si paiement porte pas sur une facture classee
535  // Si c'est le cas, on refuse la suppression
536  $billsarray = $this->getBillsArray('f.fk_statut > 1');
537  if (is_array($billsarray)) {
538  if (count($billsarray)) {
539  $this->error = "ErrorDeletePaymentLinkedToAClosedInvoiceNotPossible";
540  $this->db->rollback();
541  return -1;
542  }
543  } else {
544  $this->db->rollback();
545  return -2;
546  }
547 
548  // Delete bank urls. If payment is on a conciliated line, return error.
549  if ($bank_line_id > 0) {
550  $accline = new AccountLine($this->db);
551 
552  $result = $accline->fetch($bank_line_id);
553  if ($result == 0) {
554  $accline->id = $accline->rowid = $bank_line_id; // If not found, we set artificially rowid to allow delete of llx_bank_url
555  }
556 
557  // Delete bank account url lines linked to payment
558  $result = $accline->delete_urls($user);
559  if ($result < 0) {
560  $this->error = $accline->error;
561  $this->db->rollback();
562  return -3;
563  }
564 
565  // Delete bank account lines linked to payment
566  $result = $accline->delete($user);
567  if ($result < 0) {
568  $this->error = $accline->error;
569  $this->db->rollback();
570  return -4;
571  }
572  }
573 
574  if (!$notrigger) {
575  // Call triggers
576  $result = $this->call_trigger('PAYMENT_CUSTOMER_DELETE', $user);
577  if ($result < 0) {
578  $this->db->rollback();
579  return -1;
580  }
581  // End call triggers
582  }
583 
584  // Delete payment (into paiement_facture and paiement)
585  $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement_facture';
586  $sql .= ' WHERE fk_paiement = '.((int) $this->id);
587  dol_syslog($sql);
588  $result = $this->db->query($sql);
589  if ($result) {
590  $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement';
591  $sql .= " WHERE rowid = ".((int) $this->id);
592  dol_syslog($sql);
593  $result = $this->db->query($sql);
594  if (!$result) {
595  $this->error = $this->db->lasterror();
596  $this->db->rollback();
597  return -3;
598  }
599 
600  $this->db->commit();
601  return 1;
602  } else {
603  $this->error = $this->db->error;
604  $this->db->rollback();
605  return -5;
606  }
607  }
608 
609 
624  public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque, $notrigger = 0, $accountancycode = '')
625  {
626  global $conf, $langs, $user;
627 
628  $error = 0;
629  $bank_line_id = 0;
630 
631  if (isModEnabled('banque')) {
632  if ($accountid <= 0) {
633  $this->error = 'Bad value for parameter accountid='.$accountid;
634  dol_syslog(get_class($this).'::addPaymentToBank '.$this->error, LOG_ERR);
635  return -1;
636  }
637 
638  $this->fk_account = $accountid;
639 
640  dol_syslog("addPaymentToBank ".$user->id.", ".$mode.", ".$label.", ".$this->fk_account.", ".$emetteur_nom.", ".$emetteur_banque);
641 
642  include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
643  $acc = new Account($this->db);
644  $result = $acc->fetch($this->fk_account);
645  if ($result < 0) {
646  $error++;
647  return -1;
648  }
649 
650  $this->db->begin();
651 
652  $totalamount = $this->amount;
653  $totalamount_main_currency = null;
654  if (empty($totalamount)) {
655  $totalamount = $this->total; // For backward compatibility
656  }
657 
658  // 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)
659  if (isModEnabled('multicurrency') && $conf->currency != $acc->currency_code) {
660  $totalamount = $this->multicurrency_amount; // We will insert into llx_bank.amount in foreign currency
661  $totalamount_main_currency = $this->amount; // We will also save the amount in main currency into column llx_bank.amount_main_currency
662  }
663 
664  if ($mode == 'payment_supplier') {
665  $totalamount = -$totalamount;
666  if (isset($totalamount_main_currency)) {
667  $totalamount_main_currency = -$totalamount_main_currency;
668  }
669  }
670 
671  // Insert payment into llx_bank
672  $bank_line_id = $acc->addline(
673  $this->datepaye,
674  $this->paiementcode ? $this->paiementcode : $this->paiementid, // Payment mode code ('CB', 'CHQ' or 'VIR' for example). Use payment id if not defined for backward compatibility.
675  $label,
676  $totalamount, // Sign must be positive when we receive money (customer payment), negative when you give money (supplier invoice or credit note)
677  $this->num_payment,
678  '',
679  $user,
680  $emetteur_nom,
681  $emetteur_banque,
682  $accountancycode,
683  null,
684  '',
685  $totalamount_main_currency
686  );
687 
688  // Mise a jour fk_bank dans llx_paiement
689  // On connait ainsi le paiement qui a genere l'ecriture bancaire
690  if ($bank_line_id > 0) {
691  $result = $this->update_fk_bank($bank_line_id);
692  if ($result <= 0) {
693  $error++;
694  dol_print_error($this->db);
695  }
696 
697  // Add link 'payment', 'payment_supplier' in bank_url between payment and bank transaction
698  if (!$error) {
699  $url = '';
700  if ($mode == 'payment') {
701  $url = DOL_URL_ROOT.'/compta/paiement/card.php?id=';
702  }
703  if ($mode == 'payment_supplier') {
704  $url = DOL_URL_ROOT.'/fourn/paiement/card.php?id=';
705  }
706  if ($url) {
707  $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
708  if ($result <= 0) {
709  $error++;
710  dol_print_error($this->db);
711  }
712  }
713  }
714 
715  // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
716  //if (! $error && $label != '(WithdrawalPayment)')
717  if (!$error) {
718  $linkaddedforthirdparty = array();
719  foreach ($this->amounts as $key => $value) { // We should have invoices always for same third party but we loop in case of.
720  if ($mode == 'payment') {
721  $fac = new Facture($this->db);
722  $fac->fetch($key);
723  $fac->fetch_thirdparty();
724  if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) { // Not yet done for this thirdparty
725  $result = $acc->add_url_line(
726  $bank_line_id,
727  $fac->thirdparty->id,
728  DOL_URL_ROOT.'/comm/card.php?socid=',
729  $fac->thirdparty->name,
730  'company'
731  );
732  if ($result <= 0) {
733  dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
734  }
735  $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
736  }
737  }
738  if ($mode == 'payment_supplier') {
739  $fac = new FactureFournisseur($this->db);
740  $fac->fetch($key);
741  $fac->fetch_thirdparty();
742  if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) { // Not yet done for this thirdparty
743  $result = $acc->add_url_line(
744  $bank_line_id,
745  $fac->thirdparty->id,
746  DOL_URL_ROOT.'/fourn/card.php?socid=',
747  $fac->thirdparty->name,
748  'company'
749  );
750  if ($result <= 0) {
751  dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
752  }
753  $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
754  }
755  }
756  }
757  }
758 
759  // Add link 'WithdrawalPayment' in bank_url
760  if (!$error && $label == '(WithdrawalPayment)') {
761  $result = $acc->add_url_line(
762  $bank_line_id,
763  $this->id_prelevement,
764  DOL_URL_ROOT.'/compta/prelevement/card.php?id=',
765  $this->num_payment,
766  'withdraw'
767  );
768  }
769 
770  // Add link 'InvoiceRefused' in bank_url
771  if (! $error && $label == '(InvoiceRefused)') {
772  $result=$acc->add_url_line(
773  $bank_line_id,
774  $this->id_prelevement,
775  DOL_URL_ROOT.'/compta/prelevement/card.php?id=',
776  $this->num_prelevement,
777  'withdraw'
778  );
779  }
780 
781  if (!$error && !$notrigger) {
782  // Appel des triggers
783  $result = $this->call_trigger('PAYMENT_ADD_TO_BANK', $user);
784  if ($result < 0) {
785  $error++;
786  }
787  // Fin appel triggers
788  }
789  } else {
790  $this->error = $acc->error;
791  $error++;
792  }
793 
794  if (!$error) {
795  $this->db->commit();
796  } else {
797  $this->db->rollback();
798  }
799  }
800 
801  if (!$error) {
802  return $bank_line_id;
803  } else {
804  return -1;
805  }
806  }
807 
808 
809  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
816  public function update_fk_bank($id_bank)
817  {
818  // phpcs:enable
819  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' set fk_bank = '.((int) $id_bank);
820  $sql .= " WHERE rowid = ".((int) $this->id);
821 
822  dol_syslog(get_class($this).'::update_fk_bank', LOG_DEBUG);
823  $result = $this->db->query($sql);
824  if ($result) {
825  return 1;
826  } else {
827  $this->error = $this->db->lasterror();
828  dol_syslog(get_class($this).'::update_fk_bank '.$this->error);
829  return -1;
830  }
831  }
832 
833  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
840  public function update_date($date)
841  {
842  // phpcs:enable
843  $error = 0;
844 
845  if (!empty($date) && $this->statut != 1) {
846  $this->db->begin();
847 
848  dol_syslog(get_class($this)."::update_date with date = ".$date, LOG_DEBUG);
849 
850  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
851  $sql .= " SET datep = '".$this->db->idate($date)."'";
852  $sql .= " WHERE rowid = ".((int) $this->id);
853 
854  $result = $this->db->query($sql);
855  if (!$result) {
856  $error++;
857  $this->error = 'Error -1 '.$this->db->error();
858  }
859 
860  $type = $this->element;
861 
862  $sql = "UPDATE ".MAIN_DB_PREFIX.'bank';
863  $sql .= " SET dateo = '".$this->db->idate($date)."', datev = '".$this->db->idate($date)."'";
864  $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).")";
865  $sql .= " AND rappro = 0";
866 
867  $result = $this->db->query($sql);
868  if (!$result) {
869  $error++;
870  $this->error = 'Error -1 '.$this->db->error();
871  }
872 
873  if (!$error) {
874  }
875 
876  if (!$error) {
877  $this->datepaye = $date;
878  $this->date = $date;
879 
880  $this->db->commit();
881  return 0;
882  } else {
883  $this->db->rollback();
884  return -2;
885  }
886  }
887  return -1; //no date given or already validated
888  }
889 
890  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
897  public function update_num($num)
898  {
899  // phpcs:enable
900  if (!empty($num) && $this->statut != 1) {
901  $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
902  $sql .= " SET num_paiement = '".$this->db->escape($num)."'";
903  $sql .= " WHERE rowid = ".((int) $this->id);
904 
905  dol_syslog(get_class($this)."::update_num", LOG_DEBUG);
906  $result = $this->db->query($sql);
907  if ($result) {
908  $this->num_payment = $this->db->escape($num);
909  return 0;
910  } else {
911  $this->error = 'Error -1 '.$this->db->error();
912  return -2;
913  }
914  }
915  return -1; //no num given or already validated
916  }
917 
925  public function valide(User $user = null)
926  {
927  return $this->validate($user);
928  }
929 
936  public function validate(User $user = null)
937  {
938  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET statut = 1 WHERE rowid = '.((int) $this->id);
939 
940  dol_syslog(get_class($this).'::valide', LOG_DEBUG);
941  $result = $this->db->query($sql);
942  if ($result) {
943  return 1;
944  } else {
945  $this->error = $this->db->lasterror();
946  dol_syslog(get_class($this).'::valide '.$this->error);
947  return -1;
948  }
949  }
950 
957  public function reject(User $user = null)
958  {
959  $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET statut = 2 WHERE rowid = '.((int) $this->id);
960 
961  dol_syslog(get_class($this).'::reject', LOG_DEBUG);
962  $result = $this->db->query($sql);
963  if ($result) {
964  return 1;
965  } else {
966  $this->error = $this->db->lasterror();
967  dol_syslog(get_class($this).'::reject '.$this->error);
968  return -1;
969  }
970  }
971 
978  public function info($id)
979  {
980  $sql = 'SELECT p.rowid, p.datec, p.fk_user_creat, p.fk_user_modif, p.tms';
981  $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p';
982  $sql .= ' WHERE p.rowid = '.((int) $id);
983 
984  dol_syslog(get_class($this).'::info', LOG_DEBUG);
985  $result = $this->db->query($sql);
986 
987  if ($result) {
988  if ($this->db->num_rows($result)) {
989  $obj = $this->db->fetch_object($result);
990  $this->id = $obj->rowid;
991  if ($obj->fk_user_creat) {
992  $cuser = new User($this->db);
993  $cuser->fetch($obj->fk_user_creat);
994  $this->user_creation = $cuser;
995  }
996  if ($obj->fk_user_modif) {
997  $muser = new User($this->db);
998  $muser->fetch($obj->fk_user_modif);
999  $this->user_modification = $muser;
1000  }
1001  $this->date_creation = $this->db->jdate($obj->datec);
1002  $this->date_modification = $this->db->jdate($obj->tms);
1003  }
1004  $this->db->free($result);
1005  } else {
1006  dol_print_error($this->db);
1007  }
1008  }
1009 
1017  public function getBillsArray($filter = '')
1018  {
1019  $sql = 'SELECT pf.fk_facture';
1020  $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
1021  $sql .= ' WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = '.((int) $this->id);
1022  if ($filter) {
1023  $sql .= ' AND '.$filter;
1024  }
1025  $resql = $this->db->query($sql);
1026  if ($resql) {
1027  $i = 0;
1028  $num = $this->db->num_rows($resql);
1029  $billsarray = array();
1030 
1031  while ($i < $num) {
1032  $obj = $this->db->fetch_object($resql);
1033  $billsarray[$i] = $obj->fk_facture;
1034  $i++;
1035  }
1036 
1037  return $billsarray;
1038  } else {
1039  $this->error = $this->db->error();
1040  dol_syslog(get_class($this).'::getBillsArray Error '.$this->error.' -', LOG_DEBUG);
1041  return -1;
1042  }
1043  }
1044 
1051  public function getAmountsArray()
1052  {
1053  $sql = 'SELECT pf.fk_facture, pf.amount';
1054  $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
1055  $sql .= ' WHERE pf.fk_paiement = '.((int) $this->id);
1056  $resql = $this->db->query($sql);
1057  if ($resql) {
1058  $i = 0;
1059  $num = $this->db->num_rows($resql);
1060  $amounts = array();
1061 
1062  while ($i < $num) {
1063  $obj = $this->db->fetch_object($resql);
1064  $amounts[$obj->fk_facture] = $obj->amount;
1065  $i++;
1066  }
1067 
1068  return $amounts;
1069  } else {
1070  $this->error = $this->db->error();
1071  dol_syslog(get_class($this).'::getAmountsArray Error '.$this->error.' -', LOG_DEBUG);
1072  return -1;
1073  }
1074  }
1075 
1084  public function getNextNumRef($soc, $mode = 'next')
1085  {
1086  global $conf, $db, $langs;
1087  $langs->load("bills");
1088 
1089  // Clean parameters (if not defined or using deprecated value)
1090  if (empty($conf->global->PAYMENT_ADDON)) {
1091  $conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
1092  } elseif ($conf->global->PAYMENT_ADDON == 'ant') {
1093  $conf->global->PAYMENT_ADDON = 'mod_payment_ant';
1094  } elseif ($conf->global->PAYMENT_ADDON == 'cicada') {
1095  $conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
1096  }
1097 
1098  if (!empty($conf->global->PAYMENT_ADDON)) {
1099  $mybool = false;
1100 
1101  $file = $conf->global->PAYMENT_ADDON.".php";
1102  $classname = $conf->global->PAYMENT_ADDON;
1103 
1104  // Include file with class
1105  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1106 
1107  foreach ($dirmodels as $reldir) {
1108  $dir = dol_buildpath($reldir."core/modules/payment/");
1109 
1110  // Load file with numbering class (if found)
1111  if (is_file($dir.$file) && is_readable($dir.$file)) {
1112  $mybool |= include_once $dir.$file;
1113  }
1114  }
1115 
1116  // For compatibility
1117  if (!$mybool) {
1118  $file = $conf->global->PAYMENT_ADDON.".php";
1119  $classname = "mod_payment_".$conf->global->PAYMENT_ADDON;
1120  $classname = preg_replace('/\-.*$/', '', $classname);
1121  // Include file with class
1122  foreach ($conf->file->dol_document_root as $dirroot) {
1123  $dir = $dirroot."/core/modules/payment/";
1124 
1125  // Load file with numbering class (if found)
1126  if (is_file($dir.$file) && is_readable($dir.$file)) {
1127  $mybool |= include_once $dir.$file;
1128  }
1129  }
1130  }
1131 
1132  if (!$mybool) {
1133  dol_print_error('', "Failed to include file ".$file);
1134  return '';
1135  }
1136 
1137  $obj = new $classname();
1138  $numref = "";
1139  $numref = $obj->getNextValue($soc, $this);
1140 
1145  if ($mode != 'last' && !$numref) {
1146  dol_print_error($db, "Payment::getNextNumRef ".$obj->error);
1147  return "";
1148  }
1149 
1150  return $numref;
1151  } else {
1152  $langs->load("errors");
1153  print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Invoice"));
1154  return "";
1155  }
1156  }
1157 
1163  public function getWay()
1164  {
1165  global $conf;
1166 
1167  $way = 'dolibarr';
1168  if (isModEnabled('multicurrency')) {
1169  foreach ($this->multicurrency_amounts as $value) {
1170  if (!empty($value)) { // one value found then payment is in invoice currency
1171  $way = 'customer';
1172  break;
1173  }
1174  }
1175  }
1176 
1177  return $way;
1178  }
1179 
1188  public function initAsSpecimen($option = '')
1189  {
1190  global $user, $langs, $conf;
1191 
1192  $now = dol_now();
1193  $arraynow = dol_getdate($now);
1194  $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
1195 
1196  // Initialize parameters
1197  $this->id = 0;
1198  $this->ref = 'SPECIMEN';
1199  $this->specimen = 1;
1200  $this->facid = 1;
1201  $this->datepaye = $nownotime;
1202  }
1203 
1204 
1215  public function getNomUrl($withpicto = 0, $option = '', $mode = 'withlistofinvoices', $notooltip = 0, $morecss = '')
1216  {
1217  global $conf, $langs, $hookmanager;
1218 
1219  if (!empty($conf->dol_no_mouse_hover)) {
1220  $notooltip = 1; // Force disable tooltips
1221  }
1222 
1223  $result = '';
1224 
1225  $label = img_picto('', $this->picto).' <u>'.$langs->trans("Payment").'</u><br>';
1226  $label .= '<strong>'.$langs->trans("Ref").':</strong> '.$this->ref;
1227  $dateofpayment = ($this->datepaye ? $this->datepaye : $this->date);
1228  if ($dateofpayment) {
1229  $label .= '<br><strong>'.$langs->trans("Date").':</strong> ';
1230  $tmparray = dol_getdate($dateofpayment);
1231  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
1232  $label .= dol_print_date($dateofpayment, 'day');
1233  } else { // Hours was set to real date of payment (special case for POS for example)
1234  $label .= dol_print_date($dateofpayment, 'dayhour', 'tzuser');
1235  }
1236  }
1237  if ($this->amount) {
1238  $label .= '<br><strong>'.$langs->trans("Amount").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
1239  }
1240  if ($mode == 'withlistofinvoices') {
1241  $arraybill = $this->getBillsArray();
1242  if (is_array($arraybill) && count($arraybill) > 0) {
1243  include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1244  $facturestatic = new Facture($this->db);
1245  foreach ($arraybill as $billid) {
1246  $facturestatic->fetch($billid);
1247  $label .= '<br> '.$facturestatic->getNomUrl(1, '', 0, 0, '', 1).' '.$facturestatic->getLibStatut(2, 1);
1248  }
1249  }
1250  }
1251 
1252  $linkclose = '';
1253  if (empty($notooltip)) {
1254  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1255  $label = $langs->trans("Payment");
1256  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1257  }
1258  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
1259  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
1260  } else {
1261  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1262  }
1263 
1264  $url = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$this->id;
1265 
1266  $linkstart = '<a href="'.$url.'"';
1267  $linkstart .= $linkclose.'>';
1268  $linkend = '</a>';
1269 
1270  $result .= $linkstart;
1271  if ($withpicto) {
1272  $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);
1273  }
1274  if ($withpicto && $withpicto != 2) {
1275  $result .= ($this->ref ? $this->ref : $this->id);
1276  }
1277  $result .= $linkend;
1278  global $action;
1279  $hookmanager->initHooks(array($this->element . 'dao'));
1280  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
1281  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1282  if ($reshook > 0) {
1283  $result = $hookmanager->resPrint;
1284  } else {
1285  $result .= $hookmanager->resPrint;
1286  }
1287  return $result;
1288  }
1289 
1296  public function getLibStatut($mode = 0)
1297  {
1298  return $this->LibStatut($this->statut, $mode);
1299  }
1300 
1301  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1309  public function LibStatut($status, $mode = 0)
1310  {
1311  // phpcs:enable
1312  global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage
1313 
1314  $langs->load('compta');
1315  /*if ($mode == 0)
1316  {
1317  if ($status == 0) return $langs->trans('ToValidate');
1318  if ($status == 1) return $langs->trans('Validated');
1319  }
1320  if ($mode == 1)
1321  {
1322  if ($status == 0) return $langs->trans('ToValidate');
1323  if ($status == 1) return $langs->trans('Validated');
1324  }
1325  if ($mode == 2)
1326  {
1327  if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
1328  if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
1329  }
1330  if ($mode == 3)
1331  {
1332  if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
1333  if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
1334  }
1335  if ($mode == 4)
1336  {
1337  if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
1338  if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
1339  }
1340  if ($mode == 5)
1341  {
1342  if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
1343  if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
1344  }
1345  if ($mode == 6)
1346  {
1347  if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
1348  if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
1349  }*/
1350  return '';
1351  }
1352 
1353  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1361  public function fetch_thirdparty($force_thirdparty_id = 0)
1362  {
1363  // phpcs:enable
1364  include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1365 
1366  if (empty($force_thirdparty_id)) {
1367  $billsarray = $this->getBillsArray(); // From payment, the fk_soc isn't available, we should load the first supplier invoice to get him
1368  if (!empty($billsarray)) {
1369  $invoice = new Facture($this->db);
1370  if ($invoice->fetch($billsarray[0]) > 0) {
1371  $force_thirdparty_id = $invoice->socid;
1372  }
1373  }
1374  }
1375 
1376  return parent::fetch_thirdparty($force_thirdparty_id);
1377  }
1378 }
Paiement\$montant
$montant
Definition: paiement.class.php:72
dol_getdate
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Definition: functions.lib.php:2713
Paiement\update_num
update_num($num)
Updates the payment number.
Definition: paiement.class.php:897
Paiement\valide
valide(User $user=null)
Validate payment.
Definition: paiement.class.php:925
db
$conf db
API class for accounts.
Definition: inc.php:41
Paiement\getBillsArray
getBillsArray($filter='')
Return list of invoices the payment is related to.
Definition: paiement.class.php:1017
Paiement\getWay
getWay()
get the right way of payment
Definition: paiement.class.php:1163
Paiement\reject
reject(User $user=null)
Reject payment.
Definition: paiement.class.php:957
Paiement\info
info($id)
Information sur l'objet.
Definition: paiement.class.php:978
Paiement\update_date
update_date($date)
Updates the payment date.
Definition: paiement.class.php:840
FactureFournisseur
Class to manage suppliers invoices.
Definition: fournisseur.facture.class.php:53
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
Paiement\getNomUrl
getNomUrl($withpicto=0, $option='', $mode='withlistofinvoices', $notooltip=0, $morecss='')
Return clicable name (with picto eventually)
Definition: paiement.class.php:1215
ref
$object ref
Definition: info.php:77
Facture
Class to manage invoices.
Definition: facture.class.php:60
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:44
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
Facture\TYPE_DEPOSIT
const TYPE_DEPOSIT
Deposit invoice.
Definition: facture.class.php:397
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
Paiement\create
create($user, $closepaidinvoices=0, $thirdparty=null)
Create payment of invoices into database.
Definition: paiement.class.php:241
Facture\TYPE_REPLACEMENT
const TYPE_REPLACEMENT
Replacement invoice.
Definition: facture.class.php:387
Paiement\addPaymentToBank
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.
Definition: paiement.class.php:624
Paiement\getLibStatut
getLibStatut($mode=0)
Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee)
Definition: paiement.class.php:1296
Paiement\__construct
__construct($db)
Constructor.
Definition: paiement.class.php:163
Paiement\LibStatut
LibStatut($status, $mode=0)
Renvoi le libelle d'un statut donne.
Definition: paiement.class.php:1309
Paiement\validate
validate(User $user=null)
Validate payment.
Definition: paiement.class.php:936
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
Paiement\getNextNumRef
getNextNumRef($soc, $mode='next')
Return next reference of customer invoice not already used (or last reference) according to numbering...
Definition: paiement.class.php:1084
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
Facture\TYPE_CREDIT_NOTE
const TYPE_CREDIT_NOTE
Credit note invoice.
Definition: facture.class.php:392
User
Class to manage Dolibarr users.
Definition: user.class.php:44
Paiement
Class to manage payments of customer invoices.
Definition: paiement.class.php:41
Paiement\getAmountsArray
getAmountsArray()
Return list of amounts of payments.
Definition: paiement.class.php:1051
Paiement\update_fk_bank
update_fk_bank($id_bank)
Mise a jour du lien entre le paiement et la ligne generee dans llx_bank.
Definition: paiement.class.php:816
Facture\TYPE_STANDARD
const TYPE_STANDARD
Standard invoice.
Definition: facture.class.php:382
Paiement\fetch
fetch($id, $ref='', $fk_bank='')
Load payment from database.
Definition: paiement.class.php:176
CommonObject\$note
$note
Definition: commonobject.class.php:444
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
Paiement\fetch_thirdparty
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id into this->thirdparty.
Definition: paiement.class.php:1361
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5791
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
Facture\TYPE_SITUATION
const TYPE_SITUATION
Situation invoice.
Definition: facture.class.php:407
Paiement\initAsSpecimen
initAsSpecimen($option='')
Initialise an instance with random values.
Definition: paiement.class.php:1188
Account
Class to manage bank accounts.
Definition: account.class.php:38
float
div float
Buy price without taxes.
Definition: style.css.php:809