dolibarr 21.0.0-alpha
paiement.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
5 * Copyright (C) 2012 Cédric Salvador <csalvador@gpcsolutions.fr>
6 * Copyright (C) 2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
7 * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
8 * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
9 * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
10 * Copyright (C) 2018 Thibault FOUCART <support@ptibogxiv.net>
11 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2020 Andreu Bisquerra Gaya <jove@bisquerra.com>
13 * Copyright (C) 2021 OpenDsi <support@open-dsi.fr>
14 * Copyright (C) 2023 Joachim Kueter <git-jk@bloxera.com>
15 * Copyright (C) 2023 Sylvain Legrand <technique@infras.fr>
16 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 3 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <https://www.gnu.org/licenses/>.
30 */
31
37require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
38require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php';
39
40
45{
49 public $element = 'payment';
50
54 public $table_element = 'paiement';
55
59 public $picto = 'payment';
60
64 public $facid;
65
69 public $socid;
70
74 public $datepaye;
75
79 public $date;
80
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 $ext_payment_id;
177
181 public $id_prelevement;
182
186 public $num_prelevement;
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
307 public function create($user, $closepaidinvoices = 0, $thirdparty = null)
308 {
309 global $conf, $langs;
310
311 $error = 0;
312 $way = $this->getWay(); // 'dolibarr' to use amount, 'customer' to use foreign multicurrency amount
313
314 $now = dol_now();
315
316 // Clean parameters
317 $totalamount = 0;
318 $totalamount_converted = 0;
319 $atleastonepaymentnotnull = 0;
320
321 if ($way == 'dolibarr') { // Payments were entered into the column of main currency
322 $amounts = &$this->amounts;
323 $amounts_to_update = &$this->multicurrency_amounts;
324 } else { // Payments were entered into the column of foreign currency
325 $amounts = &$this->multicurrency_amounts;
326 $amounts_to_update = &$this->amounts;
327 }
328
329 $currencyofpayment = '';
330 $currencyofinvoices = '';
331 $currencytxofpayment = '';
332
333 foreach ($amounts as $key => $value) { // How payment is dispatched. $key is ID of invoice
334 if (empty($value)) {
335 continue;
336 }
337 // $key is id of invoice, $value is amount, $way is a 'dolibarr' if amount is in main currency, 'customer' if in foreign currency
338 $value_converted = MultiCurrency::getAmountConversionFromInvoiceRate($key, $value, $way);
339 // Add controls of input validity
340 if ($value_converted === false) {
341 // We failed to find the conversion for one invoice
342 $this->error = $langs->trans('FailedToFoundTheConversionRateForInvoice');
343 return -1;
344 }
345
346 // Set the currency of the invoice
347 $currencyofinvoiceforthisline = empty($this->multicurrency_code[$key]) ? $conf->currency : $this->multicurrency_code[$key];
348 // If a payment was enter into section of foreign currency of invoice, we want to pay in the currency if invoice
349 $currencyofpaymentforthisline = empty($this->multicurrency_amounts[$key]) ? $conf->currency : $this->multicurrency_code[$key];
350
351 //var_dump("Invoice ID: ".$key.", amount in company cur:".$this->amounts[$key]." amount in invoice cur:".$this->multicurrency_amounts[$key]." => currencyofinvoice= ".$currencyofinvoiceforthisline." - currencyofpaymentforthisline =".$currencyofpaymentforthisline);
352
353 if (empty($currencyofinvoices)) {
354 $currencyofinvoices = $currencyofinvoiceforthisline;
355 } elseif ($currencyofinvoices != $currencyofinvoiceforthisline) {
356 // If we have invoices with different currencies in the payment, we stop here
357 $this->error = 'ErrorYouTryToPayInvoicesWithDifferentCurrenciesInSamePayment';
358 return -1;
359 }
360
361 if (empty($currencyofpayment)) {
362 $currencyofpayment = $currencyofpaymentforthisline;
363 } elseif ($currencyofpayment != $currencyofpaymentforthisline) {
364 // If we have invoices with different currencies in the payment, we stop here
365 $this->error = 'ErrorYouTryToPayInvoicesWithDifferentCurrenciesInSamePayment';
366 return -1;
367 }
368
369 if (empty($currencytxofpayment)) {
370 $currencytxofpayment = isset($this->multicurrency_tx[$key]) ? $this->multicurrency_tx[$key] : "";
371 }
372
373 $totalamount_converted += $value_converted; // Total in currency of the invoice
374 $amounts_to_update[$key] = price2num($value_converted, 'MT');
375
376 $newvalue = price2num($value, 'MT');
377 $amounts[$key] = $newvalue;
378 $totalamount += $newvalue;
379 if (!empty($newvalue)) {
380 $atleastonepaymentnotnull++;
381 }
382
383 //var_dump('currencytxofpayment = '.$currencytxofpayment." totalamount_converted =".$totalamount_converted);
384 //print '<br>';
385 }
386
387 if (empty($currencyofpayment)) { // Should not happen. For the case the multicurrency_code was not saved into invoices
388 $currencyofpayment = $conf->currency;
389 }
390
391 if (!empty($currencyofpayment)) {
392 // We must check that the currency of invoices is the same than the currency of the bank
393 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
394 $bankaccount = new Account($this->db);
395 $bankaccount->fetch($this->fk_account);
396 $bankcurrencycode = empty($bankaccount->currency_code) ? $conf->currency : $bankaccount->currency_code;
397
398 if ($bankcurrencycode != $conf->currency) {
399 // If we try to pay on a bank with a different currency
400 if ($bankcurrencycode != $currencyofinvoices && $currencyofinvoices != $conf->currency) {
401 $langs->load("errors");
402 $this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofinvoices, $bankcurrencycode);
403 return -1;
404 }
405 if ($bankcurrencycode != $currencyofpayment && $currencyofpayment != $conf->currency) {
406 $langs->load("errors");
407 $this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofpayment, $bankcurrencycode);
408 return -1;
409 }
410 } else {
411 // No problem in this case
412 }
413 }
414
415 $totalamount = (float) price2num($totalamount);
416 $totalamount_converted = (float) price2num($totalamount_converted);
417
418 // Check parameters
419 if (empty($totalamount) && empty($atleastonepaymentnotnull)) { // We accept negative amounts for withdraw reject but not empty arrays
420 $this->errors[] = 'TotalAmountEmpty';
421 $this->error = $langs->trans('TotalAmountEmpty');
422 return -1;
423 }
424
425 dol_syslog(get_class($this)."::create insert paiement (closepaidinvoices = ".$closepaidinvoices.")", LOG_DEBUG);
426
427 $this->db->begin();
428
429 $this->ref = $this->getNextNumRef(is_object($thirdparty) ? $thirdparty : '');
430
431 if (empty($this->ref_ext)) {
432 $this->ref_ext = '';
433 }
434
435 if ($way == 'dolibarr') {
436 $total = $totalamount;
437 $mtotal = $totalamount_converted;
438 } else {
439 $total = $totalamount_converted;
440 $mtotal = $totalamount;
441 }
442
443 $num_payment = $this->num_payment;
444 $note = ($this->note_private ? $this->note_private : $this->note);
445
446 $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)";
447 $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).", ";
448 $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).")";
449
450 $resql = $this->db->query($sql);
451 if ($resql) {
452 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiement');
453
454 // Insert links amount / invoices
455 foreach ($this->amounts as $key => $amount) {
456 $facid = $key;
457 if (is_numeric($amount) && $amount != 0) {
458 $amount = price2num($amount);
459 $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount, multicurrency_amount, multicurrency_code, multicurrency_tx)";
460 $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).")";
461
462 dol_syslog(get_class($this).'::create Amount line '.$key.' insert paiement_facture', LOG_DEBUG);
463 $resql = $this->db->query($sql);
464 if ($resql) {
465 $invoice = new Facture($this->db);
466 $invoice->fetch($facid);
467
468 // If we want to closed paid invoices
469 if ($closepaidinvoices) {
470 $paiement = $invoice->getSommePaiement();
471 $creditnotes = $invoice->getSumCreditNotesUsed();
472 $deposits = $invoice->getSumDepositsUsed();
473 $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
474 $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
475
476 //var_dump($invoice->total_ttc.' - '.$paiement.' -'.$creditnotes.' - '.$deposits.' - '.$remaintopay);exit;
477
478 //Invoice types that are eligible for changing status to paid
479 $affected_types = array(
485 );
486
487 if (!in_array($invoice->type, $affected_types)) {
488 dol_syslog("Invoice ".$facid." is not a standard, nor replacement invoice, nor credit note, nor deposit invoice, nor situation invoice. We do nothing more.");
489 } elseif ($remaintopay) {
490 // hook to have an option to automatically close a closable invoice with less payment than the total amount (e.g. agreed cash discount terms)
491 global $hookmanager;
492 $hookmanager->initHooks(array('paymentdao'));
493 $parameters = array('facid' => $facid, 'invoice' => $invoice, 'remaintopay' => $remaintopay);
494 $action = 'CLOSEPAIDINVOICE';
495 $reshook = $hookmanager->executeHooks('createPayment', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
496 if ($reshook < 0) {
497 $this->errors[] = $hookmanager->error;
498 $this->error = $hookmanager->error;
499 $error++;
500 } elseif ($reshook == 0) {
501 dol_syslog("Remain to pay for invoice " . $facid . " not null. We do nothing more.");
502 }
503 // } else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more.");
504 } else {
505 // If invoice is a down payment, we also convert down payment to discount
506 if ($invoice->type == Facture::TYPE_DEPOSIT) {
507 $amount_ht = $amount_tva = $amount_ttc = array();
508 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
509 '
510 @phan-var-force array<string,float> $amount_ht
511 @phan-var-force array<string,float> $amount_tva
512 @phan-var-force array<string,float> $amount_ttc
513 @phan-var-force array<string,float> $multicurrency_amount_ht
514 @phan-var-force array<string,float> $multicurrency_amount_tva
515 @phan-var-force array<string,float> $multicurrency_amount_ttc
516 ';
517
518 // Insert one discount by VAT rate category
519 $discount = new DiscountAbsolute($this->db);
520 $discount->fetch(0, $invoice->id);
521 if (empty($discount->id)) { // If the invoice was not yet converted into a discount (this may have been done manually before we come here)
522 $discount->description = '(DEPOSIT)';
523 $discount->fk_soc = $invoice->socid;
524 $discount->socid = $invoice->socid;
525 $discount->fk_facture_source = $invoice->id;
526
527 // Loop on each vat rate
528 $i = 0;
529 foreach ($invoice->lines as $line) {
530 if ($line->total_ht != 0) { // no need to create discount if amount is null
531 if (!array_key_exists($line->tva_tx, $amount_ht)) {
532 $amount_ht[$line->tva_tx] = 0.0;
533 $amount_tva[$line->tva_tx] = 0.0;
534 $amount_ttc[$line->tva_tx] = 0.0;
535 $multicurrency_amount_ht[$line->tva_tx] = 0.0;
536 $multicurrency_amount_tva[$line->tva_tx] = 0.0;
537 $multicurrency_amount_ttc[$line->tva_tx] = 0.0;
538 }
539 $amount_ht[$line->tva_tx] += $line->total_ht;
540 $amount_tva[$line->tva_tx] += $line->total_tva;
541 $amount_ttc[$line->tva_tx] += $line->total_ttc;
542 $multicurrency_amount_ht[$line->tva_tx] += $line->multicurrency_total_ht;
543 $multicurrency_amount_tva[$line->tva_tx] += $line->multicurrency_total_tva;
544 $multicurrency_amount_ttc[$line->tva_tx] += $line->multicurrency_total_ttc;
545 $i++;
546 }
547 }
548
549 foreach ($amount_ht as $tva_tx => $xxx) {
550 $discount->amount_ht = abs($amount_ht[$tva_tx]);
551 $discount->amount_tva = abs($amount_tva[$tva_tx]);
552 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
553 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
554 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
555 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
556 $discount->tva_tx = abs((float) $tva_tx);
557
558 $result = $discount->create($user);
559 if ($result < 0) {
560 $error++;
561 break;
562 }
563 }
564 }
565
566 if ($error) {
567 $this->error = $discount->error;
568 $this->errors = $discount->errors;
569 $error++;
570 }
571 }
572
573 // Set invoice to paid
574 if (!$error) {
575 $invoice->context['actionmsgmore'] = 'Invoice set to paid by the payment->create() of payment '.$this->ref.' because the remain to pay is 0';
576
577 $result = $invoice->setPaid($user, '', '');
578 if ($result < 0) {
579 $this->error = $invoice->error;
580 $this->errors = $invoice->errors;
581 $error++;
582 }
583 }
584 }
585 }
586
587 // Regenerate documents of invoices
588 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
589 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);
590
591 $newlang = '';
592 $outputlangs = $langs;
593 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
594 $invoice->fetch_thirdparty();
595 $newlang = $invoice->thirdparty->default_lang;
596 }
597 if (!empty($newlang)) {
598 $outputlangs = new Translate("", $conf);
599 $outputlangs->setDefaultLang($newlang);
600 }
601
602 $hidedetails = getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0;
603 $hidedesc = getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0;
604 $hideref = getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0;
605
606 $ret = $invoice->fetch($facid); // Reload to get new records
607
608 $result = $invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
609
610 dol_syslog(get_class($this).'::create Regenerate end result='.$result, LOG_DEBUG);
611
612 if ($result < 0) {
613 $this->error = $invoice->error;
614 $this->errors = $invoice->errors;
615 $error++;
616 }
617 }
618 } else {
619 $this->error = $this->db->lasterror();
620 $error++;
621 }
622 } else {
623 dol_syslog(get_class($this).'::Create Amount line '.$key.' not a number. We discard it.');
624 }
625 }
626
627 dol_syslog(get_class($this).'::create Now we call the triggers if no error (error = '.$error.')', LOG_DEBUG);
628
629 if (!$error) { // All payments into $this->amounts were recorded without errors
630 // Appel des triggers
631 $result = $this->call_trigger('PAYMENT_CUSTOMER_CREATE', $user);
632 if ($result < 0) {
633 $error++;
634 }
635 // Fin appel triggers
636 }
637 } else {
638 $this->error = $this->db->lasterror();
639 $error++;
640 }
641
642 if (!$error) {
643 // Set some properties that may be used by other process after calling the create
644 $this->amount = $total;
645 $this->total = $total; // deprecated
646 $this->multicurrency_amount = $mtotal;
647 $this->multicurrency_currency = $currencyofinvoices;
648
649 $this->db->commit();
650 return $this->id;
651 } else {
652 $this->db->rollback();
653 return -1;
654 }
655 }
656
657
667 public function delete($user, $notrigger = 0)
668 {
669 $bank_line_id = $this->bank_line;
670
671 $this->db->begin();
672
673 // Verifier si paiement porte pas sur une facture classee
674 // Si c'est le cas, on refuse la suppression
675 $billsarray = $this->getBillsArray('f.fk_statut > 1');
676 if (is_array($billsarray)) {
677 if (count($billsarray)) {
678 $this->error = "ErrorDeletePaymentLinkedToAClosedInvoiceNotPossible";
679 $this->db->rollback();
680 return -1;
681 }
682 } else {
683 $this->db->rollback();
684 return -2;
685 }
686
687 // Delete bank urls. If payment is on a conciliated line, return error.
688 if ($bank_line_id > 0) {
689 $accline = new AccountLine($this->db);
690
691 $result = $accline->fetch($bank_line_id);
692 if ($result == 0) {
693 $accline->id = $accline->rowid = $bank_line_id; // If not found, we set artificially rowid to allow delete of llx_bank_url
694 }
695
696 // Delete bank account url lines linked to payment
697 $result = $accline->delete_urls($user);
698 if ($result < 0) {
699 $this->error = $accline->error;
700 $this->db->rollback();
701 return -3;
702 }
703
704 // Delete bank account lines linked to payment
705 $result = $accline->delete($user);
706 if ($result < 0) {
707 $this->error = $accline->error;
708 $this->db->rollback();
709 return -4;
710 }
711 }
712
713 if (!$notrigger) {
714 // Call triggers
715 $result = $this->call_trigger('PAYMENT_CUSTOMER_DELETE', $user);
716 if ($result < 0) {
717 $this->db->rollback();
718 return -1;
719 }
720 // End call triggers
721 }
722
723 // Delete payment (into paiement_facture and paiement)
724 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement_facture';
725 $sql .= ' WHERE fk_paiement = '.((int) $this->id);
726 dol_syslog($sql);
727 $result = $this->db->query($sql);
728 if ($result) {
729 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement';
730 $sql .= " WHERE rowid = ".((int) $this->id);
731 dol_syslog($sql);
732 $result = $this->db->query($sql);
733 if (!$result) {
734 $this->error = $this->db->lasterror();
735 $this->db->rollback();
736 return -3;
737 }
738
739 $this->db->commit();
740 return 1;
741 } else {
742 $this->error = $this->db->error;
743 $this->db->rollback();
744 return -5;
745 }
746 }
747
748
764 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque, $notrigger = 0, $accountancycode = '', $addbankurl = '')
765 {
766 global $conf, $user;
767
768 $error = 0;
769 $bank_line_id = 0;
770
771 // Note: ->amount (amount in company currency) ant multicurrency_amount (amount in )was set by the ->create beforecalling this.
772 // The create had also checked that currency of payment is same than currency of bank account
773
774 if (isModEnabled("bank")) {
775 if ($accountid <= 0) {
776 $this->error = 'Bad value for parameter accountid='.$accountid;
777 dol_syslog(get_class($this).'::addPaymentToBank '.$this->error, LOG_ERR);
778 return -1;
779 }
780
781 $this->fk_account = $accountid;
782
783 dol_syslog("addPaymentToBank ".$user->id.", ".$mode.", ".$label.", ".$this->fk_account.", ".$emetteur_nom.", ".$emetteur_banque);
784
785 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
786 $acc = new Account($this->db);
787 $result = $acc->fetch($this->fk_account);
788 if ($result < 0) {
789 $this->error = $acc->error;
790 $this->errors = $acc->errors;
791 $error++;
792 return -1;
793 }
794
795 $this->db->begin();
796
797 $totalamount = $this->amount;
798 $totalamount_main_currency = null;
799 if (empty($totalamount)) {
800 $totalamount = $this->total; // For backward compatibility
801 }
802
803 // this->amount is amount of payment in company currency
804 // this->multicurrency_amount of payment in other currency
805 // this->multicurrency_currency is the currency of the payment (may be same than the company one)
806 if ($this->multicurrency_currency == $conf->currency) {
807 if ($this->amount != $this->multicurrency_amount) {
808 // Add protection, should not happen
809 $error++;
810 $this->error = 'Payment in same currency than company but this->amount != this->multicurrency_amount';
811 }
812 }
813
814 // 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)
815 if ($conf->currency != $acc->currency_code) {
816 $totalamount = $this->multicurrency_amount; // We will insert into llx_bank.amount in foreign currency of invoice
817 $totalamount_main_currency = $this->amount; // We will also save the amount in main currency into column llx_bank.amount_main_currency
818 }
819
820 if ($mode == 'payment_supplier') {
821 $totalamount = -$totalamount;
822 if (isset($totalamount_main_currency)) {
823 $totalamount_main_currency = -$totalamount_main_currency;
824 }
825 }
826
827 // Insert payment into llx_bank
828 $bank_line_id = $acc->addline(
829 $this->datepaye,
830 $this->paiementcode ? $this->paiementcode : $this->paiementid, // Payment mode code ('CB', 'CHQ' or 'VIR' for example). Use payment id if not defined for backward compatibility.
831 $label,
832 $totalamount, // Sign must be positive when we receive money (customer payment), negative when you give money (supplier invoice or credit note)
833 $this->num_payment,
834 0,
835 $user,
836 $emetteur_nom,
837 $emetteur_banque,
838 $accountancycode,
839 0,
840 '',
841 $totalamount_main_currency
842 );
843
844 // Mise a jour fk_bank dans llx_paiement
845 // On connait ainsi le paiement qui a genere l'ecriture bancaire
846 if ($bank_line_id > 0) {
847 $result = $this->update_fk_bank($bank_line_id);
848 if ($result <= 0) {
849 $error++;
850 dol_print_error($this->db);
851 }
852
853 // Add link 'payment', 'payment_supplier' in bank_url between payment and bank transaction
854 if (!$error) {
855 $url = '';
856 if ($mode == 'payment') {
857 $url = DOL_URL_ROOT.'/compta/paiement/card.php?id=';
858 }
859 if ($mode == 'payment_supplier') {
860 $url = DOL_URL_ROOT.'/fourn/paiement/card.php?id=';
861 }
862 if ($url) {
863 $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
864 if ($result <= 0) {
865 $error++;
866 dol_print_error($this->db);
867 }
868 }
869 }
870
871 // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
872 if (!$error) {
873 $linkaddedforthirdparty = array();
874 foreach ($this->amounts as $key => $value) { // We should have invoices always for same third party but we loop in case of.
875 if ($mode == 'payment') {
876 $fac = new Facture($this->db);
877 $fac->fetch($key);
878 $fac->fetch_thirdparty();
879 if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) { // Not yet done for this thirdparty
880 $result = $acc->add_url_line(
881 $bank_line_id,
882 $fac->thirdparty->id,
883 DOL_URL_ROOT.'/comm/card.php?socid=',
884 $fac->thirdparty->name,
885 'company'
886 );
887 if ($result <= 0) {
888 dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
889 }
890 $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
891 }
892 }
893 if ($mode == 'payment_supplier') {
894 $fac = new FactureFournisseur($this->db);
895 $fac->fetch($key);
896 $fac->fetch_thirdparty();
897 if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) { // Not yet done for this thirdparty
898 $result = $acc->add_url_line(
899 $bank_line_id,
900 $fac->thirdparty->id,
901 DOL_URL_ROOT.'/fourn/card.php?socid=',
902 $fac->thirdparty->name,
903 'company'
904 );
905 if ($result <= 0) {
906 dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
907 }
908 $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
909 }
910 }
911 }
912 }
913
914 // Add a link to the Direct Debit ('direct-debit') or Credit transfer ('credit-transfer') file in bank_url
915 if (!$error && $addbankurl && in_array($addbankurl, array('direct-debit', 'credit-transfer'))) {
916 $result = $acc->add_url_line(
917 $bank_line_id,
918 $this->id_prelevement,
919 DOL_URL_ROOT.'/compta/prelevement/card.php?id=',
920 $this->num_payment,
921 $addbankurl
922 );
923 }
924
925 // Add link to the Direct Debit if invoice refused ('InvoiceRefused') in bank_url
926 if (!$error && $label == '(InvoiceRefused)') {
927 $result = $acc->add_url_line(
928 $bank_line_id,
929 $this->id_prelevement,
930 DOL_URL_ROOT.'/compta/prelevement/card.php?id=',
931 $this->num_prelevement,
932 'withdraw'
933 );
934 }
935
936 if (!$error && !$notrigger) {
937 // Appel des triggers
938 $result = $this->call_trigger('PAYMENT_ADD_TO_BANK', $user);
939 if ($result < 0) {
940 $error++;
941 }
942 // Fin appel triggers
943 }
944 } else {
945 $this->error = $acc->error;
946 $this->errors = $acc->errors;
947 $error++;
948 }
949
950 if (!$error) {
951 $this->db->commit();
952 } else {
953 $this->db->rollback();
954 }
955 }
956
957 if (!$error) {
958 return $bank_line_id;
959 } else {
960 return -1;
961 }
962 }
963
964
965 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
972 public function update_fk_bank($id_bank)
973 {
974 // phpcs:enable
975 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' set fk_bank = '.((int) $id_bank);
976 $sql .= " WHERE rowid = ".((int) $this->id);
977
978 dol_syslog(get_class($this).'::update_fk_bank', LOG_DEBUG);
979 $result = $this->db->query($sql);
980 if ($result) {
981 return 1;
982 } else {
983 $this->error = $this->db->lasterror();
984 dol_syslog(get_class($this).'::update_fk_bank '.$this->error);
985 return -1;
986 }
987 }
988
989 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
996 public function update_date($date)
997 {
998 // phpcs:enable
999 $error = 0;
1000
1001 if (!empty($date) && $this->statut != 1) {
1002 $this->db->begin();
1003
1004 dol_syslog(get_class($this)."::update_date with date = ".$date, LOG_DEBUG);
1005
1006 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1007 $sql .= " SET datep = '".$this->db->idate($date)."'";
1008 $sql .= " WHERE rowid = ".((int) $this->id);
1009
1010 $result = $this->db->query($sql);
1011 if (!$result) {
1012 $error++;
1013 $this->error = 'Error -1 '.$this->db->error();
1014 }
1015
1016 $type = $this->element;
1017
1018 $sql = "UPDATE ".MAIN_DB_PREFIX.'bank';
1019 $sql .= " SET dateo = '".$this->db->idate($date)."', datev = '".$this->db->idate($date)."'";
1020 $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).")";
1021 $sql .= " AND rappro = 0";
1022
1023 $result = $this->db->query($sql);
1024 if (!$result) {
1025 $error++;
1026 $this->error = 'Error -1 '.$this->db->error();
1027 }
1028
1029 if (!$error) {
1030 $this->datepaye = $date;
1031 $this->date = $date;
1032
1033 $this->db->commit();
1034 return 0;
1035 } else {
1036 $this->db->rollback();
1037 return -2;
1038 }
1039 }
1040 return -1; //no date given or already validated
1041 }
1042
1043 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1050 public function update_num($num_payment)
1051 {
1052 // phpcs:enable
1053 if (!empty($num_payment) && $this->statut != 1) {
1054 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1055 $sql .= " SET num_paiement = '".$this->db->escape($num_payment)."'";
1056 $sql .= " WHERE rowid = ".((int) $this->id);
1057
1058 dol_syslog(get_class($this)."::update_num", LOG_DEBUG);
1059 $result = $this->db->query($sql);
1060 if ($result) {
1061 $this->num_payment = $this->db->escape($num_payment);
1062 return 0;
1063 } else {
1064 $this->error = 'Error -1 '.$this->db->error();
1065 return -2;
1066 }
1067 }
1068 return -1; //no num given or already validated
1069 }
1070
1078 public function valide($user = null)
1079 {
1080 return $this->validate($user);
1081 }
1082
1089 public function validate($user = null)
1090 {
1091 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET statut = 1 WHERE rowid = '.((int) $this->id);
1092
1093 dol_syslog(get_class($this).'::valide', LOG_DEBUG);
1094 $result = $this->db->query($sql);
1095 if ($result) {
1096 return 1;
1097 } else {
1098 $this->error = $this->db->lasterror();
1099 dol_syslog(get_class($this).'::valide '.$this->error);
1100 return -1;
1101 }
1102 }
1103
1110 public function reject($user = null)
1111 {
1112 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET statut = 2 WHERE rowid = '.((int) $this->id);
1113
1114 dol_syslog(get_class($this).'::reject', LOG_DEBUG);
1115 $result = $this->db->query($sql);
1116 if ($result) {
1117 return 1;
1118 } else {
1119 $this->error = $this->db->lasterror();
1120 dol_syslog(get_class($this).'::reject '.$this->error);
1121 return -1;
1122 }
1123 }
1124
1131 public function info($id)
1132 {
1133 $sql = 'SELECT p.rowid, p.datec, p.fk_user_creat, p.fk_user_modif, p.tms';
1134 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p';
1135 $sql .= ' WHERE p.rowid = '.((int) $id);
1136
1137 dol_syslog(get_class($this).'::info', LOG_DEBUG);
1138 $result = $this->db->query($sql);
1139
1140 if ($result) {
1141 if ($this->db->num_rows($result)) {
1142 $obj = $this->db->fetch_object($result);
1143
1144 $this->id = $obj->rowid;
1145
1146 $this->user_creation_id = $obj->fk_user_creat;
1147 $this->user_modification_id = $obj->fk_user_modif;
1148 $this->date_creation = $this->db->jdate($obj->datec);
1149 $this->date_modification = $this->db->jdate($obj->tms);
1150 }
1151 $this->db->free($result);
1152 } else {
1153 dol_print_error($this->db);
1154 }
1155 }
1156
1164 public function getBillsArray($filter = '')
1165 {
1166 $sql = 'SELECT pf.fk_facture';
1167 $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
1168 $sql .= ' WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = '.((int) $this->id);
1169 if ($filter) {
1170 $sql .= ' AND '.$filter;
1171 }
1172 $resql = $this->db->query($sql);
1173 if ($resql) {
1174 $i = 0;
1175 $num = $this->db->num_rows($resql);
1176 $billsarray = array();
1177
1178 while ($i < $num) {
1179 $obj = $this->db->fetch_object($resql);
1180 $billsarray[$i] = $obj->fk_facture;
1181 $i++;
1182 }
1183
1184 return $billsarray;
1185 } else {
1186 $this->error = $this->db->error();
1187 dol_syslog(get_class($this).'::getBillsArray Error '.$this->error.' -', LOG_DEBUG);
1188 return -1;
1189 }
1190 }
1191
1198 public function getAmountsArray()
1199 {
1200 $sql = 'SELECT pf.fk_facture, pf.amount';
1201 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
1202 $sql .= ' WHERE pf.fk_paiement = '.((int) $this->id);
1203 $resql = $this->db->query($sql);
1204 if ($resql) {
1205 $i = 0;
1206 $num = $this->db->num_rows($resql);
1207 $amounts = array();
1208
1209 while ($i < $num) {
1210 $obj = $this->db->fetch_object($resql);
1211 $amounts[$obj->fk_facture] = $obj->amount;
1212 $i++;
1213 }
1214
1215 return $amounts;
1216 } else {
1217 $this->error = $this->db->error();
1218 dol_syslog(get_class($this).'::getAmountsArray Error '.$this->error.' -', LOG_DEBUG);
1219 return -1;
1220 }
1221 }
1222
1231 public function getNextNumRef($soc, $mode = 'next')
1232 {
1233 global $conf, $db, $langs;
1234 $langs->load("bills");
1235
1236 // Clean parameters (if not defined or using deprecated value)
1237 if (!getDolGlobalString('PAYMENT_ADDON')) {
1238 $conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
1239 } elseif (getDolGlobalString('PAYMENT_ADDON') == 'ant') {
1240 $conf->global->PAYMENT_ADDON = 'mod_payment_ant';
1241 } elseif (getDolGlobalString('PAYMENT_ADDON') == 'cicada') {
1242 $conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
1243 }
1244
1245 if (getDolGlobalString('PAYMENT_ADDON')) {
1246 $mybool = false;
1247
1248 $file = getDolGlobalString('PAYMENT_ADDON') . ".php";
1249 $classname = getDolGlobalString('PAYMENT_ADDON');
1250
1251 // Include file with class
1252 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1253
1254 foreach ($dirmodels as $reldir) {
1255 $dir = dol_buildpath($reldir."core/modules/payment/");
1256
1257 // Load file with numbering class (if found)
1258 if (is_file($dir.$file) && is_readable($dir.$file)) {
1259 $mybool = (include_once $dir.$file) || $mybool;
1260 }
1261 }
1262
1263 // For compatibility
1264 if (!$mybool) {
1265 $file = getDolGlobalString('PAYMENT_ADDON') . ".php";
1266 $classname = "mod_payment_" . getDolGlobalString('PAYMENT_ADDON');
1267 $classname = preg_replace('/\-.*$/', '', $classname);
1268 // Include file with class
1269 foreach ($conf->file->dol_document_root as $dirroot) {
1270 $dir = $dirroot."/core/modules/payment/";
1271
1272 // Load file with numbering class (if found)
1273 if (is_file($dir.$file) && is_readable($dir.$file)) {
1274 $mybool = (include_once $dir.$file) || $mybool;
1275 }
1276 }
1277 }
1278
1279 if (!$mybool) {
1280 dol_print_error(null, "Failed to include file ".$file);
1281 return '';
1282 }
1283
1284 $obj = new $classname();
1285 '@phan-var-force ModeleNumRefPayments $obj';
1286
1287 $numref = $obj->getNextValue($soc, $this);
1288
1293 if ($mode != 'last' && !$numref) {
1294 dol_print_error($db, "Payment::getNextNumRef ".$obj->error);
1295 return "";
1296 }
1297
1298 return $numref;
1299 } else {
1300 $langs->load("errors");
1301 print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Invoice"));
1302 return "";
1303 }
1304 }
1305
1311 public function getWay()
1312 {
1313 global $conf;
1314
1315 $way = 'dolibarr';
1316 if (isModEnabled('multicurrency')) {
1317 foreach ($this->multicurrency_amounts as $value) {
1318 if (!empty($value)) { // one value found then payment is in invoice currency
1319 $way = 'customer';
1320 break;
1321 }
1322 }
1323 }
1324
1325 return $way;
1326 }
1327
1336 public function initAsSpecimen($option = '')
1337 {
1338 global $user, $langs, $conf;
1339
1340 $now = dol_now();
1341 $arraynow = dol_getdate($now);
1342 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
1343
1344 // Initialize parameters
1345 $this->id = 0;
1346 $this->ref = 'SPECIMEN';
1347 $this->specimen = 1;
1348 $this->facid = 1;
1349 $this->datepaye = $nownotime;
1350
1351 return 1;
1352 }
1353
1354
1365 public function getNomUrl($withpicto = 0, $option = '', $mode = 'withlistofinvoices', $notooltip = 0, $morecss = '')
1366 {
1367 global $conf, $langs, $hookmanager;
1368
1369 if (!empty($conf->dol_no_mouse_hover)) {
1370 $notooltip = 1; // Force disable tooltips
1371 }
1372
1373 $result = '';
1374
1375 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Payment").'</u><br>';
1376 $label .= '<strong>'.$langs->trans("Ref").':</strong> '.$this->ref;
1377 $dateofpayment = ($this->datepaye ? $this->datepaye : $this->date);
1378 if ($dateofpayment) {
1379 $label .= '<br><strong>'.$langs->trans("Date").':</strong> ';
1380 $tmparray = dol_getdate($dateofpayment);
1381 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
1382 $label .= dol_print_date($dateofpayment, 'day');
1383 } else { // Hours was set to real date of payment (special case for POS for example)
1384 $label .= dol_print_date($dateofpayment, 'dayhour', 'tzuser');
1385 }
1386 }
1387 if ($this->amount) {
1388 $label .= '<br><strong>'.$langs->trans("Amount").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
1389 }
1390 if ($mode == 'withlistofinvoices') {
1391 $arraybill = $this->getBillsArray();
1392 if (is_array($arraybill) && count($arraybill) > 0) {
1393 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1394 $facturestatic = new Facture($this->db);
1395 foreach ($arraybill as $billid) {
1396 $facturestatic->fetch($billid);
1397 $label .= '<br> '.$facturestatic->getNomUrl(1, '', 0, 0, '', 1).' '.$facturestatic->getLibStatut(2, -1);
1398 }
1399 }
1400 }
1401
1402 $linkclose = '';
1403 if (empty($notooltip)) {
1404 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1405 $label = $langs->trans("Payment");
1406 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1407 }
1408 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
1409 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
1410 } else {
1411 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1412 }
1413
1414 $url = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$this->id;
1415
1416 $linkstart = '<a href="'.$url.'"';
1417 $linkstart .= $linkclose.'>';
1418 $linkend = '</a>';
1419
1420 $result .= $linkstart;
1421 if ($withpicto) {
1422 $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);
1423 }
1424 if ($withpicto && $withpicto != 2) {
1425 $result .= ($this->ref ? $this->ref : $this->id);
1426 }
1427 $result .= $linkend;
1428 global $action;
1429 $hookmanager->initHooks(array($this->element . 'dao'));
1430 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1431 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1432 if ($reshook > 0) {
1433 $result = $hookmanager->resPrint;
1434 } else {
1435 $result .= $hookmanager->resPrint;
1436 }
1437 return $result;
1438 }
1439
1446 public function getLibStatut($mode = 0)
1447 {
1448 return $this->LibStatut($this->statut, $mode);
1449 }
1450
1451 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1459 public function LibStatut($status, $mode = 0)
1460 {
1461 // phpcs:enable
1462 global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage
1463
1464 $langs->load('compta');
1465 /*if ($mode == 0)
1466 {
1467 if ($status == 0) return $langs->trans('ToValidate');
1468 if ($status == 1) return $langs->trans('Validated');
1469 }
1470 if ($mode == 1)
1471 {
1472 if ($status == 0) return $langs->trans('ToValidate');
1473 if ($status == 1) return $langs->trans('Validated');
1474 }
1475 if ($mode == 2)
1476 {
1477 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
1478 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
1479 }
1480 if ($mode == 3)
1481 {
1482 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
1483 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
1484 }
1485 if ($mode == 4)
1486 {
1487 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
1488 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
1489 }
1490 if ($mode == 5)
1491 {
1492 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
1493 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
1494 }
1495 if ($mode == 6)
1496 {
1497 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
1498 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
1499 }*/
1500 return '';
1501 }
1502
1503 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1511 public function fetch_thirdparty($force_thirdparty_id = 0)
1512 {
1513 // phpcs:enable
1514 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1515
1516 if (empty($force_thirdparty_id)) {
1517 $billsarray = $this->getBillsArray(); // From payment, the fk_soc isn't available, we should load the first supplier invoice to get him
1518 if (!empty($billsarray)) {
1519 $invoice = new Facture($this->db);
1520 if ($invoice->fetch($billsarray[0]) > 0) {
1521 $force_thirdparty_id = $invoice->socid;
1522 }
1523 }
1524 }
1525
1526 return parent::fetch_thirdparty($force_thirdparty_id);
1527 }
1528
1529
1535 public function isReconciled()
1536 {
1537 $accountline = new AccountLine($this->db);
1538 $accountline->fetch($this->bank_line);
1539 return $accountline->rappro ? true : false;
1540 }
1541}
$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.
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_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return 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.