dolibarr 18.0.6
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 * Copyright (C) 2023 Sylvain Legrand <technique@infras.fr>
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 3 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <https://www.gnu.org/licenses/>.
29 */
30
36require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
37require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
38
39
44{
48 public $element = 'payment';
49
53 public $table_element = 'paiement';
54
58 public $picto = 'payment';
59
60 public $facid;
61 public $datepaye;
62 public $date; // same than $datepaye
63
68 public $total;
69
74 public $montant;
75
76 public $amount; // Total amount of payment (in the main currency)
77 public $multicurrency_amount; // Total amount of payment (in the currency of the bank account)
78 public $amounts = array(); // array: invoice ID => amount for that invoice (in the main currency)
79 public $multicurrency_amounts = array(); // array: invoice ID => amount for that invoice (in the invoice's currency)
80 public $multicurrency_tx = array(); // array: invoice ID => currency tx for that invoice
81 public $multicurrency_code = array(); // array: invoice ID => currency code for that invoice
82
83 public $pos_change = 0; // Excess received in TakePOS cash payment
84
85 public $author;
86 public $paiementid; // ID of mode of payment. Is saved into fields fk_paiement on llx_paiement = id of llx_c_paiement
87 public $paiementcode; // Code of mode of payment.
88
92 public $type_label;
93
97 public $type_code;
98
104 public $num_paiement;
105
109 public $num_payment;
110
114 public $ext_payment_id;
115
119 public $id_prelevement;
120
124 public $num_prelevement;
125
129 public $ext_payment_site;
130
136 public $bank_account;
137
141 public $fk_account;
142
146 public $bank_line;
147
148 // fk_paiement dans llx_paiement est l'id du type de paiement (7 pour CHQ, ...)
149 // fk_paiement dans llx_paiement_facture est le rowid du paiement
153 public $fk_paiement; // Type of payment
154
158 public $ref_ext;
159
160
166 public function __construct($db)
167 {
168 $this->db = $db;
169 }
170
179 public function fetch($id, $ref = '', $fk_bank = '')
180 {
181 $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,';
182 $sql .= ' c.code as type_code, c.libelle as type_label,';
183 $sql .= ' p.num_paiement as num_payment, p.note,';
184 $sql .= ' b.fk_account';
185 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id';
186 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
187 $sql .= ' WHERE p.entity IN ('.getEntity('invoice').')';
188 if ($id > 0) {
189 $sql .= ' AND p.rowid = '.((int) $id);
190 } elseif ($ref) {
191 $sql .= " AND p.ref = '".$this->db->escape($ref)."'";
192 } elseif ($fk_bank) {
193 $sql .= ' AND p.fk_bank = '.((int) $fk_bank);
194 }
195
196 $resql = $this->db->query($sql);
197 if ($resql) {
198 if ($this->db->num_rows($resql)) {
199 $obj = $this->db->fetch_object($resql);
200
201 $this->id = $obj->rowid;
202 $this->ref = $obj->ref ? $obj->ref : $obj->rowid;
203 $this->ref_ext = $obj->ref_ext;
204 $this->date = $this->db->jdate($obj->dp);
205 $this->datepaye = $this->db->jdate($obj->dp);
206 $this->num_payment = $obj->num_payment;
207 $this->montant = $obj->amount; // deprecated
208 $this->amount = $obj->amount;
209 $this->multicurrency_amount = $obj->multicurrency_amount;
210 $this->note = $obj->note;
211 $this->note_private = $obj->note;
212 $this->type_label = $obj->type_label;
213 $this->type_code = $obj->type_code;
214 $this->statut = $obj->statut;
215 $this->ext_payment_id = $obj->ext_payment_id;
216 $this->ext_payment_site = $obj->ext_payment_site;
217
218 $this->bank_account = $obj->fk_account; // deprecated
219 $this->fk_account = $obj->fk_account;
220 $this->bank_line = $obj->fk_bank;
221
222 $this->db->free($resql);
223 return 1;
224 } else {
225 $this->db->free($resql);
226 return 0;
227 }
228 } else {
229 dol_print_error($this->db);
230 return -1;
231 }
232 }
233
244 public function create($user, $closepaidinvoices = 0, $thirdparty = null)
245 {
246 global $conf, $langs;
247
248 $error = 0;
249 $way = $this->getWay(); // 'dolibarr' to use amount, 'customer' to use foreign multicurrency amount
250
251 $now = dol_now();
252
253 // Clean parameters
254 $totalamount = 0;
255 $totalamount_converted = 0;
256 $atleastonepaymentnotnull = 0;
257
258 if ($way == 'dolibarr') { // Payments were entered into the column of main currency
259 $amounts = &$this->amounts;
260 $amounts_to_update = &$this->multicurrency_amounts;
261 } else { // Payments were entered into the column of foreign currency
262 $amounts = &$this->multicurrency_amounts;
263 $amounts_to_update = &$this->amounts;
264 }
265
266 $currencyofpayment = '';
267 $currencytxofpayment = '';
268
269 foreach ($amounts as $key => $value) { // How payment is dispatched
270 if (empty($value)) {
271 continue;
272 }
273 // $key is id of invoice, $value is amount, $way is a 'dolibarr' if amount is in main currency, 'customer' if in foreign currency
274 $value_converted = MultiCurrency::getAmountConversionFromInvoiceRate($key, $value, $way);
275 // Add controls of input validity
276 if ($value_converted === false) {
277 // We failed to find the conversion for one invoice
278 $this->error = $langs->trans('FailedToFoundTheConversionRateForInvoice');
279 return -1;
280 }
281 if (empty($currencyofpayment)) {
282 $currencyofpayment = isset($this->multicurrency_code[$key]) ? $this->multicurrency_code[$key] : "";
283 } elseif ($currencyofpayment != $this->multicurrency_code[$key]) {
284 // If we have invoices with different currencies in the payment, we stop here
285 $this->error = 'ErrorYouTryToPayInvoicesWithDifferentCurrenciesInSamePayment';
286 return -1;
287 }
288 if (empty($currencytxofpayment)) {
289 $currencytxofpayment = isset($this->multicurrency_tx[$key]) ? $this->multicurrency_tx[$key] : "";
290 }
291
292 $totalamount_converted += $value_converted;
293 $amounts_to_update[$key] = price2num($value_converted, 'MT');
294
295 $newvalue = price2num($value, 'MT');
296 $amounts[$key] = $newvalue;
297 $totalamount += $newvalue;
298 if (!empty($newvalue)) {
299 $atleastonepaymentnotnull++;
300 }
301 }
302
303 if (empty($currencyofpayment)) { // Should not happen. For the case the multicurrency_code was not saved into invoices
304 $currencyofpayment = $conf->currency;
305 }
306
307 if (!empty($currencyofpayment)) {
308 // We must check that the currency of invoices is the same than the currency of the bank
309 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
310 $bankaccount = new Account($this->db);
311 $bankaccount->fetch($this->fk_account);
312 $bankcurrencycode = empty($bankaccount->currency_code) ? $conf->currency : $bankaccount->currency_code;
313 if ($currencyofpayment != $bankcurrencycode && $currencyofpayment != $conf->currency && $bankcurrencycode != $conf->currency) {
314 $langs->load("errors");
315 $this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofpayment, $bankcurrencycode);
316 return -1;
317 }
318 }
319
320
321 $totalamount = price2num($totalamount);
322 $totalamount_converted = price2num($totalamount_converted);
323
324 // Check parameters
325 if (empty($totalamount) && empty($atleastonepaymentnotnull)) { // We accept negative amounts for withdraw reject but not empty arrays
326 $this->errors[] = 'TotalAmountEmpty';
327 $this->error = $langs->trans('TotalAmountEmpty');
328 return -1;
329 }
330
331 dol_syslog(get_class($this)."::create insert paiement", LOG_DEBUG);
332
333 $this->db->begin();
334
335 $this->ref = $this->getNextNumRef(is_object($thirdparty) ? $thirdparty : '');
336
337 if (empty($this->ref_ext)) {
338 $this->ref_ext = '';
339 }
340
341 if ($way == 'dolibarr') {
342 $total = $totalamount;
343 $mtotal = $totalamount_converted; // Maybe use price2num with MT for the converted value
344 } else {
345 $total = $totalamount_converted; // Maybe use price2num with MT for the converted value
346 $mtotal = $totalamount;
347 }
348
349 $num_payment = $this->num_payment;
350 $note = ($this->note_private ? $this->note_private : $this->note);
351
352 $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)";
353 $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).", ";
354 $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).")";
355
356 $resql = $this->db->query($sql);
357 if ($resql) {
358 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiement');
359
360 // Insert links amount / invoices
361 foreach ($this->amounts as $key => $amount) {
362 $facid = $key;
363 if (is_numeric($amount) && $amount <> 0) {
364 $amount = price2num($amount);
365 $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount, multicurrency_amount, multicurrency_code, multicurrency_tx)";
366 $sql .= " VALUES (".((int) $facid).", ".((int) $this->id).", ".((float) $amount).", ".((float) $this->multicurrency_amounts[$key]).", ".($currencyofpayment ? "'".$this->db->escape($currencyofpayment)."'" : 'NULL').", ".(!empty($this->multicurrency_tx) ? (double) $currencytxofpayment : 1).")";
367
368 dol_syslog(get_class($this).'::create Amount line '.$key.' insert paiement_facture', LOG_DEBUG);
369 $resql = $this->db->query($sql);
370 if ($resql) {
371 $invoice = new Facture($this->db);
372 $invoice->fetch($facid);
373
374 // If we want to closed payed invoices
375 if ($closepaidinvoices) {
376 $paiement = $invoice->getSommePaiement();
377 $creditnotes = $invoice->getSumCreditNotesUsed();
378 $deposits = $invoice->getSumDepositsUsed();
379 $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
380 $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
381
382 //var_dump($invoice->total_ttc.' - '.$paiement.' -'.$creditnotes.' - '.$deposits.' - '.$remaintopay);exit;
383
384 //Invoice types that are eligible for changing status to paid
385 $affected_types = array(
391 );
392
393 if (!in_array($invoice->type, $affected_types)) {
394 dol_syslog("Invoice ".$facid." is not a standard, nor replacement invoice, nor credit note, nor deposit invoice, nor situation invoice. We do nothing more.");
395 } elseif ($remaintopay) {
396 // hook to have an option to automatically close a closable invoice with less payment than the total amount (e.g. agreed cash discount terms)
397 global $hookmanager;
398 $hookmanager->initHooks(array('paymentdao'));
399 $parameters = array('facid' => $facid, 'invoice' => $invoice, 'remaintopay' => $remaintopay);
400 $action = 'CLOSEPAIDINVOICE';
401 $reshook = $hookmanager->executeHooks('createPayment', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
402 if ($reshook < 0) {
403 $this->errors[] = $hookmanager->error;
404 $this->error = $hookmanager->error;
405 $error++;
406 } elseif ($reshook == 0) {
407 dol_syslog("Remain to pay for invoice " . $facid . " not null. We do nothing more.");
408 }
409 // } else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more.");
410 } else {
411 // If invoice is a down payment, we also convert down payment to discount
412 if ($invoice->type == Facture::TYPE_DEPOSIT) {
413 $amount_ht = $amount_tva = $amount_ttc = array();
414 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
415
416 // Insert one discount by VAT rate category
417 $discount = new DiscountAbsolute($this->db);
418 $discount->fetch('', $invoice->id);
419 if (empty($discount->id)) { // If the invoice was not yet converted into a discount (this may have been done manually before we come here)
420 $discount->description = '(DEPOSIT)';
421 $discount->fk_soc = $invoice->socid;
422 $discount->fk_facture_source = $invoice->id;
423
424 // Loop on each vat rate
425 $i = 0;
426 foreach ($invoice->lines as $line) {
427 if ($line->total_ht != 0) { // no need to create discount if amount is null
428 $amount_ht[$line->tva_tx] += $line->total_ht;
429 $amount_tva[$line->tva_tx] += $line->total_tva;
430 $amount_ttc[$line->tva_tx] += $line->total_ttc;
431 $multicurrency_amount_ht[$line->tva_tx] += $line->multicurrency_total_ht;
432 $multicurrency_amount_tva[$line->tva_tx] += $line->multicurrency_total_tva;
433 $multicurrency_amount_ttc[$line->tva_tx] += $line->multicurrency_total_ttc;
434 $i++;
435 }
436 }
437
438 foreach ($amount_ht as $tva_tx => $xxx) {
439 $discount->amount_ht = abs($amount_ht[$tva_tx]);
440 $discount->amount_tva = abs($amount_tva[$tva_tx]);
441 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
442 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
443 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
444 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
445 $discount->tva_tx = abs($tva_tx);
446
447 $result = $discount->create($user);
448 if ($result < 0) {
449 $error++;
450 break;
451 }
452 }
453 }
454
455 if ($error) {
456 $this->error = $discount->error;
457 $this->errors = $discount->errors;
458 $error++;
459 }
460 }
461
462 // Set invoice to paid
463 if (!$error) {
464 $result = $invoice->setPaid($user, '', '');
465 if ($result < 0) {
466 $this->error = $invoice->error;
467 $this->errors = $invoice->errors;
468 $error++;
469 }
470 }
471 }
472 }
473
474 // Regenerate documents of invoices
475 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
476 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);
477
478 $newlang = '';
479 $outputlangs = $langs;
480 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
481 $invoice->fetch_thirdparty();
482 $newlang = $invoice->thirdparty->default_lang;
483 }
484 if (!empty($newlang)) {
485 $outputlangs = new Translate("", $conf);
486 $outputlangs->setDefaultLang($newlang);
487 }
488
489 $hidedetails = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0;
490 $hidedesc = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0;
491 $hideref = !empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0;
492
493 $ret = $invoice->fetch($facid); // Reload to get new records
494
495 $result = $invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
496
497 if ($result < 0) {
498 $this->error = $invoice->error;
499 $this->errors = $invoice->errors;
500 $error++;
501 }
502 }
503 } else {
504 $this->error = $this->db->lasterror();
505 $error++;
506 }
507 } else {
508 dol_syslog(get_class($this).'::Create Amount line '.$key.' not a number. We discard it.');
509 }
510 }
511
512 if (!$error) { // All payments into $this->amounts were recorded without errors
513 // Appel des triggers
514 $result = $this->call_trigger('PAYMENT_CUSTOMER_CREATE', $user);
515 if ($result < 0) {
516 $error++;
517 }
518 // Fin appel triggers
519 }
520 } else {
521 $this->error = $this->db->lasterror();
522 $error++;
523 }
524
525 if (!$error) {
526 $this->amount = $total;
527 $this->total = $total; // deprecated
528 $this->multicurrency_amount = $mtotal;
529 $this->db->commit();
530 return $this->id;
531 } else {
532 $this->db->rollback();
533 return -1;
534 }
535 }
536
537
546 public function delete($notrigger = 0)
547 {
548 global $conf, $user, $langs;
549
550 $error = 0;
551
552 $bank_line_id = $this->bank_line;
553
554 $this->db->begin();
555
556 // Verifier si paiement porte pas sur une facture classee
557 // Si c'est le cas, on refuse la suppression
558 $billsarray = $this->getBillsArray('f.fk_statut > 1');
559 if (is_array($billsarray)) {
560 if (count($billsarray)) {
561 $this->error = "ErrorDeletePaymentLinkedToAClosedInvoiceNotPossible";
562 $this->db->rollback();
563 return -1;
564 }
565 } else {
566 $this->db->rollback();
567 return -2;
568 }
569
570 // Delete bank urls. If payment is on a conciliated line, return error.
571 if ($bank_line_id > 0) {
572 $accline = new AccountLine($this->db);
573
574 $result = $accline->fetch($bank_line_id);
575 if ($result == 0) {
576 $accline->id = $accline->rowid = $bank_line_id; // If not found, we set artificially rowid to allow delete of llx_bank_url
577 }
578
579 // Delete bank account url lines linked to payment
580 $result = $accline->delete_urls($user);
581 if ($result < 0) {
582 $this->error = $accline->error;
583 $this->db->rollback();
584 return -3;
585 }
586
587 // Delete bank account lines linked to payment
588 $result = $accline->delete($user);
589 if ($result < 0) {
590 $this->error = $accline->error;
591 $this->db->rollback();
592 return -4;
593 }
594 }
595
596 if (!$notrigger) {
597 // Call triggers
598 $result = $this->call_trigger('PAYMENT_CUSTOMER_DELETE', $user);
599 if ($result < 0) {
600 $this->db->rollback();
601 return -1;
602 }
603 // End call triggers
604 }
605
606 // Delete payment (into paiement_facture and paiement)
607 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement_facture';
608 $sql .= ' WHERE fk_paiement = '.((int) $this->id);
609 dol_syslog($sql);
610 $result = $this->db->query($sql);
611 if ($result) {
612 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement';
613 $sql .= " WHERE rowid = ".((int) $this->id);
614 dol_syslog($sql);
615 $result = $this->db->query($sql);
616 if (!$result) {
617 $this->error = $this->db->lasterror();
618 $this->db->rollback();
619 return -3;
620 }
621
622 $this->db->commit();
623 return 1;
624 } else {
625 $this->error = $this->db->error;
626 $this->db->rollback();
627 return -5;
628 }
629 }
630
631
646 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque, $notrigger = 0, $accountancycode = '')
647 {
648 global $conf, $langs, $user;
649
650 $error = 0;
651 $bank_line_id = 0;
652
653 if (isModEnabled("banque")) {
654 if ($accountid <= 0) {
655 $this->error = 'Bad value for parameter accountid='.$accountid;
656 dol_syslog(get_class($this).'::addPaymentToBank '.$this->error, LOG_ERR);
657 return -1;
658 }
659
660 $this->fk_account = $accountid;
661
662 dol_syslog("addPaymentToBank ".$user->id.", ".$mode.", ".$label.", ".$this->fk_account.", ".$emetteur_nom.", ".$emetteur_banque);
663
664 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
665 $acc = new Account($this->db);
666 $result = $acc->fetch($this->fk_account);
667 if ($result < 0) {
668 $this->error = $acc->error;
669 $this->errors = $acc->errors;
670 $error++;
671 return -1;
672 }
673
674 $this->db->begin();
675
676 $totalamount = $this->amount;
677 $totalamount_main_currency = null;
678 if (empty($totalamount)) {
679 $totalamount = $this->total; // For backward compatibility
680 }
681
682 // 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)
683 if (isModEnabled('multicurrency') && $conf->currency != $acc->currency_code) {
684 $totalamount = $this->multicurrency_amount; // We will insert into llx_bank.amount in foreign currency
685 $totalamount_main_currency = $this->amount; // We will also save the amount in main currency into column llx_bank.amount_main_currency
686 }
687
688 if ($mode == 'payment_supplier') {
689 $totalamount = -$totalamount;
690 if (isset($totalamount_main_currency)) {
691 $totalamount_main_currency = -$totalamount_main_currency;
692 }
693 }
694
695 // Insert payment into llx_bank
696 $bank_line_id = $acc->addline(
697 $this->datepaye,
698 $this->paiementcode ? $this->paiementcode : $this->paiementid, // Payment mode code ('CB', 'CHQ' or 'VIR' for example). Use payment id if not defined for backward compatibility.
699 $label,
700 $totalamount, // Sign must be positive when we receive money (customer payment), negative when you give money (supplier invoice or credit note)
701 $this->num_payment,
702 '',
703 $user,
704 $emetteur_nom,
705 $emetteur_banque,
706 $accountancycode,
707 null,
708 '',
709 $totalamount_main_currency
710 );
711
712 // Mise a jour fk_bank dans llx_paiement
713 // On connait ainsi le paiement qui a genere l'ecriture bancaire
714 if ($bank_line_id > 0) {
715 $result = $this->update_fk_bank($bank_line_id);
716 if ($result <= 0) {
717 $error++;
718 dol_print_error($this->db);
719 }
720
721 // Add link 'payment', 'payment_supplier' in bank_url between payment and bank transaction
722 if (!$error) {
723 $url = '';
724 if ($mode == 'payment') {
725 $url = DOL_URL_ROOT.'/compta/paiement/card.php?id=';
726 }
727 if ($mode == 'payment_supplier') {
728 $url = DOL_URL_ROOT.'/fourn/paiement/card.php?id=';
729 }
730 if ($url) {
731 $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
732 if ($result <= 0) {
733 $error++;
734 dol_print_error($this->db);
735 }
736 }
737 }
738
739 // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
740 //if (! $error && $label != '(WithdrawalPayment)')
741 if (!$error) {
742 $linkaddedforthirdparty = array();
743 foreach ($this->amounts as $key => $value) { // We should have invoices always for same third party but we loop in case of.
744 if ($mode == 'payment') {
745 $fac = new Facture($this->db);
746 $fac->fetch($key);
747 $fac->fetch_thirdparty();
748 if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) { // Not yet done for this thirdparty
749 $result = $acc->add_url_line(
750 $bank_line_id,
751 $fac->thirdparty->id,
752 DOL_URL_ROOT.'/comm/card.php?socid=',
753 $fac->thirdparty->name,
754 'company'
755 );
756 if ($result <= 0) {
757 dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
758 }
759 $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
760 }
761 }
762 if ($mode == 'payment_supplier') {
763 $fac = new FactureFournisseur($this->db);
764 $fac->fetch($key);
765 $fac->fetch_thirdparty();
766 if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) { // Not yet done for this thirdparty
767 $result = $acc->add_url_line(
768 $bank_line_id,
769 $fac->thirdparty->id,
770 DOL_URL_ROOT.'/fourn/card.php?socid=',
771 $fac->thirdparty->name,
772 'company'
773 );
774 if ($result <= 0) {
775 dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
776 }
777 $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
778 }
779 }
780 }
781 }
782
783 // Add link 'WithdrawalPayment' in bank_url
784 if (!$error && $label == '(WithdrawalPayment)') {
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_payment,
790 'withdraw'
791 );
792 }
793
794 // Add link 'InvoiceRefused' in bank_url
795 if (!$error && $label == '(InvoiceRefused)') {
796 $result=$acc->add_url_line(
797 $bank_line_id,
798 $this->id_prelevement,
799 DOL_URL_ROOT.'/compta/prelevement/card.php?id=',
800 $this->num_prelevement,
801 'withdraw'
802 );
803 }
804
805 if (!$error && !$notrigger) {
806 // Appel des triggers
807 $result = $this->call_trigger('PAYMENT_ADD_TO_BANK', $user);
808 if ($result < 0) {
809 $error++;
810 }
811 // Fin appel triggers
812 }
813 } else {
814 $this->error = $acc->error;
815 $this->errors = $acc->errors;
816 $error++;
817 }
818
819 if (!$error) {
820 $this->db->commit();
821 } else {
822 $this->db->rollback();
823 }
824 }
825
826 if (!$error) {
827 return $bank_line_id;
828 } else {
829 return -1;
830 }
831 }
832
833
834 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
841 public function update_fk_bank($id_bank)
842 {
843 // phpcs:enable
844 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' set fk_bank = '.((int) $id_bank);
845 $sql .= " WHERE rowid = ".((int) $this->id);
846
847 dol_syslog(get_class($this).'::update_fk_bank', LOG_DEBUG);
848 $result = $this->db->query($sql);
849 if ($result) {
850 return 1;
851 } else {
852 $this->error = $this->db->lasterror();
853 dol_syslog(get_class($this).'::update_fk_bank '.$this->error);
854 return -1;
855 }
856 }
857
858 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
865 public function update_date($date)
866 {
867 // phpcs:enable
868 $error = 0;
869
870 if (!empty($date) && $this->statut != 1) {
871 $this->db->begin();
872
873 dol_syslog(get_class($this)."::update_date with date = ".$date, LOG_DEBUG);
874
875 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
876 $sql .= " SET datep = '".$this->db->idate($date)."'";
877 $sql .= " WHERE rowid = ".((int) $this->id);
878
879 $result = $this->db->query($sql);
880 if (!$result) {
881 $error++;
882 $this->error = 'Error -1 '.$this->db->error();
883 }
884
885 $type = $this->element;
886
887 $sql = "UPDATE ".MAIN_DB_PREFIX.'bank';
888 $sql .= " SET dateo = '".$this->db->idate($date)."', datev = '".$this->db->idate($date)."'";
889 $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).")";
890 $sql .= " AND rappro = 0";
891
892 $result = $this->db->query($sql);
893 if (!$result) {
894 $error++;
895 $this->error = 'Error -1 '.$this->db->error();
896 }
897
898 if (!$error) {
899 }
900
901 if (!$error) {
902 $this->datepaye = $date;
903 $this->date = $date;
904
905 $this->db->commit();
906 return 0;
907 } else {
908 $this->db->rollback();
909 return -2;
910 }
911 }
912 return -1; //no date given or already validated
913 }
914
915 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
922 public function update_num($num)
923 {
924 // phpcs:enable
925 if (!empty($num) && $this->statut != 1) {
926 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
927 $sql .= " SET num_paiement = '".$this->db->escape($num)."'";
928 $sql .= " WHERE rowid = ".((int) $this->id);
929
930 dol_syslog(get_class($this)."::update_num", LOG_DEBUG);
931 $result = $this->db->query($sql);
932 if ($result) {
933 $this->num_payment = $this->db->escape($num);
934 return 0;
935 } else {
936 $this->error = 'Error -1 '.$this->db->error();
937 return -2;
938 }
939 }
940 return -1; //no num given or already validated
941 }
942
950 public function valide(User $user = null)
951 {
952 return $this->validate($user);
953 }
954
961 public function validate(User $user = null)
962 {
963 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET statut = 1 WHERE rowid = '.((int) $this->id);
964
965 dol_syslog(get_class($this).'::valide', LOG_DEBUG);
966 $result = $this->db->query($sql);
967 if ($result) {
968 return 1;
969 } else {
970 $this->error = $this->db->lasterror();
971 dol_syslog(get_class($this).'::valide '.$this->error);
972 return -1;
973 }
974 }
975
982 public function reject(User $user = null)
983 {
984 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET statut = 2 WHERE rowid = '.((int) $this->id);
985
986 dol_syslog(get_class($this).'::reject', LOG_DEBUG);
987 $result = $this->db->query($sql);
988 if ($result) {
989 return 1;
990 } else {
991 $this->error = $this->db->lasterror();
992 dol_syslog(get_class($this).'::reject '.$this->error);
993 return -1;
994 }
995 }
996
1003 public function info($id)
1004 {
1005 $sql = 'SELECT p.rowid, p.datec, p.fk_user_creat, p.fk_user_modif, p.tms';
1006 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p';
1007 $sql .= ' WHERE p.rowid = '.((int) $id);
1008
1009 dol_syslog(get_class($this).'::info', LOG_DEBUG);
1010 $result = $this->db->query($sql);
1011
1012 if ($result) {
1013 if ($this->db->num_rows($result)) {
1014 $obj = $this->db->fetch_object($result);
1015 $this->id = $obj->rowid;
1016 if ($obj->fk_user_creat) {
1017 $cuser = new User($this->db);
1018 $cuser->fetch($obj->fk_user_creat);
1019 $this->user_creation = $cuser;
1020 }
1021 if ($obj->fk_user_modif) {
1022 $muser = new User($this->db);
1023 $muser->fetch($obj->fk_user_modif);
1024 $this->user_modification = $muser;
1025 }
1026 $this->date_creation = $this->db->jdate($obj->datec);
1027 $this->date_modification = $this->db->jdate($obj->tms);
1028 }
1029 $this->db->free($result);
1030 } else {
1031 dol_print_error($this->db);
1032 }
1033 }
1034
1042 public function getBillsArray($filter = '')
1043 {
1044 $sql = 'SELECT pf.fk_facture';
1045 $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
1046 $sql .= ' WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = '.((int) $this->id);
1047 if ($filter) {
1048 $sql .= ' AND '.$filter;
1049 }
1050 $resql = $this->db->query($sql);
1051 if ($resql) {
1052 $i = 0;
1053 $num = $this->db->num_rows($resql);
1054 $billsarray = array();
1055
1056 while ($i < $num) {
1057 $obj = $this->db->fetch_object($resql);
1058 $billsarray[$i] = $obj->fk_facture;
1059 $i++;
1060 }
1061
1062 return $billsarray;
1063 } else {
1064 $this->error = $this->db->error();
1065 dol_syslog(get_class($this).'::getBillsArray Error '.$this->error.' -', LOG_DEBUG);
1066 return -1;
1067 }
1068 }
1069
1076 public function getAmountsArray()
1077 {
1078 $sql = 'SELECT pf.fk_facture, pf.amount';
1079 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
1080 $sql .= ' WHERE pf.fk_paiement = '.((int) $this->id);
1081 $resql = $this->db->query($sql);
1082 if ($resql) {
1083 $i = 0;
1084 $num = $this->db->num_rows($resql);
1085 $amounts = array();
1086
1087 while ($i < $num) {
1088 $obj = $this->db->fetch_object($resql);
1089 $amounts[$obj->fk_facture] = $obj->amount;
1090 $i++;
1091 }
1092
1093 return $amounts;
1094 } else {
1095 $this->error = $this->db->error();
1096 dol_syslog(get_class($this).'::getAmountsArray Error '.$this->error.' -', LOG_DEBUG);
1097 return -1;
1098 }
1099 }
1100
1109 public function getNextNumRef($soc, $mode = 'next')
1110 {
1111 global $conf, $db, $langs;
1112 $langs->load("bills");
1113
1114 // Clean parameters (if not defined or using deprecated value)
1115 if (empty($conf->global->PAYMENT_ADDON)) {
1116 $conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
1117 } elseif ($conf->global->PAYMENT_ADDON == 'ant') {
1118 $conf->global->PAYMENT_ADDON = 'mod_payment_ant';
1119 } elseif ($conf->global->PAYMENT_ADDON == 'cicada') {
1120 $conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
1121 }
1122
1123 if (!empty($conf->global->PAYMENT_ADDON)) {
1124 $mybool = false;
1125
1126 $file = $conf->global->PAYMENT_ADDON.".php";
1127 $classname = $conf->global->PAYMENT_ADDON;
1128
1129 // Include file with class
1130 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1131
1132 foreach ($dirmodels as $reldir) {
1133 $dir = dol_buildpath($reldir."core/modules/payment/");
1134
1135 // Load file with numbering class (if found)
1136 if (is_file($dir.$file) && is_readable($dir.$file)) {
1137 $mybool |= include_once $dir.$file;
1138 }
1139 }
1140
1141 // For compatibility
1142 if (!$mybool) {
1143 $file = $conf->global->PAYMENT_ADDON.".php";
1144 $classname = "mod_payment_".$conf->global->PAYMENT_ADDON;
1145 $classname = preg_replace('/\-.*$/', '', $classname);
1146 // Include file with class
1147 foreach ($conf->file->dol_document_root as $dirroot) {
1148 $dir = $dirroot."/core/modules/payment/";
1149
1150 // Load file with numbering class (if found)
1151 if (is_file($dir.$file) && is_readable($dir.$file)) {
1152 $mybool |= include_once $dir.$file;
1153 }
1154 }
1155 }
1156
1157 if (!$mybool) {
1158 dol_print_error('', "Failed to include file ".$file);
1159 return '';
1160 }
1161
1162 $obj = new $classname();
1163 $numref = "";
1164 $numref = $obj->getNextValue($soc, $this);
1165
1170 if ($mode != 'last' && !$numref) {
1171 dol_print_error($db, "Payment::getNextNumRef ".$obj->error);
1172 return "";
1173 }
1174
1175 return $numref;
1176 } else {
1177 $langs->load("errors");
1178 print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Invoice"));
1179 return "";
1180 }
1181 }
1182
1188 public function getWay()
1189 {
1190 global $conf;
1191
1192 $way = 'dolibarr';
1193 if (isModEnabled('multicurrency')) {
1194 foreach ($this->multicurrency_amounts as $value) {
1195 if (!empty($value)) { // one value found then payment is in invoice currency
1196 $way = 'customer';
1197 break;
1198 }
1199 }
1200 }
1201
1202 return $way;
1203 }
1204
1213 public function initAsSpecimen($option = '')
1214 {
1215 global $user, $langs, $conf;
1216
1217 $now = dol_now();
1218 $arraynow = dol_getdate($now);
1219 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
1220
1221 // Initialize parameters
1222 $this->id = 0;
1223 $this->ref = 'SPECIMEN';
1224 $this->specimen = 1;
1225 $this->facid = 1;
1226 $this->datepaye = $nownotime;
1227 }
1228
1229
1240 public function getNomUrl($withpicto = 0, $option = '', $mode = 'withlistofinvoices', $notooltip = 0, $morecss = '')
1241 {
1242 global $conf, $langs, $hookmanager;
1243
1244 if (!empty($conf->dol_no_mouse_hover)) {
1245 $notooltip = 1; // Force disable tooltips
1246 }
1247
1248 $result = '';
1249
1250 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Payment").'</u><br>';
1251 $label .= '<strong>'.$langs->trans("Ref").':</strong> '.$this->ref;
1252 $dateofpayment = ($this->datepaye ? $this->datepaye : $this->date);
1253 if ($dateofpayment) {
1254 $label .= '<br><strong>'.$langs->trans("Date").':</strong> ';
1255 $tmparray = dol_getdate($dateofpayment);
1256 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
1257 $label .= dol_print_date($dateofpayment, 'day');
1258 } else { // Hours was set to real date of payment (special case for POS for example)
1259 $label .= dol_print_date($dateofpayment, 'dayhour', 'tzuser');
1260 }
1261 }
1262 if ($this->amount) {
1263 $label .= '<br><strong>'.$langs->trans("Amount").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
1264 }
1265 if ($mode == 'withlistofinvoices') {
1266 $arraybill = $this->getBillsArray();
1267 if (is_array($arraybill) && count($arraybill) > 0) {
1268 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1269 $facturestatic = new Facture($this->db);
1270 foreach ($arraybill as $billid) {
1271 $facturestatic->fetch($billid);
1272 $label .= '<br> '.$facturestatic->getNomUrl(1, '', 0, 0, '', 1).' '.$facturestatic->getLibStatut(2, -1);
1273 }
1274 }
1275 }
1276
1277 $linkclose = '';
1278 if (empty($notooltip)) {
1279 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1280 $label = $langs->trans("Payment");
1281 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1282 }
1283 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
1284 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
1285 } else {
1286 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1287 }
1288
1289 $url = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$this->id;
1290
1291 $linkstart = '<a href="'.$url.'"';
1292 $linkstart .= $linkclose.'>';
1293 $linkend = '</a>';
1294
1295 $result .= $linkstart;
1296 if ($withpicto) {
1297 $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);
1298 }
1299 if ($withpicto && $withpicto != 2) {
1300 $result .= ($this->ref ? $this->ref : $this->id);
1301 }
1302 $result .= $linkend;
1303 global $action;
1304 $hookmanager->initHooks(array($this->element . 'dao'));
1305 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
1306 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1307 if ($reshook > 0) {
1308 $result = $hookmanager->resPrint;
1309 } else {
1310 $result .= $hookmanager->resPrint;
1311 }
1312 return $result;
1313 }
1314
1321 public function getLibStatut($mode = 0)
1322 {
1323 return $this->LibStatut($this->statut, $mode);
1324 }
1325
1326 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1334 public function LibStatut($status, $mode = 0)
1335 {
1336 // phpcs:enable
1337 global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage
1338
1339 $langs->load('compta');
1340 /*if ($mode == 0)
1341 {
1342 if ($status == 0) return $langs->trans('ToValidate');
1343 if ($status == 1) return $langs->trans('Validated');
1344 }
1345 if ($mode == 1)
1346 {
1347 if ($status == 0) return $langs->trans('ToValidate');
1348 if ($status == 1) return $langs->trans('Validated');
1349 }
1350 if ($mode == 2)
1351 {
1352 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
1353 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
1354 }
1355 if ($mode == 3)
1356 {
1357 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
1358 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
1359 }
1360 if ($mode == 4)
1361 {
1362 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
1363 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
1364 }
1365 if ($mode == 5)
1366 {
1367 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
1368 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
1369 }
1370 if ($mode == 6)
1371 {
1372 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
1373 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
1374 }*/
1375 return '';
1376 }
1377
1378 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1386 public function fetch_thirdparty($force_thirdparty_id = 0)
1387 {
1388 // phpcs:enable
1389 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1390
1391 if (empty($force_thirdparty_id)) {
1392 $billsarray = $this->getBillsArray(); // From payment, the fk_soc isn't available, we should load the first supplier invoice to get him
1393 if (!empty($billsarray)) {
1394 $invoice = new Facture($this->db);
1395 if ($invoice->fetch($billsarray[0]) > 0) {
1396 $force_thirdparty_id = $invoice->socid;
1397 }
1398 }
1399 }
1400
1401 return parent::fetch_thirdparty($force_thirdparty_id);
1402 }
1403
1404
1410 public function isReconciled()
1411 {
1412 $accountline = new AccountLine($this->db);
1413 $accountline->fetch($this->bank_line);
1414 return $accountline->rappro;
1415 }
1416}
$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.
static getAmountConversionFromInvoiceRate($fk_facture, $amount, $way='dolibarr', $table='facture', $invoice_rate=null)
Get the conversion of amount with invoice rate.
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)
isReconciled()
Return if payment is reconciled.
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)
Return the label of a given status.
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)
Return the label of the status.
Class to manage translations.
Class to manage Dolibarr users.
print $langs trans("Ref").' m m m statut
Definition index.php:152
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.
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.