30 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
34 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
36 require_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();
86 const STATUS_DRAFT = 0;
87 const STATUS_TRANSFERED = 1;
88 const STATUS_CREDITED = 2;
89 const STATUS_DEBITED = 2;
135 public $fields=array(
136 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>
'1',
'position'=>10,
'notnull'=>1,
'visible'=>0,),
137 'ref' => array(
'type'=>
'varchar(12)',
'label'=>
'Ref',
'enabled'=>
'1',
'position'=>15,
'notnull'=>0,
'visible'=>-1,
'csslist'=>
'tdoverflowmax150',
'showoncombobox'=>
'1',),
138 'datec' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>
'1',
'position'=>25,
'notnull'=>0,
'visible'=>-1,),
139 'amount' => array(
'type'=>
'double(24,8)',
'label'=>
'Amount',
'enabled'=>
'1',
'position'=>30,
'notnull'=>0,
'visible'=>-1,),
140 'statut' => array(
'type'=>
'smallint(6)',
'label'=>
'Statut',
'enabled'=>
'1',
'position'=>500,
'notnull'=>0,
'visible'=>-1,
'arrayofkeyval'=>array(0=>
'Wait', 1=>
'Transfered', 2=>
'Credited')),
141 'credite' => array(
'type'=>
'smallint(6)',
'label'=>
'Credite',
'enabled'=>
'1',
'position'=>40,
'notnull'=>0,
'visible'=>-1,),
142 'note' => array(
'type'=>
'text',
'label'=>
'Note',
'enabled'=>
'1',
'position'=>45,
'notnull'=>0,
'visible'=>-1,),
143 'date_trans' => array(
'type'=>
'datetime',
'label'=>
'Datetrans',
'enabled'=>
'1',
'position'=>50,
'notnull'=>0,
'visible'=>-1,),
144 'method_trans' => array(
'type'=>
'smallint(6)',
'label'=>
'Methodtrans',
'enabled'=>
'1',
'position'=>55,
'notnull'=>0,
'visible'=>-1,),
145 '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',),
146 'date_credit' => array(
'type'=>
'datetime',
'label'=>
'Datecredit',
'enabled'=>
'1',
'position'=>65,
'notnull'=>0,
'visible'=>-1,),
147 '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',),
148 'type' => array(
'type'=>
'varchar(16)',
'label'=>
'Type',
'enabled'=>
'1',
'position'=>75,
'notnull'=>0,
'visible'=>-1,),
149 'fk_bank_account' => array(
'type'=>
'integer',
'label'=>
'Fkbankaccount',
'enabled'=>
'1',
'position'=>80,
'notnull'=>0,
'visible'=>-1,
'css'=>
'maxwidth500 widthcentpercentminusxx',),
159 public $method_trans;
160 public $fk_user_trans;
162 public $fk_user_credit;
164 public $fk_bank_account;
176 global $conf, $langs;
180 $this->filename =
'';
182 $this->date_echeance =
dol_now();
183 $this->raison_sociale =
"";
184 $this->reference_remise =
"";
186 $this->emetteur_code_guichet =
"";
187 $this->emetteur_numero_compte =
"";
188 $this->emetteur_code_banque =
"";
189 $this->emetteur_number_key =
"";
190 $this->sepa_xml_pti_in_ctti =
false;
192 $this->emetteur_iban =
"";
193 $this->emetteur_bic =
"";
194 $this->emetteur_ics =
"";
196 $this->factures = array();
198 $this->methodes_trans = array(0 =>
'Internet', 2 =>
'Email', 3 =>
'Api');
218 public function AddFacture($invoice_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $type =
'debit-order')
225 $result = $this->
addline($line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key);
229 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"prelevement (";
230 if ($type !=
'bank-transfer') {
231 $sql .=
"fk_facture";
233 $sql .=
"fk_facture_fourn";
235 $sql .=
",fk_prelevement_lignes";
236 $sql .=
") VALUES (";
237 $sql .= ((int) $invoice_id);
238 $sql .=
", ".((int) $line_id);
241 if ($this->
db->query(
$sql)) {
245 $this->errors[] = get_class($this).
"::AddFacture ".$this->
db->lasterror;
246 dol_syslog(get_class($this).
"::AddFacture Error $result");
250 $this->errors[] = get_class($this).
"::AddFacture linedid Empty";
251 dol_syslog(get_class($this).
"::AddFacture Error $result");
255 dol_syslog(get_class($this).
"::AddFacture Error $result");
274 public function addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key)
283 $sql =
"SELECT rowid";
284 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_lignes";
285 $sql .=
" WHERE fk_prelevement_bons = ".((int) $this->
id);
286 $sql .=
" AND fk_soc =".((int) $client_id);
287 $sql .=
" AND code_banque = '".$this->db->escape($code_banque).
"'";
288 $sql .=
" AND code_guichet = '".$this->db->escape($code_guichet).
"'";
289 $sql .=
" AND number = '".$this->db->escape($number).
"'";
291 $resql = $this->
db->query(
$sql);
293 $num = $this->
db->num_rows($resql);
301 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"prelevement_lignes (";
302 $sql .=
"fk_prelevement_bons";
304 $sql .=
", client_nom";
306 $sql .=
", code_banque";
307 $sql .=
", code_guichet";
310 $sql .=
") VALUES (";
312 $sql .=
", ".((int) $client_id);
313 $sql .=
", '".$this->db->escape($client_nom).
"'";
315 $sql .=
", '".$this->db->escape($code_banque).
"'";
316 $sql .=
", '".$this->db->escape($code_guichet).
"'";
317 $sql .=
", '".$this->db->escape($number).
"'";
318 $sql .=
", '".$this->db->escape($number_key).
"'";
321 if ($this->
db->query(
$sql)) {
322 $line_id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"prelevement_lignes");
325 $this->errors[] = get_class($this).
"::addline Error -2 ".$this->
db->lasterror;
326 dol_syslog(get_class($this).
"::addline Error -2");
346 $errors[1027] = $langs->trans(
"DateInvalid");
348 return $errors[abs($error)];
358 public function fetch($rowid, $ref =
'')
360 $sql =
"SELECT p.rowid, p.ref, p.amount, p.note";
361 $sql .=
", p.datec as dc";
362 $sql .=
", p.date_trans as date_trans";
363 $sql .=
", p.method_trans, p.fk_user_trans";
364 $sql .=
", p.date_credit as date_credit";
365 $sql .=
", p.fk_user_credit";
367 $sql .=
", p.fk_bank_account";
368 $sql .=
", p.statut as status";
369 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_bons as p";
370 $sql .=
" WHERE p.entity IN (".getEntity(
'invoice').
")";
372 $sql .=
" AND p.rowid = ".((int) $rowid);
374 $sql .=
" AND p.ref = '".$this->db->escape($ref).
"'";
377 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
378 $result = $this->
db->query(
$sql);
380 if ($this->
db->num_rows($result)) {
381 $obj = $this->
db->fetch_object($result);
383 $this->
id = $obj->rowid;
384 $this->
ref = $obj->ref;
385 $this->amount = $obj->amount;
386 $this->note = $obj->note;
387 $this->datec = $this->
db->jdate($obj->dc);
389 $this->date_trans = $this->
db->jdate($obj->date_trans);
390 $this->method_trans = $obj->method_trans;
391 $this->user_trans = $obj->fk_user_trans;
393 $this->date_credit = $this->
db->jdate($obj->date_credit);
394 $this->user_credit = $obj->fk_user_credit;
396 $this->
type = $obj->type;
397 $this->fk_bank_account = $obj->fk_bank_account;
399 $this->status = $obj->status;
400 $this->statut = $obj->status;
406 dol_syslog(get_class($this).
"::Fetch Erreur aucune ligne retournee");
438 global $conf, $langs;
442 if ($this->fetched == 1) {
443 if ($date < $this->date_trans) {
444 $langs->load(
"errors");
445 $this->error = $langs->trans(
'ErrorDateOfMovementLowerThanDateOfFileTransmission');
446 dol_syslog(
"bon-prelevment::set_infocredit 1027 ".$this->error);
452 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"prelevement_bons";
453 $sql .=
" SET fk_user_credit = ".$user->id;
454 $sql .=
", statut = ".self::STATUS_CREDITED;
455 $sql .=
", date_credit = '".$this->db->idate($date).
"'";
456 $sql .=
" WHERE rowid=".((int) $this->
id);
457 $sql .=
" AND entity = ".((int) $conf->entity);
458 $sql .=
" AND statut = ".self::STATUS_TRANSFERED;
460 $resql = $this->
db->query(
$sql);
462 $langs->load(
'withdrawals');
463 $subject = $langs->trans(
"InfoCreditSubject", $this->
ref);
464 $message = $langs->trans(
"InfoCreditMessage", $this->
ref,
dol_print_date($date,
'dayhour'));
467 $fk_bank_account = $this->fk_bank_account;
468 if (empty($fk_bank_account)) {
469 $fk_bank_account = ($this->
type ==
'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT);
474 $amountsperthirdparty = array();
480 for ($i = 0; $i < $num; $i++) {
481 if ($this->
type ==
'bank-transfer') {
487 $result = $fac->fetch($facs[$i][0]);
489 $amounts[$fac->id] = $facs[$i][1];
490 $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
492 $totalpaid = $fac->getSommePaiement();
493 $totalcreditnotes = $fac->getSumCreditNotesUsed();
494 $totaldeposits = $fac->getSumDepositsUsed();
495 $alreadypayed = $totalpaid + $totalcreditnotes + $totaldeposits;
498 if (
price2num($alreadypayed + $facs[$i][1],
'MT') == $fac->total_ttc) {
499 $result = $fac->setPaid($user);
501 $this->error = $fac->error;
502 $this->errors = $fac->errors;
509 foreach ($amountsperthirdparty as $thirdpartyid => $cursoramounts) {
510 if ($this->
type ==
'bank-transfer') {
515 $paiement->datepaye = $date;
516 $paiement->amounts = $cursoramounts;
518 if ($this->
type ==
'bank-transfer') {
519 $paiement->paiementid = 2;
520 $paiement->paiementcode =
'VIR';
522 $paiement->paiementid = 3;
523 $paiement->paiementcode =
'PRE';
526 $paiement->num_payment = $this->ref;
527 $paiement->id_prelevement = $this->id;
529 $paiement_id = $paiement->create($user);
530 if ($paiement_id < 0) {
532 $this->error = $paiement->error;
533 $this->errors = $paiement->errors;
534 dol_syslog(get_class($this).
"::set_infocredit AddPayment Error ".$this->error);
536 if ($this->
type ==
'bank-transfer') {
537 $modeforaddpayment =
'payment_supplier';
539 $modeforaddpayment =
'payment';
542 $result = $paiement->addPaymentToBank($user, $modeforaddpayment,
'(WithdrawalPayment)', $fk_bank_account,
'',
'');
545 $this->error = $paiement->error;
546 $this->errors = $paiement->errors;
547 dol_syslog(get_class($this).
"::set_infocredit AddPaymentToBank Error ".$this->error);
555 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"prelevement_lignes";
556 $sql .=
" SET statut = 2";
557 $sql .=
" WHERE fk_prelevement_bons = ".((int) $this->
id);
559 if (!$this->
db->query(
$sql)) {
560 dol_syslog(get_class($this).
"::set_infocredit Update lines Error");
565 $this->error = $this->
db->lasterror();
566 dol_syslog(get_class($this).
"::set_infocredit Update Bons Error");
574 $this->date_credit = $date;
575 $this->statut = self::STATUS_CREDITED;
580 $this->
db->rollback();
600 global $conf, $langs;
604 dol_syslog(get_class($this).
"::set_infotrans Start", LOG_INFO);
605 if ($this->
db->begin()) {
606 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_bons ";
607 $sql .=
" SET fk_user_trans = ".$user->id;
608 $sql .=
" , date_trans = '".$this->db->idate($date).
"'";
609 $sql .=
" , method_trans = ".((int) $method);
610 $sql .=
" , statut = ".self::STATUS_TRANSFERED;
611 $sql .=
" WHERE rowid = ".((int) $this->
id);
612 $sql .=
" AND entity = ".((int) $conf->entity);
613 $sql .=
" AND statut = 0";
615 if ($this->
db->query(
$sql)) {
616 $this->method_trans = $method;
617 $langs->load(
'withdrawals');
618 $subject = $langs->trans(
"InfoTransSubject", $this->
ref);
619 $message = $langs->trans(
"InfoTransMessage", $this->
ref,
dolGetFirstLastname($user->firstname, $user->lastname));
620 $message .= $langs->trans(
"InfoTransData",
price($this->amount), $this->methodes_trans[$this->method_trans],
dol_print_date($date,
'day'));
628 $this->date_trans = $date;
630 $this->user_trans = $user->id;
635 $this->
db->rollback();
636 dol_syslog(get_class($this).
"::set_infotrans ROLLBACK", LOG_ERR);
641 dol_syslog(get_class($this).
"::set_infotrans Ouverture transaction SQL impossible", LOG_CRIT);
662 if ($this->
type ==
'bank-transfer') {
663 $sql .=
" pf.fk_facture_fourn";
665 $sql .=
" pf.fk_facture";
668 $sql .=
", SUM(pl.amount)";
670 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_bons as p";
671 $sql .=
" , ".MAIN_DB_PREFIX.
"prelevement_lignes as pl";
672 $sql .=
" , ".MAIN_DB_PREFIX.
"prelevement as pf";
673 $sql .=
" WHERE pf.fk_prelevement_lignes = pl.rowid";
674 $sql .=
" AND pl.fk_prelevement_bons = p.rowid";
675 $sql .=
" AND p.rowid = ".((int) $this->
id);
676 $sql .=
" AND p.entity = ".((int) $conf->entity);
678 if ($this->
type ==
'bank-transfer') {
679 $sql .=
" GROUP BY fk_facture_fourn";
681 $sql .=
" GROUP BY fk_facture";
685 $resql = $this->
db->query(
$sql);
687 $num = $this->
db->num_rows($resql);
692 $row = $this->
db->fetch_row($resql);
704 $this->
db->free($resql);
706 dol_syslog(get_class($this).
"::getListInvoices Erreur");
724 $sql =
"SELECT sum(pfd.amount) as nb";
725 if ($mode !=
'bank-transfer') {
726 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f,";
728 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f,";
730 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement_demande as pfd";
731 $sql .=
" WHERE f.entity IN (".getEntity(
'invoice').
")";
732 if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
733 $sql .=
" AND f.fk_statut = ".Facture::STATUS_VALIDATED;
735 if ($mode !=
'bank-transfer') {
736 $sql .=
" AND f.rowid = pfd.fk_facture";
738 $sql .=
" AND f.rowid = pfd.fk_facture_fourn";
740 $sql .=
" AND f.paye = 0";
741 $sql .=
" AND pfd.traite = 0";
742 $sql .=
" AND pfd.ext_payment_id IS NULL";
743 $sql .=
" AND f.total_ttc > 0";
745 $resql = $this->
db->query(
$sql);
747 $obj = $this->
db->fetch_object($resql);
749 $this->
db->free($resql);
754 dol_syslog(get_class($this).
"::SommeAPrelever Erreur -1");
784 $sql =
"SELECT count(f.rowid) as nb";
785 if ($type ==
'bank-transfer') {
786 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
788 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
790 $sql .=
", ".MAIN_DB_PREFIX.
"prelevement_demande as pfd";
791 $sql .=
" WHERE f.entity IN (".getEntity(
'invoice').
")";
792 if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) {
793 $sql .=
" AND f.fk_statut = ".Facture::STATUS_VALIDATED;
795 if ($type ==
'bank-transfer') {
796 $sql .=
" AND f.rowid = pfd.fk_facture_fourn";
798 $sql .=
" AND f.rowid = pfd.fk_facture";
800 $sql .=
" AND pfd.traite = 0";
801 $sql .=
" AND pfd.ext_payment_id IS NULL";
802 $sql .=
" AND f.total_ttc > 0";
804 dol_syslog(get_class($this).
"::NbFactureAPrelever");
805 $resql = $this->
db->query(
$sql);
808 $obj = $this->
db->fetch_object($resql);
810 $this->
db->free($resql);
814 $this->error = get_class($this).
"::NbFactureAPrelever Erreur -1 sql=".$this->
db->error();
840 public function create($banque = 0, $agence = 0, $mode =
'real', $format =
'ALL', $executiondate =
'', $notrigger = 0, $type =
'direct-debit', $did = 0, $fk_bank_account = 0)
843 global $conf, $langs, $user;
845 dol_syslog(__METHOD__.
" Bank=".$banque.
" Office=".$agence.
" mode=".$mode.
" format=".$format, LOG_DEBUG);
847 require_once DOL_DOCUMENT_ROOT.
"/compta/facture/class/facture.class.php";
848 require_once DOL_DOCUMENT_ROOT.
"/societe/class/societe.class.php";
851 if ($type !=
'bank-transfer') {
852 if (empty($format)) {
853 $this->error =
'ErrorBadParametersForDirectDebitFileCreate';
859 if (empty($fk_bank_account)) {
860 $fk_bank_account = ($type ==
'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT);
865 $datetimeprev =
dol_now(
'gmt');
867 if (!empty($executiondate)) {
868 $datetimeprev = $executiondate;
874 $this->invoice_in_error = array();
875 $this->thirdparty_in_error = array();
879 $factures_prev = array();
880 $factures_result = array();
881 $factures_prev_id = array();
882 $factures_errors = array();
885 $sql =
"SELECT f.rowid, pfd.rowid as pfdrowid, f.fk_soc";
886 $sql .=
", pfd.code_banque, pfd.code_guichet, pfd.number, pfd.cle_rib";
887 $sql .=
", pfd.amount";
888 $sql .=
", s.nom as name";
889 if ($type !=
'bank-transfer') {
890 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
892 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
894 $sql .=
", ".MAIN_DB_PREFIX.
"societe as s";
895 $sql .=
", ".MAIN_DB_PREFIX.
"prelevement_demande as pfd";
896 $sql .=
" WHERE f.entity IN (".getEntity(
'invoice').
')';
897 if ($type !=
'bank-transfer') {
898 $sql .=
" AND f.rowid = pfd.fk_facture";
900 $sql .=
" AND f.rowid = pfd.fk_facture_fourn";
902 $sql .=
" AND s.rowid = f.fk_soc";
903 $sql .=
" AND f.fk_statut = 1";
904 $sql .=
" AND f.paye = 0";
905 $sql .=
" AND pfd.traite = 0";
906 $sql .=
" AND f.total_ttc > 0";
907 $sql .=
" AND pfd.ext_payment_id IS NULL";
909 $sql .=
" AND pfd.rowid = ".((int) $did);
911 dol_syslog(__METHOD__.
" Read invoices,", LOG_DEBUG);
913 $resql = $this->
db->query(
$sql);
915 $num = $this->
db->num_rows($resql);
919 $row = $this->
db->fetch_row($resql);
920 $factures[$i] = $row;
923 dol_syslog(__METHOD__.
" Read invoices error Found a null invoice", LOG_ERR);
924 $this->invoice_in_error[$row[0]] =
"Error for invoice id ".$row[0].
", found a null amount";
929 $this->
db->free($resql);
930 dol_syslog(__METHOD__.
" Read invoices, ".$i.
" invoices to withdraw", LOG_DEBUG);
933 dol_syslog(__METHOD__.
" Read invoices error ".$this->db->error(), LOG_ERR);
938 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
943 dol_syslog(__METHOD__.
" Check BAN", LOG_DEBUG);
945 if (count($factures) > 0) {
946 foreach ($factures as $key => $fac) {
947 if ($type !=
'bank-transfer') {
952 $resfetch = $tmpinvoice->fetch($fac[0]);
953 if ($resfetch >= 0) {
954 if ($soc->fetch($tmpinvoice->socid) >= 0) {
956 $bac->fetch(0, $soc->id);
958 if ($type !=
'bank-transfer') {
959 if ($format ==
'FRST' && $bac->frstrecur !=
'FRST') {
962 if ($format ==
'RCUR' && ($bac->frstrecur !=
'RCUR' && $bac->frstrecur !=
'RECUR')) {
967 if ($bac->verif() >= 1) {
968 $factures_prev[$i] = $fac;
970 $factures_prev_id[$i] = $fac[0];
974 dol_syslog(__METHOD__.
" Check BAN Error on default bank number IBAN/BIC for thirdparty reported by verif() ".$tmpinvoice->socid.
" ".$soc->name, LOG_WARNING);
975 $this->invoice_in_error[$fac[0]] =
"Error on default bank number IBAN/BIC for invoice ".$tmpinvoice->getNomUrl(0).
" for thirdparty ".$soc->getNomUrl(0);
976 $this->thirdparty_in_error[$soc->id] =
"Error on default bank number IBAN/BIC for invoice ".$tmpinvoice->getNomUrl(0).
" for thirdparty ".$soc->getNomUrl(0);
979 dol_syslog(__METHOD__.
" Check BAN Failed to read company", LOG_WARNING);
982 dol_syslog(__METHOD__.
" Check BAN Failed to read invoice", LOG_WARNING);
986 dol_syslog(__METHOD__.
" Check BAN No invoice to process", LOG_WARNING);
993 $out = count($factures_prev).
" invoices will be included.";
1006 if (count($factures_prev) > 0) {
1007 if ($mode ==
'real') {
1010 print $langs->trans(
"ModeWarning");
1028 $ref = substr($year, -2).$month;
1031 $sql =
"SELECT substring(ref from char_length(ref) - 1)";
1032 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_bons";
1033 $sql .=
" WHERE ref LIKE '_".$this->db->escape($ref).
"%'";
1034 $sql .=
" AND entity = ".((int) $conf->entity);
1035 $sql .=
" ORDER BY ref DESC LIMIT 1";
1037 dol_syslog(get_class($this).
" get next free number", LOG_DEBUG);
1038 $resql = $this->
db->query(
$sql);
1041 $row = $this->
db->fetch_row($resql);
1044 $ref =
"T".$ref.sprintf(
"%02d", (intval($row[0]) + 1));
1050 if ($type !=
'bank-transfer') {
1051 $dir = $conf->prelevement->dir_output.
'/receipts';
1053 $dir = $conf->paymentbybanktransfer->dir_output.
'/receipts';
1055 if (!is_dir($dir)) {
1059 $this->filename = $dir.
'/'.$ref.
'.xml';
1062 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"prelevement_bons (";
1063 $sql .=
"ref, entity, datec, type, fk_bank_account";
1064 $sql .=
") VALUES (";
1065 $sql .=
"'".$this->db->escape($ref).
"'";
1066 $sql .=
", ".((int) $conf->entity);
1067 $sql .=
", '".$this->db->idate($now).
"'";
1068 $sql .=
", '".($type ==
'bank-transfer' ?
'bank-transfer' :
'debit-order').
"'";
1069 $sql .=
", ".((int) $fk_bank_account);
1072 $resql = $this->
db->query(
$sql);
1074 $prev_id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"prelevement_bons");
1075 $this->
id = $prev_id;
1079 dol_syslog(__METHOD__.
" Create withdraw receipt ".$this->db->lasterror(), LOG_ERR);
1083 dol_syslog(__METHOD__.
" Get last withdraw receipt ".$this->db->lasterror(), LOG_ERR);
1088 if ($type !=
'bank-transfer') {
1095 if (count($factures_prev) > 0) {
1096 foreach ($factures_prev as $fac) {
1098 $result = $fact->fetch($fac[0]);
1100 $this->error =
'ERRORBONPRELEVEMENT Failed to load invoice with id '.$fac[0];
1117 $ri = $this->
AddFacture($fac[0], $fac[2], $fac[8], $fac[7], $fac[3], $fac[4], $fac[5], $fac[6], $type);
1123 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_demande";
1124 $sql .=
" SET traite = 1";
1125 $sql .=
", date_traite = '".$this->db->idate($now).
"'";
1126 $sql .=
", fk_prelevement_bons = ".((int) $this->
id);
1127 $sql .=
" WHERE rowid = ".((int) $fac[1]);
1129 $resql = $this->
db->query(
$sql);
1132 $this->errors[] = $this->
db->lasterror();
1133 dol_syslog(__METHOD__.
" Update Error=".$this->db->lasterror(), LOG_ERR);
1144 dol_syslog(__METHOD__.
" Init direct debit or credit transfer file for ".count($factures_prev).
" invoices", LOG_DEBUG);
1146 if (count($factures_prev) > 0) {
1147 $this->date_echeance = $datetimeprev;
1148 $this->reference_remise = $ref;
1151 if ($account->fetch($fk_bank_account) > 0) {
1152 $this->emetteur_code_banque = $account->code_banque;
1153 $this->emetteur_code_guichet = $account->code_guichet;
1154 $this->emetteur_numero_compte = $account->number;
1155 $this->emetteur_number_key = $account->cle_rib;
1156 $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
1157 $this->emetteur_iban = $account->iban;
1158 $this->emetteur_bic = $account->bic;
1160 $this->emetteur_ics = ($type ==
'bank-transfer' ? $account->ics_transfer : $account->ics);
1162 $this->raison_sociale = $account->proprio;
1165 $this->factures = $factures_prev_id;
1166 $this->context[
'factures_prev'] = $factures_prev;
1170 $result = $this->
generate($format, $executiondate, $type);
1177 dol_syslog(__METHOD__.
" Bank order file has been generated under filename ".$this->filename, LOG_DEBUG);
1185 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_bons";
1186 $sql .=
" SET amount = ".price2num($this->total);
1187 $sql .=
" WHERE rowid = ".((int) $this->
id);
1188 $sql .=
" AND entity = ".((int) $conf->entity);
1190 $resql = $this->
db->query(
$sql);
1193 dol_syslog(__METHOD__.
" Error update total: ".$this->db->error(), LOG_ERR);
1197 if (!$error && !$notrigger) {
1198 $triggername =
'DIRECT_DEBIT_ORDER_CREATE';
1199 if ($type !=
'bank-transfer') {
1200 $triggername =
'CREDIT_TRANSFER_ORDER_CREATE';
1212 $this->
db->commit();
1213 return count($factures_prev);
1215 $this->
db->rollback();
1231 public function delete($user =
null, $notrigger = 0)
1236 $resql1 = $resql2 = $resql3 = $resql4 = 0;
1239 $triggername =
'DIRECT_DEBIT_ORDER_DELETE';
1240 if ($this->
type ==
'bank-transfer') {
1241 $triggername =
'PAYMENTBYBANKTRANFER_DELETE';
1252 $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).
")";
1253 $resql1 = $this->
db->query(
$sql);
1260 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"prelevement_lignes WHERE fk_prelevement_bons = ".((int) $this->
id);
1261 $resql2 = $this->
db->query(
$sql);
1268 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"prelevement_bons WHERE rowid = ".((int) $this->
id);
1269 $resql3 = $this->
db->query(
$sql);
1276 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_demande SET fk_prelevement_bons = NULL, traite = 0 WHERE fk_prelevement_bons = ".((int) $this->
id);
1277 $resql4 = $this->
db->query(
$sql);
1283 if ($resql1 && $resql2 && $resql3 && $resql4 && !$error) {
1284 $this->
db->commit();
1287 $this->
db->rollback();
1303 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1305 global $conf, $langs, $hookmanager;
1307 if (!empty($conf->dol_no_mouse_hover)) {
1313 $labeltoshow =
'PaymentByDirectDebit';
1314 if (!empty($this->
type) && $this->
type ==
'bank-transfer') {
1315 $labeltoshow =
'PaymentByBankTransfer';
1318 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans($labeltoshow).
'</u> '.$this->
getLibStatut(5);
1320 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1321 if (isset($this->amount)) {
1322 $label .=
'<br><b>'.$langs->trans(
"Amount").
":</b> ".
price($this->amount);
1324 if (isset($this->date_trans)) {
1325 $label .=
'<br><b>'.$langs->trans(
"TransData").
":</b> ".
dol_print_date($this->date_trans,
'dayhour',
'tzuserrel');
1331 $url = DOL_URL_ROOT.
'/compta/prelevement/card.php?id='.$this->id;
1332 if (!empty($this->
type) && $this->
type ==
'bank-transfer') {
1333 $url = DOL_URL_ROOT.
'/compta/prelevement/card.php?id='.$this->id;
1336 if ($option !=
'nolink') {
1338 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1339 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1340 $add_save_lastsearch_values = 1;
1342 if ($add_save_lastsearch_values) {
1343 $url .=
'&save_lastsearch_values=1';
1348 if (empty($notooltip)) {
1349 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1350 $label = $langs->trans(
"ShowMyObject");
1351 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1353 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1354 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1356 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1359 $linkstart =
'<a href="'.$url.
'"';
1360 $linkstart .= $linkclose.
'>';
1363 $result .= $linkstart;
1365 $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);
1367 if ($withpicto != 2) {
1368 $result .= $this->ref;
1370 $result .= $linkend;
1372 global $action, $hookmanager;
1373 $hookmanager->initHooks(array(
'banktransferdao'));
1374 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1375 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1377 $result = $hookmanager->resPrint;
1379 $result .= $hookmanager->resPrint;
1394 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"notify_def";
1395 $sql .=
" WHERE rowid = ".((int) $rowid);
1397 if ($this->
db->query(
$sql)) {
1413 if (is_object($user)) {
1414 $userid = $user->id;
1419 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"notify_def";
1420 $sql .=
" WHERE fk_user=".((int) $userid).
" AND fk_action='".$this->
db->escape($action).
"'";
1422 if ($this->
db->query(
$sql)) {
1443 if (is_object($user)) {
1444 $userid = $user->id;
1452 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"notify_def (datec,fk_user, fk_soc, fk_contact, fk_action)";
1453 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".((int) $userid).
", 'NULL', 'NULL', '".$this->
db->escape($action).
"')";
1456 if ($this->
db->query(
$sql)) {
1460 dol_syslog(get_class($this).
"::addNotification Error $result");
1481 public function generate($format =
'ALL', $executiondate = 0, $type =
'direct-debit', $fk_bank_account = 0)
1483 global $conf, $langs, $mysoc;
1488 if (empty($fk_bank_account)) {
1489 $fk_bank_account = ($type ==
'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT);
1494 dol_syslog(get_class($this).
"::generate build file=".$this->filename.
" type=".$type);
1496 $this->file = fopen($this->filename,
"w");
1497 if (empty($this->file)) {
1498 $this->error = $langs->trans(
'ErrorFailedToOpenFile', $this->filename);
1506 if ($mysoc->isInEEC()) {
1509 if ($type !=
'bank-transfer') {
1521 if (!empty($executiondate)) {
1522 $date_actu = $executiondate;
1527 $fileDebiteurSection =
'';
1528 $fileEmetteurSection =
'';
1535 $sql =
"SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
1536 $sql .=
" pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
1537 $sql .=
" f.ref as fac, pf.fk_facture as idfac,";
1538 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
1540 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement_lignes as pl,";
1541 $sql .=
" ".MAIN_DB_PREFIX.
"facture as f,";
1542 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement as pf,";
1543 $sql .=
" ".MAIN_DB_PREFIX.
"societe as soc,";
1544 $sql .=
" ".MAIN_DB_PREFIX.
"c_country as c,";
1545 $sql .=
" ".MAIN_DB_PREFIX.
"societe_rib as rib";
1546 $sql .=
" WHERE pl.fk_prelevement_bons = ".((int) $this->
id);
1547 $sql .=
" AND pl.rowid = pf.fk_prelevement_lignes";
1548 $sql .=
" AND pf.fk_facture = f.rowid";
1549 $sql .=
" AND f.fk_soc = soc.rowid";
1550 $sql .=
" AND soc.fk_pays = c.rowid";
1551 $sql .=
" AND rib.fk_soc = f.fk_soc";
1552 $sql .=
" AND rib.default_rib = 1";
1553 $sql .=
" AND rib.type = 'ban'";
1556 $resql = $this->
db->query(
$sql);
1558 $cachearraytotestduplicate = array();
1560 $num = $this->
db->num_rows($resql);
1562 $obj = $this->
db->fetch_object($resql);
1564 if (!empty($cachearraytotestduplicate[$obj->idfac])) {
1565 $this->error = $langs->trans(
'ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
1566 $this->invoice_in_error[$obj->idfac] = $this->error;
1570 $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
1572 $daterum = (!empty($obj->date_rum)) ? $this->
db->jdate($obj->date_rum) : $this->
db->jdate($obj->datec);
1573 $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->fac, $obj->idfac, $obj->iban, $obj->bic, $daterum, $obj->drum, $obj->rum, $type);
1574 $this->total = $this->total + $obj->somme;
1577 $nbtotalDrctDbtTxInf = $i;
1579 $this->error = $this->
db->lasterror();
1580 fputs($this->file,
'ERROR DEBITOR '.
$sql.$CrLf);
1585 if ($result != -2) {
1586 $fileEmetteurSection .= $this->
EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type, $fk_bank_account);
1593 fputs($this->file,
'<'.
'?xml version="1.0" encoding="UTF-8" standalone="yes"?'.
'>'.$CrLf);
1594 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);
1595 fputs($this->file,
' <CstmrDrctDbtInitn>'.$CrLf);
1597 fputs($this->file,
' <GrpHdr>'.$CrLf);
1598 fputs($this->file,
' <MsgId>'.(
'DD/'.$dateTime_YMD.
'/REF'.$this->id).
'</MsgId>'.$CrLf);
1599 fputs($this->file,
' <CreDtTm>'.$dateTime_ECMA.
'</CreDtTm>'.$CrLf);
1600 fputs($this->file,
' <NbOfTxs>'.$i.
'</NbOfTxs>'.$CrLf);
1601 fputs($this->file,
' <CtrlSum>'.$this->total.
'</CtrlSum>'.$CrLf);
1602 fputs($this->file,
' <InitgPty>'.$CrLf);
1604 fputs($this->file,
' <Id>'.$CrLf);
1605 fputs($this->file,
' <PrvtId>'.$CrLf);
1606 fputs($this->file,
' <Othr>'.$CrLf);
1607 fputs($this->file,
' <Id>'.$this->emetteur_ics.
'</Id>'.$CrLf);
1608 fputs($this->file,
' </Othr>'.$CrLf);
1609 fputs($this->file,
' </PrvtId>'.$CrLf);
1610 fputs($this->file,
' </Id>'.$CrLf);
1611 fputs($this->file,
' </InitgPty>'.$CrLf);
1612 fputs($this->file,
' </GrpHdr>'.$CrLf);
1614 if ($result != -2) {
1615 fputs($this-> file, $fileEmetteurSection);
1618 if ($result != -2) {
1619 fputs($this-> file, $fileDebiteurSection);
1622 fputs($this->file,
' </PmtInf>'.$CrLf);
1623 fputs($this->file,
' </CstmrDrctDbtInitn>'.$CrLf);
1624 fputs($this->file,
'</Document>'.$CrLf);
1637 if (!empty($executiondate)) {
1638 $date_actu = $executiondate;
1643 $fileCrediteurSection =
'';
1644 $fileEmetteurSection =
'';
1651 $sql =
"SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
1652 $sql .=
" pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
1653 $sql .=
" f.ref as fac, pf.fk_facture_fourn as idfac, f.ref_supplier as fac_ref_supplier,";
1654 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
1656 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement_lignes as pl,";
1657 $sql .=
" ".MAIN_DB_PREFIX.
"facture_fourn as f,";
1658 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement as pf,";
1659 $sql .=
" ".MAIN_DB_PREFIX.
"societe as soc,";
1660 $sql .=
" ".MAIN_DB_PREFIX.
"c_country as c,";
1661 $sql .=
" ".MAIN_DB_PREFIX.
"societe_rib as rib";
1662 $sql .=
" WHERE pl.fk_prelevement_bons = ".((int) $this->
id);
1663 $sql .=
" AND pl.rowid = pf.fk_prelevement_lignes";
1664 $sql .=
" AND pf.fk_facture_fourn = f.rowid";
1665 $sql .=
" AND f.fk_soc = soc.rowid";
1666 $sql .=
" AND soc.fk_pays = c.rowid";
1667 $sql .=
" AND rib.fk_soc = f.fk_soc";
1668 $sql .=
" AND rib.default_rib = 1";
1669 $sql .=
" AND rib.type = 'ban'";
1672 $resql = $this->
db->query(
$sql);
1674 $cachearraytotestduplicate = array();
1676 $num = $this->
db->num_rows($resql);
1678 $obj = $this->
db->fetch_object($resql);
1680 if (!empty($cachearraytotestduplicate[$obj->idfac])) {
1681 $this->error = $langs->trans(
'ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
1682 $this->invoice_in_error[$obj->idfac] = $this->error;
1686 $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
1688 $daterum = (!empty($obj->date_rum)) ? $this->
db->jdate($obj->date_rum) : $this->
db->jdate($obj->datec);
1689 $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->fac_ref_supplier, $obj->idfac, $obj->iban, $obj->bic, $daterum, $obj->drum, $obj->rum, $type);
1690 $this->total = $this->total + $obj->somme;
1693 $nbtotalDrctDbtTxInf = $i;
1695 $this->error = $this->
db->lasterror();
1696 fputs($this->file,
'ERROR CREDITOR '.
$sql.$CrLf);
1701 if ($result != -2) {
1702 $fileEmetteurSection .= $this->
EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type);
1709 fputs($this->file,
'<'.
'?xml version="1.0" encoding="UTF-8" standalone="yes"?'.
'>'.$CrLf);
1710 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);
1711 fputs($this->file,
' <CstmrCdtTrfInitn>'.$CrLf);
1713 fputs($this->file,
' <GrpHdr>'.$CrLf);
1714 fputs($this->file,
' <MsgId>'.(
'TRF/'.$dateTime_YMD.
'/REF'.$this->id).
'</MsgId>'.$CrLf);
1715 fputs($this->file,
' <CreDtTm>'.$dateTime_ECMA.
'</CreDtTm>'.$CrLf);
1716 fputs($this->file,
' <NbOfTxs>'.$i.
'</NbOfTxs>'.$CrLf);
1717 fputs($this->file,
' <CtrlSum>'.$this->total.
'</CtrlSum>'.$CrLf);
1718 fputs($this->file,
' <InitgPty>'.$CrLf);
1720 fputs($this->file,
' <Id>'.$CrLf);
1721 fputs($this->file,
' <PrvtId>'.$CrLf);
1722 fputs($this->file,
' <Othr>'.$CrLf);
1723 fputs($this->file,
' <Id>'.$this->emetteur_ics.
'</Id>'.$CrLf);
1724 fputs($this->file,
' </Othr>'.$CrLf);
1725 fputs($this->file,
' </PrvtId>'.$CrLf);
1726 fputs($this->file,
' </Id>'.$CrLf);
1727 fputs($this->file,
' </InitgPty>'.$CrLf);
1728 fputs($this->file,
' </GrpHdr>'.$CrLf);
1730 if ($result != -2) {
1731 fputs($this-> file, $fileEmetteurSection);
1734 if ($result != -2) {
1735 fputs($this-> file, $fileCrediteurSection);
1738 fputs($this->file,
' </PmtInf>'.$CrLf);
1739 fputs($this->file,
' </CstmrCdtTrfInitn>'.$CrLf);
1740 fputs($this->file,
'</Document>'.$CrLf);
1746 if ($type !=
'bank-transfer') {
1747 $sql =
"SELECT pl.amount";
1749 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement_lignes as pl,";
1750 $sql .=
" ".MAIN_DB_PREFIX.
"facture as f,";
1751 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement as pf";
1752 $sql .=
" WHERE pl.fk_prelevement_bons = ".((int) $this->
id);
1753 $sql .=
" AND pl.rowid = pf.fk_prelevement_lignes";
1754 $sql .=
" AND pf.fk_facture = f.rowid";
1758 $resql = $this->
db->query(
$sql);
1760 $num = $this->
db->num_rows($resql);
1763 $obj = $this->
db->fetch_object($resql);
1764 $this->total = $this->total + $obj->amount;
1773 $sql =
"SELECT pl.amount";
1775 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement_lignes as pl,";
1776 $sql .=
" ".MAIN_DB_PREFIX.
"facture_fourn as f,";
1777 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement as pf";
1778 $sql .=
" WHERE pl.fk_prelevement_bons = ".((int) $this->
id);
1779 $sql .=
" AND pl.rowid = pf.fk_prelevement_lignes";
1780 $sql .=
" AND pf.fk_facture_fourn = f.rowid";
1784 $resql = $this->
db->query(
$sql);
1786 $num = $this->
db->num_rows($resql);
1789 $obj = $this->
db->fetch_object($resql);
1790 $this->total = $this->total + $obj->amount;
1800 $langs->load(
'withdrawals');
1803 fputs($this->file, $langs->transnoentitiesnoconv(
'WithdrawalFileNotCapable', $mysoc->country_code));
1806 fclose($this->file);
1828 return $pre.
'-'.
dol_print_date($row_datec,
'dayhourlogsmall').
'-'.
dol_trunc($row_drum.($row_code_client ?
'-'.$row_code_client :
''), 13,
'right',
'UTF-8', 1);
1849 public function EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $ref, $facid, $rib_dom =
'', $type =
'direct-debit')
1852 fputs($this->file,
"06");
1853 fputs($this->file,
"08");
1855 fputs($this->file,
" ");
1857 fputs($this->file, $this->emetteur_ics);
1861 fputs($this->file,
" ");
1862 fputs($this->file,
dol_print_date($this->date_echeance,
"%d%m",
'gmt'));
1863 fputs($this->file, substr(
dol_print_date($this->date_echeance,
"%y",
'gmt'), 1));
1867 fputs($this->file, substr(strtoupper($client_nom).
" ", 0, 24));
1870 $domiciliation = strtr($rib_dom, array(
" " =>
"-", CHR(13) =>
" ", CHR(10) =>
""));
1871 fputs($this->file, substr($domiciliation.
" ", 0, 24));
1875 fputs($this->file, substr(
" ", 0, 8));
1879 fputs($this->file, $rib_guichet);
1883 fputs($this->file, substr(
"000000000000000".$rib_number, -11));
1887 $montant = (round($amount, 2) * 100);
1889 fputs($this->file, substr(
"000000000000000".$montant, -16));
1893 fputs($this->file, substr(
"*_".$ref.
"_RDVnet".$rowid.
" ", 0, 31));
1897 fputs($this->file, $rib_banque);
1901 fputs($this->file, substr(
" ", 0, 5));
1903 fputs($this->file,
"\n");
1931 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')
1936 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1939 $Rowing = sprintf(
"%010d", $row_idfac);
1943 $Rum = (empty($row_rum) ? $this->
buildRumNumber($row_code_client, $row_datec, $row_drum) : $row_rum);
1948 if ($type !=
'bank-transfer') {
1951 $XML_DEBITOR .=
' <DrctDbtTxInf>'.$CrLf;
1952 $XML_DEBITOR .=
' <PmtId>'.$CrLf;
1954 $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;
1955 $XML_DEBITOR .=
' </PmtId>'.$CrLf;
1956 $XML_DEBITOR .=
' <InstdAmt Ccy="EUR">'.round($row_somme, 2).
'</InstdAmt>'.$CrLf;
1957 $XML_DEBITOR .=
' <DrctDbtTx>'.$CrLf;
1958 $XML_DEBITOR .=
' <MndtRltdInf>'.$CrLf;
1959 $XML_DEBITOR .=
' <MndtId>'.$Rum.
'</MndtId>'.$CrLf;
1960 $XML_DEBITOR .=
' <DtOfSgntr>'.$DtOfSgntr.
'</DtOfSgntr>'.$CrLf;
1961 $XML_DEBITOR .=
' <AmdmntInd>false</AmdmntInd>'.$CrLf;
1962 $XML_DEBITOR .=
' </MndtRltdInf>'.$CrLf;
1963 $XML_DEBITOR .=
' </DrctDbtTx>'.$CrLf;
1964 $XML_DEBITOR .=
' <DbtrAgt>'.$CrLf;
1965 $XML_DEBITOR .=
' <FinInstnId>'.$CrLf;
1966 $XML_DEBITOR .=
' <BIC>'.$row_bic.
'</BIC>'.$CrLf;
1967 $XML_DEBITOR .=
' </FinInstnId>'.$CrLf;
1968 $XML_DEBITOR .=
' </DbtrAgt>'.$CrLf;
1969 $XML_DEBITOR .=
' <Dbtr>'.$CrLf;
1971 $XML_DEBITOR .=
' <PstlAdr>'.$CrLf;
1972 $XML_DEBITOR .=
' <Ctry>'.$row_country_code.
'</Ctry>'.$CrLf;
1973 $addressline1 = strtr($row_address, array(CHR(13) =>
", ", CHR(10) =>
""));
1974 $addressline2 = strtr($row_zip.(($row_zip && $row_town) ?
' ' : (string) $row_town), array(CHR(13) =>
", ", CHR(10) =>
""));
1975 if (trim($addressline1)) {
1978 if (trim($addressline2)) {
1981 $XML_DEBITOR .=
' </PstlAdr>'.$CrLf;
1982 $XML_DEBITOR .=
' </Dbtr>'.$CrLf;
1983 $XML_DEBITOR .=
' <DbtrAcct>'.$CrLf;
1984 $XML_DEBITOR .=
' <Id>'.$CrLf;
1985 $XML_DEBITOR .=
' <IBAN>'.preg_replace(
'/\s/',
'', $row_iban).
'</IBAN>'.$CrLf;
1986 $XML_DEBITOR .=
' </Id>'.$CrLf;
1987 $XML_DEBITOR .=
' </DbtrAcct>'.$CrLf;
1988 $XML_DEBITOR .=
' <RmtInf>'.$CrLf;
1990 $XML_DEBITOR .=
' <Ustrd>'.(($conf->global->PRELEVEMENT_USTRD !=
"") ? $conf->global->PRELEVEMENT_USTRD :
dol_trunc($row_ref, 135,
'right',
'UTF-8', 1)).
'</Ustrd>'.$CrLf;
1991 $XML_DEBITOR .=
' </RmtInf>'.$CrLf;
1992 $XML_DEBITOR .=
' </DrctDbtTxInf>'.$CrLf;
1993 return $XML_DEBITOR;
1997 $XML_CREDITOR .=
' <CdtTrfTxInf>'.$CrLf;
1998 $XML_CREDITOR .=
' <PmtId>'.$CrLf;
2000 $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;
2001 $XML_CREDITOR .=
' </PmtId>'.$CrLf;
2002 if (!empty($this->sepa_xml_pti_in_ctti)) {
2003 $XML_CREDITOR .=
' <PmtTpInf>' . $CrLf;
2006 if (!empty($conf->global->PAYMENTBYBANKTRANSFER_FORCE_HIGH_PRIORITY)) {
2007 $instrprty =
'HIGH';
2009 $instrprty =
'NORM';
2011 $XML_CREDITOR .=
' <InstrPrty>'.$instrprty.
'</InstrPrty>' . $CrLf;
2012 $XML_CREDITOR .=
' <SvcLvl>' . $CrLf;
2013 $XML_CREDITOR .=
' <Cd>SEPA</Cd>' . $CrLf;
2014 $XML_CREDITOR .=
' </SvcLvl>' . $CrLf;
2015 $XML_CREDITOR .=
' <CtgyPurp>' . $CrLf;
2016 $XML_CREDITOR .=
' <Cd>CORE</Cd>' . $CrLf;
2017 $XML_CREDITOR .=
' </CtgyPurp>' . $CrLf;
2018 $XML_CREDITOR .=
' </PmtTpInf>' . $CrLf;
2020 $XML_CREDITOR .=
' <Amt>'.$CrLf;
2021 $XML_CREDITOR .=
' <InstdAmt Ccy="EUR">'.round($row_somme, 2).
'</InstdAmt>'.$CrLf;
2022 $XML_CREDITOR .=
' </Amt>'.$CrLf;
2033 $XML_CREDITOR .=
' <CdtrAgt>'.$CrLf;
2034 $XML_CREDITOR .=
' <FinInstnId>'.$CrLf;
2035 $XML_CREDITOR .=
' <BIC>'.$row_bic.
'</BIC>'.$CrLf;
2036 $XML_CREDITOR .=
' </FinInstnId>'.$CrLf;
2037 $XML_CREDITOR .=
' </CdtrAgt>'.$CrLf;
2038 $XML_CREDITOR .=
' <Cdtr>'.$CrLf;
2040 $XML_CREDITOR .=
' <PstlAdr>'.$CrLf;
2041 $XML_CREDITOR .=
' <Ctry>'.$row_country_code.
'</Ctry>'.$CrLf;
2042 $addressline1 = strtr($row_address, array(CHR(13) =>
", ", CHR(10) =>
""));
2043 $addressline2 = strtr($row_zip.(($row_zip && $row_town) ?
' ' : (string) $row_town), array(CHR(13) =>
", ", CHR(10) =>
""));
2044 if (trim($addressline1)) {
2047 if (trim($addressline2)) {
2050 $XML_CREDITOR .=
' </PstlAdr>'.$CrLf;
2051 $XML_CREDITOR .=
' </Cdtr>'.$CrLf;
2052 $XML_CREDITOR .=
' <CdtrAcct>'.$CrLf;
2053 $XML_CREDITOR .=
' <Id>'.$CrLf;
2054 $XML_CREDITOR .=
' <IBAN>'.preg_replace(
'/\s/',
'', $row_iban).
'</IBAN>'.$CrLf;
2055 $XML_CREDITOR .=
' </Id>'.$CrLf;
2056 $XML_CREDITOR .=
' </CdtrAcct>'.$CrLf;
2057 $XML_CREDITOR .=
' <RmtInf>'.$CrLf;
2059 $XML_CREDITOR .=
' <Ustrd>'.(($conf->global->PRELEVEMENT_USTRD !=
"") ? $conf->global->PRELEVEMENT_USTRD :
dol_trunc($row_ref, 135,
'right',
'UTF-8', 1)).
'</Ustrd>'.$CrLf;
2060 $XML_CREDITOR .=
' </RmtInf>'.$CrLf;
2061 $XML_CREDITOR .=
' </CdtTrfTxInf>'.$CrLf;
2062 return $XML_CREDITOR;
2078 fputs($this->file,
"03");
2079 fputs($this->file,
"08");
2081 fputs($this->file,
" ");
2083 fputs($this->file, $this->emetteur_ics);
2087 fputs($this->file,
" ");
2088 fputs($this->file,
dol_print_date($this->date_echeance,
"%d%m",
'gmt'));
2089 fputs($this->file, substr(
dol_print_date($this->date_echeance,
"%y",
'gmt'), 1));
2093 fputs($this->file, substr($this->raison_sociale.
" ", 0, 24));
2097 fputs($this->file, substr($this->reference_remise.
" ", 0, 7));
2101 fputs($this->file, substr(
" ", 0, 17));
2105 fputs($this->file, substr(
" ", 0, 2));
2106 fputs($this->file,
"E");
2107 fputs($this->file, substr(
" ", 0, 5));
2111 fputs($this->file, $this->emetteur_code_guichet);
2115 fputs($this->file, substr(
"000000000000000".$this->emetteur_numero_compte, -11));
2119 fputs($this->file, substr(
" ", 0, 16));
2123 fputs($this->file, substr(
" ", 0, 31));
2127 fputs($this->file, $this->emetteur_code_banque);
2131 fputs($this->file, substr(
" ", 0, 5));
2133 fputs($this->file,
"\n");
2152 public function EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf =
'\n', $format =
'FRST', $type =
'direct-debit', $fk_bank_account = 0)
2164 if (empty($fk_bank_account)) {
2165 $fk_bank_account = ($type ==
'bank-transfer' ? $conf->global->PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT : $conf->global->PRELEVEMENT_ID_BANKACCOUNT);
2170 if ($account->fetch($fk_bank_account) > 0) {
2171 $this->emetteur_code_banque = $account->code_banque;
2172 $this->emetteur_code_guichet = $account->code_guichet;
2173 $this->emetteur_numero_compte = $account->number;
2174 $this->emetteur_number_key = $account->cle_rib;
2175 $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
2176 $this->emetteur_iban = $account->iban;
2177 $this->emetteur_bic = $account->bic;
2179 $this->emetteur_ics = ($type ==
'bank-transfer' ? $account->ics_transfer : $account->ics);
2181 $this->raison_sociale = $account->proprio;
2185 $sql =
"SELECT rowid, ref";
2186 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_bons as pb";
2187 $sql .=
" WHERE pb.rowid = ".((int) $this->
id);
2189 $resql = $this->
db->query(
$sql);
2191 $obj = $this->
db->fetch_object($resql);
2193 $country = explode(
':', $configuration->global->MAIN_INFO_SOCIETE_COUNTRY);
2194 $IdBon = sprintf(
"%05d", $obj->rowid);
2195 $RefBon = $obj->ref;
2197 if ($type !=
'bank-transfer') {
2199 $XML_SEPA_INFO =
'';
2200 $XML_SEPA_INFO .=
' <PmtInf>'.$CrLf;
2201 $XML_SEPA_INFO .=
' <PmtInfId>'.(
'DD/'.$dateTime_YMD.
'/ID'.$IdBon.
'-'.$RefBon).
'</PmtInfId>'.$CrLf;
2202 $XML_SEPA_INFO .=
' <PmtMtd>DD</PmtMtd>'.$CrLf;
2203 $XML_SEPA_INFO .=
' <NbOfTxs>'.$nombre.
'</NbOfTxs>'.$CrLf;
2204 $XML_SEPA_INFO .=
' <CtrlSum>'.$total.
'</CtrlSum>'.$CrLf;
2205 $XML_SEPA_INFO .=
' <PmtTpInf>'.$CrLf;
2206 $XML_SEPA_INFO .=
' <SvcLvl>'.$CrLf;
2207 $XML_SEPA_INFO .=
' <Cd>SEPA</Cd>'.$CrLf;
2208 $XML_SEPA_INFO .=
' </SvcLvl>'.$CrLf;
2209 $XML_SEPA_INFO .=
' <LclInstrm>'.$CrLf;
2210 $XML_SEPA_INFO .=
' <Cd>CORE</Cd>'.$CrLf;
2211 $XML_SEPA_INFO .=
' </LclInstrm>'.$CrLf;
2212 $XML_SEPA_INFO .=
' <SeqTp>'.$format.
'</SeqTp>'.$CrLf;
2213 $XML_SEPA_INFO .=
' </PmtTpInf>'.$CrLf;
2214 $XML_SEPA_INFO .=
' <ReqdColltnDt>'.$dateTime_ETAD.
'</ReqdColltnDt>'.$CrLf;
2215 $XML_SEPA_INFO .=
' <Cdtr>'.$CrLf;
2217 $XML_SEPA_INFO .=
' <PstlAdr>'.$CrLf;
2218 $XML_SEPA_INFO .=
' <Ctry>'.$country[1].
'</Ctry>'.$CrLf;
2219 $addressline1 = strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(CHR(13) =>
", ", CHR(10) =>
""));
2220 $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) =>
""));
2221 if ($addressline1) {
2224 if ($addressline2) {
2227 $XML_SEPA_INFO .=
' </PstlAdr>'.$CrLf;
2228 $XML_SEPA_INFO .=
' </Cdtr>'.$CrLf;
2229 $XML_SEPA_INFO .=
' <CdtrAcct>'.$CrLf;
2230 $XML_SEPA_INFO .=
' <Id>'.$CrLf;
2231 $XML_SEPA_INFO .=
' <IBAN>'.preg_replace(
'/\s/',
'', $this->emetteur_iban).
'</IBAN>'.$CrLf;
2232 $XML_SEPA_INFO .=
' </Id>'.$CrLf;
2233 $XML_SEPA_INFO .=
' </CdtrAcct>'.$CrLf;
2234 $XML_SEPA_INFO .=
' <CdtrAgt>'.$CrLf;
2235 $XML_SEPA_INFO .=
' <FinInstnId>'.$CrLf;
2236 $XML_SEPA_INFO .=
' <BIC>'.$this->emetteur_bic.
'</BIC>'.$CrLf;
2237 $XML_SEPA_INFO .=
' </FinInstnId>'.$CrLf;
2238 $XML_SEPA_INFO .=
' </CdtrAgt>'.$CrLf;
2247 $XML_SEPA_INFO .=
' <ChrgBr>SLEV</ChrgBr>'.$CrLf;
2248 $XML_SEPA_INFO .=
' <CdtrSchmeId>'.$CrLf;
2249 $XML_SEPA_INFO .=
' <Id>'.$CrLf;
2250 $XML_SEPA_INFO .=
' <PrvtId>'.$CrLf;
2251 $XML_SEPA_INFO .=
' <Othr>'.$CrLf;
2252 $XML_SEPA_INFO .=
' <Id>'.$this->emetteur_ics.
'</Id>'.$CrLf;
2253 $XML_SEPA_INFO .=
' <SchmeNm>'.$CrLf;
2254 $XML_SEPA_INFO .=
' <Prtry>SEPA</Prtry>'.$CrLf;
2255 $XML_SEPA_INFO .=
' </SchmeNm>'.$CrLf;
2256 $XML_SEPA_INFO .=
' </Othr>'.$CrLf;
2257 $XML_SEPA_INFO .=
' </PrvtId>'.$CrLf;
2258 $XML_SEPA_INFO .=
' </Id>'.$CrLf;
2259 $XML_SEPA_INFO .=
' </CdtrSchmeId>'.$CrLf;
2262 $XML_SEPA_INFO =
'';
2263 $XML_SEPA_INFO .=
' <PmtInf>'.$CrLf;
2264 $XML_SEPA_INFO .=
' <PmtInfId>'.(
'TRF/'.$dateTime_YMD.
'/ID'.$IdBon.
'-'.$RefBon).
'</PmtInfId>'.$CrLf;
2265 $XML_SEPA_INFO .=
' <PmtMtd>TRF</PmtMtd>'.$CrLf;
2267 $XML_SEPA_INFO .=
' <NbOfTxs>'.$nombre.
'</NbOfTxs>'.$CrLf;
2268 $XML_SEPA_INFO .=
' <CtrlSum>'.$total.
'</CtrlSum>'.$CrLf;
2269 if (!empty($this->sepa_xml_pti_in_ctti) && !empty($format)) {
2270 $XML_SEPA_INFO .=
' <PmtTpInf>' . $CrLf;
2271 $XML_SEPA_INFO .=
' <SvcLvl>' . $CrLf;
2272 $XML_SEPA_INFO .=
' <Cd>SEPA</Cd>' . $CrLf;
2273 $XML_SEPA_INFO .=
' </SvcLvl>' . $CrLf;
2274 $XML_SEPA_INFO .=
' <LclInstrm>' . $CrLf;
2275 $XML_SEPA_INFO .=
' <Cd>CORE</Cd>' . $CrLf;
2276 $XML_SEPA_INFO .=
' </LclInstrm>' . $CrLf;
2277 $XML_SEPA_INFO .=
' <SeqTp>' . $format .
'</SeqTp>' . $CrLf;
2278 $XML_SEPA_INFO .=
' </PmtTpInf>' . $CrLf;
2280 $XML_SEPA_INFO .=
' <ReqdExctnDt>'.dol_print_date($dateTime_ETAD,
'dayrfc').
'</ReqdExctnDt>'.$CrLf;
2281 $XML_SEPA_INFO .=
' <Dbtr>'.$CrLf;
2283 $XML_SEPA_INFO .=
' <PstlAdr>'.$CrLf;
2284 $XML_SEPA_INFO .=
' <Ctry>'.$country[1].
'</Ctry>'.$CrLf;
2285 $addressline1 = strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(CHR(13) =>
", ", CHR(10) =>
""));
2286 $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) =>
""));
2287 if ($addressline1) {
2290 if ($addressline2) {
2293 $XML_SEPA_INFO .=
' </PstlAdr>'.$CrLf;
2294 $XML_SEPA_INFO .=
' </Dbtr>'.$CrLf;
2295 $XML_SEPA_INFO .=
' <DbtrAcct>'.$CrLf;
2296 $XML_SEPA_INFO .=
' <Id>'.$CrLf;
2297 $XML_SEPA_INFO .=
' <IBAN>'.preg_replace(
'/\s/',
'', $this->emetteur_iban).
'</IBAN>'.$CrLf;
2298 $XML_SEPA_INFO .=
' </Id>'.$CrLf;
2299 $XML_SEPA_INFO .=
' </DbtrAcct>'.$CrLf;
2300 $XML_SEPA_INFO .=
' <DbtrAgt>'.$CrLf;
2301 $XML_SEPA_INFO .=
' <FinInstnId>'.$CrLf;
2302 $XML_SEPA_INFO .=
' <BIC>'.$this->emetteur_bic.
'</BIC>'.$CrLf;
2303 $XML_SEPA_INFO .=
' </FinInstnId>'.$CrLf;
2304 $XML_SEPA_INFO .=
' </DbtrAgt>'.$CrLf;
2313 $XML_SEPA_INFO .=
' <ChrgBr>SLEV</ChrgBr>'.$CrLf;
2328 fputs($this->file,
'INCORRECT EMETTEUR '.$this->raison_sociale.$CrLf);
2329 $XML_SEPA_INFO =
'';
2331 return $XML_SEPA_INFO;
2344 fputs($this->file,
"08");
2345 fputs($this->file,
"08");
2347 fputs($this->file,
" ");
2349 fputs($this->file, $this->emetteur_ics);
2353 fputs($this->file, substr(
" ", 0, 12));
2358 fputs($this->file, substr(
" ", 0, 24));
2362 fputs($this->file, substr(
" ", 0, 24));
2366 fputs($this->file, substr(
" ", 0, 8));
2370 fputs($this->file, substr(
" ", 0, 5));
2374 fputs($this->file, substr(
" ", 0, 11));
2378 $montant = ($total * 100);
2380 fputs($this->file, substr(
"000000000000000".$montant, -16));
2384 fputs($this->file, substr(
" ", 0, 31));
2388 fputs($this->file, substr(
" ", 0, 5));
2392 fputs($this->file, substr(
" ", 0, 5));
2394 fputs($this->file,
"\n");
2405 return $this->
LibStatut($this->statut, $mode);
2419 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
2422 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'StatusWaiting');
2423 $this->labelStatus[self::STATUS_TRANSFERED] = $langs->transnoentitiesnoconv(
'StatusTrans');
2424 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'StatusWaiting');
2425 $this->labelStatusShort[self::STATUS_TRANSFERED] = $langs->transnoentitiesnoconv(
'StatusTrans');
2426 if ($this->
type ==
'bank-transfer') {
2427 $this->labelStatus[self::STATUS_DEBITED] = $langs->transnoentitiesnoconv(
'StatusDebited');
2428 $this->labelStatusShort[self::STATUS_DEBITED] = $langs->transnoentitiesnoconv(
'StatusDebited');
2430 $this->labelStatus[self::STATUS_CREDITED] = $langs->transnoentitiesnoconv(
'StatusCredited');
2431 $this->labelStatusShort[self::STATUS_CREDITED] = $langs->transnoentitiesnoconv(
'StatusCredited');
2435 $statusType =
'status1';
2436 if ($status == self::STATUS_TRANSFERED) {
2437 $statusType =
'status3';
2439 if ($status == self::STATUS_CREDITED || $status == self::STATUS_DEBITED) {
2440 $statusType =
'status6';
2443 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
2457 global $conf, $langs;
2531 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2533 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2534 $return .=
'<div class="info-box info-box-sm">';
2535 $return .=
'<span class="info-box-icon bg-infobox-action">';
2537 $return .=
'</span>';
2538 $return .=
'<div class="info-box-content">';
2539 $return .=
'<span class="info-box-ref">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
2540 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2542 if (property_exists($this,
'date_echeance')) {
2543 $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>';
2545 if (property_exists($this,
'total')) {
2546 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Amount").
'</span> : <span class="amount">'.
price($this->total).
'</span>';
2548 if (method_exists($this,
'LibStatut')) {
2549 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
2551 $return .=
'</div>';
2552 $return .=
'</div>';
2553 $return .=
'</div>';