dolibarr 21.0.0-beta
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 $value_converted = false;
338 $tmparray = MultiCurrency::getInvoiceRate($key, 'facture');
339 $invoice_multicurrency_tx = $tmparray['invoice_multicurrency_tx'];
340 $invoice_multicurrency_code = $tmparray['invoice_multicurrency_code'];
341
342 // $key is id of invoice, $value is amount, $way is 'dolibarr' if amount is in main currency, 'customer' if in foreign currency
343 if ($invoice_multicurrency_tx) {
344 if ($way == 'dolibarr') {
345 $value_converted = (float) price2num($value * $invoice_multicurrency_tx, 'MU');
346 } else {
347 $value_converted = (float) price2num($value / $invoice_multicurrency_tx, 'MU');
348 }
349 } else {
350 $invoice_multicurrency_tx = false;
351 }
352
353 // Add controls of input validity
354 if ($value_converted === false) {
355 // We failed to find the conversion for one invoice
356 $this->error = $langs->trans('FailedToFoundTheConversionRateForInvoice');
357 return -1;
358 }
359
360 // Set the currency of the invoice
361 $currencyofinvoiceforthisline = empty($this->multicurrency_code[$key]) ? $invoice_multicurrency_code : $this->multicurrency_code[$key];
362 // If a payment was entered into the section of the foreign currency of invoice, we want to pay in the currency of invoice
363 $currencyofpaymentforthisline = empty($this->multicurrency_amounts[$key]) ? $conf->currency : $this->multicurrency_code[$key];
364
365 //var_dump("Invoice ID: ".$key.", amount in company cur:".$this->amounts[$key]." amount in invoice cur:".$this->multicurrency_amounts[$key]." => currencyofinvoice= ".$currencyofinvoiceforthisline." - currencyofpaymentforthisline =".$currencyofpaymentforthisline);
366
367 if (empty($currencyofinvoices)) {
368 $currencyofinvoices = $currencyofinvoiceforthisline;
369 } elseif ($currencyofinvoices != $currencyofinvoiceforthisline) {
370 // If we have invoices with different currencies in the payment, we stop here
371 $this->error = 'ErrorYouTryToPayInvoicesWithDifferentCurrenciesInSamePayment';
372 return -1;
373 }
374
375 if (empty($currencyofpayment)) {
376 $currencyofpayment = $currencyofpaymentforthisline;
377 } elseif ($currencyofpayment != $currencyofpaymentforthisline) {
378 // If we have invoices with different currencies in the payment, we stop here
379 $this->error = 'ErrorYouTryToPayInvoicesWithDifferentCurrenciesInSamePayment';
380 return -1;
381 }
382
383 if (empty($currencytxofpayment)) {
384 $currencytxofpayment = isset($this->multicurrency_tx[$key]) ? $this->multicurrency_tx[$key] : "";
385 }
386
387 $totalamount_converted += $value_converted; // Total in currency of the invoice
388 $amounts_to_update[$key] = price2num($value_converted, 'MT');
389
390 $newvalue = price2num($value, 'MT');
391 $amounts[$key] = $newvalue;
392 $totalamount += $newvalue;
393 if (!empty($newvalue)) {
394 $atleastonepaymentnotnull++;
395 }
396
397 //var_dump('currencytxofpayment = '.$currencytxofpayment." totalamount_converted =".$totalamount_converted);
398 //print '<br>';
399 }
400
401 if (empty($currencyofpayment)) { // Should not happen. For the case the multicurrency_code was not saved into invoices
402 $currencyofpayment = $conf->currency;
403 }
404
405 if (!empty($currencyofpayment)) {
406 // We must check that the currency of invoices is the same than the currency of the bank
407 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
408 $bankaccount = new Account($this->db);
409 $bankaccount->fetch($this->fk_account);
410 $bankcurrencycode = empty($bankaccount->currency_code) ? $conf->currency : $bankaccount->currency_code;
411
412 if ($bankcurrencycode != $conf->currency) {
413 // If we try to pay on a bank with a different currency
414 if ($bankcurrencycode != $currencyofinvoices && $currencyofinvoices != $conf->currency) {
415 $langs->load("errors");
416 $this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofinvoices, $bankcurrencycode);
417 return -1;
418 }
419 if ($bankcurrencycode != $currencyofpayment && $currencyofpayment != $conf->currency) {
420 $langs->load("errors");
421 $this->error = $langs->trans('ErrorYouTryToPayInvoicesInACurrencyFromBankWithAnotherCurrency', $currencyofpayment, $bankcurrencycode);
422 return -1;
423 }
424 } else {
425 // No problem in this case
426 }
427 }
428
429 $totalamount = (float) price2num($totalamount);
430 $totalamount_converted = (float) price2num($totalamount_converted);
431
432 // Check parameters
433 if (empty($totalamount) && empty($atleastonepaymentnotnull)) { // We accept negative amounts for withdraw reject but not empty arrays
434 $this->errors[] = 'TotalAmountEmpty';
435 $this->error = $langs->trans('TotalAmountEmpty');
436 return -1;
437 }
438
439 dol_syslog(get_class($this)."::create insert paiement (closepaidinvoices = ".$closepaidinvoices.")", LOG_DEBUG);
440
441 $this->db->begin();
442
443 $this->ref = $this->getNextNumRef(is_object($thirdparty) ? $thirdparty : '');
444
445 if (empty($this->ref_ext)) {
446 $this->ref_ext = '';
447 }
448
449 if ($way == 'dolibarr') {
450 $total = $totalamount;
451 $mtotal = $totalamount_converted;
452 } else {
453 $total = $totalamount_converted;
454 $mtotal = $totalamount;
455 }
456
457 $num_payment = $this->num_payment;
458 $note = ($this->note_private ? $this->note_private : $this->note);
459
460 $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)";
461 $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).", ";
462 $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).")";
463
464 $resql = $this->db->query($sql);
465 if ($resql) {
466 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiement');
467
468 // Insert links amount / invoices
469 foreach ($this->amounts as $key => $amount) {
470 $facid = $key;
471 if (is_numeric($amount) && $amount != 0) {
472 $amount = price2num($amount);
473 $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement_facture (fk_facture, fk_paiement, amount, multicurrency_amount, multicurrency_code, multicurrency_tx)";
474 $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).")";
475
476 dol_syslog(get_class($this).'::create Amount line '.$key.' insert paiement_facture', LOG_DEBUG);
477 $resql = $this->db->query($sql);
478 if ($resql) {
479 $invoice = new Facture($this->db);
480 $invoice->fetch($facid);
481
482 // If we want to closed paid invoices
483 if ($closepaidinvoices) {
484 $paiement = $invoice->getSommePaiement();
485 $creditnotes = $invoice->getSumCreditNotesUsed();
486 $deposits = $invoice->getSumDepositsUsed();
487 $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT');
488 $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT');
489
490 //var_dump($invoice->total_ttc.' - '.$paiement.' -'.$creditnotes.' - '.$deposits.' - '.$remaintopay);exit;
491
492 //Invoice types that are eligible for changing status to paid
493 $affected_types = array(
499 );
500
501 if (!in_array($invoice->type, $affected_types)) {
502 dol_syslog("Invoice ".$facid." is not a standard, nor replacement invoice, nor credit note, nor deposit invoice, nor situation invoice. We do nothing more.");
503 } elseif ($remaintopay) {
504 // hook to have an option to automatically close a closable invoice with less payment than the total amount (e.g. agreed cash discount terms)
505 global $hookmanager;
506 $hookmanager->initHooks(array('paymentdao'));
507 $parameters = array('facid' => $facid, 'invoice' => $invoice, 'remaintopay' => $remaintopay);
508 $action = 'CLOSEPAIDINVOICE';
509 $reshook = $hookmanager->executeHooks('createPayment', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
510 if ($reshook < 0) {
511 $this->errors[] = $hookmanager->error;
512 $this->error = $hookmanager->error;
513 $error++;
514 } elseif ($reshook == 0) {
515 dol_syslog("Remain to pay for invoice " . $facid . " not null. We do nothing more.");
516 }
517 // } else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more.");
518 } else {
519 // If invoice is a down payment, we also convert down payment to discount
520 if ($invoice->type == Facture::TYPE_DEPOSIT) {
521 $amount_ht = $amount_tva = $amount_ttc = array();
522 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
523 '
524 @phan-var-force array<string,float> $amount_ht
525 @phan-var-force array<string,float> $amount_tva
526 @phan-var-force array<string,float> $amount_ttc
527 @phan-var-force array<string,float> $multicurrency_amount_ht
528 @phan-var-force array<string,float> $multicurrency_amount_tva
529 @phan-var-force array<string,float> $multicurrency_amount_ttc
530 ';
531
532 // Insert one discount by VAT rate category
533 $discount = new DiscountAbsolute($this->db);
534 $discount->fetch(0, $invoice->id);
535 if (empty($discount->id)) { // If the invoice was not yet converted into a discount (this may have been done manually before we come here)
536 $discount->description = '(DEPOSIT)';
537 $discount->fk_soc = $invoice->socid;
538 $discount->socid = $invoice->socid;
539 $discount->fk_facture_source = $invoice->id;
540
541 // Loop on each vat rate
542 $i = 0;
543 foreach ($invoice->lines as $line) {
544 if ($line->total_ht != 0) { // no need to create discount if amount is null
545 if (!array_key_exists($line->tva_tx, $amount_ht)) {
546 $amount_ht[$line->tva_tx] = 0.0;
547 $amount_tva[$line->tva_tx] = 0.0;
548 $amount_ttc[$line->tva_tx] = 0.0;
549 $multicurrency_amount_ht[$line->tva_tx] = 0.0;
550 $multicurrency_amount_tva[$line->tva_tx] = 0.0;
551 $multicurrency_amount_ttc[$line->tva_tx] = 0.0;
552 }
553 $amount_ht[$line->tva_tx] += $line->total_ht;
554 $amount_tva[$line->tva_tx] += $line->total_tva;
555 $amount_ttc[$line->tva_tx] += $line->total_ttc;
556 $multicurrency_amount_ht[$line->tva_tx] += $line->multicurrency_total_ht;
557 $multicurrency_amount_tva[$line->tva_tx] += $line->multicurrency_total_tva;
558 $multicurrency_amount_ttc[$line->tva_tx] += $line->multicurrency_total_ttc;
559 $i++;
560 }
561 }
562
563 foreach ($amount_ht as $tva_tx => $xxx) {
564 $discount->amount_ht = abs($amount_ht[$tva_tx]);
565 $discount->amount_tva = abs($amount_tva[$tva_tx]);
566 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
567 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
568 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
569 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
570 $discount->tva_tx = abs((float) $tva_tx);
571
572 $result = $discount->create($user);
573 if ($result < 0) {
574 $error++;
575 break;
576 }
577 }
578 }
579
580 if ($error) {
581 $this->error = $discount->error;
582 $this->errors = $discount->errors;
583 $error++;
584 }
585 }
586
587 // Set invoice to paid
588 if (!$error) {
589 $invoice->context['actionmsgmore'] = 'Invoice set to paid by the payment->create() of payment '.$this->ref.' because the remain to pay is 0';
590
591 $result = $invoice->setPaid($user, '', '');
592 if ($result < 0) {
593 $this->error = $invoice->error;
594 $this->errors = $invoice->errors;
595 $error++;
596 }
597 }
598 }
599 }
600
601 // Regenerate documents of invoices
602 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
603 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);
604
605 $newlang = '';
606 $outputlangs = $langs;
607 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
608 $invoice->fetch_thirdparty();
609 $newlang = $invoice->thirdparty->default_lang;
610 }
611 if (!empty($newlang)) {
612 $outputlangs = new Translate("", $conf);
613 $outputlangs->setDefaultLang($newlang);
614 }
615
616 $hidedetails = getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0;
617 $hidedesc = getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0;
618 $hideref = getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0;
619
620 $ret = $invoice->fetch($facid); // Reload to get new records
621
622 $result = $invoice->generateDocument($invoice->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
623
624 dol_syslog(get_class($this).'::create Regenerate end result='.$result, LOG_DEBUG);
625
626 if ($result < 0) {
627 $this->error = $invoice->error;
628 $this->errors = $invoice->errors;
629 $error++;
630 }
631 }
632 } else {
633 $this->error = $this->db->lasterror();
634 $error++;
635 }
636 } else {
637 dol_syslog(get_class($this).'::Create Amount line '.$key.' not a number. We discard it.');
638 }
639 }
640
641 dol_syslog(get_class($this).'::create Now we call the triggers if no error (error = '.$error.')', LOG_DEBUG);
642
643 if (!$error) { // All payments into $this->amounts were recorded without errors
644 // Appel des triggers
645 $result = $this->call_trigger('PAYMENT_CUSTOMER_CREATE', $user);
646 if ($result < 0) {
647 $error++;
648 }
649 // Fin appel triggers
650 }
651 } else {
652 $this->error = $this->db->lasterror();
653 $error++;
654 }
655
656 if (!$error) {
657 // Set some properties that may be used by other process after calling the create
658 $this->amount = $total;
659 $this->total = $total; // deprecated
660 $this->multicurrency_amount = $mtotal;
661 $this->multicurrency_currency = $currencyofinvoices;
662
663 $this->db->commit();
664 return $this->id;
665 } else {
666 $this->db->rollback();
667 return -1;
668 }
669 }
670
671
681 public function delete($user, $notrigger = 0)
682 {
683 $bank_line_id = $this->bank_line;
684
685 $this->db->begin();
686
687 // Verifier si paiement porte pas sur une facture classee
688 // Si c'est le cas, on refuse la suppression
689 $billsarray = $this->getBillsArray('f.fk_statut > 1');
690 if (is_array($billsarray)) {
691 if (count($billsarray)) {
692 $this->error = "ErrorDeletePaymentLinkedToAClosedInvoiceNotPossible";
693 $this->db->rollback();
694 return -1;
695 }
696 } else {
697 $this->db->rollback();
698 return -2;
699 }
700
701 // Delete bank urls. If payment is on a conciliated line, return error.
702 if ($bank_line_id > 0) {
703 $accline = new AccountLine($this->db);
704
705 $result = $accline->fetch($bank_line_id);
706 if ($result == 0) {
707 $accline->id = $accline->rowid = $bank_line_id; // If not found, we set artificially rowid to allow delete of llx_bank_url
708 }
709
710 // Delete bank account url lines linked to payment
711 $result = $accline->delete_urls($user);
712 if ($result < 0) {
713 $this->error = $accline->error;
714 $this->db->rollback();
715 return -3;
716 }
717
718 // Delete bank account lines linked to payment
719 $result = $accline->delete($user);
720 if ($result < 0) {
721 $this->error = $accline->error;
722 $this->db->rollback();
723 return -4;
724 }
725 }
726
727 if (!$notrigger) {
728 // Call triggers
729 $result = $this->call_trigger('PAYMENT_CUSTOMER_DELETE', $user);
730 if ($result < 0) {
731 $this->db->rollback();
732 return -1;
733 }
734 // End call triggers
735 }
736
737 // Delete payment (into paiement_facture and paiement)
738 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement_facture';
739 $sql .= ' WHERE fk_paiement = '.((int) $this->id);
740 dol_syslog($sql);
741 $result = $this->db->query($sql);
742 if ($result) {
743 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiement';
744 $sql .= " WHERE rowid = ".((int) $this->id);
745 dol_syslog($sql);
746 $result = $this->db->query($sql);
747 if (!$result) {
748 $this->error = $this->db->lasterror();
749 $this->db->rollback();
750 return -3;
751 }
752
753 $this->db->commit();
754 return 1;
755 } else {
756 $this->error = $this->db->error;
757 $this->db->rollback();
758 return -5;
759 }
760 }
761
762
778 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque, $notrigger = 0, $accountancycode = '', $addbankurl = '')
779 {
780 global $conf, $user;
781
782 $error = 0;
783 $bank_line_id = 0;
784
785 // Note: ->amount (amount in company currency) ant multicurrency_amount (amount in )was set by the ->create beforecalling this.
786 // The create had also checked that currency of payment is same than currency of bank account
787
788 if (isModEnabled("bank")) {
789 if ($accountid <= 0) {
790 $this->error = 'Bad value for parameter accountid='.$accountid;
791 dol_syslog(get_class($this).'::addPaymentToBank '.$this->error, LOG_ERR);
792 return -1;
793 }
794
795 $this->fk_account = $accountid;
796
797 dol_syslog("addPaymentToBank ".$user->id.", ".$mode.", ".$label.", ".$this->fk_account.", ".$emetteur_nom.", ".$emetteur_banque);
798
799 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
800 $acc = new Account($this->db);
801 $result = $acc->fetch($this->fk_account);
802 if ($result < 0) {
803 $this->error = $acc->error;
804 $this->errors = $acc->errors;
805 $error++;
806 return -1;
807 }
808
809 $this->db->begin();
810
811 $totalamount = $this->amount;
812 $totalamount_main_currency = null;
813 if (empty($totalamount)) {
814 $totalamount = $this->total; // For backward compatibility
815 }
816
817 // this->amount is amount of payment in company currency
818 // this->multicurrency_amount of payment in other currency
819 // this->multicurrency_currency is the currency of the payment (may be same than the company one)
820 if ($this->multicurrency_currency == $conf->currency) {
821 if ($this->amount != $this->multicurrency_amount) {
822 // Add protection, should not happen
823 $error++;
824 $this->error = 'Payment in same currency than company but this->amount != this->multicurrency_amount';
825 }
826 }
827
828 // 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)
829 if ($conf->currency != $acc->currency_code) {
830 $totalamount = $this->multicurrency_amount; // We will insert into llx_bank.amount in foreign currency of invoice
831 $totalamount_main_currency = $this->amount; // We will also save the amount in main currency into column llx_bank.amount_main_currency
832 }
833
834 if ($mode == 'payment_supplier') {
835 $totalamount = -$totalamount;
836 if (isset($totalamount_main_currency)) {
837 $totalamount_main_currency = -$totalamount_main_currency;
838 }
839 }
840
841 // Insert payment into llx_bank
842 $bank_line_id = $acc->addline(
843 $this->datepaye,
844 $this->paiementcode ? $this->paiementcode : $this->paiementid, // Payment mode code ('CB', 'CHQ' or 'VIR' for example). Use payment id if not defined for backward compatibility.
845 $label,
846 $totalamount, // Sign must be positive when we receive money (customer payment), negative when you give money (supplier invoice or credit note)
847 $this->num_payment,
848 0,
849 $user,
850 $emetteur_nom,
851 $emetteur_banque,
852 $accountancycode,
853 0,
854 '',
855 $totalamount_main_currency
856 );
857
858 // Mise a jour fk_bank dans llx_paiement
859 // On connait ainsi le paiement qui a genere l'ecriture bancaire
860 if ($bank_line_id > 0) {
861 $result = $this->update_fk_bank($bank_line_id);
862 if ($result <= 0) {
863 $error++;
864 dol_print_error($this->db);
865 }
866
867 // Add link 'payment', 'payment_supplier' in bank_url between payment and bank transaction
868 if (!$error) {
869 $url = '';
870 if ($mode == 'payment') {
871 $url = DOL_URL_ROOT.'/compta/paiement/card.php?id=';
872 }
873 if ($mode == 'payment_supplier') {
874 $url = DOL_URL_ROOT.'/fourn/paiement/card.php?id=';
875 }
876 if ($url) {
877 $result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
878 if ($result <= 0) {
879 $error++;
880 dol_print_error($this->db);
881 }
882 }
883 }
884
885 // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
886 if (!$error) {
887 $linkaddedforthirdparty = array();
888 foreach ($this->amounts as $key => $value) { // We should have invoices always for same third party but we loop in case of.
889 if ($mode == 'payment') {
890 $fac = new Facture($this->db);
891 $fac->fetch($key);
892 $fac->fetch_thirdparty();
893 if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) { // Not yet done for this thirdparty @phan-suppress-current-line PhanPossiblyUndeclaredVariable
894 $result = $acc->add_url_line(
895 $bank_line_id,
896 $fac->thirdparty->id,
897 DOL_URL_ROOT.'/comm/card.php?socid=',
898 $fac->thirdparty->name,
899 'company'
900 );
901 if ($result <= 0) {
902 dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
903 }
904 $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
905 }
906 }
907 if ($mode == 'payment_supplier') {
908 $fac = new FactureFournisseur($this->db);
909 $fac->fetch($key);
910 $fac->fetch_thirdparty();
911 if (!in_array($fac->thirdparty->id, $linkaddedforthirdparty)) { // Not yet done for this thirdparty
912 $result = $acc->add_url_line(
913 $bank_line_id,
914 $fac->thirdparty->id,
915 DOL_URL_ROOT.'/fourn/card.php?socid=',
916 $fac->thirdparty->name,
917 'company'
918 );
919 if ($result <= 0) {
920 dol_syslog(get_class($this).'::addPaymentToBank '.$this->db->lasterror());
921 }
922 $linkaddedforthirdparty[$fac->thirdparty->id] = $fac->thirdparty->id; // Mark as done for this thirdparty
923 }
924 }
925 }
926 }
927
928 // Add a link to the Direct Debit ('direct-debit') or Credit transfer ('credit-transfer') file in bank_url
929 if (!$error && $addbankurl && in_array($addbankurl, array('direct-debit', 'credit-transfer'))) {
930 $result = $acc->add_url_line(
931 $bank_line_id,
932 $this->id_prelevement,
933 DOL_URL_ROOT.'/compta/prelevement/card.php?id=',
934 $this->num_payment,
935 $addbankurl
936 );
937 }
938
939 // Add link to the Direct Debit if invoice refused ('InvoiceRefused') in bank_url
940 if (!$error && $label == '(InvoiceRefused)') {
941 $result = $acc->add_url_line(
942 $bank_line_id,
943 $this->id_prelevement,
944 DOL_URL_ROOT.'/compta/prelevement/card.php?id=',
945 $this->num_prelevement,
946 'withdraw'
947 );
948 }
949
950 if (!$error && !$notrigger) {
951 // Appel des triggers
952 $result = $this->call_trigger('PAYMENT_ADD_TO_BANK', $user);
953 if ($result < 0) {
954 $error++;
955 }
956 // Fin appel triggers
957 }
958 } else {
959 $this->error = $acc->error;
960 $this->errors = $acc->errors;
961 $error++;
962 }
963
964 if (!$error) {
965 $this->db->commit();
966 } else {
967 $this->db->rollback();
968 }
969 }
970
971 if (!$error) {
972 return $bank_line_id;
973 } else {
974 return -1;
975 }
976 }
977
978
979 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
986 public function update_fk_bank($id_bank)
987 {
988 // phpcs:enable
989 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' set fk_bank = '.((int) $id_bank);
990 $sql .= " WHERE rowid = ".((int) $this->id);
991
992 dol_syslog(get_class($this).'::update_fk_bank', LOG_DEBUG);
993 $result = $this->db->query($sql);
994 if ($result) {
995 return 1;
996 } else {
997 $this->error = $this->db->lasterror();
998 dol_syslog(get_class($this).'::update_fk_bank '.$this->error);
999 return -1;
1000 }
1001 }
1002
1003 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1010 public function update_date($date)
1011 {
1012 // phpcs:enable
1013 $error = 0;
1014
1015 if (!empty($date) && $this->statut != 1) {
1016 $this->db->begin();
1017
1018 dol_syslog(get_class($this)."::update_date with date = ".$date, LOG_DEBUG);
1019
1020 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1021 $sql .= " SET datep = '".$this->db->idate($date)."'";
1022 $sql .= " WHERE rowid = ".((int) $this->id);
1023
1024 $result = $this->db->query($sql);
1025 if (!$result) {
1026 $error++;
1027 $this->error = 'Error -1 '.$this->db->error();
1028 }
1029
1030 $type = $this->element;
1031
1032 $sql = "UPDATE ".MAIN_DB_PREFIX.'bank';
1033 $sql .= " SET dateo = '".$this->db->idate($date)."', datev = '".$this->db->idate($date)."'";
1034 $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).")";
1035 $sql .= " AND rappro = 0";
1036
1037 $result = $this->db->query($sql);
1038 if (!$result) {
1039 $error++;
1040 $this->error = 'Error -1 '.$this->db->error();
1041 }
1042
1043 if (!$error) {
1044 $this->datepaye = $date;
1045 $this->date = $date;
1046
1047 $this->db->commit();
1048 return 0;
1049 } else {
1050 $this->db->rollback();
1051 return -2;
1052 }
1053 }
1054 return -1; //no date given or already validated
1055 }
1056
1057 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1064 public function update_num($num_payment)
1065 {
1066 // phpcs:enable
1067 if (!empty($num_payment) && $this->statut != 1) {
1068 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
1069 $sql .= " SET num_paiement = '".$this->db->escape($num_payment)."'";
1070 $sql .= " WHERE rowid = ".((int) $this->id);
1071
1072 dol_syslog(get_class($this)."::update_num", LOG_DEBUG);
1073 $result = $this->db->query($sql);
1074 if ($result) {
1075 $this->num_payment = $this->db->escape($num_payment);
1076 return 0;
1077 } else {
1078 $this->error = 'Error -1 '.$this->db->error();
1079 return -2;
1080 }
1081 }
1082 return -1; //no num given or already validated
1083 }
1084
1092 public function valide($user = null)
1093 {
1094 return $this->validate($user);
1095 }
1096
1103 public function validate($user = null)
1104 {
1105 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET statut = 1 WHERE rowid = '.((int) $this->id);
1106
1107 dol_syslog(get_class($this).'::valide', LOG_DEBUG);
1108 $result = $this->db->query($sql);
1109 if ($result) {
1110 return 1;
1111 } else {
1112 $this->error = $this->db->lasterror();
1113 dol_syslog(get_class($this).'::valide '.$this->error);
1114 return -1;
1115 }
1116 }
1117
1124 public function reject($user = null)
1125 {
1126 $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET statut = 2 WHERE rowid = '.((int) $this->id);
1127
1128 dol_syslog(get_class($this).'::reject', LOG_DEBUG);
1129 $result = $this->db->query($sql);
1130 if ($result) {
1131 return 1;
1132 } else {
1133 $this->error = $this->db->lasterror();
1134 dol_syslog(get_class($this).'::reject '.$this->error);
1135 return -1;
1136 }
1137 }
1138
1145 public function info($id)
1146 {
1147 $sql = 'SELECT p.rowid, p.datec, p.fk_user_creat, p.fk_user_modif, p.tms';
1148 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p';
1149 $sql .= ' WHERE p.rowid = '.((int) $id);
1150
1151 dol_syslog(get_class($this).'::info', LOG_DEBUG);
1152 $result = $this->db->query($sql);
1153
1154 if ($result) {
1155 if ($this->db->num_rows($result)) {
1156 $obj = $this->db->fetch_object($result);
1157
1158 $this->id = $obj->rowid;
1159
1160 $this->user_creation_id = $obj->fk_user_creat;
1161 $this->user_modification_id = $obj->fk_user_modif;
1162 $this->date_creation = $this->db->jdate($obj->datec);
1163 $this->date_modification = $this->db->jdate($obj->tms);
1164 }
1165 $this->db->free($result);
1166 } else {
1167 dol_print_error($this->db);
1168 }
1169 }
1170
1178 public function getBillsArray($filter = '')
1179 {
1180 $sql = 'SELECT pf.fk_facture';
1181 $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
1182 $sql .= ' WHERE pf.fk_facture = f.rowid AND pf.fk_paiement = '.((int) $this->id);
1183 if ($filter) {
1184 $sql .= ' AND '.$filter;
1185 }
1186 $resql = $this->db->query($sql);
1187 if ($resql) {
1188 $i = 0;
1189 $num = $this->db->num_rows($resql);
1190 $billsarray = array();
1191
1192 while ($i < $num) {
1193 $obj = $this->db->fetch_object($resql);
1194 $billsarray[$i] = $obj->fk_facture;
1195 $i++;
1196 }
1197
1198 return $billsarray;
1199 } else {
1200 $this->error = $this->db->error();
1201 dol_syslog(get_class($this).'::getBillsArray Error '.$this->error.' -', LOG_DEBUG);
1202 return -1;
1203 }
1204 }
1205
1212 public function getAmountsArray()
1213 {
1214 $sql = 'SELECT pf.fk_facture, pf.amount';
1215 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
1216 $sql .= ' WHERE pf.fk_paiement = '.((int) $this->id);
1217 $resql = $this->db->query($sql);
1218 if ($resql) {
1219 $i = 0;
1220 $num = $this->db->num_rows($resql);
1221 $amounts = array();
1222
1223 while ($i < $num) {
1224 $obj = $this->db->fetch_object($resql);
1225 $amounts[$obj->fk_facture] = $obj->amount;
1226 $i++;
1227 }
1228
1229 return $amounts;
1230 } else {
1231 $this->error = $this->db->error();
1232 dol_syslog(get_class($this).'::getAmountsArray Error '.$this->error.' -', LOG_DEBUG);
1233 return -1;
1234 }
1235 }
1236
1245 public function getNextNumRef($soc, $mode = 'next')
1246 {
1247 global $conf, $db, $langs;
1248 $langs->load("bills");
1249
1250 // Clean parameters (if not defined or using deprecated value)
1251 if (!getDolGlobalString('PAYMENT_ADDON')) {
1252 $conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
1253 } elseif (getDolGlobalString('PAYMENT_ADDON') == 'ant') {
1254 $conf->global->PAYMENT_ADDON = 'mod_payment_ant';
1255 } elseif (getDolGlobalString('PAYMENT_ADDON') == 'cicada') {
1256 $conf->global->PAYMENT_ADDON = 'mod_payment_cicada';
1257 }
1258
1259 if (getDolGlobalString('PAYMENT_ADDON')) {
1260 $mybool = false;
1261
1262 $file = getDolGlobalString('PAYMENT_ADDON') . ".php";
1263 $classname = getDolGlobalString('PAYMENT_ADDON');
1264
1265 // Include file with class
1266 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
1267
1268 foreach ($dirmodels as $reldir) {
1269 $dir = dol_buildpath($reldir."core/modules/payment/");
1270
1271 // Load file with numbering class (if found)
1272 if (is_file($dir.$file) && is_readable($dir.$file)) {
1273 $mybool = (include_once $dir.$file) || $mybool;
1274 }
1275 }
1276
1277 // For compatibility
1278 if (!$mybool) {
1279 $file = getDolGlobalString('PAYMENT_ADDON') . ".php";
1280 $classname = "mod_payment_" . getDolGlobalString('PAYMENT_ADDON');
1281 $classname = preg_replace('/\-.*$/', '', $classname);
1282 // Include file with class
1283 foreach ($conf->file->dol_document_root as $dirroot) {
1284 $dir = $dirroot."/core/modules/payment/";
1285
1286 // Load file with numbering class (if found)
1287 if (is_file($dir.$file) && is_readable($dir.$file)) {
1288 $mybool = (include_once $dir.$file) || $mybool;
1289 }
1290 }
1291 }
1292
1293 if (!$mybool) {
1294 dol_print_error(null, "Failed to include file ".$file);
1295 return '';
1296 }
1297
1298 $obj = new $classname();
1299 '@phan-var-force ModeleNumRefPayments $obj';
1300
1301 $numref = $obj->getNextValue($soc, $this);
1302
1307 if ($mode != 'last' && !$numref) {
1308 dol_print_error($db, "Payment::getNextNumRef ".$obj->error);
1309 return "";
1310 }
1311
1312 return $numref;
1313 } else {
1314 $langs->load("errors");
1315 print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Invoice"));
1316 return "";
1317 }
1318 }
1319
1325 public function getWay()
1326 {
1327 $way = 'dolibarr';
1328 if (isModEnabled('multicurrency')) {
1329 foreach ($this->multicurrency_amounts as $value) {
1330 if (!empty($value)) { // one value found into multicurrency_amounts so payment is in invoice currency
1331 $way = 'customer';
1332 break;
1333 }
1334 }
1335 }
1336
1337 return $way;
1338 }
1339
1348 public function initAsSpecimen($option = '')
1349 {
1350 global $user, $langs, $conf;
1351
1352 $now = dol_now();
1353 $arraynow = dol_getdate($now);
1354 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
1355
1356 // Initialize parameters
1357 $this->id = 0;
1358 $this->ref = 'SPECIMEN';
1359 $this->specimen = 1;
1360 $this->facid = 1;
1361 $this->datepaye = $nownotime;
1362
1363 return 1;
1364 }
1365
1366
1377 public function getNomUrl($withpicto = 0, $option = '', $mode = 'withlistofinvoices', $notooltip = 0, $morecss = '')
1378 {
1379 global $conf, $langs, $hookmanager;
1380
1381 if (!empty($conf->dol_no_mouse_hover)) {
1382 $notooltip = 1; // Force disable tooltips
1383 }
1384
1385 $result = '';
1386
1387 $label = img_picto('', $this->picto).' <u>'.$langs->trans("Payment").'</u><br>';
1388 $label .= '<strong>'.$langs->trans("Ref").':</strong> '.$this->ref;
1389 $dateofpayment = ($this->datepaye ? $this->datepaye : $this->date);
1390 if ($dateofpayment) {
1391 $label .= '<br><strong>'.$langs->trans("Date").':</strong> ';
1392 $tmparray = dol_getdate($dateofpayment);
1393 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
1394 $label .= dol_print_date($dateofpayment, 'day');
1395 } else { // Hours was set to real date of payment (special case for POS for example)
1396 $label .= dol_print_date($dateofpayment, 'dayhour', 'tzuser');
1397 }
1398 }
1399 if ($this->amount) {
1400 $label .= '<br><strong>'.$langs->trans("Amount").':</strong> '.price($this->amount, 0, $langs, 1, -1, -1, $conf->currency);
1401 }
1402 if ($mode == 'withlistofinvoices') {
1403 $arraybill = $this->getBillsArray();
1404 if (is_array($arraybill) && count($arraybill) > 0) {
1405 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1406 $facturestatic = new Facture($this->db);
1407 foreach ($arraybill as $billid) {
1408 $facturestatic->fetch($billid);
1409 $label .= '<br> '.$facturestatic->getNomUrl(1, '', 0, 0, '', 1).' '.$facturestatic->getLibStatut(2, -1);
1410 }
1411 }
1412 }
1413
1414 $linkclose = '';
1415 if (empty($notooltip)) {
1416 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1417 $label = $langs->trans("Payment");
1418 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1419 }
1420 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
1421 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
1422 } else {
1423 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1424 }
1425
1426 $url = DOL_URL_ROOT.'/compta/paiement/card.php?id='.$this->id;
1427
1428 $linkstart = '<a href="'.$url.'"';
1429 $linkstart .= $linkclose.'>';
1430 $linkend = '</a>';
1431
1432 $result .= $linkstart;
1433 if ($withpicto) {
1434 $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);
1435 }
1436 if ($withpicto && $withpicto != 2) {
1437 $result .= ($this->ref ? $this->ref : $this->id);
1438 }
1439 $result .= $linkend;
1440 global $action;
1441 $hookmanager->initHooks(array($this->element . 'dao'));
1442 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1443 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1444 if ($reshook > 0) {
1445 $result = $hookmanager->resPrint;
1446 } else {
1447 $result .= $hookmanager->resPrint;
1448 }
1449 return $result;
1450 }
1451
1458 public function getLibStatut($mode = 0)
1459 {
1460 return $this->LibStatut($this->statut, $mode);
1461 }
1462
1463 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1471 public function LibStatut($status, $mode = 0)
1472 {
1473 // phpcs:enable
1474 global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage
1475
1476 $langs->load('compta');
1477 /*if ($mode == 0)
1478 {
1479 if ($status == 0) return $langs->trans('ToValidate');
1480 if ($status == 1) return $langs->trans('Validated');
1481 }
1482 if ($mode == 1)
1483 {
1484 if ($status == 0) return $langs->trans('ToValidate');
1485 if ($status == 1) return $langs->trans('Validated');
1486 }
1487 if ($mode == 2)
1488 {
1489 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
1490 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
1491 }
1492 if ($mode == 3)
1493 {
1494 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1');
1495 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
1496 }
1497 if ($mode == 4)
1498 {
1499 if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut1').' '.$langs->trans('ToValidate');
1500 if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
1501 }
1502 if ($mode == 5)
1503 {
1504 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
1505 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
1506 }
1507 if ($mode == 6)
1508 {
1509 if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut1');
1510 if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
1511 }*/
1512 return '';
1513 }
1514
1515 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1523 public function fetch_thirdparty($force_thirdparty_id = 0)
1524 {
1525 // phpcs:enable
1526 include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
1527
1528 if (empty($force_thirdparty_id)) {
1529 $billsarray = $this->getBillsArray(); // From payment, the fk_soc isn't available, we should load the first supplier invoice to get him
1530 if (!empty($billsarray)) {
1531 $invoice = new Facture($this->db);
1532 if ($invoice->fetch($billsarray[0]) > 0) {
1533 $force_thirdparty_id = $invoice->socid;
1534 }
1535 }
1536 }
1537
1538 return parent::fetch_thirdparty($force_thirdparty_id);
1539 }
1540
1541
1547 public function isReconciled()
1548 {
1549 $accountline = new AccountLine($this->db);
1550 $accountline->fetch($this->bank_line);
1551 return $accountline->rappro ? true : false;
1552 }
1553}
$object ref
Definition info.php:89
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_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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79