dolibarr 20.0.0
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-2024 Frédéric France <frederic.france@free.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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 3 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <https://www.gnu.org/licenses/>.
30 */
31
37require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
38require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
39
40
45{
49 public $element = 'payment';
50
54 public $table_element = 'paiement';
55
59 public $picto = 'payment';
60
64 public $facid;
65
69 public $socid;
70
74 public $datepaye;
75
79 public $date;
80
85 public $total;
86
91 public $montant;
92
96 public $amount;
97
101 public $multicurrency_amount;
102
106 public $amounts = array();
107
111 public $multicurrency_amounts = array();
112
116 public $multicurrency_tx = array();
117
121 public $multicurrency_code = array();
122
126 public $pos_change = 0.0;
127
128 public $author;
129
133 public $paiementid;
134
138 public $paiementcode;
139
143 public $type_label;
144
148 public $type_code;
149
155 public $num_paiement;
156
161 public $num_payment;
162
166 public $ext_payment_id;
167
171 public $id_prelevement;
172
176 public $num_prelevement;
177
181 public $ext_payment_site;
182
188 public $bank_account;
189
193 public $fk_account;
194
198 public $bank_line;
199
200 // fk_paiement dans llx_paiement est l'id du type de paiement (7 pour CHQ, ...)
201 // fk_paiement dans llx_paiement_facture est le rowid du paiement
205 public $fk_paiement; // Type of payment
206
210 public $ref_ext;
211
212
218 public function __construct($db)
219 {
220 $this->db = $db;
221 }
222
231 public function fetch($id, $ref = '', $fk_bank = 0)
232 {
233 $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,';
234 $sql .= ' c.code as type_code, c.libelle as type_label,';
235 $sql .= ' p.num_paiement as num_payment, p.note,';
236 $sql .= ' b.fk_account';
237 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id';
238 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
239 $sql .= ' WHERE p.entity IN ('.getEntity('invoice').')';
240 if ($id > 0) {
241 $sql .= ' AND p.rowid = '.((int) $id);
242 } elseif ($ref) {
243 $sql .= " AND p.ref = '".$this->db->escape($ref)."'";
244 } elseif ($fk_bank) {
245 $sql .= ' AND p.fk_bank = '.((int) $fk_bank);
246 }
247
248 $resql = $this->db->query($sql);
249 if ($resql) {
250 if ($this->db->num_rows($resql)) {
251 $obj = $this->db->fetch_object($resql);
252
253 $this->id = $obj->rowid;
254 $this->ref = $obj->ref ? $obj->ref : $obj->rowid;
255 $this->ref_ext = $obj->ref_ext;
256 $this->date = $this->db->jdate($obj->dp);
257 $this->datepaye = $this->db->jdate($obj->dp);
258 $this->num_payment = $obj->num_payment;
259 $this->montant = $obj->amount; // deprecated
260 $this->amount = $obj->amount;
261 $this->multicurrency_amount = $obj->multicurrency_amount;
262 $this->note = $obj->note;
263 $this->note_private = $obj->note;
264 $this->type_label = $obj->type_label;
265 $this->type_code = $obj->type_code;
266 $this->statut = $obj->statut;
267 $this->ext_payment_id = $obj->ext_payment_id;
268 $this->ext_payment_site = $obj->ext_payment_site;
269
270 $this->bank_account = $obj->fk_account; // deprecated
271 $this->fk_account = $obj->fk_account;
272 $this->bank_line = $obj->fk_bank;
273
274 $this->db->free($resql);
275 return 1;
276 } else {
277 $this->db->free($resql);
278 return 0;
279 }
280 } else {
281 dol_print_error($this->db);
282 return -1;
283 }
284 }
285
296 public function create($user, $closepaidinvoices = 0, $thirdparty = null)
297 {
298 global $conf, $langs;
299
300 $error = 0;
301 $way = $this->getWay(); // 'dolibarr' to use amount, 'customer' to use foreign multicurrency amount
302
303 $now = dol_now();
304
305 // Clean parameters
306 $totalamount = 0;
307 $totalamount_converted = 0;
308 $atleastonepaymentnotnull = 0;
309
310 if ($way == 'dolibarr') { // Payments were entered into the column of main currency
311 $amounts = &$this->amounts;
312 $amounts_to_update = &$this->multicurrency_amounts;
313 } else { // Payments were entered into the column of foreign currency
314 $amounts = &$this->multicurrency_amounts;
315 $amounts_to_update = &$this->amounts;
316 }
317
318 $currencyofpayment = '';
319 $currencytxofpayment = '';
320
321 foreach ($amounts as $key => $value) { // How payment is dispatched
322 if (empty($value)) {
323 continue;
324 }
325 // $key is id of invoice, $value is amount, $way is a 'dolibarr' if amount is in main currency, 'customer' if in foreign currency
326 $value_converted = MultiCurrency::getAmountConversionFromInvoiceRate($key, $value, $way);
327 // Add controls of input validity
328 if ($value_converted === false) {
329 // We failed to find the conversion for one invoice
330 $this->error = $langs->trans('FailedToFoundTheConversionRateForInvoice');
331 return -1;
332 }
333 if (empty($currencyofpayment)) {
334 $currencyofpayment = isset($this->multicurrency_code[$key]) ? $this->multicurrency_code[$key] : "";
335 } elseif ($currencyofpayment != $this->multicurrency_code[$key]) {
336 // If we have invoices with different currencies in the payment, we stop here
337 $this->error = 'ErrorYouTryToPayInvoicesWithDifferentCurrenciesInSamePayment';
338 return -1;
339 }
340 if (empty($currencytxofpayment)) {
341 $currencytxofpayment = isset($this->multicurrency_tx[$key]) ? $this->multicurrency_tx[$key] : "";
342 }
343
344 $totalamount_converted += $value_converted;
345 $amounts_to_update[$key] = price2num($value_converted, 'MT');
346
347 $newvalue = price2num($value, 'MT');
348 $amounts[$key] = $newvalue;
349 $totalamount += $newvalue;
350 if (!empty($newvalue)) {
351 $atleastonepaymentnotnull++;
352 }
353 }
354
355 if (empty($currencyofpayment)) { // Should not happen. For the case the multicurrency_code was not saved into invoices
356 $currencyofpayment = $conf->currency;
357 }
358
359 if (!empty($currencyofpayment)) {
360 // We must check that the currency of invoices is the same than the currency of the bank
361 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
362 $bankaccount = new Account($this->db);
363 $bankaccount->fetch($this->fk_account);
364 $bankcurrencycode = empty($bankaccount->currency_code) ? $conf->currency : $bankaccount->currency_code;
365 if ($currencyofpayment != $bankcurrencycode && $currencyofpayment != $conf->currency && $bankcurrencycode != $conf->currency) {
366 $langs->load("errors");
367 $this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofpayment, $bankcurrencycode);
368 return -1;
369 }
370 }
371
372
373 $totalamount = (float) price2num($totalamount);
374 $totalamount_converted = (float) price2num($totalamount_converted);
375
376 // Check parameters
377 if (empty($totalamount) && empty($atleastonepaymentnotnull)) { // We accept negative amounts for withdraw reject but not empty arrays
378 $this->errors[] = 'TotalAmountEmpty';
379 $this->error = $langs->trans('TotalAmountEmpty');
380 return -1;
381 }
382
383 dol_syslog(get_class($this)."::create insert paiement (closepaidinvoices = ".$closepaidinvoices.")", LOG_DEBUG);
384
385 $this->db->begin();
386
387 $this->ref = $this->getNextNumRef(is_object($thirdparty) ? $thirdparty : '');
388
389 if (empty($this->ref_ext)) {
390 $this->ref_ext = '';
391 }
392
393 if ($way == 'dolibarr') {
394 $total = $totalamount;
395 $mtotal = $totalamount_converted;
396 } else {
397 $total = $totalamount_converted;
398 $mtotal = $totalamount;
399 }
400
401 $num_payment = $this->num_payment;
402 $note = ($this->note_private ? $this->note_private : $this->note);
403
404 $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)";
405 $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).", ";
406 $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).")";
407
408 $resql = $this->db->query($sql);
409 if ($resql) {
410 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiement');
411
412 // Insert links amount / invoices
413 foreach ($this->amounts as $key => $amount) {
414 $facid = $key;
415 if (is_numeric($amount) && $amount != 0) {
416 $amount = price2num($amount);
417 $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount, multicurrency_amount, multicurrency_code, multicurrency_tx)";
418 $sql .= " VALUES (".((int) $facid).", ".((int) $this->id).", ".((float) $amount).", ".((float) $this->multicurrency_amounts[$key]).", ".($currencyofpayment ? "'".$this->db->escape($currencyofpayment)."'" : 'NULL').", ".(!empty($this->multicurrency_tx) ? (float) $currencytxofpayment : 1).")";
419
420 dol_syslog(get_class($this).'::create Amount line '.$key.' insert paiement_facture', LOG_DEBUG);
421 $resql = $this->db->query($sql);
422 if ($resql) {
423 $invoice = new Facture($this->db);
424 $invoice->fetch($facid);
425
426 // If we want to closed paid invoices
427 if ($closepaidinvoices) {
428 $paiement = $invoice->getSommePaiement();
429 $creditnotes = $invoice->getSumCreditNotesUsed();
430 $deposits = $invoice->getSumDepositsUsed();
431 $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
432 $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
433
434 //var_dump($invoice->total_ttc.' - '.$paiement.' -'.$creditnotes.' - '.$deposits.' - '.$remaintopay);exit;
435
436 //Invoice types that are eligible for changing status to paid
437 $affected_types = array(
443 );
444
445 if (!in_array($invoice->type, $affected_types)) {
446 dol_syslog("Invoice ".$facid." is not a standard, nor replacement invoice, nor credit note, nor deposit invoice, nor situation invoice. We do nothing more.");
447 } elseif ($remaintopay) {
448 // hook to have an option to automatically close a closable invoice with less payment than the total amount (e.g. agreed cash discount terms)
449 global $hookmanager;
450 $hookmanager->initHooks(array('paymentdao'));
451 $parameters = array('facid' => $facid, 'invoice' => $invoice, 'remaintopay' => $remaintopay);
452 $action = 'CLOSEPAIDINVOICE';
453 $reshook = $hookmanager->executeHooks('createPayment', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
454 if ($reshook < 0) {
455 $this->errors[] = $hookmanager->error;
456 $this->error = $hookmanager->error;
457 $error++;
458 } elseif ($reshook == 0) {
459 dol_syslog("Remain to pay for invoice " . $facid . " not null. We do nothing more.");
460 }
461 // } else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more.");
462 } else {
463 // If invoice is a down payment, we also convert down payment to discount
464 if ($invoice->type == Facture::TYPE_DEPOSIT) {
465 $amount_ht = $amount_tva = $amount_ttc = array();
466 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
467
468 // Insert one discount by VAT rate category
469 $discount = new DiscountAbsolute($this->db);
470 $discount->fetch('', $invoice->id);
471 if (empty($discount->id)) { // If the invoice was not yet converted into a discount (this may have been done manually before we come here)
472 $discount->description = '(DEPOSIT)';
473 $discount->fk_soc = $invoice->socid;
474 $discount->socid = $invoice->socid;
475 $discount->fk_facture_source = $invoice->id;
476
477 // Loop on each vat rate
478 $i = 0;
479 foreach ($invoice->lines as $line) {
480 if ($line->total_ht != 0) { // no need to create discount if amount is null
481 $amount_ht[$line->tva_tx] += $line->total_ht;
482 $amount_tva[$line->tva_tx] += $line->total_tva;
483 $amount_ttc[$line->tva_tx] += $line->total_ttc;
484 $multicurrency_amount_ht[$line->tva_tx] += $line->multicurrency_total_ht;
485 $multicurrency_amount_tva[$line->tva_tx] += $line->multicurrency_total_tva;
486 $multicurrency_amount_ttc[$line->tva_tx] += $line->multicurrency_total_ttc;
487 $i++;
488 }
489 }
490
491 foreach ($amount_ht as $tva_tx => $xxx) {
492 $discount->amount_ht = abs($amount_ht[$tva_tx]);
493 $discount->amount_tva = abs($amount_tva[$tva_tx]);
494 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
495 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
496 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
497 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
498 $discount->tva_tx = abs($tva_tx);
499
500 $result = $discount->create($user);
501 if ($result < 0) {
502 $error++;
503 break;
504 }
505 }
506 }
507
508 if ($error) {
509 $this->error = $discount->error;
510 $this->errors = $discount->errors;
511 $error++;
512 }
513 }
514
515 // Set invoice to paid
516 if (!$error) {
517 $result = $invoice->setPaid($user, '', '');
518 if ($result < 0) {
519 $this->error = $invoice->error;
520 $this->errors = $invoice->errors;
521 $error++;
522 }
523 }
524 }
525 }
526
527 // Regenerate documents of invoices
528 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
529 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);
530
531 $newlang = '';
532 $outputlangs = $langs;
533 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
534 $invoice->fetch_thirdparty();
535 $newlang = $invoice->thirdparty->default_lang;
536 }
537 if (!empty($newlang)) {
538 $outputlangs = new Translate("", $conf);
539 $outputlangs->setDefaultLang($newlang);
540 }
541
542 $hidedetails = getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0;
543 $hidedesc = getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0;
544 $hideref = getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0;
545
546 $ret = $invoice->fetch($facid); // Reload to get new records
547
548 $result = $invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
549
550 dol_syslog(get_class($this).'::create Regenerate end result='.$result, LOG_DEBUG);
551
552 if ($result < 0) {
553 $this->error = $invoice->error;
554 $this->errors = $invoice->errors;
555 $error++;
556 }
557 }
558 } else {
559 $this->error = $this->db->lasterror();
560 $error++;
561 }
562 } else {
563 dol_syslog(get_class($this).'::Create Amount line '.$key.' not a number. We discard it.');
564 }
565 }
566
567 dol_syslog(get_class($this).'::create Now we call the triggers if no error (error = '.$error.')', LOG_DEBUG);
568
569 if (!$error) { // All payments into $this->amounts were recorded without errors
570 // Appel des triggers
571 $result = $this->call_trigger('PAYMENT_CUSTOMER_CREATE', $user);
572 if ($result < 0) {
573 $error++;
574 }
575 // Fin appel triggers
576 }
577 } else {
578 $this->error = $this->db->lasterror();
579 $error++;
580 }
581
582 if (!$error) {
583 $this->amount = $total;
584 $this->total = $total; // deprecated
585 $this->multicurrency_amount = $mtotal;
586 $this->db->commit();
587 return $this->id;
588 } else {
589 $this->db->rollback();
590 return -1;
591 }
592 }
593
594
604 public function delete($user, $notrigger = 0)
605 {
606 $error = 0;
607
608 $bank_line_id = $this->bank_line;
609
610 $this->db->begin();
611
612 // Verifier si paiement porte pas sur une facture classee
613 // Si c'est le cas, on refuse la suppression
614 $billsarray = $this->getBillsArray('f.fk_statut > 1');
615 if (is_array($billsarray)) {
616 if (count($billsarray)) {
617 $this->error = "ErrorDeletePaymentLinkedToAClosedInvoiceNotPossible";
618 $this->db->rollback();
619 return -1;
620 }
621 } else {
622 $this->db->rollback();
623 return -2;
624 }
625
626 // Delete bank urls. If payment is on a conciliated line, return error.
627 if ($bank_line_id > 0) {
628 $accline = new AccountLine($this->db);
629
630 $result = $accline->fetch($bank_line_id);
631 if ($result == 0) {
632 $accline->id = $accline->rowid = $bank_line_id; // If not found, we set artificially rowid to allow delete of llx_bank_url
633 }
634
635 // Delete bank account url lines linked to payment
636 $result = $accline->delete_urls($user);
637 if ($result < 0) {
638 $this->error = $accline->error;
639 $this->db->rollback();
640 return -3;
641 }
642
643 // Delete bank account lines linked to payment
644 $result = $accline->delete($user);
645 if ($result < 0) {
646 $this->error = $accline->error;
647 $this->db->rollback();
648 return -4;
649 }
650 }
651
652 if (!$notrigger) {
653 // Call triggers
654 $result = $this->call_trigger('PAYMENT_CUSTOMER_DELETE', $user);
655 if ($result < 0) {
656 $this->db->rollback();
657 return -1;
658 }
659 // End call triggers
660 }
661
662 // Delete payment (into paiement_facture and paiement)
663 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement_facture';
664 $sql .= ' WHERE fk_paiement = '.((int) $this->id);
665 dol_syslog($sql);
666 $result = $this->db->query($sql);
667 if ($result) {
668 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement';
669 $sql .= " WHERE rowid = ".((int) $this->id);
670 dol_syslog($sql);
671 $result = $this->db->query($sql);
672 if (!$result) {
673 $this->error = $this->db->lasterror();
674 $this->db->rollback();
675 return -3;
676 }
677
678 $this->db->commit();
679 return 1;
680 } else {
681 $this->error = $this->db->error;
682 $this->db->rollback();
683 return -5;
684 }
685 }
686
687
703 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque, $notrigger = 0, $accountancycode = '', $addbankurl = '')
704 {
705 global $conf, $user;
706
707 $error = 0;
708 $bank_line_id = 0;
709
710 if (isModEnabled("bank")) {
711 if ($accountid <= 0) {
712 $this->error = 'Bad value for parameter accountid='.$accountid;
713 dol_syslog(get_class($this).'::addPaymentToBank '.$this->error, LOG_ERR);
714 return -1;
715 }
716
717 $this->fk_account = $accountid;
718
719 dol_syslog("addPaymentToBank ".$user->id.", ".$mode.", ".$label.", ".$this->fk_account.", ".$emetteur_nom.", ".$emetteur_banque);
720
721 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
722 $acc = new Account($this->db);
723 $result = $acc->fetch($this->fk_account);
724 if ($result < 0) {
725 $this->error = $acc->error;
726 $this->errors = $acc->errors;
727 $error++;
728 return -1;
729 }
730
731 $this->db->begin();
732
733 $totalamount = $this->amount;
734 $totalamount_main_currency = null;
735 if (empty($totalamount)) {
736 $totalamount = $this->total; // For backward compatibility
737 }
738
739 // 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)
740 if (isModEnabled('multicurrency') && $conf->currency != $acc->currency_code) {
741 $totalamount = $this->multicurrency_amount; // We will insert into llx_bank.amount in foreign currency
742 $totalamount_main_currency = $this->amount; // We will also save the amount in main currency into column llx_bank.amount_main_currency
743 }
744
745 if ($mode == 'payment_supplier') {
746 $totalamount = -$totalamount;
747 if (isset($totalamount_main_currency)) {
748 $totalamount_main_currency = -$totalamount_main_currency;
749 }
750 }
751
752 // Insert payment into llx_bank
753 $bank_line_id = $acc->addline(
754 $this->datepaye,
755 $this->paiementcode ? $this->paiementcode : $this->paiementid, // Payment mode code ('CB', 'CHQ' or 'VIR' for example). Use payment id if not defined for backward compatibility.
756 $label,
757 $totalamount, // Sign must be positive when we receive money (customer payment), negative when you give money (supplier invoice or credit note)
758 $this->num_payment,
759 '',
760 $user,
761 $emetteur_nom,
762 $emetteur_banque,
763 $accountancycode,
764 null,
765 '',
766 $totalamount_main_currency
767 );
768
769 // Mise a jour fk_bank dans llx_paiement
770 // On connait ainsi le paiement qui a genere l'ecriture bancaire
771 if ($bank_line_id > 0) {
772 $result = $this->update_fk_bank($bank_line_id);
773 if ($result <= 0) {
774 $error++;
775 dol_print_error($this->db);
776 }
777
778 // Add link 'payment', 'payment_supplier' in bank_url between payment and bank transaction
779 if (!$error) {
780 $url = '';
781 if ($mode == 'payment') {
782 $url = DOL_URL_ROOT.'/compta/paiement/card.php?id=';
783 }
784 if ($mode == 'payment_supplier') {
785 $url = DOL_URL_ROOT.'/fourn/paiement/card.php?id=';
786 }
787 if ($url) {
788 $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
789 if ($result <= 0) {
790 $error++;
791 dol_print_error($this->db);
792 }
793 }
794 }
795
796 // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
797 if (!$error) {
798 $linkaddedforthirdparty = array();
799 foreach ($this->amounts as $key => $value) { // We should have invoices always for same third party but we loop in case of.
800 if ($mode == 'payment') {
801 $fac = new Facture($this->db);
802 $fac->fetch($key);
803 $fac->fetch_thirdparty();
804 if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) { // Not yet done for this thirdparty
805 $result = $acc->add_url_line(
806 $bank_line_id,
807 $fac->thirdparty->id,
808 DOL_URL_ROOT.'/comm/card.php?socid=',
809 $fac->thirdparty->name,
810 'company'
811 );
812 if ($result <= 0) {
813 dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
814 }
815 $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
816 }
817 }
818 if ($mode == 'payment_supplier') {
819 $fac = new FactureFournisseur($this->db);
820 $fac->fetch($key);
821 $fac->fetch_thirdparty();
822 if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) { // Not yet done for this thirdparty
823 $result = $acc->add_url_line(
824 $bank_line_id,
825 $fac->thirdparty->id,
826 DOL_URL_ROOT.'/fourn/card.php?socid=',
827 $fac->thirdparty->name,
828 'company'
829 );
830 if ($result <= 0) {
831 dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
832 }
833 $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
834 }
835 }
836 }
837 }
838
839 // Add a link to the Direct Debit ('direct-debit') or Credit transfer ('credit-transfer') file in bank_url
840 if (!$error && $addbankurl && in_array($addbankurl, array('direct-debit', 'credit-transfer'))) {
841 $result = $acc->add_url_line(
842 $bank_line_id,
843 $this->id_prelevement,
844 DOL_URL_ROOT.'/compta/prelevement/card.php?id=',
845 $this->num_payment,
846 $addbankurl
847 );
848 }
849
850 // Add link to the Direct Debit if invoice refused ('InvoiceRefused') in bank_url
851 if (!$error && $label == '(InvoiceRefused)') {
852 $result = $acc->add_url_line(
853 $bank_line_id,
854 $this->id_prelevement,
855 DOL_URL_ROOT.'/compta/prelevement/card.php?id=',
856 $this->num_prelevement,
857 'withdraw'
858 );
859 }
860
861 if (!$error && !$notrigger) {
862 // Appel des triggers
863 $result = $this->call_trigger('PAYMENT_ADD_TO_BANK', $user);
864 if ($result < 0) {
865 $error++;
866 }
867 // Fin appel triggers
868 }
869 } else {
870 $this->error = $acc->error;
871 $this->errors = $acc->errors;
872 $error++;
873 }
874
875 if (!$error) {
876 $this->db->commit();
877 } else {
878 $this->db->rollback();
879 }
880 }
881
882 if (!$error) {
883 return $bank_line_id;
884 } else {
885 return -1;
886 }
887 }
888
889
890 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
897 public function update_fk_bank($id_bank)
898 {
899 // phpcs:enable
900 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' set fk_bank = '.((int) $id_bank);
901 $sql .= " WHERE rowid = ".((int) $this->id);
902
903 dol_syslog(get_class($this).'::update_fk_bank', LOG_DEBUG);
904 $result = $this->db->query($sql);
905 if ($result) {
906 return 1;
907 } else {
908 $this->error = $this->db->lasterror();
909 dol_syslog(get_class($this).'::update_fk_bank '.$this->error);
910 return -1;
911 }
912 }
913
914 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
921 public function update_date($date)
922 {
923 // phpcs:enable
924 $error = 0;
925
926 if (!empty($date) && $this->statut != 1) {
927 $this->db->begin();
928
929 dol_syslog(get_class($this)."::update_date with date = ".$date, LOG_DEBUG);
930
931 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
932 $sql .= " SET datep = '".$this->db->idate($date)."'";
933 $sql .= " WHERE rowid = ".((int) $this->id);
934
935 $result = $this->db->query($sql);
936 if (!$result) {
937 $error++;
938 $this->error = 'Error -1 '.$this->db->error();
939 }
940
941 $type = $this->element;
942
943 $sql = "UPDATE ".MAIN_DB_PREFIX.'bank';
944 $sql .= " SET dateo = '".$this->db->idate($date)."', datev = '".$this->db->idate($date)."'";
945 $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).")";
946 $sql .= " AND rappro = 0";
947
948 $result = $this->db->query($sql);
949 if (!$result) {
950 $error++;
951 $this->error = 'Error -1 '.$this->db->error();
952 }
953
954 if (!$error) {
955 }
956
957 if (!$error) {
958 $this->datepaye = $date;
959 $this->date = $date;
960
961 $this->db->commit();
962 return 0;
963 } else {
964 $this->db->rollback();
965 return -2;
966 }
967 }
968 return -1; //no date given or already validated
969 }
970
971 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
978 public function update_num($num_payment)
979 {
980 // phpcs:enable
981 if (!empty($num_payment) && $this->statut != 1) {
982 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
983 $sql .= " SET num_paiement = '".$this->db->escape($num_payment)."'";
984 $sql .= " WHERE rowid = ".((int) $this->id);
985
986 dol_syslog(get_class($this)."::update_num", LOG_DEBUG);
987 $result = $this->db->query($sql);
988 if ($result) {
989 $this->num_payment = $this->db->escape($num_payment);
990 return 0;
991 } else {
992 $this->error = 'Error -1 '.$this->db->error();
993 return -2;
994 }
995 }
996 return -1; //no num given or already validated
997 }
998
1006 public function valide(User $user = null)
1007 {
1008 return $this->validate($user);
1009 }
1010
1017 public function validate(User $user = null)
1018 {
1019 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET statut = 1 WHERE rowid = '.((int) $this->id);
1020
1021 dol_syslog(get_class($this).'::valide', LOG_DEBUG);
1022 $result = $this->db->query($sql);
1023 if ($result) {
1024 return 1;
1025 } else {
1026 $this->error = $this->db->lasterror();
1027 dol_syslog(get_class($this).'::valide '.$this->error);
1028 return -1;
1029 }
1030 }
1031
1038 public function reject(User $user = null)
1039 {
1040 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET statut = 2 WHERE rowid = '.((int) $this->id);
1041
1042 dol_syslog(get_class($this).'::reject', LOG_DEBUG);
1043 $result = $this->db->query($sql);
1044 if ($result) {
1045 return 1;
1046 } else {
1047 $this->error = $this->db->lasterror();
1048 dol_syslog(get_class($this).'::reject '.$this->error);
1049 return -1;
1050 }
1051 }
1052
1059 public function info($id)
1060 {
1061 $sql = 'SELECT p.rowid, p.datec, p.fk_user_creat, p.fk_user_modif, p.tms';
1062 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p';
1063 $sql .= ' WHERE p.rowid = '.((int) $id);
1064
1065 dol_syslog(get_class($this).'::info', LOG_DEBUG);
1066 $result = $this->db->query($sql);
1067
1068 if ($result) {
1069 if ($this->db->num_rows($result)) {
1070 $obj = $this->db->fetch_object($result);
1071
1072 $this->id = $obj->rowid;
1073
1074 $this->user_creation_id = $obj->fk_user_creat;
1075 $this->user_modification_id = $obj->fk_user_modif;
1076 $this->date_creation = $this->db->jdate($obj->datec);
1077 $this->date_modification = $this->db->jdate($obj->tms);
1078 }
1079 $this->db->free($result);
1080 } else {
1081 dol_print_error($this->db);
1082 }
1083 }
1084
1092 public function getBillsArray($filter = '')
1093 {
1094 $sql = 'SELECT pf.fk_facture';
1095 $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
1096 $sql .= ' WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = '.((int) $this->id);
1097 if ($filter) {
1098 $sql .= ' AND '.$filter;
1099 }
1100 $resql = $this->db->query($sql);
1101 if ($resql) {
1102 $i = 0;
1103 $num = $this->db->num_rows($resql);
1104 $billsarray = array();
1105
1106 while ($i < $num) {
1107 $obj = $this->db->fetch_object($resql);
1108 $billsarray[$i] = $obj->fk_facture;
1109 $i++;
1110 }
1111
1112 return $billsarray;
1113 } else {
1114 $this->error = $this->db->error();
1115 dol_syslog(get_class($this).'::getBillsArray Error '.$this->error.' -', LOG_DEBUG);
1116 return -1;
1117 }
1118 }
1119
1126 public function getAmountsArray()
1127 {
1128 $sql = 'SELECT pf.fk_facture, pf.amount';
1129 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
1130 $sql .= ' WHERE pf.fk_paiement = '.((int) $this->id);
1131 $resql = $this->db->query($sql);
1132 if ($resql) {
1133 $i = 0;
1134 $num = $this->db->num_rows($resql);
1135 $amounts = array();
1136
1137 while ($i < $num) {
1138 $obj = $this->db->fetch_object($resql);
1139 $amounts[$obj->fk_facture] = $obj->amount;
1140 $i++;
1141 }
1142
1143 return $amounts;
1144 } else {
1145 $this->error = $this->db->error();
1146 dol_syslog(get_class($this).'::getAmountsArray Error '.$this->error.' -', LOG_DEBUG);
1147 return -1;
1148 }
1149 }
1150
1159 public function getNextNumRef($soc, $mode = 'next')
1160 {
1161 global $conf, $db, $langs;
1162 $langs->load("bills");
1163
1164 // Clean parameters (if not defined or using deprecated value)
1165 if (!getDolGlobalString('PAYMENT_ADDON')) {
1166 $conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
1167 } elseif (getDolGlobalString('PAYMENT_ADDON') == 'ant') {
1168 $conf->global->PAYMENT_ADDON = 'mod_payment_ant';
1169 } elseif (getDolGlobalString('PAYMENT_ADDON') == 'cicada') {
1170 $conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
1171 }
1172
1173 if (getDolGlobalString('PAYMENT_ADDON')) {
1174 $mybool = false;
1175
1176 $file = getDolGlobalString('PAYMENT_ADDON') . ".php";
1177 $classname = getDolGlobalString('PAYMENT_ADDON');
1178
1179 // Include file with class
1180 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1181
1182 foreach ($dirmodels as $reldir) {
1183 $dir = dol_buildpath($reldir."core/modules/payment/");
1184
1185 // Load file with numbering class (if found)
1186 if (is_file($dir.$file) && is_readable($dir.$file)) {
1187 $mybool = (include_once $dir.$file) || $mybool;
1188 }
1189 }
1190
1191 // For compatibility
1192 if (!$mybool) {
1193 $file = getDolGlobalString('PAYMENT_ADDON') . ".php";
1194 $classname = "mod_payment_" . getDolGlobalString('PAYMENT_ADDON');
1195 $classname = preg_replace('/\-.*$/', '', $classname);
1196 // Include file with class
1197 foreach ($conf->file->dol_document_root as $dirroot) {
1198 $dir = $dirroot."/core/modules/payment/";
1199
1200 // Load file with numbering class (if found)
1201 if (is_file($dir.$file) && is_readable($dir.$file)) {
1202 $mybool = (include_once $dir.$file) || $mybool;
1203 }
1204 }
1205 }
1206
1207 if (!$mybool) {
1208 dol_print_error(null, "Failed to include file ".$file);
1209 return '';
1210 }
1211
1212 $obj = new $classname();
1213 $numref = "";
1214 $numref = $obj->getNextValue($soc, $this);
1215
1220 if ($mode != 'last' && !$numref) {
1221 dol_print_error($db, "Payment::getNextNumRef ".$obj->error);
1222 return "";
1223 }
1224
1225 return $numref;
1226 } else {
1227 $langs->load("errors");
1228 print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Invoice"));
1229 return "";
1230 }
1231 }
1232
1238 public function getWay()
1239 {
1240 global $conf;
1241
1242 $way = 'dolibarr';
1243 if (isModEnabled('multicurrency')) {
1244 foreach ($this->multicurrency_amounts as $value) {
1245 if (!empty($value)) { // one value found then payment is in invoice currency
1246 $way = 'customer';
1247 break;
1248 }
1249 }
1250 }
1251
1252 return $way;
1253 }
1254
1263 public function initAsSpecimen($option = '')
1264 {
1265 global $user, $langs, $conf;
1266
1267 $now = dol_now();
1268 $arraynow = dol_getdate($now);
1269 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
1270
1271 // Initialize parameters
1272 $this->id = 0;
1273 $this->ref = 'SPECIMEN';
1274 $this->specimen = 1;
1275 $this->facid = 1;
1276 $this->datepaye = $nownotime;
1277
1278 return 1;
1279 }
1280
1281
1292 public function getNomUrl($withpicto = 0, $option = '', $mode = 'withlistofinvoices', $notooltip = 0, $morecss = '')
1293 {
1294 global $conf, $langs, $hookmanager;
1295
1296 if (!empty($conf->dol_no_mouse_hover)) {
1297 $notooltip = 1; // Force disable tooltips
1298 }
1299
1300 $result = '';
1301
1302 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Payment").'</u><br>';
1303 $label .= '<strong>'.$langs->trans("Ref").':</strong> '.$this->ref;
1304 $dateofpayment = ($this->datepaye ? $this->datepaye : $this->date);
1305 if ($dateofpayment) {
1306 $label .= '<br><strong>'.$langs->trans("Date").':</strong> ';
1307 $tmparray = dol_getdate($dateofpayment);
1308 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
1309 $label .= dol_print_date($dateofpayment, 'day');
1310 } else { // Hours was set to real date of payment (special case for POS for example)
1311 $label .= dol_print_date($dateofpayment, 'dayhour', 'tzuser');
1312 }
1313 }
1314 if ($this->amount) {
1315 $label .= '<br><strong>'.$langs->trans("Amount").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
1316 }
1317 if ($mode == 'withlistofinvoices') {
1318 $arraybill = $this->getBillsArray();
1319 if (is_array($arraybill) && count($arraybill) > 0) {
1320 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1321 $facturestatic = new Facture($this->db);
1322 foreach ($arraybill as $billid) {
1323 $facturestatic->fetch($billid);
1324 $label .= '<br> '.$facturestatic->getNomUrl(1, '', 0, 0, '', 1).' '.$facturestatic->getLibStatut(2, 1);
1325 }
1326 }
1327 }
1328
1329 $linkclose = '';
1330 if (empty($notooltip)) {
1331 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1332 $label = $langs->trans("Payment");
1333 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1334 }
1335 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
1336 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
1337 } else {
1338 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1339 }
1340
1341 $url = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$this->id;
1342
1343 $linkstart = '<a href="'.$url.'"';
1344 $linkstart .= $linkclose.'>';
1345 $linkend = '</a>';
1346
1347 $result .= $linkstart;
1348 if ($withpicto) {
1349 $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);
1350 }
1351 if ($withpicto && $withpicto != 2) {
1352 $result .= ($this->ref ? $this->ref : $this->id);
1353 }
1354 $result .= $linkend;
1355 global $action;
1356 $hookmanager->initHooks(array($this->element . 'dao'));
1357 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1358 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1359 if ($reshook > 0) {
1360 $result = $hookmanager->resPrint;
1361 } else {
1362 $result .= $hookmanager->resPrint;
1363 }
1364 return $result;
1365 }
1366
1373 public function getLibStatut($mode = 0)
1374 {
1375 return $this->LibStatut($this->statut, $mode);
1376 }
1377
1378 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1386 public function LibStatut($status, $mode = 0)
1387 {
1388 // phpcs:enable
1389 global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage
1390
1391 $langs->load('compta');
1392 /*if ($mode == 0)
1393 {
1394 if ($status == 0) return $langs->trans('ToValidate');
1395 if ($status == 1) return $langs->trans('Validated');
1396 }
1397 if ($mode == 1)
1398 {
1399 if ($status == 0) return $langs->trans('ToValidate');
1400 if ($status == 1) return $langs->trans('Validated');
1401 }
1402 if ($mode == 2)
1403 {
1404 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
1405 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
1406 }
1407 if ($mode == 3)
1408 {
1409 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
1410 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
1411 }
1412 if ($mode == 4)
1413 {
1414 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
1415 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
1416 }
1417 if ($mode == 5)
1418 {
1419 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
1420 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
1421 }
1422 if ($mode == 6)
1423 {
1424 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
1425 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
1426 }*/
1427 return '';
1428 }
1429
1430 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1438 public function fetch_thirdparty($force_thirdparty_id = 0)
1439 {
1440 // phpcs:enable
1441 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1442
1443 if (empty($force_thirdparty_id)) {
1444 $billsarray = $this->getBillsArray(); // From payment, the fk_soc isn't available, we should load the first supplier invoice to get him
1445 if (!empty($billsarray)) {
1446 $invoice = new Facture($this->db);
1447 if ($invoice->fetch($billsarray[0]) > 0) {
1448 $force_thirdparty_id = $invoice->socid;
1449 }
1450 }
1451 }
1452
1453 return parent::fetch_thirdparty($force_thirdparty_id);
1454 }
1455
1456
1462 public function isReconciled()
1463 {
1464 $accountline = new AccountLine($this->db);
1465 $accountline->fetch($this->bank_line);
1466 return $accountline->rappro ? true : false;
1467 }
1468}
$object ref
Definition info.php:79
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='', $addbankurl='')
Add a record into bank for payment + links between this bank record and sources of payment.
__construct($db)
Constructor.
update_num($num_payment)
Updates the payment number.
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.
fetch($id, $ref='', $fk_bank=0)
Load payment from database.
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.
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.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e e e e e statut
Definition invoice.php:1991