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;
130 public $labelStatus = array();
135 public $factures = array();
140 public $methodes_trans = array();
145 public $invoice_in_error = array();
150 public $thirdparty_in_error = array();
162 const STATUS_DRAFT = 0;
163 const STATUS_TRANSFERED = 1;
164 const STATUS_CREDITED = 2;
165 const STATUS_DEBITED = 2;
211 public $fields = array(
212 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'position' => 10,
'notnull' => 1,
'visible' => 0,),
213 'ref' => array(
'type' =>
'varchar(12)',
'label' =>
'Ref',
'enabled' => 1,
'position' => 15,
'notnull' => 0,
'visible' => -1,
'csslist' =>
'tdoverflowmax150',
'showoncombobox' => 1,),
214 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'position' => 25,
'notnull' => 0,
'visible' => -1,),
215 'amount' => array(
'type' =>
'double(24,8)',
'label' =>
'Amount',
'enabled' => 1,
'position' => 30,
'notnull' => 0,
'visible' => -1,),
216 'statut' => array(
'type' =>
'smallint(6)',
'label' =>
'Statut',
'enabled' => 1,
'position' => 500,
'notnull' => 0,
'visible' => -1,
'arrayofkeyval' => array(0 =>
'Wait', 1 =>
'Transfered', 2 =>
'Credited')),
217 'credite' => array(
'type' =>
'smallint(6)',
'label' =>
'Credite',
'enabled' => 1,
'position' => 40,
'notnull' => 0,
'visible' => -1,),
218 'note' => array(
'type' =>
'text',
'label' =>
'Note',
'enabled' => 1,
'position' => 45,
'notnull' => 0,
'visible' => -1,),
219 'date_trans' => array(
'type' =>
'datetime',
'label' =>
'Datetrans',
'enabled' => 1,
'position' => 50,
'notnull' => 0,
'visible' => -1,),
220 'method_trans' => array(
'type' =>
'smallint(6)',
'label' =>
'Methodtrans',
'enabled' => 1,
'position' => 55,
'notnull' => 0,
'visible' => -1,),
221 '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',),
222 'date_credit' => array(
'type' =>
'datetime',
'label' =>
'Datecredit',
'enabled' => 1,
'position' => 65,
'notnull' => 0,
'visible' => -1,),
223 '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',),
224 'type' => array(
'type' =>
'varchar(16)',
'label' =>
'Type',
'enabled' => 1,
'position' => 75,
'notnull' => 0,
'visible' => -1,),
225 'fk_bank_account' => array(
'type' =>
'integer',
'label' =>
'Fkbankaccount',
'enabled' => 1,
'position' => 80,
'notnull' => 0,
'visible' => -1,
'css' =>
'maxwidth500 widthcentpercentminusxx',),
271 public $method_trans;
275 public $fk_user_trans;
283 public $fk_user_credit;
291 public $fk_bank_account;
305 $this->filename =
'';
307 $this->date_echeance =
dol_now();
308 $this->raison_sociale =
"";
309 $this->reference_remise =
"";
311 $this->emetteur_code_guichet =
"";
312 $this->emetteur_numero_compte =
"";
313 $this->emetteur_code_banque =
"";
314 $this->emetteur_number_key =
"";
315 $this->sepa_xml_pti_in_ctti =
false;
317 $this->emetteur_iban =
"";
318 $this->emetteur_bic =
"";
319 $this->emetteur_ics =
"";
321 $this->factures = array();
323 $this->methodes_trans = array(0 =>
'Internet', 2 =>
'Email', 3 =>
'Api');
347 public function AddFacture($invoice_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $type =
'debit-order', $sourcetype =
'', $bic =
'', $iban =
'', $rum =
'')
354 $result = $this->
addline($line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype, $bic, $iban, $rum);
359 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"prelevement (";
360 if ($type !=
'bank-transfer') {
361 $sql .=
"fk_facture";
363 if ($sourcetype ==
'salary') {
366 $sql .=
"fk_facture_fourn";
369 $sql .=
",fk_prelevement_lignes";
370 $sql .=
") VALUES (";
371 $sql .= ((int) $invoice_id);
372 $sql .=
", " . ((int) $line_id);
375 if ($this->db->query($sql)) {
379 $this->errors[] = get_class($this) .
"::AddFacture " . $this->db->lasterror;
380 dol_syslog(get_class($this) .
"::AddFacture Error $result");
384 $this->errors[] = get_class($this) .
"::AddFacture linedid Empty";
385 dol_syslog(get_class($this) .
"::AddFacture Error $result");
389 dol_syslog(get_class($this) .
"::AddFacture Error $result");
412 public function addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype =
'', $bic =
'', $iban =
'', $rum =
'')
421 $sql =
"SELECT rowid";
422 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_lignes";
423 $sql .=
" WHERE fk_prelevement_bons = " . ((int) $this->
id);
424 if ($sourcetype ==
'salary') {
425 $sql .=
" AND fk_soc = " . ((int) $client_id);
427 $sql .=
" AND fk_user = " . ((int) $client_id);
429 $sql .=
" AND code_banque = '" . $this->db->escape($code_banque) .
"'";
430 $sql .=
" AND code_guichet = '" . $this->db->escape($code_guichet) .
"'";
431 $sql .=
" AND number = '" . $this->db->escape($number) .
"'";
433 $resql = $this->db->query($sql);
435 $num = $this->db->num_rows($resql);
443 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"prelevement_lignes (";
444 $sql .=
"fk_prelevement_bons";
446 $sql .=
", client_nom";
451 $sql .= ($sourcetype ==
'salary' ?
", fk_user" :
"");
452 $sql .=
") VALUES (";
454 $sql .=
", " . (($sourcetype !=
'salary') ? ((
int) $client_id) :
"0");
455 $sql .=
", '" . $this->db->escape($client_nom) .
"'";
456 $sql .=
", " . ((float)
price2num($amount));
457 $sql .=
", '" . $this->db->escape($bic) .
"'";
458 $sql .=
", '" . $this->db->escape($iban) .
"'";
459 $sql .=
", '" . $this->db->escape($rum) .
"'";
460 $sql .= (($sourcetype ==
'salary') ?
", " . ((
int) $client_id) :
'');
462 if ($this->db->query($sql)) {
463 $line_id = $this->db->last_insert_id(MAIN_DB_PREFIX .
"prelevement_lignes");
466 $this->errors[] = get_class($this) .
"::addline Error -2 " . $this->db->lasterror;
467 dol_syslog(get_class($this) .
"::addline Error -2");
487 $errors[1027] = $langs->trans(
"DateInvalid");
489 return $errors[abs($error)];
499 public function fetch($rowid, $ref =
'')
501 $sql =
"SELECT p.rowid, p.ref, p.amount, p.note";
502 $sql .=
", p.datec as dc";
503 $sql .=
", p.date_trans as date_trans";
504 $sql .=
", p.method_trans, p.fk_user_trans";
505 $sql .=
", p.date_credit as date_credit";
506 $sql .=
", p.fk_user_credit";
508 $sql .=
", p.fk_bank_account";
509 $sql .=
", p.statut as status";
510 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons as p";
511 $sql .=
" WHERE p.entity IN (" .
getEntity(
'invoice') .
")";
513 $sql .=
" AND p.rowid = " . ((int) $rowid);
515 $sql .=
" AND p.ref = '" . $this->db->escape($ref) .
"'";
518 dol_syslog(get_class($this) .
"::fetch", LOG_DEBUG);
519 $result = $this->db->query($sql);
521 if ($this->db->num_rows($result)) {
522 $obj = $this->db->fetch_object($result);
524 $this->
id = $obj->rowid;
525 $this->
ref = $obj->ref;
526 $this->
amount = $obj->amount;
527 $this->note = $obj->note;
528 $this->datec = $this->db->jdate($obj->dc);
530 $this->date_trans = $this->db->jdate($obj->date_trans);
531 $this->method_trans = $obj->method_trans;
532 $this->user_trans = $obj->fk_user_trans;
534 $this->date_credit = $this->db->jdate($obj->date_credit);
535 $this->user_credit = $obj->fk_user_credit;
537 $this->
type = $obj->type;
538 $this->fk_bank_account = $obj->fk_bank_account;
540 $this->
status = $obj->status;
541 if (empty($this->
status)) {
544 $this->statut = $this->status;
550 dol_syslog(get_class($this) .
"::Fetch no record found");
583 global $conf, $langs;
587 if ($this->fetched == 1) {
588 if ($date < $this->date_trans) {
589 $langs->load(
"errors");
590 $this->error = $langs->trans(
'ErrorDateOfMovementLowerThanDateOfFileTransmission');
591 dol_syslog(
"bon-prelevment::set_infocredit 1027 " . $this->error);
597 $sql =
" UPDATE " . MAIN_DB_PREFIX .
"prelevement_bons";
598 $sql .=
" SET fk_user_credit = " . ((int) $user->id);
599 $sql .=
", statut = " . self::STATUS_CREDITED;
600 $sql .=
", date_credit = '" . $this->db->idate($date) .
"'";
601 $sql .=
" WHERE rowid = " . ((int) $this->
id);
602 $sql .=
" AND entity = " . ((int) $conf->entity);
603 $sql .=
" AND statut = " . self::STATUS_TRANSFERED;
605 $resql = $this->db->query($sql);
607 $langs->load(
'withdrawals');
608 $subject = $langs->trans(
"InfoCreditSubject", $this->
ref);
609 $message = $langs->trans(
"InfoCreditMessage", $this->
ref,
dol_print_date($date,
'dayhour'));
612 $fk_bank_account = $this->fk_bank_account;
613 if (empty($fk_bank_account)) {
618 $amountsperthirdparty = array();
628 for ($i = 0; $i < $num; $i++) {
629 if ($this->
type ==
'bank-transfer') {
630 if ($type ==
'salary') {
631 $fac =
new Salary($this->db);
639 $result = $fac->fetch($facs[$i][0]);
641 $amounts[$fac->id] = $facs[$i][1];
642 if ($this->
type ==
'bank-transfer') {
643 if ($type ==
'salary') {
644 $amountsperthirdparty[$fac->fk_user][$fac->id] = $facs[$i][1];
646 $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
649 $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
652 $totalpaid = $fac->getSommePaiement();
653 $totalcreditnotes = 0;
654 if (method_exists($fac,
'getSumCreditNotesUsed')) {
655 $totalcreditnotes = $fac->getSumCreditNotesUsed();
658 if (method_exists($fac,
'getSumDepositsUsed')) {
659 $totaldeposits = $fac->getSumDepositsUsed();
661 $alreadypayed = $totalpaid + $totalcreditnotes + $totaldeposits;
665 $amountofdocument = $fac->total_ttc;
666 if ($type ==
'salary') {
667 $amountofdocument = $fac->amount;
669 if (
price2num($alreadypayed + $facs[$i][1],
'MT') ==
price2num($amountofdocument,
'MT')) {
670 $result = $fac->setPaid($user);
672 $this->error = $fac->error;
673 $this->errors = $fac->errors;
679 foreach ($amountsperthirdparty as $thirdpartyid => $cursoramounts) {
680 if ($this->
type ==
'bank-transfer') {
681 if ($type ==
'salary') {
687 $paiement =
new Paiement($this->db);
689 $paiement->datepaye = $date;
690 $paiement->amounts = $cursoramounts;
692 if ($this->
type ==
'bank-transfer') {
693 if ($type ==
'salary') {
694 $paiement->datep = $date;
696 $paiement->paiementid = 2;
697 $paiement->fk_typepayment = 2;
698 $paiement->paiementcode =
'VIR';
700 $paiement->paiementid = 2;
701 $paiement->paiementcode =
'VIR';
704 $paiement->paiementid = 3;
705 $paiement->paiementcode =
'PRE';
708 $paiement->num_payment = $this->ref;
709 $paiement->id_prelevement = $this->id;
711 $result = $paiement->create($user, 1);
715 $this->error = $paiement->error;
716 $this->errors = $paiement->errors;
717 dol_syslog(get_class($this) .
"::set_infocredit AddPayment Error " . $this->error);
719 if ($this->
type ==
'bank-transfer') {
720 if ($type ==
'salary') {
721 $modeforaddpayment =
'payment_salary';
722 $labelforaddpayment =
'(SalaryPayment)';
723 $addbankurl =
'credit-transfer';
725 $modeforaddpayment =
'payment_supplier';
726 $labelforaddpayment =
'(SupplierInvoicePayment)';
727 $addbankurl =
'credit-transfer';
730 $modeforaddpayment =
'payment';
731 $labelforaddpayment =
'(CustomerInvoicePayment)';
732 $addbankurl =
'direct-debit';
738 $result = $paiement->addPaymentToBank($user, $modeforaddpayment, $labelforaddpayment, $fk_bank_account,
'',
'');
740 $result = $paiement->addPaymentToBank($user, $modeforaddpayment, $labelforaddpayment, $fk_bank_account,
'',
'', 0,
'', $addbankurl);
745 $this->error = $paiement->error;
746 $this->errors = $paiement->errors;
747 dol_syslog(get_class($this) .
"::set_infocredit AddPaymentToBank Error " . $this->error);
755 $sql =
" UPDATE " . MAIN_DB_PREFIX .
"prelevement_lignes";
756 $sql .=
" SET statut = 2";
757 $sql .=
" WHERE fk_prelevement_bons = " . ((int) $this->
id);
759 if (!$this->db->query($sql)) {
760 dol_syslog(get_class($this) .
"::set_infocredit Update lines Error");
765 $this->error = $this->db->lasterror();
766 dol_syslog(get_class($this) .
"::set_infocredit Update Bons Error");
772 $this->date_credit = $date;
773 $this->statut = self::STATUS_CREDITED;
774 $this->
status = self::STATUS_CREDITED;
779 $this->db->rollback();
799 global $conf, $langs;
803 dol_syslog(get_class($this) .
"::set_infotrans Start", LOG_INFO);
805 if ($this->db->begin()) {
806 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_bons ";
807 $sql .=
" SET fk_user_trans = " . $user->id;
808 $sql .=
" , date_trans = '" . $this->db->idate($date) .
"'";
809 $sql .=
" , method_trans = " . ((int) $method);
810 $sql .=
" , statut = " . self::STATUS_TRANSFERED;
811 $sql .=
" WHERE rowid = " . ((int) $this->
id);
812 $sql .=
" AND entity = " . ((int) $conf->entity);
813 $sql .=
" AND statut = " . self::STATUS_DRAFT;
815 if ($this->db->query($sql)) {
816 $this->method_trans = $method;
817 $langs->load(
'withdrawals');
818 $subject = $langs->trans(
"InfoTransSubject", $this->
ref);
819 $message = $langs->trans(
"InfoTransMessage", $this->
ref,
dolGetFirstLastname($user->firstname, $user->lastname));
820 $message .= $langs->trans(
"InfoTransData",
price($this->
amount), $this->methodes_trans[$this->method_trans],
dol_print_date($date,
'day'));
828 $this->date_trans = $date;
829 $this->statut = self::STATUS_TRANSFERED;
830 $this->
status = self::STATUS_TRANSFERED;
831 $this->user_trans = $user->id;
837 $this->db->rollback();
838 dol_syslog(get_class($this) .
"::set_infotrans ROLLBACK", LOG_ERR);
843 dol_syslog(get_class($this) .
"::set_infotrans Ouverture transaction SQL impossible", LOG_CRIT);
862 dol_syslog(get_class($this) .
"::getListInvoices");
866 if ($this->
type ==
'bank-transfer') {
867 if ($type ==
'salary') {
868 $sql .=
" p.fk_salary";
870 $sql .=
" p.fk_facture_fourn";
873 $sql .=
" p.fk_facture";
876 $sql .=
", SUM(pl.amount)";
878 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons as pb,";
879 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
880 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p";
881 $sql .=
" WHERE p.fk_prelevement_lignes = pl.rowid";
882 $sql .=
" AND pl.fk_prelevement_bons = pb.rowid";
883 $sql .=
" AND pb.rowid = " . ((int) $this->
id);
884 $sql .=
" AND pb.entity = " . ((int) $conf->entity);
886 if ($this->
type ==
'bank-transfer') {
887 if ($type ==
'salary') {
888 $sql .=
" GROUP BY p.fk_salary";
890 $sql .=
" GROUP BY p.fk_facture_fourn";
893 $sql .=
" GROUP BY p.fk_facture";
897 $resql = $this->db->query($sql);
899 $num = $this->db->num_rows($resql);
904 $row = $this->db->fetch_row($resql);
916 $this->db->free($resql);
918 $this->error = $this->db->lasterror();
935 $sql =
"SELECT sum(pd.amount) as nb";
936 if ($type !==
'salary') {
937 if ($mode !=
'bank-transfer') {
938 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f,";
940 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture_fourn as f,";
943 $sql .=
" FROM " . MAIN_DB_PREFIX .
"salary as s,";
945 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_demande as pd";
946 $sql .= ($type !==
'salary' ?
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")" :
" WHERE s.entity IN (" .
getEntity(
'salary') .
")");
948 $sql .= ($type !==
'salary' ?
" AND f.fk_statut = " .
Facture::STATUS_VALIDATED :
" AND s.paye = " . Salary::STATUS_UNPAID);
950 if ($type !==
'salary') {
951 if ($mode !=
'bank-transfer') {
952 $sql .=
" AND f.rowid = pd.fk_facture";
954 $sql .=
" AND f.rowid = pd.fk_facture_fourn";
957 $sql .=
" AND s.rowid = pd.fk_salary";
959 $sql .= ($type !==
'salary' ?
" AND f.paye = 0" :
"");
960 $sql .=
" AND pd.traite = 0";
961 $sql .=
" AND pd.ext_payment_id IS NULL";
962 $sql .= ($type !==
'salary' ?
" AND f.total_ttc > 0" :
"");
964 $resql = $this->db->query($sql);
966 $obj = $this->db->fetch_object($resql);
968 $this->db->free($resql);
973 dol_syslog(get_class($this) .
"::SommeAPrelever Erreur -1");
989 if ($type ===
'salary') {
1007 if ($forsalary == 1) {
1008 $sql =
"SELECT count(s.rowid) as nb";
1009 $sql .=
" FROM " . MAIN_DB_PREFIX .
"salary as s";
1011 $sql =
"SELECT count(f.rowid) as nb";
1013 if ($type ==
'bank-transfer') {
1014 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture_fourn as f";
1016 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
1019 $sql .=
", " . MAIN_DB_PREFIX .
"prelevement_demande as pd";
1020 if ($forsalary == 1) {
1021 $sql .=
" WHERE s.entity IN (" .
getEntity(
'invoice') .
")";
1023 $sql .=
" AND s.paye = 0";
1026 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")";
1031 if ($forsalary == 1) {
1032 $sql .=
" AND s.rowid = pd.fk_salary";
1034 if ($type ==
'bank-transfer') {
1035 $sql .=
" AND f.rowid = pd.fk_facture_fourn";
1037 $sql .=
" AND f.rowid = pd.fk_facture";
1040 $sql .=
" AND pd.traite = 0";
1041 $sql .=
" AND pd.ext_payment_id IS NULL";
1042 if (!$forsalary == 1) {
1043 $sql .=
" AND f.total_ttc > 0";
1045 $sql .=
" AND s.paye = 0";
1048 dol_syslog(get_class($this) .
"::NbFactureAPrelever");
1049 $resql = $this->db->query($sql);
1052 $obj = $this->db->fetch_object($resql);
1053 $this->db->free($resql);
1057 $this->error = get_class($this) .
"::NbFactureAPrelever Erreur -1 sql=" . $this->db->error();
1084 public function create($banque =
'', $agence =
'', $mode =
'real', $format =
'ALL', $executiondate = 0, $notrigger = 0, $type =
'direct-debit', $did = 0, $fk_bank_account = 0, $sourcetype =
'invoice')
1087 global $conf, $langs, $user;
1089 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);
1091 require_once DOL_DOCUMENT_ROOT .
"/compta/facture/class/facture.class.php";
1092 require_once DOL_DOCUMENT_ROOT .
"/societe/class/societe.class.php";
1095 if ($type !=
'bank-transfer') {
1096 if (empty($format)) {
1097 $this->error =
'ErrorBadParametersForDirectDebitFileCreate';
1103 if (empty($fk_bank_account)) {
1104 $fk_bank_account = ($type ==
'bank-transfer' ?
getDolGlobalInt(
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') :
getDolGlobalInt(
'PRELEVEMENT_ID_BANKACCOUNT'));
1109 if ($sourcetype !=
'salary') {
1110 $entities = $type !=
'bank-transfer' ?
getEntity(
'invoice', 1) :
getEntity(
'supplier_invoice', 1);
1111 $sqlTable = $type !=
'bank-transfer' ?
"facture" :
"facture_fourn";
1112 $socOrUser =
'fk_soc';
1113 $societeOrUser =
'societe';
1116 $sqlTable =
'salary';
1117 $socOrUser =
'fk_user';
1118 $societeOrUser =
'user';
1121 $thirdpartyBANId = 0;
1125 $sql =
"SELECT pd.fk_societe_rib";
1126 $sql .=
" FROM " . $this->db->prefix() .
"prelevement_demande as pd";
1127 $sql .=
" WHERE pd.rowid = ".((int) $did);
1129 $resql = $this->db->query($sql);
1132 $this->error = $this->db->lasterror();
1133 dol_syslog(__METHOD__ .
" Read fk_societe_rib error " . $this->db->lasterror(), LOG_ERR);
1137 $obj = $this->db->fetch_object($resql);
1139 $thirdpartyBANId = $obj->fk_societe_rib;
1141 dol_syslog(__METHOD__ .
" Found an BAN ID to use: ".$thirdpartyBANId);
1144 $this->db->free($resql);
1147 $datetimeprev =
dol_now(
'gmt');
1149 if (!empty($executiondate)) {
1150 $datetimeprev = $executiondate;
1156 $this->invoice_in_error = array();
1157 $this->thirdparty_in_error = array();
1160 $factures = array();
1161 $factures_prev = array();
1162 $factures_prev_id = array();
1164 dol_syslog(__METHOD__ .
" Read invoices/salaries for did=" . ((
int) $did), LOG_DEBUG);
1166 $sql =
"SELECT f.rowid, pd.rowid as pfdrowid";
1167 $sql .=
", f.".$this->db->sanitize($socOrUser);
1168 $sql .=
", pd.code_banque, pd.code_guichet, pd.number, pd.cle_rib";
1169 $sql .=
", pd.amount";
1170 if ($sourcetype !=
'salary') {
1171 $sql .=
", s.nom as name";
1173 $sql .=
", sr.bic, sr.iban_prefix, sr.frstrecur, sr.default_rib, sr.rum";
1175 $sql .=
", CONCAT(s.firstname, ' ', s.lastname) as name";
1177 $sql .=
", sr.bic, sr.iban_prefix, 'FRST' as frstrecur, sr.default_rib, '' as rum";
1179 $sql .=
", pd.fk_societe_rib as soc_rib_id";
1180 $sql .=
" FROM " . $this->db->prefix() . $sqlTable .
" as f";
1181 $sql .=
" LEFT JOIN " . $this->db->prefix() .
"prelevement_demande as pd ON f.rowid = pd.fk_".$this->db->sanitize($sqlTable);
1182 $sql .=
" LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($societeOrUser).
" as s ON s.rowid = f.".$this->db->sanitize($socOrUser);
1183 $sql .=
" LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($societeOrUser.
"_rib").
" as sr ON s.rowid = sr.".$this->db->sanitize($socOrUser);
1184 if ($sourcetype !=
'salary') {
1185 if (!empty($thirdpartyBANId)) {
1186 $sql .=
" AND sr.rowid = " . ((int) $thirdpartyBANId);
1188 $sql .=
" AND sr.default_rib = 1";
1190 $sql .=
" AND sr.type = 'ban'";
1198 $sql .=
" WHERE f.entity IN (".$this->db->escape($entities).
')';
1199 if ($sourcetype !=
'salary') {
1200 $sql .=
" AND f.fk_statut = ".Facture::STATUS_VALIDATED;
1201 $sql .=
" AND f.paye = 0";
1202 $sql .=
" AND f.total_ttc > 0";
1208 $sql .=
" AND f.paye = 0";
1209 $sql .=
" AND f.amount > 0";
1211 $sql .=
" AND pd.traite = 0";
1212 $sql .=
" AND pd.ext_payment_id IS NULL";
1214 $sql .=
" AND pd.rowid = " . ((int) $did);
1217 $resql = $this->db->query($sql);
1219 $num = $this->db->num_rows($resql);
1223 $row = $this->db->fetch_row($resql);
1224 '@phan-var-force array<int<0,12>,string> $row';
1230 $factures[$i] = $row;
1233 $factures[$i][11] =
dolDecrypt($factures[$i][11]);
1237 dol_syslog(__METHOD__ .
" Read invoices/salaries error Found a null amount", LOG_WARNING);
1238 $this->invoice_in_error[$row[0]] =
"Error for invoice or salary id " . $row[0] .
", found a null amount";
1244 $this->db->free($resql);
1245 dol_syslog(__METHOD__ .
" Read invoices/salaries, " . $i .
" invoices/salaries to withdraw", LOG_DEBUG);
1247 $this->error = $this->db->lasterror();
1248 dol_syslog(__METHOD__ .
" Read invoices/salaries error " . $this->db->lasterror(), LOG_ERR);
1254 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1255 require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
1256 require_once DOL_DOCUMENT_ROOT .
'/societe/class/companybankaccount.class.php';
1257 require_once DOL_DOCUMENT_ROOT .
'/core/lib/bank.lib.php';
1259 $tmpsoc =
new Societe($this->db);
1260 $tmpuser =
new User($this->db);
1264 dol_syslog(__METHOD__ .
" Check BAN for each invoices or salaries", LOG_DEBUG);
1266 if (count($factures) > 0) {
1267 foreach ($factures as $key => $fac) {
1269 if ($fac[8] !=
null) {
1270 if ($type !=
'bank-transfer') {
1271 if ($format ==
'FRST' && $fac[12] !=
'FRST') {
1274 if ($format ==
'RCUR' && $fac[12] !=
'RCUR') {
1281 if (!empty($fac[14])) {
1283 $bankaccount->fetch((
int) $fac[15]);
1284 if ($bankaccount->id > 0) {
1285 $fac[3] = $bankaccount->code_banque;
1286 $fac[4] = $bankaccount->code_guichet;
1287 $fac[5] = $bankaccount->number;
1288 $fac[6] = $bankaccount->cle_rib;
1289 $fac[10] = $bankaccount->bic;
1290 $fac[11] = $bankaccount->iban;
1291 $fac[14] = $bankaccount->rum;
1296 $bicinloop = $fac[10];
1297 $baninloop = $fac[11];
1300 if ($verif || (empty($fac[10]) &&
getDolGlobalInt(
"WITHDRAWAL_WITHOUT_BIC"))) {
1301 dol_syslog(__METHOD__.
" now call checkIbanForAccount(null, ".$baninloop.
")");
1306 $factures_prev[$i] = $fac;
1308 $factures_prev_id[$i] = $fac[0];
1312 if ($type !=
'bank-transfer') {
1313 $tmpsoc->id = (int) $fac[2];
1314 $tmpsoc->name = $fac[8];
1315 $invoice_url =
"<a href='" . DOL_URL_ROOT .
'/compta/facture/card.php?facid=' . $fac[0] .
"'>" . $fac[9] .
"</a>";
1316 $this->invoice_in_error[$fac[0]] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1317 $this->thirdparty_in_error[$tmpsoc->id] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1320 if ($type ==
'bank-transfer' && $sourcetype !=
'salary') {
1321 $tmpsoc->id = (int) $fac[2];
1322 $tmpsoc->name = $fac[8];
1323 $invoice_url =
"<a href='" . DOL_URL_ROOT .
'/fourn/facture/card.php?facid=' . $fac[0] .
"'>" . $fac[9] .
"</a>";
1324 $this->invoice_in_error[$fac[0]] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1325 $this->thirdparty_in_error[$tmpsoc->id] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1328 if ($type ==
'bank-transfer' && $sourcetype ==
'salary') {
1329 $tmpuser->id = (int) $fac[2];
1330 $tmpuser->firstname = $fac[8];
1331 $salary_url =
"<a href='" . DOL_URL_ROOT .
'/salaries/card.php?id=' . $fac[0] .
"'>" . $fac[0] .
"</a>";
1332 $this->invoice_in_error[$fac[0]] =
"Error on default bank number IBAN/BIC for salary " . $salary_url .
" for employee " . $tmpuser->getNomUrl(0);
1333 $this->thirdparty_in_error[$tmpuser->id] =
"Error on default bank number IBAN/BIC for salary " . $salary_url .
" for employee " . $tmpuser->getNomUrl(0);
1336 dol_syslog(__METHOD__ .
" Check BAN Error on default bank number IBAN/BIC reported by verif(): " . implode(
', ', $fac), LOG_WARNING);
1339 dol_syslog(__METHOD__ .
" Check BAN Failed to read company", LOG_WARNING);
1348 dol_syslog(__METHOD__ .
" Check BAN No invoice to process", LOG_WARNING);
1355 $out = count($factures_prev) .
" invoices or salaries will be included.";
1368 if (count($factures_prev) > 0) {
1369 if ($mode ==
'real') {
1372 print $langs->trans(
"ModeWarning");
1389 $ref = substr($year, -2) . $month;
1394 $sql =
"SELECT SUBSTRING(ref, 6) AS refnumber";
1395 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons";
1396 $sql .=
" WHERE ref LIKE '" . $this->db->escape($prefixt . $ref) .
"%'";
1397 $sql .=
" AND entity = " . ((int) $conf->entity);
1398 $sql .=
" ORDER BY LENGTH(ref) DESC, ref DESC";
1401 dol_syslog(get_class($this) .
" get next free number", LOG_DEBUG);
1403 $resql = $this->db->query($sql);
1406 $row = $this->db->fetch_row($resql);
1409 $ref = $prefixt . $ref . sprintf(
"%03d", (intval($row[0]) + 1));
1415 if ($type !=
'bank-transfer') {
1416 $dir = $conf->prelevement->dir_output .
'/receipts';
1418 $dir = $conf->paymentbybanktransfer->dir_output .
'/receipts';
1420 if (!is_dir($dir)) {
1425 $labelentity = $conf->entity;
1426 $this->filename = $dir .
'/' . $ref .
'-' . $labelentity .
'.xml';
1428 $this->filename = $dir .
'/' . $ref .
'.xml';
1432 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"prelevement_bons (";
1433 $sql .=
"ref, entity, datec, type, fk_bank_account";
1434 $sql .=
") VALUES (";
1435 $sql .=
"'" . $this->db->escape($ref) .
"'";
1436 $sql .=
", " . ((int) $conf->entity);
1437 $sql .=
", '" . $this->db->idate($now) .
"'";
1438 $sql .=
", '" . ($type ==
'bank-transfer' ?
'bank-transfer' :
'debit-order') .
"'";
1439 $sql .=
", " . ((int) $fk_bank_account);
1442 $resql = $this->db->query($sql);
1445 $prev_id = $this->db->last_insert_id(MAIN_DB_PREFIX .
"prelevement_bons");
1446 $this->
id = $prev_id;
1450 $this->errors[] = $this->db->lasterror();
1451 dol_syslog(__METHOD__ .
" Create withdraw receipt " . $this->db->lasterror(), LOG_ERR);
1455 $this->errors[] = $this->db->lasterror();
1456 dol_syslog(__METHOD__ .
" Get last withdraw receipt " . $this->db->lasterror(), LOG_ERR);
1461 dol_syslog(__METHOD__ .
" Now loop on each document to insert them in llx_prelevement_demande");
1464 if (count($factures_prev) > 0) {
1465 foreach ($factures_prev as $fac) {
1507 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_demande";
1508 $sql .=
" SET traite = 1";
1509 $sql .=
", date_traite = '" . $this->db->idate($now) .
"'";
1510 $sql .=
", fk_prelevement_bons = " . ((int) $this->
id);
1511 $sql .=
" WHERE rowid = " . ((int) $fac[1]);
1513 $resql = $this->db->query($sql);
1516 $this->errors[] = $this->db->lasterror();
1517 dol_syslog(__METHOD__ .
" Update Error=" . $this->db->lasterror(), LOG_ERR);
1528 dol_syslog(__METHOD__ .
" Init direct debit or credit transfer file for " . count($factures_prev) .
" invoices", LOG_DEBUG);
1530 if (count($factures_prev) > 0) {
1531 $this->date_echeance = $datetimeprev;
1532 $this->reference_remise = $ref;
1534 $account =
new Account($this->db);
1535 if ($account->fetch($fk_bank_account) > 0) {
1536 $this->emetteur_code_banque = $account->code_banque;
1537 $this->emetteur_code_guichet = $account->code_guichet;
1538 $this->emetteur_numero_compte = $account->number;
1539 $this->emetteur_number_key = $account->cle_rib;
1540 $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
1541 $this->emetteur_iban = $account->iban;
1542 $this->emetteur_bic = $account->bic;
1544 $this->emetteur_ics = (($type ==
'bank-transfer' &&
getDolGlobalString(
"SEPA_USE_IDS")) ? $account->ics_transfer : $account->ics);
1546 $this->raison_sociale = $account->owner_name;
1548 $this->factures = $factures_prev_id;
1549 $this->context[
'factures_prev'] = $factures_prev;
1553 if ($sourcetype ==
'salary') {
1554 $userid = $this->context[
'factures_prev'][0][2];
1556 $result = $this->
generate($format, $executiondate, $type, $fk_bank_account, $userid, (
int) $thirdpartyBANId);
1563 dol_syslog(__METHOD__ .
" Bank order file has been generated under filename " . $this->filename, LOG_DEBUG);
1571 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_bons";
1572 $sql .=
" SET amount = " .
price2num($this->total);
1573 $sql .=
" WHERE rowid = " . ((int) $this->
id);
1574 $sql .=
" AND entity = " . ((int) $conf->entity);
1575 $resql = $this->db->query($sql);
1579 dol_syslog(__METHOD__ .
" Error update total: " . $this->db->error(), LOG_ERR);
1583 if (!$error && !$notrigger) {
1584 $triggerName = ($type ==
'bank-transfer') ?
'CREDIT_TRANSFER_ORDER_CREATE' :
'DIRECT_DEBIT_ORDER_CREATE';
1585 $this->
amount = $this->total;
1588 $result = $this->call_trigger($triggerName, $user);
1596 $this->db->commit();
1597 return count($factures_prev);
1599 $this->db->rollback();
1615 public function delete($user, $notrigger = 0)
1620 $resql1 = $resql2 = $resql3 = $resql4 = 0;
1623 $triggername =
'DIRECT_DEBIT_ORDER_DELETE';
1624 if ($this->
type ==
'bank-transfer') {
1625 $triggername =
'PAYMENTBYBANKTRANFER_DELETE';
1628 $result = $this->call_trigger($triggername, $user);
1636 $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) .
")";
1637 $resql1 = $this->db->query($sql);
1644 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"prelevement_lignes WHERE fk_prelevement_bons = " . ((int) $this->
id);
1645 $resql2 = $this->db->query($sql);
1652 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"prelevement_bons WHERE rowid = " . ((int) $this->
id);
1653 $resql3 = $this->db->query($sql);
1660 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_demande SET fk_prelevement_bons = NULL, traite = 0 WHERE fk_prelevement_bons = " . ((int) $this->
id);
1661 $resql4 = $this->db->query($sql);
1667 if ($resql1 && $resql2 && $resql3 && $resql4 && !$error) {
1668 $this->db->commit();
1671 $this->db->rollback();
1687 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1689 global $conf, $langs, $hookmanager;
1691 if (!empty($conf->dol_no_mouse_hover)) {
1697 $labeltoshow =
'PaymentByDirectDebit';
1698 if (!empty($this->
type) && $this->
type ==
'bank-transfer') {
1699 $labeltoshow =
'PaymentByBankTransfer';
1702 $label =
img_picto(
'', $this->picto) .
' <u>' . $langs->trans($labeltoshow) .
'</u> ' . $this->
getLibStatut(5);
1704 $label .=
'<b>' . $langs->trans(
'Ref') .
':</b> ' . $this->ref;
1705 if (isset($this->
amount)) {
1706 $label .=
'<br><b>' . $langs->trans(
"Amount") .
":</b> " .
price($this->
amount);
1708 if (isset($this->date_trans)) {
1709 $label .=
'<br><b>' . $langs->trans(
"TransData") .
":</b> " .
dol_print_date($this->date_trans,
'dayhour',
'tzuserrel');
1715 $url = DOL_URL_ROOT .
'/compta/prelevement/card.php?id=' . $this->id;
1716 if (!empty($this->
type) && $this->
type ==
'bank-transfer') {
1717 $url = DOL_URL_ROOT .
'/compta/prelevement/card.php?id=' . $this->id;
1720 if ($option !=
'nolink') {
1722 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1723 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1724 $add_save_lastsearch_values = 1;
1726 if ($add_save_lastsearch_values) {
1727 $url .=
'&save_lastsearch_values=1';
1732 if (empty($notooltip)) {
1734 $label = $langs->trans(
"ShowMyObject");
1738 $linkclose .=
' class="classfortooltip' . ($morecss ?
' ' . $morecss :
'') .
'"';
1740 $linkclose = ($morecss ?
' class="' . $morecss .
'"' :
'');
1743 $linkstart =
'<a href="' . $url .
'"';
1744 $linkstart .= $linkclose .
'>';
1747 $result .= $linkstart;
1749 $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);
1751 if ($withpicto != 2) {
1752 $result .= $this->ref;
1754 $result .= $linkend;
1756 global $action, $hookmanager;
1757 $hookmanager->initHooks(array(
'banktransferdao'));
1758 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1759 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1761 $result = $hookmanager->resPrint;
1763 $result .= $hookmanager->resPrint;
1778 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"notify_def";
1779 $sql .=
" WHERE rowid = " . ((int) $rowid);
1781 if ($this->db->query($sql)) {
1797 if (is_object($user)) {
1798 $userid = $user->id;
1803 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"notify_def";
1804 $sql .=
" WHERE fk_user = " . ((int) $userid) .
" AND fk_action = " . ((int) $action);
1806 if ($this->db->query($sql)) {
1827 if (is_object($user)) {
1828 $userid = $user->id;
1836 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"notify_def (datec, fk_user, fk_soc, fk_contact, fk_action)";
1837 $sql .=
" VALUES ('" . $this->db->idate($now) .
"', " . ((int) $userid) .
", NULL, NULL, " . ((int) $action) .
")";
1840 if ($this->db->query($sql)) {
1844 dol_syslog(get_class($this) .
"::addNotification Error $result");
1867 public function generate(
string $format =
'ALL',
int $executiondate = 0,
string $type =
'direct-debit',
int $fk_bank_account = 0,
int $forsalary = 0,
int $thirdpartyBANId = 0)
1869 global $conf, $langs,
$mysoc;
1874 if (empty($fk_bank_account)) {
1875 $fk_bank_account = ($type ==
'bank-transfer' ?
getDolGlobalInt(
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') :
getDolGlobalInt(
'PRELEVEMENT_ID_BANKACCOUNT'));
1880 dol_syslog(get_class($this) .
"::generate build file=" . $this->filename .
" type=" . $type);
1882 $this->file = fopen($this->filename,
"w");
1883 if ($this->file ==
false) {
1884 $this->error = $langs->trans(
'ErrorFailedToOpenFile', $this->filename);
1892 if (
$mysoc->isInSEPA()) {
1895 if ($type !=
'bank-transfer') {
1907 if (!empty($executiondate)) {
1908 $date_actu = $executiondate;
1913 $fileDebiteurSection =
'';
1914 $fileEmetteurSection =
'';
1921 $sql =
"SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
1922 $sql .=
" pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
1923 $sql .=
" f.ref as reffac, p.fk_facture as idfac,";
1924 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
1926 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
1927 $sql .=
" " . MAIN_DB_PREFIX .
"facture as f,";
1928 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p,";
1929 $sql .=
" " . MAIN_DB_PREFIX .
"societe as soc,";
1930 $sql .=
" " . MAIN_DB_PREFIX .
"c_country as c,";
1931 $sql .=
" " . MAIN_DB_PREFIX .
"societe_rib as rib";
1932 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
1933 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
1934 $sql .=
" AND p.fk_facture = f.rowid";
1935 $sql .=
" AND f.fk_soc = soc.rowid";
1936 $sql .=
" AND soc.fk_pays = c.rowid";
1937 $sql .=
" AND rib.fk_soc = f.fk_soc";
1938 if (!empty($thirdpartyBANId)) {
1939 $sql .=
" AND rib.rowid = " . ((int) $thirdpartyBANId);
1941 $sql .=
" AND rib.default_rib = 1";
1943 $sql .=
" AND rib.type = 'ban'";
1946 $resql = $this->db->query($sql);
1947 $nbtotalDrctDbtTxInf = -1;
1949 $cachearraytotestduplicate = array();
1951 $num = $this->db->num_rows($resql);
1953 $obj = $this->db->fetch_object($resql);
1955 if (!empty($cachearraytotestduplicate[$obj->idfac])) {
1956 $this->error = $langs->trans(
'ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
1957 $this->invoice_in_error[$obj->idfac] = $this->error;
1961 $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
1963 $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
1966 $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);
1968 $this->total += $obj->somme;
1971 $nbtotalDrctDbtTxInf = $i;
1973 $this->error = $this->db->lasterror();
1974 fwrite($this->file,
'ERROR DEBITOR ' . $sql . $CrLf);
1979 if ($result != -2) {
1980 $fileEmetteurSection .= $this->
EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type, $fk_bank_account);
1984 $this->total = number_format((
float)
price2num($this->total,
'MT'), 2,
".",
"");
1991 fwrite($this->file,
'<' .
'?xml version="1.0" encoding="UTF-8" standalone="yes"?' .
'>' . $CrLf);
1992 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);
1993 fwrite($this->file,
' <CstmrDrctDbtInitn>' . $CrLf);
1995 fwrite($this->file,
' <GrpHdr>' . $CrLf);
1996 fwrite($this->file,
' <MsgId>' . (
'DOL/' . $dateTime_YMD .
'/DD' . $this->
id) .
'</MsgId>' . $CrLf);
1997 fwrite($this->file,
' <CreDtTm>' . $dateTime_ECMA .
'</CreDtTm>' . $CrLf);
1998 fwrite($this->file,
' <NbOfTxs>' . $i .
'</NbOfTxs>' . $CrLf);
1999 fwrite($this->file,
' <CtrlSum>' . $this->total .
'</CtrlSum>' . $CrLf);
2000 fwrite($this->file,
' <InitgPty>' . $CrLf);
2002 fwrite($this->file,
' <Id>' . $CrLf);
2003 fwrite($this->file,
' <PrvtId>' . $CrLf);
2004 fwrite($this->file,
' <Othr>' . $CrLf);
2005 fwrite($this->file,
' <Id>' . $this->emetteur_ics .
'</Id>' . $CrLf);
2006 fwrite($this->file,
' </Othr>' . $CrLf);
2007 fwrite($this->file,
' </PrvtId>' . $CrLf);
2008 fwrite($this->file,
' </Id>' . $CrLf);
2009 fwrite($this->file,
' </InitgPty>' . $CrLf);
2010 fwrite($this->file,
' </GrpHdr>' . $CrLf);
2012 if ($result != -2) {
2013 fwrite($this->file, $fileEmetteurSection);
2016 if ($result != -2) {
2017 fwrite($this->file, $fileDebiteurSection);
2020 fwrite($this->file,
' </PmtInf>' . $CrLf);
2021 fwrite($this->file,
' </CstmrDrctDbtInitn>' . $CrLf);
2022 fwrite($this->file,
'</Document>' . $CrLf);
2035 if (!empty($executiondate)) {
2036 $date_actu = $executiondate;
2041 $fileCrediteurSection =
'';
2042 $fileEmetteurSection =
'';
2048 if (!empty($forsalary)) {
2049 $sql =
"SELECT u.rowid as userId, u.address, u.zip, u.town, c.code as country_code, CONCAT(u.firstname,' ',u.lastname) as nom,";
2050 $sql .=
" pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
2051 $sql .=
" s.ref as reffac, p.fk_salary as idfac,";
2052 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, '' as rum, '' as date_rum";
2054 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
2055 $sql .=
" " . MAIN_DB_PREFIX .
"salary as s,";
2056 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p,";
2057 $sql .=
" " . MAIN_DB_PREFIX .
"user as u";
2058 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"c_country as c ON u.fk_country = c.rowid,";
2059 $sql .=
" " . MAIN_DB_PREFIX .
"user_rib as rib";
2060 $sql .=
" WHERE pl.fk_prelevement_bons=" . ((int) $this->
id);
2061 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
2062 $sql .=
" AND p.fk_salary = s.rowid";
2063 $sql .=
" AND s.fk_user = u.rowid";
2064 $sql .=
" AND rib.fk_user = s.fk_user";
2066 $sql =
"SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
2067 $sql .=
" pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
2068 $sql .=
" f.ref as reffac, f.ref_supplier as fac_ref_supplier, p.fk_facture_fourn as idfac,";
2069 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
2071 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
2072 $sql .=
" " . MAIN_DB_PREFIX .
"facture_fourn as f,";
2073 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p,";
2074 $sql .=
" " . MAIN_DB_PREFIX .
"societe as soc";
2075 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"c_country as c ON soc.fk_pays = c.rowid,";
2076 $sql .=
" " . MAIN_DB_PREFIX .
"societe_rib as rib";
2077 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
2078 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
2079 $sql .=
" AND p.fk_facture_fourn = f.rowid";
2080 $sql .=
" AND f.fk_soc = soc.rowid";
2081 $sql .=
" AND rib.fk_soc = f.fk_soc";
2082 if (!empty($thirdpartyBANId)) {
2083 $sql .=
" AND rib.rowid = " . ((int) $thirdpartyBANId);
2085 $sql .=
" AND rib.default_rib = 1";
2087 $sql .=
" AND rib.type = 'ban'";
2090 $nbtotalDrctDbtTxInf = -1;
2092 $resql = $this->db->query($sql);
2094 $cachearraytotestduplicate = array();
2096 $num = $this->db->num_rows($resql);
2098 $obj = $this->db->fetch_object($resql);
2099 if (!empty($cachearraytotestduplicate[$obj->idfac])) {
2100 $this->error = $langs->trans(
'ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
2101 $this->invoice_in_error[$obj->idfac] = $this->error;
2105 $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
2107 $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
2109 $refobj = $obj->reffac;
2110 if (empty($refobj) && !empty($forsalary)) {
2111 $refobj =
"SAL" . $obj->idfac;
2114 $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);
2116 $this->total += $obj->somme;
2119 $nbtotalDrctDbtTxInf = $i;
2121 $this->error = $this->db->lasterror();
2122 fwrite($this->file,
'ERROR CREDITOR ' . $sql . $CrLf);
2126 if ($result != -2) {
2127 $fileEmetteurSection .= $this->
EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type);
2131 $this->total = number_format((
float)
price2num($this->total,
'MT'), 2,
".",
"");
2138 fwrite($this->file,
'<' .
'?xml version="1.0" encoding="UTF-8" standalone="yes"?' .
'>' . $CrLf);
2139 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);
2140 fwrite($this->file,
' <CstmrCdtTrfInitn>' . $CrLf);
2142 fwrite($this->file,
' <GrpHdr>' . $CrLf);
2143 fwrite($this->file,
' <MsgId>' . (
'DOL/' . $dateTime_YMD .
'/CT' . $this->
id) .
'</MsgId>' . $CrLf);
2144 fwrite($this->file,
' <CreDtTm>' . $dateTime_ECMA .
'</CreDtTm>' . $CrLf);
2145 fwrite($this->file,
' <NbOfTxs>' . $i .
'</NbOfTxs>' . $CrLf);
2146 fwrite($this->file,
' <CtrlSum>' . $this->total .
'</CtrlSum>' . $CrLf);
2147 fwrite($this->file,
' <InitgPty>' . $CrLf);
2149 fwrite($this->file,
' <Id>' . $CrLf);
2150 fwrite($this->file,
' <PrvtId>' . $CrLf);
2151 fwrite($this->file,
' <Othr>' . $CrLf);
2152 fwrite($this->file,
' <Id>' . $this->emetteur_ics .
'</Id>' . $CrLf);
2153 fwrite($this->file,
' </Othr>' . $CrLf);
2154 fwrite($this->file,
' </PrvtId>' . $CrLf);
2155 fwrite($this->file,
' </Id>' . $CrLf);
2156 fwrite($this->file,
' </InitgPty>' . $CrLf);
2157 fwrite($this->file,
' </GrpHdr>' . $CrLf);
2159 if ($result != -2) {
2160 fwrite($this->file, $fileEmetteurSection);
2163 if ($result != -2) {
2164 fwrite($this->file, $fileCrediteurSection);
2167 fwrite($this->file,
' </PmtInf>' . $CrLf);
2168 fwrite($this->file,
' </CstmrCdtTrfInitn>' . $CrLf);
2169 fwrite($this->file,
'</Document>' . $CrLf);
2175 if ($type !=
'bank-transfer') {
2176 $sql =
"SELECT pl.amount";
2178 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
2179 $sql .=
" " . MAIN_DB_PREFIX .
"facture as f,";
2180 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p";
2181 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
2182 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
2183 $sql .=
" AND p.fk_facture = f.rowid";
2187 $resql = $this->db->query($sql);
2189 $num = $this->db->num_rows($resql);
2192 $obj = $this->db->fetch_object($resql);
2193 $this->total += $obj->amount;
2202 $sql =
"SELECT pl.amount";
2204 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
2205 $sql .=
" " . MAIN_DB_PREFIX .
"facture_fourn as f,";
2206 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p";
2207 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
2208 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
2209 $sql .=
" AND p.fk_facture_fourn = f.rowid";
2212 $resql = $this->db->query($sql);
2214 $num = $this->db->num_rows($resql);
2217 $obj = $this->db->fetch_object($resql);
2218 $this->total += $obj->amount;
2228 $langs->load(
'withdrawals');
2231 fwrite($this->file, $langs->transnoentitiesnoconv(
'WithdrawalFileNotCapable',
$mysoc->country_code));
2234 fclose($this->file);
2256 return $pre .
'-' .
dol_print_date($row_datec,
'dayhourlogsmall') .
'-' .
dol_trunc($row_drum . ($row_code_client ?
'-' . $row_code_client :
''), 17,
'right',
'UTF-8', 1);
2277 public function EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $ref, $facid, $rib_dom =
'', $type =
'direct-debit')
2280 fwrite($this->file,
"06");
2281 fwrite($this->file,
"08");
2283 fwrite($this->file,
" ");
2285 fwrite($this->file, $this->emetteur_ics);
2289 fwrite($this->file,
" ");
2290 fwrite($this->file,
dol_print_date($this->date_echeance,
"%d%m",
'gmt'));
2291 fwrite($this->file, substr(
dol_print_date($this->date_echeance,
"%y",
'gmt'), 1));
2295 fwrite($this->file, substr(strtoupper($client_nom) .
" ", 0, 24));
2298 $address = strtr($rib_dom, array(
" " =>
"-", chr(13) =>
" ", chr(10) =>
""));
2299 fwrite($this->file, substr($address .
" ", 0, 24));
2303 fwrite($this->file, substr(
" ", 0, 8));
2307 fwrite($this->file, $rib_guichet);
2311 fwrite($this->file, substr(
"000000000000000" . $rib_number, -11));
2315 $montant = (round($amount, 2) * 100);
2317 fwrite($this->file, substr(
"000000000000000" . $montant, -16));
2321 fwrite($this->file, substr(
"*_" . $ref .
"_RDVnet" . $rowid .
" ", 0, 31));
2325 fwrite($this->file, $rib_banque);
2329 fwrite($this->file, substr(
" ", 0, 5));
2331 fwrite($this->file,
"\n");
2361 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 =
'')
2367 $row_somme = number_format((
float)
price2num($row_somme,
'MT'), 2,
".",
"");
2369 $row_somme = round((
float) $row_somme, 2);
2372 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
2375 $Rowing = sprintf(
"%010d", $row_idfac);
2379 $Rum = (empty($row_rum) ? $this->
buildRumNumber($row_code_client, $row_datec, $row_drum) : $row_rum);
2384 if ($type !=
'bank-transfer') {
2387 $XML_DEBITOR .=
' <DrctDbtTxInf>' . $CrLf;
2388 $XML_DEBITOR .=
' <PmtId>' . $CrLf;
2390 $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;
2391 $XML_DEBITOR .=
' </PmtId>' . $CrLf;
2392 $XML_DEBITOR .=
' <InstdAmt Ccy="EUR">' . $row_somme .
'</InstdAmt>' . $CrLf;
2393 $XML_DEBITOR .=
' <DrctDbtTx>' . $CrLf;
2394 $XML_DEBITOR .=
' <MndtRltdInf>' . $CrLf;
2395 $XML_DEBITOR .=
' <MndtId>' . $Rum .
'</MndtId>' . $CrLf;
2396 $XML_DEBITOR .=
' <DtOfSgntr>' . $DtOfSgntr .
'</DtOfSgntr>' . $CrLf;
2397 $XML_DEBITOR .=
' <AmdmntInd>false</AmdmntInd>' . $CrLf;
2398 $XML_DEBITOR .=
' </MndtRltdInf>' . $CrLf;
2399 $XML_DEBITOR .=
' </DrctDbtTx>' . $CrLf;
2400 $XML_DEBITOR .=
' <DbtrAgt>' . $CrLf;
2401 $XML_DEBITOR .=
' <FinInstnId>' . $CrLf;
2403 $XML_DEBITOR .=
' <BIC>' . $row_bic .
'</BIC>' . $CrLf;
2405 $XML_DEBITOR .=
' </FinInstnId>' . $CrLf;
2406 $XML_DEBITOR .=
' </DbtrAgt>' . $CrLf;
2407 $XML_DEBITOR .=
' <Dbtr>' . $CrLf;
2409 $XML_DEBITOR .=
' <PstlAdr>' . $CrLf;
2410 $XML_DEBITOR .=
' <Ctry>' . $row_country_code .
'</Ctry>' . $CrLf;
2411 $addressline1 = strtr($row_address, array(chr(13) =>
", ", chr(10) =>
""));
2412 $addressline2 = strtr($row_zip . (($row_zip && $row_town) ?
' ' :
'') . (
string) $row_town, array(chr(13) =>
", ", chr(10) =>
""));
2413 if (trim($addressline1)) {
2416 if (trim($addressline2)) {
2419 $XML_DEBITOR .=
' </PstlAdr>' . $CrLf;
2420 $XML_DEBITOR .=
' </Dbtr>' . $CrLf;
2421 $XML_DEBITOR .=
' <DbtrAcct>' . $CrLf;
2422 $XML_DEBITOR .=
' <Id>' . $CrLf;
2423 $XML_DEBITOR .=
' <IBAN>' . preg_replace(
'/\s/',
'', $row_iban) .
'</IBAN>' . $CrLf;
2424 $XML_DEBITOR .=
' </Id>' . $CrLf;
2425 $XML_DEBITOR .=
' </DbtrAcct>' . $CrLf;
2426 $XML_DEBITOR .=
' <RmtInf>' . $CrLf;
2430 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
2432 $invoicestatic =
new Facture($this->db);
2433 $invoicestatic->fetch($row_idfac);
2436 $XML_DEBITOR .=
' <strd>' . $invoicePaymentKey .
'</strd>' . $CrLf;
2441 $XML_DEBITOR .=
' </RmtInf>' . $CrLf;
2442 $XML_DEBITOR .=
' </DrctDbtTxInf>' . $CrLf;
2443 return $XML_DEBITOR;
2447 $XML_CREDITOR .=
' <CdtTrfTxInf>' . $CrLf;
2448 $XML_CREDITOR .=
' <PmtId>' . $CrLf;
2450 $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;
2451 $XML_CREDITOR .=
' </PmtId>' . $CrLf;
2452 if (!empty($this->sepa_xml_pti_in_ctti)) {
2453 $XML_CREDITOR .=
' <PmtTpInf>' . $CrLf;
2457 $instrprty =
'HIGH';
2459 $instrprty =
'NORM';
2463 $categoryPurpose =
getDolGlobalString(
'PAYMENTBYBANKTRANSFER_CUSTOM_CATEGORY_PURPOSE',
'CORE');
2465 $XML_CREDITOR .=
' <InstrPrty>' . $instrprty .
'</InstrPrty>' . $CrLf;
2466 $XML_CREDITOR .=
' <SvcLvl>' . $CrLf;
2467 $XML_CREDITOR .=
' <Cd>SEPA</Cd>' . $CrLf;
2468 $XML_CREDITOR .=
' </SvcLvl>' . $CrLf;
2469 $XML_CREDITOR .=
' <CtgyPurp>' . $CrLf;
2470 $XML_CREDITOR .=
' <Cd>' . $categoryPurpose .
'</Cd>' . $CrLf;
2471 $XML_CREDITOR .=
' </CtgyPurp>' . $CrLf;
2472 $XML_CREDITOR .=
' </PmtTpInf>' . $CrLf;
2474 $XML_CREDITOR .=
' <Amt>' . $CrLf;
2475 $XML_CREDITOR .=
' <InstdAmt Ccy="EUR">'.round((
float) $row_somme, 2).
'</InstdAmt>'.$CrLf;
2476 $XML_CREDITOR .=
' </Amt>' . $CrLf;
2487 $XML_CREDITOR .=
' <CdtrAgt>' . $CrLf;
2488 $XML_CREDITOR .=
' <FinInstnId>' . $CrLf;
2489 $XML_CREDITOR .=
' <BIC>' . $row_bic .
'</BIC>' . $CrLf;
2490 $XML_CREDITOR .=
' </FinInstnId>' . $CrLf;
2491 $XML_CREDITOR .=
' </CdtrAgt>' . $CrLf;
2492 $XML_CREDITOR .=
' <Cdtr>' . $CrLf;
2494 $XML_CREDITOR .=
' <PstlAdr>' . $CrLf;
2495 $XML_CREDITOR .=
' <Ctry>' . $row_country_code .
'</Ctry>' . $CrLf;
2496 $addressline1 = strtr($row_address, array(chr(13) =>
", ", chr(10) =>
""));
2497 $addressline2 = strtr($row_zip . (($row_zip && $row_town) ?
' ' :
'') . (
string) $row_town, array(chr(13) =>
", ", chr(10) =>
""));
2498 if (trim($addressline1)) {
2501 if (trim($addressline2)) {
2504 $XML_CREDITOR .=
' </PstlAdr>' . $CrLf;
2505 $XML_CREDITOR .=
' </Cdtr>' . $CrLf;
2506 $XML_CREDITOR .=
' <CdtrAcct>' . $CrLf;
2507 $XML_CREDITOR .=
' <Id>' . $CrLf;
2508 $XML_CREDITOR .=
' <IBAN>' . preg_replace(
'/\s/',
'', $row_iban) .
'</IBAN>' . $CrLf;
2509 $XML_CREDITOR .=
' </Id>' . $CrLf;
2510 $XML_CREDITOR .=
' </CdtrAcct>' . $CrLf;
2511 $XML_CREDITOR .=
' <RmtInf>' . $CrLf;
2514 $XML_CREDITOR .=
' </RmtInf>' . $CrLf;
2515 $XML_CREDITOR .=
' </CdtTrfTxInf>' . $CrLf;
2516 return $XML_CREDITOR;
2533 fwrite($this->file,
"03");
2534 fwrite($this->file,
"08");
2536 fwrite($this->file,
" ");
2538 fwrite($this->file, $this->emetteur_ics);
2542 fwrite($this->file,
" ");
2543 fwrite($this->file,
dol_print_date($this->date_echeance,
"%d%m",
'gmt'));
2544 fwrite($this->file, substr(
dol_print_date($this->date_echeance,
"%y",
'gmt'), 1));
2548 fwrite($this->file, substr($this->raison_sociale .
" ", 0, 24));
2552 fwrite($this->file, substr($this->reference_remise .
" ", 0, 7));
2556 fwrite($this->file, substr(
" ", 0, 17));
2560 fwrite($this->file, substr(
" ", 0, 2));
2561 fwrite($this->file,
"E");
2562 fwrite($this->file, substr(
" ", 0, 5));
2566 fwrite($this->file, $this->emetteur_code_guichet);
2570 fwrite($this->file, substr(
"000000000000000" . $this->emetteur_numero_compte, -11));
2574 fwrite($this->file, substr(
" ", 0, 16));
2578 fwrite($this->file, substr(
" ", 0, 31));
2582 fwrite($this->file, $this->emetteur_code_banque);
2586 fwrite($this->file, substr(
" ", 0, 5));
2588 fwrite($this->file,
"\n");
2607 public function EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf =
'\n', $format =
'FRST', $type =
'direct-debit', $fk_bank_account = 0)
2617 if (empty($fk_bank_account)) {
2618 $fk_bank_account = ($type ==
'bank-transfer' ?
getDolGlobalInt(
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') :
getDolGlobalInt(
'PRELEVEMENT_ID_BANKACCOUNT'));
2622 $account =
new Account($this->db);
2623 if ($account->fetch($fk_bank_account) > 0) {
2624 $this->emetteur_code_banque = $account->code_banque;
2625 $this->emetteur_code_guichet = $account->code_guichet;
2626 $this->emetteur_numero_compte = $account->number;
2627 $this->emetteur_number_key = $account->cle_rib;
2628 $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
2629 $this->emetteur_iban = $account->iban;
2630 $this->emetteur_bic = $account->bic;
2632 $this->emetteur_ics = (($type ==
'bank-transfer' &&
getDolGlobalString(
"SEPA_USE_IDS")) ? $account->ics_transfer : $account->ics);
2634 $this->raison_sociale = $account->owner_name;
2638 $sql =
"SELECT rowid, ref";
2639 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons as pb";
2640 $sql .=
" WHERE pb.rowid = " . ((int) $this->
id);
2642 $resql = $this->db->query($sql);
2644 $obj = $this->db->fetch_object($resql);
2647 $IdBon = sprintf(
"%05d", $obj->rowid);
2648 $RefBon = $obj->ref;
2649 $localInstrument =
getDolGlobalString(
'PAYMENTBYBANKTRANSFER_CUSTOM_LOCAL_INSTRUMENT',
'CORE');
2652 $total = number_format((
float)
price2num($total,
'MT'), 2,
".",
"");
2655 if ($type !=
'bank-transfer') {
2657 $XML_SEPA_INFO =
'';
2658 $XML_SEPA_INFO .=
' <PmtInf>' . $CrLf;
2659 $XML_SEPA_INFO .=
' <PmtInfId>' . (
'DOL/' . $dateTime_YMD .
'/DD' . $IdBon .
'-' . $RefBon) .
'</PmtInfId>' . $CrLf;
2660 $XML_SEPA_INFO .=
' <PmtMtd>DD</PmtMtd>' . $CrLf;
2661 $XML_SEPA_INFO .=
' <NbOfTxs>' . $nombre .
'</NbOfTxs>' . $CrLf;
2662 $XML_SEPA_INFO .=
' <CtrlSum>' . $total .
'</CtrlSum>' . $CrLf;
2663 $XML_SEPA_INFO .=
' <PmtTpInf>' . $CrLf;
2664 $XML_SEPA_INFO .=
' <SvcLvl>' . $CrLf;
2665 $XML_SEPA_INFO .=
' <Cd>SEPA</Cd>' . $CrLf;
2666 $XML_SEPA_INFO .=
' </SvcLvl>' . $CrLf;
2667 $XML_SEPA_INFO .=
' <LclInstrm>' . $CrLf;
2668 $XML_SEPA_INFO .=
' <Cd>' . $localInstrument .
'</Cd>' . $CrLf;
2669 $XML_SEPA_INFO .=
' </LclInstrm>' . $CrLf;
2670 $XML_SEPA_INFO .=
' <SeqTp>' . $format .
'</SeqTp>' . $CrLf;
2671 $XML_SEPA_INFO .=
' </PmtTpInf>' . $CrLf;
2672 $XML_SEPA_INFO .=
' <ReqdColltnDt>' . $dateTime_ETAD .
'</ReqdColltnDt>' . $CrLf;
2673 $XML_SEPA_INFO .=
' <Cdtr>' . $CrLf;
2675 $XML_SEPA_INFO .=
' <PstlAdr>' . $CrLf;
2676 $XML_SEPA_INFO .=
' <Ctry>' . $country[1] .
'</Ctry>' . $CrLf;
2677 $addressline1 = strtr(
getDolGlobalString(
'MAIN_INFO_SOCIETE_ADDRESS'), array(chr(13) =>
", ", chr(10) =>
""));
2679 if ($addressline1) {
2682 if ($addressline2) {
2685 $XML_SEPA_INFO .=
' </PstlAdr>' . $CrLf;
2686 $XML_SEPA_INFO .=
' </Cdtr>' . $CrLf;
2687 $XML_SEPA_INFO .=
' <CdtrAcct>' . $CrLf;
2688 $XML_SEPA_INFO .=
' <Id>' . $CrLf;
2689 $XML_SEPA_INFO .=
' <IBAN>' . preg_replace(
'/\s/',
'', $this->emetteur_iban) .
'</IBAN>' . $CrLf;
2690 $XML_SEPA_INFO .=
' </Id>' . $CrLf;
2691 $XML_SEPA_INFO .=
' </CdtrAcct>' . $CrLf;
2692 $XML_SEPA_INFO .=
' <CdtrAgt>' . $CrLf;
2693 $XML_SEPA_INFO .=
' <FinInstnId>' . $CrLf;
2694 $XML_SEPA_INFO .=
' <BIC>' . $this->emetteur_bic .
'</BIC>' . $CrLf;
2695 $XML_SEPA_INFO .=
' </FinInstnId>' . $CrLf;
2696 $XML_SEPA_INFO .=
' </CdtrAgt>' . $CrLf;
2705 $XML_SEPA_INFO .=
' <ChrgBr>SLEV</ChrgBr>' . $CrLf;
2706 $XML_SEPA_INFO .=
' <CdtrSchmeId>' . $CrLf;
2707 $XML_SEPA_INFO .=
' <Id>' . $CrLf;
2708 $XML_SEPA_INFO .=
' <PrvtId>' . $CrLf;
2709 $XML_SEPA_INFO .=
' <Othr>' . $CrLf;
2710 $XML_SEPA_INFO .=
' <Id>' . $this->emetteur_ics .
'</Id>' . $CrLf;
2711 $XML_SEPA_INFO .=
' <SchmeNm>' . $CrLf;
2712 $XML_SEPA_INFO .=
' <Prtry>SEPA</Prtry>' . $CrLf;
2713 $XML_SEPA_INFO .=
' </SchmeNm>' . $CrLf;
2714 $XML_SEPA_INFO .=
' </Othr>' . $CrLf;
2715 $XML_SEPA_INFO .=
' </PrvtId>' . $CrLf;
2716 $XML_SEPA_INFO .=
' </Id>' . $CrLf;
2717 $XML_SEPA_INFO .=
' </CdtrSchmeId>' . $CrLf;
2720 $XML_SEPA_INFO =
'';
2721 $XML_SEPA_INFO .=
' <PmtInf>' . $CrLf;
2722 $XML_SEPA_INFO .=
' <PmtInfId>' . (
'DOL/' . $dateTime_YMD .
'/CT' . $IdBon .
'-' . $RefBon) .
'</PmtInfId>' . $CrLf;
2723 $XML_SEPA_INFO .=
' <PmtMtd>TRF</PmtMtd>' . $CrLf;
2725 $XML_SEPA_INFO .=
' <NbOfTxs>' . $nombre .
'</NbOfTxs>' . $CrLf;
2726 $XML_SEPA_INFO .=
' <CtrlSum>' . $total .
'</CtrlSum>' . $CrLf;
2727 if (!empty($this->sepa_xml_pti_in_ctti) && !empty($format)) {
2728 $XML_SEPA_INFO .=
' <PmtTpInf>' . $CrLf;
2729 $XML_SEPA_INFO .=
' <SvcLvl>' . $CrLf;
2730 $XML_SEPA_INFO .=
' <Cd>SEPA</Cd>' . $CrLf;
2731 $XML_SEPA_INFO .=
' </SvcLvl>' . $CrLf;
2732 $XML_SEPA_INFO .=
' <LclInstrm>' . $CrLf;
2733 $XML_SEPA_INFO .=
' <Cd>' . $localInstrument .
'</Cd>' . $CrLf;
2734 $XML_SEPA_INFO .=
' </LclInstrm>' . $CrLf;
2735 $XML_SEPA_INFO .=
' <SeqTp>' . $format .
'</SeqTp>' . $CrLf;
2736 $XML_SEPA_INFO .=
' </PmtTpInf>' . $CrLf;
2738 $XML_SEPA_INFO .=
' <ReqdExctnDt>' .
dol_print_date($dateTime_ETAD,
'dayrfc') .
'</ReqdExctnDt>' . $CrLf;
2739 $XML_SEPA_INFO .=
' <Dbtr>' . $CrLf;
2741 $XML_SEPA_INFO .=
' <PstlAdr>' . $CrLf;
2742 $XML_SEPA_INFO .=
' <Ctry>' . $country[1] .
'</Ctry>' . $CrLf;
2743 $addressline1 = strtr(
getDolGlobalString(
'MAIN_INFO_SOCIETE_ADDRESS'), array(chr(13) =>
", ", chr(10) =>
""));
2745 if ($addressline1) {
2748 if ($addressline2) {
2751 $XML_SEPA_INFO .=
' </PstlAdr>' . $CrLf;
2752 $XML_SEPA_INFO .=
' </Dbtr>' . $CrLf;
2753 $XML_SEPA_INFO .=
' <DbtrAcct>' . $CrLf;
2754 $XML_SEPA_INFO .=
' <Id>' . $CrLf;
2755 $XML_SEPA_INFO .=
' <IBAN>' . preg_replace(
'/\s/',
'', $this->emetteur_iban) .
'</IBAN>' . $CrLf;
2756 $XML_SEPA_INFO .=
' </Id>' . $CrLf;
2757 $XML_SEPA_INFO .=
' </DbtrAcct>' . $CrLf;
2758 $XML_SEPA_INFO .=
' <DbtrAgt>' . $CrLf;
2759 $XML_SEPA_INFO .=
' <FinInstnId>' . $CrLf;
2760 $XML_SEPA_INFO .=
' <BIC>' . $this->emetteur_bic .
'</BIC>' . $CrLf;
2761 $XML_SEPA_INFO .=
' </FinInstnId>' . $CrLf;
2762 $XML_SEPA_INFO .=
' </DbtrAgt>' . $CrLf;
2771 $XML_SEPA_INFO .=
' <ChrgBr>SLEV</ChrgBr>' . $CrLf;
2786 fwrite($this->file,
'INCORRECT EMETTEUR ' . $this->raison_sociale . $CrLf);
2787 $XML_SEPA_INFO =
'';
2789 return $XML_SEPA_INFO;
2802 fwrite($this->file,
"08");
2803 fwrite($this->file,
"08");
2805 fwrite($this->file,
" ");
2807 fwrite($this->file, $this->emetteur_ics);
2811 fwrite($this->file, substr(
" ", 0, 12));
2816 fwrite($this->file, substr(
" ", 0, 24));
2820 fwrite($this->file, substr(
" ", 0, 24));
2824 fwrite($this->file, substr(
" ", 0, 8));
2828 fwrite($this->file, substr(
" ", 0, 5));
2832 fwrite($this->file, substr(
" ", 0, 11));
2836 $montant = ($total * 100);
2838 fwrite($this->file, substr(
"000000000000000" . $montant, -16));
2842 fwrite($this->file, substr(
" ", 0, 31));
2846 fwrite($this->file, substr(
" ", 0, 5));
2850 fwrite($this->file, substr(
" ", 0, 5));
2852 fwrite($this->file,
"\n");
2877 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
2880 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'StatusWaiting');
2881 $this->labelStatus[self::STATUS_TRANSFERED] = $langs->transnoentitiesnoconv(
'StatusTrans');
2882 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'StatusWaiting');
2883 $this->labelStatusShort[self::STATUS_TRANSFERED] = $langs->transnoentitiesnoconv(
'StatusTrans');
2884 if ($this->
type ==
'bank-transfer') {
2885 $this->labelStatus[self::STATUS_DEBITED] = $langs->transnoentitiesnoconv(
'StatusDebited');
2886 $this->labelStatusShort[self::STATUS_DEBITED] = $langs->transnoentitiesnoconv(
'StatusDebited');
2888 $this->labelStatus[self::STATUS_CREDITED] = $langs->transnoentitiesnoconv(
'StatusCredited');
2889 $this->labelStatusShort[self::STATUS_CREDITED] = $langs->transnoentitiesnoconv(
'StatusCredited');
2893 $statusType =
'status1';
2894 if ($status == self::STATUS_TRANSFERED) {
2895 $statusType =
'status3';
2897 if ($status == self::STATUS_CREDITED || $status == self::STATUS_DEBITED) {
2898 $statusType =
'status6';
2901 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
2987 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2989 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2990 $return .=
'<div class="info-box info-box-sm">';
2991 $return .=
'<span class="info-box-icon bg-infobox-action">';
2993 $return .=
'</span>';
2994 $return .=
'<div class="info-box-content">';
2995 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->
getNomUrl(1) .
'</span>';
2996 if ($selected >= 0) {
2997 $return .=
'<input id="cb' . $this->
id .
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="' . $this->
id .
'"' . ($selected ?
' checked="checked"' :
'') .
'>';
2999 if (isset($this->date_echeance)) {
3000 $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>';
3002 if (isset($this->total)) {
3003 $return .=
'<br><span class="opacitymedium">' . $langs->trans(
"Amount") .
'</span> : <span class="amount">' .
price($this->total) .
'</span>';
3005 $return .=
'<br><div class="info-box-status">' . $this->
getLibStatut(3) .
'</div>';
3006 $return .=
'</div>';
3007 $return .=
'</div>';
3008 $return .=
'</div>';
3019 if (!empty($this->
id)) {
3024 $sql =
"SELECT COUNT(*) AS nb FROM " . MAIN_DB_PREFIX .
"prelevement_lignes";
3025 $sql .=
" WHERE fk_prelevement_bons = " . ((int) $id);
3026 $sql .=
" AND fk_soc = 0";
3027 $sql .=
" AND fk_user IS NOT NULL";
3030 $resql = $this->db->query($sql);
3032 $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)
AddFacture($invoice_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $type='debit-order', $sourcetype='', $bic='', $iban='', $rum='')
Add invoice to withdrawal.
deleteNotificationById($rowid)
Delete a notification def by id.
addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype='', $bic='', $iban='', $rum='')
Add line 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.
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.
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.
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 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...
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
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.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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_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.
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)
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.
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left 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 PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.