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