dolibarr 25.0.0-alpha
bonprelevement.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2010-2015 Juanjo Menent <jmenent@2byte.es>
5 * Copyright (C) 2010-2014 Laurent Destailleur <eldy@users.sourceforge.net>
6 * Copyright (C) 2014-2016 Ferran Marcet <fmarcet@2byte.es>
7 * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
8 * Copyright (C) 2019 JC Prieto <jcprieto@virtual20.com><prietojc@gmail.com>
9 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
10 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
11 * Copyright (C) 2026 Guillaume de Wellenstein <guillaume@tecneo.fr>
12 * Copyright (C) 2026 Nick Fragoulis
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27
34require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
35require_once DOL_DOCUMENT_ROOT . '/core/lib/bank.lib.php';
36require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
37require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php';
38require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php';
39require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php';
40require_once DOL_DOCUMENT_ROOT . '/fourn/class/paiementfourn.class.php';
41require_once DOL_DOCUMENT_ROOT . '/salaries/class/salary.class.php';
42require_once DOL_DOCUMENT_ROOT . '/salaries/class/paymentsalary.class.php';
43require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
44require_once DOL_DOCUMENT_ROOT . '/user/class/userbankaccount.class.php';
45
46
51{
55 public $element = 'widthdraw';
56
60 public $table_element = 'prelevement_bons';
61
65 public $picto = 'payment';
66
70 public $date_echeance;
74 public $raison_sociale;
78 public $reference_remise;
82 public $emetteur_code_guichet;
86 public $emetteur_numero_compte;
90 public $emetteur_code_banque;
94 public $emetteur_number_key;
98 public $sepa_xml_pti_in_ctti;
99
103 public $emetteur_iban;
107 public $emetteur_bic;
111 public $emetteur_ics;
112
116 public $sepa_schema_version = '2';
117
121 public $user_trans;
125 public $user_credit;
126
130 public $total;
131
135 public $fetched;
136
137 public $labelStatus = array();
138
142 public $factures = array();
143
147 public $methodes_trans = array();
148
152 public $invoice_in_error = array();
153
157 public $thirdparty_in_error = array();
158
162 public $file;
163
167 public $filename;
168
169 const STATUS_DRAFT = 0;
170 const STATUS_TRANSFERED = 1;
171 const STATUS_CREDITED = 2; // STATUS_CREDITED and STATUS_DEBITED is same. Difference is in ->type
172 const STATUS_DEBITED = 2; // STATUS_CREDITED and STATUS_DEBITED is same. Difference is in ->type
173 const STATUS_CANCELED = 9;
174
175
215 // BEGIN MODULEBUILDER PROPERTIES
219 public $fields = array(
220 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 10, 'notnull' => 1, 'visible' => 0,),
221 'ref' => array('type' => 'varchar(12)', 'label' => 'Ref', 'enabled' => 1, 'position' => 15, 'notnull' => 0, 'visible' => -1, 'csslist' => 'tdoverflowmax150', 'showoncombobox' => 1,),
222 'datec' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 25, 'notnull' => 0, 'visible' => -1,),
223 'amount' => array('type' => 'double(24,8)', 'label' => 'Amount', 'enabled' => 1, 'position' => 30, 'notnull' => 0, 'visible' => -1,),
224 'statut' => array('type' => 'smallint(6)', 'label' => 'Statut', 'enabled' => 1, 'position' => 500, 'notnull' => 0, 'visible' => -1, 'arrayofkeyval' => array(0 => 'Wait', 1 => 'Transfered', 2 => 'Credited')),
225 'credite' => array('type' => 'smallint(6)', 'label' => 'Credite', 'enabled' => 1, 'position' => 40, 'notnull' => 0, 'visible' => -1,),
226 'note' => array('type' => 'text', 'label' => 'Note', 'enabled' => 1, 'position' => 45, 'notnull' => 0, 'visible' => -1,),
227 'date_trans' => array('type' => 'datetime', 'label' => 'TransData', 'enabled' => 1, 'position' => 50, 'notnull' => 0, 'visible' => -1,),
228 'method_trans' => array('type' => 'smallint(6)', 'label' => 'Methodtrans', 'enabled' => 1, 'position' => 55, 'notnull' => 0, 'visible' => -1,),
229 'fk_user_trans' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserTransfer', 'enabled' => 1, 'position' => 60, 'notnull' => 0, 'visible' => -1, 'css' => 'maxwidth500 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax150',),
230 'date_credit' => array('type' => 'datetime', 'label' => 'CreditDate', 'enabled' => 1, 'position' => 65, 'notnull' => 0, 'visible' => -1,),
231 'fk_user_credit' => array('type' => 'integer:User:user/class/user.class.php', 'label' => 'UserCredit', 'enabled' => 1, 'position' => 70, 'notnull' => 0, 'visible' => -1, 'css' => 'maxwidth500 widthcentpercentminusxx', 'csslist' => 'tdoverflowmax150',),
232 'type' => array('type' => 'varchar(16)', 'label' => 'Type', 'enabled' => 1, 'position' => 75, 'notnull' => 0, 'visible' => -1,),
233 'fk_bank_account' => array('type' => 'integer', 'label' => 'BankAccount', 'enabled' => 1, 'position' => 80, 'notnull' => 0, 'visible' => -1, 'css' => 'maxwidth500 widthcentpercentminusxx',),
234 );
238 public $rowid;
242 public $ref;
246 public $datec;
247
251 public $amount;
252
257 public $statut;
261 public $status;
262
266 public $credite;
267
272 public $note;
273
277 public $note_private;
278
282 public $date_trans;
286 public $method_trans;
290 public $fk_user_trans;
294 public $date_credit;
298 public $fk_user_credit;
302 public $type;
306 public $fk_bank_account;
307 // END MODULEBUILDER PROPERTIES
308
309
310
316 public function __construct($db)
317 {
318 $this->db = $db;
319
320 $this->filename = '';
321
322 $this->date_echeance = dol_now();
323 $this->raison_sociale = "";
324 $this->reference_remise = "";
325
326 $this->emetteur_code_guichet = "";
327 $this->emetteur_numero_compte = "";
328 $this->emetteur_code_banque = "";
329 $this->emetteur_number_key = "";
330 $this->sepa_schema_version = '2';
331 $this->sepa_xml_pti_in_ctti = false;
332
333 $this->emetteur_iban = "";
334 $this->emetteur_bic = "";
335 $this->emetteur_ics = "";
336
337 $this->factures = array();
338
339 $this->methodes_trans = array(0 => 'Internet', 2 => 'Email', 3 => 'Api');
340
341 $this->fetched = 0;
342 }
343
344 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
364 public function addWithdrawDetail($invoice_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $type = 'debit-order', $sourcetype = '', $bic = '', $iban = '', $rum = '', $id_prelevement_demande = 0)
365 {
366 // phpcs:enable
367 $result = 0;
368 $line_id = 0;
369
370 // TODO Save the $id_prelevement_demande
371
372 // Add lines into prelevement_lignes for tracking. The ID of line inserted is returned into $line_id.
373 $result = $this->addline($line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype, $bic, $iban, $rum, $id_prelevement_demande);
374
375
376 if ($result == 0) {
377 if ($line_id > 0) {
378 $sql = "INSERT INTO " . MAIN_DB_PREFIX . "prelevement (";
379 if ($type != 'bank-transfer') {
380 $sql .= "fk_facture";
381 } else {
382 if ($sourcetype == 'salary') {
383 $sql .= "fk_salary";
384 } else {
385 $sql .= "fk_facture_fourn";
386 }
387 }
388 $sql .= ",fk_prelevement_lignes";
389 $sql .= ") VALUES (";
390 $sql .= ((int) $invoice_id);
391 $sql .= ", " . ((int) $line_id);
392 $sql .= ")";
393
394 if ($this->db->query($sql)) {
395 $result = 0;
396 } else {
397 $result = -1;
398 $this->errors[] = get_class($this) . "::addWithdrawDetail " . $this->db->lasterror;
399 dol_syslog(get_class($this) . "::addWithdrawDetail Error $result");
400 }
401 } else {
402 $result = -2;
403 $this->errors[] = get_class($this) . "::addWithdrawDetail linedid Empty";
404 dol_syslog(get_class($this) . "::addWithdrawDetail Error $result");
405 }
406 } else {
407 $result = -3;
408 dol_syslog(get_class($this) . "::addWithdrawDetail Error $result");
409 }
410
411 return $result;
412 }
413
432 public function addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype = '', $bic = '', $iban = '', $rum = '', $id_prelevement_demande = 0)
433 {
434 $result = -1;
435 $concat = getDolGlobalInt('MAIN_MODULE_PRELEVEMENT_CONCAT'); // ??? what is this for. Seems not used.
436
437 if ($concat == 1) {
442 $sql = "SELECT rowid";
443 $sql .= " FROM " . MAIN_DB_PREFIX . "prelevement_lignes";
444 $sql .= " WHERE fk_prelevement_bons = " . ((int) $this->id);
445 if ($sourcetype == 'salary') {
446 $sql .= " AND fk_soc = " . ((int) $client_id);
447 } else {
448 $sql .= " AND fk_user = " . ((int) $client_id);
449 }
450 $sql .= " AND code_banque = '" . $this->db->escape($code_banque) . "'";
451 $sql .= " AND code_guichet = '" . $this->db->escape($code_guichet) . "'";
452 $sql .= " AND number = '" . $this->db->escape($number) . "'";
453
454 $resql = $this->db->query($sql);
455 if ($resql) {
456 $num = $this->db->num_rows($resql);
457 } else {
458 $result = -1;
459 }
460 } else {
461 /*
462 * No aggregate, use 1 line per request of invoice/salary to pay
463 */
464 $sql = "INSERT INTO " . MAIN_DB_PREFIX . "prelevement_lignes (";
465 $sql .= "fk_prelevement_bons";
466 $sql .= ", fk_soc";
467 $sql .= ", client_nom";
468 $sql .= ", amount";
469 $sql .= ", fk_prelevement_demande";
470 $sql .= ($sourcetype == 'salary' ? ", fk_user" : "");
471 $sql .= ") VALUES (";
472 $sql .= ((int) $this->id);
473 $sql .= ", " . (($sourcetype != 'salary') ? ((int) $client_id) : "0"); // fk_soc can't be null
474 $sql .= ", '" . $this->db->escape($client_nom) . "'";
475 $sql .= ", " . ((float) price2num($amount));
476 $sql .= ", " . ((int) $id_prelevement_demande);
477 $sql .= (($sourcetype == 'salary') ? ", " . ((int) $client_id) : '');
478 $sql .= ")";
479 if ($this->db->query($sql)) {
480 $line_id = $this->db->last_insert_id(MAIN_DB_PREFIX . "prelevement_lignes");
481 $result = 0;
482 } else {
483 $this->errors[] = get_class($this) . "::addline Error -2 " . $this->db->lasterror;
484 dol_syslog(get_class($this) . "::addline Error -2");
485 $result = -2;
486 }
487 }
488
489 return $result;
490 }
491
498 public function getErrorString($error)
499 {
500 global $langs;
501
502 $errors = array();
503
504 $errors[1027] = $langs->trans("DateInvalid");
505
506 return $errors[abs($error)] ?? 'unknown error code';
507 }
508
516 public function fetch($rowid, $ref = '')
517 {
518 $sql = "SELECT p.rowid, p.ref, p.amount, p.note";
519 $sql .= ", p.datec as dc";
520 $sql .= ", p.date_trans as date_trans";
521 $sql .= ", p.method_trans, p.fk_user_trans";
522 $sql .= ", p.date_credit as date_credit";
523 $sql .= ", p.fk_user_credit";
524 $sql .= ", p.type";
525 $sql .= ", p.fk_bank_account";
526 $sql .= ", p.statut as status";
527 $sql .= " FROM " . MAIN_DB_PREFIX . "prelevement_bons as p";
528 $sql .= " WHERE p.entity IN (" . getEntity('invoice') . ")";
529 if ($rowid > 0) {
530 $sql .= " AND p.rowid = " . ((int) $rowid);
531 } else {
532 $sql .= " AND p.ref = '" . $this->db->escape($ref) . "'";
533 }
534
535 dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
536 $result = $this->db->query($sql);
537 if ($result) {
538 if ($this->db->num_rows($result)) {
539 $obj = $this->db->fetch_object($result);
540
541 $this->id = $obj->rowid;
542 $this->ref = $obj->ref;
543 $this->amount = $obj->amount;
544 $this->note = $obj->note;
545 $this->note_private = $obj->note;
546 $this->datec = $this->db->jdate($obj->dc);
547
548 $this->date_trans = $this->db->jdate($obj->date_trans);
549 $this->method_trans = $obj->method_trans;
550 $this->user_trans = $obj->fk_user_trans;
551
552 $this->date_credit = $this->db->jdate($obj->date_credit);
553 $this->user_credit = $obj->fk_user_credit;
554
555 $this->type = $obj->type;
556 $this->fk_bank_account = $obj->fk_bank_account;
557
558 $this->status = $obj->status;
559 if (empty($this->status)) { // Value is sometimes null in database
560 $this->status = 0;
561 }
562 $this->statut = $this->status; // For backward compatibility
563
564 $this->fetched = 1;
565
566 return 1;
567 } else {
568 dol_syslog(get_class($this) . "::Fetch no record found");
569 return 0;
570 }
571 } else {
572 return -1;
573 }
574 }
575
583 public function update(User $user, $notrigger = 0)
584 {
585 return $this->updateCommon($user, $notrigger);
586 }
587
588 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
598 public function set_infocredit($user, $date, $type = '')
599 {
600 // phpcs:enable
601 global $conf, $langs;
602
603 $error = 0;
604
605 if ($this->fetched == 1) {
606 if ($date < $this->date_trans) {
607 $langs->load("errors");
608 $this->error = $langs->trans('ErrorDateOfMovementLowerThanDateOfFileTransmission');
609 dol_syslog("bon-prelevment::set_infocredit 1027 " . $this->error);
610 return -1027;
611 }
612
613 $this->db->begin();
614
615 $sql = " UPDATE " . MAIN_DB_PREFIX . "prelevement_bons";
616 $sql .= " SET fk_user_credit = " . ((int) $user->id);
617 $sql .= ", statut = " . self::STATUS_CREDITED;
618 $sql .= ", date_credit = '" . $this->db->idate($date) . "'";
619 $sql .= " WHERE rowid = " . ((int) $this->id);
620 $sql .= " AND entity = " . ((int) $conf->entity);
621 $sql .= " AND statut = " . self::STATUS_TRANSFERED;
622
623 $resql = $this->db->query($sql);
624 if ($resql) {
625 $langs->load('withdrawals');
626 $subject = $langs->trans("InfoCreditSubject", $this->ref);
627 $message = $langs->trans("InfoCreditMessage", $this->ref, dol_print_date($date, 'dayhour'));
628
629 // Add payment of withdrawal into bank
630 $fk_bank_account = $this->fk_bank_account;
631 if (empty($fk_bank_account)) {
632 $fk_bank_account = ($this->type == 'bank-transfer' ? getDolGlobalInt('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') : getDolGlobalInt('PRELEVEMENT_ID_BANKACCOUNT'));
633 }
634
635 $amounts = array();
636 $amountsperthirdparty = array();
637
638 $facs = $this->getListInvoices(1, $type);
639 if ($this->error) {
640 $error++;
641 }
642
643 // Loop on each invoice or salary.
644 // $facs should be array(0=>id, 1=>amount requested)
645 $num = count($facs);
646 for ($i = 0; $i < $num; $i++) {
647 if ($this->type == 'bank-transfer') {
648 if ($type == 'salary') {
649 $fac = new Salary($this->db);
650 } else {
651 $fac = new FactureFournisseur($this->db);
652 }
653 } else {
654 $fac = new Facture($this->db);
655 }
656
657 $result = $fac->fetch($facs[$i][0]);
658
659 $amounts[$fac->id] = $facs[$i][1];
660 if ($this->type == 'bank-transfer') {
661 if ($type == 'salary') {
662 $amountsperthirdparty[$fac->fk_user][$fac->id] = $facs[$i][1];
663 } else {
664 $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
665 }
666 } else {
667 $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
668 }
669
670 $totalpaid = $fac->getSommePaiement();
671 $totalcreditnotes = 0;
672 if (method_exists($fac, 'getSumCreditNotesUsed')) {
673 $totalcreditnotes = $fac->getSumCreditNotesUsed();
674 }
675 $totaldeposits = 0;
676 if (method_exists($fac, 'getSumDepositsUsed')) {
677 $totaldeposits = $fac->getSumDepositsUsed();
678 }
679 $alreadypayed = $totalpaid + $totalcreditnotes + $totaldeposits;
680
681 // Set the main document to pay with status Paid.
682 // @TODO Move this after creation of payments done after
683 $amountofdocument = $fac->total_ttc;
684 if ($type == 'salary') {
685 $amountofdocument = $fac->amount;
686 }
687 if (price2num($alreadypayed + $facs[$i][1], 'MT') == price2num($amountofdocument, 'MT')) {
688 $result = $fac->setPaid($user);
689 if ($result < 0) {
690 $this->error = $fac->error;
691 $this->errors = $fac->errors;
692 }
693 }
694 }
695
696 // Make one payment per customer or employee
697 foreach ($amountsperthirdparty as $thirdpartyid => $cursoramounts) {
698 if ($this->type == 'bank-transfer') {
699 if ($type == 'salary') {
700 $paiement = new PaymentSalary($this->db);
701 } else {
702 $paiement = new PaiementFourn($this->db);
703 }
704 } else {
705 $paiement = new Paiement($this->db);
706 }
707 $paiement->datepaye = $date;
708 $paiement->amounts = $cursoramounts; // Array with detail of dispatching of payments for each invoice
709
710 if ($this->type == 'bank-transfer') {
711 if ($type == 'salary') {
712 $paiement->datep = $date;
713
714 $paiement->paiementid = 2;
715 $paiement->fk_typepayment = 2;
716 $paiement->paiementcode = 'VIR';
717 } else {
718 $paiement->paiementid = 2;
719 $paiement->paiementcode = 'VIR';
720 }
721 } else {
722 $paiement->paiementid = 3;
723 $paiement->paiementcode = 'PRE';
724 }
725
726 $paiement->num_payment = $this->ref; // Set ref of direct debit note
727 $paiement->id_prelevement = $this->id;
728
729 $result = $paiement->create($user, 1); // This use ->paiementid, that is ID of payment mode. closepaidinvoices=1 to convert deposit invoice to available credit
730
731 if ($result < 0) {
732 $error++;
733 $this->error = $paiement->error;
734 $this->errors = $paiement->errors;
735 dol_syslog(get_class($this) . "::set_infocredit AddPayment Error " . $this->error);
736 } else {
737 if ($this->type == 'bank-transfer') {
738 if ($type == 'salary') {
739 $modeforaddpayment = 'payment_salary';
740 $labelforaddpayment = '(SalaryPayment)';
741 $addbankurl = 'credit-transfer';
742 } else {
743 $modeforaddpayment = 'payment_supplier';
744 $labelforaddpayment = '(SupplierInvoicePayment)';
745 $addbankurl = 'credit-transfer';
746 }
747 } else {
748 $modeforaddpayment = 'payment';
749 $labelforaddpayment = '(CustomerInvoicePayment)';
750 $addbankurl = 'direct-debit'; // = 'directdebit'
751 }
752
753
754 if ($paiement instanceof PaymentSalary) {
755 // Only 6 arguments for PaymentSalary
756 $result = $paiement->addPaymentToBank($user, $modeforaddpayment, $labelforaddpayment, $fk_bank_account, '', '');
757 } else {
758 $result = $paiement->addPaymentToBank($user, $modeforaddpayment, $labelforaddpayment, $fk_bank_account, '', '', 0, '', $addbankurl);
759 }
760
761 if ($result < 0) {
762 $error++;
763 $this->error = $paiement->error;
764 $this->errors = $paiement->errors;
765 dol_syslog(get_class($this) . "::set_infocredit AddPaymentToBank Error " . $this->error);
766 }
767 }
768 }
769
770 // Update withdrawal line
771 // TODO: Translate to ligneprelevement.class.php
772 if (!$error) {
773 $sql = " UPDATE " . MAIN_DB_PREFIX . "prelevement_lignes";
774 $sql .= " SET statut = 2";
775 $sql .= " WHERE fk_prelevement_bons = " . ((int) $this->id);
776
777 if (!$this->db->query($sql)) {
778 dol_syslog(get_class($this) . "::set_infocredit Update lines Error");
779 $error++;
780 }
781 }
782 } else {
783 $this->error = $this->db->lasterror();
784 dol_syslog(get_class($this) . "::set_infocredit Update Bons Error");
785 $error++;
786 }
787
788 // End of procedure
789 if ($error == 0) {
790 $this->date_credit = $date; // date credit or debit
791 $this->statut = self::STATUS_CREDITED;
792 $this->status = self::STATUS_CREDITED;
793
794 $this->db->commit();
795 return 0;
796 } else {
797 $this->db->rollback();
798 return -1;
799 }
800 } else {
801 return -1026;
802 }
803 }
804
805 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
814 public function set_infotrans($user, $date, $method)
815 {
816 // phpcs:enable
817 global $conf, $langs;
818
819 $error = 0;
820
821 dol_syslog(get_class($this) . "::set_infotrans Start", LOG_INFO);
822
823 if ($this->db->begin()) {
824 $sql = "UPDATE " . MAIN_DB_PREFIX . "prelevement_bons ";
825 $sql .= " SET fk_user_trans = " . ((int) $user->id);
826 $sql .= " , date_trans = '" . $this->db->idate($date) . "'";
827 $sql .= " , method_trans = " . ((int) $method);
828 $sql .= " , statut = " . self::STATUS_TRANSFERED;
829 $sql .= " WHERE rowid = " . ((int) $this->id);
830 $sql .= " AND entity = " . ((int) $conf->entity);
831 $sql .= " AND statut = " . self::STATUS_DRAFT;
832
833 if ($this->db->query($sql)) {
834 $this->method_trans = $method;
835 $langs->load('withdrawals');
836 $subject = $langs->trans("InfoTransSubject", $this->ref);
837 $message = $langs->trans("InfoTransMessage", $this->ref, dolGetFirstLastname($user->firstname, $user->lastname));
838 $message .= $langs->trans("InfoTransData", price($this->amount), $this->methodes_trans[$this->method_trans], dol_print_date($date, 'day'));
839
840 // TODO Call trigger to create a notification using notification module
841 } else {
842 $error++;
843 }
844
845 if ($error == 0) {
846 $this->date_trans = $date;
847 $this->statut = self::STATUS_TRANSFERED;
848 $this->status = self::STATUS_TRANSFERED;
849 $this->user_trans = $user->id;
850
851 $this->db->commit();
852
853 return 0;
854 } else {
855 $this->db->rollback();
856 dol_syslog(get_class($this) . "::set_infotrans ROLLBACK", LOG_ERR);
857
858 return -1;
859 }
860 } else {
861 dol_syslog(get_class($this) . "::set_infotrans Ouverture transaction SQL impossible", LOG_CRIT);
862 return -2;
863 }
864 }
865
874 private function getListInvoices($amounts = 0, $type = '')
875 {
876 global $conf;
877
878 $arr = array();
879
880 dol_syslog(get_class($this) . "::getListInvoices");
881
882 // Returns all invoices presented within same order
883 $sql = "SELECT ";
884 if ($this->type == 'bank-transfer') {
885 if ($type == 'salary') {
886 $sql .= " p.fk_salary";
887 } else {
888 $sql .= " p.fk_facture_fourn";
889 }
890 } else {
891 $sql .= " p.fk_facture";
892 }
893 if ($amounts) {
894 $sql .= ", SUM(pl.amount)";
895 }
896 $sql .= " FROM " . MAIN_DB_PREFIX . "prelevement_bons as pb,";
897 $sql .= " " . MAIN_DB_PREFIX . "prelevement_lignes as pl,";
898 $sql .= " " . MAIN_DB_PREFIX . "prelevement as p";
899 $sql .= " WHERE p.fk_prelevement_lignes = pl.rowid";
900 $sql .= " AND pl.fk_prelevement_bons = pb.rowid";
901 $sql .= " AND pb.rowid = " . ((int) $this->id);
902 $sql .= " AND pb.entity = " . ((int) $conf->entity);
903 if ($amounts) {
904 if ($this->type == 'bank-transfer') {
905 if ($type == 'salary') {
906 $sql .= " GROUP BY p.fk_salary";
907 } else {
908 $sql .= " GROUP BY p.fk_facture_fourn";
909 }
910 } else {
911 $sql .= " GROUP BY p.fk_facture";
912 }
913 }
914
915 $resql = $this->db->query($sql);
916 if ($resql) {
917 $num = $this->db->num_rows($resql);
918
919 if ($num) {
920 $i = 0;
921 while ($i < $num) {
922 $row = $this->db->fetch_row($resql);
923 if (!$amounts) {
924 $arr[$i] = $row[0];
925 } else {
926 $arr[$i] = array(
927 $row[0],
928 $row[1]
929 );
930 }
931 $i++;
932 }
933 }
934 $this->db->free($resql);
935 } else {
936 $this->error = $this->db->lasterror();
937 }
938
939 return $arr;
940 }
941
942 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
950 public function SommeAPrelever($mode = 'direct-debit', $type = '')
951 {
952 // phpcs:enable
953 $sql = "SELECT sum(pd.amount) as nb";
954 if ($type !== 'salary') {
955 if ($mode != 'bank-transfer') {
956 $sql .= " FROM " . MAIN_DB_PREFIX . "facture as f,";
957 } else {
958 $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn as f,";
959 }
960 } else {
961 $sql .= " FROM " . MAIN_DB_PREFIX . "salary as s,";
962 }
963 $sql .= " " . MAIN_DB_PREFIX . "prelevement_demande as pd";
964 $sql .= ($type !== 'salary' ? " WHERE f.entity IN (" . getEntity('invoice') . ")" : " WHERE s.entity IN (" . getEntity('salary') . ")");
965 if (!getDolGlobalString('WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS')) {
966 $sql .= ($type !== 'salary' ? " AND f.fk_statut = " . Facture::STATUS_VALIDATED : " AND s.paye = " . Salary::STATUS_UNPAID);
967 }
968 if ($type !== 'salary') {
969 if ($mode != 'bank-transfer') {
970 $sql .= " AND f.rowid = pd.fk_facture";
971 } else {
972 $sql .= " AND f.rowid = pd.fk_facture_fourn";
973 }
974 } else {
975 $sql .= " AND s.rowid = pd.fk_salary";
976 }
977 $sql .= ($type !== 'salary' ? " AND f.paye = 0" : "");
978 $sql .= " AND pd.traite = 0";
979 $sql .= " AND pd.ext_payment_id IS NULL";
980 $sql .= ($type !== 'salary' ? " AND f.total_ttc > 0" : "");
981
982 $resql = $this->db->query($sql);
983 if ($resql) {
984 $obj = $this->db->fetch_object($resql);
985
986 $this->db->free($resql);
987
988 return $obj->nb;
989 } else {
990 $error = 1;
991 dol_syslog(get_class($this) . "::SommeAPrelever Erreur -1");
992 dol_syslog($this->db->error());
993
994 return -1;
995 }
996 }
997
1005 public function nbOfInvoiceToPay($mode = 'direct-debit', $type = '')
1006 {
1007 if ($type === 'salary') {
1008 return $this->NbFactureAPrelever($mode, 1);
1009 } else {
1010 return $this->NbFactureAPrelever($mode);
1011 }
1012 }
1013
1014 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1022 public function NbFactureAPrelever($type = 'direct-debit', $forsalary = 0)
1023 {
1024 // phpcs:enable
1025 if ($forsalary == 1) {
1026 $sql = "SELECT count(s.rowid) as nb";
1027 $sql .= " FROM " . MAIN_DB_PREFIX . "salary as s";
1028 } else {
1029 $sql = "SELECT count(f.rowid) as nb";
1030
1031 if ($type == 'bank-transfer') {
1032 $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn as f";
1033 } else {
1034 $sql .= " FROM " . MAIN_DB_PREFIX . "facture as f";
1035 }
1036 }
1037 $sql .= ", " . MAIN_DB_PREFIX . "prelevement_demande as pd";
1038 if ($forsalary == 1) {
1039 $sql .= " WHERE s.entity IN (" . getEntity('invoice') . ")";
1040 if (!getDolGlobalString('WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS')) {
1041 $sql .= " AND s.paye = 0";
1042 }
1043 } else {
1044 $sql .= " WHERE f.entity IN (" . getEntity('invoice') . ")";
1045 if (!getDolGlobalString('WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS')) {
1046 $sql .= " AND f.fk_statut = " . Facture::STATUS_VALIDATED;
1047 }
1048 }
1049 if ($forsalary == 1) {
1050 $sql .= " AND s.rowid = pd.fk_salary";
1051 } else {
1052 if ($type == 'bank-transfer') {
1053 $sql .= " AND f.rowid = pd.fk_facture_fourn";
1054 } else {
1055 $sql .= " AND f.rowid = pd.fk_facture";
1056 }
1057 }
1058 $sql .= " AND pd.traite = 0";
1059 $sql .= " AND pd.ext_payment_id IS NULL";
1060 if (!$forsalary == 1) {
1061 $sql .= " AND f.total_ttc > 0";
1062 } else {
1063 $sql .= " AND s.paye = 0";
1064 }
1065
1066 dol_syslog(get_class($this) . "::NbFactureAPrelever");
1067 $resql = $this->db->query($sql);
1068
1069 if ($resql) {
1070 $obj = $this->db->fetch_object($resql);
1071 $this->db->free($resql);
1072
1073 return $obj->nb;
1074 } else {
1075 $this->error = get_class($this) . "::NbFactureAPrelever Erreur -1 sql=" . $this->db->error();
1076 return -1;
1077 }
1078 }
1079
1080
1081 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1105 public function create($banque = '', $agence = '', $mode = 'real', $format = 'FRST', $executiondate = 0, $notrigger = 0, $type = 'direct-debit', $dids = 0, $fk_bank_account = 0, $sourcetype = 'invoice')
1106 {
1107 // phpcs:enable
1108 global $conf, $langs, $user;
1109
1110 dol_syslog(__METHOD__ . " mode=".$mode." format=".$format." type=".$type." dids=".(is_array($dids) ? implode(',', $dids) : $dids)." fk_bank_account=".$fk_bank_account." sourcetype=".$sourcetype, LOG_DEBUG);
1111
1112 require_once DOL_DOCUMENT_ROOT . "/compta/facture/class/facture.class.php";
1113 require_once DOL_DOCUMENT_ROOT . "/societe/class/societe.class.php";
1114
1115 // Check params
1116 if ($type != 'bank-transfer') {
1117 $format = strtoupper($format);
1118 if (empty($format)) {
1119 $this->error = 'ErrorBadParametersForDirectDebitFileCreate';
1120 return -1;
1121 }
1122 if ($mode === 'real' && !in_array($format, array('FRST', 'RCUR', 'OOFF', 'FNAL'), true)) {
1123 $this->error = 'ErrorBadParametersForDirectDebitFileCreate';
1124 return -1;
1125 }
1126 }
1127
1128 if (!is_int($dids) && !is_array($dids)) {
1129 $this->error = 'ErrorBadParametersForDirectDebitFileCreateDids';
1130 return -1;
1131 }
1132
1133 // Clean params
1134 if (empty($fk_bank_account)) {
1135 $fk_bank_account = ($type == 'bank-transfer' ? getDolGlobalInt('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') : getDolGlobalInt('PRELEVEMENT_ID_BANKACCOUNT'));
1136 }
1137 if (is_int($dids)) {
1138 $dids = array($dids);
1139 }
1140
1141 $error = 0;
1142 // Pre-store some values into variables to simplify following sql requests
1143 if ($sourcetype != 'salary') {
1144 $entity = $type != 'bank-transfer' ? getEntity('invoice', 1) : getEntity('supplier_invoice', 1); // Return entity
1145 $sqlTable = $type != 'bank-transfer' ? "facture" : "facture_fourn";
1146 $socOrUser = 'fk_soc';
1147 $societeOrUser = 'societe';
1148 } else {
1149 $entity = getEntity('salary', 1); // Return entity
1150 $sqlTable = 'salary';
1151 $socOrUser = 'fk_user';
1152 $societeOrUser = 'user';
1153 }
1154
1155 /*
1156 $thirdpartyBANId = 0;
1157
1158 // Check if there is an iban associated to the bank transfer request or if we take the default
1159 if ($dids !== [0] && !empty($dids)) {
1160 $sql = "SELECT pd.fk_societe_rib";
1161 $sql .= " FROM " . $this->db->prefix() . "prelevement_demande as pd";
1162 $sql .= " WHERE pd.rowid IN (".$this->db->sanitize(implode(',', $dids)).")";
1163
1164 $resql = $this->db->query($sql);
1165
1166 if (!$resql) {
1167 $this->error = $this->db->lasterror();
1168 dol_syslog(__METHOD__ . " Read fk_societe_rib error " . $this->db->lasterror(), LOG_ERR);
1169 return -1;
1170 }
1171
1172 $obj = $this->db->fetch_object($resql);
1173 if ($obj) {
1174 $thirdpartyBANId = $obj->fk_societe_rib;
1175
1176 dol_syslog(__METHOD__ . " Found a BAN ID to use: ".$thirdpartyBANId);
1177 }
1178
1179 $this->db->free($resql);
1180 }
1181 */
1182
1183 $datetimeprev = dol_now('gmt');
1184 // Choice of the date of the execution direct debit
1185 if (!empty($executiondate)) {
1186 $datetimeprev = $executiondate;
1187 }
1188
1189 $month = dol_print_date($datetimeprev, "%m", 'gmt');
1190 $year = dol_print_date($datetimeprev, "%Y", 'gmt');
1191
1192 $this->invoice_in_error = array();
1193 $this->thirdparty_in_error = array();
1194
1195 // Get all invoices to process into $factures
1196 $factures = array(); // TODO Rename $factures... into $payment_requests...
1197 $factures_prev = array();
1198 $factures_prev_id = array();
1199
1200 dol_syslog(__METHOD__ . " Read invoices/salaries for dids=" . implode(', ', $dids), LOG_DEBUG);
1201
1202 $sql = "SELECT f.rowid, pd.rowid as pfdrowid";
1203 $sql .= ", f.".$this->db->sanitize($socOrUser); // fk_soc or fk_user
1204 $sql .= ", pd.code_banque, pd.code_guichet, pd.number, pd.cle_rib";
1205 $sql .= ", pd.amount";
1206 if ($sourcetype != 'salary') {
1207 $sql .= ", s.nom as name";
1208 $sql .= ", f.ref";
1209 $sql .= ", sr.bic, sr.iban_prefix, sr.frstrecur, sr.default_rib, sr.rum";
1210 } else {
1211 $sql .= ", CONCAT(s.firstname, ' ', s.lastname) as name";
1212 $sql .= ", f.ref";
1213 $sql .= ", sr.bic, sr.iban_prefix, 'FRST' as frstrecur, sr.default_rib, '' as rum";
1214 }
1215 $sql .= ", pd.fk_societe_rib as soc_rib_id"; // Forced payment IBAN to use in priority
1216 $sql .= " FROM " . $this->db->prefix() . $sqlTable . " as f"; // f is salary, facture or facture_fourn
1217 $sql .= " INNER JOIN " . $this->db->prefix() . "prelevement_demande as pd ON f.rowid = pd.fk_".$this->db->sanitize($sqlTable);
1218 $sql .= " LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($societeOrUser)." as s ON s.rowid = f.".$this->db->sanitize($socOrUser);
1219 $sql .= " LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($societeOrUser."_rib")." as sr ON s.rowid = sr.".$this->db->sanitize($socOrUser); // To get the default BAN of thirdparty
1220 if ($sourcetype != 'salary') {
1221 $sql .= " AND sr.default_rib = 1";
1222 $sql .= " AND sr.type = 'ban'";
1223 } else {
1224 //$sql .= " AND sr.type = 'ban'"; // TODO Add AND sr.type = 'ban' for users too
1225 // TODO Add 'AND sr.default_rib = 1' in sourcetype salary too
1226 // Note: the column has been created in v21 in llx_user_rib and default to 0
1227 // If we add a test on sr.default_rib = 1, we must also check we have a correct error management to stop if no default BAN is found.
1228 // Also it may be found for on thirdparty and not for the other.
1229 }
1230 $sql .= " WHERE f.entity IN (".((int) $entity).')';
1231 if ($sourcetype != 'salary') {
1232 $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED; // Invoice validated
1233 $sql .= " AND f.paye = 0";
1234 $sql .= " AND f.total_ttc > 0";
1235 /*if ($socid > 0) {
1236 $sql .= " AND f.fk_soc = ".((int) $socid);
1237 }*/
1238 } else {
1239 //$sql .= " AND f.fk_statut = 1"; // Invoice validated
1240 $sql .= " AND f.paye = 0";
1241 $sql .= " AND f.amount > 0";
1242 }
1243 $sql .= " AND pd.traite = 0";
1244 $sql .= " AND pd.ext_payment_id IS NULL";
1245 if ($dids !== [0] && !empty($dids)) {
1246 $sql .= " AND pd.rowid IN (".$this->db->sanitize(implode(',', $dids)).")";
1247 }
1248
1249 $resql = $this->db->query($sql);
1250 if ($resql) {
1251 $num = $this->db->num_rows($resql);
1252 $i = 0;
1253
1254 while ($i < $num) {
1255 $row = $this->db->fetch_row($resql); // TODO Replace with fetch_object()
1256 '@phan-var-force array<int<0,12>,string> $row';
1259 // All fields:
1260 // 0=invoice or salary id, 1=pfdrowid (id of payment request), 2=$socOrUser, 3=code_banque, 4=code_guichet, 5=number, 6=key,
1261 // 7=amount, 8=company name, 9=invoice ref,
1262 // 10=default bic, 11=default iban (=the BAN to use if no soc_rib_id set), 12=default frstrecur, 13=default_rib, 14=default rum, 15=soc_rib_id (=the BAN to use in priority)
1263 $factures[$i] = $row;
1264
1265 // Decode default BAN
1266 $factures[$i][11] = dolDecrypt($factures[$i][11]);
1267
1268 if ($row[7] == 0) {
1269 $error++;
1270 dol_syslog(__METHOD__ . " Read invoices/salaries error Found a null amount", LOG_WARNING);
1271 $this->invoice_in_error[$row[0]] = "Error for invoice or salary id " . $row[0] . ", found a null amount";
1272 break;
1273 }
1274 $i++;
1275 }
1276
1277 $this->db->free($resql);
1278 dol_syslog(__METHOD__ . " Read invoices/salaries, " . $i . " invoices/salaries to withdraw", LOG_DEBUG);
1279 } else {
1280 $this->error = $this->db->lasterror();
1281 dol_syslog(__METHOD__ . " Read invoices/salaries error " . $this->db->lasterror(), LOG_ERR);
1282 return -1;
1283 }
1284
1285 if (!$error) {
1286 // Make some checks
1287 require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
1288 require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php';
1289 require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
1290 require_once DOL_DOCUMENT_ROOT . '/core/lib/bank.lib.php';
1291
1292 $tmpsoc = new Societe($this->db);
1293 $tmpuser = new User($this->db);
1294
1295 // Check BAN
1296 $i = 0;
1297 dol_syslog(__METHOD__ . " Check BAN for each invoices or salaries", LOG_DEBUG);
1298
1299 if (count($factures) > 0) {
1300 foreach ($factures as $key => $fac) {
1301 //var_dump($type, $format, $fac[8], $fac[12]);
1302
1303 // Check if $fac[8] s.nom is null
1304 if ($fac[8] != null) {
1305 if ($type != 'bank-transfer') {
1306 if ($format == 'FRST' && $fac[12] && $fac[12] != 'FRST') {
1307 continue;
1308 }
1309 if ($format == 'RCUR' && $fac[12] && $fac[12] != 'RCUR') {
1310 continue;
1311 }
1312 }
1313
1314 // If a bank account was forced on llx_prelevement_demande (the direct debit or credit transfer request),
1315 // we must use this one, so we reload values from soc_rib_id
1316 if (!empty($fac[15])) {
1317 $bankaccount = new CompanyBankAccount($this->db);
1318 $bankaccount->fetch((int) $fac[15]);
1319 if ($bankaccount->id > 0) {
1320 $fac[3] = $bankaccount->code_banque;
1321 $fac[4] = $bankaccount->code_guichet;
1322 $fac[5] = $bankaccount->number;
1323 $fac[6] = $bankaccount->cle_rib;
1324 $fac[10] = $bankaccount->bic;
1325 $fac[11] = $bankaccount->iban;
1326 $fac[14] = $bankaccount->rum;
1327 //var_dump('fetch id='.(int) $fac[14].' => '.$fac[3].'-'.$fac[4].'-'.$fac[5].'-'.$fac[6].'-'.$fac[10]."-".$fac[11]."-".$fac[14]);
1328 }
1329 }
1330
1331 $bicinloop = $fac[10];
1332 $baninloop = $fac[11];
1333
1334 $verif = checkSwiftForAccount(null, $bicinloop);
1335
1336 if ($verif || (empty($fac[10]) && getDolGlobalInt("WITHDRAWAL_WITHOUT_BIC"))) {
1337 dol_syslog(__METHOD__." now call checkIbanForAccount(null, ".$baninloop.")");
1338 $verif = checkIbanForAccount(null, $baninloop);
1339 }
1340
1341 if ($verif) {
1342 $factures_prev[$i] = $fac;
1343 /* second array necessary for BonPrelevement */
1344 $factures_prev_id[$i] = $fac[0];
1345 $i++;
1346 //dol_syslog(__METHOD__."::RIB is ok", LOG_DEBUG);
1347 } else {
1348 if ($type != 'bank-transfer') {
1349 $tmpsoc->id = (int) $fac[2];
1350 $tmpsoc->name = $fac[8];
1351 $invoice_url = "<a href='" . DOL_URL_ROOT . '/compta/facture/card.php?facid=' . $fac[0] . "'>" . $fac[9] . "</a>";
1352 $this->invoice_in_error[$fac[0]] = "Error incomplete properties of the default bank number ".$baninloop." IBAN/BIC for invoice " . $invoice_url . " for thirdparty " . $tmpsoc->getNomUrl(0);
1353 $this->thirdparty_in_error[$tmpsoc->id] = "Error on default bank number IBAN/BIC for invoice " . $invoice_url . " for thirdparty " . $tmpsoc->getNomUrl(0);
1354 $error++;
1355 }
1356 if ($type == 'bank-transfer' && $sourcetype != 'salary') {
1357 $tmpsoc->id = (int) $fac[2];
1358 $tmpsoc->name = $fac[8];
1359 $invoice_url = "<a href='" . DOL_URL_ROOT . '/fourn/facture/card.php?facid=' . $fac[0] . "'>" . $fac[9] . "</a>";
1360 $this->invoice_in_error[$fac[0]] = "Error incomplete properties of the default bank number ".$baninloop." IBAN/BIC for invoice " . $invoice_url . " for thirdparty " . $tmpsoc->getNomUrl(0);
1361 $this->thirdparty_in_error[$tmpsoc->id] = "Error on default bank number IBAN/BIC for invoice " . $invoice_url . " for thirdparty " . $tmpsoc->getNomUrl(0);
1362 $error++;
1363 }
1364 if ($type == 'bank-transfer' && $sourcetype == 'salary') {
1365 $tmpuser->id = (int) $fac[2];
1366 $tmpuser->firstname = $fac[8];
1367 $salary_url = "<a href='" . DOL_URL_ROOT . '/salaries/card.php?id=' . $fac[0] . "'>" . $fac[0] . "</a>";
1368 $this->invoice_in_error[$fac[0]] = "Error incomplete properties of the default bank number ".$baninloop." IBAN/BIC for salary " . $salary_url . " for employee " . $tmpuser->getNomUrl(0);
1369 $this->thirdparty_in_error[$tmpuser->id] = "Error on default bank number IBAN/BIC for salary " . $salary_url . " for employee " . $tmpuser->getNomUrl(0);
1370 $error++;
1371 }
1372 dol_syslog(__METHOD__ . " Check BAN Error on default bank number IBAN/BIC reported by verif(): " . implode(', ', $fac), LOG_WARNING);
1373 }
1374 } else {
1375 dol_syslog(__METHOD__ . " Check BAN Failed to read company", LOG_WARNING);
1376 }
1377 /*
1378 } else {
1379 dol_syslog(__METHOD__." Check BAN Failed to read invoice", LOG_WARNING);
1380 }
1381 */
1382 }
1383 } else {
1384 dol_syslog(__METHOD__ . " Check BAN No invoice to process", LOG_WARNING);
1385 }
1386 }
1387
1388 $ok = 0;
1389
1390 // Withdraw invoices in factures_prev array
1391 $out = count($factures_prev) . " invoices or salaries will be included.";
1392 dol_syslog($out);
1393
1394 //var_dump($factures_prev, $this->invoice_in_error, $this->thirdparty_in_error);exit;
1395
1396 if (count($factures_prev) > 0) {
1397 if ($mode == 'real') {
1398 $ok = 1;
1399 } else {
1400 print $langs->trans("ModeWarning"); // "Option for real mode was not set, we stop after this simulation\n";
1401 }
1402 }
1403 if ($ok) {
1404 /*
1405 * We are in real mode.
1406 * We create order and build file into disk
1407 */
1408 $this->db->begin();
1409
1410 $now = dol_now();
1411 $ref = '';
1412
1413 /*
1414 * Process order generation
1415 */
1416 if (!$error) {
1417 $ref = substr($year, -2) . $month;
1418
1419 $prefixt = "T";
1420
1421 // Get next free number for the ref of bon prelevement
1422 $sql = "SELECT SUBSTRING(ref, 6) AS refnumber"; // To suppress "TYYMM" from "TYYMMXXX"
1423 $sql .= " FROM " . MAIN_DB_PREFIX . "prelevement_bons";
1424 $sql .= " WHERE ref LIKE '" . $this->db->escape($prefixt . $ref) . "%'";
1425 $sql .= " AND entity = " . ((int) $conf->entity);
1426 $sql .= " ORDER BY LENGTH(ref) DESC, ref DESC";
1427 $sql .= " LIMIT 1";
1428
1429 dol_syslog(get_class($this) . " get next free number", LOG_DEBUG);
1430
1431 $resql = $this->db->query($sql);
1432
1433 if ($resql) {
1434 $row = $this->db->fetch_row($resql);
1435
1436 // Build the new ref
1437 $ref = $prefixt . $ref . sprintf("%03d", (intval($row[0] ?? 0) + 1));
1438
1439 // $conf->abc->dir_output may be:
1440 // /home/ldestailleur/git/dolibarr_15.0/documents/abc/
1441 // or
1442 // /home/ldestailleur/git/dolibarr_15.0/documents/X/abc with X >= 2 with multicompany.
1443 if ($type != 'bank-transfer') {
1444 $dir = $conf->prelevement->dir_output . '/receipts';
1445 } else {
1446 $dir = $conf->paymentbybanktransfer->dir_output . '/receipts';
1447 }
1448 if (!is_dir($dir)) {
1449 dol_mkdir($dir);
1450 }
1451
1452 if (isModEnabled('multicompany')) {
1453 $labelentity = $conf->entity;
1454 $this->filename = $dir . '/' . $ref . '-' . $labelentity . '.xml';
1455 } else {
1456 $this->filename = $dir . '/' . $ref . '.xml';
1457 }
1458
1459 // Create withdraw order in database
1460 $sql = "INSERT INTO " . MAIN_DB_PREFIX . "prelevement_bons (";
1461 $sql .= "ref, entity, datec, type, fk_bank_account";
1462 $sql .= ") VALUES (";
1463 $sql .= "'" . $this->db->escape($ref) . "'";
1464 $sql .= ", " . ((int) $conf->entity);
1465 $sql .= ", '" . $this->db->idate($now) . "'";
1466 $sql .= ", '" . ($type == 'bank-transfer' ? 'bank-transfer' : 'debit-order') . "'";
1467 $sql .= ", " . ((int) $fk_bank_account);
1468 $sql .= ")";
1469
1470 $resql = $this->db->query($sql);
1471
1472 if ($resql) {
1473 $prev_id = $this->db->last_insert_id(MAIN_DB_PREFIX . "prelevement_bons");
1474 $this->id = $prev_id;
1475 $this->ref = $ref;
1476 } else {
1477 $error++;
1478 $this->errors[] = $this->db->lasterror();
1479 dol_syslog(__METHOD__ . " Create withdraw receipt " . $this->db->lasterror(), LOG_ERR);
1480 }
1481 } else {
1482 $error++;
1483 $this->errors[] = $this->db->lasterror();
1484 dol_syslog(__METHOD__ . " Get last withdraw receipt " . $this->db->lasterror(), LOG_ERR);
1485 }
1486 }
1487
1488 if (!$error) {
1489 dol_syslog(__METHOD__ . " Now loop on each document to insert them in llx_prelevement_demande");
1490
1491 // Add lines for the direct debit or crdit transfer
1492 if (count($factures_prev) > 0) {
1493 foreach ($factures_prev as $fac) { // Add a link in database for each invoice or salary
1494 /*
1495 * Add standing order. This add record into llx_prelevement_lignes and llx_prelevement
1496 * The llx_prelevement_ligne will then be read to build the XML SEPA file.
1497 *
1498 * $fac[0] : invoice or salary id
1499 * $fac[1] : id of payment request (rowid in llx_prelevement_demande)
1500 * $fac[2] : third party id
1501 * $fac[3] : banque
1502 * $fac[4] : guichet
1503 * $fac[5] : number
1504 * $fac[6] : cle rib
1505 * $fac[7] : amount
1506 * $fac[8] : client nom
1507 * $fac[9] : Invoice ref
1508 * $fac[10] : BIC
1509 * $fac[11] : IBAN
1510 * $fac[12] : frstrcur
1511 * $fac[13] : default_rib (0 or 1)
1512 * $fac[14] : rum
1513 * $fac[15] : soc_rib_id (id bank account preselected for direct debit or credit transfer)
1514 */
1515 $ri = $this->addWithdrawDetail(
1516 $fac[0],
1517 $fac[2],
1518 $fac[8],
1519 $fac[7],
1520 $fac[3],
1521 $fac[4],
1522 $fac[5],
1523 $fac[6],
1524 $type,
1525 $sourcetype,
1526 $fac[10],
1527 $fac[11],
1528 $fac[14],
1529 $fac[1]
1530 );
1531
1532 if ($ri != 0) {
1533 $error++;
1534 }
1535
1536 // Update invoice requests as done
1537 $sql = "UPDATE " . MAIN_DB_PREFIX . "prelevement_demande";
1538 $sql .= " SET traite = 1";
1539 $sql .= ", date_traite = '" . $this->db->idate($now) . "'";
1540 $sql .= ", fk_prelevement_bons = " . ((int) $this->id);
1541 $sql .= " WHERE rowid = " . ((int) $fac[1]);
1542
1543 $resql = $this->db->query($sql);
1544 if (!$resql) {
1545 $error++;
1546 $this->errors[] = $this->db->lasterror();
1547 dol_syslog(__METHOD__ . " Update Error=" . $this->db->lasterror(), LOG_ERR);
1548 }
1549 }
1550 }
1551 }
1552
1553 if (!$error) {
1554 /*
1555 * Create file of type='direct-debit' for direct debit order or type='bank-transfer' for credit transfer into a XML file
1556 */
1557
1558 dol_syslog(__METHOD__ . " Init direct debit or credit transfer file for " . count($factures_prev) . " invoices", LOG_DEBUG);
1559
1560 if (count($factures_prev) > 0) {
1561 $this->date_echeance = $datetimeprev;
1562 $this->reference_remise = $ref;
1563
1564 $account = new Account($this->db);
1565 if ($account->fetch($fk_bank_account) > 0) {
1566 $this->emetteur_code_banque = $account->code_banque;
1567 $this->emetteur_code_guichet = $account->code_guichet;
1568 $this->emetteur_numero_compte = $account->number;
1569 $this->emetteur_number_key = $account->cle_rib;
1570 $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
1571 $this->emetteur_iban = $account->iban;
1572 $this->emetteur_bic = $account->bic;
1573
1574 $this->emetteur_ics = (($type == 'bank-transfer' && getDolGlobalString("SEPA_USE_IDS")) ? $account->ics_transfer : $account->ics); // Example "FR78ZZZ123456"
1575
1576 $this->raison_sociale = $account->owner_name;
1577 }
1578 $this->factures = $factures_prev_id;
1579 $this->context['factures_prev'] = $factures_prev;
1580 // Generation of direct debit or credit transfer file $this->filename (May be a SEPA file for european countries)
1581 // This also set the property $this->total with amount that is included into file
1582 $userid = 0;
1583 if ($sourcetype == 'salary') {
1584 $userid = $this->context['factures_prev'][0][2];
1585 }
1586 $result = $this->generate($format, $executiondate, $type, $fk_bank_account, $userid, 0);
1587 if ($result < 0) {
1588 //var_dump($this->error);
1589 //var_dump($this->invoice_in_error);
1590 $error++;
1591 }
1592 }
1593 dol_syslog(__METHOD__ . " Bank order file has been generated under filename " . $this->filename, LOG_DEBUG);
1594 }
1595
1596
1597 /*
1598 * Update total defined after generation of file
1599 */
1600 if (!$error) {
1601 $sql = "UPDATE " . MAIN_DB_PREFIX . "prelevement_bons";
1602 $sql .= " SET amount = " . price2num($this->total);
1603 $sql .= " WHERE rowid = " . ((int) $this->id);
1604 $sql .= " AND entity = " . ((int) $conf->entity);
1605 $resql = $this->db->query($sql);
1606
1607 if (!$resql) {
1608 $error++;
1609 dol_syslog(__METHOD__ . " Error update total: " . $this->db->error(), LOG_ERR);
1610 }
1611 }
1612
1613 if (!$error && !$notrigger) {
1614 $triggerName = ($type == 'bank-transfer') ? 'CREDIT_TRANSFER_ORDER_CREATE' : 'DIRECT_DEBIT_ORDER_CREATE';
1615 $this->amount = $this->total;
1616
1617 // Call trigger
1618 $result = $this->call_trigger($triggerName, $user);
1619 if ($result < 0) {
1620 $error++;
1621 }
1622 // End call triggers
1623 }
1624
1625 if (!$error) {
1626 $this->db->commit();
1627 return count($factures_prev); // The error of failed lines are into $this->invoice_in_error and $this->thirdparty_in_error
1628 } else {
1629 $this->db->rollback();
1630 return -1;
1631 }
1632 } else {
1633 return 0;
1634 }
1635 }
1636
1637
1645 public function delete($user, $notrigger = 0)
1646 {
1647 $this->db->begin();
1648
1649 $error = 0;
1650 $resql1 = $resql2 = $resql3 = $resql4 = 0;
1651
1652 if (!$notrigger) {
1653 $triggername = 'DIRECT_DEBIT_ORDER_DELETE';
1654 if ($this->type == 'bank-transfer') {
1655 $triggername = 'PAYMENTBYBANKTRANFER_DELETE';
1656 }
1657 // Call trigger
1658 $result = $this->call_trigger($triggername, $user);
1659 if ($result < 0) {
1660 $error++;
1661 }
1662 // End call triggers
1663 }
1664
1665 if (!$error) {
1666 $sql = "DELETE FROM " . MAIN_DB_PREFIX . "prelevement WHERE fk_prelevement_lignes IN (SELECT rowid FROM " . MAIN_DB_PREFIX . "prelevement_lignes WHERE fk_prelevement_bons = " . ((int) $this->id) . ")";
1667 $resql1 = $this->db->query($sql);
1668 if (!$resql1) {
1669 dol_print_error($this->db);
1670 }
1671 }
1672
1673 if (!$error) {
1674 $sql = "DELETE FROM " . MAIN_DB_PREFIX . "prelevement_lignes WHERE fk_prelevement_bons = " . ((int) $this->id);
1675 $resql2 = $this->db->query($sql);
1676 if (!$resql2) {
1677 dol_print_error($this->db);
1678 }
1679 }
1680
1681 if (!$error) {
1682 $sql = "DELETE FROM " . MAIN_DB_PREFIX . "prelevement_bons WHERE rowid = " . ((int) $this->id);
1683 $resql3 = $this->db->query($sql);
1684 if (!$resql3) {
1685 dol_print_error($this->db);
1686 }
1687 }
1688
1689 if (!$error) {
1690 $sql = "UPDATE " . MAIN_DB_PREFIX . "prelevement_demande SET fk_prelevement_bons = NULL, traite = 0 WHERE fk_prelevement_bons = " . ((int) $this->id);
1691 $resql4 = $this->db->query($sql);
1692 if (!$resql4) {
1693 dol_print_error($this->db);
1694 }
1695 }
1696
1697 if ($resql1 && $resql2 && $resql3 && $resql4 && !$error) {
1698 $this->db->commit();
1699 return 1;
1700 } else {
1701 $this->db->rollback();
1702 return -1;
1703 }
1704 }
1705
1706
1717 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
1718 {
1719 global $conf, $langs, $hookmanager;
1720
1721 if (!empty($conf->dol_no_mouse_hover)) {
1722 $notooltip = 1; // Force disable tooltips
1723 }
1724
1725 $result = '';
1726
1727 $labeltoshow = 'PaymentByDirectDebit';
1728 $labelforclosedate = 'CreditDate';
1729 if (!empty($this->type) && $this->type == 'bank-transfer') {
1730 $labeltoshow = 'PaymentByBankTransfer';
1731 $labelforclosedate = 'ClosedOn';
1732 }
1733
1734 $label = img_picto('', $this->picto) . ' <u>' . $langs->trans($labeltoshow) . '</u> ' . $this->getLibStatut(5);
1735 $label .= '<br>';
1736 $label .= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
1737 if (isset($this->amount)) {
1738 $label .= '<br><b>' . $langs->trans("Amount") . ':</b> <span class="amount">' . price($this->amount).'</span>';
1739 }
1740 if (isset($this->date_creation)) {
1741 $label .= '<br><b>'.$langs->trans("DateCreation").":</b> ".dol_print_date($this->date_creation, 'dayhour', 'tzuserrel');
1742 }
1743 if (isset($this->date_trans)) {
1744 $label .= '<br><b>' . $langs->trans("TransData") . ":</b> " . dol_print_date($this->date_trans, 'dayhour', 'tzuserrel');
1745 }
1746 if (isset($this->date_credit)) {
1747 $label .= '<br><b>'.$langs->trans($labelforclosedate).":</b> ".dol_print_date($this->date_credit, 'dayhour', 'tzuserrel');
1748 }
1749
1750 $url = DOL_URL_ROOT . '/compta/prelevement/card.php?id=' . $this->id;
1751 if (!empty($this->type) && $this->type == 'bank-transfer') {
1752 $url = DOL_URL_ROOT . '/compta/prelevement/card.php?id=' . $this->id;
1753 }
1754
1755 if ($option != 'nolink') {
1756 // Add param to save lastsearch_values or not
1757 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1758 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1759 $add_save_lastsearch_values = 1;
1760 }
1761 if ($add_save_lastsearch_values) {
1762 $url .= '&save_lastsearch_values=1';
1763 }
1764 }
1765
1766 $linkclose = '';
1767 if (empty($notooltip)) {
1768 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
1769 $label = $langs->trans("ShowMyObject");
1770 $linkclose .= ' alt="' . dol_escape_htmltag($label, 1) . '"';
1771 }
1772 $linkclose .= ' title="' . dol_escape_htmltag($label, 1) . '"';
1773 $linkclose .= ' class="classfortooltip' . ($morecss ? ' ' . $morecss : '') . '"';
1774 } else {
1775 $linkclose = ($morecss ? ' class="' . $morecss . '"' : '');
1776 }
1777
1778 $linkstart = '<a href="' . $url . '"';
1779 $linkstart .= $linkclose . '>';
1780 $linkend = '</a>';
1781
1782 $result .= $linkstart;
1783 if ($withpicto) {
1784 $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);
1785 }
1786 if ($withpicto != 2) {
1787 $result .= $this->ref;
1788 }
1789 $result .= $linkend;
1790
1791 global $action, $hookmanager;
1792 $hookmanager->initHooks(array('banktransferdao'));
1793 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1794 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1795 if ($reshook > 0) {
1796 $result = $hookmanager->resPrint;
1797 } else {
1798 $result .= $hookmanager->resPrint;
1799 }
1800
1801 return $result;
1802 }
1803
1804
1811 public function deleteNotificationById($rowid)
1812 {
1813 $sql = "DELETE FROM " . MAIN_DB_PREFIX . "notify_def";
1814 $sql .= " WHERE rowid = " . ((int) $rowid);
1815
1816 if ($this->db->query($sql)) {
1817 return 0;
1818 } else {
1819 return -1;
1820 }
1821 }
1822
1830 public function deleteNotification($user, $action)
1831 {
1832 if (is_object($user)) {
1833 $userid = $user->id;
1834 } else { // If user is an id
1835 $userid = $user;
1836 }
1837
1838 $sql = "DELETE FROM " . MAIN_DB_PREFIX . "notify_def";
1839 $sql .= " WHERE fk_user = " . ((int) $userid) . " AND fk_action = " . ((int) $action);
1840
1841 if ($this->db->query($sql)) {
1842 return 0;
1843 } else {
1844 return -1;
1845 }
1846 }
1847
1848 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1857 public function addNotification($db, $user, $action)
1858 {
1859 // phpcs:enable
1860 $result = 0;
1861
1862 if (is_object($user)) {
1863 $userid = $user->id;
1864 } else { // If user is an id
1865 $userid = $user;
1866 }
1867
1868 if ($this->deleteNotification($user, $action) == 0) {
1869 $now = dol_now();
1870
1871 $sql = "INSERT INTO " . MAIN_DB_PREFIX . "notify_def (datec, fk_user, fk_soc, fk_contact, fk_action)";
1872 $sql .= " VALUES ('" . $this->db->idate($now) . "', " . ((int) $userid) . ", NULL, NULL, " . ((int) $action) . ")";
1873
1874 dol_syslog("adnotiff: " . $sql);
1875 if ($this->db->query($sql)) {
1876 $result = 0;
1877 } else {
1878 $result = -1;
1879 dol_syslog(get_class($this) . "::addNotification Error $result");
1880 }
1881 }
1882
1883 return $result;
1884 }
1885
1886
1902 public function generate(string $format = 'FRST', int $executiondate = 0, string $type = 'direct-debit', int $fk_bank_account = 0, int $forsalary = 0, int $thirdpartyBANId = 0)
1903 {
1904 global $conf, $langs, $mysoc;
1905
1906 $this->sepa_schema_version = (getDolGlobalString('PRELEVEMENT_SEPA_SCHEMA_VERSION') == '8' ? '8' : '2');
1907
1908 if ($type !== 'bank-transfer') {
1909 $format = strtoupper($format);
1910 if (!in_array($format, array('FRST', 'RCUR', 'OOFF', 'FNAL'), true)) {
1911 $this->error = 'ErrorBadParametersForDirectDebitFileCreate';
1912 return -1;
1913 }
1914 }
1915
1916 //TODO: Optimize code to read lines in a single function
1917
1918 // Clean params
1919 if (empty($fk_bank_account)) {
1920 $fk_bank_account = ($type == 'bank-transfer' ? getDolGlobalInt('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') : getDolGlobalInt('PRELEVEMENT_ID_BANKACCOUNT'));
1921 }
1922
1923 $result = 0;
1924
1925 dol_syslog(get_class($this) . "::generate build file=" . $this->filename . " type=" . $type);
1926
1927 $this->file = fopen($this->filename, "w");
1928 if ($this->file == false) {
1929 $this->error = $langs->trans('ErrorFailedToOpenFile', $this->filename);
1930 return -1;
1931 }
1932
1933 $found = 0;
1934 $this->total = 0;
1935
1936 // Build file for European countries
1937 if ($mysoc->isInSEPA()) {
1938 $found++;
1939
1940 if ($type != 'bank-transfer') {
1944 // SEPA Initialisation
1945 $CrLf = "\n";
1946
1947 $now = dol_now();
1948
1949 $dateTime_ECMA = dol_print_date($now, '%Y-%m-%dT%H:%M:%S');
1950
1951 $date_actu = $now;
1952 if (!empty($executiondate)) {
1953 $date_actu = $executiondate;
1954 }
1955
1956 $dateTime_YMD = dol_print_date($date_actu, '%Y%m%d');
1957 $dateTime_YMDHMS = dol_print_date($date_actu, '%Y%m%d%H%M%S');
1958 $fileDebiteurSection = '';
1959 $fileEmetteurSection = '';
1960 $i = 0;
1961
1962 /*
1963 * Section Debitor (sepa Debiteurs block lines)
1964 */
1965
1966 $sql = "SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
1967 //$sql .= " pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, ";
1968 $sql .= " pl.client_nom as nom, pl.amount as somme, pl.fk_prelevement_demande,";
1969 $sql .= " f.ref as reffac,";
1970 $sql .= " p.fk_facture as idfac, p.rowid as pid,";
1971 $sql .= " rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
1972 $sql .= " FROM";
1973 $sql .= " " . MAIN_DB_PREFIX . "prelevement_lignes as pl,";
1974 $sql .= " " . MAIN_DB_PREFIX . "facture as f,";
1975 $sql .= " " . MAIN_DB_PREFIX . "prelevement as p,";
1976 $sql .= " " . MAIN_DB_PREFIX . "societe as soc,";
1977 $sql .= " " . MAIN_DB_PREFIX . "c_country as c,";
1978 $sql .= " " . MAIN_DB_PREFIX . "societe_rib as rib";
1979 $sql .= " WHERE pl.fk_prelevement_bons = " . ((int) $this->id);
1980 $sql .= " AND pl.rowid = p.fk_prelevement_lignes";
1981 $sql .= " AND p.fk_facture = f.rowid";
1982 $sql .= " AND f.fk_soc = soc.rowid";
1983 $sql .= " AND soc.fk_pays = c.rowid";
1984 $sql .= " AND rib.fk_soc = f.fk_soc";
1985 if (!empty($thirdpartyBANId)) {
1986 $sql .= " AND rib.rowid = " . ((int) $thirdpartyBANId);
1987 } else {
1988 $sql .= " AND rib.default_rib = 1";
1989 }
1990 $sql .= " AND rib.type = 'ban'";
1991
1992 // Define $fileDebiteurSection. One section DrctDbtTxInf per invoice.
1993 $resql = $this->db->query($sql);
1994 $nbtotalDrctDbtTxInf = -1;
1995 if ($resql) {
1996 $cachearraytotestduplicate = array();
1997
1998 $num = $this->db->num_rows($resql);
1999 while ($i < $num) {
2000 $obj = $this->db->fetch_object($resql);
2001
2002 if (!empty($cachearraytotestduplicate[$obj->idfac])) {
2003 $this->error = $langs->trans('ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
2004 $this->invoice_in_error[$obj->idfac] = $this->error;
2005 $result = -2;
2006 break;
2007 }
2008 $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
2009
2010 // Get the default value
2011 $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
2012 $iban = dolDecrypt($obj->iban);
2013 $bic = $obj->bic;
2014 $drum = $obj->drum;
2015 $rum = $obj->rum;
2016
2017 // But if a force bank account is defined, we use it instead
2018 if (!empty($obj->fk_prelevement_demande)) {
2019 $companybankaccountid = 0;
2020
2021 $sqltmp = "SELECT fk_societe_rib FROM ".MAIN_DB_PREFIX."prelevement_demande";
2022 $sqltmp .= " WHERE rowid = ".((int) $obj->fk_prelevement_demande);
2023
2024 $resqltmp = $this->db->query($sqltmp);
2025
2026 $objtmp = $this->db->fetch_object($resqltmp);
2027 if ($objtmp) {
2028 $companybankaccountid = (int) $objtmp->fk_societe_rib;
2029 }
2030
2031 $bankaccount = new CompanyBankAccount($this->db);
2032 $bankaccount->fetch($companybankaccountid);
2033 if ($bankaccount->id > 0) {
2034 $daterum = (!empty($bankaccount->date_rum) ? $bankaccount->date_rum : $bankaccount->datec); // Same fallback as the default bank account, or <DtOfSgntr> is empty
2035 $iban = $bankaccount->iban;
2036 $bic = $bankaccount->bic;
2037 $drum = $bankaccount->id;
2038 $rum = $bankaccount->rum;
2039 }
2040 }
2041
2042 $fileDebiteurSection .= $this->EnregDestinataireSEPA($obj->code, $obj->nom, $obj->address, $obj->zip, $obj->town, $obj->country_code, '', '', '', $obj->somme, $obj->reffac, $obj->idfac, $iban, $bic, $daterum, (string) $drum, $rum, $type);
2043
2044 $this->total += $obj->somme;
2045 $i++;
2046 }
2047 $nbtotalDrctDbtTxInf = $i;
2048 } else {
2049 $this->error = $this->db->lasterror();
2050 fwrite($this->file, 'ERROR DEBITOR ' . $sql . $CrLf); // DEBITOR = Customers
2051 $result = -2;
2052 }
2053
2054 // Define $fileEmetteurSection. Start of block PmtInf. Will contains all $nbtotalDrctDbtTxInf
2055 if ($result != -2) {
2056 $fileEmetteurSection .= $this->EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type, $fk_bank_account);
2057 }
2058
2059 if (getDolGlobalString('SEPA_FORCE_TWO_DECIMAL')) {
2060 $this->total = number_format((float) price2num($this->total, 'MT'), 2, ".", "");
2061 }
2062
2066 // SEPA File Header
2067 fwrite($this->file, '<' . '?xml version="1.0" encoding="UTF-8" standalone="yes"?' . '>' . $CrLf);
2068 $sepaSchemaVersion = $this->sepa_schema_version;
2069 $sepaNamespace = 'urn:iso:std:iso:20022:tech:xsd:pain.008.001.0' . $sepaSchemaVersion;
2070 fwrite($this->file, '<Document xmlns="' . $sepaNamespace . '" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' . $CrLf);
2071 fwrite($this->file, ' <CstmrDrctDbtInitn>' . $CrLf);
2072 // SEPA Group header
2073 fwrite($this->file, ' <GrpHdr>' . $CrLf);
2074 fwrite($this->file, ' <MsgId>' . ('DOL/' . $dateTime_YMD . '/DD' . $this->id) . '</MsgId>' . $CrLf);
2075 fwrite($this->file, ' <CreDtTm>' . $dateTime_ECMA . '</CreDtTm>' . $CrLf);
2076 fwrite($this->file, ' <NbOfTxs>' . $i . '</NbOfTxs>' . $CrLf);
2077 fwrite($this->file, ' <CtrlSum>' . $this->total . '</CtrlSum>' . $CrLf);
2078 fwrite($this->file, ' <InitgPty>' . $CrLf);
2079 fwrite($this->file, ' <Nm>' . dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale), ' '))) . '</Nm>' . $CrLf);
2080 fwrite($this->file, ' <Id>' . $CrLf);
2081 fwrite($this->file, ' <PrvtId>' . $CrLf);
2082 fwrite($this->file, ' <Othr>' . $CrLf);
2083 fwrite($this->file, ' <Id>' . $this->emetteur_ics . '</Id>' . $CrLf);
2084 fwrite($this->file, ' </Othr>' . $CrLf);
2085 fwrite($this->file, ' </PrvtId>' . $CrLf);
2086 fwrite($this->file, ' </Id>' . $CrLf);
2087 fwrite($this->file, ' </InitgPty>' . $CrLf);
2088 fwrite($this->file, ' </GrpHdr>' . $CrLf);
2089 // SEPA File Emetteur
2090 if ($result != -2) {
2091 fwrite($this->file, $fileEmetteurSection);
2092 }
2093 // SEPA File Debiteurs
2094 if ($result != -2) {
2095 fwrite($this->file, $fileDebiteurSection);
2096 }
2097 // SEPA FILE FOOTER
2098 fwrite($this->file, ' </PmtInf>' . $CrLf);
2099 fwrite($this->file, ' </CstmrDrctDbtInitn>' . $CrLf);
2100 fwrite($this->file, '</Document>' . $CrLf);
2101 } else {
2105 // SEPA Initialisation
2106 $CrLf = "\n";
2107
2108 $now = dol_now();
2109
2110 $dateTime_ECMA = dol_print_date($now, '%Y-%m-%dT%H:%M:%S');
2111
2112 $date_actu = $now;
2113 if (!empty($executiondate)) {
2114 $date_actu = $executiondate;
2115 }
2116
2117 $dateTime_YMD = dol_print_date($date_actu, '%Y%m%d');
2118 $dateTime_YMDHMS = dol_print_date($date_actu, '%Y%m%d%H%M%S');
2119 $fileCrediteurSection = '';
2120 $fileEmetteurSection = '';
2121 $i = 0;
2122
2123 /*
2124 * Section Creditor (sepa Crediteurs block lines)
2125 */
2126 if (!empty($forsalary)) {
2127 $sql = "SELECT u.rowid as userId, u.address, u.zip, u.town, c.code as country_code, CONCAT(u.firstname,' ',u.lastname) as nom,";
2128 //$sql .= " pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, ";
2129 $sql .= " pl.client_nom as nom, pl.amount as somme, pl.fk_prelevement_demande,";
2130 $sql .= " s.ref as reffac,";
2131 $sql .= " p.fk_salary as idfac,";
2132 $sql .= " rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, '' as rum, '' as date_rum";
2133 $sql .= " FROM";
2134 $sql .= " " . MAIN_DB_PREFIX . "prelevement_lignes as pl,";
2135 $sql .= " " . MAIN_DB_PREFIX . "salary as s,";
2136 $sql .= " " . MAIN_DB_PREFIX . "prelevement as p,";
2137 $sql .= " " . MAIN_DB_PREFIX . "user as u";
2138 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_country as c ON u.fk_country = c.rowid,";
2139 $sql .= " " . MAIN_DB_PREFIX . "user_rib as rib";
2140 $sql .= " WHERE pl.fk_prelevement_bons=" . ((int) $this->id);
2141 $sql .= " AND pl.rowid = p.fk_prelevement_lignes";
2142 $sql .= " AND p.fk_salary = s.rowid";
2143 $sql .= " AND s.fk_user = u.rowid";
2144 $sql .= " AND rib.fk_user = s.fk_user";
2145 } else {
2146 $sql = "SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
2147 //$sql .= " pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, ";
2148 $sql .= " pl.client_nom as nom, pl.amount as somme, pl.fk_prelevement_demande,";
2149 $sql .= " f.ref as reffac, f.ref_supplier as fac_ref_supplier,";
2150 $sql .= " p.fk_facture_fourn as idfac,";
2151 $sql .= " rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
2152 $sql .= " FROM";
2153 $sql .= " " . MAIN_DB_PREFIX . "prelevement_lignes as pl,";
2154 $sql .= " " . MAIN_DB_PREFIX . "facture_fourn as f,";
2155 $sql .= " " . MAIN_DB_PREFIX . "prelevement as p,";
2156 $sql .= " " . MAIN_DB_PREFIX . "societe as soc";
2157 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_country as c ON soc.fk_pays = c.rowid,";
2158 $sql .= " " . MAIN_DB_PREFIX . "societe_rib as rib";
2159 $sql .= " WHERE pl.fk_prelevement_bons = " . ((int) $this->id);
2160 $sql .= " AND pl.rowid = p.fk_prelevement_lignes";
2161 $sql .= " AND p.fk_facture_fourn = f.rowid";
2162 $sql .= " AND f.fk_soc = soc.rowid";
2163 $sql .= " AND rib.fk_soc = f.fk_soc";
2164 if (!empty($thirdpartyBANId)) {
2165 $sql .= " AND rib.rowid = " . ((int) $thirdpartyBANId);
2166 } else {
2167 $sql .= " AND rib.default_rib = 1";
2168 }
2169 $sql .= " AND rib.type = 'ban'";
2170 }
2171 // Define $fileCrediteurSection. One section DrctDbtTxInf per invoice.
2172 $nbtotalDrctDbtTxInf = -1;
2173
2174 require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
2175
2176 $resql = $this->db->query($sql);
2177 if ($resql) {
2178 $cachearraytotestduplicate = array();
2179
2180 $num = $this->db->num_rows($resql);
2181 while ($i < $num) {
2182 $obj = $this->db->fetch_object($resql);
2183
2184 // Test to avoid duplicate default IBAN, to ask user to clean its data
2185 if (!empty($cachearraytotestduplicate[$obj->idfac])) {
2186 $this->error = $langs->trans('ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
2187 $this->invoice_in_error[$obj->idfac] = $this->error;
2188 $result = -2;
2189 break;
2190 }
2191
2192 $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
2193
2194 // Get the default value
2195 $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
2196 $iban = dolDecrypt($obj->iban);
2197 $bic = $obj->bic;
2198 $drum = $obj->drum;
2199 $rum = $obj->rum;
2200
2201 // But if a force bank account is defined, we use it instead
2202 if (!empty($obj->fk_prelevement_demande)) {
2203 $companybankaccountid = 0;
2204
2205 $sqltmp = "SELECT fk_societe_rib FROM ".MAIN_DB_PREFIX."prelevement_demande";
2206 $sqltmp .= " WHERE rowid = ".((int) $obj->fk_prelevement_demande);
2207
2208 $resqltmp = $this->db->query($sqltmp);
2209
2210 $objtmp = $this->db->fetch_object($resqltmp);
2211 if ($objtmp) {
2212 $companybankaccountid = (int) $objtmp->fk_societe_rib;
2213 }
2214
2215 $bankaccount = new CompanyBankAccount($this->db);
2216 $bankaccount->fetch($companybankaccountid);
2217 if ($bankaccount->id > 0) {
2218 $daterum = (!empty($bankaccount->date_rum) ? $bankaccount->date_rum : $bankaccount->datec); // Same fallback as the default bank account, or <DtOfSgntr> is empty
2219 $iban = $bankaccount->iban;
2220 $bic = $bankaccount->bic;
2221 $drum = $bankaccount->id;
2222 $rum = $bankaccount->rum;
2223 }
2224 }
2225
2226 $refobj = $obj->reffac;
2227 if (empty($refobj) && !empty($forsalary)) { // If ref of salary not defined, we force a value
2228 $refobj = "SAL" . $obj->idfac;
2229 }
2230
2231 $fileCrediteurSection .= $this->EnregDestinataireSEPA($obj->code, $obj->nom, $obj->address, $obj->zip, $obj->town, $obj->country_code, '', '', '', $obj->somme, $refobj, $obj->idfac, $iban, $bic, $daterum, (string) $drum, $rum, $type, $obj->fac_ref_supplier);
2232
2233 $this->total += $obj->somme;
2234 $i++;
2235 }
2236 $nbtotalDrctDbtTxInf = $i;
2237 } else {
2238 $this->error = $this->db->lasterror();
2239 fwrite($this->file, 'ERROR CREDITOR ' . $sql . $CrLf); // CREDITORS = Suppliers
2240 $result = -2;
2241 }
2242 // Define $fileEmetteurSection. Start of block PmtInf. Will contains all $nbtotalDrctDbtTxInf
2243 if ($result != -2) {
2244 $fileEmetteurSection .= $this->EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type);
2245 }
2246
2247 if (getDolGlobalString('SEPA_FORCE_TWO_DECIMAL')) {
2248 $this->total = number_format((float) price2num($this->total, 'MT'), 2, ".", "");
2249 }
2250
2254 // SEPA File Header
2255 fwrite($this->file, '<' . '?xml version="1.0" encoding="UTF-8" standalone="yes"?' . '>' . $CrLf);
2256 fwrite($this->file, '<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' . $CrLf);
2257 fwrite($this->file, ' <CstmrCdtTrfInitn>' . $CrLf);
2258 // SEPA Group header
2259 fwrite($this->file, ' <GrpHdr>' . $CrLf);
2260 fwrite($this->file, ' <MsgId>' . ('DOL/' . $dateTime_YMD . '/CT' . $this->id) . '</MsgId>' . $CrLf);
2261 fwrite($this->file, ' <CreDtTm>' . $dateTime_ECMA . '</CreDtTm>' . $CrLf);
2262 fwrite($this->file, ' <NbOfTxs>' . $i . '</NbOfTxs>' . $CrLf);
2263 fwrite($this->file, ' <CtrlSum>' . $this->total . '</CtrlSum>' . $CrLf);
2264 fwrite($this->file, ' <InitgPty>' . $CrLf);
2265 fwrite($this->file, ' <Nm>' . dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale), ' '))) . '</Nm>' . $CrLf);
2266 fwrite($this->file, ' <Id>' . $CrLf);
2267 fwrite($this->file, ' <PrvtId>' . $CrLf);
2268 fwrite($this->file, ' <Othr>' . $CrLf);
2269 fwrite($this->file, ' <Id>' . $this->emetteur_ics . '</Id>' . $CrLf);
2270 fwrite($this->file, ' </Othr>' . $CrLf);
2271 fwrite($this->file, ' </PrvtId>' . $CrLf);
2272 fwrite($this->file, ' </Id>' . $CrLf);
2273 fwrite($this->file, ' </InitgPty>' . $CrLf);
2274 fwrite($this->file, ' </GrpHdr>' . $CrLf);
2275 // SEPA File Emetteur (mycompany)
2276 if ($result != -2) {
2277 fwrite($this->file, $fileEmetteurSection);
2278 }
2279 // SEPA File Creditors
2280 if ($result != -2) {
2281 fwrite($this->file, $fileCrediteurSection);
2282 }
2283 // SEPA FILE FOOTER
2284 fwrite($this->file, ' </PmtInf>' . $CrLf);
2285 fwrite($this->file, ' </CstmrCdtTrfInitn>' . $CrLf);
2286 fwrite($this->file, '</Document>' . $CrLf);
2287 }
2288 }
2289
2290 // Build file for Other Countries with unknown format
2291 if (!$found) {
2292 if ($type != 'bank-transfer') {
2293 $sql = "SELECT pl.amount";
2294 $sql .= " FROM";
2295 $sql .= " " . MAIN_DB_PREFIX . "prelevement_lignes as pl,";
2296 $sql .= " " . MAIN_DB_PREFIX . "facture as f,";
2297 $sql .= " " . MAIN_DB_PREFIX . "prelevement as p";
2298 $sql .= " WHERE pl.fk_prelevement_bons = " . ((int) $this->id);
2299 $sql .= " AND pl.rowid = p.fk_prelevement_lignes";
2300 $sql .= " AND p.fk_facture = f.rowid";
2301
2302 // Lines
2303 $i = 0;
2304 $resql = $this->db->query($sql);
2305 if ($resql) {
2306 $num = $this->db->num_rows($resql);
2307
2308 while ($i < $num) {
2309 $obj = $this->db->fetch_object($resql);
2310 $this->total += $obj->amount;
2311
2312 // TODO Write record into file
2313 $i++;
2314 }
2315 } else {
2316 $result = -2;
2317 }
2318 } else {
2319 $sql = "SELECT pl.amount";
2320 $sql .= " FROM";
2321 $sql .= " " . MAIN_DB_PREFIX . "prelevement_lignes as pl,";
2322 $sql .= " " . MAIN_DB_PREFIX . "facture_fourn as f,";
2323 $sql .= " " . MAIN_DB_PREFIX . "prelevement as p";
2324 $sql .= " WHERE pl.fk_prelevement_bons = " . ((int) $this->id);
2325 $sql .= " AND pl.rowid = p.fk_prelevement_lignes";
2326 $sql .= " AND p.fk_facture_fourn = f.rowid";
2327 // Lines
2328 $i = 0;
2329 $resql = $this->db->query($sql);
2330 if ($resql) {
2331 $num = $this->db->num_rows($resql);
2332
2333 while ($i < $num) {
2334 $obj = $this->db->fetch_object($resql);
2335 $this->total += $obj->amount;
2336
2337 // TODO Write record into file
2338 $i++;
2339 }
2340 } else {
2341 $result = -2;
2342 }
2343 }
2344
2345 $langs->load('withdrawals');
2346
2347 // TODO Add here code to generate a generic file
2348 fwrite($this->file, $langs->transnoentitiesnoconv('WithdrawalFileNotCapable', $mysoc->country_code));
2349 }
2350
2351 fclose($this->file);
2352 dolChmod($this->filename);
2353
2354 return $result;
2355 }
2356
2357
2366 public static function buildRumNumber($row_code_client, $row_datec, $row_drum)
2367 {
2368 global $langs;
2369
2370 $pre = substr(dol_string_nospecial(dol_string_unaccent($langs->transnoentitiesnoconv('RUM'))), 0, 3); // Must always be on 3 char ('RUM' or 'UMR'. This is a protection against bad translation)
2371
2372 // 3 char + '-' + 10 (yymmddHHMM) + '-' + id + '-' + code. Must be under 32 (SEPA char limit for MndtId is however 35).
2373 return $pre . '-' . dol_print_date($row_datec, 'dayhourlogsmall') . '-' . dol_trunc((string) $row_drum . ($row_code_client ? '-' . $row_code_client : ''), 17, 'right', 'UTF-8', 1);
2374 }
2375
2376
2395 public function buildSEPAPostalAddressXML($address, $zip, $town, $country_code, $indent, $CrLf)
2396 {
2397 $town = dol_string_nospecial(dol_string_unaccent((string) $town), ' ');
2398 $country_code = trim((string) $country_code);
2399
2400 $missingelements = array();
2401 if (trim($town) == '') {
2402 $missingelements[] = 'town';
2403 }
2404 if ($country_code == '') {
2405 $missingelements[] = 'country code';
2406 }
2407 if (count($missingelements) > 0) {
2408 // TwnNm and Ctry are mandatory inside PstlAdr: omit the whole block and warn when one of them is empty
2409 dol_syslog('buildSEPAPostalAddressXML: PstlAdr block omitted because the '.implode(' and the ', $missingelements).' is empty.', LOG_WARNING);
2410 return '';
2411 }
2412
2413 $XML_ADR = $indent . '<PstlAdr>' . $CrLf;
2414 $zip = dol_string_nospecial(dol_string_unaccent((string) $zip), ' ');
2415 if (trim($zip) != '') {
2416 $XML_ADR .= $indent . ' <PstCd>' . dolEscapeXML(dol_trunc($zip, 16, 'right', 'UTF-8', 1)) . '</PstCd>' . $CrLf;
2417 }
2418 $XML_ADR .= $indent . ' <TwnNm>' . dolEscapeXML(dol_trunc($town, 35, 'right', 'UTF-8', 1)) . '</TwnNm>' . $CrLf;
2419 $XML_ADR .= $indent . ' <Ctry>' . dolEscapeXML($country_code) . '</Ctry>' . $CrLf;
2420 $addressline1 = strtr((string) $address, array(chr(13) => ", ", chr(10) => ""));
2421 if (trim($addressline1)) {
2422 $XML_ADR .= $indent . ' <AdrLine>' . dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($addressline1), ' '), 70, 'right', 'UTF-8', 1)) . '</AdrLine>' . $CrLf;
2423 }
2424 $XML_ADR .= $indent . '</PstlAdr>' . $CrLf;
2425
2426 return $XML_ADR;
2427 }
2428
2429 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2446 public function EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $ref, $facid, $rib_dom = '', $type = 'direct-debit')
2447 {
2448 // phpcs:enable
2449 fwrite($this->file, "06");
2450 fwrite($this->file, "08"); // Prelevement ordinaire
2451
2452 fwrite($this->file, " "); // Zone Reservee B2
2453
2454 fwrite($this->file, $this->emetteur_ics); // ICS
2455
2456 // Date d'echeance C1
2457
2458 fwrite($this->file, " ");
2459 fwrite($this->file, dol_print_date($this->date_echeance, "%d%m", 'gmt'));
2460 fwrite($this->file, substr(dol_print_date($this->date_echeance, "%y", 'gmt'), 1));
2461
2462 // Raison Sociale Destinataire C2
2463
2464 fwrite($this->file, substr(strtoupper($client_nom) . " ", 0, 24));
2465
2466 // Address optional D1
2467 $address = strtr($rib_dom, array(" " => "-", chr(13) => " ", chr(10) => ""));
2468 fwrite($this->file, substr($address . " ", 0, 24));
2469
2470 // Zone Reservee D2
2471
2472 fwrite($this->file, substr(" ", 0, 8));
2473
2474 // Code Guichet D3
2475
2476 fwrite($this->file, $rib_guichet);
2477
2478 // Numero de compte D4
2479
2480 fwrite($this->file, substr("000000000000000" . $rib_number, -11));
2481
2482 // Zone E Montant
2483
2484 $montant = (round($amount, 2) * 100);
2485
2486 fwrite($this->file, substr("000000000000000" . $montant, -16));
2487
2488 // Label F
2489
2490 fwrite($this->file, substr("*_" . $ref . "_RDVnet" . $rowid . " ", 0, 31));
2491
2492 // Code etablissement G1
2493
2494 fwrite($this->file, $rib_banque);
2495
2496 // Zone Reservee G2
2497
2498 fwrite($this->file, substr(" ", 0, 5));
2499
2500 fwrite($this->file, "\n");
2501 }
2502
2503
2504 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2530 public function EnregDestinataireSEPA($row_code_client, $row_nom, $row_address, $row_zip, $row_town, $row_country_code, $row_cb, $row_cg, $row_cc, $row_somme, $row_ref, $row_idfac, $row_iban, $row_bic, $row_datec, $row_drum, $row_rum, $type = 'direct-debit', $row_comment = '')
2531 {
2532 // phpcs:enable
2533 global $conf, $mysoc, $hookmanager;
2534
2535 if (getDolGlobalString('SEPA_FORCE_TWO_DECIMAL')) {
2536 $row_somme = number_format((float) price2num($row_somme, 'MT'), 2, ".", "");
2537 } else {
2538 $row_somme = round((float) $row_somme, 2);
2539 }
2540
2541 include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
2542
2543 $CrLf = "\n";
2544 $Rowing = sprintf("%010d", $row_idfac);
2545
2546 // Define value for RUM
2547 // Example: RUM-CustomerCode-CustomerBankAccountId-01424448606 (note: Date is the timestamp of the date of creation of CustomerBankAccountId)
2548 $Rum = (empty($row_rum) ? $this->buildRumNumber($row_code_client, $row_datec, $row_drum) : $row_rum);
2549
2550 // Define date of RUM signature
2551 $DtOfSgntr = dol_print_date($row_datec, '%Y-%m-%d');
2552 $XML_RESULT = '';
2553
2554 if (!is_object($hookmanager)) {
2555 include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
2556 $hookmanager = new HookManager($this->db);
2557 }
2558 $hookmanager->initHooks(array('bonprelevementdao'));
2559 $parameters = array(
2560 'row_code_client' => &$row_code_client, 'row_nom' => &$row_nom, 'row_address' => &$row_address, 'row_zip' => &$row_zip, 'row_town' => &$row_town,
2561 'row_country_code' => &$row_country_code, 'row_cb' => &$row_cb, 'row_cg' => &$row_cg, 'row_cc' => &$row_cc, 'row_somme' => &$row_somme,
2562 'row_ref' => &$row_ref, 'row_idfac' => &$row_idfac, 'row_iban' => &$row_iban, 'row_bic' => &$row_bic, 'row_datec' => &$row_datec,
2563 'row_drum' => &$row_drum, 'row_rum' => &$row_rum, 'type' => &$type, 'row_comment' => &$row_comment,
2564 'crlf' => &$CrLf, 'rowing' => &$Rowing, 'rum' => &$Rum, 'dtofsgntr' => &$DtOfSgntr,
2565 );
2566 $reshook = $hookmanager->executeHooks('enregDestinataireSEPA', $parameters, $this); // Note that $action and $object may have been modified by some hooks
2567 if (empty($reshook)) {
2568 if ($type != 'bank-transfer') {
2569 // SEPA Paiement Information of buyer for Direct Debit
2570 $XML_DEBITOR = '';
2571 $XML_DEBITOR .= ' <DrctDbtTxInf>' . $CrLf;
2572 $XML_DEBITOR .= ' <PmtId>' . $CrLf;
2573 // Add EndToEndId. Must be a unique ID for each payment (for example by including bank, buyer or seller, date, checksum)
2574 $XML_DEBITOR .= ' <EndToEndId>' . ((getDolGlobalString('PRELEVEMENT_END_TO_END') != "") ? $conf->global->PRELEVEMENT_END_TO_END : ('DD-' . dol_trunc($row_idfac . '-' . $row_ref, 20, 'right', 'UTF-8', 1)) . '-' . $Rowing) . '</EndToEndId>' . $CrLf; // ISO20022 states that EndToEndId has a MaxLength of 35 characters
2575 $XML_DEBITOR .= ' </PmtId>' . $CrLf;
2576 $XML_DEBITOR .= ' <InstdAmt Ccy="EUR">' . $row_somme . '</InstdAmt>' . $CrLf;
2577 $XML_DEBITOR .= ' <DrctDbtTx>' . $CrLf;
2578 $XML_DEBITOR .= ' <MndtRltdInf>' . $CrLf;
2579 $XML_DEBITOR .= ' <MndtId>' . $Rum . '</MndtId>' . $CrLf;
2580 $XML_DEBITOR .= ' <DtOfSgntr>' . $DtOfSgntr . '</DtOfSgntr>' . $CrLf;
2581 $XML_DEBITOR .= ' <AmdmntInd>false</AmdmntInd>' . $CrLf;
2582 $XML_DEBITOR .= ' </MndtRltdInf>' . $CrLf;
2583 $XML_DEBITOR .= ' </DrctDbtTx>' . $CrLf;
2584 $XML_DEBITOR .= ' <DbtrAgt>' . $CrLf;
2585 $XML_DEBITOR .= ' <FinInstnId>' . $CrLf;
2586 if (getDolGlobalInt('WITHDRAWAL_WITHOUT_BIC') == 0) {
2587 $XML_DEBITOR .= ' ' . ($this->sepa_schema_version == '8' ? '<BICFI>' : '<BIC>') . $row_bic . ($this->sepa_schema_version == '8' ? '</BICFI>' : '</BIC>') . $CrLf;
2588 }
2589 $XML_DEBITOR .= ' </FinInstnId>' . $CrLf;
2590 $XML_DEBITOR .= ' </DbtrAgt>' . $CrLf;
2591 $XML_DEBITOR .= ' <Dbtr>' . $CrLf;
2592 $XML_DEBITOR .= ' <Nm>' . dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($row_nom), ' '))) . '</Nm>' . $CrLf;
2593 $XML_DEBITOR .= $this->buildSEPAPostalAddressXML($row_address, $row_zip, $row_town, $row_country_code, "\t\t\t\t\t", $CrLf);
2594 $XML_DEBITOR .= ' </Dbtr>' . $CrLf;
2595 $XML_DEBITOR .= ' <DbtrAcct>' . $CrLf;
2596 $XML_DEBITOR .= ' <Id>' . $CrLf;
2597 $XML_DEBITOR .= ' <IBAN>' . preg_replace('/\s/', '', $row_iban) . '</IBAN>' . $CrLf;
2598 $XML_DEBITOR .= ' </Id>' . $CrLf;
2599 $XML_DEBITOR .= ' </DbtrAcct>' . $CrLf;
2600 $XML_DEBITOR .= ' <RmtInf>' . $CrLf;
2601
2602 // Structured payment reference, see core/lib/paymentref.lib.php
2603 include_once DOL_DOCUMENT_ROOT . '/core/lib/functions_creditorref.lib.php';
2604
2605 $invoicestatic = new Facture($this->db);
2606 $invoicestatic->fetch($row_idfac);
2607
2608 $paymentref = empty($invoicestatic->payment_reference) ? '' : (string) $invoicestatic->payment_reference;
2609
2610 // Invoices issued before the reference was stored still get one here
2611 if ($paymentref === '' && getDolGlobalString('INVOICE_PAYMENT_ENABLE_STRUCTURED_COMMUNICATION') && $mysoc->country_code == 'BE') {
2612 include_once DOL_DOCUMENT_ROOT . '/core/lib/functions_be.lib.php';
2613 $paymentref = dolBECalculateStructuredCommunication($invoicestatic->ref, $invoicestatic->type);
2614 }
2615
2616 $scheme = dolPayRefDetectScheme($paymentref);
2617
2618 if ($scheme == 'SCOR' || $scheme == 'BBA') {
2619 // ISO 20022 needs the reference inside a CdtrRefInf block. SCOR is the
2620 // code for ISO 11649, BBA the proprietary scheme of the belgian banks.
2621 $XML_DEBITOR .= ' <Strd>' . $CrLf;
2622 $XML_DEBITOR .= ' <CdtrRefInf>' . $CrLf;
2623 $XML_DEBITOR .= ' <Tp>' . $CrLf;
2624 $XML_DEBITOR .= ' <CdOrPrtry>' . $CrLf;
2625 if ($scheme == 'SCOR') {
2626 $XML_DEBITOR .= ' <Cd>SCOR</Cd>' . $CrLf;
2627 } else {
2628 $XML_DEBITOR .= ' <Prtry>BBA</Prtry>' . $CrLf;
2629 }
2630 $XML_DEBITOR .= ' </CdOrPrtry>' . $CrLf;
2631 $XML_DEBITOR .= ' </Tp>' . $CrLf;
2632 $XML_DEBITOR .= ' <Ref>' . dolEscapeXML(dolPayRefStrip($paymentref)) . '</Ref>' . $CrLf;
2633 $XML_DEBITOR .= ' </CdtrRefInf>' . $CrLf;
2634 $XML_DEBITOR .= ' </Strd>' . $CrLf;
2635 } elseif ($scheme == 'FI') {
2636 // A finnish national reference has no ISO 20022 code, it travels as free text
2637 $XML_DEBITOR .= ' <Ustrd>' . dolEscapeXML($paymentref) . '</Ustrd>' . $CrLf;
2638 } else {
2639 // A string with some information on payment - 140 max
2640 $XML_DEBITOR .= ' <Ustrd>' . getDolGlobalString('PRELEVEMENT_USTRD', dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($row_ref . ($row_comment ? ' - ' . $row_comment : '')), '', '', '', 1), 135, 'right', 'UTF-8', 1))) . '</Ustrd>' . $CrLf; // Free unstuctured data - 140 max
2641 }
2642 $XML_DEBITOR .= ' </RmtInf>' . $CrLf;
2643 $XML_DEBITOR .= ' </DrctDbtTxInf>' . $CrLf;
2644
2645 $XML_RESULT = $XML_DEBITOR;
2646 } else {
2647 // SEPA Payment Information of seller for Credit Transfer
2648 $XML_CREDITOR = '';
2649 $XML_CREDITOR .= ' <CdtTrfTxInf>' . $CrLf;
2650 $XML_CREDITOR .= ' <PmtId>' . $CrLf;
2651 // Add EndToEndId. Must be a unique ID for each payment (for example by including bank, buyer or seller, date, checksum)
2652 $XML_CREDITOR .= ' <EndToEndId>' . ((getDolGlobalString('PRELEVEMENT_END_TO_END') != "") ? getDolGlobalString("PRELEVEMENT_END_TO_END") : ('CT-' . dol_trunc($row_idfac . '-' . $row_ref, 20, 'right', 'UTF-8', 1)) . '-' . $Rowing) . '</EndToEndId>' . $CrLf; // ISO20022 states that EndToEndId has a MaxLength of 35 characters
2653 $XML_CREDITOR .= ' </PmtId>' . $CrLf;
2654 if (!empty($this->sepa_xml_pti_in_ctti)) {
2655 $XML_CREDITOR .= ' <PmtTpInf>' . $CrLf;
2656
2657 // Can be 'NORM' for normal or 'HIGH' for high priority level
2658 if (getDolGlobalString('PAYMENTBYBANKTRANSFER_FORCE_HIGH_PRIORITY')) {
2659 $instrprty = 'HIGH';
2660 } else {
2661 $instrprty = 'NORM';
2662 }
2663
2664 // Set $categoryPurpose: CORE, TREA, SUPP, ...
2665 $categoryPurpose = getDolGlobalString('PAYMENTBYBANKTRANSFER_CUSTOM_CATEGORY_PURPOSE', 'CORE');
2666
2667 $XML_CREDITOR .= ' <InstrPrty>' . $instrprty . '</InstrPrty>' . $CrLf;
2668 $XML_CREDITOR .= ' <SvcLvl>' . $CrLf;
2669 $XML_CREDITOR .= ' <Cd>SEPA</Cd>' . $CrLf;
2670 $XML_CREDITOR .= ' </SvcLvl>' . $CrLf;
2671 $XML_CREDITOR .= ' <CtgyPurp>' . $CrLf;
2672 $XML_CREDITOR .= ' <Cd>' . $categoryPurpose . '</Cd>' . $CrLf;
2673 $XML_CREDITOR .= ' </CtgyPurp>' . $CrLf;
2674 $XML_CREDITOR .= ' </PmtTpInf>' . $CrLf;
2675 }
2676 $XML_CREDITOR .= ' <Amt>' . $CrLf;
2677 $XML_CREDITOR .= ' <InstdAmt Ccy="EUR">' . round((float) $row_somme, 2) . '</InstdAmt>' . $CrLf;
2678 $XML_CREDITOR .= ' </Amt>' . $CrLf;
2679 /*
2680 $XML_CREDITOR .= ' <DrctDbtTx>'.$CrLf;
2681 $XML_CREDITOR .= ' <MndtRltdInf>'.$CrLf;
2682 $XML_CREDITOR .= ' <MndtId>'.$Rum.'</MndtId>'.$CrLf;
2683 $XML_CREDITOR .= ' <DtOfSgntr>'.$DtOfSgntr.'</DtOfSgntr>'.$CrLf;
2684 $XML_CREDITOR .= ' <AmdmntInd>false</AmdmntInd>'.$CrLf;
2685 $XML_CREDITOR .= ' </MndtRltdInf>'.$CrLf;
2686 $XML_CREDITOR .= ' </DrctDbtTx>'.$CrLf;
2687 */
2688 //$XML_CREDITOR .= ' <ChrgBr>SLEV</ChrgBr>'.$CrLf;
2689 $XML_CREDITOR .= ' <CdtrAgt>' . $CrLf;
2690 $XML_CREDITOR .= ' <FinInstnId>' . $CrLf;
2691 $XML_CREDITOR .= ' <BIC>' . $row_bic . '</BIC>' . $CrLf;
2692 $XML_CREDITOR .= ' </FinInstnId>' . $CrLf;
2693 $XML_CREDITOR .= ' </CdtrAgt>' . $CrLf;
2694 $XML_CREDITOR .= ' <Cdtr>' . $CrLf;
2695 $XML_CREDITOR .= ' <Nm>' . dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($row_nom), ' '))) . '</Nm>' . $CrLf;
2696 $XML_CREDITOR .= $this->buildSEPAPostalAddressXML($row_address, $row_zip, $row_town, $row_country_code, "\t\t\t\t\t", $CrLf);
2697 $XML_CREDITOR .= ' </Cdtr>' . $CrLf;
2698 $XML_CREDITOR .= ' <CdtrAcct>' . $CrLf;
2699 $XML_CREDITOR .= ' <Id>' . $CrLf;
2700 $XML_CREDITOR .= ' <IBAN>' . preg_replace('/\s/', '', $row_iban) . '</IBAN>' . $CrLf;
2701 $XML_CREDITOR .= ' </Id>' . $CrLf;
2702 $XML_CREDITOR .= ' </CdtrAcct>' . $CrLf;
2703 $XML_CREDITOR .= ' <RmtInf>' . $CrLf;
2704 // A string with some information on payment - 140 max
2705 $XML_CREDITOR .= ' <Ustrd>' . getDolGlobalString('CREDITTRANSFER_USTRD', dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent($row_ref . ($row_comment ? ' - ' . $row_comment : '')), '', '', '', 1), 135, 'right', 'UTF-8', 1))) . '</Ustrd>' . $CrLf; // Free unstructured data - 140 max
2706 $XML_CREDITOR .= ' </RmtInf>' . $CrLf;
2707 $XML_CREDITOR .= ' </CdtTrfTxInf>' . $CrLf;
2708
2709 $XML_RESULT = $XML_CREDITOR;
2710 }
2711 } elseif ($reshook > 0) {
2712 $XML_RESULT = $hookmanager->resPrint;
2713 }
2714 $XML_RESULT .= $hookmanager->resPrint;
2715
2716 return $XML_RESULT;
2717 }
2718
2719
2720 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2729 public function EnregEmetteur($type = 'direct-debit')
2730 {
2731 // phpcs:enable
2732 fwrite($this->file, "03");
2733 fwrite($this->file, "08"); // Prelevement ordinaire
2734
2735 fwrite($this->file, " "); // Zone Reservee B2
2736
2737 fwrite($this->file, $this->emetteur_ics); // ICS
2738
2739 // Date d'echeance C1
2740
2741 fwrite($this->file, " ");
2742 fwrite($this->file, dol_print_date($this->date_echeance, "%d%m", 'gmt'));
2743 fwrite($this->file, substr(dol_print_date($this->date_echeance, "%y", 'gmt'), 1));
2744
2745 // Raison Sociale C2
2746
2747 fwrite($this->file, substr($this->raison_sociale . " ", 0, 24));
2748
2749 // Ref of thirdparty on 7 characters
2750
2751 fwrite($this->file, substr($this->reference_remise . " ", 0, 7));
2752
2753 // Zone Reservee D1-2
2754
2755 fwrite($this->file, substr(" ", 0, 17));
2756
2757 // Zone Reservee D2
2758
2759 fwrite($this->file, substr(" ", 0, 2));
2760 fwrite($this->file, "E");
2761 fwrite($this->file, substr(" ", 0, 5));
2762
2763 // Code Guichet D3
2764
2765 fwrite($this->file, $this->emetteur_code_guichet);
2766
2767 // Numero de compte D4
2768
2769 fwrite($this->file, substr("000000000000000" . $this->emetteur_numero_compte, -11));
2770
2771 // Zone Reservee E
2772
2773 fwrite($this->file, substr(" ", 0, 16));
2774
2775 // Zone Reservee F
2776
2777 fwrite($this->file, substr(" ", 0, 31));
2778
2779 // Code etablissement
2780
2781 fwrite($this->file, $this->emetteur_code_banque);
2782
2783 // Zone Reservee G
2784
2785 fwrite($this->file, substr(" ", 0, 5));
2786
2787 fwrite($this->file, "\n");
2788 }
2789
2790
2791 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2806 public function EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf = '\n', $format = 'FRST', $type = 'direct-debit', $fk_bank_account = 0)
2807 {
2808 // phpcs:enable
2809
2810 // Clean parameters
2811 $dateTime_YMD = dol_print_date($ladate, '%Y%m%d');
2812 $dateTime_ETAD = dol_print_date($ladate, '%Y-%m-%d');
2813 $dateTime_YMDHMS = dol_print_date($ladate, '%Y-%m-%dT%H:%M:%S');
2814
2815 // Clean params
2816 if (empty($fk_bank_account)) {
2817 $fk_bank_account = ($type == 'bank-transfer' ? getDolGlobalInt('PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') : getDolGlobalInt('PRELEVEMENT_ID_BANKACCOUNT'));
2818 }
2819
2820 // Get data of bank account
2821 $account = new Account($this->db);
2822 if ($account->fetch($fk_bank_account) > 0) {
2823 $this->emetteur_code_banque = $account->code_banque;
2824 $this->emetteur_code_guichet = $account->code_guichet;
2825 $this->emetteur_numero_compte = $account->number;
2826 $this->emetteur_number_key = $account->cle_rib;
2827 $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
2828 $this->emetteur_iban = $account->iban;
2829 $this->emetteur_bic = $account->bic;
2830
2831 $this->emetteur_ics = (($type == 'bank-transfer' && getDolGlobalString("SEPA_USE_IDS")) ? $account->ics_transfer : $account->ics); // Ex: PRELEVEMENT_ICS = "FR78ZZZ123456";
2832
2833 $this->raison_sociale = $account->owner_name;
2834 }
2835
2836 // Get pending payments
2837 $sql = "SELECT rowid, ref";
2838 $sql .= " FROM " . MAIN_DB_PREFIX . "prelevement_bons as pb";
2839 $sql .= " WHERE pb.rowid = " . ((int) $this->id);
2840
2841 $resql = $this->db->query($sql);
2842 if ($resql) {
2843 $obj = $this->db->fetch_object($resql);
2844
2845 $country = explode(':', getDolGlobalString('MAIN_INFO_SOCIETE_COUNTRY'));
2846 $IdBon = sprintf("%05d", $obj->rowid);
2847 $RefBon = $obj->ref;
2848 $localInstrument = getDolGlobalString('PAYMENTBYBANKTRANSFER_CUSTOM_LOCAL_INSTRUMENT', 'CORE');
2849
2850 if (getDolGlobalString('SEPA_FORCE_TWO_DECIMAL')) {
2851 $total = number_format((float) price2num($total, 'MT'), 2, ".", "");
2852 }
2853
2854 if ($type != 'bank-transfer') {
2855 // SEPA Paiement Information of my company for Direct Debit
2856 $XML_SEPA_INFO = '';
2857 $XML_SEPA_INFO .= ' <PmtInf>' . $CrLf;
2858 $XML_SEPA_INFO .= ' <PmtInfId>' . ('DOL/' . $dateTime_YMD . '/DD' . $IdBon . '-' . $RefBon) . '</PmtInfId>' . $CrLf;
2859 $XML_SEPA_INFO .= ' <PmtMtd>DD</PmtMtd>' . $CrLf;
2860 $XML_SEPA_INFO .= ' <NbOfTxs>' . $nombre . '</NbOfTxs>' . $CrLf;
2861 $XML_SEPA_INFO .= ' <CtrlSum>' . $total . '</CtrlSum>' . $CrLf;
2862 $XML_SEPA_INFO .= ' <PmtTpInf>' . $CrLf;
2863 $XML_SEPA_INFO .= ' <SvcLvl>' . $CrLf;
2864 $XML_SEPA_INFO .= ' <Cd>SEPA</Cd>' . $CrLf;
2865 $XML_SEPA_INFO .= ' </SvcLvl>' . $CrLf;
2866 $XML_SEPA_INFO .= ' <LclInstrm>' . $CrLf;
2867 $XML_SEPA_INFO .= ' <Cd>' . $localInstrument . '</Cd>' . $CrLf;
2868 $XML_SEPA_INFO .= ' </LclInstrm>' . $CrLf;
2869 $XML_SEPA_INFO .= ' <SeqTp>' . $format . '</SeqTp>' . $CrLf;
2870 $XML_SEPA_INFO .= ' </PmtTpInf>' . $CrLf;
2871 $XML_SEPA_INFO .= ' <ReqdColltnDt>' . $dateTime_ETAD . '</ReqdColltnDt>' . $CrLf;
2872 $XML_SEPA_INFO .= ' <Cdtr>' . $CrLf;
2873 $XML_SEPA_INFO .= ' <Nm>' . dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale), ' '))) . '</Nm>' . $CrLf;
2874 $sender_address = (string) getDolGlobalString('MAIN_INFO_SOCIETE_ADDRESS');
2875 $sender_zip = (string) getDolGlobalString('MAIN_INFO_SOCIETE_ZIP');
2876 $sender_town = (string) getDolGlobalString('MAIN_INFO_SOCIETE_TOWN');
2877 $sender_country_code = (string) ($country[1] ?? '');
2878 $XML_SEPA_INFO .= $this->buildSEPAPostalAddressXML($sender_address, $sender_zip, $sender_town, $sender_country_code, "\t\t\t\t", $CrLf);
2879 $XML_SEPA_INFO .= ' </Cdtr>' . $CrLf;
2880 $XML_SEPA_INFO .= ' <CdtrAcct>' . $CrLf;
2881 $XML_SEPA_INFO .= ' <Id>' . $CrLf;
2882 $XML_SEPA_INFO .= ' <IBAN>' . preg_replace('/\s/', '', $this->emetteur_iban) . '</IBAN>' . $CrLf;
2883 $XML_SEPA_INFO .= ' </Id>' . $CrLf;
2884 $XML_SEPA_INFO .= ' </CdtrAcct>' . $CrLf;
2885 $XML_SEPA_INFO .= ' <CdtrAgt>' . $CrLf;
2886 $XML_SEPA_INFO .= ' <FinInstnId>' . $CrLf;
2887 $XML_SEPA_INFO .= ' ' . ($this->sepa_schema_version == '8' ? '<BICFI>' : '<BIC>') . $this->emetteur_bic . ($this->sepa_schema_version == '8' ? '</BICFI>' : '</BIC>') . $CrLf;
2888 $XML_SEPA_INFO .= ' </FinInstnId>' . $CrLf;
2889 $XML_SEPA_INFO .= ' </CdtrAgt>' . $CrLf;
2890 /* $XML_SEPA_INFO .= ' <UltmtCdtr>'.$CrLf;
2891 $XML_SEPA_INFO .= ' <Nm>'.dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale), ' '))).'</Nm>'.$CrLf;
2892 $XML_SEPA_INFO .= ' <PstlAdr>'.$CrLf;
2893 $XML_SEPA_INFO .= ' <Ctry>'.$country[1].'</Ctry>'.$CrLf;
2894 $XML_SEPA_INFO .= ' <AdrLine>'.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent(getDolGlobalString('MAIN_INFO_SOCIETE_ADDRESS')), ' '), 70, 'right', 'UTF-8', 1)).'</AdrLine>'.$CrLf;
2895 $XML_SEPA_INFO .= ' <AdrLine>'.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent(getDolGlobalString('MAIN_INFO_SOCIETE_ZIP').' '.getDolGlobalString('MAIN_INFO_SOCIETE_TOWN')), ' '), 70, 'right', 'UTF-8', 1)).'</AdrLine>'.$CrLf;
2896 $XML_SEPA_INFO .= ' </PstlAdr>'.$CrLf;
2897 $XML_SEPA_INFO .= ' </UltmtCdtr>'.$CrLf;*/
2898 $XML_SEPA_INFO .= ' <ChrgBr>SLEV</ChrgBr>' . $CrLf; // Field "Responsible of fees". Must be SLEV
2899 $XML_SEPA_INFO .= ' <CdtrSchmeId>' . $CrLf;
2900 $XML_SEPA_INFO .= ' <Id>' . $CrLf;
2901 $XML_SEPA_INFO .= ' <PrvtId>' . $CrLf;
2902 $XML_SEPA_INFO .= ' <Othr>' . $CrLf;
2903 $XML_SEPA_INFO .= ' <Id>' . $this->emetteur_ics . '</Id>' . $CrLf;
2904 $XML_SEPA_INFO .= ' <SchmeNm>' . $CrLf;
2905 $XML_SEPA_INFO .= ' <Prtry>SEPA</Prtry>' . $CrLf;
2906 $XML_SEPA_INFO .= ' </SchmeNm>' . $CrLf;
2907 $XML_SEPA_INFO .= ' </Othr>' . $CrLf;
2908 $XML_SEPA_INFO .= ' </PrvtId>' . $CrLf;
2909 $XML_SEPA_INFO .= ' </Id>' . $CrLf;
2910 $XML_SEPA_INFO .= ' </CdtrSchmeId>' . $CrLf;
2911 } else {
2912 // SEPA Paiement Information of my company for Credit Transfer
2913 $XML_SEPA_INFO = '';
2914 $XML_SEPA_INFO .= ' <PmtInf>' . $CrLf;
2915 $XML_SEPA_INFO .= ' <PmtInfId>' . ('DOL/' . $dateTime_YMD . '/CT' . $IdBon . '-' . $RefBon) . '</PmtInfId>' . $CrLf;
2916 $XML_SEPA_INFO .= ' <PmtMtd>TRF</PmtMtd>' . $CrLf;
2917 //$XML_SEPA_INFO .= ' <BtchBookg>False</BtchBookg>'.$CrLf;
2918 $XML_SEPA_INFO .= ' <NbOfTxs>' . $nombre . '</NbOfTxs>' . $CrLf;
2919 $XML_SEPA_INFO .= ' <CtrlSum>' . $total . '</CtrlSum>' . $CrLf;
2920 if (!empty($this->sepa_xml_pti_in_ctti) && !empty($format)) { // @TODO Using $format (FRST ou RCUR) in a section for a Credit Transfer looks strange.
2921 $XML_SEPA_INFO .= ' <PmtTpInf>' . $CrLf;
2922 $XML_SEPA_INFO .= ' <SvcLvl>' . $CrLf;
2923 $XML_SEPA_INFO .= ' <Cd>SEPA</Cd>' . $CrLf;
2924 $XML_SEPA_INFO .= ' </SvcLvl>' . $CrLf;
2925 $XML_SEPA_INFO .= ' <LclInstrm>' . $CrLf;
2926 $XML_SEPA_INFO .= ' <Cd>' . $localInstrument . '</Cd>' . $CrLf;
2927 $XML_SEPA_INFO .= ' </LclInstrm>' . $CrLf;
2928 $XML_SEPA_INFO .= ' <SeqTp>' . $format . '</SeqTp>' . $CrLf;
2929 $XML_SEPA_INFO .= ' </PmtTpInf>' . $CrLf;
2930 }
2931 $XML_SEPA_INFO .= ' <ReqdExctnDt>' . dol_print_date($dateTime_ETAD, 'dayrfc') . '</ReqdExctnDt>' . $CrLf;
2932 $XML_SEPA_INFO .= ' <Dbtr>' . $CrLf;
2933 $XML_SEPA_INFO .= ' <Nm>' . dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale), ' '))) . '</Nm>' . $CrLf;
2934 $sender_address = (string) getDolGlobalString('MAIN_INFO_SOCIETE_ADDRESS');
2935 $sender_zip = (string) getDolGlobalString('MAIN_INFO_SOCIETE_ZIP');
2936 $sender_town = (string) getDolGlobalString('MAIN_INFO_SOCIETE_TOWN');
2937 $sender_country_code = (string) ($country[1] ?? '');
2938 $XML_SEPA_INFO .= $this->buildSEPAPostalAddressXML($sender_address, $sender_zip, $sender_town, $sender_country_code, "\t\t\t\t", $CrLf);
2939 $XML_SEPA_INFO .= ' </Dbtr>' . $CrLf;
2940 $XML_SEPA_INFO .= ' <DbtrAcct>' . $CrLf;
2941 $XML_SEPA_INFO .= ' <Id>' . $CrLf;
2942 $XML_SEPA_INFO .= ' <IBAN>' . preg_replace('/\s/', '', $this->emetteur_iban) . '</IBAN>' . $CrLf;
2943 $XML_SEPA_INFO .= ' </Id>' . $CrLf;
2944 $XML_SEPA_INFO .= ' </DbtrAcct>' . $CrLf;
2945 $XML_SEPA_INFO .= ' <DbtrAgt>' . $CrLf;
2946 $XML_SEPA_INFO .= ' <FinInstnId>' . $CrLf;
2947 $XML_SEPA_INFO .= ' <BIC>' . $this->emetteur_bic . '</BIC>' . $CrLf;
2948 $XML_SEPA_INFO .= ' </FinInstnId>' . $CrLf;
2949 $XML_SEPA_INFO .= ' </DbtrAgt>' . $CrLf;
2950 /* $XML_SEPA_INFO .= ' <UltmtCdtr>'.$CrLf;
2951 $XML_SEPA_INFO .= ' <Nm>'.dolEscapeXML(strtoupper(dol_string_nospecial(dol_string_unaccent($this->raison_sociale), ' '))).'</Nm>'.$CrLf;
2952 $XML_SEPA_INFO .= ' <PstlAdr>'.$CrLf;
2953 $XML_SEPA_INFO .= ' <Ctry>'.$country[1].'</Ctry>'.$CrLf;
2954 $XML_SEPA_INFO .= ' <AdrLine>'.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent(getDolGlobalString('MAIN_INFO_SOCIETE_ADDRESS')), ' '), 70, 'right', 'UTF-8', 1)).'</AdrLine>'.$CrLf;
2955 $XML_SEPA_INFO .= ' <AdrLine>'.dolEscapeXML(dol_trunc(dol_string_nospecial(dol_string_unaccent(getDolGlobalString('MAIN_INFO_SOCIETE_ZIP').' '.getDolGlobalString('MAIN_INFO_SOCIETE_TOWN')), ' '), 70, 'right', 'UTF-8', 1)).'</AdrLine>'.$CrLf;
2956 $XML_SEPA_INFO .= ' </PstlAdr>'.$CrLf;
2957 $XML_SEPA_INFO .= ' </UltmtCdtr>'.$CrLf;*/
2958 $XML_SEPA_INFO .= ' <ChrgBr>SLEV</ChrgBr>' . $CrLf; // Field "Responsible of fees". Must be SLEV
2959 /*$XML_SEPA_INFO .= ' <CdtrSchmeId>'.$CrLf;
2960 $XML_SEPA_INFO .= ' <Id>'.$CrLf;
2961 $XML_SEPA_INFO .= ' <PrvtId>'.$CrLf;
2962 $XML_SEPA_INFO .= ' <Othr>'.$CrLf;
2963 $XML_SEPA_INFO .= ' <Id>'.$this->emetteur_ics.'</Id>'.$CrLf;
2964 $XML_SEPA_INFO .= ' <SchmeNm>'.$CrLf;
2965 $XML_SEPA_INFO .= ' <Prtry>SEPA</Prtry>'.$CrLf;
2966 $XML_SEPA_INFO .= ' </SchmeNm>'.$CrLf;
2967 $XML_SEPA_INFO .= ' </Othr>'.$CrLf;
2968 $XML_SEPA_INFO .= ' </PrvtId>'.$CrLf;
2969 $XML_SEPA_INFO .= ' </Id>'.$CrLf;
2970 $XML_SEPA_INFO .= ' </CdtrSchmeId>'.$CrLf;*/
2971 }
2972 } else {
2973 fwrite($this->file, 'INCORRECT EMETTEUR ' . $this->raison_sociale . $CrLf);
2974 $XML_SEPA_INFO = '';
2975 }
2976 return $XML_SEPA_INFO;
2977 }
2978
2979 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2986 public function EnregTotal($total)
2987 {
2988 // phpcs:enable
2989 fwrite($this->file, "08");
2990 fwrite($this->file, "08"); // Prelevement ordinaire
2991
2992 fwrite($this->file, " "); // Zone Reservee B2
2993
2994 fwrite($this->file, $this->emetteur_ics); // ICS
2995
2996 // Reserve C1
2997
2998 fwrite($this->file, substr(" ", 0, 12));
2999
3000
3001 // Raison Sociale C2
3002
3003 fwrite($this->file, substr(" ", 0, 24));
3004
3005 // D1
3006
3007 fwrite($this->file, substr(" ", 0, 24));
3008
3009 // Zone Reservee D2
3010
3011 fwrite($this->file, substr(" ", 0, 8));
3012
3013 // Code Guichet D3
3014
3015 fwrite($this->file, substr(" ", 0, 5));
3016
3017 // Numero de compte D4
3018
3019 fwrite($this->file, substr(" ", 0, 11));
3020
3021 // Zone E Montant
3022
3023 $montant = ($total * 100);
3024
3025 fwrite($this->file, substr("000000000000000" . $montant, -16));
3026
3027 // Zone Reservee F
3028
3029 fwrite($this->file, substr(" ", 0, 31));
3030
3031 // Code etablissement
3032
3033 fwrite($this->file, substr(" ", 0, 5));
3034
3035 // Zone Reservee F
3036
3037 fwrite($this->file, substr(" ", 0, 5));
3038
3039 fwrite($this->file, "\n");
3040 }
3041
3048 public function getLibStatut($mode = 0)
3049 {
3050 return $this->LibStatut((isset($this->status) ? $this->status : $this->statut), $mode);
3051 }
3052
3053 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3061 public function LibStatut($status, $mode = 0)
3062 {
3063 // phpcs:enable
3064 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3065 global $langs;
3066 //$langs->load("mymodule");
3067 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('StatusWaiting');
3068 $this->labelStatus[self::STATUS_TRANSFERED] = $langs->transnoentitiesnoconv('StatusTrans');
3069 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('StatusWaiting');
3070 $this->labelStatusShort[self::STATUS_TRANSFERED] = $langs->transnoentitiesnoconv('StatusTrans');
3071 if ($this->type == 'bank-transfer') {
3072 $this->labelStatus[self::STATUS_DEBITED] = $langs->transnoentitiesnoconv('StatusDebited');
3073 $this->labelStatusShort[self::STATUS_DEBITED] = $langs->transnoentitiesnoconv('StatusDebited');
3074 } else {
3075 $this->labelStatus[self::STATUS_CREDITED] = $langs->transnoentitiesnoconv('StatusCredited');
3076 $this->labelStatusShort[self::STATUS_CREDITED] = $langs->transnoentitiesnoconv('StatusCredited');
3077 }
3078 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
3079 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv('Canceled');
3080 }
3081
3082 $statusType = 'status1';
3083 if ($status == self::STATUS_TRANSFERED) {
3084 $statusType = 'status3';
3085 }
3086 if ($status == self::STATUS_CREDITED || $status == self::STATUS_DEBITED) {
3087 $statusType = 'status6';
3088 }
3089 if ($status == self::STATUS_CANCELED) {
3090 $statusType = 'status9';
3091 }
3092
3093 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
3094 }
3095
3096 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
3104 public function load_board($user, $mode)
3105 {
3106 // phpcs:enable
3107 global $conf, $langs;
3108
3109 if ($user->socid) {
3110 return -1; // Protection to prevent calls by external users
3111 }
3112
3113 if ($mode == 'direct-debit') {
3114 $sql = "SELECT p.rowid, p.datec, p.date_trans as date_trans, p.date_credit as date_credit";
3115 $sql .= " FROM " . MAIN_DB_PREFIX . "prelevement_bons as p";
3116 $sql .= " WHERE p.entity IN (" . getEntity('prelevement_bons') . ")";
3117 $sql .= " AND (p.type = 'debit-order' OR p.type = 'direct-debit')"; // direct debit
3118 $sql .= " AND p.statut < ".((int) BonPrelevement::STATUS_DEBITED);
3119 } else {
3120 $sql = "SELECT p.rowid, p.datec, p.date_trans as date_trans, p.date_credit as date_credit";
3121 $sql .= " FROM " . MAIN_DB_PREFIX . "prelevement_bons as p";
3122 $sql .= " WHERE p.entity IN (" . getEntity('prelevement_bons') . ")";
3123 $sql .= " AND (p.type = 'bank-transfer' OR p.type = 'credit-transfer')"; // credit transfer
3124 $sql .= " AND p.statut < ".((int) BonPrelevement::STATUS_CREDITED);
3125 }
3126
3127 $resql = $this->db->query($sql);
3128 if ($resql) {
3129 $langs->load("banks");
3130 $now = dol_now();
3131
3132 $response = new WorkboardResponse();
3133 if ($mode == 'direct-debit') {
3134 $warning_delay = (int) $conf->warning_delays['bank_direct_debit']; // In seconds. The one of the response is in days.
3135 $response->warning_delay = $warning_delay / 60 / 60 / 24;
3136 $response->label = $langs->trans("PendingDirectDebitToComplete");
3137 $response->labelShort = $langs->trans("PendingDirectDebitToCompleteShort");
3138 $response->url = DOL_URL_ROOT . '/compta/prelevement/orders_list.php?leftmenu=checks&mainmenu=bank&search_status=0,1';
3139 $response->url_late = DOL_URL_ROOT . '/compta/prelevement/orders_list.php?leftmenu=checks&mainmenu=bank&search_status=0,1';
3140 } else {
3141 $warning_delay = (int) $conf->warning_delays['bank_credit_transfer']; // In seconds. The one of the response is in days.
3142 $response->warning_delay = $warning_delay / 60 / 60 / 24;
3143 $response->label = $langs->trans("PendingCreditTransferToComplete");
3144 $response->labelShort = $langs->trans("PendingCreditTransferToCompleteShort");
3145 $response->url = DOL_URL_ROOT . '/compta/prelevement/orders_list.php?leftmenu=checks&mainmenu=bank&type=bank-transfer&search_status=0,1';
3146 $response->url_late = DOL_URL_ROOT . '/compta/prelevement/orders_list.php?leftmenu=checks&mainmenu=bank&type=bank-transfer&search_status=0,1';
3147 }
3148 $response->img = img_object('', "payment");
3149
3150 $response->nbtodo = 0;
3151 $response->nbtodolate = 0;
3152
3153 while ($obj = $this->db->fetch_object($resql)) {
3154 $response->nbtodo++;
3155
3156 // An order is waiting since it was transmitted to the bank, or since its creation when it was not transmitted yet
3157 $datetotest = $this->db->jdate(!empty($obj->date_trans) ? $obj->date_trans : $obj->datec);
3158 if ($datetotest && $datetotest < ($now - $warning_delay)) {
3159 $response->nbtodolate++;
3160 }
3161 }
3162
3163 // Return workboard only if quantity is not 0
3164 //if ($response->nbtodo) {
3165 return $response;
3166 //} else {
3167 // return 0;
3168 //}
3169 } else {
3170 dol_print_error($this->db);
3171 $this->error = $this->db->error();
3172 return -1;
3173 }
3174 }
3175
3183 public function getKanbanView($option = '', $arraydata = null)
3184 {
3185 global $langs;
3186
3187 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
3188
3189 $return = '<div class="box-flex-item box-flex-grow-zero">';
3190 $return .= '<div class="info-box info-box-sm">';
3191 $return .= '<span class="info-box-icon bg-infobox-action">';
3192 $return .= img_picto('', $this->picto);
3193 $return .= '</span>';
3194 $return .= '<div class="info-box-content">';
3195 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->getNomUrl(1) . '</span>';
3196 if ($selected >= 0) {
3197 $return .= '<input id="cb' . $this->id . '" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="' . $this->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
3198 }
3199 /*
3200 if (isset($this->date_trans)) {
3201 $return .= '<br><span class="opacitymedium">' . $langs->trans("TransData") . '</span> : <span class="info-box-label">' . dol_print_date($this->db->jdate($this->date_tans), 'day') . '</span>';
3202 }
3203 if (isset($this->date_credit)) {
3204 $return .= '<br><span class="opacitymedium">' . $langs->trans("CreditDate") . '</span> : <span class="info-box-label">' . dol_print_date($this->db->jdate($this->date_credit), 'day') . '</span>';
3205 }
3206 if (isset($this->date_echeance)) {
3207 $return .= '<br><span class="opacitymedium">' . $langs->trans("Date") . '</span> : <span class="info-box-label">' . dol_print_date($this->db->jdate($this->date_echeance), 'day') . '</span>';
3208 }
3209 */
3210 if (isset($this->amount)) {
3211 $return .= '<br><span class="opacitymedium">' . $langs->trans("Amount") . '</span> : <span class="amount">' . price($this->amount) . '</span>';
3212 }
3213 $return .= '<br><div class="info-box-status">' . $this->getLibStatut(3) . '</div>';
3214 $return .= '</div>';
3215 $return .= '</div>';
3216 $return .= '</div>';
3217 return $return;
3218 }
3219
3226 {
3227 if (!empty($this->id)) {
3228 $id = $this->id;
3229 } else {
3230 return 0;
3231 }
3232 $sql = "SELECT COUNT(*) AS nb FROM " . MAIN_DB_PREFIX . "prelevement_lignes";
3233 $sql .= " WHERE fk_prelevement_bons = " . ((int) $id);
3234 $sql .= " AND fk_soc = 0"; // fk_soc can't be NULL
3235 $sql .= " AND fk_user IS NOT NULL";
3236
3237 $num = 0;
3238 $resql = $this->db->query($sql);
3239 if ($resql) {
3240 $obj = $this->db->fetch_object($resql);
3241 $num = $obj->nb;
3242 } else {
3243 dol_print_error($this->db);
3244 }
3245 if ($num > 0) {
3246 return 1;
3247 }
3248
3249 return 0;
3250 }
3251}
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:281
checkIbanForAccount($account=null, $ibantocheck=null)
Check IBAN number information for a bank account.
Definition bank.lib.php:394
checkSwiftForAccount($account=null, $swift=null)
Check SWIFT information for a bank account.
Definition bank.lib.php:373
$object ref
Definition info.php:90
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage bank accounts.
Class to manage withdrawal receipts.
addWithdrawDetail($invoice_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $type='debit-order', $sourcetype='', $bic='', $iban='', $rum='', $id_prelevement_demande=0)
Add invoice to withdrawal.
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
SommeAPrelever($mode='direct-debit', $type='')
Returns amount waiting for direct debit payment or credit transfer payment.
static buildRumNumber($row_code_client, $row_datec, $row_drum)
Generate dynamically a RUM number for a customer bank account.
EnregEmetteur($type='direct-debit')
Write sender of request (me).
checkIfSalaryBonPrelevement()
Check if is bon prelevement for salary invoice.
EnregTotal($total)
Write end.
NbFactureAPrelever($type='direct-debit', $forsalary=0)
Get number of invoices to pay.
fetch($rowid, $ref='')
Get object and lines from database.
addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype='', $bic='', $iban='', $rum='', $id_prelevement_demande=0)
Add line to withdrawal.
getListInvoices($amounts=0, $type='')
Get invoice or salary list (with amount or not)
deleteNotificationById($rowid)
Delete a notification def by id.
__construct($db)
Constructor.
EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $ref, $facid, $rib_dom='', $type='direct-debit')
Write recipient of request (customer)
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Returns clickable name (with picto)
LibStatut($status, $mode=0)
Return status label for a status.
update(User $user, $notrigger=0)
Update object into database.
set_infotrans($user, $date, $method)
Set withdrawal to transmitted status.
buildSEPAPostalAddressXML($address, $zip, $town, $country_code, $indent, $CrLf)
Build the SEPA postal address block (<PstlAdr>) in the hybrid format required by ISO 20022 usage guid...
generate(string $format='FRST', int $executiondate=0, string $type='direct-debit', int $fk_bank_account=0, int $forsalary=0, int $thirdpartyBANId=0)
Generate a direct debit or credit transfer file.
getErrorString($error)
Return error string.
EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf='\n', $format='FRST', $type='direct-debit', $fk_bank_account=0)
Write sender of request (me).
set_infocredit($user, $date, $type='')
Set direct debit or credit transfer order to "paid" status.
getLibStatut($mode=0)
Return status label of object.
EnregDestinataireSEPA($row_code_client, $row_nom, $row_address, $row_zip, $row_town, $row_country_code, $row_cb, $row_cg, $row_cc, $row_somme, $row_ref, $row_idfac, $row_iban, $row_bic, $row_datec, $row_drum, $row_rum, $type='direct-debit', $row_comment='')
Write recipient (thirdparty concerned by request)
addNotification($db, $user, $action)
Add a notification.
nbOfInvoiceToPay($mode='direct-debit', $type='')
Get number of invoices waiting for payment.
deleteNotification($user, $action)
Delete a notification.
updateCommon(User $user, $notrigger=0)
Update object into database.
Class to manage bank accounts description of third parties.
Class to manage suppliers invoices.
Class to manage invoices.
const STATUS_VALIDATED
Validated (need to be paid)
Class to manage hooks.
Class to manage payments for supplier invoices.
Class to manage payments of customer invoices.
Class to manage payments of salaries.
Class to manage salary payments.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:169
global $mysoc
dol_now($mode='gmt')
Return date for now.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
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.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dolBECalculateStructuredCommunication($invoice_number, $invoice_type)
Calculate Structured Communication / BE Bank payment reference number.
dolPayRefStrip($ref)
Remove formatting spaces from a payment reference (machine form).
dolPayRefDetectScheme($ref)
Detect which structured payment reference scheme a stored value belongs to.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount
Definition receipt.php:494
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.