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;
166 const STATUS_CANCELED = 9;
212 public $fields = array(
213 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'position' => 10,
'notnull' => 1,
'visible' => 0,),
214 'ref' => array(
'type' =>
'varchar(12)',
'label' =>
'Ref',
'enabled' => 1,
'position' => 15,
'notnull' => 0,
'visible' => -1,
'csslist' =>
'tdoverflowmax150',
'showoncombobox' => 1,),
215 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'position' => 25,
'notnull' => 0,
'visible' => -1,),
216 'amount' => array(
'type' =>
'double(24,8)',
'label' =>
'Amount',
'enabled' => 1,
'position' => 30,
'notnull' => 0,
'visible' => -1,),
217 'statut' => array(
'type' =>
'smallint(6)',
'label' =>
'Statut',
'enabled' => 1,
'position' => 500,
'notnull' => 0,
'visible' => -1,
'arrayofkeyval' => array(0 =>
'Wait', 1 =>
'Transfered', 2 =>
'Credited')),
218 'credite' => array(
'type' =>
'smallint(6)',
'label' =>
'Credite',
'enabled' => 1,
'position' => 40,
'notnull' => 0,
'visible' => -1,),
219 'note' => array(
'type' =>
'text',
'label' =>
'Note',
'enabled' => 1,
'position' => 45,
'notnull' => 0,
'visible' => -1,),
220 'date_trans' => array(
'type' =>
'datetime',
'label' =>
'TransData',
'enabled' => 1,
'position' => 50,
'notnull' => 0,
'visible' => -1,),
221 'method_trans' => array(
'type' =>
'smallint(6)',
'label' =>
'Methodtrans',
'enabled' => 1,
'position' => 55,
'notnull' => 0,
'visible' => -1,),
222 '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',),
223 'date_credit' => array(
'type' =>
'datetime',
'label' =>
'CreditDate',
'enabled' => 1,
'position' => 65,
'notnull' => 0,
'visible' => -1,),
224 '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',),
225 'type' => array(
'type' =>
'varchar(16)',
'label' =>
'Type',
'enabled' => 1,
'position' => 75,
'notnull' => 0,
'visible' => -1,),
226 'fk_bank_account' => array(
'type' =>
'integer',
'label' =>
'Fkbankaccount',
'enabled' => 1,
'position' => 80,
'notnull' => 0,
'visible' => -1,
'css' =>
'maxwidth500 widthcentpercentminusxx',),
270 public $note_private;
279 public $method_trans;
283 public $fk_user_trans;
291 public $fk_user_credit;
299 public $fk_bank_account;
313 $this->filename =
'';
315 $this->date_echeance =
dol_now();
316 $this->raison_sociale =
"";
317 $this->reference_remise =
"";
319 $this->emetteur_code_guichet =
"";
320 $this->emetteur_numero_compte =
"";
321 $this->emetteur_code_banque =
"";
322 $this->emetteur_number_key =
"";
323 $this->sepa_xml_pti_in_ctti =
false;
325 $this->emetteur_iban =
"";
326 $this->emetteur_bic =
"";
327 $this->emetteur_ics =
"";
329 $this->factures = array();
331 $this->methodes_trans = array(0 =>
'Internet', 2 =>
'Email', 3 =>
'Api');
356 public function addWithdrawDetail($invoice_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $type =
'debit-order', $sourcetype =
'', $bic =
'', $iban =
'', $rum =
'', $id_prelevement_demande = 0)
365 $result = $this->
addline($line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype, $bic, $iban, $rum, $id_prelevement_demande);
370 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"prelevement (";
371 if ($type !=
'bank-transfer') {
372 $sql .=
"fk_facture";
374 if ($sourcetype ==
'salary') {
377 $sql .=
"fk_facture_fourn";
380 $sql .=
",fk_prelevement_lignes";
381 $sql .=
") VALUES (";
382 $sql .= ((int) $invoice_id);
383 $sql .=
", " . ((int) $line_id);
386 if ($this->db->query($sql)) {
390 $this->errors[] = get_class($this) .
"::addWithdrawDetail " . $this->db->lasterror;
391 dol_syslog(get_class($this) .
"::addWithdrawDetail Error $result");
395 $this->errors[] = get_class($this) .
"::addWithdrawDetail linedid Empty";
396 dol_syslog(get_class($this) .
"::addWithdrawDetail Error $result");
400 dol_syslog(get_class($this) .
"::addWithdrawDetail Error $result");
424 public function addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype =
'', $bic =
'', $iban =
'', $rum =
'', $id_prelevement_demande = 0)
434 $sql =
"SELECT rowid";
435 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_lignes";
436 $sql .=
" WHERE fk_prelevement_bons = " . ((int) $this->
id);
437 if ($sourcetype ==
'salary') {
438 $sql .=
" AND fk_soc = " . ((int) $client_id);
440 $sql .=
" AND fk_user = " . ((int) $client_id);
442 $sql .=
" AND code_banque = '" . $this->db->escape($code_banque) .
"'";
443 $sql .=
" AND code_guichet = '" . $this->db->escape($code_guichet) .
"'";
444 $sql .=
" AND number = '" . $this->db->escape($number) .
"'";
446 $resql = $this->db->query($sql);
448 $num = $this->db->num_rows($resql);
456 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"prelevement_lignes (";
457 $sql .=
"fk_prelevement_bons";
459 $sql .=
", client_nom";
461 $sql .=
", fk_prelevement_demande";
462 $sql .= ($sourcetype ==
'salary' ?
", fk_user" :
"");
463 $sql .=
") VALUES (";
464 $sql .= ((int) $this->
id);
465 $sql .=
", " . (($sourcetype !=
'salary') ? ((
int) $client_id) :
"0");
466 $sql .=
", '" . $this->db->escape($client_nom) .
"'";
467 $sql .=
", " . ((float)
price2num($amount));
468 $sql .=
", " . ((int) $id_prelevement_demande);
469 $sql .= (($sourcetype ==
'salary') ?
", " . ((
int) $client_id) :
'');
471 if ($this->db->query($sql)) {
472 $line_id = $this->db->last_insert_id(MAIN_DB_PREFIX .
"prelevement_lignes");
475 $this->errors[] = get_class($this) .
"::addline Error -2 " . $this->db->lasterror;
476 dol_syslog(get_class($this) .
"::addline Error -2");
496 $errors[1027] = $langs->trans(
"DateInvalid");
498 return $errors[abs($error)] ??
'unknown error code';
508 public function fetch($rowid, $ref =
'')
510 $sql =
"SELECT p.rowid, p.ref, p.amount, p.note";
511 $sql .=
", p.datec as dc";
512 $sql .=
", p.date_trans as date_trans";
513 $sql .=
", p.method_trans, p.fk_user_trans";
514 $sql .=
", p.date_credit as date_credit";
515 $sql .=
", p.fk_user_credit";
517 $sql .=
", p.fk_bank_account";
518 $sql .=
", p.statut as status";
519 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons as p";
520 $sql .=
" WHERE p.entity IN (" .
getEntity(
'invoice') .
")";
522 $sql .=
" AND p.rowid = " . ((int) $rowid);
524 $sql .=
" AND p.ref = '" . $this->db->escape($ref) .
"'";
527 dol_syslog(get_class($this) .
"::fetch", LOG_DEBUG);
528 $result = $this->db->query($sql);
530 if ($this->db->num_rows($result)) {
531 $obj = $this->db->fetch_object($result);
533 $this->
id = $obj->rowid;
534 $this->
ref = $obj->ref;
535 $this->
amount = $obj->amount;
536 $this->note = $obj->note;
537 $this->note_private = $obj->note;
538 $this->datec = $this->db->jdate($obj->dc);
540 $this->date_trans = $this->db->jdate($obj->date_trans);
541 $this->method_trans = $obj->method_trans;
542 $this->user_trans = $obj->fk_user_trans;
544 $this->date_credit = $this->db->jdate($obj->date_credit);
545 $this->user_credit = $obj->fk_user_credit;
547 $this->
type = $obj->type;
548 $this->fk_bank_account = $obj->fk_bank_account;
550 $this->
status = $obj->status;
551 if (empty($this->
status)) {
554 $this->statut = $this->status;
560 dol_syslog(get_class($this) .
"::Fetch no record found");
593 global
$conf, $langs;
597 if ($this->fetched == 1) {
598 if ($date < $this->date_trans) {
599 $langs->load(
"errors");
600 $this->error = $langs->trans(
'ErrorDateOfMovementLowerThanDateOfFileTransmission');
601 dol_syslog(
"bon-prelevment::set_infocredit 1027 " . $this->error);
607 $sql =
" UPDATE " . MAIN_DB_PREFIX .
"prelevement_bons";
608 $sql .=
" SET fk_user_credit = " . ((int) $user->id);
609 $sql .=
", statut = " . self::STATUS_CREDITED;
610 $sql .=
", date_credit = '" . $this->db->idate($date) .
"'";
611 $sql .=
" WHERE rowid = " . ((int) $this->
id);
612 $sql .=
" AND entity = " . ((int)
$conf->entity);
613 $sql .=
" AND statut = " . self::STATUS_TRANSFERED;
615 $resql = $this->db->query($sql);
617 $langs->load(
'withdrawals');
618 $subject = $langs->trans(
"InfoCreditSubject", $this->
ref);
619 $message = $langs->trans(
"InfoCreditMessage", $this->
ref,
dol_print_date($date,
'dayhour'));
622 $fk_bank_account = $this->fk_bank_account;
623 if (empty($fk_bank_account)) {
628 $amountsperthirdparty = array();
638 for ($i = 0; $i < $num; $i++) {
639 if ($this->
type ==
'bank-transfer') {
640 if ($type ==
'salary') {
641 $fac =
new Salary($this->db);
649 $result = $fac->fetch($facs[$i][0]);
651 $amounts[$fac->id] = $facs[$i][1];
652 if ($this->
type ==
'bank-transfer') {
653 if ($type ==
'salary') {
654 $amountsperthirdparty[$fac->fk_user][$fac->id] = $facs[$i][1];
656 $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
659 $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
662 $totalpaid = $fac->getSommePaiement();
663 $totalcreditnotes = 0;
664 if (method_exists($fac,
'getSumCreditNotesUsed')) {
665 $totalcreditnotes = $fac->getSumCreditNotesUsed();
668 if (method_exists($fac,
'getSumDepositsUsed')) {
669 $totaldeposits = $fac->getSumDepositsUsed();
671 $alreadypayed = $totalpaid + $totalcreditnotes + $totaldeposits;
675 $amountofdocument = $fac->total_ttc;
676 if ($type ==
'salary') {
677 $amountofdocument = $fac->amount;
679 if (
price2num($alreadypayed + $facs[$i][1],
'MT') ==
price2num($amountofdocument,
'MT')) {
680 $result = $fac->setPaid($user);
682 $this->error = $fac->error;
683 $this->errors = $fac->errors;
689 foreach ($amountsperthirdparty as $thirdpartyid => $cursoramounts) {
690 if ($this->
type ==
'bank-transfer') {
691 if ($type ==
'salary') {
697 $paiement =
new Paiement($this->db);
699 $paiement->datepaye = $date;
700 $paiement->amounts = $cursoramounts;
702 if ($this->
type ==
'bank-transfer') {
703 if ($type ==
'salary') {
704 $paiement->datep = $date;
706 $paiement->paiementid = 2;
707 $paiement->fk_typepayment = 2;
708 $paiement->paiementcode =
'VIR';
710 $paiement->paiementid = 2;
711 $paiement->paiementcode =
'VIR';
714 $paiement->paiementid = 3;
715 $paiement->paiementcode =
'PRE';
718 $paiement->num_payment = $this->ref;
719 $paiement->id_prelevement = $this->id;
721 $result = $paiement->create($user, 1);
725 $this->error = $paiement->error;
726 $this->errors = $paiement->errors;
727 dol_syslog(get_class($this) .
"::set_infocredit AddPayment Error " . $this->error);
729 if ($this->
type ==
'bank-transfer') {
730 if ($type ==
'salary') {
731 $modeforaddpayment =
'payment_salary';
732 $labelforaddpayment =
'(SalaryPayment)';
733 $addbankurl =
'credit-transfer';
735 $modeforaddpayment =
'payment_supplier';
736 $labelforaddpayment =
'(SupplierInvoicePayment)';
737 $addbankurl =
'credit-transfer';
740 $modeforaddpayment =
'payment';
741 $labelforaddpayment =
'(CustomerInvoicePayment)';
742 $addbankurl =
'direct-debit';
748 $result = $paiement->addPaymentToBank($user, $modeforaddpayment, $labelforaddpayment, $fk_bank_account,
'',
'');
750 $result = $paiement->addPaymentToBank($user, $modeforaddpayment, $labelforaddpayment, $fk_bank_account,
'',
'', 0,
'', $addbankurl);
755 $this->error = $paiement->error;
756 $this->errors = $paiement->errors;
757 dol_syslog(get_class($this) .
"::set_infocredit AddPaymentToBank Error " . $this->error);
765 $sql =
" UPDATE " . MAIN_DB_PREFIX .
"prelevement_lignes";
766 $sql .=
" SET statut = 2";
767 $sql .=
" WHERE fk_prelevement_bons = " . ((int) $this->
id);
769 if (!$this->db->query($sql)) {
770 dol_syslog(get_class($this) .
"::set_infocredit Update lines Error");
775 $this->error = $this->db->lasterror();
776 dol_syslog(get_class($this) .
"::set_infocredit Update Bons Error");
782 $this->date_credit = $date;
783 $this->statut = self::STATUS_CREDITED;
784 $this->
status = self::STATUS_CREDITED;
789 $this->db->rollback();
809 global
$conf, $langs;
813 dol_syslog(get_class($this) .
"::set_infotrans Start", LOG_INFO);
815 if ($this->db->begin()) {
816 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_bons ";
817 $sql .=
" SET fk_user_trans = " . ((int) $user->id);
818 $sql .=
" , date_trans = '" . $this->db->idate($date) .
"'";
819 $sql .=
" , method_trans = " . ((int) $method);
820 $sql .=
" , statut = " . self::STATUS_TRANSFERED;
821 $sql .=
" WHERE rowid = " . ((int) $this->
id);
822 $sql .=
" AND entity = " . ((int)
$conf->entity);
823 $sql .=
" AND statut = " . self::STATUS_DRAFT;
825 if ($this->db->query($sql)) {
826 $this->method_trans = $method;
827 $langs->load(
'withdrawals');
828 $subject = $langs->trans(
"InfoTransSubject", $this->
ref);
829 $message = $langs->trans(
"InfoTransMessage", $this->
ref,
dolGetFirstLastname($user->firstname, $user->lastname));
830 $message .= $langs->trans(
"InfoTransData",
price($this->
amount), $this->methodes_trans[$this->method_trans],
dol_print_date($date,
'day'));
838 $this->date_trans = $date;
839 $this->statut = self::STATUS_TRANSFERED;
840 $this->
status = self::STATUS_TRANSFERED;
841 $this->user_trans = $user->id;
847 $this->db->rollback();
848 dol_syslog(get_class($this) .
"::set_infotrans ROLLBACK", LOG_ERR);
853 dol_syslog(get_class($this) .
"::set_infotrans Ouverture transaction SQL impossible", LOG_CRIT);
872 dol_syslog(get_class($this) .
"::getListInvoices");
876 if ($this->
type ==
'bank-transfer') {
877 if ($type ==
'salary') {
878 $sql .=
" p.fk_salary";
880 $sql .=
" p.fk_facture_fourn";
883 $sql .=
" p.fk_facture";
886 $sql .=
", SUM(pl.amount)";
888 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons as pb,";
889 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
890 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p";
891 $sql .=
" WHERE p.fk_prelevement_lignes = pl.rowid";
892 $sql .=
" AND pl.fk_prelevement_bons = pb.rowid";
893 $sql .=
" AND pb.rowid = " . ((int) $this->
id);
894 $sql .=
" AND pb.entity = " . ((int)
$conf->entity);
896 if ($this->
type ==
'bank-transfer') {
897 if ($type ==
'salary') {
898 $sql .=
" GROUP BY p.fk_salary";
900 $sql .=
" GROUP BY p.fk_facture_fourn";
903 $sql .=
" GROUP BY p.fk_facture";
907 $resql = $this->db->query($sql);
909 $num = $this->db->num_rows($resql);
914 $row = $this->db->fetch_row($resql);
926 $this->db->free($resql);
928 $this->error = $this->db->lasterror();
945 $sql =
"SELECT sum(pd.amount) as nb";
946 if ($type !==
'salary') {
947 if ($mode !=
'bank-transfer') {
948 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f,";
950 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture_fourn as f,";
953 $sql .=
" FROM " . MAIN_DB_PREFIX .
"salary as s,";
955 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_demande as pd";
956 $sql .= ($type !==
'salary' ?
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")" :
" WHERE s.entity IN (" .
getEntity(
'salary') .
")");
958 $sql .= ($type !==
'salary' ?
" AND f.fk_statut = " .
Facture::STATUS_VALIDATED :
" AND s.paye = " . Salary::STATUS_UNPAID);
960 if ($type !==
'salary') {
961 if ($mode !=
'bank-transfer') {
962 $sql .=
" AND f.rowid = pd.fk_facture";
964 $sql .=
" AND f.rowid = pd.fk_facture_fourn";
967 $sql .=
" AND s.rowid = pd.fk_salary";
969 $sql .= ($type !==
'salary' ?
" AND f.paye = 0" :
"");
970 $sql .=
" AND pd.traite = 0";
971 $sql .=
" AND pd.ext_payment_id IS NULL";
972 $sql .= ($type !==
'salary' ?
" AND f.total_ttc > 0" :
"");
974 $resql = $this->db->query($sql);
976 $obj = $this->db->fetch_object($resql);
978 $this->db->free($resql);
983 dol_syslog(get_class($this) .
"::SommeAPrelever Erreur -1");
999 if ($type ===
'salary') {
1017 if ($forsalary == 1) {
1018 $sql =
"SELECT count(s.rowid) as nb";
1019 $sql .=
" FROM " . MAIN_DB_PREFIX .
"salary as s";
1021 $sql =
"SELECT count(f.rowid) as nb";
1023 if ($type ==
'bank-transfer') {
1024 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture_fourn as f";
1026 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
1029 $sql .=
", " . MAIN_DB_PREFIX .
"prelevement_demande as pd";
1030 if ($forsalary == 1) {
1031 $sql .=
" WHERE s.entity IN (" .
getEntity(
'invoice') .
")";
1033 $sql .=
" AND s.paye = 0";
1036 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")";
1041 if ($forsalary == 1) {
1042 $sql .=
" AND s.rowid = pd.fk_salary";
1044 if ($type ==
'bank-transfer') {
1045 $sql .=
" AND f.rowid = pd.fk_facture_fourn";
1047 $sql .=
" AND f.rowid = pd.fk_facture";
1050 $sql .=
" AND pd.traite = 0";
1051 $sql .=
" AND pd.ext_payment_id IS NULL";
1052 if (!$forsalary == 1) {
1053 $sql .=
" AND f.total_ttc > 0";
1055 $sql .=
" AND s.paye = 0";
1058 dol_syslog(get_class($this) .
"::NbFactureAPrelever");
1059 $resql = $this->db->query($sql);
1062 $obj = $this->db->fetch_object($resql);
1063 $this->db->free($resql);
1067 $this->error = get_class($this) .
"::NbFactureAPrelever Erreur -1 sql=" . $this->db->error();
1097 public function create($banque =
'', $agence =
'', $mode =
'real', $format =
'ALL', $executiondate = 0, $notrigger = 0, $type =
'direct-debit', $dids = 0, $fk_bank_account = 0, $sourcetype =
'invoice')
1100 global
$conf, $langs, $user;
1102 dol_syslog(__METHOD__ .
" mode=".$mode.
" format=".$format.
" type=".$type.
" dids=".(is_array($dids) ? implode(
',', $dids) : $dids).
" fk_bank_account=".$fk_bank_account.
" sourcetype=".$sourcetype, LOG_DEBUG);
1104 require_once DOL_DOCUMENT_ROOT .
"/compta/facture/class/facture.class.php";
1105 require_once DOL_DOCUMENT_ROOT .
"/societe/class/societe.class.php";
1108 if ($type !=
'bank-transfer') {
1109 if (empty($format)) {
1110 $this->error =
'ErrorBadParametersForDirectDebitFileCreate';
1115 if (!is_int($dids) && !is_array($dids)) {
1116 $this->error =
'ErrorBadParametersForDirectDebitFileCreateDids';
1121 if (empty($fk_bank_account)) {
1122 $fk_bank_account = ($type ==
'bank-transfer' ?
getDolGlobalInt(
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') :
getDolGlobalInt(
'PRELEVEMENT_ID_BANKACCOUNT'));
1124 if (is_int($dids)) {
1125 $dids = array($dids);
1130 if ($sourcetype !=
'salary') {
1131 $entity = $type !=
'bank-transfer' ?
getEntity(
'invoice', 1) :
getEntity(
'supplier_invoice', 1);
1132 $sqlTable = $type !=
'bank-transfer' ?
"facture" :
"facture_fourn";
1133 $socOrUser =
'fk_soc';
1134 $societeOrUser =
'societe';
1137 $sqlTable =
'salary';
1138 $socOrUser =
'fk_user';
1139 $societeOrUser =
'user';
1170 $datetimeprev =
dol_now(
'gmt');
1172 if (!empty($executiondate)) {
1173 $datetimeprev = $executiondate;
1179 $this->invoice_in_error = array();
1180 $this->thirdparty_in_error = array();
1183 $factures = array();
1184 $factures_prev = array();
1185 $factures_prev_id = array();
1187 dol_syslog(__METHOD__ .
" Read invoices/salaries for dids=" . implode(
', ', $dids), LOG_DEBUG);
1189 $sql =
"SELECT f.rowid, pd.rowid as pfdrowid";
1190 $sql .=
", f.".$this->db->sanitize($socOrUser);
1191 $sql .=
", pd.code_banque, pd.code_guichet, pd.number, pd.cle_rib";
1192 $sql .=
", pd.amount";
1193 if ($sourcetype !=
'salary') {
1194 $sql .=
", s.nom as name";
1196 $sql .=
", sr.bic, sr.iban_prefix, sr.frstrecur, sr.default_rib, sr.rum";
1198 $sql .=
", CONCAT(s.firstname, ' ', s.lastname) as name";
1200 $sql .=
", sr.bic, sr.iban_prefix, 'FRST' as frstrecur, sr.default_rib, '' as rum";
1202 $sql .=
", pd.fk_societe_rib as soc_rib_id";
1203 $sql .=
" FROM " . $this->db->prefix() . $sqlTable .
" as f";
1204 $sql .=
" INNER JOIN " . $this->db->prefix() .
"prelevement_demande as pd ON f.rowid = pd.fk_".$this->db->sanitize($sqlTable);
1205 $sql .=
" LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($societeOrUser).
" as s ON s.rowid = f.".$this->db->sanitize($socOrUser);
1206 $sql .=
" LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($societeOrUser.
"_rib").
" as sr ON s.rowid = sr.".$this->db->sanitize($socOrUser);
1207 if ($sourcetype !=
'salary') {
1208 $sql .=
" AND sr.default_rib = 1";
1209 $sql .=
" AND sr.type = 'ban'";
1217 $sql .=
" WHERE f.entity IN (".((int) $entity).
')';
1218 if ($sourcetype !=
'salary') {
1219 $sql .=
" AND f.fk_statut = ".Facture::STATUS_VALIDATED;
1220 $sql .=
" AND f.paye = 0";
1221 $sql .=
" AND f.total_ttc > 0";
1227 $sql .=
" AND f.paye = 0";
1228 $sql .=
" AND f.amount > 0";
1230 $sql .=
" AND pd.traite = 0";
1231 $sql .=
" AND pd.ext_payment_id IS NULL";
1232 if ($dids !== [0] && !empty($dids)) {
1233 $sql .=
" AND pd.rowid IN (".$this->db->sanitize(implode(
',', $dids)).
")";
1236 $resql = $this->db->query($sql);
1238 $num = $this->db->num_rows($resql);
1242 $row = $this->db->fetch_row($resql);
1243 '@phan-var-force array<int<0,12>,string> $row';
1250 $factures[$i] = $row;
1253 $factures[$i][11] =
dolDecrypt($factures[$i][11]);
1257 dol_syslog(__METHOD__ .
" Read invoices/salaries error Found a null amount", LOG_WARNING);
1258 $this->invoice_in_error[$row[0]] =
"Error for invoice or salary id " . $row[0] .
", found a null amount";
1264 $this->db->free($resql);
1265 dol_syslog(__METHOD__ .
" Read invoices/salaries, " . $i .
" invoices/salaries to withdraw", LOG_DEBUG);
1267 $this->error = $this->db->lasterror();
1268 dol_syslog(__METHOD__ .
" Read invoices/salaries error " . $this->db->lasterror(), LOG_ERR);
1274 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1275 require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
1276 require_once DOL_DOCUMENT_ROOT .
'/societe/class/companybankaccount.class.php';
1277 require_once DOL_DOCUMENT_ROOT .
'/core/lib/bank.lib.php';
1279 $tmpsoc =
new Societe($this->db);
1280 $tmpuser =
new User($this->db);
1284 dol_syslog(__METHOD__ .
" Check BAN for each invoices or salaries", LOG_DEBUG);
1286 if (count($factures) > 0) {
1287 foreach ($factures as $key => $fac) {
1291 if ($fac[8] !=
null) {
1292 if ($type !=
'bank-transfer') {
1293 if ($format ==
'FRST' && $fac[12] && $fac[12] !=
'FRST') {
1296 if ($format ==
'RCUR' && $fac[12] && $fac[12] !=
'RCUR') {
1303 if (!empty($fac[15])) {
1305 $bankaccount->fetch((
int) $fac[15]);
1306 if ($bankaccount->id > 0) {
1307 $fac[3] = $bankaccount->code_banque;
1308 $fac[4] = $bankaccount->code_guichet;
1309 $fac[5] = $bankaccount->number;
1310 $fac[6] = $bankaccount->cle_rib;
1311 $fac[10] = $bankaccount->bic;
1312 $fac[11] = $bankaccount->iban;
1313 $fac[14] = $bankaccount->rum;
1318 $bicinloop = $fac[10];
1319 $baninloop = $fac[11];
1323 if ($verif || (empty($fac[10]) &&
getDolGlobalInt(
"WITHDRAWAL_WITHOUT_BIC"))) {
1324 dol_syslog(__METHOD__.
" now call checkIbanForAccount(null, ".$baninloop.
")");
1329 $factures_prev[$i] = $fac;
1331 $factures_prev_id[$i] = $fac[0];
1335 if ($type !=
'bank-transfer') {
1336 $tmpsoc->id = (int) $fac[2];
1337 $tmpsoc->name = $fac[8];
1338 $invoice_url =
"<a href='" . DOL_URL_ROOT .
'/compta/facture/card.php?facid=' . $fac[0] .
"'>" . $fac[9] .
"</a>";
1339 $this->invoice_in_error[$fac[0]] =
"Error incomplete properties of the default bank number ".$baninloop.
" IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1340 $this->thirdparty_in_error[$tmpsoc->id] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1343 if ($type ==
'bank-transfer' && $sourcetype !=
'salary') {
1344 $tmpsoc->id = (int) $fac[2];
1345 $tmpsoc->name = $fac[8];
1346 $invoice_url =
"<a href='" . DOL_URL_ROOT .
'/fourn/facture/card.php?facid=' . $fac[0] .
"'>" . $fac[9] .
"</a>";
1347 $this->invoice_in_error[$fac[0]] =
"Error incomplete properties of the default bank number ".$baninloop.
" IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1348 $this->thirdparty_in_error[$tmpsoc->id] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1351 if ($type ==
'bank-transfer' && $sourcetype ==
'salary') {
1352 $tmpuser->id = (int) $fac[2];
1353 $tmpuser->firstname = $fac[8];
1354 $salary_url =
"<a href='" . DOL_URL_ROOT .
'/salaries/card.php?id=' . $fac[0] .
"'>" . $fac[0] .
"</a>";
1355 $this->invoice_in_error[$fac[0]] =
"Error incomplete properties of the default bank number ".$baninloop.
" IBAN/BIC for salary " . $salary_url .
" for employee " . $tmpuser->getNomUrl(0);
1356 $this->thirdparty_in_error[$tmpuser->id] =
"Error on default bank number IBAN/BIC for salary " . $salary_url .
" for employee " . $tmpuser->getNomUrl(0);
1359 dol_syslog(__METHOD__ .
" Check BAN Error on default bank number IBAN/BIC reported by verif(): " . implode(
', ', $fac), LOG_WARNING);
1362 dol_syslog(__METHOD__ .
" Check BAN Failed to read company", LOG_WARNING);
1371 dol_syslog(__METHOD__ .
" Check BAN No invoice to process", LOG_WARNING);
1378 $out = count($factures_prev) .
" invoices or salaries will be included.";
1383 if (count($factures_prev) > 0) {
1384 if ($mode ==
'real') {
1387 print $langs->trans(
"ModeWarning");
1404 $ref = substr($year, -2) . $month;
1409 $sql =
"SELECT SUBSTRING(ref, 6) AS refnumber";
1410 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons";
1411 $sql .=
" WHERE ref LIKE '" . $this->db->escape($prefixt . $ref) .
"%'";
1412 $sql .=
" AND entity = " . ((int)
$conf->entity);
1413 $sql .=
" ORDER BY LENGTH(ref) DESC, ref DESC";
1416 dol_syslog(get_class($this) .
" get next free number", LOG_DEBUG);
1418 $resql = $this->db->query($sql);
1421 $row = $this->db->fetch_row($resql);
1424 $ref = $prefixt . $ref . sprintf(
"%03d", (intval($row[0] ?? 0) + 1));
1430 if ($type !=
'bank-transfer') {
1431 $dir =
$conf->prelevement->dir_output .
'/receipts';
1433 $dir =
$conf->paymentbybanktransfer->dir_output .
'/receipts';
1435 if (!is_dir($dir)) {
1440 $labelentity =
$conf->entity;
1441 $this->filename = $dir .
'/' . $ref .
'-' . $labelentity .
'.xml';
1443 $this->filename = $dir .
'/' . $ref .
'.xml';
1447 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"prelevement_bons (";
1448 $sql .=
"ref, entity, datec, type, fk_bank_account";
1449 $sql .=
") VALUES (";
1450 $sql .=
"'" . $this->db->escape($ref) .
"'";
1451 $sql .=
", " . ((int)
$conf->entity);
1452 $sql .=
", '" . $this->db->idate($now) .
"'";
1453 $sql .=
", '" . ($type ==
'bank-transfer' ?
'bank-transfer' :
'debit-order') .
"'";
1454 $sql .=
", " . ((int) $fk_bank_account);
1457 $resql = $this->db->query($sql);
1460 $prev_id = $this->db->last_insert_id(MAIN_DB_PREFIX .
"prelevement_bons");
1461 $this->
id = $prev_id;
1465 $this->errors[] = $this->db->lasterror();
1466 dol_syslog(__METHOD__ .
" Create withdraw receipt " . $this->db->lasterror(), LOG_ERR);
1470 $this->errors[] = $this->db->lasterror();
1471 dol_syslog(__METHOD__ .
" Get last withdraw receipt " . $this->db->lasterror(), LOG_ERR);
1476 dol_syslog(__METHOD__ .
" Now loop on each document to insert them in llx_prelevement_demande");
1479 if (count($factures_prev) > 0) {
1480 foreach ($factures_prev as $fac) {
1524 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_demande";
1525 $sql .=
" SET traite = 1";
1526 $sql .=
", date_traite = '" . $this->db->idate($now) .
"'";
1527 $sql .=
", fk_prelevement_bons = " . ((int) $this->
id);
1528 $sql .=
" WHERE rowid = " . ((int) $fac[1]);
1530 $resql = $this->db->query($sql);
1533 $this->errors[] = $this->db->lasterror();
1534 dol_syslog(__METHOD__ .
" Update Error=" . $this->db->lasterror(), LOG_ERR);
1545 dol_syslog(__METHOD__ .
" Init direct debit or credit transfer file for " . count($factures_prev) .
" invoices", LOG_DEBUG);
1547 if (count($factures_prev) > 0) {
1548 $this->date_echeance = $datetimeprev;
1549 $this->reference_remise = $ref;
1551 $account =
new Account($this->db);
1552 if ($account->fetch($fk_bank_account) > 0) {
1553 $this->emetteur_code_banque = $account->code_banque;
1554 $this->emetteur_code_guichet = $account->code_guichet;
1555 $this->emetteur_numero_compte = $account->number;
1556 $this->emetteur_number_key = $account->cle_rib;
1557 $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
1558 $this->emetteur_iban = $account->iban;
1559 $this->emetteur_bic = $account->bic;
1561 $this->emetteur_ics = (($type ==
'bank-transfer' &&
getDolGlobalString(
"SEPA_USE_IDS")) ? $account->ics_transfer : $account->ics);
1563 $this->raison_sociale = $account->owner_name;
1565 $this->factures = $factures_prev_id;
1566 $this->context[
'factures_prev'] = $factures_prev;
1570 if ($sourcetype ==
'salary') {
1571 $userid = $this->context[
'factures_prev'][0][2];
1573 $result = $this->
generate($format, $executiondate, $type, $fk_bank_account, $userid, 0);
1580 dol_syslog(__METHOD__ .
" Bank order file has been generated under filename " . $this->filename, LOG_DEBUG);
1588 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_bons";
1589 $sql .=
" SET amount = " .
price2num($this->total);
1590 $sql .=
" WHERE rowid = " . ((int) $this->
id);
1591 $sql .=
" AND entity = " . ((int)
$conf->entity);
1592 $resql = $this->db->query($sql);
1596 dol_syslog(__METHOD__ .
" Error update total: " . $this->db->error(), LOG_ERR);
1600 if (!$error && !$notrigger) {
1601 $triggerName =
'DIRECT_DEBIT_ORDER_CREATE';
1602 if ($type !=
'bank-transfer') {
1603 $triggerName =
'CREDIT_TRANSFER_ORDER_CREATE';
1607 $result = $this->call_trigger($triggerName, $user);
1615 $this->db->commit();
1616 return count($factures_prev);
1618 $this->db->rollback();
1634 public function delete($user, $notrigger = 0)
1639 $resql1 = $resql2 = $resql3 = $resql4 = 0;
1642 $triggername =
'DIRECT_DEBIT_ORDER_DELETE';
1643 if ($this->
type ==
'bank-transfer') {
1644 $triggername =
'PAYMENTBYBANKTRANFER_DELETE';
1647 $result = $this->call_trigger($triggername, $user);
1655 $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) .
")";
1656 $resql1 = $this->db->query($sql);
1663 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"prelevement_lignes WHERE fk_prelevement_bons = " . ((int) $this->
id);
1664 $resql2 = $this->db->query($sql);
1671 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"prelevement_bons WHERE rowid = " . ((int) $this->
id);
1672 $resql3 = $this->db->query($sql);
1679 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_demande SET fk_prelevement_bons = NULL, traite = 0 WHERE fk_prelevement_bons = " . ((int) $this->
id);
1680 $resql4 = $this->db->query($sql);
1686 if ($resql1 && $resql2 && $resql3 && $resql4 && !$error) {
1687 $this->db->commit();
1690 $this->db->rollback();
1706 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1708 global
$conf, $langs, $hookmanager;
1710 if (!empty(
$conf->dol_no_mouse_hover)) {
1716 $labeltoshow =
'PaymentByDirectDebit';
1717 $labelforclosedate =
'CreditDate';
1718 if (!empty($this->
type) && $this->
type ==
'bank-transfer') {
1719 $labeltoshow =
'PaymentByBankTransfer';
1720 $labelforclosedate =
'ClosedOn';
1723 $label =
img_picto(
'', $this->picto) .
' <u>' . $langs->trans($labeltoshow) .
'</u> ' . $this->
getLibStatut(5);
1725 $label .=
'<b>' . $langs->trans(
'Ref') .
':</b> ' . $this->ref;
1726 if (isset($this->
amount)) {
1727 $label .=
'<br><b>' . $langs->trans(
"Amount") .
':</b> <span class="amount">' .
price($this->
amount).
'</span>';
1729 if (isset($this->date_creation)) {
1730 $label .=
'<br><b>'.$langs->trans(
"DateCreation").
":</b> ".
dol_print_date($this->date_creation,
'dayhour',
'tzuserrel');
1732 if (isset($this->date_trans)) {
1733 $label .=
'<br><b>' . $langs->trans(
"TransData") .
":</b> " .
dol_print_date($this->date_trans,
'dayhour',
'tzuserrel');
1735 if (isset($this->date_credit)) {
1736 $label .=
'<br><b>'.$langs->trans($labelforclosedate).
":</b> ".
dol_print_date($this->date_credit,
'dayhour',
'tzuserrel');
1739 $url = DOL_URL_ROOT .
'/compta/prelevement/card.php?id=' . $this->id;
1740 if (!empty($this->
type) && $this->
type ==
'bank-transfer') {
1741 $url = DOL_URL_ROOT .
'/compta/prelevement/card.php?id=' . $this->id;
1744 if ($option !=
'nolink') {
1746 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1747 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1748 $add_save_lastsearch_values = 1;
1750 if ($add_save_lastsearch_values) {
1751 $url .=
'&save_lastsearch_values=1';
1756 if (empty($notooltip)) {
1758 $label = $langs->trans(
"ShowMyObject");
1762 $linkclose .=
' class="classfortooltip' . ($morecss ?
' ' . $morecss :
'') .
'"';
1764 $linkclose = ($morecss ?
' class="' . $morecss .
'"' :
'');
1767 $linkstart =
'<a href="' . $url .
'"';
1768 $linkstart .= $linkclose .
'>';
1771 $result .= $linkstart;
1773 $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);
1775 if ($withpicto != 2) {
1776 $result .= $this->ref;
1778 $result .= $linkend;
1780 global $action, $hookmanager;
1781 $hookmanager->initHooks(array(
'banktransferdao'));
1782 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1783 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1785 $result = $hookmanager->resPrint;
1787 $result .= $hookmanager->resPrint;
1802 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"notify_def";
1803 $sql .=
" WHERE rowid = " . ((int) $rowid);
1805 if ($this->db->query($sql)) {
1821 if (is_object($user)) {
1822 $userid = $user->id;
1827 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"notify_def";
1828 $sql .=
" WHERE fk_user=" . ((int) $userid) .
" AND fk_action='" . $this->db->escape($action) .
"'";
1830 if ($this->db->query($sql)) {
1851 if (is_object($user)) {
1852 $userid = $user->id;
1860 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"notify_def (datec,fk_user, fk_soc, fk_contact, fk_action)";
1861 $sql .=
" VALUES ('" . $this->db->idate($now) .
"', " . ((int) $userid) .
", 'NULL', 'NULL', '" . $this->db->escape($action) .
"')";
1864 if ($this->db->query($sql)) {
1868 dol_syslog(get_class($this) .
"::addNotification Error $result");
1891 public function generate(
string $format =
'ALL',
int $executiondate = 0,
string $type =
'direct-debit',
int $fk_bank_account = 0,
int $forsalary = 0,
int $thirdpartyBANId = 0)
1898 if (empty($fk_bank_account)) {
1899 $fk_bank_account = ($type ==
'bank-transfer' ?
getDolGlobalInt(
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') :
getDolGlobalInt(
'PRELEVEMENT_ID_BANKACCOUNT'));
1904 dol_syslog(get_class($this) .
"::generate build file=" . $this->filename .
" type=" . $type);
1906 $this->file = fopen($this->filename,
"w");
1907 if ($this->file ==
false) {
1908 $this->error = $langs->trans(
'ErrorFailedToOpenFile', $this->filename);
1916 if (
$mysoc->isInSEPA()) {
1919 if ($type !=
'bank-transfer') {
1931 if (!empty($executiondate)) {
1932 $date_actu = $executiondate;
1937 $fileDebiteurSection =
'';
1938 $fileEmetteurSection =
'';
1945 $sql =
"SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
1947 $sql .=
" pl.client_nom as nom, pl.amount as somme, pl.fk_prelevement_demande,";
1948 $sql .=
" f.ref as reffac,";
1949 $sql .=
" p.fk_facture as idfac, p.rowid as pid,";
1950 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
1952 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
1953 $sql .=
" " . MAIN_DB_PREFIX .
"facture as f,";
1954 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p,";
1955 $sql .=
" " . MAIN_DB_PREFIX .
"societe as soc,";
1956 $sql .=
" " . MAIN_DB_PREFIX .
"c_country as c,";
1957 $sql .=
" " . MAIN_DB_PREFIX .
"societe_rib as rib";
1958 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
1959 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
1960 $sql .=
" AND p.fk_facture = f.rowid";
1961 $sql .=
" AND f.fk_soc = soc.rowid";
1962 $sql .=
" AND soc.fk_pays = c.rowid";
1963 $sql .=
" AND rib.fk_soc = f.fk_soc";
1964 if (!empty($thirdpartyBANId)) {
1965 $sql .=
" AND rib.rowid = " . ((int) $thirdpartyBANId);
1967 $sql .=
" AND rib.default_rib = 1";
1969 $sql .=
" AND rib.type = 'ban'";
1972 $resql = $this->db->query($sql);
1973 $nbtotalDrctDbtTxInf = -1;
1975 $cachearraytotestduplicate = array();
1977 $num = $this->db->num_rows($resql);
1979 $obj = $this->db->fetch_object($resql);
1981 if (!empty($cachearraytotestduplicate[$obj->idfac])) {
1982 $this->error = $langs->trans(
'ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
1983 $this->invoice_in_error[$obj->idfac] = $this->error;
1987 $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
1990 $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
1997 if (!empty($obj->fk_prelevement_demande)) {
1998 $companybankaccountid = 0;
2000 $sqltmp =
"SELECT fk_societe_rib FROM ".MAIN_DB_PREFIX.
"prelevement_demande";
2001 $sqltmp .=
" WHERE rowid = ".((int) $obj->fk_prelevement_demande);
2003 $resqltmp = $this->db->query($sqltmp);
2005 $objtmp = $this->db->fetch_object($resqltmp);
2007 $companybankaccountid = (int) $objtmp->fk_societe_rib;
2011 $bankaccount->fetch($companybankaccountid);
2012 if ($bankaccount->id > 0) {
2013 $daterum = $bankaccount->date_rum;
2014 $iban = $bankaccount->iban;
2015 $bic = $bankaccount->bic;
2016 $drum = $bankaccount->id;
2017 $rum = $bankaccount->rum;
2021 $fileDebiteurSection .= $this->
EnregDestinataireSEPA($obj->code, $obj->nom, $obj->address, $obj->zip, $obj->town, $obj->country_code,
'',
'',
'', $obj->somme, $obj->reffac, $obj->idfac, $iban, $bic, $daterum, (
string) $drum, $rum, $type);
2023 $this->total += $obj->somme;
2026 $nbtotalDrctDbtTxInf = $i;
2028 $this->error = $this->db->lasterror();
2029 fwrite($this->file,
'ERROR DEBITOR ' . $sql . $CrLf);
2034 if ($result != -2) {
2035 $fileEmetteurSection .= $this->
EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type, $fk_bank_account);
2039 $this->total = number_format((
float)
price2num($this->total,
'MT'), 2,
".",
"");
2046 fwrite($this->file,
'<' .
'?xml version="1.0" encoding="UTF-8" standalone="yes"?' .
'>' . $CrLf);
2047 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);
2048 fwrite($this->file,
' <CstmrDrctDbtInitn>' . $CrLf);
2050 fwrite($this->file,
' <GrpHdr>' . $CrLf);
2051 fwrite($this->file,
' <MsgId>' . (
'DOL/' . $dateTime_YMD .
'/DD' . $this->
id) .
'</MsgId>' . $CrLf);
2052 fwrite($this->file,
' <CreDtTm>' . $dateTime_ECMA .
'</CreDtTm>' . $CrLf);
2053 fwrite($this->file,
' <NbOfTxs>' . $i .
'</NbOfTxs>' . $CrLf);
2054 fwrite($this->file,
' <CtrlSum>' . $this->total .
'</CtrlSum>' . $CrLf);
2055 fwrite($this->file,
' <InitgPty>' . $CrLf);
2057 fwrite($this->file,
' <Id>' . $CrLf);
2058 fwrite($this->file,
' <PrvtId>' . $CrLf);
2059 fwrite($this->file,
' <Othr>' . $CrLf);
2060 fwrite($this->file,
' <Id>' . $this->emetteur_ics .
'</Id>' . $CrLf);
2061 fwrite($this->file,
' </Othr>' . $CrLf);
2062 fwrite($this->file,
' </PrvtId>' . $CrLf);
2063 fwrite($this->file,
' </Id>' . $CrLf);
2064 fwrite($this->file,
' </InitgPty>' . $CrLf);
2065 fwrite($this->file,
' </GrpHdr>' . $CrLf);
2067 if ($result != -2) {
2068 fwrite($this->file, $fileEmetteurSection);
2071 if ($result != -2) {
2072 fwrite($this->file, $fileDebiteurSection);
2075 fwrite($this->file,
' </PmtInf>' . $CrLf);
2076 fwrite($this->file,
' </CstmrDrctDbtInitn>' . $CrLf);
2077 fwrite($this->file,
'</Document>' . $CrLf);
2090 if (!empty($executiondate)) {
2091 $date_actu = $executiondate;
2096 $fileCrediteurSection =
'';
2097 $fileEmetteurSection =
'';
2103 if (!empty($forsalary)) {
2104 $sql =
"SELECT u.rowid as userId, u.address, u.zip, u.town, c.code as country_code, CONCAT(u.firstname,' ',u.lastname) as nom,";
2106 $sql .=
" pl.client_nom as nom, pl.amount as somme, pl.fk_prelevement_demande,";
2107 $sql .=
" s.ref as reffac,";
2108 $sql .=
" p.fk_salary as idfac,";
2109 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, '' as rum, '' as date_rum";
2111 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
2112 $sql .=
" " . MAIN_DB_PREFIX .
"salary as s,";
2113 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p,";
2114 $sql .=
" " . MAIN_DB_PREFIX .
"user as u";
2115 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"c_country as c ON u.fk_country = c.rowid,";
2116 $sql .=
" " . MAIN_DB_PREFIX .
"user_rib as rib";
2117 $sql .=
" WHERE pl.fk_prelevement_bons=" . ((int) $this->
id);
2118 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
2119 $sql .=
" AND p.fk_salary = s.rowid";
2120 $sql .=
" AND s.fk_user = u.rowid";
2121 $sql .=
" AND rib.fk_user = s.fk_user";
2123 $sql =
"SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
2125 $sql .=
" pl.client_nom as nom, pl.amount as somme, pl.fk_prelevement_demande,";
2126 $sql .=
" f.ref as reffac, f.ref_supplier as fac_ref_supplier,";
2127 $sql .=
" p.fk_facture_fourn as idfac,";
2128 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
2130 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
2131 $sql .=
" " . MAIN_DB_PREFIX .
"facture_fourn as f,";
2132 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p,";
2133 $sql .=
" " . MAIN_DB_PREFIX .
"societe as soc";
2134 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"c_country as c ON soc.fk_pays = c.rowid,";
2135 $sql .=
" " . MAIN_DB_PREFIX .
"societe_rib as rib";
2136 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
2137 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
2138 $sql .=
" AND p.fk_facture_fourn = f.rowid";
2139 $sql .=
" AND f.fk_soc = soc.rowid";
2140 $sql .=
" AND rib.fk_soc = f.fk_soc";
2141 if (!empty($thirdpartyBANId)) {
2142 $sql .=
" AND rib.rowid = " . ((int) $thirdpartyBANId);
2144 $sql .=
" AND rib.default_rib = 1";
2146 $sql .=
" AND rib.type = 'ban'";
2149 $nbtotalDrctDbtTxInf = -1;
2151 require_once DOL_DOCUMENT_ROOT .
'/societe/class/companybankaccount.class.php';
2153 $resql = $this->db->query($sql);
2155 $cachearraytotestduplicate = array();
2157 $num = $this->db->num_rows($resql);
2159 $obj = $this->db->fetch_object($resql);
2162 if (!empty($cachearraytotestduplicate[$obj->idfac])) {
2163 $this->error = $langs->trans(
'ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
2164 $this->invoice_in_error[$obj->idfac] = $this->error;
2169 $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
2172 $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
2179 if (!empty($obj->fk_prelevement_demande)) {
2180 $companybankaccountid = 0;
2182 $sqltmp =
"SELECT fk_societe_rib FROM ".MAIN_DB_PREFIX.
"prelevement_demande";
2183 $sqltmp .=
" WHERE rowid = ".((int) $obj->fk_prelevement_demande);
2185 $resqltmp = $this->db->query($sqltmp);
2187 $objtmp = $this->db->fetch_object($resqltmp);
2189 $companybankaccountid = (int) $objtmp->fk_societe_rib;
2193 $bankaccount->fetch($companybankaccountid);
2194 if ($bankaccount->id > 0) {
2195 $daterum = $bankaccount->date_rum;
2196 $iban = $bankaccount->iban;
2197 $bic = $bankaccount->bic;
2198 $drum = $bankaccount->id;
2199 $rum = $bankaccount->rum;
2203 $refobj = $obj->reffac;
2204 if (empty($refobj) && !empty($forsalary)) {
2205 $refobj =
"SAL" . $obj->idfac;
2208 $fileCrediteurSection .= $this->
EnregDestinataireSEPA($obj->code, $obj->nom, $obj->address, $obj->zip, $obj->town, $obj->country_code,
'',
'',
'', $obj->somme, $refobj, $obj->idfac, $iban, $bic, $daterum, (
string) $drum, $rum, $type, $obj->fac_ref_supplier);
2210 $this->total += $obj->somme;
2213 $nbtotalDrctDbtTxInf = $i;
2215 $this->error = $this->db->lasterror();
2216 fwrite($this->file,
'ERROR CREDITOR ' . $sql . $CrLf);
2220 if ($result != -2) {
2221 $fileEmetteurSection .= $this->
EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type);
2225 $this->total = number_format((
float)
price2num($this->total,
'MT'), 2,
".",
"");
2232 fwrite($this->file,
'<' .
'?xml version="1.0" encoding="UTF-8" standalone="yes"?' .
'>' . $CrLf);
2233 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);
2234 fwrite($this->file,
' <CstmrCdtTrfInitn>' . $CrLf);
2236 fwrite($this->file,
' <GrpHdr>' . $CrLf);
2237 fwrite($this->file,
' <MsgId>' . (
'DOL/' . $dateTime_YMD .
'/CT' . $this->
id) .
'</MsgId>' . $CrLf);
2238 fwrite($this->file,
' <CreDtTm>' . $dateTime_ECMA .
'</CreDtTm>' . $CrLf);
2239 fwrite($this->file,
' <NbOfTxs>' . $i .
'</NbOfTxs>' . $CrLf);
2240 fwrite($this->file,
' <CtrlSum>' . $this->total .
'</CtrlSum>' . $CrLf);
2241 fwrite($this->file,
' <InitgPty>' . $CrLf);
2243 fwrite($this->file,
' <Id>' . $CrLf);
2244 fwrite($this->file,
' <PrvtId>' . $CrLf);
2245 fwrite($this->file,
' <Othr>' . $CrLf);
2246 fwrite($this->file,
' <Id>' . $this->emetteur_ics .
'</Id>' . $CrLf);
2247 fwrite($this->file,
' </Othr>' . $CrLf);
2248 fwrite($this->file,
' </PrvtId>' . $CrLf);
2249 fwrite($this->file,
' </Id>' . $CrLf);
2250 fwrite($this->file,
' </InitgPty>' . $CrLf);
2251 fwrite($this->file,
' </GrpHdr>' . $CrLf);
2253 if ($result != -2) {
2254 fwrite($this->file, $fileEmetteurSection);
2257 if ($result != -2) {
2258 fwrite($this->file, $fileCrediteurSection);
2261 fwrite($this->file,
' </PmtInf>' . $CrLf);
2262 fwrite($this->file,
' </CstmrCdtTrfInitn>' . $CrLf);
2263 fwrite($this->file,
'</Document>' . $CrLf);
2269 if ($type !=
'bank-transfer') {
2270 $sql =
"SELECT pl.amount";
2272 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
2273 $sql .=
" " . MAIN_DB_PREFIX .
"facture as f,";
2274 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p";
2275 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
2276 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
2277 $sql .=
" AND p.fk_facture = f.rowid";
2281 $resql = $this->db->query($sql);
2283 $num = $this->db->num_rows($resql);
2286 $obj = $this->db->fetch_object($resql);
2287 $this->total += $obj->amount;
2296 $sql =
"SELECT pl.amount";
2298 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
2299 $sql .=
" " . MAIN_DB_PREFIX .
"facture_fourn as f,";
2300 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p";
2301 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
2302 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
2303 $sql .=
" AND p.fk_facture_fourn = f.rowid";
2306 $resql = $this->db->query($sql);
2308 $num = $this->db->num_rows($resql);
2311 $obj = $this->db->fetch_object($resql);
2312 $this->total += $obj->amount;
2322 $langs->load(
'withdrawals');
2325 fwrite($this->file, $langs->transnoentitiesnoconv(
'WithdrawalFileNotCapable',
$mysoc->country_code));
2328 fclose($this->file);
2350 return $pre .
'-' .
dol_print_date($row_datec,
'dayhourlogsmall') .
'-' .
dol_trunc((
string) $row_drum . ($row_code_client ?
'-' . $row_code_client :
''), 17,
'right',
'UTF-8', 1);
2371 public function EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $ref, $facid, $rib_dom =
'', $type =
'direct-debit')
2374 fwrite($this->file,
"06");
2375 fwrite($this->file,
"08");
2377 fwrite($this->file,
" ");
2379 fwrite($this->file, $this->emetteur_ics);
2383 fwrite($this->file,
" ");
2384 fwrite($this->file,
dol_print_date($this->date_echeance,
"%d%m",
'gmt'));
2385 fwrite($this->file, substr(
dol_print_date($this->date_echeance,
"%y",
'gmt'), 1));
2389 fwrite($this->file, substr(strtoupper($client_nom) .
" ", 0, 24));
2392 $address = strtr($rib_dom, array(
" " =>
"-", chr(13) =>
" ", chr(10) =>
""));
2393 fwrite($this->file, substr($address .
" ", 0, 24));
2397 fwrite($this->file, substr(
" ", 0, 8));
2401 fwrite($this->file, $rib_guichet);
2405 fwrite($this->file, substr(
"000000000000000" . $rib_number, -11));
2409 $montant = (round($amount, 2) * 100);
2411 fwrite($this->file, substr(
"000000000000000" . $montant, -16));
2415 fwrite($this->file, substr(
"*_" . $ref .
"_RDVnet" . $rowid .
" ", 0, 31));
2419 fwrite($this->file, $rib_banque);
2423 fwrite($this->file, substr(
" ", 0, 5));
2425 fwrite($this->file,
"\n");
2455 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 =
'')
2461 $row_somme = number_format((
float)
price2num($row_somme,
'MT'), 2,
".",
"");
2463 $row_somme = round((
float) $row_somme, 2);
2466 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
2469 $Rowing = sprintf(
"%010d", $row_idfac);
2473 $Rum = (empty($row_rum) ? $this->
buildRumNumber($row_code_client, $row_datec, $row_drum) : $row_rum);
2479 if (!is_object($hookmanager)) {
2480 include_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
2483 $hookmanager->initHooks(array(
'bonprelevementdao'));
2484 $parameters = array(
2485 'row_code_client' => &$row_code_client,
'row_nom' => &$row_nom,
'row_address' => &$row_address,
'row_zip' => &$row_zip,
'row_town' => &$row_town,
2486 'row_country_code' => &$row_country_code,
'row_cb' => &$row_cb,
'row_cg' => &$row_cg,
'row_cc' => &$row_cc,
'row_somme' => &$row_somme,
2487 'row_ref' => &$row_ref,
'row_idfac' => &$row_idfac,
'row_iban' => &$row_iban,
'row_bic' => &$row_bic,
'row_datec' => &$row_datec,
2488 'row_drum' => &$row_drum,
'row_rum' => &$row_rum,
'type' => &$type,
'row_comment' => &$row_comment,
2489 'crlf' => &$CrLf,
'rowing' => &$Rowing,
'rum' => &$Rum,
'dtofsgntr' => &$DtOfSgntr,
2491 $reshook = $hookmanager->executeHooks(
'enregDestinataireSEPA', $parameters, $this);
2492 if (empty($reshook)) {
2493 if ($type !=
'bank-transfer') {
2496 $XML_DEBITOR .=
' <DrctDbtTxInf>' . $CrLf;
2497 $XML_DEBITOR .=
' <PmtId>' . $CrLf;
2499 $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;
2500 $XML_DEBITOR .=
' </PmtId>' . $CrLf;
2501 $XML_DEBITOR .=
' <InstdAmt Ccy="EUR">' . $row_somme .
'</InstdAmt>' . $CrLf;
2502 $XML_DEBITOR .=
' <DrctDbtTx>' . $CrLf;
2503 $XML_DEBITOR .=
' <MndtRltdInf>' . $CrLf;
2504 $XML_DEBITOR .=
' <MndtId>' . $Rum .
'</MndtId>' . $CrLf;
2505 $XML_DEBITOR .=
' <DtOfSgntr>' . $DtOfSgntr .
'</DtOfSgntr>' . $CrLf;
2506 $XML_DEBITOR .=
' <AmdmntInd>false</AmdmntInd>' . $CrLf;
2507 $XML_DEBITOR .=
' </MndtRltdInf>' . $CrLf;
2508 $XML_DEBITOR .=
' </DrctDbtTx>' . $CrLf;
2509 $XML_DEBITOR .=
' <DbtrAgt>' . $CrLf;
2510 $XML_DEBITOR .=
' <FinInstnId>' . $CrLf;
2512 $XML_DEBITOR .=
' <BIC>' . $row_bic .
'</BIC>' . $CrLf;
2514 $XML_DEBITOR .=
' </FinInstnId>' . $CrLf;
2515 $XML_DEBITOR .=
' </DbtrAgt>' . $CrLf;
2516 $XML_DEBITOR .=
' <Dbtr>' . $CrLf;
2518 $XML_DEBITOR .=
' <PstlAdr>' . $CrLf;
2519 $XML_DEBITOR .=
' <Ctry>' . $row_country_code .
'</Ctry>' . $CrLf;
2520 $addressline1 = strtr($row_address, array(chr(13) =>
", ", chr(10) =>
""));
2521 $addressline2 = strtr($row_zip . (($row_zip && $row_town) ?
' ' :
'') . (
string) $row_town, array(chr(13) =>
", ", chr(10) =>
""));
2522 if (trim($addressline1)) {
2525 if (trim($addressline2)) {
2528 $XML_DEBITOR .=
' </PstlAdr>' . $CrLf;
2529 $XML_DEBITOR .=
' </Dbtr>' . $CrLf;
2530 $XML_DEBITOR .=
' <DbtrAcct>' . $CrLf;
2531 $XML_DEBITOR .=
' <Id>' . $CrLf;
2532 $XML_DEBITOR .=
' <IBAN>' . preg_replace(
'/\s/',
'', $row_iban) .
'</IBAN>' . $CrLf;
2533 $XML_DEBITOR .=
' </Id>' . $CrLf;
2534 $XML_DEBITOR .=
' </DbtrAcct>' . $CrLf;
2535 $XML_DEBITOR .=
' <RmtInf>' . $CrLf;
2539 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functions_be.lib.php';
2541 $invoicestatic =
new Facture($this->db);
2542 $invoicestatic->fetch($row_idfac);
2545 $XML_DEBITOR .=
' <strd>' . $invoicePaymentKey .
'</strd>' . $CrLf;
2550 $XML_DEBITOR .=
' </RmtInf>' . $CrLf;
2551 $XML_DEBITOR .=
' </DrctDbtTxInf>' . $CrLf;
2553 $XML_RESULT = $XML_DEBITOR;
2557 $XML_CREDITOR .=
' <CdtTrfTxInf>' . $CrLf;
2558 $XML_CREDITOR .=
' <PmtId>' . $CrLf;
2560 $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;
2561 $XML_CREDITOR .=
' </PmtId>' . $CrLf;
2562 if (!empty($this->sepa_xml_pti_in_ctti)) {
2563 $XML_CREDITOR .=
' <PmtTpInf>' . $CrLf;
2567 $instrprty =
'HIGH';
2569 $instrprty =
'NORM';
2573 $categoryPurpose =
getDolGlobalString(
'PAYMENTBYBANKTRANSFER_CUSTOM_CATEGORY_PURPOSE',
'CORE');
2575 $XML_CREDITOR .=
' <InstrPrty>' . $instrprty .
'</InstrPrty>' . $CrLf;
2576 $XML_CREDITOR .=
' <SvcLvl>' . $CrLf;
2577 $XML_CREDITOR .=
' <Cd>SEPA</Cd>' . $CrLf;
2578 $XML_CREDITOR .=
' </SvcLvl>' . $CrLf;
2579 $XML_CREDITOR .=
' <CtgyPurp>' . $CrLf;
2580 $XML_CREDITOR .=
' <Cd>' . $categoryPurpose .
'</Cd>' . $CrLf;
2581 $XML_CREDITOR .=
' </CtgyPurp>' . $CrLf;
2582 $XML_CREDITOR .=
' </PmtTpInf>' . $CrLf;
2584 $XML_CREDITOR .=
' <Amt>' . $CrLf;
2585 $XML_CREDITOR .=
' <InstdAmt Ccy="EUR">' . round((
float) $row_somme, 2) .
'</InstdAmt>' . $CrLf;
2586 $XML_CREDITOR .=
' </Amt>' . $CrLf;
2597 $XML_CREDITOR .=
' <CdtrAgt>' . $CrLf;
2598 $XML_CREDITOR .=
' <FinInstnId>' . $CrLf;
2599 $XML_CREDITOR .=
' <BIC>' . $row_bic .
'</BIC>' . $CrLf;
2600 $XML_CREDITOR .=
' </FinInstnId>' . $CrLf;
2601 $XML_CREDITOR .=
' </CdtrAgt>' . $CrLf;
2602 $XML_CREDITOR .=
' <Cdtr>' . $CrLf;
2604 $XML_CREDITOR .=
' <PstlAdr>' . $CrLf;
2605 $XML_CREDITOR .=
' <Ctry>' . $row_country_code .
'</Ctry>' . $CrLf;
2606 $addressline1 = strtr($row_address, array(chr(13) =>
", ", chr(10) =>
""));
2607 $addressline2 = strtr($row_zip . (($row_zip && $row_town) ?
' ' :
'') . (
string) $row_town, array(chr(13) =>
", ", chr(10) =>
""));
2608 if (trim($addressline1)) {
2611 if (trim($addressline2)) {
2614 $XML_CREDITOR .=
' </PstlAdr>' . $CrLf;
2615 $XML_CREDITOR .=
' </Cdtr>' . $CrLf;
2616 $XML_CREDITOR .=
' <CdtrAcct>' . $CrLf;
2617 $XML_CREDITOR .=
' <Id>' . $CrLf;
2618 $XML_CREDITOR .=
' <IBAN>' . preg_replace(
'/\s/',
'', $row_iban) .
'</IBAN>' . $CrLf;
2619 $XML_CREDITOR .=
' </Id>' . $CrLf;
2620 $XML_CREDITOR .=
' </CdtrAcct>' . $CrLf;
2621 $XML_CREDITOR .=
' <RmtInf>' . $CrLf;
2624 $XML_CREDITOR .=
' </RmtInf>' . $CrLf;
2625 $XML_CREDITOR .=
' </CdtTrfTxInf>' . $CrLf;
2627 $XML_RESULT = $XML_CREDITOR;
2629 } elseif ($reshook > 0) {
2630 $XML_RESULT = $hookmanager->resPrint;
2632 $XML_RESULT .= $hookmanager->resPrint;
2650 fwrite($this->file,
"03");
2651 fwrite($this->file,
"08");
2653 fwrite($this->file,
" ");
2655 fwrite($this->file, $this->emetteur_ics);
2659 fwrite($this->file,
" ");
2660 fwrite($this->file,
dol_print_date($this->date_echeance,
"%d%m",
'gmt'));
2661 fwrite($this->file, substr(
dol_print_date($this->date_echeance,
"%y",
'gmt'), 1));
2665 fwrite($this->file, substr($this->raison_sociale .
" ", 0, 24));
2669 fwrite($this->file, substr($this->reference_remise .
" ", 0, 7));
2673 fwrite($this->file, substr(
" ", 0, 17));
2677 fwrite($this->file, substr(
" ", 0, 2));
2678 fwrite($this->file,
"E");
2679 fwrite($this->file, substr(
" ", 0, 5));
2683 fwrite($this->file, $this->emetteur_code_guichet);
2687 fwrite($this->file, substr(
"000000000000000" . $this->emetteur_numero_compte, -11));
2691 fwrite($this->file, substr(
" ", 0, 16));
2695 fwrite($this->file, substr(
" ", 0, 31));
2699 fwrite($this->file, $this->emetteur_code_banque);
2703 fwrite($this->file, substr(
" ", 0, 5));
2705 fwrite($this->file,
"\n");
2724 public function EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf =
'\n', $format =
'FRST', $type =
'direct-debit', $fk_bank_account = 0)
2734 if (empty($fk_bank_account)) {
2735 $fk_bank_account = ($type ==
'bank-transfer' ?
getDolGlobalInt(
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') :
getDolGlobalInt(
'PRELEVEMENT_ID_BANKACCOUNT'));
2739 $account =
new Account($this->db);
2740 if ($account->fetch($fk_bank_account) > 0) {
2741 $this->emetteur_code_banque = $account->code_banque;
2742 $this->emetteur_code_guichet = $account->code_guichet;
2743 $this->emetteur_numero_compte = $account->number;
2744 $this->emetteur_number_key = $account->cle_rib;
2745 $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
2746 $this->emetteur_iban = $account->iban;
2747 $this->emetteur_bic = $account->bic;
2749 $this->emetteur_ics = (($type ==
'bank-transfer' &&
getDolGlobalString(
"SEPA_USE_IDS")) ? $account->ics_transfer : $account->ics);
2751 $this->raison_sociale = $account->owner_name;
2755 $sql =
"SELECT rowid, ref";
2756 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons as pb";
2757 $sql .=
" WHERE pb.rowid = " . ((int) $this->
id);
2759 $resql = $this->db->query($sql);
2761 $obj = $this->db->fetch_object($resql);
2764 $IdBon = sprintf(
"%05d", $obj->rowid);
2765 $RefBon = $obj->ref;
2766 $localInstrument =
getDolGlobalString(
'PAYMENTBYBANKTRANSFER_CUSTOM_LOCAL_INSTRUMENT',
'CORE');
2769 $total = number_format((
float)
price2num($total,
'MT'), 2,
".",
"");
2772 if ($type !=
'bank-transfer') {
2774 $XML_SEPA_INFO =
'';
2775 $XML_SEPA_INFO .=
' <PmtInf>' . $CrLf;
2776 $XML_SEPA_INFO .=
' <PmtInfId>' . (
'DOL/' . $dateTime_YMD .
'/DD' . $IdBon .
'-' . $RefBon) .
'</PmtInfId>' . $CrLf;
2777 $XML_SEPA_INFO .=
' <PmtMtd>DD</PmtMtd>' . $CrLf;
2778 $XML_SEPA_INFO .=
' <NbOfTxs>' . $nombre .
'</NbOfTxs>' . $CrLf;
2779 $XML_SEPA_INFO .=
' <CtrlSum>' . $total .
'</CtrlSum>' . $CrLf;
2780 $XML_SEPA_INFO .=
' <PmtTpInf>' . $CrLf;
2781 $XML_SEPA_INFO .=
' <SvcLvl>' . $CrLf;
2782 $XML_SEPA_INFO .=
' <Cd>SEPA</Cd>' . $CrLf;
2783 $XML_SEPA_INFO .=
' </SvcLvl>' . $CrLf;
2784 $XML_SEPA_INFO .=
' <LclInstrm>' . $CrLf;
2785 $XML_SEPA_INFO .=
' <Cd>' . $localInstrument .
'</Cd>' . $CrLf;
2786 $XML_SEPA_INFO .=
' </LclInstrm>' . $CrLf;
2787 $XML_SEPA_INFO .=
' <SeqTp>' . $format .
'</SeqTp>' . $CrLf;
2788 $XML_SEPA_INFO .=
' </PmtTpInf>' . $CrLf;
2789 $XML_SEPA_INFO .=
' <ReqdColltnDt>' . $dateTime_ETAD .
'</ReqdColltnDt>' . $CrLf;
2790 $XML_SEPA_INFO .=
' <Cdtr>' . $CrLf;
2792 $XML_SEPA_INFO .=
' <PstlAdr>' . $CrLf;
2793 $XML_SEPA_INFO .=
' <Ctry>' . $country[1] .
'</Ctry>' . $CrLf;
2794 $addressline1 = strtr(
getDolGlobalString(
'MAIN_INFO_SOCIETE_ADDRESS'), array(chr(13) =>
", ", chr(10) =>
""));
2796 if ($addressline1) {
2799 if ($addressline2) {
2802 $XML_SEPA_INFO .=
' </PstlAdr>' . $CrLf;
2803 $XML_SEPA_INFO .=
' </Cdtr>' . $CrLf;
2804 $XML_SEPA_INFO .=
' <CdtrAcct>' . $CrLf;
2805 $XML_SEPA_INFO .=
' <Id>' . $CrLf;
2806 $XML_SEPA_INFO .=
' <IBAN>' . preg_replace(
'/\s/',
'', $this->emetteur_iban) .
'</IBAN>' . $CrLf;
2807 $XML_SEPA_INFO .=
' </Id>' . $CrLf;
2808 $XML_SEPA_INFO .=
' </CdtrAcct>' . $CrLf;
2809 $XML_SEPA_INFO .=
' <CdtrAgt>' . $CrLf;
2810 $XML_SEPA_INFO .=
' <FinInstnId>' . $CrLf;
2811 $XML_SEPA_INFO .=
' <BIC>' . $this->emetteur_bic .
'</BIC>' . $CrLf;
2812 $XML_SEPA_INFO .=
' </FinInstnId>' . $CrLf;
2813 $XML_SEPA_INFO .=
' </CdtrAgt>' . $CrLf;
2822 $XML_SEPA_INFO .=
' <ChrgBr>SLEV</ChrgBr>' . $CrLf;
2823 $XML_SEPA_INFO .=
' <CdtrSchmeId>' . $CrLf;
2824 $XML_SEPA_INFO .=
' <Id>' . $CrLf;
2825 $XML_SEPA_INFO .=
' <PrvtId>' . $CrLf;
2826 $XML_SEPA_INFO .=
' <Othr>' . $CrLf;
2827 $XML_SEPA_INFO .=
' <Id>' . $this->emetteur_ics .
'</Id>' . $CrLf;
2828 $XML_SEPA_INFO .=
' <SchmeNm>' . $CrLf;
2829 $XML_SEPA_INFO .=
' <Prtry>SEPA</Prtry>' . $CrLf;
2830 $XML_SEPA_INFO .=
' </SchmeNm>' . $CrLf;
2831 $XML_SEPA_INFO .=
' </Othr>' . $CrLf;
2832 $XML_SEPA_INFO .=
' </PrvtId>' . $CrLf;
2833 $XML_SEPA_INFO .=
' </Id>' . $CrLf;
2834 $XML_SEPA_INFO .=
' </CdtrSchmeId>' . $CrLf;
2837 $XML_SEPA_INFO =
'';
2838 $XML_SEPA_INFO .=
' <PmtInf>' . $CrLf;
2839 $XML_SEPA_INFO .=
' <PmtInfId>' . (
'DOL/' . $dateTime_YMD .
'/CT' . $IdBon .
'-' . $RefBon) .
'</PmtInfId>' . $CrLf;
2840 $XML_SEPA_INFO .=
' <PmtMtd>TRF</PmtMtd>' . $CrLf;
2842 $XML_SEPA_INFO .=
' <NbOfTxs>' . $nombre .
'</NbOfTxs>' . $CrLf;
2843 $XML_SEPA_INFO .=
' <CtrlSum>' . $total .
'</CtrlSum>' . $CrLf;
2844 if (!empty($this->sepa_xml_pti_in_ctti) && !empty($format)) {
2845 $XML_SEPA_INFO .=
' <PmtTpInf>' . $CrLf;
2846 $XML_SEPA_INFO .=
' <SvcLvl>' . $CrLf;
2847 $XML_SEPA_INFO .=
' <Cd>SEPA</Cd>' . $CrLf;
2848 $XML_SEPA_INFO .=
' </SvcLvl>' . $CrLf;
2849 $XML_SEPA_INFO .=
' <LclInstrm>' . $CrLf;
2850 $XML_SEPA_INFO .=
' <Cd>' . $localInstrument .
'</Cd>' . $CrLf;
2851 $XML_SEPA_INFO .=
' </LclInstrm>' . $CrLf;
2852 $XML_SEPA_INFO .=
' <SeqTp>' . $format .
'</SeqTp>' . $CrLf;
2853 $XML_SEPA_INFO .=
' </PmtTpInf>' . $CrLf;
2855 $XML_SEPA_INFO .=
' <ReqdExctnDt>' .
dol_print_date($dateTime_ETAD,
'dayrfc') .
'</ReqdExctnDt>' . $CrLf;
2856 $XML_SEPA_INFO .=
' <Dbtr>' . $CrLf;
2858 $XML_SEPA_INFO .=
' <PstlAdr>' . $CrLf;
2859 $XML_SEPA_INFO .=
' <Ctry>' . $country[1] .
'</Ctry>' . $CrLf;
2860 $addressline1 = strtr(
getDolGlobalString(
'MAIN_INFO_SOCIETE_ADDRESS'), array(chr(13) =>
", ", chr(10) =>
""));
2862 if ($addressline1) {
2865 if ($addressline2) {
2868 $XML_SEPA_INFO .=
' </PstlAdr>' . $CrLf;
2869 $XML_SEPA_INFO .=
' </Dbtr>' . $CrLf;
2870 $XML_SEPA_INFO .=
' <DbtrAcct>' . $CrLf;
2871 $XML_SEPA_INFO .=
' <Id>' . $CrLf;
2872 $XML_SEPA_INFO .=
' <IBAN>' . preg_replace(
'/\s/',
'', $this->emetteur_iban) .
'</IBAN>' . $CrLf;
2873 $XML_SEPA_INFO .=
' </Id>' . $CrLf;
2874 $XML_SEPA_INFO .=
' </DbtrAcct>' . $CrLf;
2875 $XML_SEPA_INFO .=
' <DbtrAgt>' . $CrLf;
2876 $XML_SEPA_INFO .=
' <FinInstnId>' . $CrLf;
2877 $XML_SEPA_INFO .=
' <BIC>' . $this->emetteur_bic .
'</BIC>' . $CrLf;
2878 $XML_SEPA_INFO .=
' </FinInstnId>' . $CrLf;
2879 $XML_SEPA_INFO .=
' </DbtrAgt>' . $CrLf;
2888 $XML_SEPA_INFO .=
' <ChrgBr>SLEV</ChrgBr>' . $CrLf;
2903 fwrite($this->file,
'INCORRECT EMETTEUR ' . $this->raison_sociale . $CrLf);
2904 $XML_SEPA_INFO =
'';
2906 return $XML_SEPA_INFO;
2919 fwrite($this->file,
"08");
2920 fwrite($this->file,
"08");
2922 fwrite($this->file,
" ");
2924 fwrite($this->file, $this->emetteur_ics);
2928 fwrite($this->file, substr(
" ", 0, 12));
2933 fwrite($this->file, substr(
" ", 0, 24));
2937 fwrite($this->file, substr(
" ", 0, 24));
2941 fwrite($this->file, substr(
" ", 0, 8));
2945 fwrite($this->file, substr(
" ", 0, 5));
2949 fwrite($this->file, substr(
" ", 0, 11));
2953 $montant = ($total * 100);
2955 fwrite($this->file, substr(
"000000000000000" . $montant, -16));
2959 fwrite($this->file, substr(
" ", 0, 31));
2963 fwrite($this->file, substr(
" ", 0, 5));
2967 fwrite($this->file, substr(
" ", 0, 5));
2969 fwrite($this->file,
"\n");
2994 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
2997 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'StatusWaiting');
2998 $this->labelStatus[self::STATUS_TRANSFERED] = $langs->transnoentitiesnoconv(
'StatusTrans');
2999 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'StatusWaiting');
3000 $this->labelStatusShort[self::STATUS_TRANSFERED] = $langs->transnoentitiesnoconv(
'StatusTrans');
3001 if ($this->
type ==
'bank-transfer') {
3002 $this->labelStatus[self::STATUS_DEBITED] = $langs->transnoentitiesnoconv(
'StatusDebited');
3003 $this->labelStatusShort[self::STATUS_DEBITED] = $langs->transnoentitiesnoconv(
'StatusDebited');
3005 $this->labelStatus[self::STATUS_CREDITED] = $langs->transnoentitiesnoconv(
'StatusCredited');
3006 $this->labelStatusShort[self::STATUS_CREDITED] = $langs->transnoentitiesnoconv(
'StatusCredited');
3008 $this->labelStatus[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Canceled');
3009 $this->labelStatusShort[self::STATUS_CANCELED] = $langs->transnoentitiesnoconv(
'Canceled');
3012 $statusType =
'status1';
3013 if ($status == self::STATUS_TRANSFERED) {
3014 $statusType =
'status3';
3016 if ($status == self::STATUS_CREDITED || $status == self::STATUS_DEBITED) {
3017 $statusType =
'status6';
3019 if ($status == self::STATUS_CANCELED) {
3020 $statusType =
'status9';
3023 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
3037 global
$conf, $langs;
3043 if ($mode ==
'direct-debit') {
3044 $sql =
"SELECT p.rowid, p.date_trans as date_trans, p.date_credit as date_credit";
3045 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons as p";
3046 $sql .=
" WHERE p.entity IN (" .
getEntity(
'prelevement_bons') .
")";
3047 $sql .=
" AND (p.type = 'debit-order' OR p.type = 'direct-debit')";
3048 $sql .=
" AND p.statut < ".((int) BonPrelevement::STATUS_DEBITED);
3050 $sql =
"SELECT p.rowid, p.date_trans as date_trans, p.date_credit as date_credit";
3051 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons as p";
3052 $sql .=
" WHERE p.entity IN (" .
getEntity(
'prelevement_bons') .
")";
3053 $sql .=
" AND (p.type = 'bank-transfer' OR p.type = 'credit-transfer')";
3054 $sql .=
" AND p.statut < ".((int) BonPrelevement::STATUS_CREDITED);
3057 $resql = $this->db->query($sql);
3059 $langs->load(
"banks");
3063 if ($mode ==
'direct-debit') {
3064 $response->warning_delay =
$conf->warning_delays[
'bank_direct_debit'] / 60 / 60 / 24;
3065 $response->label = $langs->trans(
"PendingDirectDebitToComplete");
3066 $response->labelShort = $langs->trans(
"PendingDirectDebitToCompleteShort");
3067 $response->url = DOL_URL_ROOT .
'/compta/prelevement/orders_list.php?leftmenu=checks&mainmenu=bank&search_status=0,1';
3068 $response->url_late = DOL_URL_ROOT .
'/compta/prelevement/orders_list.php?leftmenu=checks&mainmenu=bank&search_status=0,1';
3070 $response->warning_delay =
$conf->warning_delays[
'bank_credit_transfer'] / 60 / 60 / 24;
3071 $response->label = $langs->trans(
"PendingCreditTransferToComplete");
3072 $response->labelShort = $langs->trans(
"PendingCreditTransferToCompleteShort");
3073 $response->url = DOL_URL_ROOT .
'/compta/prelevement/orders_list.php?leftmenu=checks&mainmenu=bank&type=bank-transfer&search_status=0,1';
3074 $response->url_late = DOL_URL_ROOT .
'/compta/prelevement/orders_list.php?leftmenu=checks&mainmenu=bank&type=bank-transfer&search_status=0,1';
3078 $response->nbtodo = 0;
3079 $response->nbtodolate = 0;
3081 while ($obj = $this->db->fetch_object($resql)) {
3082 $response->nbtodo++;
3084 if ($this->db->jdate($obj->date_trans) < ($now - $response->warning_delay)) {
3085 $response->nbtodolate++;
3097 $this->error = $this->db->error();
3113 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3115 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3116 $return .=
'<div class="info-box info-box-sm">';
3117 $return .=
'<span class="info-box-icon bg-infobox-action">';
3119 $return .=
'</span>';
3120 $return .=
'<div class="info-box-content">';
3121 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . $this->
getNomUrl(1) .
'</span>';
3122 if ($selected >= 0) {
3123 $return .=
'<input id="cb' . $this->
id .
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="' . $this->
id .
'"' . ($selected ?
' checked="checked"' :
'') .
'>';
3136 if (isset($this->
amount)) {
3137 $return .=
'<br><span class="opacitymedium">' . $langs->trans(
"Amount") .
'</span> : <span class="amount">' .
price($this->
amount) .
'</span>';
3139 $return .=
'<br><div class="info-box-status">' . $this->
getLibStatut(3) .
'</div>';
3140 $return .=
'</div>';
3141 $return .=
'</div>';
3142 $return .=
'</div>';
3153 if (!empty($this->
id)) {
3158 $sql =
"SELECT COUNT(*) AS nb FROM " . MAIN_DB_PREFIX .
"prelevement_lignes";
3159 $sql .=
" WHERE fk_prelevement_bons = " . ((int) $id);
3160 $sql .=
" AND fk_soc = 0";
3161 $sql .=
" AND fk_user IS NOT NULL";
3164 $resql = $this->db->query($sql);
3166 $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.
addWithdrawDetail($invoice_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $type='debit-order', $sourcetype='', $bic='', $iban='', $rum='', $id_prelevement_demande=0)
Add invoice to withdrawal.
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
SommeAPrelever($mode='direct-debit', $type='')
Returns amount waiting for direct debit payment or credit transfer payment.
static buildRumNumber($row_code_client, $row_datec, $row_drum)
Generate dynamically a RUM number for a customer bank account.
EnregEmetteur($type='direct-debit')
Write sender of request (me).
checkIfSalaryBonPrelevement()
Check if is bon prelevement for salary invoice.
EnregTotal($total)
Write end.
NbFactureAPrelever($type='direct-debit', $forsalary=0)
Get number of invoices to pay.
fetch($rowid, $ref='')
Get object and lines from database.
addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype='', $bic='', $iban='', $rum='', $id_prelevement_demande=0)
Add line to withdrawal.
getListInvoices($amounts=0, $type='')
Get invoice or salary list (with amount or not)
deleteNotificationById($rowid)
Delete a notification def by id.
__construct($db)
Constructor.
EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $ref, $facid, $rib_dom='', $type='direct-debit')
Write recipient of request (customer)
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Returns clickable name (with picto)
LibStatut($status, $mode=0)
Return status label for a status.
update(User $user, $notrigger=0)
Update object into database.
set_infotrans($user, $date, $method)
Set withdrawal to transmitted status.
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.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount
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='', $patterntotest='')
Decode a string with a symmetric encryption.