30require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
48 public $element =
'widthdraw';
53 public $table_element =
'prelevement_bons';
58 public $picto =
'payment';
60 public $date_echeance;
61 public $raison_sociale;
62 public $reference_remise;
63 public $emetteur_code_guichet;
64 public $emetteur_numero_compte;
65 public $emetteur_code_banque;
66 public $emetteur_number_key;
67 public $sepa_xml_pti_in_ctti;
69 public $emetteur_iban;
78 public $labelStatus = array();
80 public $factures = array();
82 public $invoice_in_error = array();
83 public $thirdparty_in_error = array();
91 const STATUS_DRAFT = 0;
92 const STATUS_TRANSFERED = 1;
93 const STATUS_CREDITED = 2;
94 const STATUS_DEBITED = 2;
140 public $fields=array(
141 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>
'1',
'position'=>10,
'notnull'=>1,
'visible'=>0,),
142 'ref' => array(
'type'=>
'varchar(12)',
'label'=>
'Ref',
'enabled'=>
'1',
'position'=>15,
'notnull'=>0,
'visible'=>-1,
'csslist'=>
'tdoverflowmax150',
'showoncombobox'=>
'1',),
143 'datec' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>
'1',
'position'=>25,
'notnull'=>0,
'visible'=>-1,),
144 'amount' => array(
'type'=>
'double(24,8)',
'label'=>
'Amount',
'enabled'=>
'1',
'position'=>30,
'notnull'=>0,
'visible'=>-1,),
145 'statut' => array(
'type'=>
'smallint(6)',
'label'=>
'Statut',
'enabled'=>
'1',
'position'=>500,
'notnull'=>0,
'visible'=>-1,
'arrayofkeyval'=>array(0=>
'Wait', 1=>
'Transfered', 2=>
'Credited')),
146 'credite' => array(
'type'=>
'smallint(6)',
'label'=>
'Credite',
'enabled'=>
'1',
'position'=>40,
'notnull'=>0,
'visible'=>-1,),
147 'note' => array(
'type'=>
'text',
'label'=>
'Note',
'enabled'=>
'1',
'position'=>45,
'notnull'=>0,
'visible'=>-1,),
148 'date_trans' => array(
'type'=>
'datetime',
'label'=>
'Datetrans',
'enabled'=>
'1',
'position'=>50,
'notnull'=>0,
'visible'=>-1,),
149 'method_trans' => array(
'type'=>
'smallint(6)',
'label'=>
'Methodtrans',
'enabled'=>
'1',
'position'=>55,
'notnull'=>0,
'visible'=>-1,),
150 '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',),
151 'date_credit' => array(
'type'=>
'datetime',
'label'=>
'Datecredit',
'enabled'=>
'1',
'position'=>65,
'notnull'=>0,
'visible'=>-1,),
152 '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',),
153 'type' => array(
'type'=>
'varchar(16)',
'label'=>
'Type',
'enabled'=>
'1',
'position'=>75,
'notnull'=>0,
'visible'=>-1,),
154 'fk_bank_account' => array(
'type'=>
'integer',
'label'=>
'Fkbankaccount',
'enabled'=>
'1',
'position'=>80,
'notnull'=>0,
'visible'=>-1,
'css'=>
'maxwidth500 widthcentpercentminusxx',),
164 public $method_trans;
165 public $fk_user_trans;
167 public $fk_user_credit;
169 public $fk_bank_account;
181 global $conf, $langs;
185 $this->filename =
'';
187 $this->date_echeance =
dol_now();
188 $this->raison_sociale =
"";
189 $this->reference_remise =
"";
191 $this->emetteur_code_guichet =
"";
192 $this->emetteur_numero_compte =
"";
193 $this->emetteur_code_banque =
"";
194 $this->emetteur_number_key =
"";
195 $this->sepa_xml_pti_in_ctti =
false;
197 $this->emetteur_iban =
"";
198 $this->emetteur_bic =
"";
199 $this->emetteur_ics =
"";
201 $this->factures = array();
203 $this->methodes_trans = array(0 =>
'Internet', 2 =>
'Email', 3 =>
'Api');
223 public function AddFacture($invoice_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $type =
'debit-order')
230 $result = $this->
addline($line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key);
234 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"prelevement (";
235 if ($type !=
'bank-transfer') {
236 $sql .=
"fk_facture";
238 $sql .=
"fk_facture_fourn";
240 $sql .=
",fk_prelevement_lignes";
241 $sql .=
") VALUES (";
242 $sql .= ((int) $invoice_id);
243 $sql .=
", ".((int) $line_id);
246 if ($this->db->query($sql)) {
250 $this->errors[] = get_class($this).
"::AddFacture ".$this->db->lasterror;
251 dol_syslog(get_class($this).
"::AddFacture Error $result");
255 $this->errors[] = get_class($this).
"::AddFacture linedid Empty";
256 dol_syslog(get_class($this).
"::AddFacture Error $result");
260 dol_syslog(get_class($this).
"::AddFacture Error $result");
279 public function addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key)
288 $sql =
"SELECT rowid";
289 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_lignes";
290 $sql .=
" WHERE fk_prelevement_bons = ".((int) $this->
id);
291 $sql .=
" AND fk_soc =".((int) $client_id);
292 $sql .=
" AND code_banque = '".$this->db->escape($code_banque).
"'";
293 $sql .=
" AND code_guichet = '".$this->db->escape($code_guichet).
"'";
294 $sql .=
" AND number = '".$this->db->escape($number).
"'";
296 $resql = $this->db->query($sql);
298 $num = $this->db->num_rows($resql);
306 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"prelevement_lignes (";
307 $sql .=
"fk_prelevement_bons";
309 $sql .=
", client_nom";
311 $sql .=
", code_banque";
312 $sql .=
", code_guichet";
315 $sql .=
") VALUES (";
317 $sql .=
", ".((int) $client_id);
318 $sql .=
", '".$this->db->escape($client_nom).
"'";
319 $sql .=
", ".((float)
price2num($amount));
320 $sql .=
", '".$this->db->escape($code_banque).
"'";
321 $sql .=
", '".$this->db->escape($code_guichet).
"'";
322 $sql .=
", '".$this->db->escape($number).
"'";
323 $sql .=
", '".$this->db->escape($number_key).
"'";
326 if ($this->db->query($sql)) {
327 $line_id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"prelevement_lignes");
330 $this->errors[] = get_class($this).
"::addline Error -2 ".$this->db->lasterror;
331 dol_syslog(get_class($this).
"::addline Error -2");
351 $errors[1027] = $langs->trans(
"DateInvalid");
353 return $errors[abs($error)];
363 public function fetch($rowid, $ref =
'')
365 $sql =
"SELECT p.rowid, p.ref, p.amount, p.note";
366 $sql .=
", p.datec as dc";
367 $sql .=
", p.date_trans as date_trans";
368 $sql .=
", p.method_trans, p.fk_user_trans";
369 $sql .=
", p.date_credit as date_credit";
370 $sql .=
", p.fk_user_credit";
372 $sql .=
", p.fk_bank_account";
373 $sql .=
", p.statut as status";
374 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_bons as p";
375 $sql .=
" WHERE p.entity IN (".getEntity(
'invoice').
")";
377 $sql .=
" AND p.rowid = ".((int) $rowid);
379 $sql .=
" AND p.ref = '".$this->db->escape($ref).
"'";
382 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
383 $result = $this->db->query($sql);
385 if ($this->db->num_rows($result)) {
386 $obj = $this->db->fetch_object($result);
388 $this->
id = $obj->rowid;
389 $this->
ref = $obj->ref;
390 $this->amount = $obj->amount;
391 $this->note = $obj->note;
392 $this->datec = $this->db->jdate($obj->dc);
394 $this->date_trans = $this->db->jdate($obj->date_trans);
395 $this->method_trans = $obj->method_trans;
396 $this->user_trans = $obj->fk_user_trans;
398 $this->date_credit = $this->db->jdate($obj->date_credit);
399 $this->user_credit = $obj->fk_user_credit;
401 $this->
type = $obj->type;
402 $this->fk_bank_account = $obj->fk_bank_account;
404 $this->status = $obj->status;
405 $this->
statut = $obj->status;
411 dol_syslog(get_class($this).
"::Fetch Erreur aucune ligne retournee");
443 global $conf, $langs;
447 if ($this->fetched == 1) {
448 if ($date < $this->date_trans) {
449 $langs->load(
"errors");
450 $this->error = $langs->trans(
'ErrorDateOfMovementLowerThanDateOfFileTransmission');
451 dol_syslog(
"bon-prelevment::set_infocredit 1027 ".$this->error);
457 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"prelevement_bons";
458 $sql .=
" SET fk_user_credit = ".$user->id;
459 $sql .=
", statut = ".self::STATUS_CREDITED;
460 $sql .=
", date_credit = '".$this->db->idate($date).
"'";
461 $sql .=
" WHERE rowid=".((int) $this->
id);
462 $sql .=
" AND entity = ".((int) $conf->entity);
463 $sql .=
" AND statut = ".self::STATUS_TRANSFERED;
465 $resql = $this->db->query($sql);
467 $langs->load(
'withdrawals');
468 $subject = $langs->trans(
"InfoCreditSubject", $this->
ref);
469 $message = $langs->trans(
"InfoCreditMessage", $this->
ref,
dol_print_date($date,
'dayhour'));
472 $fk_bank_account = $this->fk_bank_account;
473 if (empty($fk_bank_account)) {
474 $fk_bank_account = ($this->
type ==
'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT);
479 $amountsperthirdparty = array();
485 for ($i = 0; $i < $num; $i++) {
486 if ($this->
type ==
'bank-transfer') {
492 $result = $fac->fetch($facs[$i][0]);
494 $amounts[$fac->id] = $facs[$i][1];
495 $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
497 $totalpaid = $fac->getSommePaiement();
498 $totalcreditnotes = $fac->getSumCreditNotesUsed();
499 $totaldeposits = $fac->getSumDepositsUsed();
500 $alreadypayed = $totalpaid + $totalcreditnotes + $totaldeposits;
503 if (
price2num($alreadypayed + $facs[$i][1],
'MT') == $fac->total_ttc) {
504 $result = $fac->setPaid($user);
506 $this->error = $fac->error;
507 $this->errors = $fac->errors;
514 foreach ($amountsperthirdparty as $thirdpartyid => $cursoramounts) {
515 if ($this->
type ==
'bank-transfer') {
518 $paiement =
new Paiement($this->db);
520 $paiement->datepaye = $date;
521 $paiement->amounts = $cursoramounts;
523 if ($this->
type ==
'bank-transfer') {
524 $paiement->paiementid = 2;
525 $paiement->paiementcode =
'VIR';
527 $paiement->paiementid = 3;
528 $paiement->paiementcode =
'PRE';
531 $paiement->num_payment = $this->ref;
532 $paiement->id_prelevement = $this->id;
534 $paiement_id = $paiement->create($user);
535 if ($paiement_id < 0) {
537 $this->error = $paiement->error;
538 $this->errors = $paiement->errors;
539 dol_syslog(get_class($this).
"::set_infocredit AddPayment Error ".$this->error);
541 if ($this->
type ==
'bank-transfer') {
542 $modeforaddpayment =
'payment_supplier';
543 $labelforaddpayment =
'(BankTransferPayment)';
545 $modeforaddpayment =
'payment';
546 $labelforaddpayment =
'(WithdrawalPayment)';
549 $result = $paiement->addPaymentToBank($user, $modeforaddpayment, $labelforaddpayment, $fk_bank_account,
'',
'');
552 $this->error = $paiement->error;
553 $this->errors = $paiement->errors;
554 dol_syslog(get_class($this).
"::set_infocredit AddPaymentToBank Error ".$this->error);
562 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"prelevement_lignes";
563 $sql .=
" SET statut = 2";
564 $sql .=
" WHERE fk_prelevement_bons = ".((int) $this->
id);
566 if (!$this->db->query($sql)) {
567 dol_syslog(get_class($this).
"::set_infocredit Update lines Error");
572 $this->error = $this->db->lasterror();
573 dol_syslog(get_class($this).
"::set_infocredit Update Bons Error");
581 $this->date_credit = $date;
582 $this->
statut = self::STATUS_CREDITED;
587 $this->db->rollback();
607 global $conf, $langs;
611 dol_syslog(get_class($this).
"::set_infotrans Start", LOG_INFO);
612 if ($this->db->begin()) {
613 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_bons ";
614 $sql .=
" SET fk_user_trans = ".$user->id;
615 $sql .=
" , date_trans = '".$this->db->idate($date).
"'";
616 $sql .=
" , method_trans = ".((int) $method);
617 $sql .=
" , statut = ".self::STATUS_TRANSFERED;
618 $sql .=
" WHERE rowid = ".((int) $this->
id);
619 $sql .=
" AND entity = ".((int) $conf->entity);
620 $sql .=
" AND statut = 0";
622 if ($this->db->query($sql)) {
623 $this->method_trans = $method;
624 $langs->load(
'withdrawals');
625 $subject = $langs->trans(
"InfoTransSubject", $this->
ref);
626 $message = $langs->trans(
"InfoTransMessage", $this->
ref,
dolGetFirstLastname($user->firstname, $user->lastname));
627 $message .= $langs->trans(
"InfoTransData",
price($this->amount), $this->methodes_trans[$this->method_trans],
dol_print_date($date,
'day'));
635 $this->date_trans = $date;
637 $this->user_trans = $user->id;
642 $this->db->rollback();
643 dol_syslog(get_class($this).
"::set_infotrans ROLLBACK", LOG_ERR);
648 dol_syslog(get_class($this).
"::set_infotrans Ouverture transaction SQL impossible", LOG_CRIT);
669 if ($this->
type ==
'bank-transfer') {
670 $sql .=
" pf.fk_facture_fourn";
672 $sql .=
" pf.fk_facture";
675 $sql .=
", SUM(pl.amount)";
677 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_bons as p";
678 $sql .=
" , ".MAIN_DB_PREFIX.
"prelevement_lignes as pl";
679 $sql .=
" , ".MAIN_DB_PREFIX.
"prelevement as pf";
680 $sql .=
" WHERE pf.fk_prelevement_lignes = pl.rowid";
681 $sql .=
" AND pl.fk_prelevement_bons = p.rowid";
682 $sql .=
" AND p.rowid = ".((int) $this->
id);
683 $sql .=
" AND p.entity = ".((int) $conf->entity);
685 if ($this->
type ==
'bank-transfer') {
686 $sql .=
" GROUP BY fk_facture_fourn";
688 $sql .=
" GROUP BY fk_facture";
692 $resql = $this->db->query($sql);
694 $num = $this->db->num_rows($resql);
699 $row = $this->db->fetch_row($resql);
711 $this->db->free($resql);
713 dol_syslog(get_class($this).
"::getListInvoices Erreur");
731 $sql =
"SELECT sum(pfd.amount) as nb";
732 if ($mode !=
'bank-transfer') {
733 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f,";
735 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f,";
737 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement_demande as pfd";
738 $sql .=
" WHERE f.entity IN (".getEntity(
'invoice').
")";
739 if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
740 $sql .=
" AND f.fk_statut = ".Facture::STATUS_VALIDATED;
742 if ($mode !=
'bank-transfer') {
743 $sql .=
" AND f.rowid = pfd.fk_facture";
745 $sql .=
" AND f.rowid = pfd.fk_facture_fourn";
747 $sql .=
" AND f.paye = 0";
748 $sql .=
" AND pfd.traite = 0";
749 $sql .=
" AND pfd.ext_payment_id IS NULL";
750 $sql .=
" AND f.total_ttc > 0";
752 $resql = $this->db->query($sql);
754 $obj = $this->db->fetch_object($resql);
756 $this->db->free($resql);
761 dol_syslog(get_class($this).
"::SommeAPrelever Erreur -1");
791 $sql =
"SELECT count(f.rowid) as nb";
792 if ($type ==
'bank-transfer') {
793 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
795 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
797 $sql .=
", ".MAIN_DB_PREFIX.
"prelevement_demande as pfd";
798 $sql .=
" WHERE f.entity IN (".getEntity(
'invoice').
")";
799 if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
800 $sql .=
" AND f.fk_statut = ".Facture::STATUS_VALIDATED;
802 if ($type ==
'bank-transfer') {
803 $sql .=
" AND f.rowid = pfd.fk_facture_fourn";
805 $sql .=
" AND f.rowid = pfd.fk_facture";
807 $sql .=
" AND pfd.traite = 0";
808 $sql .=
" AND pfd.ext_payment_id IS NULL";
809 $sql .=
" AND f.total_ttc > 0";
811 dol_syslog(get_class($this).
"::NbFactureAPrelever");
812 $resql = $this->db->query($sql);
815 $obj = $this->db->fetch_object($resql);
817 $this->db->free($resql);
821 $this->error = get_class($this).
"::NbFactureAPrelever Erreur -1 sql=".$this->db->error();
847 public function create($banque = 0, $agence = 0, $mode =
'real', $format =
'ALL', $executiondate =
'', $notrigger = 0, $type =
'direct-debit', $did = 0, $fk_bank_account = 0)
850 global $conf, $langs, $user;
852 dol_syslog(__METHOD__.
" Bank=".$banque.
" Office=".$agence.
" mode=".$mode.
" format=".$format, LOG_DEBUG);
854 require_once DOL_DOCUMENT_ROOT.
"/compta/facture/class/facture.class.php";
855 require_once DOL_DOCUMENT_ROOT.
"/societe/class/societe.class.php";
858 if ($type !=
'bank-transfer') {
859 if (empty($format)) {
860 $this->error =
'ErrorBadParametersForDirectDebitFileCreate';
866 if (empty($fk_bank_account)) {
867 $fk_bank_account = ($type ==
'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT);
872 $datetimeprev =
dol_now(
'gmt');
874 if (!empty($executiondate)) {
875 $datetimeprev = $executiondate;
881 $this->invoice_in_error = array();
882 $this->thirdparty_in_error = array();
886 $factures_prev = array();
887 $factures_result = array();
888 $factures_prev_id = array();
889 $factures_errors = array();
892 $sql =
"SELECT f.rowid, pfd.rowid as pfdrowid, f.fk_soc";
893 $sql .=
", pfd.code_banque, pfd.code_guichet, pfd.number, pfd.cle_rib";
894 $sql .=
", pfd.amount";
895 $sql .=
", s.nom as name";
896 if ($type !=
'bank-transfer') {
897 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
899 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
901 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
902 $sql .=
", ".MAIN_DB_PREFIX.
"prelevement_demande as pfd";
903 $sql .=
" WHERE f.entity IN (".getEntity(
'invoice').
')';
904 if ($type !=
'bank-transfer') {
905 $sql .=
" AND f.rowid = pfd.fk_facture";
907 $sql .=
" AND f.rowid = pfd.fk_facture_fourn";
909 $sql .=
" AND s.rowid = f.fk_soc";
910 $sql .=
" AND f.fk_statut = 1";
911 $sql .=
" AND f.paye = 0";
912 $sql .=
" AND pfd.traite = 0";
913 $sql .=
" AND f.total_ttc > 0";
914 $sql .=
" AND pfd.ext_payment_id IS NULL";
916 $sql .=
" AND pfd.rowid = ".((int) $did);
918 dol_syslog(__METHOD__.
" Read invoices,", LOG_DEBUG);
920 $resql = $this->db->query($sql);
922 $num = $this->db->num_rows($resql);
926 $row = $this->db->fetch_row($resql);
927 $factures[$i] = $row;
930 dol_syslog(__METHOD__.
" Read invoices error Found a null invoice", LOG_ERR);
931 $this->invoice_in_error[$row[0]] =
"Error for invoice id ".$row[0].
", found a null amount";
936 $this->db->free($resql);
937 dol_syslog(__METHOD__.
" Read invoices, ".$i.
" invoices to withdraw", LOG_DEBUG);
940 dol_syslog(__METHOD__.
" Read invoices error ".$this->db->error(), LOG_ERR);
945 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
950 dol_syslog(__METHOD__.
" Check BAN", LOG_DEBUG);
952 if (count($factures) > 0) {
953 foreach ($factures as $key => $fac) {
954 if ($type !=
'bank-transfer') {
955 $tmpinvoice =
new Facture($this->db);
959 $resfetch = $tmpinvoice->fetch($fac[0]);
960 if ($resfetch >= 0) {
961 if ($soc->fetch($tmpinvoice->socid) >= 0) {
963 $bac->fetch(0, $soc->id);
965 if ($type !=
'bank-transfer') {
966 if ($format ==
'FRST' && $bac->frstrecur !=
'FRST') {
969 if ($format ==
'RCUR' && ($bac->frstrecur !=
'RCUR' && $bac->frstrecur !=
'RECUR')) {
974 if ($bac->verif() >= 1) {
975 $factures_prev[$i] = $fac;
977 $factures_prev_id[$i] = $fac[0];
981 dol_syslog(__METHOD__.
" Check BAN Error on default bank number IBAN/BIC for thirdparty reported by verif() ".$tmpinvoice->socid.
" ".$soc->name, LOG_WARNING);
982 $this->invoice_in_error[$fac[0]] =
"Error on default bank number IBAN/BIC for invoice ".$tmpinvoice->getNomUrl(0).
" for thirdparty ".$soc->getNomUrl(0);
983 $this->thirdparty_in_error[$soc->id] =
"Error on default bank number IBAN/BIC for invoice ".$tmpinvoice->getNomUrl(0).
" for thirdparty ".$soc->getNomUrl(0);
986 dol_syslog(__METHOD__.
" Check BAN Failed to read company", LOG_WARNING);
989 dol_syslog(__METHOD__.
" Check BAN Failed to read invoice", LOG_WARNING);
993 dol_syslog(__METHOD__.
" Check BAN No invoice to process", LOG_WARNING);
1000 $out = count($factures_prev).
" invoices will be included.";
1013 if (count($factures_prev) > 0) {
1014 if ($mode ==
'real') {
1017 print $langs->trans(
"ModeWarning");
1035 $ref = substr($year, -2).$month;
1038 $sql =
"SELECT substring(ref from char_length(ref) - 1)";
1039 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_bons";
1040 $sql .=
" WHERE ref LIKE '_".$this->db->escape($ref).
"%'";
1041 $sql .=
" AND entity = ".((int) $conf->entity);
1042 $sql .=
" ORDER BY ref DESC LIMIT 1";
1044 dol_syslog(get_class($this).
" get next free number", LOG_DEBUG);
1045 $resql = $this->db->query($sql);
1048 $row = $this->db->fetch_row($resql);
1051 $ref =
"T".$ref.sprintf(
"%02d", (intval($row[0]) + 1));
1057 if ($type !=
'bank-transfer') {
1058 $dir = $conf->prelevement->dir_output.
'/receipts';
1060 $dir = $conf->paymentbybanktransfer->dir_output.
'/receipts';
1062 if (!is_dir($dir)) {
1066 if (isModEnabled(
'multicompany')) {
1067 $labelentity = $conf->entity;
1068 $this->filename = $dir.
'/'.$ref.
'-'.$labelentity.
'.xml';
1070 $this->filename = $dir.
'/'.$ref.
'.xml';
1074 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"prelevement_bons (";
1075 $sql .=
"ref, entity, datec, type, fk_bank_account";
1076 $sql .=
") VALUES (";
1077 $sql .=
"'".$this->db->escape($ref).
"'";
1078 $sql .=
", ".((int) $conf->entity);
1079 $sql .=
", '".$this->db->idate($now).
"'";
1080 $sql .=
", '".($type ==
'bank-transfer' ?
'bank-transfer' :
'debit-order').
"'";
1081 $sql .=
", ".((int) $fk_bank_account);
1084 $resql = $this->db->query($sql);
1086 $prev_id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"prelevement_bons");
1087 $this->
id = $prev_id;
1091 dol_syslog(__METHOD__.
" Create withdraw receipt ".$this->db->lasterror(), LOG_ERR);
1095 dol_syslog(__METHOD__.
" Get last withdraw receipt ".$this->db->lasterror(), LOG_ERR);
1100 if ($type !=
'bank-transfer') {
1101 $fact =
new Facture($this->db);
1107 if (count($factures_prev) > 0) {
1108 foreach ($factures_prev as $fac) {
1110 $result = $fact->fetch($fac[0]);
1112 $this->error =
'ERRORBONPRELEVEMENT Failed to load invoice with id '.$fac[0];
1129 $ri = $this->
AddFacture($fac[0], $fac[2], $fac[8], $fac[7], $fac[3], $fac[4], $fac[5], $fac[6], $type);
1135 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_demande";
1136 $sql .=
" SET traite = 1";
1137 $sql .=
", date_traite = '".$this->db->idate($now).
"'";
1138 $sql .=
", fk_prelevement_bons = ".((int) $this->
id);
1139 $sql .=
" WHERE rowid = ".((int) $fac[1]);
1141 $resql = $this->db->query($sql);
1144 $this->errors[] = $this->db->lasterror();
1145 dol_syslog(__METHOD__.
" Update Error=".$this->db->lasterror(), LOG_ERR);
1156 dol_syslog(__METHOD__.
" Init direct debit or credit transfer file for ".count($factures_prev).
" invoices", LOG_DEBUG);
1158 if (count($factures_prev) > 0) {
1159 $this->date_echeance = $datetimeprev;
1160 $this->reference_remise = $ref;
1162 $account =
new Account($this->db);
1163 if ($account->fetch($fk_bank_account) > 0) {
1164 $this->emetteur_code_banque = $account->code_banque;
1165 $this->emetteur_code_guichet = $account->code_guichet;
1166 $this->emetteur_numero_compte = $account->number;
1167 $this->emetteur_number_key = $account->cle_rib;
1168 $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
1169 $this->emetteur_iban = $account->iban;
1170 $this->emetteur_bic = $account->bic;
1172 $this->emetteur_ics = ($type ==
'bank-transfer' ? $account->ics_transfer : $account->ics);
1174 $this->raison_sociale = $account->proprio;
1177 $this->factures = $factures_prev_id;
1178 $this->context[
'factures_prev'] = $factures_prev;
1182 $result = $this->
generate($format, $executiondate, $type);
1189 dol_syslog(__METHOD__.
" Bank order file has been generated under filename ".$this->filename, LOG_DEBUG);
1197 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_bons";
1198 $sql .=
" SET amount = ".price2num($this->total);
1199 $sql .=
" WHERE rowid = ".((int) $this->
id);
1200 $sql .=
" AND entity = ".((int) $conf->entity);
1202 $resql = $this->db->query($sql);
1205 dol_syslog(__METHOD__.
" Error update total: ".$this->db->error(), LOG_ERR);
1209 if (!$error && !$notrigger) {
1210 $triggername =
'DIRECT_DEBIT_ORDER_CREATE';
1211 if ($type !=
'bank-transfer') {
1212 $triggername =
'CREDIT_TRANSFER_ORDER_CREATE';
1224 $this->db->commit();
1225 return count($factures_prev);
1227 $this->db->rollback();
1243 public function delete($user =
null, $notrigger = 0)
1248 $resql1 = $resql2 = $resql3 = $resql4 = 0;
1251 $triggername =
'DIRECT_DEBIT_ORDER_DELETE';
1252 if ($this->
type ==
'bank-transfer') {
1253 $triggername =
'PAYMENTBYBANKTRANFER_DELETE';
1264 $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).
")";
1265 $resql1 = $this->db->query($sql);
1272 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"prelevement_lignes WHERE fk_prelevement_bons = ".((int) $this->
id);
1273 $resql2 = $this->db->query($sql);
1280 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"prelevement_bons WHERE rowid = ".((int) $this->
id);
1281 $resql3 = $this->db->query($sql);
1288 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_demande SET fk_prelevement_bons = NULL, traite = 0 WHERE fk_prelevement_bons = ".((int) $this->
id);
1289 $resql4 = $this->db->query($sql);
1295 if ($resql1 && $resql2 && $resql3 && $resql4 && !$error) {
1296 $this->db->commit();
1299 $this->db->rollback();
1315 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1317 global $conf, $langs, $hookmanager;
1319 if (!empty($conf->dol_no_mouse_hover)) {
1325 $labeltoshow =
'PaymentByDirectDebit';
1326 if (!empty($this->
type) && $this->
type ==
'bank-transfer') {
1327 $labeltoshow =
'PaymentByBankTransfer';
1330 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans($labeltoshow).
'</u> '.$this->
getLibStatut(5);
1332 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1333 if (isset($this->amount)) {
1334 $label .=
'<br><b>'.$langs->trans(
"Amount").
":</b> ".
price($this->amount);
1336 if (isset($this->date_trans)) {
1337 $label .=
'<br><b>'.$langs->trans(
"TransData").
":</b> ".
dol_print_date($this->date_trans,
'dayhour',
'tzuserrel');
1343 $url = DOL_URL_ROOT.
'/compta/prelevement/card.php?id='.$this->id;
1344 if (!empty($this->
type) && $this->
type ==
'bank-transfer') {
1345 $url = DOL_URL_ROOT.
'/compta/prelevement/card.php?id='.$this->id;
1348 if ($option !=
'nolink') {
1350 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1351 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1352 $add_save_lastsearch_values = 1;
1354 if ($add_save_lastsearch_values) {
1355 $url .=
'&save_lastsearch_values=1';
1360 if (empty($notooltip)) {
1361 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1362 $label = $langs->trans(
"ShowMyObject");
1363 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1365 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1366 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1368 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1371 $linkstart =
'<a href="'.$url.
'"';
1372 $linkstart .= $linkclose.
'>';
1375 $result .= $linkstart;
1377 $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);
1379 if ($withpicto != 2) {
1380 $result .= $this->ref;
1382 $result .= $linkend;
1384 global $action, $hookmanager;
1385 $hookmanager->initHooks(array(
'banktransferdao'));
1386 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1387 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1389 $result = $hookmanager->resPrint;
1391 $result .= $hookmanager->resPrint;
1406 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"notify_def";
1407 $sql .=
" WHERE rowid = ".((int) $rowid);
1409 if ($this->db->query($sql)) {
1425 if (is_object($user)) {
1426 $userid = $user->id;
1431 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"notify_def";
1432 $sql .=
" WHERE fk_user=".((int) $userid).
" AND fk_action='".$this->db->escape($action).
"'";
1434 if ($this->db->query($sql)) {
1455 if (is_object($user)) {
1456 $userid = $user->id;
1464 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"notify_def (datec,fk_user, fk_soc, fk_contact, fk_action)";
1465 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".((int) $userid).
", 'NULL', 'NULL', '".$this->db->escape($action).
"')";
1468 if ($this->db->query($sql)) {
1472 dol_syslog(get_class($this).
"::addNotification Error $result");
1493 public function generate($format =
'ALL', $executiondate = 0, $type =
'direct-debit', $fk_bank_account = 0)
1495 global $conf, $langs, $mysoc;
1500 if (empty($fk_bank_account)) {
1501 $fk_bank_account = ($type ==
'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT);
1506 dol_syslog(get_class($this).
"::generate build file=".$this->filename.
" type=".$type);
1508 $this->file = fopen($this->filename,
"w");
1509 if (empty($this->file)) {
1510 $this->error = $langs->trans(
'ErrorFailedToOpenFile', $this->filename);
1518 if ($mysoc->isInEEC()) {
1521 if ($type !=
'bank-transfer') {
1533 if (!empty($executiondate)) {
1534 $date_actu = $executiondate;
1539 $fileDebiteurSection =
'';
1540 $fileEmetteurSection =
'';
1547 $sql =
"SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
1548 $sql .=
" pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
1549 $sql .=
" f.ref as reffac, pf.fk_facture as idfac,";
1550 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
1552 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement_lignes as pl,";
1553 $sql .=
" ".MAIN_DB_PREFIX.
"facture as f,";
1554 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement as pf,";
1555 $sql .=
" ".MAIN_DB_PREFIX.
"societe as soc,";
1556 $sql .=
" ".MAIN_DB_PREFIX.
"c_country as c,";
1557 $sql .=
" ".MAIN_DB_PREFIX.
"societe_rib as rib";
1558 $sql .=
" WHERE pl.fk_prelevement_bons = ".((int) $this->
id);
1559 $sql .=
" AND pl.rowid = pf.fk_prelevement_lignes";
1560 $sql .=
" AND pf.fk_facture = f.rowid";
1561 $sql .=
" AND f.fk_soc = soc.rowid";
1562 $sql .=
" AND soc.fk_pays = c.rowid";
1563 $sql .=
" AND rib.fk_soc = f.fk_soc";
1564 $sql .=
" AND rib.default_rib = 1";
1565 $sql .=
" AND rib.type = 'ban'";
1568 $resql = $this->db->query($sql);
1570 $cachearraytotestduplicate = array();
1572 $num = $this->db->num_rows($resql);
1574 $obj = $this->db->fetch_object($resql);
1576 if (!empty($cachearraytotestduplicate[$obj->idfac])) {
1577 $this->error = $langs->trans(
'ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
1578 $this->invoice_in_error[$obj->idfac] = $this->error;
1582 $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
1584 $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
1586 $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);
1588 $this->total = $this->total + $obj->somme;
1591 $nbtotalDrctDbtTxInf = $i;
1593 $this->error = $this->db->lasterror();
1594 fputs($this->file,
'ERROR DEBITOR '.$sql.$CrLf);
1599 if ($result != -2) {
1600 $fileEmetteurSection .= $this->
EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type, $fk_bank_account);
1607 fputs($this->file,
'<'.
'?xml version="1.0" encoding="UTF-8" standalone="yes"?'.
'>'.$CrLf);
1608 fputs($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);
1609 fputs($this->file,
' <CstmrDrctDbtInitn>'.$CrLf);
1611 fputs($this->file,
' <GrpHdr>'.$CrLf);
1612 fputs($this->file,
' <MsgId>'.(
'DD/'.$dateTime_YMD.
'/REF'.$this->id).
'</MsgId>'.$CrLf);
1613 fputs($this->file,
' <CreDtTm>'.$dateTime_ECMA.
'</CreDtTm>'.$CrLf);
1614 fputs($this->file,
' <NbOfTxs>'.$i.
'</NbOfTxs>'.$CrLf);
1615 fputs($this->file,
' <CtrlSum>'.$this->total.
'</CtrlSum>'.$CrLf);
1616 fputs($this->file,
' <InitgPty>'.$CrLf);
1618 fputs($this->file,
' <Id>'.$CrLf);
1619 fputs($this->file,
' <PrvtId>'.$CrLf);
1620 fputs($this->file,
' <Othr>'.$CrLf);
1621 fputs($this->file,
' <Id>'.$this->emetteur_ics.
'</Id>'.$CrLf);
1622 fputs($this->file,
' </Othr>'.$CrLf);
1623 fputs($this->file,
' </PrvtId>'.$CrLf);
1624 fputs($this->file,
' </Id>'.$CrLf);
1625 fputs($this->file,
' </InitgPty>'.$CrLf);
1626 fputs($this->file,
' </GrpHdr>'.$CrLf);
1628 if ($result != -2) {
1629 fputs($this-> file, $fileEmetteurSection);
1632 if ($result != -2) {
1633 fputs($this-> file, $fileDebiteurSection);
1636 fputs($this->file,
' </PmtInf>'.$CrLf);
1637 fputs($this->file,
' </CstmrDrctDbtInitn>'.$CrLf);
1638 fputs($this->file,
'</Document>'.$CrLf);
1651 if (!empty($executiondate)) {
1652 $date_actu = $executiondate;
1657 $fileCrediteurSection =
'';
1658 $fileEmetteurSection =
'';
1665 $sql =
"SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
1666 $sql .=
" pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
1667 $sql .=
" f.ref as reffac, pf.fk_facture_fourn as idfac, f.ref_supplier as fac_ref_supplier,";
1668 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
1670 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement_lignes as pl,";
1671 $sql .=
" ".MAIN_DB_PREFIX.
"facture_fourn as f,";
1672 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement as pf,";
1673 $sql .=
" ".MAIN_DB_PREFIX.
"societe as soc,";
1674 $sql .=
" ".MAIN_DB_PREFIX.
"c_country as c,";
1675 $sql .=
" ".MAIN_DB_PREFIX.
"societe_rib as rib";
1676 $sql .=
" WHERE pl.fk_prelevement_bons = ".((int) $this->
id);
1677 $sql .=
" AND pl.rowid = pf.fk_prelevement_lignes";
1678 $sql .=
" AND pf.fk_facture_fourn = f.rowid";
1679 $sql .=
" AND f.fk_soc = soc.rowid";
1680 $sql .=
" AND soc.fk_pays = c.rowid";
1681 $sql .=
" AND rib.fk_soc = f.fk_soc";
1682 $sql .=
" AND rib.default_rib = 1";
1683 $sql .=
" AND rib.type = 'ban'";
1686 $resql = $this->db->query($sql);
1688 $cachearraytotestduplicate = array();
1690 $num = $this->db->num_rows($resql);
1692 $obj = $this->db->fetch_object($resql);
1694 if (!empty($cachearraytotestduplicate[$obj->idfac])) {
1695 $this->error = $langs->trans(
'ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
1696 $this->invoice_in_error[$obj->idfac] = $this->error;
1700 $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
1702 $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
1704 $fileCrediteurSection .= $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, $obj->fac_ref_supplier);
1706 $this->total = $this->total + $obj->somme;
1709 $nbtotalDrctDbtTxInf = $i;
1711 $this->error = $this->db->lasterror();
1712 fputs($this->file,
'ERROR CREDITOR '.$sql.$CrLf);
1717 if ($result != -2) {
1718 $fileEmetteurSection .= $this->
EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type);
1725 fputs($this->file,
'<'.
'?xml version="1.0" encoding="UTF-8" standalone="yes"?'.
'>'.$CrLf);
1726 fputs($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);
1727 fputs($this->file,
' <CstmrCdtTrfInitn>'.$CrLf);
1729 fputs($this->file,
' <GrpHdr>'.$CrLf);
1730 fputs($this->file,
' <MsgId>'.(
'TRF/'.$dateTime_YMD.
'/REF'.$this->id).
'</MsgId>'.$CrLf);
1731 fputs($this->file,
' <CreDtTm>'.$dateTime_ECMA.
'</CreDtTm>'.$CrLf);
1732 fputs($this->file,
' <NbOfTxs>'.$i.
'</NbOfTxs>'.$CrLf);
1733 fputs($this->file,
' <CtrlSum>'.$this->total.
'</CtrlSum>'.$CrLf);
1734 fputs($this->file,
' <InitgPty>'.$CrLf);
1736 fputs($this->file,
' <Id>'.$CrLf);
1737 fputs($this->file,
' <PrvtId>'.$CrLf);
1738 fputs($this->file,
' <Othr>'.$CrLf);
1739 fputs($this->file,
' <Id>'.$this->emetteur_ics.
'</Id>'.$CrLf);
1740 fputs($this->file,
' </Othr>'.$CrLf);
1741 fputs($this->file,
' </PrvtId>'.$CrLf);
1742 fputs($this->file,
' </Id>'.$CrLf);
1743 fputs($this->file,
' </InitgPty>'.$CrLf);
1744 fputs($this->file,
' </GrpHdr>'.$CrLf);
1746 if ($result != -2) {
1747 fputs($this-> file, $fileEmetteurSection);
1750 if ($result != -2) {
1751 fputs($this-> file, $fileCrediteurSection);
1754 fputs($this->file,
' </PmtInf>'.$CrLf);
1755 fputs($this->file,
' </CstmrCdtTrfInitn>'.$CrLf);
1756 fputs($this->file,
'</Document>'.$CrLf);
1762 if ($type !=
'bank-transfer') {
1763 $sql =
"SELECT pl.amount";
1765 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement_lignes as pl,";
1766 $sql .=
" ".MAIN_DB_PREFIX.
"facture as f,";
1767 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement as pf";
1768 $sql .=
" WHERE pl.fk_prelevement_bons = ".((int) $this->
id);
1769 $sql .=
" AND pl.rowid = pf.fk_prelevement_lignes";
1770 $sql .=
" AND pf.fk_facture = f.rowid";
1774 $resql = $this->db->query($sql);
1776 $num = $this->db->num_rows($resql);
1779 $obj = $this->db->fetch_object($resql);
1780 $this->total = $this->total + $obj->amount;
1789 $sql =
"SELECT pl.amount";
1791 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement_lignes as pl,";
1792 $sql .=
" ".MAIN_DB_PREFIX.
"facture_fourn as f,";
1793 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement as pf";
1794 $sql .=
" WHERE pl.fk_prelevement_bons = ".((int) $this->
id);
1795 $sql .=
" AND pl.rowid = pf.fk_prelevement_lignes";
1796 $sql .=
" AND pf.fk_facture_fourn = f.rowid";
1800 $resql = $this->db->query($sql);
1802 $num = $this->db->num_rows($resql);
1805 $obj = $this->db->fetch_object($resql);
1806 $this->total = $this->total + $obj->amount;
1816 $langs->load(
'withdrawals');
1819 fputs($this->file, $langs->transnoentitiesnoconv(
'WithdrawalFileNotCapable', $mysoc->country_code));
1822 fclose($this->file);
1844 return $pre.
'-'.
dol_print_date($row_datec,
'dayhourlogsmall').
'-'.
dol_trunc($row_drum.($row_code_client ?
'-'.$row_code_client :
''), 13,
'right',
'UTF-8', 1);
1865 public function EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $ref, $facid, $rib_dom =
'', $type =
'direct-debit')
1868 fputs($this->file,
"06");
1869 fputs($this->file,
"08");
1871 fputs($this->file,
" ");
1873 fputs($this->file, $this->emetteur_ics);
1877 fputs($this->file,
" ");
1878 fputs($this->file,
dol_print_date($this->date_echeance,
"%d%m",
'gmt'));
1879 fputs($this->file, substr(
dol_print_date($this->date_echeance,
"%y",
'gmt'), 1));
1883 fputs($this->file, substr(strtoupper($client_nom).
" ", 0, 24));
1886 $domiciliation = strtr($rib_dom, array(
" " =>
"-", CHR(13) =>
" ", CHR(10) =>
""));
1887 fputs($this->file, substr($domiciliation.
" ", 0, 24));
1891 fputs($this->file, substr(
" ", 0, 8));
1895 fputs($this->file, $rib_guichet);
1899 fputs($this->file, substr(
"000000000000000".$rib_number, -11));
1903 $montant = (round($amount, 2) * 100);
1905 fputs($this->file, substr(
"000000000000000".$montant, -16));
1909 fputs($this->file, substr(
"*_".$ref.
"_RDVnet".$rowid.
" ", 0, 31));
1913 fputs($this->file, $rib_banque);
1917 fputs($this->file, substr(
" ", 0, 5));
1919 fputs($this->file,
"\n");
1948 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 =
'')
1953 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1956 $Rowing = sprintf(
"%010d", $row_idfac);
1960 $Rum = (empty($row_rum) ? $this->
buildRumNumber($row_code_client, $row_datec, $row_drum) : $row_rum);
1965 if ($type !=
'bank-transfer') {
1968 $XML_DEBITOR .=
' <DrctDbtTxInf>'.$CrLf;
1969 $XML_DEBITOR .=
' <PmtId>'.$CrLf;
1971 $XML_DEBITOR .=
' <EndToEndId>'.(($conf->global->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;
1972 $XML_DEBITOR .=
' </PmtId>'.$CrLf;
1973 $XML_DEBITOR .=
' <InstdAmt Ccy="EUR">'.round($row_somme, 2).
'</InstdAmt>'.$CrLf;
1974 $XML_DEBITOR .=
' <DrctDbtTx>'.$CrLf;
1975 $XML_DEBITOR .=
' <MndtRltdInf>'.$CrLf;
1976 $XML_DEBITOR .=
' <MndtId>'.$Rum.
'</MndtId>'.$CrLf;
1977 $XML_DEBITOR .=
' <DtOfSgntr>'.$DtOfSgntr.
'</DtOfSgntr>'.$CrLf;
1978 $XML_DEBITOR .=
' <AmdmntInd>false</AmdmntInd>'.$CrLf;
1979 $XML_DEBITOR .=
' </MndtRltdInf>'.$CrLf;
1980 $XML_DEBITOR .=
' </DrctDbtTx>'.$CrLf;
1981 $XML_DEBITOR .=
' <DbtrAgt>'.$CrLf;
1982 $XML_DEBITOR .=
' <FinInstnId>'.$CrLf;
1983 $XML_DEBITOR .=
' <BIC>'.$row_bic.
'</BIC>'.$CrLf;
1984 $XML_DEBITOR .=
' </FinInstnId>'.$CrLf;
1985 $XML_DEBITOR .=
' </DbtrAgt>'.$CrLf;
1986 $XML_DEBITOR .=
' <Dbtr>'.$CrLf;
1988 $XML_DEBITOR .=
' <PstlAdr>'.$CrLf;
1989 $XML_DEBITOR .=
' <Ctry>'.$row_country_code.
'</Ctry>'.$CrLf;
1990 $addressline1 = strtr($row_address, array(CHR(13) =>
", ", CHR(10) =>
""));
1991 $addressline2 = strtr($row_zip.(($row_zip && $row_town) ?
' ' : (string) $row_town), array(CHR(13) =>
", ", CHR(10) =>
""));
1992 if (trim($addressline1)) {
1995 if (trim($addressline2)) {
1998 $XML_DEBITOR .=
' </PstlAdr>'.$CrLf;
1999 $XML_DEBITOR .=
' </Dbtr>'.$CrLf;
2000 $XML_DEBITOR .=
' <DbtrAcct>'.$CrLf;
2001 $XML_DEBITOR .=
' <Id>'.$CrLf;
2002 $XML_DEBITOR .=
' <IBAN>'.preg_replace(
'/\s/',
'', $row_iban).
'</IBAN>'.$CrLf;
2003 $XML_DEBITOR .=
' </Id>'.$CrLf;
2004 $XML_DEBITOR .=
' </DbtrAcct>'.$CrLf;
2005 $XML_DEBITOR .=
' <RmtInf>'.$CrLf;
2007 $XML_DEBITOR .=
' <Ustrd>'.getDolGlobalString(
'PRELEVEMENT_USTRD', dolEscapeXML(
dol_trunc(
dol_string_nospecial(
dol_string_unaccent($row_ref.($row_comment ?
' - '.$row_comment :
'')),
'',
'',
'', 1), 135,
'right',
'UTF-8', 1))).
'</Ustrd>'.$CrLf;
2008 $XML_DEBITOR .=
' </RmtInf>'.$CrLf;
2009 $XML_DEBITOR .=
' </DrctDbtTxInf>'.$CrLf;
2010 return $XML_DEBITOR;
2014 $XML_CREDITOR .=
' <CdtTrfTxInf>'.$CrLf;
2015 $XML_CREDITOR .=
' <PmtId>'.$CrLf;
2017 $XML_CREDITOR .=
' <EndToEndId>'.(($conf->global->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;
2018 $XML_CREDITOR .=
' </PmtId>'.$CrLf;
2019 if (!empty($this->sepa_xml_pti_in_ctti)) {
2020 $XML_CREDITOR .=
' <PmtTpInf>' . $CrLf;
2023 if (!empty($conf->global->PAYMENTBYBANKTRANSFER_FORCE_HIGH_PRIORITY)) {
2024 $instrprty =
'HIGH';
2026 $instrprty =
'NORM';
2028 $XML_CREDITOR .=
' <InstrPrty>'.$instrprty.
'</InstrPrty>' . $CrLf;
2029 $XML_CREDITOR .=
' <SvcLvl>' . $CrLf;
2030 $XML_CREDITOR .=
' <Cd>SEPA</Cd>' . $CrLf;
2031 $XML_CREDITOR .=
' </SvcLvl>' . $CrLf;
2032 $XML_CREDITOR .=
' <CtgyPurp>' . $CrLf;
2033 $XML_CREDITOR .=
' <Cd>CORE</Cd>' . $CrLf;
2034 $XML_CREDITOR .=
' </CtgyPurp>' . $CrLf;
2035 $XML_CREDITOR .=
' </PmtTpInf>' . $CrLf;
2037 $XML_CREDITOR .=
' <Amt>'.$CrLf;
2038 $XML_CREDITOR .=
' <InstdAmt Ccy="EUR">'.round($row_somme, 2).
'</InstdAmt>'.$CrLf;
2039 $XML_CREDITOR .=
' </Amt>'.$CrLf;
2050 $XML_CREDITOR .=
' <CdtrAgt>'.$CrLf;
2051 $XML_CREDITOR .=
' <FinInstnId>'.$CrLf;
2052 $XML_CREDITOR .=
' <BIC>'.$row_bic.
'</BIC>'.$CrLf;
2053 $XML_CREDITOR .=
' </FinInstnId>'.$CrLf;
2054 $XML_CREDITOR .=
' </CdtrAgt>'.$CrLf;
2055 $XML_CREDITOR .=
' <Cdtr>'.$CrLf;
2057 $XML_CREDITOR .=
' <PstlAdr>'.$CrLf;
2058 $XML_CREDITOR .=
' <Ctry>'.$row_country_code.
'</Ctry>'.$CrLf;
2059 $addressline1 = strtr($row_address, array(CHR(13) =>
", ", CHR(10) =>
""));
2060 $addressline2 = strtr($row_zip.(($row_zip && $row_town) ?
' ' : (string) $row_town), array(CHR(13) =>
", ", CHR(10) =>
""));
2061 if (trim($addressline1)) {
2064 if (trim($addressline2)) {
2067 $XML_CREDITOR .=
' </PstlAdr>'.$CrLf;
2068 $XML_CREDITOR .=
' </Cdtr>'.$CrLf;
2069 $XML_CREDITOR .=
' <CdtrAcct>'.$CrLf;
2070 $XML_CREDITOR .=
' <Id>'.$CrLf;
2071 $XML_CREDITOR .=
' <IBAN>'.preg_replace(
'/\s/',
'', $row_iban).
'</IBAN>'.$CrLf;
2072 $XML_CREDITOR .=
' </Id>'.$CrLf;
2073 $XML_CREDITOR .=
' </CdtrAcct>'.$CrLf;
2074 $XML_CREDITOR .=
' <RmtInf>'.$CrLf;
2076 $XML_CREDITOR .=
' <Ustrd>'.getDolGlobalString(
'CREDITTRANSFER_USTRD', dolEscapeXML(
dol_trunc(
dol_string_nospecial(
dol_string_unaccent($row_ref.($row_comment ?
' - '.$row_comment :
'')),
'',
'',
'', 1), 135,
'right',
'UTF-8', 1))).
'</Ustrd>'.$CrLf;
2077 $XML_CREDITOR .=
' </RmtInf>'.$CrLf;
2078 $XML_CREDITOR .=
' </CdtTrfTxInf>'.$CrLf;
2079 return $XML_CREDITOR;
2095 fputs($this->file,
"03");
2096 fputs($this->file,
"08");
2098 fputs($this->file,
" ");
2100 fputs($this->file, $this->emetteur_ics);
2104 fputs($this->file,
" ");
2105 fputs($this->file,
dol_print_date($this->date_echeance,
"%d%m",
'gmt'));
2106 fputs($this->file, substr(
dol_print_date($this->date_echeance,
"%y",
'gmt'), 1));
2110 fputs($this->file, substr($this->raison_sociale.
" ", 0, 24));
2114 fputs($this->file, substr($this->reference_remise.
" ", 0, 7));
2118 fputs($this->file, substr(
" ", 0, 17));
2122 fputs($this->file, substr(
" ", 0, 2));
2123 fputs($this->file,
"E");
2124 fputs($this->file, substr(
" ", 0, 5));
2128 fputs($this->file, $this->emetteur_code_guichet);
2132 fputs($this->file, substr(
"000000000000000".$this->emetteur_numero_compte, -11));
2136 fputs($this->file, substr(
" ", 0, 16));
2140 fputs($this->file, substr(
" ", 0, 31));
2144 fputs($this->file, $this->emetteur_code_banque);
2148 fputs($this->file, substr(
" ", 0, 5));
2150 fputs($this->file,
"\n");
2169 public function EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf =
'\n', $format =
'FRST', $type =
'direct-debit', $fk_bank_account = 0)
2181 if (empty($fk_bank_account)) {
2182 $fk_bank_account = ($type ==
'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT);
2186 $account =
new Account($this->db);
2187 if ($account->fetch($fk_bank_account) > 0) {
2188 $this->emetteur_code_banque = $account->code_banque;
2189 $this->emetteur_code_guichet = $account->code_guichet;
2190 $this->emetteur_numero_compte = $account->number;
2191 $this->emetteur_number_key = $account->cle_rib;
2192 $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
2193 $this->emetteur_iban = $account->iban;
2194 $this->emetteur_bic = $account->bic;
2196 $this->emetteur_ics = ($type ==
'bank-transfer' ? $account->ics_transfer : $account->ics);
2198 $this->raison_sociale = $account->proprio;
2202 $sql =
"SELECT rowid, ref";
2203 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_bons as pb";
2204 $sql .=
" WHERE pb.rowid = ".((int) $this->
id);
2206 $resql = $this->db->query($sql);
2208 $obj = $this->db->fetch_object($resql);
2210 $country = explode(
':', $configuration->global->MAIN_INFO_SOCIETE_COUNTRY);
2211 $IdBon = sprintf(
"%05d", $obj->rowid);
2212 $RefBon = $obj->ref;
2214 if ($type !=
'bank-transfer') {
2216 $XML_SEPA_INFO =
'';
2217 $XML_SEPA_INFO .=
' <PmtInf>'.$CrLf;
2218 $XML_SEPA_INFO .=
' <PmtInfId>'.(
'DD/'.$dateTime_YMD.
'/ID'.$IdBon.
'-'.$RefBon).
'</PmtInfId>'.$CrLf;
2219 $XML_SEPA_INFO .=
' <PmtMtd>DD</PmtMtd>'.$CrLf;
2220 $XML_SEPA_INFO .=
' <NbOfTxs>'.$nombre.
'</NbOfTxs>'.$CrLf;
2221 $XML_SEPA_INFO .=
' <CtrlSum>'.$total.
'</CtrlSum>'.$CrLf;
2222 $XML_SEPA_INFO .=
' <PmtTpInf>'.$CrLf;
2223 $XML_SEPA_INFO .=
' <SvcLvl>'.$CrLf;
2224 $XML_SEPA_INFO .=
' <Cd>SEPA</Cd>'.$CrLf;
2225 $XML_SEPA_INFO .=
' </SvcLvl>'.$CrLf;
2226 $XML_SEPA_INFO .=
' <LclInstrm>'.$CrLf;
2227 $XML_SEPA_INFO .=
' <Cd>CORE</Cd>'.$CrLf;
2228 $XML_SEPA_INFO .=
' </LclInstrm>'.$CrLf;
2229 $XML_SEPA_INFO .=
' <SeqTp>'.$format.
'</SeqTp>'.$CrLf;
2230 $XML_SEPA_INFO .=
' </PmtTpInf>'.$CrLf;
2231 $XML_SEPA_INFO .=
' <ReqdColltnDt>'.$dateTime_ETAD.
'</ReqdColltnDt>'.$CrLf;
2232 $XML_SEPA_INFO .=
' <Cdtr>'.$CrLf;
2234 $XML_SEPA_INFO .=
' <PstlAdr>'.$CrLf;
2235 $XML_SEPA_INFO .=
' <Ctry>'.$country[1].
'</Ctry>'.$CrLf;
2236 $addressline1 = strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(CHR(13) =>
", ", CHR(10) =>
""));
2237 $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) =>
""));
2238 if ($addressline1) {
2241 if ($addressline2) {
2244 $XML_SEPA_INFO .=
' </PstlAdr>'.$CrLf;
2245 $XML_SEPA_INFO .=
' </Cdtr>'.$CrLf;
2246 $XML_SEPA_INFO .=
' <CdtrAcct>'.$CrLf;
2247 $XML_SEPA_INFO .=
' <Id>'.$CrLf;
2248 $XML_SEPA_INFO .=
' <IBAN>'.preg_replace(
'/\s/',
'', $this->emetteur_iban).
'</IBAN>'.$CrLf;
2249 $XML_SEPA_INFO .=
' </Id>'.$CrLf;
2250 $XML_SEPA_INFO .=
' </CdtrAcct>'.$CrLf;
2251 $XML_SEPA_INFO .=
' <CdtrAgt>'.$CrLf;
2252 $XML_SEPA_INFO .=
' <FinInstnId>'.$CrLf;
2253 $XML_SEPA_INFO .=
' <BIC>'.$this->emetteur_bic.
'</BIC>'.$CrLf;
2254 $XML_SEPA_INFO .=
' </FinInstnId>'.$CrLf;
2255 $XML_SEPA_INFO .=
' </CdtrAgt>'.$CrLf;
2264 $XML_SEPA_INFO .=
' <ChrgBr>SLEV</ChrgBr>'.$CrLf;
2265 $XML_SEPA_INFO .=
' <CdtrSchmeId>'.$CrLf;
2266 $XML_SEPA_INFO .=
' <Id>'.$CrLf;
2267 $XML_SEPA_INFO .=
' <PrvtId>'.$CrLf;
2268 $XML_SEPA_INFO .=
' <Othr>'.$CrLf;
2269 $XML_SEPA_INFO .=
' <Id>'.$this->emetteur_ics.
'</Id>'.$CrLf;
2270 $XML_SEPA_INFO .=
' <SchmeNm>'.$CrLf;
2271 $XML_SEPA_INFO .=
' <Prtry>SEPA</Prtry>'.$CrLf;
2272 $XML_SEPA_INFO .=
' </SchmeNm>'.$CrLf;
2273 $XML_SEPA_INFO .=
' </Othr>'.$CrLf;
2274 $XML_SEPA_INFO .=
' </PrvtId>'.$CrLf;
2275 $XML_SEPA_INFO .=
' </Id>'.$CrLf;
2276 $XML_SEPA_INFO .=
' </CdtrSchmeId>'.$CrLf;
2279 $XML_SEPA_INFO =
'';
2280 $XML_SEPA_INFO .=
' <PmtInf>'.$CrLf;
2281 $XML_SEPA_INFO .=
' <PmtInfId>'.(
'TRF/'.$dateTime_YMD.
'/ID'.$IdBon.
'-'.$RefBon).
'</PmtInfId>'.$CrLf;
2282 $XML_SEPA_INFO .=
' <PmtMtd>TRF</PmtMtd>'.$CrLf;
2284 $XML_SEPA_INFO .=
' <NbOfTxs>'.$nombre.
'</NbOfTxs>'.$CrLf;
2285 $XML_SEPA_INFO .=
' <CtrlSum>'.$total.
'</CtrlSum>'.$CrLf;
2286 if (!empty($this->sepa_xml_pti_in_ctti) && !empty($format)) {
2287 $XML_SEPA_INFO .=
' <PmtTpInf>' . $CrLf;
2288 $XML_SEPA_INFO .=
' <SvcLvl>' . $CrLf;
2289 $XML_SEPA_INFO .=
' <Cd>SEPA</Cd>' . $CrLf;
2290 $XML_SEPA_INFO .=
' </SvcLvl>' . $CrLf;
2291 $XML_SEPA_INFO .=
' <LclInstrm>' . $CrLf;
2292 $XML_SEPA_INFO .=
' <Cd>CORE</Cd>' . $CrLf;
2293 $XML_SEPA_INFO .=
' </LclInstrm>' . $CrLf;
2294 $XML_SEPA_INFO .=
' <SeqTp>' . $format .
'</SeqTp>' . $CrLf;
2295 $XML_SEPA_INFO .=
' </PmtTpInf>' . $CrLf;
2297 $XML_SEPA_INFO .=
' <ReqdExctnDt>'.dol_print_date($dateTime_ETAD,
'dayrfc').
'</ReqdExctnDt>'.$CrLf;
2298 $XML_SEPA_INFO .=
' <Dbtr>'.$CrLf;
2300 $XML_SEPA_INFO .=
' <PstlAdr>'.$CrLf;
2301 $XML_SEPA_INFO .=
' <Ctry>'.$country[1].
'</Ctry>'.$CrLf;
2302 $addressline1 = strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(CHR(13) =>
", ", CHR(10) =>
""));
2303 $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) =>
""));
2304 if ($addressline1) {
2307 if ($addressline2) {
2310 $XML_SEPA_INFO .=
' </PstlAdr>'.$CrLf;
2311 $XML_SEPA_INFO .=
' </Dbtr>'.$CrLf;
2312 $XML_SEPA_INFO .=
' <DbtrAcct>'.$CrLf;
2313 $XML_SEPA_INFO .=
' <Id>'.$CrLf;
2314 $XML_SEPA_INFO .=
' <IBAN>'.preg_replace(
'/\s/',
'', $this->emetteur_iban).
'</IBAN>'.$CrLf;
2315 $XML_SEPA_INFO .=
' </Id>'.$CrLf;
2316 $XML_SEPA_INFO .=
' </DbtrAcct>'.$CrLf;
2317 $XML_SEPA_INFO .=
' <DbtrAgt>'.$CrLf;
2318 $XML_SEPA_INFO .=
' <FinInstnId>'.$CrLf;
2319 $XML_SEPA_INFO .=
' <BIC>'.$this->emetteur_bic.
'</BIC>'.$CrLf;
2320 $XML_SEPA_INFO .=
' </FinInstnId>'.$CrLf;
2321 $XML_SEPA_INFO .=
' </DbtrAgt>'.$CrLf;
2330 $XML_SEPA_INFO .=
' <ChrgBr>SLEV</ChrgBr>'.$CrLf;
2345 fputs($this->file,
'INCORRECT EMETTEUR '.$this->raison_sociale.$CrLf);
2346 $XML_SEPA_INFO =
'';
2348 return $XML_SEPA_INFO;
2361 fputs($this->file,
"08");
2362 fputs($this->file,
"08");
2364 fputs($this->file,
" ");
2366 fputs($this->file, $this->emetteur_ics);
2370 fputs($this->file, substr(
" ", 0, 12));
2375 fputs($this->file, substr(
" ", 0, 24));
2379 fputs($this->file, substr(
" ", 0, 24));
2383 fputs($this->file, substr(
" ", 0, 8));
2387 fputs($this->file, substr(
" ", 0, 5));
2391 fputs($this->file, substr(
" ", 0, 11));
2395 $montant = ($total * 100);
2397 fputs($this->file, substr(
"000000000000000".$montant, -16));
2401 fputs($this->file, substr(
" ", 0, 31));
2405 fputs($this->file, substr(
" ", 0, 5));
2409 fputs($this->file, substr(
" ", 0, 5));
2411 fputs($this->file,
"\n");
2436 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
2439 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'StatusWaiting');
2440 $this->labelStatus[self::STATUS_TRANSFERED] = $langs->transnoentitiesnoconv(
'StatusTrans');
2441 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'StatusWaiting');
2442 $this->labelStatusShort[self::STATUS_TRANSFERED] = $langs->transnoentitiesnoconv(
'StatusTrans');
2443 if ($this->
type ==
'bank-transfer') {
2444 $this->labelStatus[self::STATUS_DEBITED] = $langs->transnoentitiesnoconv(
'StatusDebited');
2445 $this->labelStatusShort[self::STATUS_DEBITED] = $langs->transnoentitiesnoconv(
'StatusDebited');
2447 $this->labelStatus[self::STATUS_CREDITED] = $langs->transnoentitiesnoconv(
'StatusCredited');
2448 $this->labelStatusShort[self::STATUS_CREDITED] = $langs->transnoentitiesnoconv(
'StatusCredited');
2452 $statusType =
'status1';
2453 if ($status == self::STATUS_TRANSFERED) {
2454 $statusType =
'status3';
2456 if ($status == self::STATUS_CREDITED || $status == self::STATUS_DEBITED) {
2457 $statusType =
'status6';
2460 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
2474 global $conf, $langs;
2548 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2550 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2551 $return .=
'<div class="info-box info-box-sm">';
2552 $return .=
'<span class="info-box-icon bg-infobox-action">';
2554 $return .=
'</span>';
2555 $return .=
'<div class="info-box-content">';
2556 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
2557 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2559 if (property_exists($this,
'date_echeance')) {
2560 $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>';
2562 if (property_exists($this,
'total')) {
2563 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Amount").
'</span> : <span class="amount">'.
price($this->total).
'</span>';
2565 if (method_exists($this,
'LibStatut')) {
2566 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
2568 $return .=
'</div>';
2569 $return .=
'</div>';
2570 $return .=
'</div>';
Class to manage bank accounts.
Class to manage withdrawal receipts.
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
static buildRumNumber($row_code_client, $row_datec, $row_drum)
Generate dynamically a RUM number for a customer bank account.
SommeAPrelever($mode='direct-debit')
Returns amount waiting for direct debit payment or credit transfer payment.
EnregEmetteur($type='direct-debit')
Write sender of request (me).
update(User $user, $notrigger=false)
Update object into database.
EnregTotal($total)
Write end.
fetch($rowid, $ref='')
Get object and lines from database.
create($banque=0, $agence=0, $mode='real', $format='ALL', $executiondate='', $notrigger=0, $type='direct-debit', $did=0, $fk_bank_account=0)
Create a BAN payment order:
generate($format='ALL', $executiondate=0, $type='direct-debit', $fk_bank_account=0)
Generate a direct debit or credit transfer file.
deleteNotificationById($rowid)
Delete a notification def by id.
addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key)
Add line to withdrawal.
__construct($db)
Constructor.
EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $ref, $facid, $rib_dom='', $type='direct-debit')
Write recipient of request (customer)
NbFactureAPrelever($type='direct-debit')
Get number of invoices to pay.
getKanbanView($option='', $arraydata=null)
Return clicable 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.
set_infotrans($user, $date, $method)
Set withdrawal to transmited 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)
Set direct debit or credit transfer order to "paid" status.
nbOfInvoiceToPay($mode='direct-debit')
Get number of invoices waiting for payment.
AddFacture($invoice_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $type='debit-order')
Add invoice 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)
getListInvoices($amounts=0)
Get invoice list.
addNotification($db, $user, $action)
Add a notification.
deleteNotification($user, $action)
Delete a notification.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
updateCommon(User $user, $notrigger=false)
Update object into database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage bank accounts description of third parties.
Class to manage suppliers invoices.
Class to manage invoices.
Class to manage payments for supplier invoices.
Class to manage payments of customer invoices.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
print $langs trans("Ref").' m m m statut
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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_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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type