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';
65 public $date_echeance;
66 public $raison_sociale;
67 public $reference_remise;
68 public $emetteur_code_guichet;
69 public $emetteur_numero_compte;
70 public $emetteur_code_banque;
71 public $emetteur_number_key;
72 public $sepa_xml_pti_in_ctti;
74 public $emetteur_iban;
83 public $labelStatus = array();
85 public $factures = array();
90 public $methodes_trans = array();
92 public $invoice_in_error = array();
93 public $thirdparty_in_error = array();
105 const STATUS_DRAFT = 0;
106 const STATUS_TRANSFERED = 1;
107 const STATUS_CREDITED = 2;
108 const STATUS_DEBITED = 2;
154 public $fields = array(
155 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'position' => 10,
'notnull' => 1,
'visible' => 0,),
156 'ref' => array(
'type' =>
'varchar(12)',
'label' =>
'Ref',
'enabled' => 1,
'position' => 15,
'notnull' => 0,
'visible' => -1,
'csslist' =>
'tdoverflowmax150',
'showoncombobox' => 1,),
157 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'position' => 25,
'notnull' => 0,
'visible' => -1,),
158 'amount' => array(
'type' =>
'double(24,8)',
'label' =>
'Amount',
'enabled' => 1,
'position' => 30,
'notnull' => 0,
'visible' => -1,),
159 'statut' => array(
'type' =>
'smallint(6)',
'label' =>
'Statut',
'enabled' => 1,
'position' => 500,
'notnull' => 0,
'visible' => -1,
'arrayofkeyval' => array(0 =>
'Wait', 1 =>
'Transfered', 2 =>
'Credited')),
160 'credite' => array(
'type' =>
'smallint(6)',
'label' =>
'Credite',
'enabled' => 1,
'position' => 40,
'notnull' => 0,
'visible' => -1,),
161 'note' => array(
'type' =>
'text',
'label' =>
'Note',
'enabled' => 1,
'position' => 45,
'notnull' => 0,
'visible' => -1,),
162 'date_trans' => array(
'type' =>
'datetime',
'label' =>
'Datetrans',
'enabled' => 1,
'position' => 50,
'notnull' => 0,
'visible' => -1,),
163 'method_trans' => array(
'type' =>
'smallint(6)',
'label' =>
'Methodtrans',
'enabled' => 1,
'position' => 55,
'notnull' => 0,
'visible' => -1,),
164 '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',),
165 'date_credit' => array(
'type' =>
'datetime',
'label' =>
'Datecredit',
'enabled' => 1,
'position' => 65,
'notnull' => 0,
'visible' => -1,),
166 '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',),
167 'type' => array(
'type' =>
'varchar(16)',
'label' =>
'Type',
'enabled' => 1,
'position' => 75,
'notnull' => 0,
'visible' => -1,),
168 'fk_bank_account' => array(
'type' =>
'integer',
'label' =>
'Fkbankaccount',
'enabled' => 1,
'position' => 80,
'notnull' => 0,
'visible' => -1,
'css' =>
'maxwidth500 widthcentpercentminusxx',),
191 public $method_trans;
192 public $fk_user_trans;
194 public $fk_user_credit;
196 public $fk_bank_account;
210 $this->filename =
'';
212 $this->date_echeance =
dol_now();
213 $this->raison_sociale =
"";
214 $this->reference_remise =
"";
216 $this->emetteur_code_guichet =
"";
217 $this->emetteur_numero_compte =
"";
218 $this->emetteur_code_banque =
"";
219 $this->emetteur_number_key =
"";
220 $this->sepa_xml_pti_in_ctti =
false;
222 $this->emetteur_iban =
"";
223 $this->emetteur_bic =
"";
224 $this->emetteur_ics =
"";
226 $this->factures = array();
228 $this->methodes_trans = array(0 =>
'Internet', 2 =>
'Email', 3 =>
'Api');
249 public function AddFacture($invoice_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $type =
'debit-order', $sourcetype =
'')
256 $result = $this->
addline($line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype);
261 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"prelevement (";
262 if ($type !=
'bank-transfer') {
263 $sql .=
"fk_facture";
265 if ($sourcetype ==
'salary') {
268 $sql .=
"fk_facture_fourn";
271 $sql .=
",fk_prelevement_lignes";
272 $sql .=
") VALUES (";
273 $sql .= ((int) $invoice_id);
274 $sql .=
", " . ((int) $line_id);
277 if ($this->db->query($sql)) {
281 $this->errors[] = get_class($this) .
"::AddFacture " . $this->db->lasterror;
282 dol_syslog(get_class($this) .
"::AddFacture Error $result");
286 $this->errors[] = get_class($this) .
"::AddFacture linedid Empty";
287 dol_syslog(get_class($this) .
"::AddFacture Error $result");
291 dol_syslog(get_class($this) .
"::AddFacture Error $result");
311 public function addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype =
'')
320 $sql =
"SELECT rowid";
321 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_lignes";
322 $sql .=
" WHERE fk_prelevement_bons = " . ((int) $this->
id);
323 if ($sourcetype ==
'salary') {
324 $sql .=
" AND fk_soc = " . ((int) $client_id);
326 $sql .=
" AND fk_user = " . ((int) $client_id);
328 $sql .=
" AND code_banque = '" . $this->db->escape($code_banque) .
"'";
329 $sql .=
" AND code_guichet = '" . $this->db->escape($code_guichet) .
"'";
330 $sql .=
" AND number = '" . $this->db->escape($number) .
"'";
332 $resql = $this->db->query($sql);
334 $num = $this->db->num_rows($resql);
342 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"prelevement_lignes (";
343 $sql .=
"fk_prelevement_bons";
345 $sql .=
", client_nom";
347 $sql .=
", code_banque";
348 $sql .=
", code_guichet";
351 $sql .= ($sourcetype ==
'salary' ?
", fk_user" :
"");
352 $sql .=
") VALUES (";
354 $sql .=
", " . (($sourcetype !=
'salary') ? ((
int) $client_id) :
"0");
355 $sql .=
", '" . $this->db->escape($client_nom) .
"'";
356 $sql .=
", " . ((float)
price2num($amount));
357 $sql .=
", '" . $this->db->escape($code_banque) .
"'";
358 $sql .=
", '" . $this->db->escape($code_guichet) .
"'";
359 $sql .=
", '" . $this->db->escape($number) .
"'";
360 $sql .=
", '" . $this->db->escape($number_key) .
"'";
361 $sql .= (($sourcetype ==
'salary') ?
", " . ((
int) $client_id) :
'');
363 if ($this->db->query($sql)) {
364 $line_id = $this->db->last_insert_id(MAIN_DB_PREFIX .
"prelevement_lignes");
367 $this->errors[] = get_class($this) .
"::addline Error -2 " . $this->db->lasterror;
368 dol_syslog(get_class($this) .
"::addline Error -2");
388 $errors[1027] = $langs->trans(
"DateInvalid");
390 return $errors[abs($error)];
400 public function fetch($rowid, $ref =
'')
402 $sql =
"SELECT p.rowid, p.ref, p.amount, p.note";
403 $sql .=
", p.datec as dc";
404 $sql .=
", p.date_trans as date_trans";
405 $sql .=
", p.method_trans, p.fk_user_trans";
406 $sql .=
", p.date_credit as date_credit";
407 $sql .=
", p.fk_user_credit";
409 $sql .=
", p.fk_bank_account";
410 $sql .=
", p.statut as status";
411 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons as p";
412 $sql .=
" WHERE p.entity IN (" .
getEntity(
'invoice') .
")";
414 $sql .=
" AND p.rowid = " . ((int) $rowid);
416 $sql .=
" AND p.ref = '" . $this->db->escape($ref) .
"'";
419 dol_syslog(get_class($this) .
"::fetch", LOG_DEBUG);
420 $result = $this->db->query($sql);
422 if ($this->db->num_rows($result)) {
423 $obj = $this->db->fetch_object($result);
425 $this->
id = $obj->rowid;
426 $this->
ref = $obj->ref;
427 $this->amount = $obj->amount;
428 $this->note = $obj->note;
429 $this->datec = $this->db->jdate($obj->dc);
431 $this->date_trans = $this->db->jdate($obj->date_trans);
432 $this->method_trans = $obj->method_trans;
433 $this->user_trans = $obj->fk_user_trans;
435 $this->date_credit = $this->db->jdate($obj->date_credit);
436 $this->user_credit = $obj->fk_user_credit;
438 $this->
type = $obj->type;
439 $this->fk_bank_account = $obj->fk_bank_account;
441 $this->
status = $obj->status;
442 if (empty($this->
status)) {
445 $this->statut = $this->status;
451 dol_syslog(get_class($this) .
"::Fetch no record found");
484 global $conf, $langs;
488 if ($this->fetched == 1) {
489 if ($date < $this->date_trans) {
490 $langs->load(
"errors");
491 $this->error = $langs->trans(
'ErrorDateOfMovementLowerThanDateOfFileTransmission');
492 dol_syslog(
"bon-prelevment::set_infocredit 1027 " . $this->error);
498 $sql =
" UPDATE " . MAIN_DB_PREFIX .
"prelevement_bons";
499 $sql .=
" SET fk_user_credit = " . ((int) $user->id);
500 $sql .=
", statut = " . self::STATUS_CREDITED;
501 $sql .=
", date_credit = '" . $this->db->idate($date) .
"'";
502 $sql .=
" WHERE rowid = " . ((int) $this->
id);
503 $sql .=
" AND entity = " . ((int) $conf->entity);
504 $sql .=
" AND statut = " . self::STATUS_TRANSFERED;
506 $resql = $this->db->query($sql);
508 $langs->load(
'withdrawals');
509 $subject = $langs->trans(
"InfoCreditSubject", $this->
ref);
510 $message = $langs->trans(
"InfoCreditMessage", $this->
ref,
dol_print_date($date,
'dayhour'));
513 $fk_bank_account = $this->fk_bank_account;
514 if (empty($fk_bank_account)) {
519 $amountsperthirdparty = array();
529 for ($i = 0; $i < $num; $i++) {
530 if ($this->
type ==
'bank-transfer') {
531 if ($type ==
'salary') {
532 $fac =
new Salary($this->db);
540 $result = $fac->fetch($facs[$i][0]);
542 $amounts[$fac->id] = $facs[$i][1];
543 if ($this->
type ==
'bank-transfer') {
544 if ($type ==
'salary') {
545 $amountsperthirdparty[$fac->fk_user][$fac->id] = $facs[$i][1];
547 $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
550 $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
553 $totalpaid = $fac->getSommePaiement();
554 $totalcreditnotes = 0;
555 if (method_exists($fac,
'getSumCreditNotesUsed')) {
556 $totalcreditnotes = $fac->getSumCreditNotesUsed();
559 if (method_exists($fac,
'getSumDepositsUsed')) {
560 $totaldeposits = $fac->getSumDepositsUsed();
562 $alreadypayed = $totalpaid + $totalcreditnotes + $totaldeposits;
566 $amountofdocument = $fac->total_ttc;
567 if ($type ==
'salary') {
568 $amountofdocument = $fac->amount;
570 if (
price2num($alreadypayed + $facs[$i][1],
'MT') ==
price2num($amountofdocument,
'MT')) {
571 $result = $fac->setPaid($user);
573 $this->error = $fac->error;
574 $this->errors = $fac->errors;
580 foreach ($amountsperthirdparty as $thirdpartyid => $cursoramounts) {
581 if ($this->
type ==
'bank-transfer') {
582 if ($type ==
'salary') {
588 $paiement =
new Paiement($this->db);
590 $paiement->datepaye = $date;
591 $paiement->amounts = $cursoramounts;
593 if ($this->
type ==
'bank-transfer') {
594 if ($type ==
'salary') {
595 $paiement->datep = $date;
597 $paiement->paiementid = 2;
598 $paiement->fk_typepayment = 2;
599 $paiement->paiementcode =
'VIR';
601 $paiement->paiementid = 2;
602 $paiement->paiementcode =
'VIR';
605 $paiement->paiementid = 3;
606 $paiement->paiementcode =
'PRE';
609 $paiement->num_payment = $this->ref;
610 $paiement->id_prelevement = $this->id;
612 $result = $paiement->create($user);
616 $this->error = $paiement->error;
617 $this->errors = $paiement->errors;
618 dol_syslog(get_class($this) .
"::set_infocredit AddPayment Error " . $this->error);
620 if ($this->
type ==
'bank-transfer') {
621 if ($type ==
'salary') {
622 $modeforaddpayment =
'payment_salary';
623 $labelforaddpayment =
'(SalaryPayment)';
624 $addbankurl =
'credit-transfer';
626 $modeforaddpayment =
'payment_supplier';
627 $labelforaddpayment =
'(SupplierInvoicePayment)';
628 $addbankurl =
'credit-transfer';
631 $modeforaddpayment =
'payment';
632 $labelforaddpayment =
'(CustomerInvoicePayment)';
633 $addbankurl =
'direct-debit';
639 $result = $paiement->addPaymentToBank($user, $modeforaddpayment, $labelforaddpayment, $fk_bank_account,
'',
'');
641 $result = $paiement->addPaymentToBank($user, $modeforaddpayment, $labelforaddpayment, $fk_bank_account,
'',
'', 0,
'', $addbankurl);
646 $this->error = $paiement->error;
647 $this->errors = $paiement->errors;
648 dol_syslog(get_class($this) .
"::set_infocredit AddPaymentToBank Error " . $this->error);
656 $sql =
" UPDATE " . MAIN_DB_PREFIX .
"prelevement_lignes";
657 $sql .=
" SET statut = 2";
658 $sql .=
" WHERE fk_prelevement_bons = " . ((int) $this->
id);
660 if (!$this->db->query($sql)) {
661 dol_syslog(get_class($this) .
"::set_infocredit Update lines Error");
666 $this->error = $this->db->lasterror();
667 dol_syslog(get_class($this) .
"::set_infocredit Update Bons Error");
673 $this->date_credit = $date;
674 $this->statut = self::STATUS_CREDITED;
675 $this->
status = self::STATUS_CREDITED;
680 $this->db->rollback();
700 global $conf, $langs;
704 dol_syslog(get_class($this) .
"::set_infotrans Start", LOG_INFO);
706 if ($this->db->begin()) {
707 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_bons ";
708 $sql .=
" SET fk_user_trans = " . $user->id;
709 $sql .=
" , date_trans = '" . $this->db->idate($date) .
"'";
710 $sql .=
" , method_trans = " . ((int) $method);
711 $sql .=
" , statut = " . self::STATUS_TRANSFERED;
712 $sql .=
" WHERE rowid = " . ((int) $this->
id);
713 $sql .=
" AND entity = " . ((int) $conf->entity);
714 $sql .=
" AND statut = " . self::STATUS_DRAFT;
716 if ($this->db->query($sql)) {
717 $this->method_trans = $method;
718 $langs->load(
'withdrawals');
719 $subject = $langs->trans(
"InfoTransSubject", $this->
ref);
720 $message = $langs->trans(
"InfoTransMessage", $this->
ref,
dolGetFirstLastname($user->firstname, $user->lastname));
721 $message .= $langs->trans(
"InfoTransData",
price($this->amount), $this->methodes_trans[$this->method_trans],
dol_print_date($date,
'day'));
729 $this->date_trans = $date;
730 $this->statut = self::STATUS_TRANSFERED;
731 $this->
status = self::STATUS_TRANSFERED;
732 $this->user_trans = $user->id;
738 $this->db->rollback();
739 dol_syslog(get_class($this) .
"::set_infotrans ROLLBACK", LOG_ERR);
744 dol_syslog(get_class($this) .
"::set_infotrans Ouverture transaction SQL impossible", LOG_CRIT);
763 dol_syslog(get_class($this) .
"::getListInvoices");
767 if ($this->
type ==
'bank-transfer') {
768 if ($type ==
'salary') {
769 $sql .=
" p.fk_salary";
771 $sql .=
" p.fk_facture_fourn";
774 $sql .=
" p.fk_facture";
777 $sql .=
", SUM(pl.amount)";
779 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons as pb,";
780 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
781 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p";
782 $sql .=
" WHERE p.fk_prelevement_lignes = pl.rowid";
783 $sql .=
" AND pl.fk_prelevement_bons = pb.rowid";
784 $sql .=
" AND pb.rowid = " . ((int) $this->
id);
785 $sql .=
" AND pb.entity = " . ((int) $conf->entity);
787 if ($this->
type ==
'bank-transfer') {
788 if ($type ==
'salary') {
789 $sql .=
" GROUP BY p.fk_salary";
791 $sql .=
" GROUP BY p.fk_facture_fourn";
794 $sql .=
" GROUP BY p.fk_facture";
798 $resql = $this->db->query($sql);
800 $num = $this->db->num_rows($resql);
805 $row = $this->db->fetch_row($resql);
817 $this->db->free($resql);
819 $this->error = $this->db->lasterror();
836 $sql =
"SELECT sum(pd.amount) as nb";
837 if ($type !==
'salary') {
838 if ($mode !=
'bank-transfer') {
839 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f,";
841 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture_fourn as f,";
844 $sql .=
" FROM " . MAIN_DB_PREFIX .
"salary as s,";
846 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_demande as pd";
847 $sql .= ($type !==
'salary' ?
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")" :
" WHERE s.entity IN (" .
getEntity(
'salary') .
")");
849 $sql .= ($type !==
'salary' ?
" AND f.fk_statut = " .
Facture::STATUS_VALIDATED :
" AND s.paye = " . Salary::STATUS_UNPAID);
851 if ($type !==
'salary') {
852 if ($mode !=
'bank-transfer') {
853 $sql .=
" AND f.rowid = pd.fk_facture";
855 $sql .=
" AND f.rowid = pd.fk_facture_fourn";
858 $sql .=
" AND s.rowid = pd.fk_salary";
860 $sql .= ($type !==
'salary' ?
" AND f.paye = 0" :
"");
861 $sql .=
" AND pd.traite = 0";
862 $sql .=
" AND pd.ext_payment_id IS NULL";
863 $sql .= ($type !==
'salary' ?
" AND f.total_ttc > 0" :
"");
865 $resql = $this->db->query($sql);
867 $obj = $this->db->fetch_object($resql);
869 $this->db->free($resql);
874 dol_syslog(get_class($this) .
"::SommeAPrelever Erreur -1");
890 if ($type ===
'salary') {
908 if ($forsalary == 1) {
909 $sql =
"SELECT count(s.rowid) as nb";
910 $sql .=
" FROM " . MAIN_DB_PREFIX .
"salary as s";
912 $sql =
"SELECT count(f.rowid) as nb";
914 if ($type ==
'bank-transfer') {
915 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture_fourn as f";
917 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
920 $sql .=
", " . MAIN_DB_PREFIX .
"prelevement_demande as pd";
921 if ($forsalary == 1) {
922 $sql .=
" WHERE s.entity IN (" .
getEntity(
'invoice') .
")";
924 $sql .=
" AND s.paye = 0";
927 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")";
932 if ($forsalary == 1) {
933 $sql .=
" AND s.rowid = pd.fk_salary";
935 if ($type ==
'bank-transfer') {
936 $sql .=
" AND f.rowid = pd.fk_facture_fourn";
938 $sql .=
" AND f.rowid = pd.fk_facture";
941 $sql .=
" AND pd.traite = 0";
942 $sql .=
" AND pd.ext_payment_id IS NULL";
943 if (!$forsalary == 1) {
944 $sql .=
" AND f.total_ttc > 0";
946 $sql .=
" AND s.paye = 0";
949 dol_syslog(get_class($this) .
"::NbFactureAPrelever");
950 $resql = $this->db->query($sql);
953 $obj = $this->db->fetch_object($resql);
954 $this->db->free($resql);
958 $this->error = get_class($this) .
"::NbFactureAPrelever Erreur -1 sql=" . $this->db->error();
985 public function create($banque = 0, $agence = 0, $mode =
'real', $format =
'ALL', $executiondate =
'', $notrigger = 0, $type =
'direct-debit', $did = 0, $fk_bank_account = 0, $sourcetype =
'invoice')
988 global $conf, $langs, $user;
990 dol_syslog(__METHOD__ .
" Bank=" . $banque .
" Office=" . $agence .
" mode=" . $mode .
" format=" . $format, LOG_DEBUG);
992 require_once DOL_DOCUMENT_ROOT .
"/compta/facture/class/facture.class.php";
993 require_once DOL_DOCUMENT_ROOT .
"/societe/class/societe.class.php";
996 if ($type !=
'bank-transfer') {
997 if (empty($format)) {
998 $this->error =
'ErrorBadParametersForDirectDebitFileCreate';
1004 if (empty($fk_bank_account)) {
1005 $fk_bank_account = ($type ==
'bank-transfer' ?
getDolGlobalInt(
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') :
getDolGlobalInt(
'PRELEVEMENT_ID_BANKACCOUNT'));
1010 $datetimeprev =
dol_now(
'gmt');
1012 if (!empty($executiondate)) {
1013 $datetimeprev = $executiondate;
1019 $this->invoice_in_error = array();
1020 $this->thirdparty_in_error = array();
1023 $factures = array();
1024 $factures_prev = array();
1025 $factures_result = array();
1026 $factures_prev_id = array();
1027 $factures_errors = array();
1029 dol_syslog(__METHOD__ .
" Read invoices for did=" . ((
int) $did), LOG_DEBUG);
1031 $sql =
"SELECT f.rowid, pd.rowid as pfdrowid";
1032 if ($sourcetype !=
'salary') {
1033 $sql .=
", f.fk_soc";
1035 $sql .=
", f.fk_user";
1037 $sql .=
", pd.code_banque, pd.code_guichet, pd.number, pd.cle_rib";
1038 $sql .=
", pd.amount";
1039 if ($sourcetype !=
'salary') {
1040 $sql .=
", s.nom as name";
1041 $sql .=
", f.ref, sr.bic, sr.iban_prefix, sr.frstrecur";
1043 $sql .=
", CONCAT(s.firstname,' ',s.lastname) as name";
1044 $sql .=
", f.ref, sr.bic, sr.iban_prefix, 'FRST' as frstrecur";
1046 if ($sourcetype !=
'salary') {
1047 if ($type !=
'bank-transfer') {
1048 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
1049 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"prelevement_demande as pd ON f.rowid = pd.fk_facture";
1051 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture_fourn as f";
1052 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"prelevement_demande as pd ON f.rowid = pd.fk_facture_fourn";
1054 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe as s ON s.rowid = f.fk_soc";
1055 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_rib as sr ON s.rowid = sr.fk_soc AND sr.default_rib = 1";
1057 $sql .=
" FROM " . MAIN_DB_PREFIX .
"salary as f";
1058 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"prelevement_demande as pd ON f.rowid = pd.fk_salary";
1059 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"user as s ON s.rowid = f.fk_user";
1060 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"user_rib as sr ON s.rowid = sr.fk_user";
1062 if ($sourcetype !=
'salary') {
1063 if ($type !=
'bank-transfer') {
1064 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
')';
1066 $sql .=
" WHERE f.entity IN (" .
getEntity(
'supplier_invoice') .
')';
1069 $sql .=
" WHERE f.entity IN (" .
getEntity(
'salary') .
')';
1071 if ($sourcetype !=
'salary') {
1072 $sql .=
" AND f.fk_statut = 1";
1073 $sql .=
" AND f.paye = 0";
1074 $sql .=
" AND f.total_ttc > 0";
1077 $sql .=
" AND f.paye = 0";
1078 $sql .=
" AND f.amount > 0";
1080 $sql .=
" AND pd.traite = 0";
1081 $sql .=
" AND pd.ext_payment_id IS NULL";
1082 if ($sourcetype !=
'salary') {
1083 $sql .=
" AND sr.type = 'ban'";
1086 $sql .=
" AND pd.rowid = " . ((int) $did);
1089 $resql = $this->db->query($sql);
1091 $num = $this->db->num_rows($resql);
1095 $row = $this->db->fetch_row($resql);
1096 $factures[$i] = $row;
1100 dol_syslog(__METHOD__ .
" Read invoices/salary error Found a null amount", LOG_ERR);
1101 $this->invoice_in_error[$row[0]] =
"Error for invoice or salary id " . $row[0] .
", found a null amount";
1107 $this->db->free($resql);
1108 dol_syslog(__METHOD__ .
" Read invoices/salary, " . $i .
" invoices/salary to withdraw", LOG_DEBUG);
1111 $this->error = $this->db->lasterror();
1112 dol_syslog(__METHOD__ .
" Read invoices/salary error " . $this->db->lasterror(), LOG_ERR);
1119 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1120 require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
1121 require_once DOL_DOCUMENT_ROOT .
'/societe/class/companybankaccount.class.php';
1122 require_once DOL_DOCUMENT_ROOT .
'/core/lib/bank.lib.php';
1124 $tmpsoc =
new Societe($this->db);
1125 $tmpuser =
new User($this->db);
1129 dol_syslog(__METHOD__ .
" Check BAN", LOG_DEBUG);
1131 if (count($factures) > 0) {
1132 foreach ($factures as $key => $fac) {
1144 if ($fac[8] !=
null) {
1145 if ($type !=
'bank-transfer') {
1146 if ($format ==
'FRST' && $fac[12] !=
'FRST') {
1149 if ($format ==
'RCUR' && $fac[12] !=
'RCUR') {
1155 if ($verif || (empty($fac[10]) &&
getDolGlobalInt(
"WITHDRAWAL_WITHOUT_BIC"))) {
1160 $factures_prev[$i] = $fac;
1162 $factures_prev_id[$i] = $fac[0];
1166 if ($type !=
'bank-transfer') {
1167 $tmpsoc->id = $fac[2];
1168 $tmpsoc->name = $fac[8];
1169 $invoice_url =
"<a href='" . DOL_URL_ROOT .
'/compta/facture/card.php?facid=' . $fac[0] .
"'>" . $fac[9] .
"</a>";
1170 $this->invoice_in_error[$fac[0]] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1171 $this->thirdparty_in_error[$tmpsoc->id] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1174 if ($type ==
'bank-transfer' && $sourcetype !=
'salary') {
1175 $tmpsoc->id = $fac[2];
1176 $tmpsoc->name = $fac[8];
1177 $invoice_url =
"<a href='" . DOL_URL_ROOT .
'/fourn/facture/card.php?facid=' . $fac[0] .
"'>" . $fac[9] .
"</a>";
1178 $this->invoice_in_error[$fac[0]] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1179 $this->thirdparty_in_error[$tmpsoc->id] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1182 if ($type ==
'bank-transfer' && $sourcetype ==
'salary') {
1183 $tmpuser->id = $fac[2];
1184 $tmpuser->firstname = $fac[8];
1185 $salary_url =
"<a href='" . DOL_URL_ROOT .
'/salaries/card.php?id=' . $fac[0] .
"'>" . $fac[0] .
"</a>";
1186 $this->invoice_in_error[$fac[0]] =
"Error on default bank number IBAN/BIC for salary " . $salary_url .
" for employee " . $tmpuser->getNomUrl(0);
1187 $this->thirdparty_in_error[$tmpuser->id] =
"Error on default bank number IBAN/BIC for salary " . $salary_url .
" for employee " . $tmpuser->getNomUrl(0);
1190 dol_syslog(__METHOD__ .
" Check BAN Error on default bank number IBAN/BIC reported by verif(): " . implode(
', ', $fac), LOG_WARNING);
1193 dol_syslog(__METHOD__ .
" Check BAN Failed to read company", LOG_WARNING);
1202 dol_syslog(__METHOD__ .
" Check BAN No invoice to process", LOG_WARNING);
1209 $out = count($factures_prev) .
" invoices will be included.";
1222 if (count($factures_prev) > 0) {
1223 if ($mode ==
'real') {
1226 print $langs->trans(
"ModeWarning");
1243 $ref = substr($year, -2) . $month;
1246 $sql =
"SELECT substring(ref from char_length(ref) - 1)";
1247 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons";
1248 $sql .=
" WHERE ref LIKE '_" . $this->db->escape($ref) .
"%'";
1249 $sql .=
" AND entity = " . ((int) $conf->entity);
1250 $sql .=
" ORDER BY ref DESC LIMIT 1";
1252 dol_syslog(get_class($this) .
" get next free number", LOG_DEBUG);
1253 $resql = $this->db->query($sql);
1256 $row = $this->db->fetch_row($resql);
1259 $ref =
"T" . $ref . sprintf(
"%02d", (intval($row[0]) + 1));
1265 if ($type !=
'bank-transfer') {
1266 $dir = $conf->prelevement->dir_output .
'/receipts';
1268 $dir = $conf->paymentbybanktransfer->dir_output .
'/receipts';
1270 if (!is_dir($dir)) {
1274 if (isModEnabled(
'multicompany')) {
1275 $labelentity = $conf->entity;
1276 $this->filename = $dir .
'/' . $ref .
'-' . $labelentity .
'.xml';
1278 $this->filename = $dir .
'/' . $ref .
'.xml';
1282 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"prelevement_bons (";
1283 $sql .=
"ref, entity, datec, type, fk_bank_account";
1284 $sql .=
") VALUES (";
1285 $sql .=
"'" . $this->db->escape($ref) .
"'";
1286 $sql .=
", " . ((int) $conf->entity);
1287 $sql .=
", '" . $this->db->idate($now) .
"'";
1288 $sql .=
", '" . ($type ==
'bank-transfer' ?
'bank-transfer' :
'debit-order') .
"'";
1289 $sql .=
", " . ((int) $fk_bank_account);
1292 $resql = $this->db->query($sql);
1296 $prev_id = $this->db->last_insert_id(MAIN_DB_PREFIX .
"prelevement_bons");
1297 $this->
id = $prev_id;
1301 dol_syslog(__METHOD__ .
" Create withdraw receipt " . $this->db->lasterror(), LOG_ERR);
1305 dol_syslog(__METHOD__ .
" Get last withdraw receipt " . $this->db->lasterror(), LOG_ERR);
1310 dol_syslog(__METHOD__ .
" Now loop on each document to insert them in llx_prelevement_demande");
1313 if (count($factures_prev) > 0) {
1314 foreach ($factures_prev as $fac) {
1332 $ri = $this->
AddFacture($fac[0], $fac[2], $fac[8], $fac[7], $fac[3], $fac[4], $fac[5], $fac[6], $type, $sourcetype);
1339 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_demande";
1340 $sql .=
" SET traite = 1";
1341 $sql .=
", date_traite = '" . $this->db->idate($now) .
"'";
1342 $sql .=
", fk_prelevement_bons = " . ((int) $this->
id);
1343 $sql .=
" WHERE rowid = " . ((int) $fac[1]);
1345 $resql = $this->db->query($sql);
1348 $this->errors[] = $this->db->lasterror();
1349 dol_syslog(__METHOD__ .
" Update Error=" . $this->db->lasterror(), LOG_ERR);
1360 dol_syslog(__METHOD__ .
" Init direct debit or credit transfer file for " . count($factures_prev) .
" invoices", LOG_DEBUG);
1362 if (count($factures_prev) > 0) {
1363 $this->date_echeance = $datetimeprev;
1364 $this->reference_remise = $ref;
1366 $account =
new Account($this->db);
1367 if ($account->fetch($fk_bank_account) > 0) {
1368 $this->emetteur_code_banque = $account->code_banque;
1369 $this->emetteur_code_guichet = $account->code_guichet;
1370 $this->emetteur_numero_compte = $account->number;
1371 $this->emetteur_number_key = $account->cle_rib;
1372 $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
1373 $this->emetteur_iban = $account->iban;
1374 $this->emetteur_bic = $account->bic;
1376 $this->emetteur_ics = (($type ==
'bank-transfer' &&
getDolGlobalString(
"SEPA_USE_IDS")) ? $account->ics_transfer : $account->ics);
1378 $this->raison_sociale = $account->proprio;
1380 $this->factures = $factures_prev_id;
1381 $this->context[
'factures_prev'] = $factures_prev;
1385 if ($sourcetype ==
'salary') {
1386 $userid = $this->context[
'factures_prev'][0][2];
1388 $result = $this->
generate($format, $executiondate, $type, $fk_bank_account, $userid);
1395 dol_syslog(__METHOD__ .
" Bank order file has been generated under filename " . $this->filename, LOG_DEBUG);
1403 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_bons";
1404 $sql .=
" SET amount = " .
price2num($this->total);
1405 $sql .=
" WHERE rowid = " . ((int) $this->
id);
1406 $sql .=
" AND entity = " . ((int) $conf->entity);
1407 $resql = $this->db->query($sql);
1411 dol_syslog(__METHOD__ .
" Error update total: " . $this->db->error(), LOG_ERR);
1415 if (!$error && !$notrigger) {
1416 $triggername =
'DIRECT_DEBIT_ORDER_CREATE';
1417 if ($type !=
'bank-transfer') {
1418 $triggername =
'CREDIT_TRANSFER_ORDER_CREATE';
1430 $this->db->commit();
1431 return count($factures_prev);
1433 $this->db->rollback();
1449 public function delete($user =
null, $notrigger = 0)
1454 $resql1 = $resql2 = $resql3 = $resql4 = 0;
1457 $triggername =
'DIRECT_DEBIT_ORDER_DELETE';
1458 if ($this->
type ==
'bank-transfer') {
1459 $triggername =
'PAYMENTBYBANKTRANFER_DELETE';
1470 $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) .
")";
1471 $resql1 = $this->db->query($sql);
1478 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"prelevement_lignes WHERE fk_prelevement_bons = " . ((int) $this->
id);
1479 $resql2 = $this->db->query($sql);
1486 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"prelevement_bons WHERE rowid = " . ((int) $this->
id);
1487 $resql3 = $this->db->query($sql);
1494 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_demande SET fk_prelevement_bons = NULL, traite = 0 WHERE fk_prelevement_bons = " . ((int) $this->
id);
1495 $resql4 = $this->db->query($sql);
1501 if ($resql1 && $resql2 && $resql3 && $resql4 && !$error) {
1502 $this->db->commit();
1505 $this->db->rollback();
1521 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1523 global $conf, $langs, $hookmanager;
1525 if (!empty($conf->dol_no_mouse_hover)) {
1531 $labeltoshow =
'PaymentByDirectDebit';
1532 if (!empty($this->
type) && $this->
type ==
'bank-transfer') {
1533 $labeltoshow =
'PaymentByBankTransfer';
1536 $label =
img_picto(
'', $this->picto) .
' <u>' . $langs->trans($labeltoshow) .
'</u> ' . $this->
getLibStatut(5);
1538 $label .=
'<b>' . $langs->trans(
'Ref') .
':</b> ' . $this->ref;
1539 if (isset($this->amount)) {
1540 $label .=
'<br><b>' . $langs->trans(
"Amount") .
":</b> " .
price($this->amount);
1542 if (isset($this->date_trans)) {
1543 $label .=
'<br><b>' . $langs->trans(
"TransData") .
":</b> " .
dol_print_date($this->date_trans,
'dayhour',
'tzuserrel');
1549 $url = DOL_URL_ROOT .
'/compta/prelevement/card.php?id=' . $this->id;
1550 if (!empty($this->
type) && $this->
type ==
'bank-transfer') {
1551 $url = DOL_URL_ROOT .
'/compta/prelevement/card.php?id=' . $this->id;
1554 if ($option !=
'nolink') {
1556 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1557 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1558 $add_save_lastsearch_values = 1;
1560 if ($add_save_lastsearch_values) {
1561 $url .=
'&save_lastsearch_values=1';
1566 if (empty($notooltip)) {
1568 $label = $langs->trans(
"ShowMyObject");
1572 $linkclose .=
' class="classfortooltip' . ($morecss ?
' ' . $morecss :
'') .
'"';
1574 $linkclose = ($morecss ?
' class="' . $morecss .
'"' :
'');
1577 $linkstart =
'<a href="' . $url .
'"';
1578 $linkstart .= $linkclose .
'>';
1581 $result .= $linkstart;
1583 $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);
1585 if ($withpicto != 2) {
1586 $result .= $this->ref;
1588 $result .= $linkend;
1590 global $action, $hookmanager;
1591 $hookmanager->initHooks(array(
'banktransferdao'));
1592 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1593 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1595 $result = $hookmanager->resPrint;
1597 $result .= $hookmanager->resPrint;
1612 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"notify_def";
1613 $sql .=
" WHERE rowid = " . ((int) $rowid);
1615 if ($this->db->query($sql)) {
1631 if (is_object($user)) {
1632 $userid = $user->id;
1637 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"notify_def";
1638 $sql .=
" WHERE fk_user=" . ((int) $userid) .
" AND fk_action='" . $this->db->escape($action) .
"'";
1640 if ($this->db->query($sql)) {
1661 if (is_object($user)) {
1662 $userid = $user->id;
1670 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"notify_def (datec,fk_user, fk_soc, fk_contact, fk_action)";
1671 $sql .=
" VALUES ('" . $this->db->idate($now) .
"', " . ((int) $userid) .
", 'NULL', 'NULL', '" . $this->db->escape($action) .
"')";
1674 if ($this->db->query($sql)) {
1678 dol_syslog(get_class($this) .
"::addNotification Error $result");
1700 public function generate($format =
'ALL', $executiondate = 0, $type =
'direct-debit', $fk_bank_account = 0, $forsalary = 0)
1702 global $conf, $langs, $mysoc;
1707 if (empty($fk_bank_account)) {
1708 $fk_bank_account = ($type ==
'bank-transfer' ?
getDolGlobalInt(
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') :
getDolGlobalInt(
'PRELEVEMENT_ID_BANKACCOUNT'));
1713 dol_syslog(get_class($this) .
"::generate build file=" . $this->filename .
" type=" . $type);
1715 $this->file = fopen($this->filename,
"w");
1716 if ($this->file ==
false) {
1717 $this->error = $langs->trans(
'ErrorFailedToOpenFile', $this->filename);
1725 if ($mysoc->isInEEC()) {
1728 if ($type !=
'bank-transfer') {
1740 if (!empty($executiondate)) {
1741 $date_actu = $executiondate;
1746 $fileDebiteurSection =
'';
1747 $fileEmetteurSection =
'';
1754 $sql =
"SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
1755 $sql .=
" pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
1756 $sql .=
" f.ref as reffac, p.fk_facture as idfac,";
1757 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
1759 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
1760 $sql .=
" " . MAIN_DB_PREFIX .
"facture as f,";
1761 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p,";
1762 $sql .=
" " . MAIN_DB_PREFIX .
"societe as soc,";
1763 $sql .=
" " . MAIN_DB_PREFIX .
"c_country as c,";
1764 $sql .=
" " . MAIN_DB_PREFIX .
"societe_rib as rib";
1765 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
1766 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
1767 $sql .=
" AND p.fk_facture = f.rowid";
1768 $sql .=
" AND f.fk_soc = soc.rowid";
1769 $sql .=
" AND soc.fk_pays = c.rowid";
1770 $sql .=
" AND rib.fk_soc = f.fk_soc";
1771 $sql .=
" AND rib.default_rib = 1";
1772 $sql .=
" AND rib.type = 'ban'";
1775 $resql = $this->db->query($sql);
1777 $cachearraytotestduplicate = array();
1779 $num = $this->db->num_rows($resql);
1781 $obj = $this->db->fetch_object($resql);
1783 if (!empty($cachearraytotestduplicate[$obj->idfac])) {
1784 $this->error = $langs->trans(
'ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
1785 $this->invoice_in_error[$obj->idfac] = $this->error;
1789 $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
1791 $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
1793 $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, $obj->iban, $obj->bic, $daterum, $obj->drum, $obj->rum, $type);
1795 $this->total += $obj->somme;
1798 $nbtotalDrctDbtTxInf = $i;
1800 $this->error = $this->db->lasterror();
1801 fwrite($this->file,
'ERROR DEBITOR ' . $sql . $CrLf);
1806 if ($result != -2) {
1807 $fileEmetteurSection .= $this->
EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type, $fk_bank_account);
1811 $this->total = number_format((
float)
price2num($this->total,
'MT'), 2,
".",
"");
1818 fwrite($this->file,
'<' .
'?xml version="1.0" encoding="UTF-8" standalone="yes"?' .
'>' . $CrLf);
1819 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);
1820 fwrite($this->file,
' <CstmrDrctDbtInitn>' . $CrLf);
1822 fwrite($this->file,
' <GrpHdr>' . $CrLf);
1823 fwrite($this->file,
' <MsgId>' . (
'DD/' . $dateTime_YMD .
'/REF' . $this->
id) .
'</MsgId>' . $CrLf);
1824 fwrite($this->file,
' <CreDtTm>' . $dateTime_ECMA .
'</CreDtTm>' . $CrLf);
1825 fwrite($this->file,
' <NbOfTxs>' . $i .
'</NbOfTxs>' . $CrLf);
1826 fwrite($this->file,
' <CtrlSum>' . $this->total .
'</CtrlSum>' . $CrLf);
1827 fwrite($this->file,
' <InitgPty>' . $CrLf);
1829 fwrite($this->file,
' <Id>' . $CrLf);
1830 fwrite($this->file,
' <PrvtId>' . $CrLf);
1831 fwrite($this->file,
' <Othr>' . $CrLf);
1832 fwrite($this->file,
' <Id>' . $this->emetteur_ics .
'</Id>' . $CrLf);
1833 fwrite($this->file,
' </Othr>' . $CrLf);
1834 fwrite($this->file,
' </PrvtId>' . $CrLf);
1835 fwrite($this->file,
' </Id>' . $CrLf);
1836 fwrite($this->file,
' </InitgPty>' . $CrLf);
1837 fwrite($this->file,
' </GrpHdr>' . $CrLf);
1839 if ($result != -2) {
1840 fwrite($this->file, $fileEmetteurSection);
1843 if ($result != -2) {
1844 fwrite($this->file, $fileDebiteurSection);
1847 fwrite($this->file,
' </PmtInf>' . $CrLf);
1848 fwrite($this->file,
' </CstmrDrctDbtInitn>' . $CrLf);
1849 fwrite($this->file,
'</Document>' . $CrLf);
1862 if (!empty($executiondate)) {
1863 $date_actu = $executiondate;
1868 $fileCrediteurSection =
'';
1869 $fileEmetteurSection =
'';
1875 if (!empty($forsalary)) {
1876 $sql =
"SELECT u.rowid as userId, u.address, u.zip, u.town, c.code as country_code, CONCAT(u.firstname,' ',u.lastname) as nom,";
1877 $sql .=
" pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
1878 $sql .=
" s.ref as reffac, p.fk_salary as idfac,";
1879 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, '' as rum, '' as date_rum";
1881 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
1882 $sql .=
" " . MAIN_DB_PREFIX .
"salary as s,";
1883 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p,";
1884 $sql .=
" " . MAIN_DB_PREFIX .
"user as u";
1885 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"c_country as c ON u.fk_country = c.rowid,";
1886 $sql .=
" " . MAIN_DB_PREFIX .
"user_rib as rib";
1887 $sql .=
" WHERE pl.fk_prelevement_bons=" . ((int) $this->
id);
1888 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
1889 $sql .=
" AND p.fk_salary = s.rowid";
1890 $sql .=
" AND s.fk_user = u.rowid";
1891 $sql .=
" AND rib.fk_user = s.fk_user";
1893 $sql =
"SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
1894 $sql .=
" pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
1895 $sql .=
" f.ref as reffac, f.ref_supplier as fac_ref_supplier, p.fk_facture_fourn as idfac,";
1896 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
1898 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
1899 $sql .=
" " . MAIN_DB_PREFIX .
"facture_fourn as f,";
1900 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p,";
1901 $sql .=
" " . MAIN_DB_PREFIX .
"societe as soc";
1902 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"c_country as c ON soc.fk_pays = c.rowid,";
1903 $sql .=
" " . MAIN_DB_PREFIX .
"societe_rib as rib";
1904 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
1905 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
1906 $sql .=
" AND p.fk_facture_fourn = f.rowid";
1907 $sql .=
" AND f.fk_soc = soc.rowid";
1908 $sql .=
" AND rib.fk_soc = f.fk_soc";
1909 $sql .=
" AND rib.default_rib = 1";
1910 $sql .=
" AND rib.type = 'ban'";
1913 $resql = $this->db->query($sql);
1915 $cachearraytotestduplicate = array();
1917 $num = $this->db->num_rows($resql);
1919 $obj = $this->db->fetch_object($resql);
1920 if (!empty($cachearraytotestduplicate[$obj->idfac])) {
1921 $this->error = $langs->trans(
'ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
1922 $this->invoice_in_error[$obj->idfac] = $this->error;
1926 $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
1928 $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
1929 $refobj = $obj->reffac;
1930 if (empty($refobj) && !empty($forsalary)) {
1931 $refobj =
"SAL" . $obj->idfac;
1934 $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, $obj->iban, $obj->bic, $daterum, $obj->drum, $obj->rum, $type, $obj->fac_ref_supplier);
1936 $this->total += $obj->somme;
1939 $nbtotalDrctDbtTxInf = $i;
1941 $this->error = $this->db->lasterror();
1942 fwrite($this->file,
'ERROR CREDITOR ' . $sql . $CrLf);
1946 if ($result != -2) {
1947 $fileEmetteurSection .= $this->
EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type);
1951 $this->total = number_format((
float)
price2num($this->total,
'MT'), 2,
".",
"");
1958 fwrite($this->file,
'<' .
'?xml version="1.0" encoding="UTF-8" standalone="yes"?' .
'>' . $CrLf);
1959 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);
1960 fwrite($this->file,
' <CstmrCdtTrfInitn>' . $CrLf);
1962 fwrite($this->file,
' <GrpHdr>' . $CrLf);
1963 fwrite($this->file,
' <MsgId>' . (
'TRF/' . $dateTime_YMD .
'/REF' . $this->
id) .
'</MsgId>' . $CrLf);
1964 fwrite($this->file,
' <CreDtTm>' . $dateTime_ECMA .
'</CreDtTm>' . $CrLf);
1965 fwrite($this->file,
' <NbOfTxs>' . $i .
'</NbOfTxs>' . $CrLf);
1966 fwrite($this->file,
' <CtrlSum>' . $this->total .
'</CtrlSum>' . $CrLf);
1967 fwrite($this->file,
' <InitgPty>' . $CrLf);
1969 fwrite($this->file,
' <Id>' . $CrLf);
1970 fwrite($this->file,
' <PrvtId>' . $CrLf);
1971 fwrite($this->file,
' <Othr>' . $CrLf);
1972 fwrite($this->file,
' <Id>' . $this->emetteur_ics .
'</Id>' . $CrLf);
1973 fwrite($this->file,
' </Othr>' . $CrLf);
1974 fwrite($this->file,
' </PrvtId>' . $CrLf);
1975 fwrite($this->file,
' </Id>' . $CrLf);
1976 fwrite($this->file,
' </InitgPty>' . $CrLf);
1977 fwrite($this->file,
' </GrpHdr>' . $CrLf);
1979 if ($result != -2) {
1980 fwrite($this->file, $fileEmetteurSection);
1983 if ($result != -2) {
1984 fwrite($this->file, $fileCrediteurSection);
1987 fwrite($this->file,
' </PmtInf>' . $CrLf);
1988 fwrite($this->file,
' </CstmrCdtTrfInitn>' . $CrLf);
1989 fwrite($this->file,
'</Document>' . $CrLf);
1995 if ($type !=
'bank-transfer') {
1996 $sql =
"SELECT pl.amount";
1998 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
1999 $sql .=
" " . MAIN_DB_PREFIX .
"facture as f,";
2000 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p";
2001 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
2002 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
2003 $sql .=
" AND p.fk_facture = f.rowid";
2007 $resql = $this->db->query($sql);
2009 $num = $this->db->num_rows($resql);
2012 $obj = $this->db->fetch_object($resql);
2013 $this->total += $obj->amount;
2022 $sql =
"SELECT pl.amount";
2024 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
2025 $sql .=
" " . MAIN_DB_PREFIX .
"facture_fourn as f,";
2026 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p";
2027 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
2028 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
2029 $sql .=
" AND p.fk_facture_fourn = f.rowid";
2032 $resql = $this->db->query($sql);
2034 $num = $this->db->num_rows($resql);
2037 $obj = $this->db->fetch_object($resql);
2038 $this->total += $obj->amount;
2048 $langs->load(
'withdrawals');
2051 fwrite($this->file, $langs->transnoentitiesnoconv(
'WithdrawalFileNotCapable', $mysoc->country_code));
2054 fclose($this->file);
2076 return $pre .
'-' .
dol_print_date($row_datec,
'dayhourlogsmall') .
'-' .
dol_trunc($row_drum . ($row_code_client ?
'-' . $row_code_client :
''), 13,
'right',
'UTF-8', 1);
2097 public function EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $ref, $facid, $rib_dom =
'', $type =
'direct-debit')
2100 fwrite($this->file,
"06");
2101 fwrite($this->file,
"08");
2103 fwrite($this->file,
" ");
2105 fwrite($this->file, $this->emetteur_ics);
2109 fwrite($this->file,
" ");
2110 fwrite($this->file,
dol_print_date($this->date_echeance,
"%d%m",
'gmt'));
2111 fwrite($this->file, substr(
dol_print_date($this->date_echeance,
"%y",
'gmt'), 1));
2115 fwrite($this->file, substr(strtoupper($client_nom) .
" ", 0, 24));
2118 $address = strtr($rib_dom, array(
" " =>
"-", chr(13) =>
" ", chr(10) =>
""));
2119 fwrite($this->file, substr($address .
" ", 0, 24));
2123 fwrite($this->file, substr(
" ", 0, 8));
2127 fwrite($this->file, $rib_guichet);
2131 fwrite($this->file, substr(
"000000000000000" . $rib_number, -11));
2135 $montant = (round($amount, 2) * 100);
2137 fwrite($this->file, substr(
"000000000000000" . $montant, -16));
2141 fwrite($this->file, substr(
"*_" . $ref .
"_RDVnet" . $rowid .
" ", 0, 31));
2145 fwrite($this->file, $rib_banque);
2149 fwrite($this->file, substr(
" ", 0, 5));
2151 fwrite($this->file,
"\n");
2181 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 =
'')
2187 $row_somme = number_format((
float)
price2num($row_somme,
'MT'), 2,
".",
"");
2189 $row_somme = round((
float) $row_somme, 2);
2192 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
2195 $Rowing = sprintf(
"%010d", $row_idfac);
2199 $Rum = (empty($row_rum) ? $this->
buildRumNumber($row_code_client, $row_datec, $row_drum) : $row_rum);
2204 if ($type !=
'bank-transfer') {
2207 $XML_DEBITOR .=
' <DrctDbtTxInf>' . $CrLf;
2208 $XML_DEBITOR .=
' <PmtId>' . $CrLf;
2210 $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;
2211 $XML_DEBITOR .=
' </PmtId>' . $CrLf;
2212 $XML_DEBITOR .=
' <InstdAmt Ccy="EUR">' . $row_somme .
'</InstdAmt>' . $CrLf;
2213 $XML_DEBITOR .=
' <DrctDbtTx>' . $CrLf;
2214 $XML_DEBITOR .=
' <MndtRltdInf>' . $CrLf;
2215 $XML_DEBITOR .=
' <MndtId>' . $Rum .
'</MndtId>' . $CrLf;
2216 $XML_DEBITOR .=
' <DtOfSgntr>' . $DtOfSgntr .
'</DtOfSgntr>' . $CrLf;
2217 $XML_DEBITOR .=
' <AmdmntInd>false</AmdmntInd>' . $CrLf;
2218 $XML_DEBITOR .=
' </MndtRltdInf>' . $CrLf;
2219 $XML_DEBITOR .=
' </DrctDbtTx>' . $CrLf;
2220 $XML_DEBITOR .=
' <DbtrAgt>' . $CrLf;
2221 $XML_DEBITOR .=
' <FinInstnId>' . $CrLf;
2223 $XML_DEBITOR .=
' <BIC>' . $row_bic .
'</BIC>' . $CrLf;
2225 $XML_DEBITOR .=
' </FinInstnId>' . $CrLf;
2226 $XML_DEBITOR .=
' </DbtrAgt>' . $CrLf;
2227 $XML_DEBITOR .=
' <Dbtr>' . $CrLf;
2229 $XML_DEBITOR .=
' <PstlAdr>' . $CrLf;
2230 $XML_DEBITOR .=
' <Ctry>' . $row_country_code .
'</Ctry>' . $CrLf;
2231 $addressline1 = strtr($row_address, array(chr(13) =>
", ", chr(10) =>
""));
2232 $addressline2 = strtr($row_zip . (($row_zip && $row_town) ?
' ' : (string) $row_town), array(chr(13) =>
", ", chr(10) =>
""));
2233 if (trim($addressline1)) {
2236 if (trim($addressline2)) {
2239 $XML_DEBITOR .=
' </PstlAdr>' . $CrLf;
2240 $XML_DEBITOR .=
' </Dbtr>' . $CrLf;
2241 $XML_DEBITOR .=
' <DbtrAcct>' . $CrLf;
2242 $XML_DEBITOR .=
' <Id>' . $CrLf;
2243 $XML_DEBITOR .=
' <IBAN>' . preg_replace(
'/\s/',
'', $row_iban) .
'</IBAN>' . $CrLf;
2244 $XML_DEBITOR .=
' </Id>' . $CrLf;
2245 $XML_DEBITOR .=
' </DbtrAcct>' . $CrLf;
2246 $XML_DEBITOR .=
' <RmtInf>' . $CrLf;
2249 $XML_DEBITOR .=
' </RmtInf>' . $CrLf;
2250 $XML_DEBITOR .=
' </DrctDbtTxInf>' . $CrLf;
2251 return $XML_DEBITOR;
2255 $XML_CREDITOR .=
' <CdtTrfTxInf>' . $CrLf;
2256 $XML_CREDITOR .=
' <PmtId>' . $CrLf;
2258 $XML_CREDITOR .=
' <EndToEndId>' . ((
getDolGlobalString(
'PRELEVEMENT_END_TO_END') !=
"") ? $conf->global->PRELEVEMENT_END_TO_END : (
'CT-' .
dol_trunc($row_idfac .
'-' . $row_ref, 20,
'right',
'UTF-8', 1)) .
'-' . $Rowing) .
'</EndToEndId>' . $CrLf;
2259 $XML_CREDITOR .=
' </PmtId>' . $CrLf;
2260 if (!empty($this->sepa_xml_pti_in_ctti)) {
2261 $XML_CREDITOR .=
' <PmtTpInf>' . $CrLf;
2265 $instrprty =
'HIGH';
2267 $instrprty =
'NORM';
2269 $XML_CREDITOR .=
' <InstrPrty>' . $instrprty .
'</InstrPrty>' . $CrLf;
2270 $XML_CREDITOR .=
' <SvcLvl>' . $CrLf;
2271 $XML_CREDITOR .=
' <Cd>SEPA</Cd>' . $CrLf;
2272 $XML_CREDITOR .=
' </SvcLvl>' . $CrLf;
2273 $XML_CREDITOR .=
' <CtgyPurp>' . $CrLf;
2274 $XML_CREDITOR .=
' <Cd>CORE</Cd>' . $CrLf;
2275 $XML_CREDITOR .=
' </CtgyPurp>' . $CrLf;
2276 $XML_CREDITOR .=
' </PmtTpInf>' . $CrLf;
2278 $XML_CREDITOR .=
' <Amt>' . $CrLf;
2279 $XML_CREDITOR .=
' <InstdAmt Ccy="EUR">'.round((
float) $row_somme, 2).
'</InstdAmt>'.$CrLf;
2280 $XML_CREDITOR .=
' </Amt>' . $CrLf;
2291 $XML_CREDITOR .=
' <CdtrAgt>' . $CrLf;
2292 $XML_CREDITOR .=
' <FinInstnId>' . $CrLf;
2293 $XML_CREDITOR .=
' <BIC>' . $row_bic .
'</BIC>' . $CrLf;
2294 $XML_CREDITOR .=
' </FinInstnId>' . $CrLf;
2295 $XML_CREDITOR .=
' </CdtrAgt>' . $CrLf;
2296 $XML_CREDITOR .=
' <Cdtr>' . $CrLf;
2298 $XML_CREDITOR .=
' <PstlAdr>' . $CrLf;
2299 $XML_CREDITOR .=
' <Ctry>' . $row_country_code .
'</Ctry>' . $CrLf;
2300 $addressline1 = strtr($row_address, array(chr(13) =>
", ", chr(10) =>
""));
2301 $addressline2 = strtr($row_zip . (($row_zip && $row_town) ?
' ' : (string) $row_town), array(chr(13) =>
", ", chr(10) =>
""));
2302 if (trim($addressline1)) {
2305 if (trim($addressline2)) {
2308 $XML_CREDITOR .=
' </PstlAdr>' . $CrLf;
2309 $XML_CREDITOR .=
' </Cdtr>' . $CrLf;
2310 $XML_CREDITOR .=
' <CdtrAcct>' . $CrLf;
2311 $XML_CREDITOR .=
' <Id>' . $CrLf;
2312 $XML_CREDITOR .=
' <IBAN>' . preg_replace(
'/\s/',
'', $row_iban) .
'</IBAN>' . $CrLf;
2313 $XML_CREDITOR .=
' </Id>' . $CrLf;
2314 $XML_CREDITOR .=
' </CdtrAcct>' . $CrLf;
2315 $XML_CREDITOR .=
' <RmtInf>' . $CrLf;
2318 $XML_CREDITOR .=
' </RmtInf>' . $CrLf;
2319 $XML_CREDITOR .=
' </CdtTrfTxInf>' . $CrLf;
2320 return $XML_CREDITOR;
2336 fwrite($this->file,
"03");
2337 fwrite($this->file,
"08");
2339 fwrite($this->file,
" ");
2341 fwrite($this->file, $this->emetteur_ics);
2345 fwrite($this->file,
" ");
2346 fwrite($this->file,
dol_print_date($this->date_echeance,
"%d%m",
'gmt'));
2347 fwrite($this->file, substr(
dol_print_date($this->date_echeance,
"%y",
'gmt'), 1));
2351 fwrite($this->file, substr($this->raison_sociale .
" ", 0, 24));
2355 fwrite($this->file, substr($this->reference_remise .
" ", 0, 7));
2359 fwrite($this->file, substr(
" ", 0, 17));
2363 fwrite($this->file, substr(
" ", 0, 2));
2364 fwrite($this->file,
"E");
2365 fwrite($this->file, substr(
" ", 0, 5));
2369 fwrite($this->file, $this->emetteur_code_guichet);
2373 fwrite($this->file, substr(
"000000000000000" . $this->emetteur_numero_compte, -11));
2377 fwrite($this->file, substr(
" ", 0, 16));
2381 fwrite($this->file, substr(
" ", 0, 31));
2385 fwrite($this->file, $this->emetteur_code_banque);
2389 fwrite($this->file, substr(
" ", 0, 5));
2391 fwrite($this->file,
"\n");
2411 public function EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf =
'\n', $format =
'FRST', $type =
'direct-debit', $fk_bank_account = 0)
2421 if (empty($fk_bank_account)) {
2422 $fk_bank_account = ($type ==
'bank-transfer' ?
getDolGlobalInt(
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') :
getDolGlobalInt(
'PRELEVEMENT_ID_BANKACCOUNT'));
2426 $account =
new Account($this->db);
2427 if ($account->fetch($fk_bank_account) > 0) {
2428 $this->emetteur_code_banque = $account->code_banque;
2429 $this->emetteur_code_guichet = $account->code_guichet;
2430 $this->emetteur_numero_compte = $account->number;
2431 $this->emetteur_number_key = $account->cle_rib;
2432 $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
2433 $this->emetteur_iban = $account->iban;
2434 $this->emetteur_bic = $account->bic;
2436 $this->emetteur_ics = (($type ==
'bank-transfer' &&
getDolGlobalString(
"SEPA_USE_IDS")) ? $account->ics_transfer : $account->ics);
2438 $this->raison_sociale = $account->proprio;
2442 $sql =
"SELECT rowid, ref";
2443 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons as pb";
2444 $sql .=
" WHERE pb.rowid = " . ((int) $this->
id);
2446 $resql = $this->db->query($sql);
2448 $obj = $this->db->fetch_object($resql);
2450 $country = explode(
':', $configuration->global->MAIN_INFO_SOCIETE_COUNTRY);
2451 $IdBon = sprintf(
"%05d", $obj->rowid);
2452 $RefBon = $obj->ref;
2454 if (!empty($configuration->global->SEPA_FORCE_TWO_DECIMAL)) {
2455 $total = number_format((
float)
price2num($total,
'MT'), 2,
".",
"");
2458 if ($type !=
'bank-transfer') {
2460 $XML_SEPA_INFO =
'';
2461 $XML_SEPA_INFO .=
' <PmtInf>' . $CrLf;
2462 $XML_SEPA_INFO .=
' <PmtInfId>' . (
'DD/' . $dateTime_YMD .
'/ID' . $IdBon .
'-' . $RefBon) .
'</PmtInfId>' . $CrLf;
2463 $XML_SEPA_INFO .=
' <PmtMtd>DD</PmtMtd>' . $CrLf;
2464 $XML_SEPA_INFO .=
' <NbOfTxs>' . $nombre .
'</NbOfTxs>' . $CrLf;
2465 $XML_SEPA_INFO .=
' <CtrlSum>' . $total .
'</CtrlSum>' . $CrLf;
2466 $XML_SEPA_INFO .=
' <PmtTpInf>' . $CrLf;
2467 $XML_SEPA_INFO .=
' <SvcLvl>' . $CrLf;
2468 $XML_SEPA_INFO .=
' <Cd>SEPA</Cd>' . $CrLf;
2469 $XML_SEPA_INFO .=
' </SvcLvl>' . $CrLf;
2470 $XML_SEPA_INFO .=
' <LclInstrm>' . $CrLf;
2471 $XML_SEPA_INFO .=
' <Cd>CORE</Cd>' . $CrLf;
2472 $XML_SEPA_INFO .=
' </LclInstrm>' . $CrLf;
2473 $XML_SEPA_INFO .=
' <SeqTp>' . $format .
'</SeqTp>' . $CrLf;
2474 $XML_SEPA_INFO .=
' </PmtTpInf>' . $CrLf;
2475 $XML_SEPA_INFO .=
' <ReqdColltnDt>' . $dateTime_ETAD .
'</ReqdColltnDt>' . $CrLf;
2476 $XML_SEPA_INFO .=
' <Cdtr>' . $CrLf;
2478 $XML_SEPA_INFO .=
' <PstlAdr>' . $CrLf;
2479 $XML_SEPA_INFO .=
' <Ctry>' . $country[1] .
'</Ctry>' . $CrLf;
2480 $addressline1 = strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(chr(13) =>
", ", chr(10) =>
""));
2481 $addressline2 = strtr($configuration->global->MAIN_INFO_SOCIETE_ZIP . (($configuration->global->MAIN_INFO_SOCIETE_ZIP ||
' ' . $configuration->global->MAIN_INFO_SOCIETE_TOWN) ?
' ' :
'') . $configuration->global->MAIN_INFO_SOCIETE_TOWN, array(chr(13) =>
", ", chr(10) =>
""));
2482 if ($addressline1) {
2485 if ($addressline2) {
2488 $XML_SEPA_INFO .=
' </PstlAdr>' . $CrLf;
2489 $XML_SEPA_INFO .=
' </Cdtr>' . $CrLf;
2490 $XML_SEPA_INFO .=
' <CdtrAcct>' . $CrLf;
2491 $XML_SEPA_INFO .=
' <Id>' . $CrLf;
2492 $XML_SEPA_INFO .=
' <IBAN>' . preg_replace(
'/\s/',
'', $this->emetteur_iban) .
'</IBAN>' . $CrLf;
2493 $XML_SEPA_INFO .=
' </Id>' . $CrLf;
2494 $XML_SEPA_INFO .=
' </CdtrAcct>' . $CrLf;
2495 $XML_SEPA_INFO .=
' <CdtrAgt>' . $CrLf;
2496 $XML_SEPA_INFO .=
' <FinInstnId>' . $CrLf;
2497 $XML_SEPA_INFO .=
' <BIC>' . $this->emetteur_bic .
'</BIC>' . $CrLf;
2498 $XML_SEPA_INFO .=
' </FinInstnId>' . $CrLf;
2499 $XML_SEPA_INFO .=
' </CdtrAgt>' . $CrLf;
2508 $XML_SEPA_INFO .=
' <ChrgBr>SLEV</ChrgBr>' . $CrLf;
2509 $XML_SEPA_INFO .=
' <CdtrSchmeId>' . $CrLf;
2510 $XML_SEPA_INFO .=
' <Id>' . $CrLf;
2511 $XML_SEPA_INFO .=
' <PrvtId>' . $CrLf;
2512 $XML_SEPA_INFO .=
' <Othr>' . $CrLf;
2513 $XML_SEPA_INFO .=
' <Id>' . $this->emetteur_ics .
'</Id>' . $CrLf;
2514 $XML_SEPA_INFO .=
' <SchmeNm>' . $CrLf;
2515 $XML_SEPA_INFO .=
' <Prtry>SEPA</Prtry>' . $CrLf;
2516 $XML_SEPA_INFO .=
' </SchmeNm>' . $CrLf;
2517 $XML_SEPA_INFO .=
' </Othr>' . $CrLf;
2518 $XML_SEPA_INFO .=
' </PrvtId>' . $CrLf;
2519 $XML_SEPA_INFO .=
' </Id>' . $CrLf;
2520 $XML_SEPA_INFO .=
' </CdtrSchmeId>' . $CrLf;
2523 $XML_SEPA_INFO =
'';
2524 $XML_SEPA_INFO .=
' <PmtInf>' . $CrLf;
2525 $XML_SEPA_INFO .=
' <PmtInfId>' . (
'TRF/' . $dateTime_YMD .
'/ID' . $IdBon .
'-' . $RefBon) .
'</PmtInfId>' . $CrLf;
2526 $XML_SEPA_INFO .=
' <PmtMtd>TRF</PmtMtd>' . $CrLf;
2528 $XML_SEPA_INFO .=
' <NbOfTxs>' . $nombre .
'</NbOfTxs>' . $CrLf;
2529 $XML_SEPA_INFO .=
' <CtrlSum>' . $total .
'</CtrlSum>' . $CrLf;
2530 if (!empty($this->sepa_xml_pti_in_ctti) && !empty($format)) {
2531 $XML_SEPA_INFO .=
' <PmtTpInf>' . $CrLf;
2532 $XML_SEPA_INFO .=
' <SvcLvl>' . $CrLf;
2533 $XML_SEPA_INFO .=
' <Cd>SEPA</Cd>' . $CrLf;
2534 $XML_SEPA_INFO .=
' </SvcLvl>' . $CrLf;
2535 $XML_SEPA_INFO .=
' <LclInstrm>' . $CrLf;
2536 $XML_SEPA_INFO .=
' <Cd>CORE</Cd>' . $CrLf;
2537 $XML_SEPA_INFO .=
' </LclInstrm>' . $CrLf;
2538 $XML_SEPA_INFO .=
' <SeqTp>' . $format .
'</SeqTp>' . $CrLf;
2539 $XML_SEPA_INFO .=
' </PmtTpInf>' . $CrLf;
2541 $XML_SEPA_INFO .=
' <ReqdExctnDt>' .
dol_print_date($dateTime_ETAD,
'dayrfc') .
'</ReqdExctnDt>' . $CrLf;
2542 $XML_SEPA_INFO .=
' <Dbtr>' . $CrLf;
2544 $XML_SEPA_INFO .=
' <PstlAdr>' . $CrLf;
2545 $XML_SEPA_INFO .=
' <Ctry>' . $country[1] .
'</Ctry>' . $CrLf;
2546 $addressline1 = strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(chr(13) =>
", ", chr(10) =>
""));
2547 $addressline2 = strtr($configuration->global->MAIN_INFO_SOCIETE_ZIP . (($configuration->global->MAIN_INFO_SOCIETE_ZIP ||
' ' . $configuration->global->MAIN_INFO_SOCIETE_TOWN) ?
' ' :
'') . $configuration->global->MAIN_INFO_SOCIETE_TOWN, array(chr(13) =>
", ", chr(10) =>
""));
2548 if ($addressline1) {
2551 if ($addressline2) {
2554 $XML_SEPA_INFO .=
' </PstlAdr>' . $CrLf;
2555 $XML_SEPA_INFO .=
' </Dbtr>' . $CrLf;
2556 $XML_SEPA_INFO .=
' <DbtrAcct>' . $CrLf;
2557 $XML_SEPA_INFO .=
' <Id>' . $CrLf;
2558 $XML_SEPA_INFO .=
' <IBAN>' . preg_replace(
'/\s/',
'', $this->emetteur_iban) .
'</IBAN>' . $CrLf;
2559 $XML_SEPA_INFO .=
' </Id>' . $CrLf;
2560 $XML_SEPA_INFO .=
' </DbtrAcct>' . $CrLf;
2561 $XML_SEPA_INFO .=
' <DbtrAgt>' . $CrLf;
2562 $XML_SEPA_INFO .=
' <FinInstnId>' . $CrLf;
2563 $XML_SEPA_INFO .=
' <BIC>' . $this->emetteur_bic .
'</BIC>' . $CrLf;
2564 $XML_SEPA_INFO .=
' </FinInstnId>' . $CrLf;
2565 $XML_SEPA_INFO .=
' </DbtrAgt>' . $CrLf;
2574 $XML_SEPA_INFO .=
' <ChrgBr>SLEV</ChrgBr>' . $CrLf;
2589 fwrite($this->file,
'INCORRECT EMETTEUR ' . $this->raison_sociale . $CrLf);
2590 $XML_SEPA_INFO =
'';
2592 return $XML_SEPA_INFO;
2605 fwrite($this->file,
"08");
2606 fwrite($this->file,
"08");
2608 fwrite($this->file,
" ");
2610 fwrite($this->file, $this->emetteur_ics);
2614 fwrite($this->file, substr(
" ", 0, 12));
2619 fwrite($this->file, substr(
" ", 0, 24));
2623 fwrite($this->file, substr(
" ", 0, 24));
2627 fwrite($this->file, substr(
" ", 0, 8));
2631 fwrite($this->file, substr(
" ", 0, 5));
2635 fwrite($this->file, substr(
" ", 0, 11));
2639 $montant = ($total * 100);
2641 fwrite($this->file, substr(
"000000000000000" . $montant, -16));
2645 fwrite($this->file, substr(
" ", 0, 31));
2649 fwrite($this->file, substr(
" ", 0, 5));
2653 fwrite($this->file, substr(
" ", 0, 5));
2655 fwrite($this->file,
"\n");
2666 return $this->
LibStatut($this->statut, $mode);
2680 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
2683 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'StatusWaiting');
2684 $this->labelStatus[self::STATUS_TRANSFERED] = $langs->transnoentitiesnoconv(
'StatusTrans');
2685 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'StatusWaiting');
2686 $this->labelStatusShort[self::STATUS_TRANSFERED] = $langs->transnoentitiesnoconv(
'StatusTrans');
2687 if ($this->
type ==
'bank-transfer') {
2688 $this->labelStatus[self::STATUS_DEBITED] = $langs->transnoentitiesnoconv(
'StatusDebited');
2689 $this->labelStatusShort[self::STATUS_DEBITED] = $langs->transnoentitiesnoconv(
'StatusDebited');
2691 $this->labelStatus[self::STATUS_CREDITED] = $langs->transnoentitiesnoconv(
'StatusCredited');
2692 $this->labelStatusShort[self::STATUS_CREDITED] = $langs->transnoentitiesnoconv(
'StatusCredited');
2696 $statusType =
'status1';
2697 if ($status == self::STATUS_TRANSFERED) {
2698 $statusType =
'status3';
2700 if ($status == self::STATUS_CREDITED || $status == self::STATUS_DEBITED) {
2701 $statusType =
'status6';
2704 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
2790 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2792 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2793 $return .=
'<div class="info-box info-box-sm">';
2794 $return .=
'<span class="info-box-icon bg-infobox-action">';
2796 $return .=
'</span>';
2797 $return .=
'<div class="info-box-content">';
2798 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . (method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref) .
'</span>';
2799 if ($selected >= 0) {
2800 $return .=
'<input id="cb' . $this->
id .
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="' . $this->
id .
'"' . ($selected ?
' checked="checked"' :
'') .
'>';
2802 if (property_exists($this,
'date_echeance')) {
2803 $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>';
2805 if (property_exists($this,
'total')) {
2806 $return .=
'<br><span class="opacitymedium">' . $langs->trans(
"Amount") .
'</span> : <span class="amount">' .
price($this->total) .
'</span>';
2808 if (method_exists($this,
'LibStatut')) {
2809 $return .=
'<br><div class="info-box-status">' . $this->
getLibStatut(3) .
'</div>';
2811 $return .=
'</div>';
2812 $return .=
'</div>';
2813 $return .=
'</div>';
2824 if (!empty($this->
id)) {
2830 $sql =
"SELECT COUNT(*) AS nb FROM " . MAIN_DB_PREFIX .
"prelevement_lignes";
2831 $sql .=
" WHERE fk_prelevement_bons = " . ((int) $id);
2832 $sql .=
" AND fk_soc = 0";
2833 $sql .=
" AND fk_user IS NOT NULL";
2836 $resql = $this->db->query($sql);
2838 $obj = $this->db->fetch_object($resql);
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
checkSwiftForAccount(Account $account=null, $swift=null)
Check SWIFT information for a bank account.
checkIbanForAccount(Account $account=null, $ibantocheck=null)
Check IBAN number 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.
generate($format='ALL', $executiondate=0, $type='direct-debit', $fk_bank_account=0, $forsalary=0)
Generate a direct debit or credit transfer file.
fetch($rowid, $ref='')
Get object and lines from database.
getListInvoices($amounts=0, $type='')
Get invoice or salary list (with amount or not)
deleteNotificationById($rowid)
Delete a notification def by id.
AddFacture($invoice_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $type='debit-order', $sourcetype='')
Add invoice to withdrawal.
__construct($db)
Constructor.
EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $ref, $facid, $rib_dom='', $type='direct-debit')
Write recipient of request (customer)
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Returns clickable name (with picto)
LibStatut($status, $mode=0)
Return status label for a status.
update(User $user, $notrigger=0)
Update object into database.
set_infotrans($user, $date, $method)
Set withdrawal to transmitted status.
getErrorString($error)
Return error string.
EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf='\n', $format='FRST', $type='direct-debit', $fk_bank_account=0)
Write sender of request (me).
set_infocredit($user, $date, $type='')
Set direct debit or credit transfer order to "paid" status.
addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype='')
Add line to withdrawal.
getLibStatut($mode=0)
Return status label of object.
EnregDestinataireSEPA($row_code_client, $row_nom, $row_address, $row_zip, $row_town, $row_country_code, $row_cb, $row_cg, $row_cc, $row_somme, $row_ref, $row_idfac, $row_iban, $row_bic, $row_datec, $row_drum, $row_rum, $type='direct-debit', $row_comment='')
Write recipient (thirdparty concerned by request)
addNotification($db, $user, $action)
Add a notification.
nbOfInvoiceToPay($mode='direct-debit', $type='')
Get number of invoices waiting for payment.
create($banque=0, $agence=0, $mode='real', $format='ALL', $executiondate='', $notrigger=0, $type='direct-debit', $did=0, $fk_bank_account=0, $sourcetype='invoice')
Create a BAN payment order:
deleteNotification($user, $action)
Delete a notification.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
updateCommon(User $user, $notrigger=0)
Update object into database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage suppliers invoices.
Class to manage invoices.
const STATUS_VALIDATED
Validated (need to be paid)
Class to manage payments for supplier invoices.
Class to manage payments of customer invoices.
Class to manage payments of salaries.
Class to manage salary payments.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type