dolibarr 22.0.5
paiement.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5 * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
6 * Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
7 * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
8 * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
9 * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
10 * Copyright (C) 2018 Thibault FOUCART <support@ptibogxiv.net>
11 * Copyright (C) 2018-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-2025 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
86 public $total;
87
93 public $montant;
94
98 public $amount;
99
103 public $multicurrency_amount;
104
108 public $multicurrency_currency;
109
113 public $amounts = array();
114
118 public $multicurrency_amounts = array();
119
123 public $multicurrency_tx = array();
124
128 public $multicurrency_code = array();
129
133 public $pos_change = 0.0;
134
138 public $author;
139
143 public $paiementid;
144
148 public $paiementcode;
149
153 public $type_label;
154
158 public $type_code;
159
165 public $num_paiement;
166
171 public $num_payment;
172
176 public $id_prelevement;
177
181 public $num_prelevement;
182
186 public $ext_payment_id;
187
191 public $ext_payment_site;
192
198 public $bank_account;
199
203 public $fk_account;
204
208 public $bank_line;
209
210 // fk_paiement dans llx_paiement est l'id du type de paiement (7 pour CHQ, ...)
211 // fk_paiement dans llx_paiement_facture est le rowid du paiement
215 public $fk_paiement; // Type of payment
216
220 public $ref_ext;
221
222
228 public function __construct($db)
229 {
230 $this->db = $db;
231 }
232
241 public function fetch($id, $ref = '', $fk_bank = 0)
242 {
243 $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,';
244 $sql .= ' c.code as type_code, c.libelle as type_label,';
245 $sql .= ' p.num_paiement as num_payment, p.note,';
246 $sql .= ' b.fk_account';
247 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id';
248 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
249 $sql .= ' WHERE p.entity IN ('.getEntity('invoice').')';
250 if ($id > 0) {
251 $sql .= ' AND p.rowid = '.((int) $id);
252 } elseif ($ref) {
253 $sql .= " AND p.ref = '".$this->db->escape($ref)."'";
254 } elseif ($fk_bank) {
255 $sql .= ' AND p.fk_bank = '.((int) $fk_bank);
256 }
257
258 $resql = $this->db->query($sql);
259 if ($resql) {
260 if ($this->db->num_rows($resql)) {
261 $obj = $this->db->fetch_object($resql);
262
263 $this->id = $obj->rowid;
264 $this->ref = $obj->ref ? $obj->ref : $obj->rowid;
265 $this->ref_ext = $obj->ref_ext;
266 $this->date = $this->db->jdate($obj->dp);
267 $this->datepaye = $this->db->jdate($obj->dp);
268 $this->num_payment = $obj->num_payment;
269 $this->montant = $obj->amount; // deprecated
270 $this->amount = $obj->amount;
271 $this->multicurrency_amount = $obj->multicurrency_amount;
272 $this->note = $obj->note;
273 $this->note_private = $obj->note;
274 $this->type_label = $obj->type_label;
275 $this->type_code = $obj->type_code;
276 $this->statut = $obj->statut;
277 $this->ext_payment_id = $obj->ext_payment_id;
278 $this->ext_payment_site = $obj->ext_payment_site;
279
280 $this->bank_account = $obj->fk_account; // deprecated
281 $this->fk_account = $obj->fk_account;
282 $this->bank_line = $obj->fk_bank;
283
284 $this->db->free($resql);
285 return 1;
286 } else {
287 $this->db->free($resql);
288 return 0;
289 }
290 } else {
291 dol_print_error($this->db);
292 return -1;
293 }
294 }
295
308 public function create($user, $closepaidinvoices = 0, $thirdparty = null)
309 {
310 global $conf, $langs;
311
312 $error = 0;
313 $way = $this->getWay(); // 'dolibarr' to use amount, 'customer' to use foreign multicurrency amount
314
315 $now = dol_now();
316
317 // Clean parameters
318 $totalamount = 0;
319 $totalamount_converted = 0;
320 $atleastonepaymentnotnull = 0;
321
322 if ($way == 'dolibarr') { // Payments were entered into the column of main currency
323 $amounts = &$this->amounts;
324 $amounts_to_update = &$this->multicurrency_amounts;
325 } else { // Payments were entered into the column of foreign currency
326 $amounts = &$this->multicurrency_amounts;
327 $amounts_to_update = &$this->amounts;
328 }
329
330 $currencyofpayment = '';
331 $currencyofinvoices = '';
332 $currencytxofpayment = '';
333
334 foreach ($amounts as $key => $value) { // How payment is dispatched. $key is ID of invoice
335 if (empty($value)) {
336 continue;
337 }
338 $value_converted = false;
339 $tmparray = MultiCurrency::getInvoiceRate($key, 'facture');
340 $invoice_multicurrency_tx = $tmparray['invoice_multicurrency_tx'];
341 $invoice_multicurrency_code = $tmparray['invoice_multicurrency_code'];
342
343 // $key is id of invoice, $value is amount, $way is 'dolibarr' if amount is in main currency, 'customer' if in foreign currency
344 if ($invoice_multicurrency_tx) {
345 if ($way == 'dolibarr') {
346 $value_converted = (float) price2num($value * $invoice_multicurrency_tx, 'MU');
347 } else {
348 $value_converted = (float) price2num($value / $invoice_multicurrency_tx, 'MU');
349 }
350 } else {
351 $invoice_multicurrency_tx = false;
352 }
353
354 // Add controls of input validity
355 if ($value_converted === false) {
356 // We failed to find the conversion for one invoice
357 $this->error = $langs->trans('FailedToFoundTheConversionRateForInvoice');
358 return -1;
359 }
360
361 // Set the currency of the invoice
362 $currencyofinvoiceforthisline = empty($this->multicurrency_code[$key]) ? $invoice_multicurrency_code : $this->multicurrency_code[$key];
363 // If a payment was entered into the section of the foreign currency of invoice, we want to pay in the currency of invoice
364 $currencyofpaymentforthisline = empty($this->multicurrency_amounts[$key]) ? $conf->currency : $this->multicurrency_code[$key];
365
366 //var_dump("Invoice ID: ".$key.", amount in company cur:".$this->amounts[$key]." amount in invoice cur:".$this->multicurrency_amounts[$key]." => currencyofinvoice= ".$currencyofinvoiceforthisline." - currencyofpaymentforthisline =".$currencyofpaymentforthisline);
367
368 if (empty($currencyofinvoices)) {
369 $currencyofinvoices = $currencyofinvoiceforthisline;
370 } elseif ($currencyofinvoices != $currencyofinvoiceforthisline) {
371 // If we have invoices with different currencies in the payment, we stop here
372 $this->error = 'ErrorYouTryToPayInvoicesWithDifferentCurrenciesInSamePayment';
373 return -1;
374 }
375
376 if (empty($currencyofpayment)) {
377 $currencyofpayment = $currencyofpaymentforthisline;
378 } elseif ($currencyofpayment != $currencyofpaymentforthisline) {
379 // If we have invoices with different currencies in the payment, we stop here
380 $this->error = 'ErrorYouTryToPayInvoicesWithDifferentCurrenciesInSamePayment';
381 return -1;
382 }
383
384 if (empty($currencytxofpayment)) {
385 $currencytxofpayment = isset($this->multicurrency_tx[$key]) ? $this->multicurrency_tx[$key] : "";
386 }
387
388 $totalamount_converted += $value_converted; // Total in currency of the invoice
389 $amounts_to_update[$key] = price2num($value_converted, 'MT');
390
391 $newvalue = price2num($value, 'MT');
392 $amounts[$key] = $newvalue;
393 $totalamount += $newvalue;
394 if (!empty($newvalue)) {
395 $atleastonepaymentnotnull++;
396 }
397
398 //var_dump('currencytxofpayment = '.$currencytxofpayment." totalamount_converted =".$totalamount_converted);
399 //print '<br>';
400 }
401
402 if (empty($currencyofpayment)) { // Should not happen. For the case the multicurrency_code was not saved into invoices
403 $currencyofpayment = $conf->currency;
404 }
405
406 if (!empty($currencyofpayment)) {
407 // We must check that the currency of invoices is the same than the currency of the bank
408 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
409 $bankaccount = new Account($this->db);
410 $bankaccount->fetch($this->fk_account);
411 $bankcurrencycode = empty($bankaccount->currency_code) ? $conf->currency : $bankaccount->currency_code;
412
413 if ($bankcurrencycode != $conf->currency) {
414 // If we try to pay on a bank with a different currency
415 if ($bankcurrencycode != $currencyofinvoices && $currencyofinvoices != $conf->currency) {
416 $langs->load("errors");
417 $this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofinvoices, $bankcurrencycode);
418 return -1;
419 }
420 if ($bankcurrencycode != $currencyofpayment && $currencyofpayment != $conf->currency) {
421 $langs->load("errors");
422 $this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofpayment, $bankcurrencycode);
423 return -1;
424 }
425 } else {
426 // No problem in this case
427 }
428 }
429
430 $totalamount = (float) price2num($totalamount, 'MT');
431 $totalamount_converted = (float) price2num($totalamount_converted, 'MT');
432
433 // Check parameters
434 if (empty($totalamount) && empty($atleastonepaymentnotnull)) { // We accept negative amounts for withdraw reject but not empty arrays
435 $this->errors[] = 'TotalAmountEmpty';
436 $this->error = $langs->trans('TotalAmountEmpty');
437 return -1;
438 }
439
440 dol_syslog(get_class($this)."::create insert paiement (closepaidinvoices = ".$closepaidinvoices.")", LOG_DEBUG);
441
442 $this->db->begin();
443
444 $this->ref = $this->getNextNumRef(is_object($thirdparty) ? $thirdparty : '');
445
446 if (empty($this->ref_ext)) {
447 $this->ref_ext = '';
448 }
449
450 if ($way == 'dolibarr') {
451 $total = $totalamount;
452 $mtotal = $totalamount_converted;
453 } else {
454 $total = $totalamount_converted;
455 $mtotal = $totalamount;
456 }
457
458 $num_payment = $this->num_payment;
459 $note = ($this->note_private ? $this->note_private : $this->note);
460
461 $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)";
462 $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).", ";
463 $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).")";
464
465 $resql = $this->db->query($sql);
466 if ($resql) {
467 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiement');
468
469 // Insert links amount / invoices
470 foreach ($this->amounts as $key => $amount) {
471 $facid = $key;
472 if (is_numeric($amount) && $amount != 0) {
473 $amount = price2num($amount);
474 $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount, multicurrency_amount, multicurrency_code, multicurrency_tx)";
475 $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).")";
476
477 dol_syslog(get_class($this).'::create Amount line '.$key.' insert paiement_facture', LOG_DEBUG);
478 $resql = $this->db->query($sql);
479 if ($resql) {
480 $invoice = new Facture($this->db);
481 $invoice->fetch($facid);
482
483 // If we want to closed paid invoices
484 if ($closepaidinvoices) {
485 $paiement = $invoice->getSommePaiement();
486 $creditnotes = $invoice->getSumCreditNotesUsed();
487 $deposits = $invoice->getSumDepositsUsed();
488 $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
489 $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
490
491 //var_dump($invoice->total_ttc.' - '.$paiement.' -'.$creditnotes.' - '.$deposits.' - '.$remaintopay);exit;
492
493 //Invoice types that are eligible for changing status to paid
494 $affected_types = array(
500 );
501
502 if (!in_array($invoice->type, $affected_types)) {
503 dol_syslog("Invoice ".$facid." is not a standard, nor replacement invoice, nor credit note, nor deposit invoice, nor situation invoice. We do nothing more.");
504 } elseif ($remaintopay) {
505 // hook to have an option to automatically close a closable invoice with less payment than the total amount (e.g. agreed cash discount terms)
506 global $hookmanager;
507 $hookmanager->initHooks(array('paymentdao'));
508 $parameters = array('facid' => $facid, 'invoice' => $invoice, 'remaintopay' => $remaintopay);
509 $action = 'CLOSEPAIDINVOICE';
510 $reshook = $hookmanager->executeHooks('createPayment', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
511 if ($reshook < 0) {
512 $this->errors[] = $hookmanager->error;
513 $this->error = $hookmanager->error;
514 $error++;
515 } elseif ($reshook == 0) {
516 dol_syslog("Remain to pay for invoice " . $facid . " not null. We do nothing more.");
517 }
518 // } else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more.");
519 } else {
520 // If invoice is a down payment, we also convert down payment to discount
521 if ($invoice->type == Facture::TYPE_DEPOSIT) {
522 $amount_ht = $amount_tva = $amount_ttc = array();
523 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
524 '
525 @phan-var-force array<string,float> $amount_ht
526 @phan-var-force array<string,float> $amount_tva
527 @phan-var-force array<string,float> $amount_ttc
528 @phan-var-force array<string,float> $multicurrency_amount_ht
529 @phan-var-force array<string,float> $multicurrency_amount_tva
530 @phan-var-force array<string,float> $multicurrency_amount_ttc
531 ';
532
533 // Insert one discount by VAT rate category
534 $discount = new DiscountAbsolute($this->db);
535 $discount->fetch(0, $invoice->id);
536 if (empty($discount->id)) { // If the invoice was not yet converted into a discount (this may have been done manually before we come here)
537 $discount->description = '(DEPOSIT)';
538 $discount->fk_soc = $invoice->socid;
539 $discount->socid = $invoice->socid;
540 $discount->fk_facture_source = $invoice->id;
541
542 // Loop on each vat rate
543 $i = 0;
544 foreach ($invoice->lines as $line) {
545 if ($line->product_type != 9 && $line->total_ht != 0) { // no need to create discount if amount is null or is special product
546 if (!array_key_exists($line->tva_tx, $amount_ht)) {
547 $amount_ht[$line->tva_tx] = 0.0;
548 $amount_tva[$line->tva_tx] = 0.0;
549 $amount_ttc[$line->tva_tx] = 0.0;
550 $multicurrency_amount_ht[$line->tva_tx] = 0.0;
551 $multicurrency_amount_tva[$line->tva_tx] = 0.0;
552 $multicurrency_amount_ttc[$line->tva_tx] = 0.0;
553 }
554 $amount_ht[$line->tva_tx] += $line->total_ht;
555 $amount_tva[$line->tva_tx] += $line->total_tva;
556 $amount_ttc[$line->tva_tx] += $line->total_ttc;
557 $multicurrency_amount_ht[$line->tva_tx] += $line->multicurrency_total_ht;
558 $multicurrency_amount_tva[$line->tva_tx] += $line->multicurrency_total_tva;
559 $multicurrency_amount_ttc[$line->tva_tx] += $line->multicurrency_total_ttc;
560 $i++;
561 }
562 }
563
564 foreach ($amount_ht as $tva_tx => $xxx) {
565 $discount->amount_ht = abs($amount_ht[$tva_tx]);
566 $discount->total_ht = abs($amount_ht[$tva_tx]);
567 $discount->amount_tva = abs($amount_tva[$tva_tx]);
568 $discount->total_tva = abs($amount_tva[$tva_tx]);
569 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
570 $discount->total_ttc = abs($amount_ttc[$tva_tx]);
571 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
572 $discount->multicurrency_total_ht = abs($multicurrency_amount_ht[$tva_tx]);
573 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
574 $discount->multicurrency_total_tva = abs($multicurrency_amount_tva[$tva_tx]);
575 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
576 $discount->multicurrency_total_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
577 $discount->tva_tx = abs((float) $tva_tx);
578
579 $result = $discount->create($user);
580 if ($result < 0) {
581 $error++;
582 break;
583 }
584 }
585 }
586
587 if ($error) {
588 $this->error = $discount->error;
589 $this->errors = $discount->errors;
590 $error++;
591 }
592 }
593
594 // Set invoice to paid
595 if (!$error) {
596 $invoice->context['actionmsgmore'] = 'Invoice set to paid by the payment->create() of payment '.$this->ref.' because the remain to pay is 0';
597
598 $result = $invoice->setPaid($user, '', '');
599 if ($result < 0) {
600 $this->error = $invoice->error;
601 $this->errors = $invoice->errors;
602 $error++;
603 }
604 }
605 }
606 }
607
608 // Regenerate documents of invoices
609 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
610 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);
611
612 $newlang = '';
613 $outputlangs = $langs;
614 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
615 $invoice->fetch_thirdparty();
616 $newlang = $invoice->thirdparty->default_lang;
617 }
618 if (!empty($newlang)) {
619 $outputlangs = new Translate("", $conf);
620 $outputlangs->setDefaultLang($newlang);
621 }
622
623 $hidedetails = getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0;
624 $hidedesc = getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0;
625 $hideref = getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0;
626
627 $ret = $invoice->fetch($facid); // Reload to get new records
628
629 $result = $invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
630
631 dol_syslog(get_class($this).'::create Regenerate end result='.$result, LOG_DEBUG);
632
633 if ($result < 0) {
634 $this->error = $invoice->error;
635 $this->errors = $invoice->errors;
636 $error++;
637 }
638 }
639 } else {
640 $this->error = $this->db->lasterror();
641 $error++;
642 }
643 } else {
644 dol_syslog(get_class($this).'::Create Amount line '.$key.' not a number. We discard it.');
645 }
646 }
647
648 dol_syslog(get_class($this).'::create Now we call the triggers if no error (error = '.$error.')', LOG_DEBUG);
649
650 if (!$error) { // All payments into $this->amounts were recorded without errors
651 // Appel des triggers
652 $result = $this->call_trigger('PAYMENT_CUSTOMER_CREATE', $user);
653 if ($result < 0) {
654 $error++;
655 }
656 // Fin appel triggers
657 }
658 } else {
659 $this->error = $this->db->lasterror();
660 $error++;
661 }
662
663 if (!$error) {
664 // Set some properties that may be used by other process after calling the create
665 $this->amount = $total;
666 $this->total = $total; // deprecated
667 $this->multicurrency_amount = $mtotal;
668 $this->multicurrency_currency = $currencyofinvoices;
669
670 $this->db->commit();
671 return $this->id;
672 } else {
673 $this->db->rollback();
674 return -1;
675 }
676 }
677
678
688 public function delete($user, $notrigger = 0)
689 {
690 $bank_line_id = $this->bank_line;
691
692 $this->db->begin();
693
694 // Verifier si paiement porte pas sur une facture classee
695 // Si c'est le cas, on refuse la suppression
696 $billsarray = $this->getBillsArray('f.fk_statut > 1');
697 if (is_array($billsarray)) {
698 if (count($billsarray)) {
699 $this->error = "ErrorDeletePaymentLinkedToAClosedInvoiceNotPossible";
700 $this->db->rollback();
701 return -1;
702 }
703 } else {
704 $this->db->rollback();
705 return -2;
706 }
707
708 // Delete bank urls. If payment is on a conciliated line, return error.
709 if ($bank_line_id > 0) {
710 $accline = new AccountLine($this->db);
711
712 $result = $accline->fetch($bank_line_id);
713 if ($result == 0) {
714 $accline->id = $accline->rowid = $bank_line_id; // If not found, we set artificially rowid to allow delete of llx_bank_url
715 }
716
717 // Delete bank account url lines linked to payment
718 $result = $accline->delete_urls($user);
719 if ($result < 0) {
720 $this->error = $accline->error;
721 $this->db->rollback();
722 return -3;
723 }
724
725 // Delete bank account lines linked to payment
726 $result = $accline->delete($user);
727 if ($result < 0) {
728 $this->error = $accline->error;
729 $this->db->rollback();
730 return -4;
731 }
732 }
733
734 if (!$notrigger) {
735 // Call triggers
736 $result = $this->call_trigger('PAYMENT_CUSTOMER_DELETE', $user);
737 if ($result < 0) {
738 $this->db->rollback();
739 return -1;
740 }
741 // End call triggers
742 }
743
744 // Delete payment (into paiement_facture and paiement)
745 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement_facture';
746 $sql .= ' WHERE fk_paiement = '.((int) $this->id);
747 dol_syslog($sql);
748 $result = $this->db->query($sql);
749 if ($result) {
750 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement';
751 $sql .= " WHERE rowid = ".((int) $this->id);
752 dol_syslog($sql);
753 $result = $this->db->query($sql);
754 if (!$result) {
755 $this->error = $this->db->lasterror();
756 $this->db->rollback();
757 return -3;
758 }
759
760 $this->db->commit();
761 return 1;
762 } else {
763 $this->error = $this->db->error;
764 $this->db->rollback();
765 return -5;
766 }
767 }
768
769
785 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque, $notrigger = 0, $accountancycode = '', $addbankurl = '')
786 {
787 global $conf, $user;
788
789 $error = 0;
790 $bank_line_id = 0;
791
792 // Note: ->amount (amount in company currency) ant multicurrency_amount (amount in )was set by the ->create beforecalling this.
793 // The create had also checked that currency of payment is same than currency of bank account
794
795 if (isModEnabled("bank")) {
796 if ($accountid <= 0) {
797 $this->error = 'Bad value for parameter accountid='.$accountid;
798 dol_syslog(get_class($this).'::addPaymentToBank '.$this->error, LOG_ERR);
799 return -1;
800 }
801
802 $this->fk_account = $accountid;
803
804 dol_syslog("addPaymentToBank ".$user->id.", ".$mode.", ".$label.", ".$this->fk_account.", ".$emetteur_nom.", ".$emetteur_banque);
805
806 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
807 $acc = new Account($this->db);
808 $result = $acc->fetch($this->fk_account);
809 if ($result < 0) {
810 $this->error = $acc->error;
811 $this->errors = $acc->errors;
812 $error++;
813 return -1;
814 }
815
816 $this->db->begin();
817
818 $totalamount = $this->amount;
819 $totalamount_main_currency = null;
820 if (empty($totalamount)) {
821 $totalamount = $this->total; // For backward compatibility
822 }
823
824 // this->amount is amount of payment in company currency
825 // this->multicurrency_amount of payment in other currency
826 // this->multicurrency_currency is the currency of the payment (may be same than the company one)
827 if ($this->multicurrency_currency == $conf->currency) {
828 if ($this->amount != $this->multicurrency_amount) {
829 // Add protection, should not happen
830 $error++;
831 $this->error = 'Payment in same currency than company but this->amount != this->multicurrency_amount';
832 }
833 }
834
835 // if company 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)
836 if ($conf->currency != $acc->currency_code) {
837 $totalamount = $this->multicurrency_amount; // We will insert into llx_bank.amount in foreign currency of invoice
838 $totalamount_main_currency = $this->amount; // We will also save the amount in main currency into column llx_bank.amount_main_currency
839 }
840
841 if ($mode == 'payment_supplier') {
842 $totalamount = -$totalamount;
843 if (isset($totalamount_main_currency)) {
844 $totalamount_main_currency = -$totalamount_main_currency;
845 }
846 }
847
848 // Insert payment into llx_bank
849 $bank_line_id = $acc->addline(
850 $this->datepaye,
851 $this->paiementcode ? $this->paiementcode : $this->paiementid, // Payment mode code ('CB', 'CHQ' or 'VIR' for example). Use payment id if not defined for backward compatibility.
852 $label,
853 $totalamount, // Sign must be positive when we receive money (customer payment), negative when you give money (supplier invoice or credit note)
854 $this->num_payment,
855 0,
856 $user,
857 $emetteur_nom,
858 $emetteur_banque,
859 $accountancycode,
860 0,
861 '',
862 (float) $totalamount_main_currency
863 );
864
865 // Mise a jour fk_bank dans llx_paiement
866 // On connait ainsi le paiement qui a genere l'ecriture bancaire
867 if ($bank_line_id > 0) {
868 $result = $this->update_fk_bank($bank_line_id);
869 if ($result <= 0) {
870 $error++;
871 dol_print_error($this->db);
872 }
873
874 // Add link 'payment', 'payment_supplier' in bank_url between payment and bank transaction
875 if (!$error) {
876 $url = '';
877 if ($mode == 'payment') {
878 $url = DOL_URL_ROOT.'/compta/paiement/card.php?id=';
879 }
880 if ($mode == 'payment_supplier') {
881 $url = DOL_URL_ROOT.'/fourn/paiement/card.php?id=';
882 }
883 if ($url) {
884 $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
885 if ($result <= 0) {
886 $error++;
887 dol_print_error($this->db);
888 }
889 }
890 }
891
892 // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
893 if (!$error) {
894 $linkaddedforthirdparty = array();
895 foreach ($this->amounts as $key => $value) { // We should have invoices always for same third party but we loop in case of.
896 if ($mode == 'payment') {
897 $fac = new Facture($this->db);
898 $fac->fetch($key);
899 $fac->fetch_thirdparty();
900 if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) { // Not yet done for this thirdparty @phan-suppress-current-line PhanPossiblyUndeclaredVariable
901 $result = $acc->add_url_line(
902 $bank_line_id,
903 $fac->thirdparty->id,
904 DOL_URL_ROOT.'/comm/card.php?socid=',
905 (string) $fac->thirdparty->name,
906 'company'
907 );
908 if ($result <= 0) {
909 $error++;
910 dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
911 }
912 $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
913 }
914 }
915 if ($mode == 'payment_supplier') {
916 $fac = new FactureFournisseur($this->db);
917 $fac->fetch($key);
918 $fac->fetch_thirdparty();
919 if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) { // Not yet done for this thirdparty
920 $result = $acc->add_url_line(
921 $bank_line_id,
922 $fac->thirdparty->id,
923 DOL_URL_ROOT.'/fourn/card.php?socid=',
924 (string) $fac->thirdparty->name,
925 'company'
926 );
927 if ($result <= 0) {
928 $error++;
929 dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
930 }
931 $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
932 }
933 }
934 }
935 }
936
937 // Add a link to the Direct Debit ('direct-debit') or Credit transfer ('credit-transfer') file in bank_url
938 if (!$error && $addbankurl && in_array($addbankurl, array('direct-debit', 'credit-transfer'))) {
939 $result = $acc->add_url_line(
940 $bank_line_id,
941 $this->id_prelevement,
942 DOL_URL_ROOT.'/compta/prelevement/card.php?id=',
943 $this->num_payment,
944 $addbankurl
945 );
946 }
947
948 // Add link to the Direct Debit if invoice refused ('InvoiceRefused') in bank_url
949 if (!$error && $label == '(InvoiceRefused)') {
950 $result = $acc->add_url_line(
951 $bank_line_id,
952 $this->id_prelevement,
953 DOL_URL_ROOT.'/compta/prelevement/card.php?id=',
954 $this->num_prelevement,
955 'withdraw'
956 );
957 }
958
959 if (!$error && !$notrigger) {
960 // Appel des triggers
961 $result = $this->call_trigger('PAYMENT_ADD_TO_BANK', $user);
962 if ($result < 0) {
963 $error++;
964 }
965 // Fin appel triggers
966 }
967 } else {
968 $this->error = $acc->error;
969 $this->errors = $acc->errors;
970 $error++;
971 }
972
973 if (!$error) {
974 $this->db->commit();
975 } else {
976 $this->db->rollback();
977 }
978 }
979
980 if (!$error) {
981 return $bank_line_id;
982 } else {
983 return -1;
984 }
985 }
986
987
988 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
995 public function update_fk_bank($id_bank)
996 {
997 // phpcs:enable
998 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' set fk_bank = '.((int) $id_bank);
999 $sql .= " WHERE rowid = ".((int) $this->id);
1000
1001 dol_syslog(get_class($this).'::update_fk_bank', LOG_DEBUG);
1002 $result = $this->db->query($sql);
1003 if ($result) {
1004 return 1;
1005 } else {
1006 $this->error = $this->db->lasterror();
1007 dol_syslog(get_class($this).'::update_fk_bank '.$this->error);
1008 return -1;
1009 }
1010 }
1011
1012 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1019 public function update_date($date)
1020 {
1021 // phpcs:enable
1022 $error = 0;
1023
1024 if (!empty($date) && $this->statut != 1) {
1025 $this->db->begin();
1026
1027 dol_syslog(get_class($this)."::update_date with date = ".$date, LOG_DEBUG);
1028
1029 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1030 $sql .= " SET datep = '".$this->db->idate($date)."'";
1031 $sql .= " WHERE rowid = ".((int) $this->id);
1032
1033 $result = $this->db->query($sql);
1034 if (!$result) {
1035 $error++;
1036 $this->error = 'Error -1 '.$this->db->error();
1037 }
1038
1039 $type = $this->element;
1040
1041 $sql = "UPDATE ".MAIN_DB_PREFIX.'bank';
1042 $sql .= " SET dateo = '".$this->db->idate($date)."', datev = '".$this->db->idate($date)."'";
1043 $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).")";
1044 $sql .= " AND rappro = 0";
1045
1046 $result = $this->db->query($sql);
1047 if (!$result) {
1048 $error++;
1049 $this->error = 'Error -1 '.$this->db->error();
1050 }
1051
1052 if (!$error) {
1053 $this->datepaye = $date;
1054 $this->date = $date;
1055
1056 $this->db->commit();
1057 return 0;
1058 } else {
1059 $this->db->rollback();
1060 return -2;
1061 }
1062 }
1063 return -1; //no date given or already validated
1064 }
1065
1066 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1073 public function update_num($num_payment)
1074 {
1075 // phpcs:enable
1076 if (!empty($num_payment) && $this->statut != 1) {
1077 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1078 $sql .= " SET num_paiement = '".$this->db->escape($num_payment)."'";
1079 $sql .= " WHERE rowid = ".((int) $this->id);
1080
1081 dol_syslog(get_class($this)."::update_num", LOG_DEBUG);
1082 $result = $this->db->query($sql);
1083 if ($result) {
1084 $this->num_payment = $this->db->escape($num_payment);
1085 return 0;
1086 } else {
1087 $this->error = 'Error -1 '.$this->db->error();
1088 return -2;
1089 }
1090 }
1091 return -1; //no num given or already validated
1092 }
1093
1101 public function valide($user = null)
1102 {
1103 return $this->validate($user);
1104 }
1105
1112 public function validate($user = null)
1113 {
1114 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET statut = 1 WHERE rowid = '.((int) $this->id);
1115
1116 dol_syslog(get_class($this).'::valide', LOG_DEBUG);
1117 $result = $this->db->query($sql);
1118 if ($result) {
1119 return 1;
1120 } else {
1121 $this->error = $this->db->lasterror();
1122 dol_syslog(get_class($this).'::valide '.$this->error);
1123 return -1;
1124 }
1125 }
1126
1133 public function reject($user = null)
1134 {
1135 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET statut = 2 WHERE rowid = '.((int) $this->id);
1136
1137 dol_syslog(get_class($this).'::reject', LOG_DEBUG);
1138 $result = $this->db->query($sql);
1139 if ($result) {
1140 return 1;
1141 } else {
1142 $this->error = $this->db->lasterror();
1143 dol_syslog(get_class($this).'::reject '.$this->error);
1144 return -1;
1145 }
1146 }
1147
1154 public function info($id)
1155 {
1156 $sql = 'SELECT p.rowid, p.datec, p.fk_user_creat, p.fk_user_modif, p.tms';
1157 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p';
1158 $sql .= ' WHERE p.rowid = '.((int) $id);
1159
1160 dol_syslog(get_class($this).'::info', LOG_DEBUG);
1161 $result = $this->db->query($sql);
1162
1163 if ($result) {
1164 if ($this->db->num_rows($result)) {
1165 $obj = $this->db->fetch_object($result);
1166
1167 $this->id = $obj->rowid;
1168
1169 $this->user_creation_id = $obj->fk_user_creat;
1170 $this->user_modification_id = $obj->fk_user_modif;
1171 $this->date_creation = $this->db->jdate($obj->datec);
1172 $this->date_modification = $this->db->jdate($obj->tms);
1173 }
1174 $this->db->free($result);
1175 } else {
1176 dol_print_error($this->db);
1177 }
1178 }
1179
1187 public function getBillsArray($filter = '')
1188 {
1189 $sql = 'SELECT pf.fk_facture';
1190 $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
1191 $sql .= ' WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = '.((int) $this->id);
1192 if ($filter) {
1193 $sql .= ' AND '.$filter;
1194 }
1195 $resql = $this->db->query($sql);
1196 if ($resql) {
1197 $i = 0;
1198 $num = $this->db->num_rows($resql);
1199 $billsarray = array();
1200
1201 while ($i < $num) {
1202 $obj = $this->db->fetch_object($resql);
1203 $billsarray[$i] = $obj->fk_facture;
1204 $i++;
1205 }
1206
1207 return $billsarray;
1208 } else {
1209 $this->error = $this->db->error();
1210 dol_syslog(get_class($this).'::getBillsArray Error '.$this->error.' -', LOG_DEBUG);
1211 return -1;
1212 }
1213 }
1214
1221 public function getAmountsArray()
1222 {
1223 $sql = 'SELECT pf.fk_facture, pf.amount';
1224 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
1225 $sql .= ' WHERE pf.fk_paiement = '.((int) $this->id);
1226 $resql = $this->db->query($sql);
1227 if ($resql) {
1228 $i = 0;
1229 $num = $this->db->num_rows($resql);
1230 $amounts = array();
1231
1232 while ($i < $num) {
1233 $obj = $this->db->fetch_object($resql);
1234 $amounts[$obj->fk_facture] = $obj->amount;
1235 $i++;
1236 }
1237
1238 return $amounts;
1239 } else {
1240 $this->error = $this->db->error();
1241 dol_syslog(get_class($this).'::getAmountsArray Error '.$this->error.' -', LOG_DEBUG);
1242 return -1;
1243 }
1244 }
1245
1254 public function getNextNumRef($soc, $mode = 'next')
1255 {
1256 global $conf, $db, $langs;
1257 $langs->load("bills");
1258
1259 // Clean parameters (if not defined or using deprecated value)
1260 if (!getDolGlobalString('PAYMENT_ADDON')) {
1261 $conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
1262 } elseif (getDolGlobalString('PAYMENT_ADDON') == 'ant') {
1263 $conf->global->PAYMENT_ADDON = 'mod_payment_ant';
1264 } elseif (getDolGlobalString('PAYMENT_ADDON') == 'cicada') {
1265 $conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
1266 }
1267
1268 if (getDolGlobalString('PAYMENT_ADDON')) {
1269 $mybool = false;
1270
1271 $file = getDolGlobalString('PAYMENT_ADDON') . ".php";
1272 $classname = getDolGlobalString('PAYMENT_ADDON');
1273
1274 // Include file with class
1275 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1276
1277 foreach ($dirmodels as $reldir) {
1278 $dir = dol_buildpath($reldir."core/modules/payment/");
1279
1280 // Load file with numbering class (if found)
1281 if (is_file($dir.$file) && is_readable($dir.$file)) {
1282 $mybool = (include_once $dir.$file) || $mybool;
1283 }
1284 }
1285
1286 // For compatibility
1287 if (!$mybool) {
1288 $file = getDolGlobalString('PAYMENT_ADDON') . ".php";
1289 $classname = "mod_payment_" . getDolGlobalString('PAYMENT_ADDON');
1290 $classname = preg_replace('/\-.*$/', '', $classname);
1291 // Include file with class
1292 foreach ($conf->file->dol_document_root as $dirroot) {
1293 $dir = $dirroot."/core/modules/payment/";
1294
1295 // Load file with numbering class (if found)
1296 if (is_file($dir.$file) && is_readable($dir.$file)) {
1297 $mybool = (include_once $dir.$file) || $mybool;
1298 }
1299 }
1300 }
1301
1302 if (!$mybool) {
1303 dol_print_error(null, "Failed to include file ".$file);
1304 return '';
1305 }
1306
1307 $obj = new $classname();
1308 '@phan-var-force ModeleNumRefPayments $obj';
1309
1310 $numref = $obj->getNextValue($soc, $this);
1311
1316 if ($mode != 'last' && !$numref) {
1317 dol_print_error($db, "Payment::getNextNumRef ".$obj->error);
1318 return "";
1319 }
1320
1321 return $numref;
1322 } else {
1323 $langs->load("errors");
1324 print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Invoice"));
1325 return "";
1326 }
1327 }
1328
1334 public function getWay()
1335 {
1336 $way = 'dolibarr';
1337 if (isModEnabled('multicurrency')) {
1338 foreach ($this->multicurrency_amounts as $value) {
1339 if (!empty($value)) { // one value found into multicurrency_amounts so payment is in invoice currency
1340 $way = 'customer';
1341 break;
1342 }
1343 }
1344 }
1345
1346 return $way;
1347 }
1348
1357 public function initAsSpecimen($option = '')
1358 {
1359 global $user, $langs, $conf;
1360
1361 $now = dol_now();
1362 $arraynow = dol_getdate($now);
1363 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
1364
1365 // Initialize parameters
1366 $this->id = 0;
1367 $this->ref = 'SPECIMEN';
1368 $this->specimen = 1;
1369 $this->facid = 1;
1370 $this->datepaye = $nownotime;
1371
1372 return 1;
1373 }
1374
1375
1386 public function getNomUrl($withpicto = 0, $option = '', $mode = 'withlistofinvoices', $notooltip = 0, $morecss = '')
1387 {
1388 global $conf, $langs, $hookmanager;
1389
1390 if (!empty($conf->dol_no_mouse_hover)) {
1391 $notooltip = 1; // Force disable tooltips
1392 }
1393
1394 $result = '';
1395
1396 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Payment").'</u><br>';
1397 $label .= '<strong>'.$langs->trans("Ref").':</strong> '.$this->ref;
1398 $dateofpayment = ($this->datepaye ? $this->datepaye : $this->date);
1399 if ($dateofpayment) {
1400 $label .= '<br><strong>'.$langs->trans("Date").':</strong> ';
1401 $tmparray = dol_getdate($dateofpayment);
1402 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
1403 $label .= dol_print_date($dateofpayment, 'day');
1404 } else { // Hours was set to real date of payment (special case for POS for example)
1405 $label .= dol_print_date($dateofpayment, 'dayhour', 'tzuser');
1406 }
1407 }
1408 if ($this->amount) {
1409 $label .= '<br><strong>'.$langs->trans("Amount").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
1410 }
1411 if ($mode == 'withlistofinvoices') {
1412 $arraybill = $this->getBillsArray();
1413 if (is_array($arraybill) && count($arraybill) > 0) {
1414 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1415 $facturestatic = new Facture($this->db);
1416 foreach ($arraybill as $billid) {
1417 $facturestatic->fetch($billid);
1418 $label .= '<br> '.$facturestatic->getNomUrl(1, '', 0, 0, '', 1).' '.$facturestatic->getLibStatut(2, -1);
1419 }
1420 }
1421 }
1422
1423 $linkclose = '';
1424 if (empty($notooltip)) {
1425 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1426 $label = $langs->trans("Payment");
1427 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
1428 }
1429 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
1430 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
1431 } else {
1432 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1433 }
1434
1435 $url = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$this->id;
1436
1437 $linkstart = '<a href="'.$url.'"';
1438 $linkstart .= $linkclose.'>';
1439 $linkend = '</a>';
1440
1441 $result .= $linkstart;
1442 if ($withpicto) {
1443 $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);
1444 }
1445 if ($withpicto && $withpicto != 2) {
1446 $result .= ($this->ref ? $this->ref : $this->id);
1447 }
1448 $result .= $linkend;
1449 global $action;
1450 $hookmanager->initHooks(array($this->element . 'dao'));
1451 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1452 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1453 if ($reshook > 0) {
1454 $result = $hookmanager->resPrint;
1455 } else {
1456 $result .= $hookmanager->resPrint;
1457 }
1458 return $result;
1459 }
1460
1467 public function getLibStatut($mode = 0)
1468 {
1469 return $this->LibStatut($this->statut, $mode);
1470 }
1471
1472 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1480 public function LibStatut($status, $mode = 0)
1481 {
1482 // phpcs:enable
1483 global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage
1484
1485 $langs->load('compta');
1486 /*if ($mode == 0)
1487 {
1488 if ($status == 0) return $langs->trans('ToValidate');
1489 if ($status == 1) return $langs->trans('Validated');
1490 }
1491 if ($mode == 1)
1492 {
1493 if ($status == 0) return $langs->trans('ToValidate');
1494 if ($status == 1) return $langs->trans('Validated');
1495 }
1496 if ($mode == 2)
1497 {
1498 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
1499 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
1500 }
1501 if ($mode == 3)
1502 {
1503 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
1504 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
1505 }
1506 if ($mode == 4)
1507 {
1508 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
1509 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
1510 }
1511 if ($mode == 5)
1512 {
1513 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
1514 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
1515 }
1516 if ($mode == 6)
1517 {
1518 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
1519 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
1520 }*/
1521 return '';
1522 }
1523
1524 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1532 public function fetch_thirdparty($force_thirdparty_id = 0)
1533 {
1534 // phpcs:enable
1535 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1536
1537 if (empty($force_thirdparty_id)) {
1538 $billsarray = $this->getBillsArray(); // From payment, the fk_soc isn't available, we should load the first supplier invoice to get him
1539 if (!empty($billsarray)) {
1540 $invoice = new Facture($this->db);
1541 if ($invoice->fetch($billsarray[0]) > 0) {
1542 $force_thirdparty_id = $invoice->socid;
1543 }
1544 }
1545 }
1546
1547 return parent::fetch_thirdparty($force_thirdparty_id);
1548 }
1549
1550
1556 public function isReconciled()
1557 {
1558 $accountline = new AccountLine($this->db);
1559 $accountline->fetch($this->bank_line);
1560 return $accountline->rappro ? true : false;
1561 }
1562}
$object ref
Definition info.php:90
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 getInvoiceRate($fk_facture, $table='facture')
Get current invoite 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.
getAmountsArray()
Return list of amounts of payments.
getNomUrl($withpicto=0, $option='', $mode='withlistofinvoices', $notooltip=0, $morecss='')
Return clickable 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)
Update the link between the Payment and the line generated in llx_bank.
getWay()
get the right way of payment
validate($user=null)
Validate payment.
reject($user=null)
Reject 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.
valide($user=null)
Validate payment.
info($id)
Information sur l'objet.
getLibStatut($mode=0)
Return the label of the status.
Class to manage translations.
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_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
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 '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
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_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 a 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79