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 =
'DIRECT_DEBIT_ORDER_CREATE';
1585 if ($type !=
'bank-transfer') {
1586 $triggerName =
'CREDIT_TRANSFER_ORDER_CREATE';
1590 $result = $this->call_trigger($triggerName, $user);
1598 $this->db->commit();
1599 return count($factures_prev);
1601 $this->db->rollback();
1617 public function delete($user, $notrigger = 0)
1622 $resql1 = $resql2 = $resql3 = $resql4 = 0;
1625 $triggername =
'DIRECT_DEBIT_ORDER_DELETE';
1626 if ($this->
type ==
'bank-transfer') {
1627 $triggername =
'PAYMENTBYBANKTRANFER_DELETE';
1630 $result = $this->call_trigger($triggername, $user);
1638 $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) .
")";
1639 $resql1 = $this->db->query($sql);
1646 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"prelevement_lignes WHERE fk_prelevement_bons = " . ((int) $this->
id);
1647 $resql2 = $this->db->query($sql);
1654 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"prelevement_bons WHERE rowid = " . ((int) $this->
id);
1655 $resql3 = $this->db->query($sql);
1662 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_demande SET fk_prelevement_bons = NULL, traite = 0 WHERE fk_prelevement_bons = " . ((int) $this->
id);
1663 $resql4 = $this->db->query($sql);
1669 if ($resql1 && $resql2 && $resql3 && $resql4 && !$error) {
1670 $this->db->commit();
1673 $this->db->rollback();
1689 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1691 global $conf, $langs, $hookmanager;
1693 if (!empty($conf->dol_no_mouse_hover)) {
1699 $labeltoshow =
'PaymentByDirectDebit';
1700 if (!empty($this->
type) && $this->
type ==
'bank-transfer') {
1701 $labeltoshow =
'PaymentByBankTransfer';
1704 $label =
img_picto(
'', $this->picto) .
' <u>' . $langs->trans($labeltoshow) .
'</u> ' . $this->
getLibStatut(5);
1706 $label .=
'<b>' . $langs->trans(
'Ref') .
':</b> ' . $this->ref;
1707 if (isset($this->
amount)) {
1708 $label .=
'<br><b>' . $langs->trans(
"Amount") .
":</b> " .
price($this->
amount);
1710 if (isset($this->date_trans)) {
1711 $label .=
'<br><b>' . $langs->trans(
"TransData") .
":</b> " .
dol_print_date($this->date_trans,
'dayhour',
'tzuserrel');
1717 $url = DOL_URL_ROOT .
'/compta/prelevement/card.php?id=' . $this->id;
1718 if (!empty($this->
type) && $this->
type ==
'bank-transfer') {
1719 $url = DOL_URL_ROOT .
'/compta/prelevement/card.php?id=' . $this->id;
1722 if ($option !=
'nolink') {
1724 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1725 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1726 $add_save_lastsearch_values = 1;
1728 if ($add_save_lastsearch_values) {
1729 $url .=
'&save_lastsearch_values=1';
1734 if (empty($notooltip)) {
1736 $label = $langs->trans(
"ShowMyObject");
1740 $linkclose .=
' class="classfortooltip' . ($morecss ?
' ' . $morecss :
'') .
'"';
1742 $linkclose = ($morecss ?
' class="' . $morecss .
'"' :
'');
1745 $linkstart =
'<a href="' . $url .
'"';
1746 $linkstart .= $linkclose .
'>';
1749 $result .= $linkstart;
1751 $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);
1753 if ($withpicto != 2) {
1754 $result .= $this->ref;
1756 $result .= $linkend;
1758 global $action, $hookmanager;
1759 $hookmanager->initHooks(array(
'banktransferdao'));
1760 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1761 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1763 $result = $hookmanager->resPrint;
1765 $result .= $hookmanager->resPrint;
1780 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"notify_def";
1781 $sql .=
" WHERE rowid = " . ((int) $rowid);
1783 if ($this->db->query($sql)) {
1799 if (is_object($user)) {
1800 $userid = $user->id;
1805 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"notify_def";
1806 $sql .=
" WHERE fk_user=" . ((int) $userid) .
" AND fk_action='" . $this->db->escape($action) .
"'";
1808 if ($this->db->query($sql)) {
1829 if (is_object($user)) {
1830 $userid = $user->id;
1838 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"notify_def (datec,fk_user, fk_soc, fk_contact, fk_action)";
1839 $sql .=
" VALUES ('" . $this->db->idate($now) .
"', " . ((int) $userid) .
", 'NULL', 'NULL', '" . $this->db->escape($action) .
"')";
1842 if ($this->db->query($sql)) {
1846 dol_syslog(get_class($this) .
"::addNotification Error $result");
1869 public function generate(
string $format =
'ALL',
int $executiondate = 0,
string $type =
'direct-debit',
int $fk_bank_account = 0,
int $forsalary = 0,
int $thirdpartyBANId = 0)
1871 global $conf, $langs,
$mysoc;
1876 if (empty($fk_bank_account)) {
1877 $fk_bank_account = ($type ==
'bank-transfer' ?
getDolGlobalInt(
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') :
getDolGlobalInt(
'PRELEVEMENT_ID_BANKACCOUNT'));
1882 dol_syslog(get_class($this) .
"::generate build file=" . $this->filename .
" type=" . $type);
1884 $this->file = fopen($this->filename,
"w");
1885 if ($this->file ==
false) {
1886 $this->error = $langs->trans(
'ErrorFailedToOpenFile', $this->filename);
1894 if (
$mysoc->isInSEPA()) {
1897 if ($type !=
'bank-transfer') {
1909 if (!empty($executiondate)) {
1910 $date_actu = $executiondate;
1915 $fileDebiteurSection =
'';
1916 $fileEmetteurSection =
'';
1923 $sql =
"SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
1924 $sql .=
" pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
1925 $sql .=
" f.ref as reffac, p.fk_facture as idfac,";
1926 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
1928 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
1929 $sql .=
" " . MAIN_DB_PREFIX .
"facture as f,";
1930 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p,";
1931 $sql .=
" " . MAIN_DB_PREFIX .
"societe as soc,";
1932 $sql .=
" " . MAIN_DB_PREFIX .
"c_country as c,";
1933 $sql .=
" " . MAIN_DB_PREFIX .
"societe_rib as rib";
1934 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
1935 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
1936 $sql .=
" AND p.fk_facture = f.rowid";
1937 $sql .=
" AND f.fk_soc = soc.rowid";
1938 $sql .=
" AND soc.fk_pays = c.rowid";
1939 $sql .=
" AND rib.fk_soc = f.fk_soc";
1940 if (!empty($thirdpartyBANId)) {
1941 $sql .=
" AND rib.rowid = " . ((int) $thirdpartyBANId);
1943 $sql .=
" AND rib.default_rib = 1";
1945 $sql .=
" AND rib.type = 'ban'";
1948 $resql = $this->db->query($sql);
1949 $nbtotalDrctDbtTxInf = -1;
1951 $cachearraytotestduplicate = array();
1953 $num = $this->db->num_rows($resql);
1955 $obj = $this->db->fetch_object($resql);
1957 if (!empty($cachearraytotestduplicate[$obj->idfac])) {
1958 $this->error = $langs->trans(
'ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
1959 $this->invoice_in_error[$obj->idfac] = $this->error;
1963 $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
1965 $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
1968 $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);
1970 $this->total += $obj->somme;
1973 $nbtotalDrctDbtTxInf = $i;
1975 $this->error = $this->db->lasterror();
1976 fwrite($this->file,
'ERROR DEBITOR ' . $sql . $CrLf);
1981 if ($result != -2) {
1982 $fileEmetteurSection .= $this->
EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type, $fk_bank_account);
1986 $this->total = number_format((
float)
price2num($this->total,
'MT'), 2,
".",
"");
1993 fwrite($this->file,
'<' .
'?xml version="1.0" encoding="UTF-8" standalone="yes"?' .
'>' . $CrLf);
1994 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);
1995 fwrite($this->file,
' <CstmrDrctDbtInitn>' . $CrLf);
1997 fwrite($this->file,
' <GrpHdr>' . $CrLf);
1998 fwrite($this->file,
' <MsgId>' . (
'DOL/' . $dateTime_YMD .
'/DD' . $this->
id) .
'</MsgId>' . $CrLf);
1999 fwrite($this->file,
' <CreDtTm>' . $dateTime_ECMA .
'</CreDtTm>' . $CrLf);
2000 fwrite($this->file,
' <NbOfTxs>' . $i .
'</NbOfTxs>' . $CrLf);
2001 fwrite($this->file,
' <CtrlSum>' . $this->total .
'</CtrlSum>' . $CrLf);
2002 fwrite($this->file,
' <InitgPty>' . $CrLf);
2004 fwrite($this->file,
' <Id>' . $CrLf);
2005 fwrite($this->file,
' <PrvtId>' . $CrLf);
2006 fwrite($this->file,
' <Othr>' . $CrLf);
2007 fwrite($this->file,
' <Id>' . $this->emetteur_ics .
'</Id>' . $CrLf);
2008 fwrite($this->file,
' </Othr>' . $CrLf);
2009 fwrite($this->file,
' </PrvtId>' . $CrLf);
2010 fwrite($this->file,
' </Id>' . $CrLf);
2011 fwrite($this->file,
' </InitgPty>' . $CrLf);
2012 fwrite($this->file,
' </GrpHdr>' . $CrLf);
2014 if ($result != -2) {
2015 fwrite($this->file, $fileEmetteurSection);
2018 if ($result != -2) {
2019 fwrite($this->file, $fileDebiteurSection);
2022 fwrite($this->file,
' </PmtInf>' . $CrLf);
2023 fwrite($this->file,
' </CstmrDrctDbtInitn>' . $CrLf);
2024 fwrite($this->file,
'</Document>' . $CrLf);
2037 if (!empty($executiondate)) {
2038 $date_actu = $executiondate;
2043 $fileCrediteurSection =
'';
2044 $fileEmetteurSection =
'';
2050 if (!empty($forsalary)) {
2051 $sql =
"SELECT u.rowid as userId, u.address, u.zip, u.town, c.code as country_code, CONCAT(u.firstname,' ',u.lastname) as nom,";
2052 $sql .=
" pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
2053 $sql .=
" s.ref as reffac, p.fk_salary as idfac,";
2054 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, '' as rum, '' as date_rum";
2056 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
2057 $sql .=
" " . MAIN_DB_PREFIX .
"salary as s,";
2058 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p,";
2059 $sql .=
" " . MAIN_DB_PREFIX .
"user as u";
2060 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"c_country as c ON u.fk_country = c.rowid,";
2061 $sql .=
" " . MAIN_DB_PREFIX .
"user_rib as rib";
2062 $sql .=
" WHERE pl.fk_prelevement_bons=" . ((int) $this->
id);
2063 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
2064 $sql .=
" AND p.fk_salary = s.rowid";
2065 $sql .=
" AND s.fk_user = u.rowid";
2066 $sql .=
" AND rib.fk_user = s.fk_user";
2068 $sql =
"SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
2069 $sql .=
" pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
2070 $sql .=
" f.ref as reffac, f.ref_supplier as fac_ref_supplier, p.fk_facture_fourn as idfac,";
2071 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
2073 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
2074 $sql .=
" " . MAIN_DB_PREFIX .
"facture_fourn as f,";
2075 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p,";
2076 $sql .=
" " . MAIN_DB_PREFIX .
"societe as soc";
2077 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"c_country as c ON soc.fk_pays = c.rowid,";
2078 $sql .=
" " . MAIN_DB_PREFIX .
"societe_rib as rib";
2079 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
2080 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
2081 $sql .=
" AND p.fk_facture_fourn = f.rowid";
2082 $sql .=
" AND f.fk_soc = soc.rowid";
2083 $sql .=
" AND rib.fk_soc = f.fk_soc";
2084 if (!empty($thirdpartyBANId)) {
2085 $sql .=
" AND rib.rowid = " . ((int) $thirdpartyBANId);
2087 $sql .=
" AND rib.default_rib = 1";
2089 $sql .=
" AND rib.type = 'ban'";
2092 $nbtotalDrctDbtTxInf = -1;
2094 $resql = $this->db->query($sql);
2096 $cachearraytotestduplicate = array();
2098 $num = $this->db->num_rows($resql);
2100 $obj = $this->db->fetch_object($resql);
2101 if (!empty($cachearraytotestduplicate[$obj->idfac])) {
2102 $this->error = $langs->trans(
'ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
2103 $this->invoice_in_error[$obj->idfac] = $this->error;
2107 $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
2109 $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
2111 $refobj = $obj->reffac;
2112 if (empty($refobj) && !empty($forsalary)) {
2113 $refobj =
"SAL" . $obj->idfac;
2116 $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);
2118 $this->total += $obj->somme;
2121 $nbtotalDrctDbtTxInf = $i;
2123 $this->error = $this->db->lasterror();
2124 fwrite($this->file,
'ERROR CREDITOR ' . $sql . $CrLf);
2128 if ($result != -2) {
2129 $fileEmetteurSection .= $this->
EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type);
2133 $this->total = number_format((
float)
price2num($this->total,
'MT'), 2,
".",
"");
2140 fwrite($this->file,
'<' .
'?xml version="1.0" encoding="UTF-8" standalone="yes"?' .
'>' . $CrLf);
2141 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);
2142 fwrite($this->file,
' <CstmrCdtTrfInitn>' . $CrLf);
2144 fwrite($this->file,
' <GrpHdr>' . $CrLf);
2145 fwrite($this->file,
' <MsgId>' . (
'DOL/' . $dateTime_YMD .
'/CT' . $this->
id) .
'</MsgId>' . $CrLf);
2146 fwrite($this->file,
' <CreDtTm>' . $dateTime_ECMA .
'</CreDtTm>' . $CrLf);
2147 fwrite($this->file,
' <NbOfTxs>' . $i .
'</NbOfTxs>' . $CrLf);
2148 fwrite($this->file,
' <CtrlSum>' . $this->total .
'</CtrlSum>' . $CrLf);
2149 fwrite($this->file,
' <InitgPty>' . $CrLf);
2151 fwrite($this->file,
' <Id>' . $CrLf);
2152 fwrite($this->file,
' <PrvtId>' . $CrLf);
2153 fwrite($this->file,
' <Othr>' . $CrLf);
2154 fwrite($this->file,
' <Id>' . $this->emetteur_ics .
'</Id>' . $CrLf);
2155 fwrite($this->file,
' </Othr>' . $CrLf);
2156 fwrite($this->file,
' </PrvtId>' . $CrLf);
2157 fwrite($this->file,
' </Id>' . $CrLf);
2158 fwrite($this->file,
' </InitgPty>' . $CrLf);
2159 fwrite($this->file,
' </GrpHdr>' . $CrLf);
2161 if ($result != -2) {
2162 fwrite($this->file, $fileEmetteurSection);
2165 if ($result != -2) {
2166 fwrite($this->file, $fileCrediteurSection);
2169 fwrite($this->file,
' </PmtInf>' . $CrLf);
2170 fwrite($this->file,
' </CstmrCdtTrfInitn>' . $CrLf);
2171 fwrite($this->file,
'</Document>' . $CrLf);
2177 if ($type !=
'bank-transfer') {
2178 $sql =
"SELECT pl.amount";
2180 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
2181 $sql .=
" " . MAIN_DB_PREFIX .
"facture as f,";
2182 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p";
2183 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
2184 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
2185 $sql .=
" AND p.fk_facture = f.rowid";
2189 $resql = $this->db->query($sql);
2191 $num = $this->db->num_rows($resql);
2194 $obj = $this->db->fetch_object($resql);
2195 $this->total += $obj->amount;
2204 $sql =
"SELECT pl.amount";
2206 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
2207 $sql .=
" " . MAIN_DB_PREFIX .
"facture_fourn as f,";
2208 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p";
2209 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
2210 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
2211 $sql .=
" AND p.fk_facture_fourn = f.rowid";
2214 $resql = $this->db->query($sql);
2216 $num = $this->db->num_rows($resql);
2219 $obj = $this->db->fetch_object($resql);
2220 $this->total += $obj->amount;
2230 $langs->load(
'withdrawals');
2233 fwrite($this->file, $langs->transnoentitiesnoconv(
'WithdrawalFileNotCapable',
$mysoc->country_code));
2236 fclose($this->file);
2258 return $pre .
'-' .
dol_print_date($row_datec,
'dayhourlogsmall') .
'-' .
dol_trunc($row_drum . ($row_code_client ?
'-' . $row_code_client :
''), 17,
'right',
'UTF-8', 1);
2279 public function EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $ref, $facid, $rib_dom =
'', $type =
'direct-debit')
2282 fwrite($this->file,
"06");
2283 fwrite($this->file,
"08");
2285 fwrite($this->file,
" ");
2287 fwrite($this->file, $this->emetteur_ics);
2291 fwrite($this->file,
" ");
2292 fwrite($this->file,
dol_print_date($this->date_echeance,
"%d%m",
'gmt'));
2293 fwrite($this->file, substr(
dol_print_date($this->date_echeance,
"%y",
'gmt'), 1));
2297 fwrite($this->file, substr(strtoupper($client_nom) .
" ", 0, 24));
2300 $address = strtr($rib_dom, array(
" " =>
"-", chr(13) =>
" ", chr(10) =>
""));
2301 fwrite($this->file, substr($address .
" ", 0, 24));
2305 fwrite($this->file, substr(
" ", 0, 8));
2309 fwrite($this->file, $rib_guichet);
2313 fwrite($this->file, substr(
"000000000000000" . $rib_number, -11));
2317 $montant = (round($amount, 2) * 100);
2319 fwrite($this->file, substr(
"000000000000000" . $montant, -16));
2323 fwrite($this->file, substr(
"*_" . $ref .
"_RDVnet" . $rowid .
" ", 0, 31));
2327 fwrite($this->file, $rib_banque);
2331 fwrite($this->file, substr(
" ", 0, 5));
2333 fwrite($this->file,
"\n");
2363 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 =
'')
2369 $row_somme = number_format((
float)
price2num($row_somme,
'MT'), 2,
".",
"");
2371 $row_somme = round((
float) $row_somme, 2);
2374 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
2377 $Rowing = sprintf(
"%010d", $row_idfac);
2381 $Rum = (empty($row_rum) ? $this->
buildRumNumber($row_code_client, $row_datec, $row_drum) : $row_rum);
2386 if ($type !=
'bank-transfer') {
2389 $XML_DEBITOR .=
' <DrctDbtTxInf>' . $CrLf;
2390 $XML_DEBITOR .=
' <PmtId>' . $CrLf;
2392 $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;
2393 $XML_DEBITOR .=
' </PmtId>' . $CrLf;
2394 $XML_DEBITOR .=
' <InstdAmt Ccy="EUR">' . $row_somme .
'</InstdAmt>' . $CrLf;
2395 $XML_DEBITOR .=
' <DrctDbtTx>' . $CrLf;
2396 $XML_DEBITOR .=
' <MndtRltdInf>' . $CrLf;
2397 $XML_DEBITOR .=
' <MndtId>' . $Rum .
'</MndtId>' . $CrLf;
2398 $XML_DEBITOR .=
' <DtOfSgntr>' . $DtOfSgntr .
'</DtOfSgntr>' . $CrLf;
2399 $XML_DEBITOR .=
' <AmdmntInd>false</AmdmntInd>' . $CrLf;
2400 $XML_DEBITOR .=
' </MndtRltdInf>' . $CrLf;
2401 $XML_DEBITOR .=
' </DrctDbtTx>' . $CrLf;
2402 $XML_DEBITOR .=
' <DbtrAgt>' . $CrLf;
2403 $XML_DEBITOR .=
' <FinInstnId>' . $CrLf;
2405 $XML_DEBITOR .=
' <BIC>' . $row_bic .
'</BIC>' . $CrLf;
2407 $XML_DEBITOR .=
' </FinInstnId>' . $CrLf;
2408 $XML_DEBITOR .=
' </DbtrAgt>' . $CrLf;
2409 $XML_DEBITOR .=
' <Dbtr>' . $CrLf;
2411 $XML_DEBITOR .=
' <PstlAdr>' . $CrLf;
2412 $XML_DEBITOR .=
' <Ctry>' . $row_country_code .
'</Ctry>' . $CrLf;
2413 $addressline1 = strtr($row_address, array(chr(13) =>
", ", chr(10) =>
""));
2414 $addressline2 = strtr($row_zip . (($row_zip && $row_town) ?
' ' :
'') . (
string) $row_town, array(chr(13) =>
", ", chr(10) =>
""));
2415 if (trim($addressline1)) {
2418 if (trim($addressline2)) {
2421 $XML_DEBITOR .=
' </PstlAdr>' . $CrLf;
2422 $XML_DEBITOR .=
' </Dbtr>' . $CrLf;
2423 $XML_DEBITOR .=
' <DbtrAcct>' . $CrLf;
2424 $XML_DEBITOR .=
' <Id>' . $CrLf;
2425 $XML_DEBITOR .=
' <IBAN>' . preg_replace(
'/\s/',
'', $row_iban) .
'</IBAN>' . $CrLf;
2426 $XML_DEBITOR .=
' </Id>' . $CrLf;
2427 $XML_DEBITOR .=
' </DbtrAcct>' . $CrLf;
2428 $XML_DEBITOR .=
' <RmtInf>' . $CrLf;
2432 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions_be.lib.php';
2434 $invoicestatic =
new Facture($this->db);
2435 $invoicestatic->fetch($row_idfac);
2438 $XML_DEBITOR .=
' <strd>' . $invoicePaymentKey .
'</strd>' . $CrLf;
2443 $XML_DEBITOR .=
' </RmtInf>' . $CrLf;
2444 $XML_DEBITOR .=
' </DrctDbtTxInf>' . $CrLf;
2445 return $XML_DEBITOR;
2449 $XML_CREDITOR .=
' <CdtTrfTxInf>' . $CrLf;
2450 $XML_CREDITOR .=
' <PmtId>' . $CrLf;
2452 $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;
2453 $XML_CREDITOR .=
' </PmtId>' . $CrLf;
2454 if (!empty($this->sepa_xml_pti_in_ctti)) {
2455 $XML_CREDITOR .=
' <PmtTpInf>' . $CrLf;
2459 $instrprty =
'HIGH';
2461 $instrprty =
'NORM';
2465 $categoryPurpose =
getDolGlobalString(
'PAYMENTBYBANKTRANSFER_CUSTOM_CATEGORY_PURPOSE',
'CORE');
2467 $XML_CREDITOR .=
' <InstrPrty>' . $instrprty .
'</InstrPrty>' . $CrLf;
2468 $XML_CREDITOR .=
' <SvcLvl>' . $CrLf;
2469 $XML_CREDITOR .=
' <Cd>SEPA</Cd>' . $CrLf;
2470 $XML_CREDITOR .=
' </SvcLvl>' . $CrLf;
2471 $XML_CREDITOR .=
' <CtgyPurp>' . $CrLf;
2472 $XML_CREDITOR .=
' <Cd>' . $categoryPurpose .
'</Cd>' . $CrLf;
2473 $XML_CREDITOR .=
' </CtgyPurp>' . $CrLf;
2474 $XML_CREDITOR .=
' </PmtTpInf>' . $CrLf;
2476 $XML_CREDITOR .=
' <Amt>' . $CrLf;
2477 $XML_CREDITOR .=
' <InstdAmt Ccy="EUR">'.round((
float) $row_somme, 2).
'</InstdAmt>'.$CrLf;
2478 $XML_CREDITOR .=
' </Amt>' . $CrLf;
2489 $XML_CREDITOR .=
' <CdtrAgt>' . $CrLf;
2490 $XML_CREDITOR .=
' <FinInstnId>' . $CrLf;
2491 $XML_CREDITOR .=
' <BIC>' . $row_bic .
'</BIC>' . $CrLf;
2492 $XML_CREDITOR .=
' </FinInstnId>' . $CrLf;
2493 $XML_CREDITOR .=
' </CdtrAgt>' . $CrLf;
2494 $XML_CREDITOR .=
' <Cdtr>' . $CrLf;
2496 $XML_CREDITOR .=
' <PstlAdr>' . $CrLf;
2497 $XML_CREDITOR .=
' <Ctry>' . $row_country_code .
'</Ctry>' . $CrLf;
2498 $addressline1 = strtr($row_address, array(chr(13) =>
", ", chr(10) =>
""));
2499 $addressline2 = strtr($row_zip . (($row_zip && $row_town) ?
' ' :
'') . (
string) $row_town, array(chr(13) =>
", ", chr(10) =>
""));
2500 if (trim($addressline1)) {
2503 if (trim($addressline2)) {
2506 $XML_CREDITOR .=
' </PstlAdr>' . $CrLf;
2507 $XML_CREDITOR .=
' </Cdtr>' . $CrLf;
2508 $XML_CREDITOR .=
' <CdtrAcct>' . $CrLf;
2509 $XML_CREDITOR .=
' <Id>' . $CrLf;
2510 $XML_CREDITOR .=
' <IBAN>' . preg_replace(
'/\s/',
'', $row_iban) .
'</IBAN>' . $CrLf;
2511 $XML_CREDITOR .=
' </Id>' . $CrLf;
2512 $XML_CREDITOR .=
' </CdtrAcct>' . $CrLf;
2513 $XML_CREDITOR .=
' <RmtInf>' . $CrLf;
2516 $XML_CREDITOR .=
' </RmtInf>' . $CrLf;
2517 $XML_CREDITOR .=
' </CdtTrfTxInf>' . $CrLf;
2518 return $XML_CREDITOR;
2535 fwrite($this->file,
"03");
2536 fwrite($this->file,
"08");
2538 fwrite($this->file,
" ");
2540 fwrite($this->file, $this->emetteur_ics);
2544 fwrite($this->file,
" ");
2545 fwrite($this->file,
dol_print_date($this->date_echeance,
"%d%m",
'gmt'));
2546 fwrite($this->file, substr(
dol_print_date($this->date_echeance,
"%y",
'gmt'), 1));
2550 fwrite($this->file, substr($this->raison_sociale .
" ", 0, 24));
2554 fwrite($this->file, substr($this->reference_remise .
" ", 0, 7));
2558 fwrite($this->file, substr(
" ", 0, 17));
2562 fwrite($this->file, substr(
" ", 0, 2));
2563 fwrite($this->file,
"E");
2564 fwrite($this->file, substr(
" ", 0, 5));
2568 fwrite($this->file, $this->emetteur_code_guichet);
2572 fwrite($this->file, substr(
"000000000000000" . $this->emetteur_numero_compte, -11));
2576 fwrite($this->file, substr(
" ", 0, 16));
2580 fwrite($this->file, substr(
" ", 0, 31));
2584 fwrite($this->file, $this->emetteur_code_banque);
2588 fwrite($this->file, substr(
" ", 0, 5));
2590 fwrite($this->file,
"\n");
2609 public function EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf =
'\n', $format =
'FRST', $type =
'direct-debit', $fk_bank_account = 0)
2619 if (empty($fk_bank_account)) {
2620 $fk_bank_account = ($type ==
'bank-transfer' ?
getDolGlobalInt(
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') :
getDolGlobalInt(
'PRELEVEMENT_ID_BANKACCOUNT'));
2624 $account =
new Account($this->db);
2625 if ($account->fetch($fk_bank_account) > 0) {
2626 $this->emetteur_code_banque = $account->code_banque;
2627 $this->emetteur_code_guichet = $account->code_guichet;
2628 $this->emetteur_numero_compte = $account->number;
2629 $this->emetteur_number_key = $account->cle_rib;
2630 $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
2631 $this->emetteur_iban = $account->iban;
2632 $this->emetteur_bic = $account->bic;
2634 $this->emetteur_ics = (($type ==
'bank-transfer' &&
getDolGlobalString(
"SEPA_USE_IDS")) ? $account->ics_transfer : $account->ics);
2636 $this->raison_sociale = $account->owner_name;
2640 $sql =
"SELECT rowid, ref";
2641 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons as pb";
2642 $sql .=
" WHERE pb.rowid = " . ((int) $this->
id);
2644 $resql = $this->db->query($sql);
2646 $obj = $this->db->fetch_object($resql);
2649 $IdBon = sprintf(
"%05d", $obj->rowid);
2650 $RefBon = $obj->ref;
2651 $localInstrument =
getDolGlobalString(
'PAYMENTBYBANKTRANSFER_CUSTOM_LOCAL_INSTRUMENT',
'CORE');
2654 $total = number_format((
float)
price2num($total,
'MT'), 2,
".",
"");
2657 if ($type !=
'bank-transfer') {
2659 $XML_SEPA_INFO =
'';
2660 $XML_SEPA_INFO .=
' <PmtInf>' . $CrLf;
2661 $XML_SEPA_INFO .=
' <PmtInfId>' . (
'DOL/' . $dateTime_YMD .
'/DD' . $IdBon .
'-' . $RefBon) .
'</PmtInfId>' . $CrLf;
2662 $XML_SEPA_INFO .=
' <PmtMtd>DD</PmtMtd>' . $CrLf;
2663 $XML_SEPA_INFO .=
' <NbOfTxs>' . $nombre .
'</NbOfTxs>' . $CrLf;
2664 $XML_SEPA_INFO .=
' <CtrlSum>' . $total .
'</CtrlSum>' . $CrLf;
2665 $XML_SEPA_INFO .=
' <PmtTpInf>' . $CrLf;
2666 $XML_SEPA_INFO .=
' <SvcLvl>' . $CrLf;
2667 $XML_SEPA_INFO .=
' <Cd>SEPA</Cd>' . $CrLf;
2668 $XML_SEPA_INFO .=
' </SvcLvl>' . $CrLf;
2669 $XML_SEPA_INFO .=
' <LclInstrm>' . $CrLf;
2670 $XML_SEPA_INFO .=
' <Cd>' . $localInstrument .
'</Cd>' . $CrLf;
2671 $XML_SEPA_INFO .=
' </LclInstrm>' . $CrLf;
2672 $XML_SEPA_INFO .=
' <SeqTp>' . $format .
'</SeqTp>' . $CrLf;
2673 $XML_SEPA_INFO .=
' </PmtTpInf>' . $CrLf;
2674 $XML_SEPA_INFO .=
' <ReqdColltnDt>' . $dateTime_ETAD .
'</ReqdColltnDt>' . $CrLf;
2675 $XML_SEPA_INFO .=
' <Cdtr>' . $CrLf;
2677 $XML_SEPA_INFO .=
' <PstlAdr>' . $CrLf;
2678 $XML_SEPA_INFO .=
' <Ctry>' . $country[1] .
'</Ctry>' . $CrLf;
2679 $addressline1 = strtr(
getDolGlobalString(
'MAIN_INFO_SOCIETE_ADDRESS'), array(chr(13) =>
", ", chr(10) =>
""));
2681 if ($addressline1) {
2684 if ($addressline2) {
2687 $XML_SEPA_INFO .=
' </PstlAdr>' . $CrLf;
2688 $XML_SEPA_INFO .=
' </Cdtr>' . $CrLf;
2689 $XML_SEPA_INFO .=
' <CdtrAcct>' . $CrLf;
2690 $XML_SEPA_INFO .=
' <Id>' . $CrLf;
2691 $XML_SEPA_INFO .=
' <IBAN>' . preg_replace(
'/\s/',
'', $this->emetteur_iban) .
'</IBAN>' . $CrLf;
2692 $XML_SEPA_INFO .=
' </Id>' . $CrLf;
2693 $XML_SEPA_INFO .=
' </CdtrAcct>' . $CrLf;
2694 $XML_SEPA_INFO .=
' <CdtrAgt>' . $CrLf;
2695 $XML_SEPA_INFO .=
' <FinInstnId>' . $CrLf;
2696 $XML_SEPA_INFO .=
' <BIC>' . $this->emetteur_bic .
'</BIC>' . $CrLf;
2697 $XML_SEPA_INFO .=
' </FinInstnId>' . $CrLf;
2698 $XML_SEPA_INFO .=
' </CdtrAgt>' . $CrLf;
2707 $XML_SEPA_INFO .=
' <ChrgBr>SLEV</ChrgBr>' . $CrLf;
2708 $XML_SEPA_INFO .=
' <CdtrSchmeId>' . $CrLf;
2709 $XML_SEPA_INFO .=
' <Id>' . $CrLf;
2710 $XML_SEPA_INFO .=
' <PrvtId>' . $CrLf;
2711 $XML_SEPA_INFO .=
' <Othr>' . $CrLf;
2712 $XML_SEPA_INFO .=
' <Id>' . $this->emetteur_ics .
'</Id>' . $CrLf;
2713 $XML_SEPA_INFO .=
' <SchmeNm>' . $CrLf;
2714 $XML_SEPA_INFO .=
' <Prtry>SEPA</Prtry>' . $CrLf;
2715 $XML_SEPA_INFO .=
' </SchmeNm>' . $CrLf;
2716 $XML_SEPA_INFO .=
' </Othr>' . $CrLf;
2717 $XML_SEPA_INFO .=
' </PrvtId>' . $CrLf;
2718 $XML_SEPA_INFO .=
' </Id>' . $CrLf;
2719 $XML_SEPA_INFO .=
' </CdtrSchmeId>' . $CrLf;
2722 $XML_SEPA_INFO =
'';
2723 $XML_SEPA_INFO .=
' <PmtInf>' . $CrLf;
2724 $XML_SEPA_INFO .=
' <PmtInfId>' . (
'DOL/' . $dateTime_YMD .
'/CT' . $IdBon .
'-' . $RefBon) .
'</PmtInfId>' . $CrLf;
2725 $XML_SEPA_INFO .=
' <PmtMtd>TRF</PmtMtd>' . $CrLf;
2727 $XML_SEPA_INFO .=
' <NbOfTxs>' . $nombre .
'</NbOfTxs>' . $CrLf;
2728 $XML_SEPA_INFO .=
' <CtrlSum>' . $total .
'</CtrlSum>' . $CrLf;
2729 if (!empty($this->sepa_xml_pti_in_ctti) && !empty($format)) {
2730 $XML_SEPA_INFO .=
' <PmtTpInf>' . $CrLf;
2731 $XML_SEPA_INFO .=
' <SvcLvl>' . $CrLf;
2732 $XML_SEPA_INFO .=
' <Cd>SEPA</Cd>' . $CrLf;
2733 $XML_SEPA_INFO .=
' </SvcLvl>' . $CrLf;
2734 $XML_SEPA_INFO .=
' <LclInstrm>' . $CrLf;
2735 $XML_SEPA_INFO .=
' <Cd>' . $localInstrument .
'</Cd>' . $CrLf;
2736 $XML_SEPA_INFO .=
' </LclInstrm>' . $CrLf;
2737 $XML_SEPA_INFO .=
' <SeqTp>' . $format .
'</SeqTp>' . $CrLf;
2738 $XML_SEPA_INFO .=
' </PmtTpInf>' . $CrLf;
2740 $XML_SEPA_INFO .=
' <ReqdExctnDt>' .
dol_print_date($dateTime_ETAD,
'dayrfc') .
'</ReqdExctnDt>' . $CrLf;
2741 $XML_SEPA_INFO .=
' <Dbtr>' . $CrLf;
2743 $XML_SEPA_INFO .=
' <PstlAdr>' . $CrLf;
2744 $XML_SEPA_INFO .=
' <Ctry>' . $country[1] .
'</Ctry>' . $CrLf;
2745 $addressline1 = strtr(
getDolGlobalString(
'MAIN_INFO_SOCIETE_ADDRESS'), array(chr(13) =>
", ", chr(10) =>
""));
2747 if ($addressline1) {
2750 if ($addressline2) {
2753 $XML_SEPA_INFO .=
' </PstlAdr>' . $CrLf;
2754 $XML_SEPA_INFO .=
' </Dbtr>' . $CrLf;
2755 $XML_SEPA_INFO .=
' <DbtrAcct>' . $CrLf;
2756 $XML_SEPA_INFO .=
' <Id>' . $CrLf;
2757 $XML_SEPA_INFO .=
' <IBAN>' . preg_replace(
'/\s/',
'', $this->emetteur_iban) .
'</IBAN>' . $CrLf;
2758 $XML_SEPA_INFO .=
' </Id>' . $CrLf;
2759 $XML_SEPA_INFO .=
' </DbtrAcct>' . $CrLf;
2760 $XML_SEPA_INFO .=
' <DbtrAgt>' . $CrLf;
2761 $XML_SEPA_INFO .=
' <FinInstnId>' . $CrLf;
2762 $XML_SEPA_INFO .=
' <BIC>' . $this->emetteur_bic .
'</BIC>' . $CrLf;
2763 $XML_SEPA_INFO .=
' </FinInstnId>' . $CrLf;
2764 $XML_SEPA_INFO .=
' </DbtrAgt>' . $CrLf;
2773 $XML_SEPA_INFO .=
' <ChrgBr>SLEV</ChrgBr>' . $CrLf;
2788 fwrite($this->file,
'INCORRECT EMETTEUR ' . $this->raison_sociale . $CrLf);
2789 $XML_SEPA_INFO =
'';
2791 return $XML_SEPA_INFO;
2804 fwrite($this->file,
"08");
2805 fwrite($this->file,
"08");
2807 fwrite($this->file,
" ");
2809 fwrite($this->file, $this->emetteur_ics);
2813 fwrite($this->file, substr(
" ", 0, 12));
2818 fwrite($this->file, substr(
" ", 0, 24));
2822 fwrite($this->file, substr(
" ", 0, 24));
2826 fwrite($this->file, substr(
" ", 0, 8));
2830 fwrite($this->file, substr(
" ", 0, 5));
2834 fwrite($this->file, substr(
" ", 0, 11));
2838 $montant = ($total * 100);
2840 fwrite($this->file, substr(
"000000000000000" . $montant, -16));
2844 fwrite($this->file, substr(
" ", 0, 31));
2848 fwrite($this->file, substr(
" ", 0, 5));
2852 fwrite($this->file, substr(
" ", 0, 5));
2854 fwrite($this->file,
"\n");
2879 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
2882 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'StatusWaiting');
2883 $this->labelStatus[self::STATUS_TRANSFERED] = $langs->transnoentitiesnoconv(
'StatusTrans');
2884 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'StatusWaiting');
2885 $this->labelStatusShort[self::STATUS_TRANSFERED] = $langs->transnoentitiesnoconv(
'StatusTrans');
2886 if ($this->
type ==
'bank-transfer') {
2887 $this->labelStatus[self::STATUS_DEBITED] = $langs->transnoentitiesnoconv(
'StatusDebited');
2888 $this->labelStatusShort[self::STATUS_DEBITED] = $langs->transnoentitiesnoconv(
'StatusDebited');
2890 $this->labelStatus[self::STATUS_CREDITED] = $langs->transnoentitiesnoconv(
'StatusCredited');
2891 $this->labelStatusShort[self::STATUS_CREDITED] = $langs->transnoentitiesnoconv(
'StatusCredited');
2895 $statusType =
'status1';
2896 if ($status == self::STATUS_TRANSFERED) {
2897 $statusType =
'status3';
2899 if ($status == self::STATUS_CREDITED || $status == self::STATUS_DEBITED) {
2900 $statusType =
'status6';
2903 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
2989 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2991 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2992 $return .=
'<div class="info-box info-box-sm">';
2993 $return .=
'<span class="info-box-icon bg-infobox-action">';
2995 $return .=
'</span>';
2996 $return .=
'<div class="info-box-content">';
2997 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->
getNomUrl(1) .
'</span>';
2998 if ($selected >= 0) {
2999 $return .=
'<input id="cb' . $this->
id .
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="' . $this->
id .
'"' . ($selected ?
' checked="checked"' :
'') .
'>';
3001 if (isset($this->date_echeance)) {
3002 $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>';
3004 if (isset($this->total)) {
3005 $return .=
'<br><span class="opacitymedium">' . $langs->trans(
"Amount") .
'</span> : <span class="amount">' .
price($this->total) .
'</span>';
3007 $return .=
'<br><div class="info-box-status">' . $this->
getLibStatut(3) .
'</div>';
3008 $return .=
'</div>';
3009 $return .=
'</div>';
3010 $return .=
'</div>';
3021 if (!empty($this->
id)) {
3026 $sql =
"SELECT COUNT(*) AS nb FROM " . MAIN_DB_PREFIX .
"prelevement_lignes";
3027 $sql .=
" WHERE fk_prelevement_bons = " . ((int) $id);
3028 $sql .=
" AND fk_soc = 0";
3029 $sql .=
" AND fk_user IS NOT NULL";
3032 $resql = $this->db->query($sql);
3034 $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.