32require_once DOL_DOCUMENT_ROOT .
'/core/class/commonobject.class.php';
33require_once DOL_DOCUMENT_ROOT .
'/core/lib/bank.lib.php';
34require_once DOL_DOCUMENT_ROOT .
'/compta/bank/class/account.class.php';
35require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
36require_once DOL_DOCUMENT_ROOT .
'/compta/paiement/class/paiement.class.php';
37require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.facture.class.php';
38require_once DOL_DOCUMENT_ROOT .
'/fourn/class/paiementfourn.class.php';
39require_once DOL_DOCUMENT_ROOT .
'/salaries/class/salary.class.php';
40require_once DOL_DOCUMENT_ROOT .
'/salaries/class/paymentsalary.class.php';
41require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
42require_once DOL_DOCUMENT_ROOT .
'/user/class/userbankaccount.class.php';
53 public $element =
'widthdraw';
58 public $table_element =
'prelevement_bons';
63 public $picto =
'payment';
68 public $date_echeance;
72 public $raison_sociale;
76 public $reference_remise;
80 public $emetteur_code_guichet;
84 public $emetteur_numero_compte;
88 public $emetteur_code_banque;
92 public $emetteur_number_key;
96 public $sepa_xml_pti_in_ctti;
101 public $emetteur_iban;
105 public $emetteur_bic;
109 public $emetteur_ics;
128 public $labelStatus = array();
130 public $factures = array();
135 public $methodes_trans = array();
137 public $invoice_in_error = array();
138 public $thirdparty_in_error = array();
150 const STATUS_DRAFT = 0;
151 const STATUS_TRANSFERED = 1;
152 const STATUS_CREDITED = 2;
153 const STATUS_DEBITED = 2;
199 public $fields = array(
200 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'position' => 10,
'notnull' => 1,
'visible' => 0,),
201 'ref' => array(
'type' =>
'varchar(12)',
'label' =>
'Ref',
'enabled' => 1,
'position' => 15,
'notnull' => 0,
'visible' => -1,
'csslist' =>
'tdoverflowmax150',
'showoncombobox' => 1,),
202 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'position' => 25,
'notnull' => 0,
'visible' => -1,),
203 'amount' => array(
'type' =>
'double(24,8)',
'label' =>
'Amount',
'enabled' => 1,
'position' => 30,
'notnull' => 0,
'visible' => -1,),
204 'statut' => array(
'type' =>
'smallint(6)',
'label' =>
'Statut',
'enabled' => 1,
'position' => 500,
'notnull' => 0,
'visible' => -1,
'arrayofkeyval' => array(0 =>
'Wait', 1 =>
'Transfered', 2 =>
'Credited')),
205 'credite' => array(
'type' =>
'smallint(6)',
'label' =>
'Credite',
'enabled' => 1,
'position' => 40,
'notnull' => 0,
'visible' => -1,),
206 'note' => array(
'type' =>
'text',
'label' =>
'Note',
'enabled' => 1,
'position' => 45,
'notnull' => 0,
'visible' => -1,),
207 'date_trans' => array(
'type' =>
'datetime',
'label' =>
'Datetrans',
'enabled' => 1,
'position' => 50,
'notnull' => 0,
'visible' => -1,),
208 'method_trans' => array(
'type' =>
'smallint(6)',
'label' =>
'Methodtrans',
'enabled' => 1,
'position' => 55,
'notnull' => 0,
'visible' => -1,),
209 'fk_user_trans' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fkusertrans',
'enabled' => 1,
'position' => 60,
'notnull' => 0,
'visible' => -1,
'css' =>
'maxwidth500 widthcentpercentminusxx',
'csslist' =>
'tdoverflowmax150',),
210 'date_credit' => array(
'type' =>
'datetime',
'label' =>
'Datecredit',
'enabled' => 1,
'position' => 65,
'notnull' => 0,
'visible' => -1,),
211 'fk_user_credit' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fkusercredit',
'enabled' => 1,
'position' => 70,
'notnull' => 0,
'visible' => -1,
'css' =>
'maxwidth500 widthcentpercentminusxx',
'csslist' =>
'tdoverflowmax150',),
212 'type' => array(
'type' =>
'varchar(16)',
'label' =>
'Type',
'enabled' => 1,
'position' => 75,
'notnull' => 0,
'visible' => -1,),
213 'fk_bank_account' => array(
'type' =>
'integer',
'label' =>
'Fkbankaccount',
'enabled' => 1,
'position' => 80,
'notnull' => 0,
'visible' => -1,
'css' =>
'maxwidth500 widthcentpercentminusxx',),
257 public $method_trans;
261 public $fk_user_trans;
269 public $fk_user_credit;
277 public $fk_bank_account;
291 $this->filename =
'';
293 $this->date_echeance =
dol_now();
294 $this->raison_sociale =
"";
295 $this->reference_remise =
"";
297 $this->emetteur_code_guichet =
"";
298 $this->emetteur_numero_compte =
"";
299 $this->emetteur_code_banque =
"";
300 $this->emetteur_number_key =
"";
301 $this->sepa_xml_pti_in_ctti =
false;
303 $this->emetteur_iban =
"";
304 $this->emetteur_bic =
"";
305 $this->emetteur_ics =
"";
307 $this->factures = array();
309 $this->methodes_trans = array(0 =>
'Internet', 2 =>
'Email', 3 =>
'Api');
330 public function AddFacture($invoice_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $type =
'debit-order', $sourcetype =
'')
337 $result = $this->
addline($line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype);
342 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"prelevement (";
343 if ($type !=
'bank-transfer') {
344 $sql .=
"fk_facture";
346 if ($sourcetype ==
'salary') {
349 $sql .=
"fk_facture_fourn";
352 $sql .=
",fk_prelevement_lignes";
353 $sql .=
") VALUES (";
354 $sql .= ((int) $invoice_id);
355 $sql .=
", " . ((int) $line_id);
358 if ($this->db->query($sql)) {
362 $this->errors[] = get_class($this) .
"::AddFacture " . $this->db->lasterror;
363 dol_syslog(get_class($this) .
"::AddFacture Error $result");
367 $this->errors[] = get_class($this) .
"::AddFacture linedid Empty";
368 dol_syslog(get_class($this) .
"::AddFacture Error $result");
372 dol_syslog(get_class($this) .
"::AddFacture Error $result");
392 public function addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype =
'')
401 $sql =
"SELECT rowid";
402 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_lignes";
403 $sql .=
" WHERE fk_prelevement_bons = " . ((int) $this->
id);
404 if ($sourcetype ==
'salary') {
405 $sql .=
" AND fk_soc = " . ((int) $client_id);
407 $sql .=
" AND fk_user = " . ((int) $client_id);
409 $sql .=
" AND code_banque = '" . $this->db->escape($code_banque) .
"'";
410 $sql .=
" AND code_guichet = '" . $this->db->escape($code_guichet) .
"'";
411 $sql .=
" AND number = '" . $this->db->escape($number) .
"'";
413 $resql = $this->db->query($sql);
415 $num = $this->db->num_rows($resql);
423 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"prelevement_lignes (";
424 $sql .=
"fk_prelevement_bons";
426 $sql .=
", client_nom";
428 $sql .=
", code_banque";
429 $sql .=
", code_guichet";
432 $sql .= ($sourcetype ==
'salary' ?
", fk_user" :
"");
433 $sql .=
") VALUES (";
435 $sql .=
", " . (($sourcetype !=
'salary') ? ((
int) $client_id) :
"0");
436 $sql .=
", '" . $this->db->escape($client_nom) .
"'";
437 $sql .=
", " . ((float)
price2num($amount));
438 $sql .=
", '" . $this->db->escape($code_banque) .
"'";
439 $sql .=
", '" . $this->db->escape($code_guichet) .
"'";
440 $sql .=
", '" . $this->db->escape($number) .
"'";
441 $sql .=
", '" . $this->db->escape($number_key) .
"'";
442 $sql .= (($sourcetype ==
'salary') ?
", " . ((
int) $client_id) :
'');
444 if ($this->db->query($sql)) {
445 $line_id = $this->db->last_insert_id(MAIN_DB_PREFIX .
"prelevement_lignes");
448 $this->errors[] = get_class($this) .
"::addline Error -2 " . $this->db->lasterror;
449 dol_syslog(get_class($this) .
"::addline Error -2");
469 $errors[1027] = $langs->trans(
"DateInvalid");
471 return $errors[abs($error)];
481 public function fetch($rowid, $ref =
'')
483 $sql =
"SELECT p.rowid, p.ref, p.amount, p.note";
484 $sql .=
", p.datec as dc";
485 $sql .=
", p.date_trans as date_trans";
486 $sql .=
", p.method_trans, p.fk_user_trans";
487 $sql .=
", p.date_credit as date_credit";
488 $sql .=
", p.fk_user_credit";
490 $sql .=
", p.fk_bank_account";
491 $sql .=
", p.statut as status";
492 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons as p";
493 $sql .=
" WHERE p.entity IN (" .
getEntity(
'invoice') .
")";
495 $sql .=
" AND p.rowid = " . ((int) $rowid);
497 $sql .=
" AND p.ref = '" . $this->db->escape($ref) .
"'";
500 dol_syslog(get_class($this) .
"::fetch", LOG_DEBUG);
501 $result = $this->db->query($sql);
503 if ($this->db->num_rows($result)) {
504 $obj = $this->db->fetch_object($result);
506 $this->
id = $obj->rowid;
507 $this->
ref = $obj->ref;
508 $this->amount = $obj->amount;
509 $this->note = $obj->note;
510 $this->datec = $this->db->jdate($obj->dc);
512 $this->date_trans = $this->db->jdate($obj->date_trans);
513 $this->method_trans = $obj->method_trans;
514 $this->user_trans = $obj->fk_user_trans;
516 $this->date_credit = $this->db->jdate($obj->date_credit);
517 $this->user_credit = $obj->fk_user_credit;
519 $this->
type = $obj->type;
520 $this->fk_bank_account = $obj->fk_bank_account;
522 $this->
status = $obj->status;
523 if (empty($this->
status)) {
526 $this->statut = $this->status;
532 dol_syslog(get_class($this) .
"::Fetch no record found");
565 global
$conf, $langs;
569 if ($this->fetched == 1) {
570 if ($date < $this->date_trans) {
571 $langs->load(
"errors");
572 $this->error = $langs->trans(
'ErrorDateOfMovementLowerThanDateOfFileTransmission');
573 dol_syslog(
"bon-prelevment::set_infocredit 1027 " . $this->error);
579 $sql =
" UPDATE " . MAIN_DB_PREFIX .
"prelevement_bons";
580 $sql .=
" SET fk_user_credit = " . ((int) $user->id);
581 $sql .=
", statut = " . self::STATUS_CREDITED;
582 $sql .=
", date_credit = '" . $this->db->idate($date) .
"'";
583 $sql .=
" WHERE rowid = " . ((int) $this->
id);
584 $sql .=
" AND entity = " . ((int)
$conf->entity);
585 $sql .=
" AND statut = " . self::STATUS_TRANSFERED;
587 $resql = $this->db->query($sql);
589 $langs->load(
'withdrawals');
590 $subject = $langs->trans(
"InfoCreditSubject", $this->
ref);
591 $message = $langs->trans(
"InfoCreditMessage", $this->
ref,
dol_print_date($date,
'dayhour'));
594 $fk_bank_account = $this->fk_bank_account;
595 if (empty($fk_bank_account)) {
600 $amountsperthirdparty = array();
610 for ($i = 0; $i < $num; $i++) {
611 if ($this->
type ==
'bank-transfer') {
612 if ($type ==
'salary') {
613 $fac =
new Salary($this->db);
621 $result = $fac->fetch($facs[$i][0]);
623 $amounts[$fac->id] = $facs[$i][1];
624 if ($this->
type ==
'bank-transfer') {
625 if ($type ==
'salary') {
626 $amountsperthirdparty[$fac->fk_user][$fac->id] = $facs[$i][1];
628 $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
631 $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
634 $totalpaid = $fac->getSommePaiement();
635 $totalcreditnotes = 0;
636 if (method_exists($fac,
'getSumCreditNotesUsed')) {
637 $totalcreditnotes = $fac->getSumCreditNotesUsed();
640 if (method_exists($fac,
'getSumDepositsUsed')) {
641 $totaldeposits = $fac->getSumDepositsUsed();
643 $alreadypayed = $totalpaid + $totalcreditnotes + $totaldeposits;
647 $amountofdocument = $fac->total_ttc;
648 if ($type ==
'salary') {
649 $amountofdocument = $fac->amount;
651 if (
price2num($alreadypayed + $facs[$i][1],
'MT') ==
price2num($amountofdocument,
'MT')) {
652 $result = $fac->setPaid($user);
654 $this->error = $fac->error;
655 $this->errors = $fac->errors;
661 foreach ($amountsperthirdparty as $thirdpartyid => $cursoramounts) {
662 if ($this->
type ==
'bank-transfer') {
663 if ($type ==
'salary') {
669 $paiement =
new Paiement($this->db);
671 $paiement->datepaye = $date;
672 $paiement->amounts = $cursoramounts;
674 if ($this->
type ==
'bank-transfer') {
675 if ($type ==
'salary') {
676 $paiement->datep = $date;
678 $paiement->paiementid = 2;
679 $paiement->fk_typepayment = 2;
680 $paiement->paiementcode =
'VIR';
682 $paiement->paiementid = 2;
683 $paiement->paiementcode =
'VIR';
686 $paiement->paiementid = 3;
687 $paiement->paiementcode =
'PRE';
690 $paiement->num_payment = $this->ref;
691 $paiement->id_prelevement = $this->id;
693 $result = $paiement->create($user);
697 $this->error = $paiement->error;
698 $this->errors = $paiement->errors;
699 dol_syslog(get_class($this) .
"::set_infocredit AddPayment Error " . $this->error);
701 if ($this->
type ==
'bank-transfer') {
702 if ($type ==
'salary') {
703 $modeforaddpayment =
'payment_salary';
704 $labelforaddpayment =
'(SalaryPayment)';
705 $addbankurl =
'credit-transfer';
707 $modeforaddpayment =
'payment_supplier';
708 $labelforaddpayment =
'(SupplierInvoicePayment)';
709 $addbankurl =
'credit-transfer';
712 $modeforaddpayment =
'payment';
713 $labelforaddpayment =
'(CustomerInvoicePayment)';
714 $addbankurl =
'direct-debit';
720 $result = $paiement->addPaymentToBank($user, $modeforaddpayment, $labelforaddpayment, $fk_bank_account,
'',
'');
722 $result = $paiement->addPaymentToBank($user, $modeforaddpayment, $labelforaddpayment, $fk_bank_account,
'',
'', 0,
'', $addbankurl);
727 $this->error = $paiement->error;
728 $this->errors = $paiement->errors;
729 dol_syslog(get_class($this) .
"::set_infocredit AddPaymentToBank Error " . $this->error);
737 $sql =
" UPDATE " . MAIN_DB_PREFIX .
"prelevement_lignes";
738 $sql .=
" SET statut = 2";
739 $sql .=
" WHERE fk_prelevement_bons = " . ((int) $this->
id);
741 if (!$this->db->query($sql)) {
742 dol_syslog(get_class($this) .
"::set_infocredit Update lines Error");
747 $this->error = $this->db->lasterror();
748 dol_syslog(get_class($this) .
"::set_infocredit Update Bons Error");
754 $this->date_credit = $date;
755 $this->statut = self::STATUS_CREDITED;
756 $this->
status = self::STATUS_CREDITED;
761 $this->db->rollback();
781 global
$conf, $langs;
785 dol_syslog(get_class($this) .
"::set_infotrans Start", LOG_INFO);
787 if ($this->db->begin()) {
788 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_bons ";
789 $sql .=
" SET fk_user_trans = " . $user->id;
790 $sql .=
" , date_trans = '" . $this->db->idate($date) .
"'";
791 $sql .=
" , method_trans = " . ((int) $method);
792 $sql .=
" , statut = " . self::STATUS_TRANSFERED;
793 $sql .=
" WHERE rowid = " . ((int) $this->
id);
794 $sql .=
" AND entity = " . ((int)
$conf->entity);
795 $sql .=
" AND statut = " . self::STATUS_DRAFT;
797 if ($this->db->query($sql)) {
798 $this->method_trans = $method;
799 $langs->load(
'withdrawals');
800 $subject = $langs->trans(
"InfoTransSubject", $this->
ref);
801 $message = $langs->trans(
"InfoTransMessage", $this->
ref,
dolGetFirstLastname($user->firstname, $user->lastname));
802 $message .= $langs->trans(
"InfoTransData",
price($this->amount), $this->methodes_trans[$this->method_trans],
dol_print_date($date,
'day'));
810 $this->date_trans = $date;
811 $this->statut = self::STATUS_TRANSFERED;
812 $this->
status = self::STATUS_TRANSFERED;
813 $this->user_trans = $user->id;
819 $this->db->rollback();
820 dol_syslog(get_class($this) .
"::set_infotrans ROLLBACK", LOG_ERR);
825 dol_syslog(get_class($this) .
"::set_infotrans Ouverture transaction SQL impossible", LOG_CRIT);
844 dol_syslog(get_class($this) .
"::getListInvoices");
848 if ($this->
type ==
'bank-transfer') {
849 if ($type ==
'salary') {
850 $sql .=
" p.fk_salary";
852 $sql .=
" p.fk_facture_fourn";
855 $sql .=
" p.fk_facture";
858 $sql .=
", SUM(pl.amount)";
860 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons as pb,";
861 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
862 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p";
863 $sql .=
" WHERE p.fk_prelevement_lignes = pl.rowid";
864 $sql .=
" AND pl.fk_prelevement_bons = pb.rowid";
865 $sql .=
" AND pb.rowid = " . ((int) $this->
id);
866 $sql .=
" AND pb.entity = " . ((int)
$conf->entity);
868 if ($this->
type ==
'bank-transfer') {
869 if ($type ==
'salary') {
870 $sql .=
" GROUP BY p.fk_salary";
872 $sql .=
" GROUP BY p.fk_facture_fourn";
875 $sql .=
" GROUP BY p.fk_facture";
879 $resql = $this->db->query($sql);
881 $num = $this->db->num_rows($resql);
886 $row = $this->db->fetch_row($resql);
898 $this->db->free($resql);
900 $this->error = $this->db->lasterror();
917 $sql =
"SELECT sum(pd.amount) as nb";
918 if ($type !==
'salary') {
919 if ($mode !=
'bank-transfer') {
920 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f,";
922 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture_fourn as f,";
925 $sql .=
" FROM " . MAIN_DB_PREFIX .
"salary as s,";
927 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_demande as pd";
928 $sql .= ($type !==
'salary' ?
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")" :
" WHERE s.entity IN (" .
getEntity(
'salary') .
")");
930 $sql .= ($type !==
'salary' ?
" AND f.fk_statut = " .
Facture::STATUS_VALIDATED :
" AND s.paye = " . Salary::STATUS_UNPAID);
932 if ($type !==
'salary') {
933 if ($mode !=
'bank-transfer') {
934 $sql .=
" AND f.rowid = pd.fk_facture";
936 $sql .=
" AND f.rowid = pd.fk_facture_fourn";
939 $sql .=
" AND s.rowid = pd.fk_salary";
941 $sql .= ($type !==
'salary' ?
" AND f.paye = 0" :
"");
942 $sql .=
" AND pd.traite = 0";
943 $sql .=
" AND pd.ext_payment_id IS NULL";
944 $sql .= ($type !==
'salary' ?
" AND f.total_ttc > 0" :
"");
946 $resql = $this->db->query($sql);
948 $obj = $this->db->fetch_object($resql);
950 $this->db->free($resql);
955 dol_syslog(get_class($this) .
"::SommeAPrelever Erreur -1");
971 if ($type ===
'salary') {
989 if ($forsalary == 1) {
990 $sql =
"SELECT count(s.rowid) as nb";
991 $sql .=
" FROM " . MAIN_DB_PREFIX .
"salary as s";
993 $sql =
"SELECT count(f.rowid) as nb";
995 if ($type ==
'bank-transfer') {
996 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture_fourn as f";
998 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
1001 $sql .=
", " . MAIN_DB_PREFIX .
"prelevement_demande as pd";
1002 if ($forsalary == 1) {
1003 $sql .=
" WHERE s.entity IN (" .
getEntity(
'invoice') .
")";
1005 $sql .=
" AND s.paye = 0";
1008 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")";
1013 if ($forsalary == 1) {
1014 $sql .=
" AND s.rowid = pd.fk_salary";
1016 if ($type ==
'bank-transfer') {
1017 $sql .=
" AND f.rowid = pd.fk_facture_fourn";
1019 $sql .=
" AND f.rowid = pd.fk_facture";
1022 $sql .=
" AND pd.traite = 0";
1023 $sql .=
" AND pd.ext_payment_id IS NULL";
1024 if (!$forsalary == 1) {
1025 $sql .=
" AND f.total_ttc > 0";
1027 $sql .=
" AND s.paye = 0";
1030 dol_syslog(get_class($this) .
"::NbFactureAPrelever");
1031 $resql = $this->db->query($sql);
1034 $obj = $this->db->fetch_object($resql);
1035 $this->db->free($resql);
1039 $this->error = get_class($this) .
"::NbFactureAPrelever Erreur -1 sql=" . $this->db->error();
1066 public function create($banque = 0, $agence = 0, $mode =
'real', $format =
'ALL', $executiondate = 0, $notrigger = 0, $type =
'direct-debit', $did = 0, $fk_bank_account = 0, $sourcetype =
'invoice')
1069 global
$conf, $langs, $user;
1071 dol_syslog(__METHOD__ .
" Bank=".$banque.
" Office=".$agence.
" mode=".$mode.
" format=".$format.
" type=".$type.
" did=".$did.
" fk_bank_account=".$fk_bank_account.
" sourcetype=".$sourcetype, LOG_DEBUG);
1073 require_once DOL_DOCUMENT_ROOT .
"/compta/facture/class/facture.class.php";
1074 require_once DOL_DOCUMENT_ROOT .
"/societe/class/societe.class.php";
1077 if ($type !=
'bank-transfer') {
1078 if (empty($format)) {
1079 $this->error =
'ErrorBadParametersForDirectDebitFileCreate';
1085 if (empty($fk_bank_account)) {
1086 $fk_bank_account = ($type ==
'bank-transfer' ?
getDolGlobalInt(
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') :
getDolGlobalInt(
'PRELEVEMENT_ID_BANKACCOUNT'));
1091 if ($sourcetype !=
'salary') {
1092 $entities = $type !=
'bank-transfer' ?
getEntity(
'invoice') :
getEntity(
'supplier_invoice');
1093 $socOrUser =
'fk_soc';
1094 $societeOrUser =
'societe';
1097 $sqlTable =
'salary';
1098 $socOrUser =
'fk_user';
1099 $societeOrUser =
'user';
1102 $sqlTable = $type !=
'bank-transfer' ?
"facture" :
"facture_fourn";
1104 $thirdpartyBANId = 0;
1108 $sql =
"SELECT pd.fk_societe_rib";
1109 $sql .=
" FROM " . $this->db->prefix() .
"prelevement_demande as pd";
1110 $sql .=
" WHERE pd.rowid = ".((int) $did);
1112 $resql = $this->db->query($sql);
1115 $this->error = $this->db->lasterror();
1116 dol_syslog(__METHOD__ .
" Read fk_societe_rib error " . $this->db->lasterror(), LOG_ERR);
1120 $obj = $this->db->fetch_object($resql);
1122 $thirdpartyBANId = $obj->fk_societe_rib;
1124 dol_syslog(__METHOD__ .
" Found an BAN ID to use: ".$thirdpartyBANId);
1127 $this->db->free($resql);
1130 $datetimeprev =
dol_now(
'gmt');
1132 if (!empty($executiondate)) {
1133 $datetimeprev = $executiondate;
1139 $this->invoice_in_error = array();
1140 $this->thirdparty_in_error = array();
1143 $factures = array();
1144 $factures_prev = array();
1145 $factures_result = array();
1146 $factures_prev_id = array();
1147 $factures_errors = array();
1150 dol_syslog(__METHOD__ .
" Read invoices for did=" . ((
int) $did), LOG_DEBUG);
1152 $sql =
"SELECT f.rowid, pd.rowid as pfdrowid";
1153 $sql .=
", f.".$this->db->sanitize($socOrUser);
1154 $sql .=
", pd.code_banque, pd.code_guichet, pd.number, pd.cle_rib";
1155 $sql .=
", pd.amount";
1156 if ($sourcetype !=
'salary') {
1157 $sql .=
", s.nom as name";
1158 $sql .=
", f.ref, sr.bic, sr.iban_prefix, sr.frstrecur";
1160 $sql .=
", CONCAT(s.firstname,' ',s.lastname) as name";
1161 $sql .=
", f.ref, sr.bic, sr.iban_prefix, 'FRST' as frstrecur";
1163 $sql .=
" FROM " . $this->db->prefix() . $sqlTable .
" as f";
1164 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"prelevement_demande as pd ON f.rowid = pd.fk_".$this->db->sanitize($sqlTable);
1165 $sql .=
" LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($societeOrUser).
" as s ON s.rowid = f.".$this->db->sanitize($socOrUser);
1166 $sql .=
" LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($societeOrUser.
"_rib").
" as sr ON s.rowid = sr.".$this->db->sanitize($socOrUser);
1167 if ($sourcetype !=
'salary') {
1168 if (!empty($thirdpartyBANId)) {
1169 $sql .=
" AND sr.rowid = " . ((int) $thirdpartyBANId);
1171 $sql .=
" AND sr.default_rib = 1";
1176 $sql .=
" WHERE f.entity IN (".$this->db->escape($entities).
')';
1177 if ($sourcetype !=
'salary') {
1178 $sql .=
" AND f.fk_statut = 1";
1179 $sql .=
" AND f.paye = 0";
1180 $sql .=
" AND f.total_ttc > 0";
1183 $sql .=
" AND f.paye = 0";
1184 $sql .=
" AND f.amount > 0";
1186 $sql .=
" AND pd.traite = 0";
1187 $sql .=
" AND pd.ext_payment_id IS NULL";
1188 if ($sourcetype !=
'salary') {
1189 $sql .=
" AND sr.type = 'ban'";
1192 $sql .=
" AND pd.rowid = " . ((int) $did);
1195 $resql = $this->db->query($sql);
1197 $num = $this->db->num_rows($resql);
1201 $row = $this->db->fetch_row($resql);
1202 '@phan-var-force array<int<0,12>,string> $row';
1205 $factures[$i] = $row;
1208 $factures[$i][11] =
dolDecrypt($factures[$i][11]);
1212 dol_syslog(__METHOD__ .
" Read invoices/salary error Found a null amount", LOG_ERR);
1213 $this->invoice_in_error[$row[0]] =
"Error for invoice or salary id " . $row[0] .
", found a null amount";
1219 $this->db->free($resql);
1220 dol_syslog(__METHOD__ .
" Read invoices/salary, " . $i .
" invoices/salary to withdraw", LOG_DEBUG);
1222 $this->error = $this->db->lasterror();
1223 dol_syslog(__METHOD__ .
" Read invoices/salary error " . $this->db->lasterror(), LOG_ERR);
1230 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1231 require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
1232 require_once DOL_DOCUMENT_ROOT .
'/societe/class/companybankaccount.class.php';
1233 require_once DOL_DOCUMENT_ROOT .
'/core/lib/bank.lib.php';
1235 $tmpsoc =
new Societe($this->db);
1236 $tmpuser =
new User($this->db);
1240 dol_syslog(__METHOD__ .
" Check BAN for each invoices or salary", LOG_DEBUG);
1242 if (count($factures) > 0) {
1243 foreach ($factures as $key => $fac) {
1245 if ($fac[8] !=
null) {
1246 if ($type !=
'bank-transfer') {
1247 if ($format ==
'FRST' && $fac[12] !=
'FRST') {
1250 if ($format ==
'RCUR' && $fac[12] !=
'RCUR') {
1256 if ($verif || (empty($fac[10]) &&
getDolGlobalInt(
"WITHDRAWAL_WITHOUT_BIC"))) {
1257 dol_syslog(__METHOD__.
" now call checkIbanForAccount(null, ".$fac[11].
")");
1262 $factures_prev[$i] = $fac;
1264 $factures_prev_id[$i] = $fac[0];
1268 if ($type !=
'bank-transfer') {
1269 $tmpsoc->id = (int) $fac[2];
1270 $tmpsoc->name = $fac[8];
1271 $invoice_url =
"<a href='" . DOL_URL_ROOT .
'/compta/facture/card.php?facid=' . $fac[0] .
"'>" . $fac[9] .
"</a>";
1272 $this->invoice_in_error[$fac[0]] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1273 $this->thirdparty_in_error[$tmpsoc->id] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1276 if ($type ==
'bank-transfer' && $sourcetype !=
'salary') {
1277 $tmpsoc->id = (int) $fac[2];
1278 $tmpsoc->name = $fac[8];
1279 $invoice_url =
"<a href='" . DOL_URL_ROOT .
'/fourn/facture/card.php?facid=' . $fac[0] .
"'>" . $fac[9] .
"</a>";
1280 $this->invoice_in_error[$fac[0]] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1281 $this->thirdparty_in_error[$tmpsoc->id] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1284 if ($type ==
'bank-transfer' && $sourcetype ==
'salary') {
1285 $tmpuser->id = (int) $fac[2];
1286 $tmpuser->firstname = $fac[8];
1287 $salary_url =
"<a href='" . DOL_URL_ROOT .
'/salaries/card.php?id=' . $fac[0] .
"'>" . $fac[0] .
"</a>";
1288 $this->invoice_in_error[$fac[0]] =
"Error on default bank number IBAN/BIC for salary " . $salary_url .
" for employee " . $tmpuser->getNomUrl(0);
1289 $this->thirdparty_in_error[$tmpuser->id] =
"Error on default bank number IBAN/BIC for salary " . $salary_url .
" for employee " . $tmpuser->getNomUrl(0);
1292 dol_syslog(__METHOD__ .
" Check BAN Error on default bank number IBAN/BIC reported by verif(): " . implode(
', ', $fac), LOG_WARNING);
1295 dol_syslog(__METHOD__ .
" Check BAN Failed to read company", LOG_WARNING);
1304 dol_syslog(__METHOD__ .
" Check BAN No invoice to process", LOG_WARNING);
1311 $out = count($factures_prev) .
" invoices or salaries will be included.";
1324 if (count($factures_prev) > 0) {
1325 if ($mode ==
'real') {
1328 print $langs->trans(
"ModeWarning");
1345 $ref = substr($year, -2) . $month;
1348 $sql =
"SELECT substring(ref from char_length(ref) - 1)";
1349 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons";
1350 $sql .=
" WHERE ref LIKE '_" . $this->db->escape($ref) .
"%'";
1351 $sql .=
" AND entity = " . ((int)
$conf->entity);
1352 $sql .=
" ORDER BY ref DESC LIMIT 1";
1354 dol_syslog(get_class($this) .
" get next free number", LOG_DEBUG);
1355 $resql = $this->db->query($sql);
1358 $row = $this->db->fetch_row($resql);
1361 $ref =
"T" . $ref . sprintf(
"%02d", (intval($row[0]) + 1));
1367 if ($type !=
'bank-transfer') {
1368 $dir =
$conf->prelevement->dir_output .
'/receipts';
1370 $dir =
$conf->paymentbybanktransfer->dir_output .
'/receipts';
1372 if (!is_dir($dir)) {
1376 if (isModEnabled(
'multicompany')) {
1377 $labelentity =
$conf->entity;
1378 $this->filename = $dir .
'/' . $ref .
'-' . $labelentity .
'.xml';
1380 $this->filename = $dir .
'/' . $ref .
'.xml';
1384 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"prelevement_bons (";
1385 $sql .=
"ref, entity, datec, type, fk_bank_account";
1386 $sql .=
") VALUES (";
1387 $sql .=
"'" . $this->db->escape($ref) .
"'";
1388 $sql .=
", " . ((int)
$conf->entity);
1389 $sql .=
", '" . $this->db->idate($now) .
"'";
1390 $sql .=
", '" . ($type ==
'bank-transfer' ?
'bank-transfer' :
'debit-order') .
"'";
1391 $sql .=
", " . ((int) $fk_bank_account);
1394 $resql = $this->db->query($sql);
1398 $prev_id = $this->db->last_insert_id(MAIN_DB_PREFIX .
"prelevement_bons");
1399 $this->
id = $prev_id;
1403 dol_syslog(__METHOD__ .
" Create withdraw receipt " . $this->db->lasterror(), LOG_ERR);
1407 dol_syslog(__METHOD__ .
" Get last withdraw receipt " . $this->db->lasterror(), LOG_ERR);
1412 dol_syslog(__METHOD__ .
" Now loop on each document to insert them in llx_prelevement_demande");
1415 if (count($factures_prev) > 0) {
1416 foreach ($factures_prev as $fac) {
1434 $ri = $this->
AddFacture($fac[0], $fac[2], $fac[8], $fac[7], $fac[3], $fac[4], $fac[5], $fac[6], $type, $sourcetype);
1441 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_demande";
1442 $sql .=
" SET traite = 1";
1443 $sql .=
", date_traite = '" . $this->db->idate($now) .
"'";
1444 $sql .=
", fk_prelevement_bons = " . ((int) $this->
id);
1445 $sql .=
" WHERE rowid = " . ((int) $fac[1]);
1447 $resql = $this->db->query($sql);
1450 $this->errors[] = $this->db->lasterror();
1451 dol_syslog(__METHOD__ .
" Update Error=" . $this->db->lasterror(), LOG_ERR);
1462 dol_syslog(__METHOD__ .
" Init direct debit or credit transfer file for " . count($factures_prev) .
" invoices", LOG_DEBUG);
1464 if (count($factures_prev) > 0) {
1465 $this->date_echeance = $datetimeprev;
1466 $this->reference_remise = $ref;
1468 $account =
new Account($this->db);
1469 if ($account->fetch($fk_bank_account) > 0) {
1470 $this->emetteur_code_banque = $account->code_banque;
1471 $this->emetteur_code_guichet = $account->code_guichet;
1472 $this->emetteur_numero_compte = $account->number;
1473 $this->emetteur_number_key = $account->cle_rib;
1474 $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
1475 $this->emetteur_iban = $account->iban;
1476 $this->emetteur_bic = $account->bic;
1478 $this->emetteur_ics = (($type ==
'bank-transfer' &&
getDolGlobalString(
"SEPA_USE_IDS")) ? $account->ics_transfer : $account->ics);
1480 $this->raison_sociale = $account->owner_name;
1482 $this->factures = $factures_prev_id;
1483 $this->context[
'factures_prev'] = $factures_prev;
1487 if ($sourcetype ==
'salary') {
1488 $userid = $this->context[
'factures_prev'][0][2];
1490 $result = $this->
generate($format, $executiondate, $type, $fk_bank_account, $userid, $thirdpartyBANId);
1497 dol_syslog(__METHOD__ .
" Bank order file has been generated under filename " . $this->filename, LOG_DEBUG);
1505 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_bons";
1506 $sql .=
" SET amount = " .
price2num($this->total);
1507 $sql .=
" WHERE rowid = " . ((int) $this->
id);
1508 $sql .=
" AND entity = " . ((int)
$conf->entity);
1509 $resql = $this->db->query($sql);
1513 dol_syslog(__METHOD__ .
" Error update total: " . $this->db->error(), LOG_ERR);
1517 if (!$error && !$notrigger) {
1518 $triggername =
'DIRECT_DEBIT_ORDER_CREATE';
1519 if ($type !=
'bank-transfer') {
1520 $triggername =
'CREDIT_TRANSFER_ORDER_CREATE';
1532 $this->db->commit();
1533 return count($factures_prev);
1535 $this->db->rollback();
1551 public function delete($user =
null, $notrigger = 0)
1556 $resql1 = $resql2 = $resql3 = $resql4 = 0;
1559 $triggername =
'DIRECT_DEBIT_ORDER_DELETE';
1560 if ($this->
type ==
'bank-transfer') {
1561 $triggername =
'PAYMENTBYBANKTRANFER_DELETE';
1572 $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) .
")";
1573 $resql1 = $this->db->query($sql);
1580 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"prelevement_lignes WHERE fk_prelevement_bons = " . ((int) $this->
id);
1581 $resql2 = $this->db->query($sql);
1588 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"prelevement_bons WHERE rowid = " . ((int) $this->
id);
1589 $resql3 = $this->db->query($sql);
1596 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_demande SET fk_prelevement_bons = NULL, traite = 0 WHERE fk_prelevement_bons = " . ((int) $this->
id);
1597 $resql4 = $this->db->query($sql);
1603 if ($resql1 && $resql2 && $resql3 && $resql4 && !$error) {
1604 $this->db->commit();
1607 $this->db->rollback();
1623 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1625 global
$conf, $langs, $hookmanager;
1627 if (!empty(
$conf->dol_no_mouse_hover)) {
1633 $labeltoshow =
'PaymentByDirectDebit';
1634 if (!empty($this->
type) && $this->
type ==
'bank-transfer') {
1635 $labeltoshow =
'PaymentByBankTransfer';
1638 $label =
img_picto(
'', $this->picto) .
' <u>' . $langs->trans($labeltoshow) .
'</u> ' . $this->
getLibStatut(5);
1640 $label .=
'<b>' . $langs->trans(
'Ref') .
':</b> ' . $this->ref;
1641 if (isset($this->amount)) {
1642 $label .=
'<br><b>' . $langs->trans(
"Amount") .
":</b> " .
price($this->amount);
1644 if (isset($this->date_trans)) {
1645 $label .=
'<br><b>' . $langs->trans(
"TransData") .
":</b> " .
dol_print_date($this->date_trans,
'dayhour',
'tzuserrel');
1651 $url = DOL_URL_ROOT .
'/compta/prelevement/card.php?id=' . $this->id;
1652 if (!empty($this->
type) && $this->
type ==
'bank-transfer') {
1653 $url = DOL_URL_ROOT .
'/compta/prelevement/card.php?id=' . $this->id;
1656 if ($option !=
'nolink') {
1658 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1659 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1660 $add_save_lastsearch_values = 1;
1662 if ($add_save_lastsearch_values) {
1663 $url .=
'&save_lastsearch_values=1';
1668 if (empty($notooltip)) {
1670 $label = $langs->trans(
"ShowMyObject");
1674 $linkclose .=
' class="classfortooltip' . ($morecss ?
' ' . $morecss :
'') .
'"';
1676 $linkclose = ($morecss ?
' class="' . $morecss .
'"' :
'');
1679 $linkstart =
'<a href="' . $url .
'"';
1680 $linkstart .= $linkclose .
'>';
1683 $result .= $linkstart;
1685 $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);
1687 if ($withpicto != 2) {
1688 $result .= $this->ref;
1690 $result .= $linkend;
1692 global $action, $hookmanager;
1693 $hookmanager->initHooks(array(
'banktransferdao'));
1694 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1695 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1697 $result = $hookmanager->resPrint;
1699 $result .= $hookmanager->resPrint;
1714 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"notify_def";
1715 $sql .=
" WHERE rowid = " . ((int) $rowid);
1717 if ($this->db->query($sql)) {
1733 if (is_object($user)) {
1734 $userid = $user->id;
1739 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"notify_def";
1740 $sql .=
" WHERE fk_user=" . ((int) $userid) .
" AND fk_action='" . $this->db->escape($action) .
"'";
1742 if ($this->db->query($sql)) {
1763 if (is_object($user)) {
1764 $userid = $user->id;
1772 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"notify_def (datec,fk_user, fk_soc, fk_contact, fk_action)";
1773 $sql .=
" VALUES ('" . $this->db->idate($now) .
"', " . ((int) $userid) .
", 'NULL', 'NULL', '" . $this->db->escape($action) .
"')";
1776 if ($this->db->query($sql)) {
1780 dol_syslog(get_class($this) .
"::addNotification Error $result");
1803 public function generate(
string $format =
'ALL',
int $executiondate = 0,
string $type =
'direct-debit',
int $fk_bank_account = 0,
int $forsalary = 0,
int $thirdpartyBANId = 0)
1805 global
$conf, $langs, $mysoc;
1810 if (empty($fk_bank_account)) {
1811 $fk_bank_account = ($type ==
'bank-transfer' ?
getDolGlobalInt(
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') :
getDolGlobalInt(
'PRELEVEMENT_ID_BANKACCOUNT'));
1816 dol_syslog(get_class($this) .
"::generate build file=" . $this->filename .
" type=" . $type);
1818 $this->file = fopen($this->filename,
"w");
1819 if ($this->file ==
false) {
1820 $this->error = $langs->trans(
'ErrorFailedToOpenFile', $this->filename);
1828 if ($mysoc->isInEEC()) {
1831 if ($type !=
'bank-transfer') {
1843 if (!empty($executiondate)) {
1844 $date_actu = $executiondate;
1849 $fileDebiteurSection =
'';
1850 $fileEmetteurSection =
'';
1857 $sql =
"SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
1858 $sql .=
" pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
1859 $sql .=
" f.ref as reffac, p.fk_facture as idfac,";
1860 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
1862 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
1863 $sql .=
" " . MAIN_DB_PREFIX .
"facture as f,";
1864 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p,";
1865 $sql .=
" " . MAIN_DB_PREFIX .
"societe as soc,";
1866 $sql .=
" " . MAIN_DB_PREFIX .
"c_country as c,";
1867 $sql .=
" " . MAIN_DB_PREFIX .
"societe_rib as rib";
1868 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
1869 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
1870 $sql .=
" AND p.fk_facture = f.rowid";
1871 $sql .=
" AND f.fk_soc = soc.rowid";
1872 $sql .=
" AND soc.fk_pays = c.rowid";
1873 $sql .=
" AND rib.fk_soc = f.fk_soc";
1874 if (!empty($thirdpartyBANId)) {
1875 $sql .=
" AND rib.rowid = " . ((int) $thirdpartyBANId);
1877 $sql .=
" AND rib.default_rib = 1";
1879 $sql .=
" AND rib.type = 'ban'";
1882 $resql = $this->db->query($sql);
1883 $nbtotalDrctDbtTxInf = -1;
1885 $cachearraytotestduplicate = array();
1887 $num = $this->db->num_rows($resql);
1889 $obj = $this->db->fetch_object($resql);
1891 if (!empty($cachearraytotestduplicate[$obj->idfac])) {
1892 $this->error = $langs->trans(
'ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
1893 $this->invoice_in_error[$obj->idfac] = $this->error;
1897 $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
1899 $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
1902 $fileDebiteurSection .= $this->
EnregDestinataireSEPA($obj->code, $obj->nom, $obj->address, $obj->zip, $obj->town, $obj->country_code, $obj->cb, $obj->cg, $obj->cc, $obj->somme, $obj->reffac, $obj->idfac, $iban, $obj->bic, $daterum, $obj->drum, $obj->rum, $type);
1904 $this->total += $obj->somme;
1907 $nbtotalDrctDbtTxInf = $i;
1909 $this->error = $this->db->lasterror();
1910 fwrite($this->file,
'ERROR DEBITOR ' . $sql . $CrLf);
1915 if ($result != -2) {
1916 $fileEmetteurSection .= $this->
EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type, $fk_bank_account);
1920 $this->total = number_format((
float)
price2num($this->total,
'MT'), 2,
".",
"");
1927 fwrite($this->file,
'<' .
'?xml version="1.0" encoding="UTF-8" standalone="yes"?' .
'>' . $CrLf);
1928 fwrite($this->file,
'<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.001.02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' . $CrLf);
1929 fwrite($this->file,
' <CstmrDrctDbtInitn>' . $CrLf);
1931 fwrite($this->file,
' <GrpHdr>' . $CrLf);
1932 fwrite($this->file,
' <MsgId>' . (
'DOL/' . $dateTime_YMD .
'/DD' . $this->
id) .
'</MsgId>' . $CrLf);
1933 fwrite($this->file,
' <CreDtTm>' . $dateTime_ECMA .
'</CreDtTm>' . $CrLf);
1934 fwrite($this->file,
' <NbOfTxs>' . $i .
'</NbOfTxs>' . $CrLf);
1935 fwrite($this->file,
' <CtrlSum>' . $this->total .
'</CtrlSum>' . $CrLf);
1936 fwrite($this->file,
' <InitgPty>' . $CrLf);
1938 fwrite($this->file,
' <Id>' . $CrLf);
1939 fwrite($this->file,
' <PrvtId>' . $CrLf);
1940 fwrite($this->file,
' <Othr>' . $CrLf);
1941 fwrite($this->file,
' <Id>' . $this->emetteur_ics .
'</Id>' . $CrLf);
1942 fwrite($this->file,
' </Othr>' . $CrLf);
1943 fwrite($this->file,
' </PrvtId>' . $CrLf);
1944 fwrite($this->file,
' </Id>' . $CrLf);
1945 fwrite($this->file,
' </InitgPty>' . $CrLf);
1946 fwrite($this->file,
' </GrpHdr>' . $CrLf);
1948 if ($result != -2) {
1949 fwrite($this->file, $fileEmetteurSection);
1952 if ($result != -2) {
1953 fwrite($this->file, $fileDebiteurSection);
1956 fwrite($this->file,
' </PmtInf>' . $CrLf);
1957 fwrite($this->file,
' </CstmrDrctDbtInitn>' . $CrLf);
1958 fwrite($this->file,
'</Document>' . $CrLf);
1971 if (!empty($executiondate)) {
1972 $date_actu = $executiondate;
1977 $fileCrediteurSection =
'';
1978 $fileEmetteurSection =
'';
1984 if (!empty($forsalary)) {
1985 $sql =
"SELECT u.rowid as userId, u.address, u.zip, u.town, c.code as country_code, CONCAT(u.firstname,' ',u.lastname) as nom,";
1986 $sql .=
" pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
1987 $sql .=
" s.ref as reffac, p.fk_salary as idfac,";
1988 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, '' as rum, '' as date_rum";
1990 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
1991 $sql .=
" " . MAIN_DB_PREFIX .
"salary as s,";
1992 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p,";
1993 $sql .=
" " . MAIN_DB_PREFIX .
"user as u";
1994 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"c_country as c ON u.fk_country = c.rowid,";
1995 $sql .=
" " . MAIN_DB_PREFIX .
"user_rib as rib";
1996 $sql .=
" WHERE pl.fk_prelevement_bons=" . ((int) $this->
id);
1997 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
1998 $sql .=
" AND p.fk_salary = s.rowid";
1999 $sql .=
" AND s.fk_user = u.rowid";
2000 $sql .=
" AND rib.fk_user = s.fk_user";
2002 $sql =
"SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
2003 $sql .=
" pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
2004 $sql .=
" f.ref as reffac, f.ref_supplier as fac_ref_supplier, p.fk_facture_fourn as idfac,";
2005 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
2007 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
2008 $sql .=
" " . MAIN_DB_PREFIX .
"facture_fourn as f,";
2009 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p,";
2010 $sql .=
" " . MAIN_DB_PREFIX .
"societe as soc";
2011 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"c_country as c ON soc.fk_pays = c.rowid,";
2012 $sql .=
" " . MAIN_DB_PREFIX .
"societe_rib as rib";
2013 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
2014 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
2015 $sql .=
" AND p.fk_facture_fourn = f.rowid";
2016 $sql .=
" AND f.fk_soc = soc.rowid";
2017 $sql .=
" AND rib.fk_soc = f.fk_soc";
2018 if (!empty($thirdpartyBANId)) {
2019 $sql .=
" AND rib.rowid = " . ((int) $thirdpartyBANId);
2021 $sql .=
" AND rib.default_rib = 1";
2023 $sql .=
" AND rib.type = 'ban'";
2026 $nbtotalDrctDbtTxInf = -1;
2028 $resql = $this->db->query($sql);
2030 $cachearraytotestduplicate = array();
2032 $num = $this->db->num_rows($resql);
2034 $obj = $this->db->fetch_object($resql);
2035 if (!empty($cachearraytotestduplicate[$obj->idfac])) {
2036 $this->error = $langs->trans(
'ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
2037 $this->invoice_in_error[$obj->idfac] = $this->error;
2041 $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
2043 $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
2045 $refobj = $obj->reffac;
2046 if (empty($refobj) && !empty($forsalary)) {
2047 $refobj =
"SAL" . $obj->idfac;
2050 $fileCrediteurSection .= $this->
EnregDestinataireSEPA($obj->code, $obj->nom, $obj->address, $obj->zip, $obj->town, $obj->country_code, $obj->cb, $obj->cg, $obj->cc, $obj->somme, $refobj, $obj->idfac, $iban, $obj->bic, $daterum, $obj->drum, $obj->rum, $type, $obj->fac_ref_supplier);
2052 $this->total += $obj->somme;
2055 $nbtotalDrctDbtTxInf = $i;
2057 $this->error = $this->db->lasterror();
2058 fwrite($this->file,
'ERROR CREDITOR ' . $sql . $CrLf);
2062 if ($result != -2) {
2063 $fileEmetteurSection .= $this->
EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type);
2067 $this->total = number_format((
float)
price2num($this->total,
'MT'), 2,
".",
"");
2074 fwrite($this->file,
'<' .
'?xml version="1.0" encoding="UTF-8" standalone="yes"?' .
'>' . $CrLf);
2075 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);
2076 fwrite($this->file,
' <CstmrCdtTrfInitn>' . $CrLf);
2078 fwrite($this->file,
' <GrpHdr>' . $CrLf);
2079 fwrite($this->file,
' <MsgId>' . (
'DOL/' . $dateTime_YMD .
'/CT' . $this->
id) .
'</MsgId>' . $CrLf);
2080 fwrite($this->file,
' <CreDtTm>' . $dateTime_ECMA .
'</CreDtTm>' . $CrLf);
2081 fwrite($this->file,
' <NbOfTxs>' . $i .
'</NbOfTxs>' . $CrLf);
2082 fwrite($this->file,
' <CtrlSum>' . $this->total .
'</CtrlSum>' . $CrLf);
2083 fwrite($this->file,
' <InitgPty>' . $CrLf);
2085 fwrite($this->file,
' <Id>' . $CrLf);
2086 fwrite($this->file,
' <PrvtId>' . $CrLf);
2087 fwrite($this->file,
' <Othr>' . $CrLf);
2088 fwrite($this->file,
' <Id>' . $this->emetteur_ics .
'</Id>' . $CrLf);
2089 fwrite($this->file,
' </Othr>' . $CrLf);
2090 fwrite($this->file,
' </PrvtId>' . $CrLf);
2091 fwrite($this->file,
' </Id>' . $CrLf);
2092 fwrite($this->file,
' </InitgPty>' . $CrLf);
2093 fwrite($this->file,
' </GrpHdr>' . $CrLf);
2095 if ($result != -2) {
2096 fwrite($this->file, $fileEmetteurSection);
2099 if ($result != -2) {
2100 fwrite($this->file, $fileCrediteurSection);
2103 fwrite($this->file,
' </PmtInf>' . $CrLf);
2104 fwrite($this->file,
' </CstmrCdtTrfInitn>' . $CrLf);
2105 fwrite($this->file,
'</Document>' . $CrLf);
2111 if ($type !=
'bank-transfer') {
2112 $sql =
"SELECT pl.amount";
2114 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
2115 $sql .=
" " . MAIN_DB_PREFIX .
"facture as f,";
2116 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p";
2117 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
2118 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
2119 $sql .=
" AND p.fk_facture = f.rowid";
2123 $resql = $this->db->query($sql);
2125 $num = $this->db->num_rows($resql);
2128 $obj = $this->db->fetch_object($resql);
2129 $this->total += $obj->amount;
2138 $sql =
"SELECT pl.amount";
2140 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
2141 $sql .=
" " . MAIN_DB_PREFIX .
"facture_fourn as f,";
2142 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p";
2143 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
2144 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
2145 $sql .=
" AND p.fk_facture_fourn = f.rowid";
2148 $resql = $this->db->query($sql);
2150 $num = $this->db->num_rows($resql);
2153 $obj = $this->db->fetch_object($resql);
2154 $this->total += $obj->amount;
2164 $langs->load(
'withdrawals');
2167 fwrite($this->file, $langs->transnoentitiesnoconv(
'WithdrawalFileNotCapable', $mysoc->country_code));
2170 fclose($this->file);
2192 return $pre .
'-' .
dol_print_date($row_datec,
'dayhourlogsmall') .
'-' .
dol_trunc($row_drum . ($row_code_client ?
'-' . $row_code_client :
''), 13,
'right',
'UTF-8', 1);
2213 public function EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $ref, $facid, $rib_dom =
'', $type =
'direct-debit')
2216 fwrite($this->file,
"06");
2217 fwrite($this->file,
"08");
2219 fwrite($this->file,
" ");
2221 fwrite($this->file, $this->emetteur_ics);
2225 fwrite($this->file,
" ");
2226 fwrite($this->file,
dol_print_date($this->date_echeance,
"%d%m",
'gmt'));
2227 fwrite($this->file, substr(
dol_print_date($this->date_echeance,
"%y",
'gmt'), 1));
2231 fwrite($this->file, substr(strtoupper($client_nom) .
" ", 0, 24));
2234 $address = strtr($rib_dom, array(
" " =>
"-", chr(13) =>
" ", chr(10) =>
""));
2235 fwrite($this->file, substr($address .
" ", 0, 24));
2239 fwrite($this->file, substr(
" ", 0, 8));
2243 fwrite($this->file, $rib_guichet);
2247 fwrite($this->file, substr(
"000000000000000" . $rib_number, -11));
2251 $montant = (round($amount, 2) * 100);
2253 fwrite($this->file, substr(
"000000000000000" . $montant, -16));
2257 fwrite($this->file, substr(
"*_" . $ref .
"_RDVnet" . $rowid .
" ", 0, 31));
2261 fwrite($this->file, $rib_banque);
2265 fwrite($this->file, substr(
" ", 0, 5));
2267 fwrite($this->file,
"\n");
2297 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 =
'')
2300 global
$conf, $mysoc;
2303 $row_somme = number_format((
float)
price2num($row_somme,
'MT'), 2,
".",
"");
2305 $row_somme = round((
float) $row_somme, 2);
2308 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
2311 $Rowing = sprintf(
"%010d", $row_idfac);
2315 $Rum = (empty($row_rum) ? $this->
buildRumNumber($row_code_client, $row_datec, $row_drum) : $row_rum);
2320 if ($type !=
'bank-transfer') {
2323 $XML_DEBITOR .=
' <DrctDbtTxInf>' . $CrLf;
2324 $XML_DEBITOR .=
' <PmtId>' . $CrLf;
2326 $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;
2327 $XML_DEBITOR .=
' </PmtId>' . $CrLf;
2328 $XML_DEBITOR .=
' <InstdAmt Ccy="EUR">' . $row_somme .
'</InstdAmt>' . $CrLf;
2329 $XML_DEBITOR .=
' <DrctDbtTx>' . $CrLf;
2330 $XML_DEBITOR .=
' <MndtRltdInf>' . $CrLf;
2331 $XML_DEBITOR .=
' <MndtId>' . $Rum .
'</MndtId>' . $CrLf;
2332 $XML_DEBITOR .=
' <DtOfSgntr>' . $DtOfSgntr .
'</DtOfSgntr>' . $CrLf;
2333 $XML_DEBITOR .=
' <AmdmntInd>false</AmdmntInd>' . $CrLf;
2334 $XML_DEBITOR .=
' </MndtRltdInf>' . $CrLf;
2335 $XML_DEBITOR .=
' </DrctDbtTx>' . $CrLf;
2336 $XML_DEBITOR .=
' <DbtrAgt>' . $CrLf;
2337 $XML_DEBITOR .=
' <FinInstnId>' . $CrLf;
2339 $XML_DEBITOR .=
' <BIC>' . $row_bic .
'</BIC>' . $CrLf;
2341 $XML_DEBITOR .=
' </FinInstnId>' . $CrLf;
2342 $XML_DEBITOR .=
' </DbtrAgt>' . $CrLf;
2343 $XML_DEBITOR .=
' <Dbtr>' . $CrLf;
2345 $XML_DEBITOR .=
' <PstlAdr>' . $CrLf;
2346 $XML_DEBITOR .=
' <Ctry>' . $row_country_code .
'</Ctry>' . $CrLf;
2347 $addressline1 = strtr($row_address, array(chr(13) =>
", ", chr(10) =>
""));
2348 $addressline2 = strtr($row_zip . (($row_zip && $row_town) ?
' ' : (string) $row_town), array(chr(13) =>
", ", chr(10) =>
""));
2349 if (trim($addressline1)) {
2352 if (trim($addressline2)) {
2355 $XML_DEBITOR .=
' </PstlAdr>' . $CrLf;
2356 $XML_DEBITOR .=
' </Dbtr>' . $CrLf;
2357 $XML_DEBITOR .=
' <DbtrAcct>' . $CrLf;
2358 $XML_DEBITOR .=
' <Id>' . $CrLf;
2359 $XML_DEBITOR .=
' <IBAN>' . preg_replace(
'/\s/',
'', $row_iban) .
'</IBAN>' . $CrLf;
2360 $XML_DEBITOR .=
' </Id>' . $CrLf;
2361 $XML_DEBITOR .=
' </DbtrAcct>' . $CrLf;
2362 $XML_DEBITOR .=
' <RmtInf>' . $CrLf;
2365 if (
getDolGlobalString(
'INVOICE_PAYMENT_ENABLE_STRUCTURED_COMMUNICATION') && $mysoc->country_code ==
'BE') {
2366 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
2368 $invoicestatic =
new Facture($this->db);
2369 $invoicestatic->fetch($row_idfac);
2372 $XML_DEBITOR .=
' <strd>' . $invoicePaymentKey .
'</strd>' . $CrLf;
2377 $XML_DEBITOR .=
' </RmtInf>' . $CrLf;
2378 $XML_DEBITOR .=
' </DrctDbtTxInf>' . $CrLf;
2379 return $XML_DEBITOR;
2383 $XML_CREDITOR .=
' <CdtTrfTxInf>' . $CrLf;
2384 $XML_CREDITOR .=
' <PmtId>' . $CrLf;
2386 $XML_CREDITOR .=
' <EndToEndId>' . ((
getDolGlobalString(
'PRELEVEMENT_END_TO_END') !=
"") ?
$conf->global->PRELEVEMENT_END_TO_END : (
'CT-' .
dol_trunc($row_idfac .
'-' . $row_ref, 20,
'right',
'UTF-8', 1)) .
'-' . $Rowing) .
'</EndToEndId>' . $CrLf;
2387 $XML_CREDITOR .=
' </PmtId>' . $CrLf;
2388 if (!empty($this->sepa_xml_pti_in_ctti)) {
2389 $XML_CREDITOR .=
' <PmtTpInf>' . $CrLf;
2393 $instrprty =
'HIGH';
2395 $instrprty =
'NORM';
2397 $XML_CREDITOR .=
' <InstrPrty>' . $instrprty .
'</InstrPrty>' . $CrLf;
2398 $XML_CREDITOR .=
' <SvcLvl>' . $CrLf;
2399 $XML_CREDITOR .=
' <Cd>SEPA</Cd>' . $CrLf;
2400 $XML_CREDITOR .=
' </SvcLvl>' . $CrLf;
2401 $XML_CREDITOR .=
' <CtgyPurp>' . $CrLf;
2402 $XML_CREDITOR .=
' <Cd>CORE</Cd>' . $CrLf;
2403 $XML_CREDITOR .=
' </CtgyPurp>' . $CrLf;
2404 $XML_CREDITOR .=
' </PmtTpInf>' . $CrLf;
2406 $XML_CREDITOR .=
' <Amt>' . $CrLf;
2407 $XML_CREDITOR .=
' <InstdAmt Ccy="EUR">'.round((
float) $row_somme, 2).
'</InstdAmt>'.$CrLf;
2408 $XML_CREDITOR .=
' </Amt>' . $CrLf;
2419 $XML_CREDITOR .=
' <CdtrAgt>' . $CrLf;
2420 $XML_CREDITOR .=
' <FinInstnId>' . $CrLf;
2421 $XML_CREDITOR .=
' <BIC>' . $row_bic .
'</BIC>' . $CrLf;
2422 $XML_CREDITOR .=
' </FinInstnId>' . $CrLf;
2423 $XML_CREDITOR .=
' </CdtrAgt>' . $CrLf;
2424 $XML_CREDITOR .=
' <Cdtr>' . $CrLf;
2426 $XML_CREDITOR .=
' <PstlAdr>' . $CrLf;
2427 $XML_CREDITOR .=
' <Ctry>' . $row_country_code .
'</Ctry>' . $CrLf;
2428 $addressline1 = strtr($row_address, array(chr(13) =>
", ", chr(10) =>
""));
2429 $addressline2 = strtr($row_zip . (($row_zip && $row_town) ?
' ' : (string) $row_town), array(chr(13) =>
", ", chr(10) =>
""));
2430 if (trim($addressline1)) {
2433 if (trim($addressline2)) {
2436 $XML_CREDITOR .=
' </PstlAdr>' . $CrLf;
2437 $XML_CREDITOR .=
' </Cdtr>' . $CrLf;
2438 $XML_CREDITOR .=
' <CdtrAcct>' . $CrLf;
2439 $XML_CREDITOR .=
' <Id>' . $CrLf;
2440 $XML_CREDITOR .=
' <IBAN>' . preg_replace(
'/\s/',
'', $row_iban) .
'</IBAN>' . $CrLf;
2441 $XML_CREDITOR .=
' </Id>' . $CrLf;
2442 $XML_CREDITOR .=
' </CdtrAcct>' . $CrLf;
2443 $XML_CREDITOR .=
' <RmtInf>' . $CrLf;
2446 $XML_CREDITOR .=
' </RmtInf>' . $CrLf;
2447 $XML_CREDITOR .=
' </CdtTrfTxInf>' . $CrLf;
2448 return $XML_CREDITOR;
2465 fwrite($this->file,
"03");
2466 fwrite($this->file,
"08");
2468 fwrite($this->file,
" ");
2470 fwrite($this->file, $this->emetteur_ics);
2474 fwrite($this->file,
" ");
2475 fwrite($this->file,
dol_print_date($this->date_echeance,
"%d%m",
'gmt'));
2476 fwrite($this->file, substr(
dol_print_date($this->date_echeance,
"%y",
'gmt'), 1));
2480 fwrite($this->file, substr($this->raison_sociale .
" ", 0, 24));
2484 fwrite($this->file, substr($this->reference_remise .
" ", 0, 7));
2488 fwrite($this->file, substr(
" ", 0, 17));
2492 fwrite($this->file, substr(
" ", 0, 2));
2493 fwrite($this->file,
"E");
2494 fwrite($this->file, substr(
" ", 0, 5));
2498 fwrite($this->file, $this->emetteur_code_guichet);
2502 fwrite($this->file, substr(
"000000000000000" . $this->emetteur_numero_compte, -11));
2506 fwrite($this->file, substr(
" ", 0, 16));
2510 fwrite($this->file, substr(
" ", 0, 31));
2514 fwrite($this->file, $this->emetteur_code_banque);
2518 fwrite($this->file, substr(
" ", 0, 5));
2520 fwrite($this->file,
"\n");
2539 public function EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf =
'\n', $format =
'FRST', $type =
'direct-debit', $fk_bank_account = 0)
2549 if (empty($fk_bank_account)) {
2550 $fk_bank_account = ($type ==
'bank-transfer' ?
getDolGlobalInt(
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') :
getDolGlobalInt(
'PRELEVEMENT_ID_BANKACCOUNT'));
2554 $account =
new Account($this->db);
2555 if ($account->fetch($fk_bank_account) > 0) {
2556 $this->emetteur_code_banque = $account->code_banque;
2557 $this->emetteur_code_guichet = $account->code_guichet;
2558 $this->emetteur_numero_compte = $account->number;
2559 $this->emetteur_number_key = $account->cle_rib;
2560 $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
2561 $this->emetteur_iban = $account->iban;
2562 $this->emetteur_bic = $account->bic;
2564 $this->emetteur_ics = (($type ==
'bank-transfer' &&
getDolGlobalString(
"SEPA_USE_IDS")) ? $account->ics_transfer : $account->ics);
2566 $this->raison_sociale = $account->owner_name;
2570 $sql =
"SELECT rowid, ref";
2571 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons as pb";
2572 $sql .=
" WHERE pb.rowid = " . ((int) $this->
id);
2574 $resql = $this->db->query($sql);
2576 $obj = $this->db->fetch_object($resql);
2578 $country = explode(
':', $configuration->global->MAIN_INFO_SOCIETE_COUNTRY);
2579 $IdBon = sprintf(
"%05d", $obj->rowid);
2580 $RefBon = $obj->ref;
2582 if (!empty($configuration->global->SEPA_FORCE_TWO_DECIMAL)) {
2583 $total = number_format((
float)
price2num($total,
'MT'), 2,
".",
"");
2586 if ($type !=
'bank-transfer') {
2588 $XML_SEPA_INFO =
'';
2589 $XML_SEPA_INFO .=
' <PmtInf>' . $CrLf;
2590 $XML_SEPA_INFO .=
' <PmtInfId>' . (
'DOL/' . $dateTime_YMD .
'/DD' . $IdBon .
'-' . $RefBon) .
'</PmtInfId>' . $CrLf;
2591 $XML_SEPA_INFO .=
' <PmtMtd>DD</PmtMtd>' . $CrLf;
2592 $XML_SEPA_INFO .=
' <NbOfTxs>' . $nombre .
'</NbOfTxs>' . $CrLf;
2593 $XML_SEPA_INFO .=
' <CtrlSum>' . $total .
'</CtrlSum>' . $CrLf;
2594 $XML_SEPA_INFO .=
' <PmtTpInf>' . $CrLf;
2595 $XML_SEPA_INFO .=
' <SvcLvl>' . $CrLf;
2596 $XML_SEPA_INFO .=
' <Cd>SEPA</Cd>' . $CrLf;
2597 $XML_SEPA_INFO .=
' </SvcLvl>' . $CrLf;
2598 $XML_SEPA_INFO .=
' <LclInstrm>' . $CrLf;
2599 $XML_SEPA_INFO .=
' <Cd>CORE</Cd>' . $CrLf;
2600 $XML_SEPA_INFO .=
' </LclInstrm>' . $CrLf;
2601 $XML_SEPA_INFO .=
' <SeqTp>' . $format .
'</SeqTp>' . $CrLf;
2602 $XML_SEPA_INFO .=
' </PmtTpInf>' . $CrLf;
2603 $XML_SEPA_INFO .=
' <ReqdColltnDt>' . $dateTime_ETAD .
'</ReqdColltnDt>' . $CrLf;
2604 $XML_SEPA_INFO .=
' <Cdtr>' . $CrLf;
2606 $XML_SEPA_INFO .=
' <PstlAdr>' . $CrLf;
2607 $XML_SEPA_INFO .=
' <Ctry>' . $country[1] .
'</Ctry>' . $CrLf;
2608 $addressline1 = strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(chr(13) =>
", ", chr(10) =>
""));
2609 $addressline2 = strtr($configuration->global->MAIN_INFO_SOCIETE_ZIP . (($configuration->global->MAIN_INFO_SOCIETE_ZIP ||
' ' . $configuration->global->MAIN_INFO_SOCIETE_TOWN) ?
' ' :
'') . $configuration->global->MAIN_INFO_SOCIETE_TOWN, array(chr(13) =>
", ", chr(10) =>
""));
2610 if ($addressline1) {
2613 if ($addressline2) {
2616 $XML_SEPA_INFO .=
' </PstlAdr>' . $CrLf;
2617 $XML_SEPA_INFO .=
' </Cdtr>' . $CrLf;
2618 $XML_SEPA_INFO .=
' <CdtrAcct>' . $CrLf;
2619 $XML_SEPA_INFO .=
' <Id>' . $CrLf;
2620 $XML_SEPA_INFO .=
' <IBAN>' . preg_replace(
'/\s/',
'', $this->emetteur_iban) .
'</IBAN>' . $CrLf;
2621 $XML_SEPA_INFO .=
' </Id>' . $CrLf;
2622 $XML_SEPA_INFO .=
' </CdtrAcct>' . $CrLf;
2623 $XML_SEPA_INFO .=
' <CdtrAgt>' . $CrLf;
2624 $XML_SEPA_INFO .=
' <FinInstnId>' . $CrLf;
2625 $XML_SEPA_INFO .=
' <BIC>' . $this->emetteur_bic .
'</BIC>' . $CrLf;
2626 $XML_SEPA_INFO .=
' </FinInstnId>' . $CrLf;
2627 $XML_SEPA_INFO .=
' </CdtrAgt>' . $CrLf;
2636 $XML_SEPA_INFO .=
' <ChrgBr>SLEV</ChrgBr>' . $CrLf;
2637 $XML_SEPA_INFO .=
' <CdtrSchmeId>' . $CrLf;
2638 $XML_SEPA_INFO .=
' <Id>' . $CrLf;
2639 $XML_SEPA_INFO .=
' <PrvtId>' . $CrLf;
2640 $XML_SEPA_INFO .=
' <Othr>' . $CrLf;
2641 $XML_SEPA_INFO .=
' <Id>' . $this->emetteur_ics .
'</Id>' . $CrLf;
2642 $XML_SEPA_INFO .=
' <SchmeNm>' . $CrLf;
2643 $XML_SEPA_INFO .=
' <Prtry>SEPA</Prtry>' . $CrLf;
2644 $XML_SEPA_INFO .=
' </SchmeNm>' . $CrLf;
2645 $XML_SEPA_INFO .=
' </Othr>' . $CrLf;
2646 $XML_SEPA_INFO .=
' </PrvtId>' . $CrLf;
2647 $XML_SEPA_INFO .=
' </Id>' . $CrLf;
2648 $XML_SEPA_INFO .=
' </CdtrSchmeId>' . $CrLf;
2651 $XML_SEPA_INFO =
'';
2652 $XML_SEPA_INFO .=
' <PmtInf>' . $CrLf;
2653 $XML_SEPA_INFO .=
' <PmtInfId>' . (
'DOL/' . $dateTime_YMD .
'/CT' . $IdBon .
'-' . $RefBon) .
'</PmtInfId>' . $CrLf;
2654 $XML_SEPA_INFO .=
' <PmtMtd>TRF</PmtMtd>' . $CrLf;
2656 $XML_SEPA_INFO .=
' <NbOfTxs>' . $nombre .
'</NbOfTxs>' . $CrLf;
2657 $XML_SEPA_INFO .=
' <CtrlSum>' . $total .
'</CtrlSum>' . $CrLf;
2658 if (!empty($this->sepa_xml_pti_in_ctti) && !empty($format)) {
2659 $XML_SEPA_INFO .=
' <PmtTpInf>' . $CrLf;
2660 $XML_SEPA_INFO .=
' <SvcLvl>' . $CrLf;
2661 $XML_SEPA_INFO .=
' <Cd>SEPA</Cd>' . $CrLf;
2662 $XML_SEPA_INFO .=
' </SvcLvl>' . $CrLf;
2663 $XML_SEPA_INFO .=
' <LclInstrm>' . $CrLf;
2664 $XML_SEPA_INFO .=
' <Cd>CORE</Cd>' . $CrLf;
2665 $XML_SEPA_INFO .=
' </LclInstrm>' . $CrLf;
2666 $XML_SEPA_INFO .=
' <SeqTp>' . $format .
'</SeqTp>' . $CrLf;
2667 $XML_SEPA_INFO .=
' </PmtTpInf>' . $CrLf;
2669 $XML_SEPA_INFO .=
' <ReqdExctnDt>' .
dol_print_date($dateTime_ETAD,
'dayrfc') .
'</ReqdExctnDt>' . $CrLf;
2670 $XML_SEPA_INFO .=
' <Dbtr>' . $CrLf;
2672 $XML_SEPA_INFO .=
' <PstlAdr>' . $CrLf;
2673 $XML_SEPA_INFO .=
' <Ctry>' . $country[1] .
'</Ctry>' . $CrLf;
2674 $addressline1 = strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(chr(13) =>
", ", chr(10) =>
""));
2675 $addressline2 = strtr($configuration->global->MAIN_INFO_SOCIETE_ZIP . (($configuration->global->MAIN_INFO_SOCIETE_ZIP ||
' ' . $configuration->global->MAIN_INFO_SOCIETE_TOWN) ?
' ' :
'') . $configuration->global->MAIN_INFO_SOCIETE_TOWN, array(chr(13) =>
", ", chr(10) =>
""));
2676 if ($addressline1) {
2679 if ($addressline2) {
2682 $XML_SEPA_INFO .=
' </PstlAdr>' . $CrLf;
2683 $XML_SEPA_INFO .=
' </Dbtr>' . $CrLf;
2684 $XML_SEPA_INFO .=
' <DbtrAcct>' . $CrLf;
2685 $XML_SEPA_INFO .=
' <Id>' . $CrLf;
2686 $XML_SEPA_INFO .=
' <IBAN>' . preg_replace(
'/\s/',
'', $this->emetteur_iban) .
'</IBAN>' . $CrLf;
2687 $XML_SEPA_INFO .=
' </Id>' . $CrLf;
2688 $XML_SEPA_INFO .=
' </DbtrAcct>' . $CrLf;
2689 $XML_SEPA_INFO .=
' <DbtrAgt>' . $CrLf;
2690 $XML_SEPA_INFO .=
' <FinInstnId>' . $CrLf;
2691 $XML_SEPA_INFO .=
' <BIC>' . $this->emetteur_bic .
'</BIC>' . $CrLf;
2692 $XML_SEPA_INFO .=
' </FinInstnId>' . $CrLf;
2693 $XML_SEPA_INFO .=
' </DbtrAgt>' . $CrLf;
2702 $XML_SEPA_INFO .=
' <ChrgBr>SLEV</ChrgBr>' . $CrLf;
2717 fwrite($this->file,
'INCORRECT EMETTEUR ' . $this->raison_sociale . $CrLf);
2718 $XML_SEPA_INFO =
'';
2720 return $XML_SEPA_INFO;
2733 fwrite($this->file,
"08");
2734 fwrite($this->file,
"08");
2736 fwrite($this->file,
" ");
2738 fwrite($this->file, $this->emetteur_ics);
2742 fwrite($this->file, substr(
" ", 0, 12));
2747 fwrite($this->file, substr(
" ", 0, 24));
2751 fwrite($this->file, substr(
" ", 0, 24));
2755 fwrite($this->file, substr(
" ", 0, 8));
2759 fwrite($this->file, substr(
" ", 0, 5));
2763 fwrite($this->file, substr(
" ", 0, 11));
2767 $montant = ($total * 100);
2769 fwrite($this->file, substr(
"000000000000000" . $montant, -16));
2773 fwrite($this->file, substr(
" ", 0, 31));
2777 fwrite($this->file, substr(
" ", 0, 5));
2781 fwrite($this->file, substr(
" ", 0, 5));
2783 fwrite($this->file,
"\n");
2794 return $this->
LibStatut($this->statut, $mode);
2808 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
2811 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'StatusWaiting');
2812 $this->labelStatus[self::STATUS_TRANSFERED] = $langs->transnoentitiesnoconv(
'StatusTrans');
2813 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'StatusWaiting');
2814 $this->labelStatusShort[self::STATUS_TRANSFERED] = $langs->transnoentitiesnoconv(
'StatusTrans');
2815 if ($this->
type ==
'bank-transfer') {
2816 $this->labelStatus[self::STATUS_DEBITED] = $langs->transnoentitiesnoconv(
'StatusDebited');
2817 $this->labelStatusShort[self::STATUS_DEBITED] = $langs->transnoentitiesnoconv(
'StatusDebited');
2819 $this->labelStatus[self::STATUS_CREDITED] = $langs->transnoentitiesnoconv(
'StatusCredited');
2820 $this->labelStatusShort[self::STATUS_CREDITED] = $langs->transnoentitiesnoconv(
'StatusCredited');
2824 $statusType =
'status1';
2825 if ($status == self::STATUS_TRANSFERED) {
2826 $statusType =
'status3';
2828 if ($status == self::STATUS_CREDITED || $status == self::STATUS_DEBITED) {
2829 $statusType =
'status6';
2832 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
2918 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2920 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2921 $return .=
'<div class="info-box info-box-sm">';
2922 $return .=
'<span class="info-box-icon bg-infobox-action">';
2924 $return .=
'</span>';
2925 $return .=
'<div class="info-box-content">';
2926 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . (method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref) .
'</span>';
2927 if ($selected >= 0) {
2928 $return .=
'<input id="cb' . $this->
id .
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="' . $this->
id .
'"' . ($selected ?
' checked="checked"' :
'') .
'>';
2930 if (property_exists($this,
'date_echeance')) {
2931 $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>';
2933 if (property_exists($this,
'total')) {
2934 $return .=
'<br><span class="opacitymedium">' . $langs->trans(
"Amount") .
'</span> : <span class="amount">' .
price($this->total) .
'</span>';
2936 if (method_exists($this,
'LibStatut')) {
2937 $return .=
'<br><div class="info-box-status">' . $this->
getLibStatut(3) .
'</div>';
2939 $return .=
'</div>';
2940 $return .=
'</div>';
2941 $return .=
'</div>';
2952 if (!empty($this->
id)) {
2958 $sql =
"SELECT COUNT(*) AS nb FROM " . MAIN_DB_PREFIX .
"prelevement_lignes";
2959 $sql .=
" WHERE fk_prelevement_bons = " . ((int) $id);
2960 $sql .=
" AND fk_soc = 0";
2961 $sql .=
" AND fk_user IS NOT NULL";
2964 $resql = $this->db->query($sql);
2966 $obj = $this->db->fetch_object($resql);
checkIbanForAccount($account=null, $ibantocheck=null)
Check IBAN number information for a bank account.
checkSwiftForAccount($account=null, $swift=null)
Check SWIFT information for a bank account.
Class to manage bank accounts.
Class to manage withdrawal receipts.
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.
getListInvoices($amounts=0, $type='')
Get invoice or salary list (with amount or not)
deleteNotificationById($rowid)
Delete a notification def by id.
AddFacture($invoice_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $type='debit-order', $sourcetype='')
Add invoice to withdrawal.
__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.
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.
addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype='')
Add line to withdrawal.
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.
create($banque=0, $agence=0, $mode='real', $format='ALL', $executiondate=0, $notrigger=0, $type='direct-debit', $did=0, $fk_bank_account=0, $sourcetype='invoice')
Create a BAN payment order:
generate(string $format='ALL', 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.
deleteNotification($user, $action)
Delete a notification.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
updateCommon(User $user, $notrigger=0)
Update object into database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage suppliers invoices.
Class to manage invoices.
const STATUS_VALIDATED
Validated (need to be paid)
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...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_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.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
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)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
dolBECalculateStructuredCommunication($invoice_number, $invoice_type)
Calculate Structured Communication / BE Bank payment reference number.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.