30require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
36require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/salaries/class/salary.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/salaries/class/paymentsalary.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/user/class/userbankaccount.class.php';
51 public $element =
'widthdraw';
56 public $table_element =
'prelevement_bons';
61 public $picto =
'payment';
63 public $date_echeance;
64 public $raison_sociale;
65 public $reference_remise;
66 public $emetteur_code_guichet;
67 public $emetteur_numero_compte;
68 public $emetteur_code_banque;
69 public $emetteur_number_key;
70 public $sepa_xml_pti_in_ctti;
72 public $emetteur_iban;
81 public $labelStatus = array();
83 public $factures = array();
85 public $methodes_trans = array();
87 public $invoice_in_error = array();
88 public $thirdparty_in_error = array();
100 const STATUS_DRAFT = 0;
101 const STATUS_TRANSFERED = 1;
102 const STATUS_CREDITED = 2;
103 const STATUS_DEBITED = 2;
149 public $fields=array(
150 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>
'1',
'position'=>10,
'notnull'=>1,
'visible'=>0,),
151 'ref' => array(
'type'=>
'varchar(12)',
'label'=>
'Ref',
'enabled'=>
'1',
'position'=>15,
'notnull'=>0,
'visible'=>-1,
'csslist'=>
'tdoverflowmax150',
'showoncombobox'=>
'1',),
152 'datec' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>
'1',
'position'=>25,
'notnull'=>0,
'visible'=>-1,),
153 'amount' => array(
'type'=>
'double(24,8)',
'label'=>
'Amount',
'enabled'=>
'1',
'position'=>30,
'notnull'=>0,
'visible'=>-1,),
154 'statut' => array(
'type'=>
'smallint(6)',
'label'=>
'Statut',
'enabled'=>
'1',
'position'=>500,
'notnull'=>0,
'visible'=>-1,
'arrayofkeyval'=>array(0=>
'Wait', 1=>
'Transfered', 2=>
'Credited')),
155 'credite' => array(
'type'=>
'smallint(6)',
'label'=>
'Credite',
'enabled'=>
'1',
'position'=>40,
'notnull'=>0,
'visible'=>-1,),
156 'note' => array(
'type'=>
'text',
'label'=>
'Note',
'enabled'=>
'1',
'position'=>45,
'notnull'=>0,
'visible'=>-1,),
157 'date_trans' => array(
'type'=>
'datetime',
'label'=>
'Datetrans',
'enabled'=>
'1',
'position'=>50,
'notnull'=>0,
'visible'=>-1,),
158 'method_trans' => array(
'type'=>
'smallint(6)',
'label'=>
'Methodtrans',
'enabled'=>
'1',
'position'=>55,
'notnull'=>0,
'visible'=>-1,),
159 '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',),
160 'date_credit' => array(
'type'=>
'datetime',
'label'=>
'Datecredit',
'enabled'=>
'1',
'position'=>65,
'notnull'=>0,
'visible'=>-1,),
161 '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',),
162 'type' => array(
'type'=>
'varchar(16)',
'label'=>
'Type',
'enabled'=>
'1',
'position'=>75,
'notnull'=>0,
'visible'=>-1,),
163 'fk_bank_account' => array(
'type'=>
'integer',
'label'=>
'Fkbankaccount',
'enabled'=>
'1',
'position'=>80,
'notnull'=>0,
'visible'=>-1,
'css'=>
'maxwidth500 widthcentpercentminusxx',),
173 public $method_trans;
174 public $fk_user_trans;
176 public $fk_user_credit;
178 public $fk_bank_account;
192 $this->filename =
'';
194 $this->date_echeance =
dol_now();
195 $this->raison_sociale =
"";
196 $this->reference_remise =
"";
198 $this->emetteur_code_guichet =
"";
199 $this->emetteur_numero_compte =
"";
200 $this->emetteur_code_banque =
"";
201 $this->emetteur_number_key =
"";
202 $this->sepa_xml_pti_in_ctti =
false;
204 $this->emetteur_iban =
"";
205 $this->emetteur_bic =
"";
206 $this->emetteur_ics =
"";
208 $this->factures = array();
210 $this->methodes_trans = array(0 =>
'Internet', 2 =>
'Email', 3 =>
'Api');
231 public function AddFacture($invoice_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $type =
'debit-order', $sourcetype =
'')
238 $result = $this->
addline($line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype);
243 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"prelevement (";
244 if ($type !=
'bank-transfer') {
245 $sql .=
"fk_facture";
247 if ($sourcetype ==
'salary') {
250 $sql .=
"fk_facture_fourn";
253 $sql .=
",fk_prelevement_lignes";
254 $sql .=
") VALUES (";
255 $sql .= ((int) $invoice_id);
256 $sql .=
", ".((int) $line_id);
259 if ($this->db->query($sql)) {
263 $this->errors[] = get_class($this).
"::AddFacture ".$this->db->lasterror;
264 dol_syslog(get_class($this).
"::AddFacture Error $result");
268 $this->errors[] = get_class($this).
"::AddFacture linedid Empty";
269 dol_syslog(get_class($this).
"::AddFacture Error $result");
273 dol_syslog(get_class($this).
"::AddFacture Error $result");
293 public function addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype =
'')
302 $sql =
"SELECT rowid";
303 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_lignes";
304 $sql .=
" WHERE fk_prelevement_bons = ".((int) $this->
id);
305 if ($sourcetype ==
'salary') {
306 $sql .=
" AND fk_soc = ".((int) $client_id);
308 $sql .=
" AND fk_user = ".((int) $client_id);
310 $sql .=
" AND code_banque = '".$this->db->escape($code_banque).
"'";
311 $sql .=
" AND code_guichet = '".$this->db->escape($code_guichet).
"'";
312 $sql .=
" AND number = '".$this->db->escape($number).
"'";
314 $resql = $this->db->query($sql);
316 $num = $this->db->num_rows($resql);
324 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"prelevement_lignes (";
325 $sql .=
"fk_prelevement_bons";
327 $sql .=
", client_nom";
329 $sql .=
", code_banque";
330 $sql .=
", code_guichet";
333 $sql .= ($sourcetype ==
'salary' ?
", fk_user" :
"");
334 $sql .=
") VALUES (";
336 $sql .=
", ".(($sourcetype !=
'salary') ? ((
int) $client_id) :
"0");
337 $sql .=
", '".$this->db->escape($client_nom).
"'";
338 $sql .=
", ".((float)
price2num($amount));
339 $sql .=
", '".$this->db->escape($code_banque).
"'";
340 $sql .=
", '".$this->db->escape($code_guichet).
"'";
341 $sql .=
", '".$this->db->escape($number).
"'";
342 $sql .=
", '".$this->db->escape($number_key).
"'";
343 $sql .= (($sourcetype ==
'salary') ?
", ". ((
int) $client_id) :
'');
345 if ($this->db->query($sql)) {
346 $line_id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"prelevement_lignes");
349 $this->errors[] = get_class($this).
"::addline Error -2 ".$this->db->lasterror;
350 dol_syslog(get_class($this).
"::addline Error -2");
370 $errors[1027] = $langs->trans(
"DateInvalid");
372 return $errors[abs($error)];
382 public function fetch($rowid, $ref =
'')
384 $sql =
"SELECT p.rowid, p.ref, p.amount, p.note";
385 $sql .=
", p.datec as dc";
386 $sql .=
", p.date_trans as date_trans";
387 $sql .=
", p.method_trans, p.fk_user_trans";
388 $sql .=
", p.date_credit as date_credit";
389 $sql .=
", p.fk_user_credit";
391 $sql .=
", p.fk_bank_account";
392 $sql .=
", p.statut as status";
393 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_bons as p";
394 $sql .=
" WHERE p.entity IN (".getEntity(
'invoice').
")";
396 $sql .=
" AND p.rowid = ".((int) $rowid);
398 $sql .=
" AND p.ref = '".$this->db->escape($ref).
"'";
401 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
402 $result = $this->db->query($sql);
404 if ($this->db->num_rows($result)) {
405 $obj = $this->db->fetch_object($result);
407 $this->
id = $obj->rowid;
408 $this->
ref = $obj->ref;
409 $this->amount = $obj->amount;
410 $this->note = $obj->note;
411 $this->datec = $this->db->jdate($obj->dc);
413 $this->date_trans = $this->db->jdate($obj->date_trans);
414 $this->method_trans = $obj->method_trans;
415 $this->user_trans = $obj->fk_user_trans;
417 $this->date_credit = $this->db->jdate($obj->date_credit);
418 $this->user_credit = $obj->fk_user_credit;
420 $this->
type = $obj->type;
421 $this->fk_bank_account = $obj->fk_bank_account;
423 $this->
status = $obj->status;
424 $this->
statut = $obj->status;
430 dol_syslog(get_class($this).
"::Fetch Erreur aucune ligne retournee");
463 global $conf, $langs;
467 if ($this->fetched == 1) {
468 if ($date < $this->date_trans) {
469 $langs->load(
"errors");
470 $this->error = $langs->trans(
'ErrorDateOfMovementLowerThanDateOfFileTransmission');
471 dol_syslog(
"bon-prelevment::set_infocredit 1027 ".$this->error);
477 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"prelevement_bons";
478 $sql .=
" SET fk_user_credit = ".((int) $user->id);
479 $sql .=
", statut = ".self::STATUS_CREDITED;
480 $sql .=
", date_credit = '".$this->db->idate($date).
"'";
481 $sql .=
" WHERE rowid = ".((int) $this->
id);
482 $sql .=
" AND entity = ".((int) $conf->entity);
483 $sql .=
" AND statut = ".self::STATUS_TRANSFERED;
485 $resql = $this->db->query($sql);
487 $langs->load(
'withdrawals');
488 $subject = $langs->trans(
"InfoCreditSubject", $this->
ref);
489 $message = $langs->trans(
"InfoCreditMessage", $this->
ref,
dol_print_date($date,
'dayhour'));
492 $fk_bank_account = $this->fk_bank_account;
493 if (empty($fk_bank_account)) {
499 $amountsperthirdparty = array();
509 for ($i = 0; $i < $num; $i++) {
510 if ($this->
type ==
'bank-transfer') {
511 if ($type ==
'salary') {
512 $fac =
new Salary($this->db);
520 $result = $fac->fetch($facs[$i][0]);
522 $amounts[$fac->id] = $facs[$i][1];
523 if ($this->
type ==
'bank-transfer') {
524 if ($type ==
'salary') {
525 $amountsperthirdparty[$fac->fk_user][$fac->id] = $facs[$i][1];
527 $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
530 $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
533 $totalpaid = $fac->getSommePaiement();
534 $totalcreditnotes = 0;
535 if (method_exists($fac,
'getSumCreditNotesUsed')) {
536 $totalcreditnotes = $fac->getSumCreditNotesUsed();
539 if (method_exists($fac,
'getSumDepositsUsed')) {
540 $totaldeposits = $fac->getSumDepositsUsed();
542 $alreadypayed = $totalpaid + $totalcreditnotes + $totaldeposits;
546 $amountofdocument = $fac->total_ttc;
547 if ($type ==
'salary') {
548 $amountofdocument = $fac->amount;
550 if (
price2num($alreadypayed + $facs[$i][1],
'MT') ==
price2num($amountofdocument,
'MT')) {
551 $result = $fac->setPaid($user);
553 $this->error = $fac->error;
554 $this->errors = $fac->errors;
560 foreach ($amountsperthirdparty as $thirdpartyid => $cursoramounts) {
561 if ($this->
type ==
'bank-transfer') {
562 if ($type ==
'salary') {
568 $paiement =
new Paiement($this->db);
570 $paiement->datepaye = $date;
571 $paiement->amounts = $cursoramounts;
573 if ($this->
type ==
'bank-transfer') {
574 if ($type ==
'salary') {
575 $paiement->datep = $date;
577 $paiement->paiementid = 2;
578 $paiement->fk_typepayment = 2;
579 $paiement->paiementcode =
'VIR';
581 $paiement->paiementid = 2;
582 $paiement->paiementcode =
'VIR';
585 $paiement->paiementid = 3;
586 $paiement->paiementcode =
'PRE';
589 $paiement->num_payment = $this->ref;
590 $paiement->id_prelevement = $this->id;
592 $result = $paiement->create($user);
596 $this->error = $paiement->error;
597 $this->errors = $paiement->errors;
598 dol_syslog(get_class($this).
"::set_infocredit AddPayment Error ".$this->error);
600 if ($this->
type ==
'bank-transfer') {
601 if ($type ==
'salary') {
602 $modeforaddpayment =
'payment_salary';
603 $labelforaddpayment =
'(SalaryPayment)';
604 $addbankurl =
'credit-transfer';
606 $modeforaddpayment =
'payment_supplier';
607 $labelforaddpayment =
'(SupplierInvoicePayment)';
608 $addbankurl =
'credit-transfer';
611 $modeforaddpayment =
'payment';
612 $labelforaddpayment =
'(CustomerInvoicePayment)';
613 $addbankurl =
'direct-debit';
616 $result = $paiement->addPaymentToBank($user, $modeforaddpayment, $labelforaddpayment, $fk_bank_account,
'',
'', 0,
'', $addbankurl);
620 $this->error = $paiement->error;
621 $this->errors = $paiement->errors;
622 dol_syslog(get_class($this).
"::set_infocredit AddPaymentToBank Error ".$this->error);
630 $sql =
" UPDATE ".MAIN_DB_PREFIX.
"prelevement_lignes";
631 $sql .=
" SET statut = 2";
632 $sql .=
" WHERE fk_prelevement_bons = ".((int) $this->
id);
634 if (!$this->db->query($sql)) {
635 dol_syslog(get_class($this).
"::set_infocredit Update lines Error");
640 $this->error = $this->db->lasterror();
641 dol_syslog(get_class($this).
"::set_infocredit Update Bons Error");
647 $this->date_credit = $date;
648 $this->
statut = self::STATUS_CREDITED;
649 $this->
status = self::STATUS_CREDITED;
654 $this->db->rollback();
674 global $conf, $langs;
678 dol_syslog(get_class($this).
"::set_infotrans Start", LOG_INFO);
680 if ($this->db->begin()) {
681 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_bons ";
682 $sql .=
" SET fk_user_trans = ".$user->id;
683 $sql .=
" , date_trans = '".$this->db->idate($date).
"'";
684 $sql .=
" , method_trans = ".((int) $method);
685 $sql .=
" , statut = ".self::STATUS_TRANSFERED;
686 $sql .=
" WHERE rowid = ".((int) $this->
id);
687 $sql .=
" AND entity = ".((int) $conf->entity);
688 $sql .=
" AND statut = ".self::STATUS_DRAFT;
690 if ($this->db->query($sql)) {
691 $this->method_trans = $method;
692 $langs->load(
'withdrawals');
693 $subject = $langs->trans(
"InfoTransSubject", $this->
ref);
694 $message = $langs->trans(
"InfoTransMessage", $this->
ref,
dolGetFirstLastname($user->firstname, $user->lastname));
695 $message .= $langs->trans(
"InfoTransData",
price($this->amount), $this->methodes_trans[$this->method_trans],
dol_print_date($date,
'day'));
703 $this->date_trans = $date;
704 $this->
statut = self::STATUS_TRANSFERED;
705 $this->
status = self::STATUS_TRANSFERED;
706 $this->user_trans = $user->id;
712 $this->db->rollback();
713 dol_syslog(get_class($this).
"::set_infotrans ROLLBACK", LOG_ERR);
718 dol_syslog(get_class($this).
"::set_infotrans Ouverture transaction SQL impossible", LOG_CRIT);
736 dol_syslog(get_class($this).
"::getListInvoices");
740 if ($this->
type ==
'bank-transfer') {
741 if ($type ==
'salary') {
742 $sql .=
" p.fk_salary";
744 $sql .=
" p.fk_facture_fourn";
747 $sql .=
" p.fk_facture";
750 $sql .=
", SUM(pl.amount)";
752 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_bons as pb,";
753 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement_lignes as pl,";
754 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement as p";
755 $sql .=
" WHERE p.fk_prelevement_lignes = pl.rowid";
756 $sql .=
" AND pl.fk_prelevement_bons = pb.rowid";
757 $sql .=
" AND pb.rowid = ".((int) $this->
id);
758 $sql .=
" AND pb.entity = ".((int) $conf->entity);
760 if ($this->
type ==
'bank-transfer') {
761 if ($type ==
'salary') {
762 $sql .=
" GROUP BY p.fk_salary";
764 $sql .=
" GROUP BY p.fk_facture_fourn";
767 $sql .=
" GROUP BY p.fk_facture";
771 $resql = $this->db->query($sql);
773 $num = $this->db->num_rows($resql);
778 $row = $this->db->fetch_row($resql);
790 $this->db->free($resql);
792 $this->error = $this->db->lasterror();
809 $sql =
"SELECT sum(pd.amount) as nb";
810 if ($type !==
'salary') {
811 if ($mode !=
'bank-transfer') {
812 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f,";
814 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f,";
817 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s,";
819 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement_demande as pd";
820 $sql .= ($type !==
'salary' ?
" WHERE f.entity IN (".getEntity(
'invoice').
")" :
" WHERE s.entity IN (".getEntity(
'salary').
")");
822 $sql .= ($type !==
'salary' ?
" AND f.fk_statut = ".Facture::STATUS_VALIDATED :
" AND s.paye = ".Salary::STATUS_UNPAID);
824 if ($type !==
'salary') {
825 if ($mode !=
'bank-transfer') {
826 $sql .=
" AND f.rowid = pd.fk_facture";
828 $sql .=
" AND f.rowid = pd.fk_facture_fourn";
831 $sql .=
" AND s.rowid = pd.fk_salary";
833 $sql .= ($type !==
'salary' ?
" AND f.paye = 0" :
"");
834 $sql .=
" AND pd.traite = 0";
835 $sql .=
" AND pd.ext_payment_id IS NULL";
836 $sql .= ($type !==
'salary' ?
" AND f.total_ttc > 0" :
"");
838 $resql = $this->db->query($sql);
840 $obj = $this->db->fetch_object($resql);
842 $this->db->free($resql);
847 dol_syslog(get_class($this).
"::SommeAPrelever Erreur -1");
863 if ($type ===
'salary') {
881 if ($forsalary == 1) {
882 $sql =
"SELECT count(s.rowid) as nb";
883 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as s";
885 $sql =
"SELECT count(f.rowid) as nb";
887 if ($type ==
'bank-transfer') {
888 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
890 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
893 $sql .=
", ".MAIN_DB_PREFIX.
"prelevement_demande as pd";
894 if ($forsalary == 1) {
895 $sql .=
" WHERE s.entity IN (".getEntity(
'invoice').
")";
897 $sql .=
" AND s.paye = 0";
900 $sql .=
" WHERE f.entity IN (".getEntity(
'invoice').
")";
902 $sql .=
" AND f.fk_statut = ".Facture::STATUS_VALIDATED;
905 if ($forsalary == 1) {
906 $sql .=
" AND s.rowid = pd.fk_salary";
908 if ($type ==
'bank-transfer') {
909 $sql .=
" AND f.rowid = pd.fk_facture_fourn";
911 $sql .=
" AND f.rowid = pd.fk_facture";
914 $sql .=
" AND pd.traite = 0";
915 $sql .=
" AND pd.ext_payment_id IS NULL";
916 if (!$forsalary == 1) {
917 $sql .=
" AND f.total_ttc > 0";
919 $sql .=
" AND s.paye = 0";
922 dol_syslog(get_class($this).
"::NbFactureAPrelever");
923 $resql = $this->db->query($sql);
926 $obj = $this->db->fetch_object($resql);
927 $this->db->free($resql);
931 $this->error = get_class($this).
"::NbFactureAPrelever Erreur -1 sql=".$this->db->error();
958 public function create($banque = 0, $agence = 0, $mode =
'real', $format =
'ALL', $executiondate =
'', $notrigger = 0, $type =
'direct-debit', $did = 0, $fk_bank_account = 0, $sourcetype =
'invoice')
961 global $conf, $langs, $user;
963 dol_syslog(__METHOD__.
" Bank=".$banque.
" Office=".$agence.
" mode=".$mode.
" format=".$format, LOG_DEBUG);
965 require_once DOL_DOCUMENT_ROOT.
"/compta/facture/class/facture.class.php";
966 require_once DOL_DOCUMENT_ROOT.
"/societe/class/societe.class.php";
969 if ($type !=
'bank-transfer') {
970 if (empty($format)) {
971 $this->error =
'ErrorBadParametersForDirectDebitFileCreate';
977 if (empty($fk_bank_account)) {
978 $fk_bank_account = ($type ==
'bank-transfer' ?
getDolGlobalInt(
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') :
getDolGlobalInt(
'PRELEVEMENT_ID_BANKACCOUNT'));
983 $datetimeprev =
dol_now(
'gmt');
985 if (!empty($executiondate)) {
986 $datetimeprev = $executiondate;
992 $this->invoice_in_error = array();
993 $this->thirdparty_in_error = array();
997 $factures_prev = array();
998 $factures_result = array();
999 $factures_prev_id = array();
1000 $factures_errors = array();
1002 dol_syslog(__METHOD__.
" Read invoices for did=".((
int) $did), LOG_DEBUG);
1004 $sql =
"SELECT f.rowid, pd.rowid as pfdrowid";
1005 if ($sourcetype !=
'salary') {
1006 $sql .=
", f.fk_soc";
1008 $sql .=
", f.fk_user";
1010 $sql .=
", pd.code_banque, pd.code_guichet, pd.number, pd.cle_rib";
1011 $sql .=
", pd.amount";
1012 if ($sourcetype !=
'salary') {
1013 $sql .=
", s.nom as name";
1014 $sql .=
", f.ref, sr.bic, sr.iban_prefix, sr.frstrecur";
1016 $sql .=
", CONCAT(s.firstname,' ',s.lastname) as name";
1017 $sql .=
", f.ref, sr.bic, sr.iban_prefix, 'FRST' as frstrecur";
1019 if ($sourcetype !=
'salary') {
1020 if ($type !=
'bank-transfer') {
1021 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
1022 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"prelevement_demande as pd ON f.rowid = pd.fk_facture";
1024 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
1025 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"prelevement_demande as pd ON f.rowid = pd.fk_facture_fourn";
1027 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = f.fk_soc";
1028 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_rib as sr ON s.rowid = sr.fk_soc AND sr.default_rib = 1";
1030 $sql .=
" FROM ".MAIN_DB_PREFIX.
"salary as f";
1031 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"prelevement_demande as pd ON f.rowid = pd.fk_salary";
1032 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as s ON s.rowid = f.fk_user";
1033 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user_rib as sr ON s.rowid = sr.fk_user";
1035 if ($sourcetype !=
'salary') {
1036 if ($type !=
'bank-transfer') {
1037 $sql .=
" WHERE f.entity IN (".getEntity(
'invoice').
')';
1039 $sql .=
" WHERE f.entity IN (".getEntity(
'supplier_invoice').
')';
1042 $sql .=
" WHERE f.entity IN (".getEntity(
'salary').
')';
1044 if ($sourcetype !=
'salary') {
1045 $sql .=
" AND f.fk_statut = 1";
1046 $sql .=
" AND f.paye = 0";
1047 $sql .=
" AND f.total_ttc > 0";
1050 $sql .=
" AND f.paye = 0";
1051 $sql .=
" AND f.amount > 0";
1053 $sql .=
" AND pd.traite = 0";
1054 $sql .=
" AND pd.ext_payment_id IS NULL";
1055 if ($sourcetype !=
'salary') {
1056 $sql .=
" AND sr.type = 'ban'";
1059 $sql .=
" AND pd.rowid = ".((int) $did);
1062 $resql = $this->db->query($sql);
1064 $num = $this->db->num_rows($resql);
1068 $row = $this->db->fetch_row($resql);
1069 $factures[$i] = $row;
1073 dol_syslog(__METHOD__.
" Read invoices/salary error Found a null amount", LOG_ERR);
1074 $this->invoice_in_error[$row[0]] =
"Error for invoice or salary id ".$row[0].
", found a null amount";
1080 $this->db->free($resql);
1081 dol_syslog(__METHOD__.
" Read invoices/salary, ".$i.
" invoices/salary to withdraw", LOG_DEBUG);
1084 $this->error = $this->db->lasterror();
1085 dol_syslog(__METHOD__.
" Read invoices/salary error ".$this->db->lasterror(), LOG_ERR);
1092 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1093 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
1094 require_once DOL_DOCUMENT_ROOT.
'/societe/class/companybankaccount.class.php';
1095 require_once DOL_DOCUMENT_ROOT.
'/core/lib/bank.lib.php';
1097 $tmpsoc =
new Societe($this->db);
1098 $tmpuser =
new User($this->db);
1102 dol_syslog(__METHOD__.
" Check BAN", LOG_DEBUG);
1104 if (count($factures) > 0) {
1105 foreach ($factures as $key => $fac) {
1117 if ($fac[8] !=
null) {
1121 if ($type !=
'bank-transfer') {
1122 if ($format ==
'FRST' && $fac[12] !=
'FRST') {
1125 if ($format ==
'RCUR' && $fac[12] !=
'RCUR') {
1136 $factures_prev[$i] = $fac;
1138 $factures_prev_id[$i] = $fac[0];
1142 if ($type !=
'bank-transfer') {
1143 $tmpsoc->id = $fac[2];
1144 $tmpsoc->name = $fac[8];
1145 $invoice_url =
"<a href='".DOL_URL_ROOT.
'/compta/facture/card.php?facid='.$fac[0].
"'>".$fac[9].
"</a>";
1146 $this->invoice_in_error[$fac[0]] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1147 $this->thirdparty_in_error[$tmpsoc->id] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1150 if ($type ==
'bank-transfer' && $sourcetype !=
'salary') {
1151 $tmpsoc->id = $fac[2];
1152 $tmpsoc->name = $fac[8];
1153 $invoice_url =
"<a href='".DOL_URL_ROOT.
'/fourn/facture/card.php?facid='.$fac[0].
"'>".$fac[9].
"</a>";
1154 $this->invoice_in_error[$fac[0]] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1155 $this->thirdparty_in_error[$tmpsoc->id] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1158 if ($type ==
'bank-transfer' && $sourcetype ==
'salary') {
1159 $tmpuser->id = $fac[2];
1160 $tmpuser->firstname = $fac[8];
1161 $salary_url =
"<a href='".DOL_URL_ROOT.
'/salaries/card.php?id='.$fac[0].
"'>".$fac[0].
"</a>";
1162 $this->invoice_in_error[$fac[0]] =
"Error on default bank number IBAN/BIC for salary " . $salary_url .
" for employee " . $tmpuser->getNomUrl(0);
1163 $this->thirdparty_in_error[$tmpuser->id] =
"Error on default bank number IBAN/BIC for salary " . $salary_url .
" for employee " . $tmpuser->getNomUrl(0);
1166 dol_syslog(__METHOD__ .
" Check BAN Error on default bank number IBAN/BIC reported by verif(): " . join(
', ', $fac), LOG_WARNING);
1169 dol_syslog(__METHOD__ .
" Check BAN Failed to read company", LOG_WARNING);
1178 dol_syslog(__METHOD__.
" Check BAN No invoice to process", LOG_WARNING);
1185 $out = count($factures_prev).
" invoices will be included.";
1198 if (count($factures_prev) > 0) {
1199 if ($mode ==
'real') {
1202 print $langs->trans(
"ModeWarning");
1219 $ref = substr($year, -2).$month;
1222 $sql =
"SELECT substring(ref from char_length(ref) - 1)";
1223 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_bons";
1224 $sql .=
" WHERE ref LIKE '_".$this->db->escape($ref).
"%'";
1225 $sql .=
" AND entity = ".((int) $conf->entity);
1226 $sql .=
" ORDER BY ref DESC LIMIT 1";
1228 dol_syslog(get_class($this).
" get next free number", LOG_DEBUG);
1229 $resql = $this->db->query($sql);
1232 $row = $this->db->fetch_row($resql);
1235 $ref =
"T".$ref.sprintf(
"%02d", (intval($row[0]) + 1));
1241 if ($type !=
'bank-transfer') {
1242 $dir = $conf->prelevement->dir_output.
'/receipts';
1244 $dir = $conf->paymentbybanktransfer->dir_output.
'/receipts';
1246 if (!is_dir($dir)) {
1250 if (isModEnabled(
'multicompany')) {
1251 $labelentity = $conf->entity;
1252 $this->filename = $dir.
'/'.$ref.
'-'.$labelentity.
'.xml';
1254 $this->filename = $dir.
'/'.$ref.
'.xml';
1258 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"prelevement_bons (";
1259 $sql .=
"ref, entity, datec, type, fk_bank_account";
1260 $sql .=
") VALUES (";
1261 $sql .=
"'".$this->db->escape($ref).
"'";
1262 $sql .=
", ".((int) $conf->entity);
1263 $sql .=
", '".$this->db->idate($now).
"'";
1264 $sql .=
", '".($type ==
'bank-transfer' ?
'bank-transfer' :
'debit-order').
"'";
1265 $sql .=
", ".((int) $fk_bank_account);
1268 $resql = $this->db->query($sql);
1272 $prev_id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"prelevement_bons");
1273 $this->
id = $prev_id;
1277 dol_syslog(__METHOD__.
" Create withdraw receipt ".$this->db->lasterror(), LOG_ERR);
1281 dol_syslog(__METHOD__.
" Get last withdraw receipt ".$this->db->lasterror(), LOG_ERR);
1286 dol_syslog(__METHOD__.
" Now loop on each document to insert them in llx_prelevement_demande");
1289 if (count($factures_prev) > 0) {
1290 foreach ($factures_prev as $fac) {
1308 $ri = $this->
AddFacture($fac[0], $fac[2], $fac[8], $fac[7], $fac[3], $fac[4], $fac[5], $fac[6], $type, $sourcetype);
1315 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_demande";
1316 $sql .=
" SET traite = 1";
1317 $sql .=
", date_traite = '".$this->db->idate($now).
"'";
1318 $sql .=
", fk_prelevement_bons = ".((int) $this->
id);
1319 $sql .=
" WHERE rowid = ".((int) $fac[1]);
1321 $resql = $this->db->query($sql);
1324 $this->errors[] = $this->db->lasterror();
1325 dol_syslog(__METHOD__.
" Update Error=".$this->db->lasterror(), LOG_ERR);
1336 dol_syslog(__METHOD__.
" Init direct debit or credit transfer file for ".count($factures_prev).
" invoices", LOG_DEBUG);
1338 if (count($factures_prev) > 0) {
1339 $this->date_echeance = $datetimeprev;
1340 $this->reference_remise = $ref;
1342 $account =
new Account($this->db);
1343 if ($account->fetch($fk_bank_account) > 0) {
1344 $this->emetteur_code_banque = $account->code_banque;
1345 $this->emetteur_code_guichet = $account->code_guichet;
1346 $this->emetteur_numero_compte = $account->number;
1347 $this->emetteur_number_key = $account->cle_rib;
1348 $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
1349 $this->emetteur_iban = $account->iban;
1350 $this->emetteur_bic = $account->bic;
1352 $this->emetteur_ics = (($type ==
'bank-transfer' &&
getDolGlobalString(
"SEPA_USE_IDS")) ? $account->ics_transfer : $account->ics);
1354 $this->raison_sociale = $account->proprio;
1356 $this->factures = $factures_prev_id;
1357 $this->context[
'factures_prev'] = $factures_prev;
1360 if ($sourcetype ==
'salary') {
1361 $userid = $this->context[
'factures_prev'][0][2];
1363 $result = $this->
generate($format, $executiondate, $type, $fk_bank_account, $userid);
1370 dol_syslog(__METHOD__.
" Bank order file has been generated under filename ".$this->filename, LOG_DEBUG);
1378 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_bons";
1379 $sql .=
" SET amount = ".price2num($this->total);
1380 $sql .=
" WHERE rowid = ".((int) $this->
id);
1381 $sql .=
" AND entity = ".((int) $conf->entity);
1382 $resql = $this->db->query($sql);
1386 dol_syslog(__METHOD__.
" Error update total: ".$this->db->error(), LOG_ERR);
1390 if (!$error && !$notrigger) {
1391 $triggername =
'DIRECT_DEBIT_ORDER_CREATE';
1392 if ($type !=
'bank-transfer') {
1393 $triggername =
'CREDIT_TRANSFER_ORDER_CREATE';
1405 $this->db->commit();
1406 return count($factures_prev);
1408 $this->db->rollback();
1424 public function delete($user =
null, $notrigger = 0)
1429 $resql1 = $resql2 = $resql3 = $resql4 = 0;
1432 $triggername =
'DIRECT_DEBIT_ORDER_DELETE';
1433 if ($this->
type ==
'bank-transfer') {
1434 $triggername =
'PAYMENTBYBANKTRANFER_DELETE';
1445 $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).
")";
1446 $resql1 = $this->db->query($sql);
1453 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"prelevement_lignes WHERE fk_prelevement_bons = ".((int) $this->
id);
1454 $resql2 = $this->db->query($sql);
1461 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"prelevement_bons WHERE rowid = ".((int) $this->
id);
1462 $resql3 = $this->db->query($sql);
1469 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"prelevement_demande SET fk_prelevement_bons = NULL, traite = 0 WHERE fk_prelevement_bons = ".((int) $this->
id);
1470 $resql4 = $this->db->query($sql);
1476 if ($resql1 && $resql2 && $resql3 && $resql4 && !$error) {
1477 $this->db->commit();
1480 $this->db->rollback();
1496 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1498 global $conf, $langs, $hookmanager;
1500 if (!empty($conf->dol_no_mouse_hover)) {
1506 $labeltoshow =
'PaymentByDirectDebit';
1507 if (!empty($this->
type) && $this->
type ==
'bank-transfer') {
1508 $labeltoshow =
'PaymentByBankTransfer';
1511 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans($labeltoshow).
'</u> '.$this->
getLibStatut(5);
1513 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1514 if (isset($this->amount)) {
1515 $label .=
'<br><b>'.$langs->trans(
"Amount").
":</b> ".
price($this->amount);
1517 if (isset($this->date_trans)) {
1518 $label .=
'<br><b>'.$langs->trans(
"TransData").
":</b> ".
dol_print_date($this->date_trans,
'dayhour',
'tzuserrel');
1524 $url = DOL_URL_ROOT.
'/compta/prelevement/card.php?id='.$this->id;
1525 if (!empty($this->
type) && $this->
type ==
'bank-transfer') {
1526 $url = DOL_URL_ROOT.
'/compta/prelevement/card.php?id='.$this->id;
1529 if ($option !=
'nolink') {
1531 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1532 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1533 $add_save_lastsearch_values = 1;
1535 if ($add_save_lastsearch_values) {
1536 $url .=
'&save_lastsearch_values=1';
1541 if (empty($notooltip)) {
1543 $label = $langs->trans(
"ShowMyObject");
1544 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1546 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1547 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1549 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1552 $linkstart =
'<a href="'.$url.
'"';
1553 $linkstart .= $linkclose.
'>';
1556 $result .= $linkstart;
1558 $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);
1560 if ($withpicto != 2) {
1561 $result .= $this->ref;
1563 $result .= $linkend;
1565 global $action, $hookmanager;
1566 $hookmanager->initHooks(array(
'banktransferdao'));
1567 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1568 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1570 $result = $hookmanager->resPrint;
1572 $result .= $hookmanager->resPrint;
1587 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"notify_def";
1588 $sql .=
" WHERE rowid = ".((int) $rowid);
1590 if ($this->db->query($sql)) {
1606 if (is_object($user)) {
1607 $userid = $user->id;
1612 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"notify_def";
1613 $sql .=
" WHERE fk_user=".((int) $userid).
" AND fk_action='".$this->db->escape($action).
"'";
1615 if ($this->db->query($sql)) {
1636 if (is_object($user)) {
1637 $userid = $user->id;
1645 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"notify_def (datec,fk_user, fk_soc, fk_contact, fk_action)";
1646 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".((int) $userid).
", 'NULL', 'NULL', '".$this->db->escape($action).
"')";
1649 if ($this->db->query($sql)) {
1653 dol_syslog(get_class($this).
"::addNotification Error $result");
1675 public function generate($format =
'ALL', $executiondate = 0, $type =
'direct-debit', $fk_bank_account = 0, $user_dest = 0)
1677 global $conf, $langs, $mysoc;
1682 if (empty($fk_bank_account)) {
1683 $fk_bank_account = ($type ==
'bank-transfer' ?
getDolGlobalInt(
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') :
getDolGlobalInt(
'PRELEVEMENT_ID_BANKACCOUNT'));
1688 dol_syslog(get_class($this).
"::generate build file=".$this->filename.
" type=".$type);
1690 $this->file = fopen($this->filename,
"w");
1691 if (empty($this->file)) {
1692 $this->error = $langs->trans(
'ErrorFailedToOpenFile', $this->filename);
1700 if ($mysoc->isInEEC()) {
1703 if ($type !=
'bank-transfer') {
1715 if (!empty($executiondate)) {
1716 $date_actu = $executiondate;
1721 $fileDebiteurSection =
'';
1722 $fileEmetteurSection =
'';
1729 $sql =
"SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
1730 $sql .=
" pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
1731 $sql .=
" f.ref as reffac, p.fk_facture as idfac,";
1732 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
1734 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement_lignes as pl,";
1735 $sql .=
" ".MAIN_DB_PREFIX.
"facture as f,";
1736 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement as p,";
1737 $sql .=
" ".MAIN_DB_PREFIX.
"societe as soc,";
1738 $sql .=
" ".MAIN_DB_PREFIX.
"c_country as c,";
1739 $sql .=
" ".MAIN_DB_PREFIX.
"societe_rib as rib";
1740 $sql .=
" WHERE pl.fk_prelevement_bons = ".((int) $this->
id);
1741 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
1742 $sql .=
" AND p.fk_facture = f.rowid";
1743 $sql .=
" AND f.fk_soc = soc.rowid";
1744 $sql .=
" AND soc.fk_pays = c.rowid";
1745 $sql .=
" AND rib.fk_soc = f.fk_soc";
1746 $sql .=
" AND rib.default_rib = 1";
1747 $sql .=
" AND rib.type = 'ban'";
1750 $resql = $this->db->query($sql);
1752 $cachearraytotestduplicate = array();
1754 $num = $this->db->num_rows($resql);
1756 $obj = $this->db->fetch_object($resql);
1758 if (!empty($cachearraytotestduplicate[$obj->idfac])) {
1759 $this->error = $langs->trans(
'ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
1760 $this->invoice_in_error[$obj->idfac] = $this->error;
1764 $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
1766 $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
1768 $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);
1770 $this->total = $this->total + $obj->somme;
1773 $nbtotalDrctDbtTxInf = $i;
1775 $this->error = $this->db->lasterror();
1776 fputs($this->file,
'ERROR DEBITOR '.$sql.$CrLf);
1781 if ($result != -2) {
1782 $fileEmetteurSection .= $this->
EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type, $fk_bank_account);
1789 fputs($this->file,
'<'.
'?xml version="1.0" encoding="UTF-8" standalone="yes"?'.
'>'.$CrLf);
1790 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);
1791 fputs($this->file,
' <CstmrDrctDbtInitn>'.$CrLf);
1793 fputs($this->file,
' <GrpHdr>'.$CrLf);
1794 fputs($this->file,
' <MsgId>'.(
'DD/'.$dateTime_YMD.
'/REF'.$this->id).
'</MsgId>'.$CrLf);
1795 fputs($this->file,
' <CreDtTm>'.$dateTime_ECMA.
'</CreDtTm>'.$CrLf);
1796 fputs($this->file,
' <NbOfTxs>'.$i.
'</NbOfTxs>'.$CrLf);
1797 fputs($this->file,
' <CtrlSum>'.$this->total.
'</CtrlSum>'.$CrLf);
1798 fputs($this->file,
' <InitgPty>'.$CrLf);
1800 fputs($this->file,
' <Id>'.$CrLf);
1801 fputs($this->file,
' <PrvtId>'.$CrLf);
1802 fputs($this->file,
' <Othr>'.$CrLf);
1803 fputs($this->file,
' <Id>'.$this->emetteur_ics.
'</Id>'.$CrLf);
1804 fputs($this->file,
' </Othr>'.$CrLf);
1805 fputs($this->file,
' </PrvtId>'.$CrLf);
1806 fputs($this->file,
' </Id>'.$CrLf);
1807 fputs($this->file,
' </InitgPty>'.$CrLf);
1808 fputs($this->file,
' </GrpHdr>'.$CrLf);
1810 if ($result != -2) {
1811 fputs($this-> file, $fileEmetteurSection);
1814 if ($result != -2) {
1815 fputs($this-> file, $fileDebiteurSection);
1818 fputs($this->file,
' </PmtInf>'.$CrLf);
1819 fputs($this->file,
' </CstmrDrctDbtInitn>'.$CrLf);
1820 fputs($this->file,
'</Document>'.$CrLf);
1833 if (!empty($executiondate)) {
1834 $date_actu = $executiondate;
1839 $fileCrediteurSection =
'';
1840 $fileEmetteurSection =
'';
1846 if (!empty($user_dest)) {
1847 $sql =
"SELECT u.rowid as userId, u.address, u.zip, u.town, c.code as country_code, CONCAT(u.firstname,' ',u.lastname) as nom,";
1848 $sql .=
" pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
1849 $sql .=
" s.ref as reffac, p.fk_salary as idfac,";
1850 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, '' as rum, '' as date_rum";
1852 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement_lignes as pl,";
1853 $sql .=
" ".MAIN_DB_PREFIX.
"salary as s,";
1854 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement as p,";
1855 $sql .=
" ".MAIN_DB_PREFIX.
"user as u";
1856 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as c ON u.fk_country = c.rowid,";
1857 $sql .=
" ".MAIN_DB_PREFIX.
"user_rib as rib";
1858 $sql .=
" WHERE pl.fk_prelevement_bons=".((int) $this->
id);
1859 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
1860 $sql .=
" AND p.fk_salary = s.rowid";
1861 $sql .=
" AND s.fk_user = u.rowid";
1862 $sql .=
" AND rib.fk_user = s.fk_user";
1864 $sql =
"SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
1865 $sql .=
" pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
1866 $sql .=
" f.ref as reffac, f.ref_supplier as fac_ref_supplier, p.fk_facture_fourn as idfac,";
1867 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
1869 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement_lignes as pl,";
1870 $sql .=
" ".MAIN_DB_PREFIX.
"facture_fourn as f,";
1871 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement as p,";
1872 $sql .=
" ".MAIN_DB_PREFIX.
"societe as soc";
1873 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as c ON soc.fk_pays = c.rowid,";
1874 $sql .=
" ".MAIN_DB_PREFIX.
"societe_rib as rib";
1875 $sql .=
" WHERE pl.fk_prelevement_bons = ".((int) $this->
id);
1876 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
1877 $sql .=
" AND p.fk_facture_fourn = f.rowid";
1878 $sql .=
" AND f.fk_soc = soc.rowid";
1879 $sql .=
" AND rib.fk_soc = f.fk_soc";
1880 $sql .=
" AND rib.default_rib = 1";
1881 $sql .=
" AND rib.type = 'ban'";
1884 $resql = $this->db->query($sql);
1886 $cachearraytotestduplicate = array();
1888 $num = $this->db->num_rows($resql);
1890 $obj = $this->db->fetch_object($resql);
1891 if (!empty($cachearraytotestduplicate[$obj->idfac])) {
1892 $this->error = $langs->trans(
'ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
1893 $this->invoice_in_error[$obj->idfac] = $this->error;
1897 $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
1899 $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
1900 $refobj = $obj->reffac;
1901 if (empty($refobj) && !empty($user_dest)) {
1902 $refobj =
"SAL".$obj->idfac;
1905 $fileCrediteurSection .= $this->
EnregDestinataireSEPA($obj->code, $obj->nom, $obj->address, $obj->zip, $obj->town, $obj->country_code, $obj->cb, $obj->cg, $obj->cc, $obj->somme, $refobj, $obj->idfac, $obj->iban, $obj->bic, $daterum, $obj->drum, $obj->rum, $type, $obj->fac_ref_supplier);
1907 $this->total = $this->total + $obj->somme;
1910 $nbtotalDrctDbtTxInf = $i;
1912 $this->error = $this->db->lasterror();
1913 fputs($this->file,
'ERROR CREDITOR '.$sql.$CrLf);
1917 if ($result != -2) {
1918 $fileEmetteurSection .= $this->
EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type);
1925 fputs($this->file,
'<'.
'?xml version="1.0" encoding="UTF-8" standalone="yes"?'.
'>'.$CrLf);
1926 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);
1927 fputs($this->file,
' <CstmrCdtTrfInitn>'.$CrLf);
1929 fputs($this->file,
' <GrpHdr>'.$CrLf);
1930 fputs($this->file,
' <MsgId>'.(
'TRF/'.$dateTime_YMD.
'/REF'.$this->id).
'</MsgId>'.$CrLf);
1931 fputs($this->file,
' <CreDtTm>'.$dateTime_ECMA.
'</CreDtTm>'.$CrLf);
1932 fputs($this->file,
' <NbOfTxs>'.$i.
'</NbOfTxs>'.$CrLf);
1933 fputs($this->file,
' <CtrlSum>'.$this->total.
'</CtrlSum>'.$CrLf);
1934 fputs($this->file,
' <InitgPty>'.$CrLf);
1936 fputs($this->file,
' <Id>'.$CrLf);
1937 fputs($this->file,
' <PrvtId>'.$CrLf);
1938 fputs($this->file,
' <Othr>'.$CrLf);
1939 fputs($this->file,
' <Id>'.$this->emetteur_ics.
'</Id>'.$CrLf);
1940 fputs($this->file,
' </Othr>'.$CrLf);
1941 fputs($this->file,
' </PrvtId>'.$CrLf);
1942 fputs($this->file,
' </Id>'.$CrLf);
1943 fputs($this->file,
' </InitgPty>'.$CrLf);
1944 fputs($this->file,
' </GrpHdr>'.$CrLf);
1946 if ($result != -2) {
1947 fputs($this-> file, $fileEmetteurSection);
1950 if ($result != -2) {
1951 fputs($this-> file, $fileCrediteurSection);
1954 fputs($this->file,
' </PmtInf>'.$CrLf);
1955 fputs($this->file,
' </CstmrCdtTrfInitn>'.$CrLf);
1956 fputs($this->file,
'</Document>'.$CrLf);
1962 if ($type !=
'bank-transfer') {
1963 $sql =
"SELECT pl.amount";
1965 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement_lignes as pl,";
1966 $sql .=
" ".MAIN_DB_PREFIX.
"facture as f,";
1967 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement as p";
1968 $sql .=
" WHERE pl.fk_prelevement_bons = ".((int) $this->
id);
1969 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
1970 $sql .=
" AND p.fk_facture = f.rowid";
1974 $resql = $this->db->query($sql);
1976 $num = $this->db->num_rows($resql);
1979 $obj = $this->db->fetch_object($resql);
1980 $this->total = $this->total + $obj->amount;
1989 $sql =
"SELECT pl.amount";
1991 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement_lignes as pl,";
1992 $sql .=
" ".MAIN_DB_PREFIX.
"facture_fourn as f,";
1993 $sql .=
" ".MAIN_DB_PREFIX.
"prelevement as p";
1994 $sql .=
" WHERE pl.fk_prelevement_bons = ".((int) $this->
id);
1995 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
1996 $sql .=
" AND p.fk_facture_fourn = f.rowid";
1999 $resql = $this->db->query($sql);
2001 $num = $this->db->num_rows($resql);
2004 $obj = $this->db->fetch_object($resql);
2005 $this->total = $this->total + $obj->amount;
2015 $langs->load(
'withdrawals');
2018 fputs($this->file, $langs->transnoentitiesnoconv(
'WithdrawalFileNotCapable', $mysoc->country_code));
2021 fclose($this->file);
2043 return $pre.
'-'.
dol_print_date($row_datec,
'dayhourlogsmall').
'-'.
dol_trunc($row_drum.($row_code_client ?
'-'.$row_code_client :
''), 13,
'right',
'UTF-8', 1);
2064 public function EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $ref, $facid, $rib_dom =
'', $type =
'direct-debit')
2067 fputs($this->file,
"06");
2068 fputs($this->file,
"08");
2070 fputs($this->file,
" ");
2072 fputs($this->file, $this->emetteur_ics);
2076 fputs($this->file,
" ");
2077 fputs($this->file,
dol_print_date($this->date_echeance,
"%d%m",
'gmt'));
2078 fputs($this->file, substr(
dol_print_date($this->date_echeance,
"%y",
'gmt'), 1));
2082 fputs($this->file, substr(strtoupper($client_nom).
" ", 0, 24));
2085 $domiciliation = strtr($rib_dom, array(
" " =>
"-", CHR(13) =>
" ", CHR(10) =>
""));
2086 fputs($this->file, substr($domiciliation.
" ", 0, 24));
2090 fputs($this->file, substr(
" ", 0, 8));
2094 fputs($this->file, $rib_guichet);
2098 fputs($this->file, substr(
"000000000000000".$rib_number, -11));
2102 $montant = (round($amount, 2) * 100);
2104 fputs($this->file, substr(
"000000000000000".$montant, -16));
2108 fputs($this->file, substr(
"*_".$ref.
"_RDVnet".$rowid.
" ", 0, 31));
2112 fputs($this->file, $rib_banque);
2116 fputs($this->file, substr(
" ", 0, 5));
2118 fputs($this->file,
"\n");
2148 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 =
'')
2153 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
2156 $Rowing = sprintf(
"%010d", $row_idfac);
2160 $Rum = (empty($row_rum) ? $this->
buildRumNumber($row_code_client, $row_datec, $row_drum) : $row_rum);
2165 if ($type !=
'bank-transfer') {
2168 $XML_DEBITOR .=
' <DrctDbtTxInf>'.$CrLf;
2169 $XML_DEBITOR .=
' <PmtId>'.$CrLf;
2171 $XML_DEBITOR .=
' <EndToEndId>'.((getDolGlobalString(
'PRELEVEMENT_END_TO_END') !=
"") ? $conf->global->PRELEVEMENT_END_TO_END : (
'DD-'.dol_trunc($row_idfac.
'-'.$row_ref, 20,
'right',
'UTF-8', 1)).
'-'.$Rowing).
'</EndToEndId>'.$CrLf;
2172 $XML_DEBITOR .=
' </PmtId>'.$CrLf;
2173 $XML_DEBITOR .=
' <InstdAmt Ccy="EUR">'.round($row_somme, 2).
'</InstdAmt>'.$CrLf;
2174 $XML_DEBITOR .=
' <DrctDbtTx>'.$CrLf;
2175 $XML_DEBITOR .=
' <MndtRltdInf>'.$CrLf;
2176 $XML_DEBITOR .=
' <MndtId>'.$Rum.
'</MndtId>'.$CrLf;
2177 $XML_DEBITOR .=
' <DtOfSgntr>'.$DtOfSgntr.
'</DtOfSgntr>'.$CrLf;
2178 $XML_DEBITOR .=
' <AmdmntInd>false</AmdmntInd>'.$CrLf;
2179 $XML_DEBITOR .=
' </MndtRltdInf>'.$CrLf;
2180 $XML_DEBITOR .=
' </DrctDbtTx>'.$CrLf;
2181 $XML_DEBITOR .=
' <DbtrAgt>'.$CrLf;
2182 $XML_DEBITOR .=
' <FinInstnId>'.$CrLf;
2183 $XML_DEBITOR .=
' <BIC>'.$row_bic.
'</BIC>'.$CrLf;
2184 $XML_DEBITOR .=
' </FinInstnId>'.$CrLf;
2185 $XML_DEBITOR .=
' </DbtrAgt>'.$CrLf;
2186 $XML_DEBITOR .=
' <Dbtr>'.$CrLf;
2188 $XML_DEBITOR .=
' <PstlAdr>'.$CrLf;
2189 $XML_DEBITOR .=
' <Ctry>'.$row_country_code.
'</Ctry>'.$CrLf;
2190 $addressline1 = strtr($row_address, array(CHR(13) =>
", ", CHR(10) =>
""));
2191 $addressline2 = strtr($row_zip.(($row_zip && $row_town) ?
' ' : (string) $row_town), array(CHR(13) =>
", ", CHR(10) =>
""));
2192 if (trim($addressline1)) {
2195 if (trim($addressline2)) {
2198 $XML_DEBITOR .=
' </PstlAdr>'.$CrLf;
2199 $XML_DEBITOR .=
' </Dbtr>'.$CrLf;
2200 $XML_DEBITOR .=
' <DbtrAcct>'.$CrLf;
2201 $XML_DEBITOR .=
' <Id>'.$CrLf;
2202 $XML_DEBITOR .=
' <IBAN>'.preg_replace(
'/\s/',
'', $row_iban).
'</IBAN>'.$CrLf;
2203 $XML_DEBITOR .=
' </Id>'.$CrLf;
2204 $XML_DEBITOR .=
' </DbtrAcct>'.$CrLf;
2205 $XML_DEBITOR .=
' <RmtInf>'.$CrLf;
2207 $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;
2208 $XML_DEBITOR .=
' </RmtInf>'.$CrLf;
2209 $XML_DEBITOR .=
' </DrctDbtTxInf>'.$CrLf;
2210 return $XML_DEBITOR;
2214 $XML_CREDITOR .=
' <CdtTrfTxInf>'.$CrLf;
2215 $XML_CREDITOR .=
' <PmtId>'.$CrLf;
2217 $XML_CREDITOR .=
' <EndToEndId>'.((getDolGlobalString(
'PRELEVEMENT_END_TO_END') !=
"") ? $conf->global->PRELEVEMENT_END_TO_END : (
'CT-'.dol_trunc($row_idfac.
'-'.$row_ref, 20,
'right',
'UTF-8', 1)).
'-'.$Rowing).
'</EndToEndId>'.$CrLf;
2218 $XML_CREDITOR .=
' </PmtId>'.$CrLf;
2219 if (!empty($this->sepa_xml_pti_in_ctti)) {
2220 $XML_CREDITOR .=
' <PmtTpInf>' . $CrLf;
2224 $instrprty =
'HIGH';
2226 $instrprty =
'NORM';
2228 $XML_CREDITOR .=
' <InstrPrty>'.$instrprty.
'</InstrPrty>' . $CrLf;
2229 $XML_CREDITOR .=
' <SvcLvl>' . $CrLf;
2230 $XML_CREDITOR .=
' <Cd>SEPA</Cd>' . $CrLf;
2231 $XML_CREDITOR .=
' </SvcLvl>' . $CrLf;
2232 $XML_CREDITOR .=
' <CtgyPurp>' . $CrLf;
2233 $XML_CREDITOR .=
' <Cd>CORE</Cd>' . $CrLf;
2234 $XML_CREDITOR .=
' </CtgyPurp>' . $CrLf;
2235 $XML_CREDITOR .=
' </PmtTpInf>' . $CrLf;
2237 $XML_CREDITOR .=
' <Amt>'.$CrLf;
2238 $XML_CREDITOR .=
' <InstdAmt Ccy="EUR">'.round($row_somme, 2).
'</InstdAmt>'.$CrLf;
2239 $XML_CREDITOR .=
' </Amt>'.$CrLf;
2250 $XML_CREDITOR .=
' <CdtrAgt>'.$CrLf;
2251 $XML_CREDITOR .=
' <FinInstnId>'.$CrLf;
2252 $XML_CREDITOR .=
' <BIC>'.$row_bic.
'</BIC>'.$CrLf;
2253 $XML_CREDITOR .=
' </FinInstnId>'.$CrLf;
2254 $XML_CREDITOR .=
' </CdtrAgt>'.$CrLf;
2255 $XML_CREDITOR .=
' <Cdtr>'.$CrLf;
2257 $XML_CREDITOR .=
' <PstlAdr>'.$CrLf;
2258 $XML_CREDITOR .=
' <Ctry>'.$row_country_code.
'</Ctry>'.$CrLf;
2259 $addressline1 = strtr($row_address, array(CHR(13) =>
", ", CHR(10) =>
""));
2260 $addressline2 = strtr($row_zip.(($row_zip && $row_town) ?
' ' : (string) $row_town), array(CHR(13) =>
", ", CHR(10) =>
""));
2261 if (trim($addressline1)) {
2264 if (trim($addressline2)) {
2267 $XML_CREDITOR .=
' </PstlAdr>'.$CrLf;
2268 $XML_CREDITOR .=
' </Cdtr>'.$CrLf;
2269 $XML_CREDITOR .=
' <CdtrAcct>'.$CrLf;
2270 $XML_CREDITOR .=
' <Id>'.$CrLf;
2271 $XML_CREDITOR .=
' <IBAN>'.preg_replace(
'/\s/',
'', $row_iban).
'</IBAN>'.$CrLf;
2272 $XML_CREDITOR .=
' </Id>'.$CrLf;
2273 $XML_CREDITOR .=
' </CdtrAcct>'.$CrLf;
2274 $XML_CREDITOR .=
' <RmtInf>'.$CrLf;
2276 $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;
2277 $XML_CREDITOR .=
' </RmtInf>'.$CrLf;
2278 $XML_CREDITOR .=
' </CdtTrfTxInf>'.$CrLf;
2279 return $XML_CREDITOR;
2295 fputs($this->file,
"03");
2296 fputs($this->file,
"08");
2298 fputs($this->file,
" ");
2300 fputs($this->file, $this->emetteur_ics);
2304 fputs($this->file,
" ");
2305 fputs($this->file,
dol_print_date($this->date_echeance,
"%d%m",
'gmt'));
2306 fputs($this->file, substr(
dol_print_date($this->date_echeance,
"%y",
'gmt'), 1));
2310 fputs($this->file, substr($this->raison_sociale.
" ", 0, 24));
2314 fputs($this->file, substr($this->reference_remise.
" ", 0, 7));
2318 fputs($this->file, substr(
" ", 0, 17));
2322 fputs($this->file, substr(
" ", 0, 2));
2323 fputs($this->file,
"E");
2324 fputs($this->file, substr(
" ", 0, 5));
2328 fputs($this->file, $this->emetteur_code_guichet);
2332 fputs($this->file, substr(
"000000000000000".$this->emetteur_numero_compte, -11));
2336 fputs($this->file, substr(
" ", 0, 16));
2340 fputs($this->file, substr(
" ", 0, 31));
2344 fputs($this->file, $this->emetteur_code_banque);
2348 fputs($this->file, substr(
" ", 0, 5));
2350 fputs($this->file,
"\n");
2370 public function EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf =
'\n', $format =
'FRST', $type =
'direct-debit', $fk_bank_account = 0)
2380 if (empty($fk_bank_account)) {
2381 $fk_bank_account = ($type ==
'bank-transfer' ?
getDolGlobalInt(
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') :
getDolGlobalInt(
'PRELEVEMENT_ID_BANKACCOUNT'));
2385 $account =
new Account($this->db);
2386 if ($account->fetch($fk_bank_account) > 0) {
2387 $this->emetteur_code_banque = $account->code_banque;
2388 $this->emetteur_code_guichet = $account->code_guichet;
2389 $this->emetteur_numero_compte = $account->number;
2390 $this->emetteur_number_key = $account->cle_rib;
2391 $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
2392 $this->emetteur_iban = $account->iban;
2393 $this->emetteur_bic = $account->bic;
2395 $this->emetteur_ics = (($type ==
'bank-transfer' &&
getDolGlobalString(
"SEPA_USE_IDS")) ? $account->ics_transfer : $account->ics);
2397 $this->raison_sociale = $account->proprio;
2401 $sql =
"SELECT rowid, ref";
2402 $sql .=
" FROM ".MAIN_DB_PREFIX.
"prelevement_bons as pb";
2403 $sql .=
" WHERE pb.rowid = ".((int) $this->
id);
2405 $resql = $this->db->query($sql);
2407 $obj = $this->db->fetch_object($resql);
2409 $country = explode(
':', $configuration->global->MAIN_INFO_SOCIETE_COUNTRY);
2410 $IdBon = sprintf(
"%05d", $obj->rowid);
2411 $RefBon = $obj->ref;
2413 if ($type !=
'bank-transfer') {
2415 $XML_SEPA_INFO =
'';
2416 $XML_SEPA_INFO .=
' <PmtInf>'.$CrLf;
2417 $XML_SEPA_INFO .=
' <PmtInfId>'.(
'DD/'.$dateTime_YMD.
'/ID'.$IdBon.
'-'.$RefBon).
'</PmtInfId>'.$CrLf;
2418 $XML_SEPA_INFO .=
' <PmtMtd>DD</PmtMtd>'.$CrLf;
2419 $XML_SEPA_INFO .=
' <NbOfTxs>'.$nombre.
'</NbOfTxs>'.$CrLf;
2420 $XML_SEPA_INFO .=
' <CtrlSum>'.$total.
'</CtrlSum>'.$CrLf;
2421 $XML_SEPA_INFO .=
' <PmtTpInf>'.$CrLf;
2422 $XML_SEPA_INFO .=
' <SvcLvl>'.$CrLf;
2423 $XML_SEPA_INFO .=
' <Cd>SEPA</Cd>'.$CrLf;
2424 $XML_SEPA_INFO .=
' </SvcLvl>'.$CrLf;
2425 $XML_SEPA_INFO .=
' <LclInstrm>'.$CrLf;
2426 $XML_SEPA_INFO .=
' <Cd>CORE</Cd>'.$CrLf;
2427 $XML_SEPA_INFO .=
' </LclInstrm>'.$CrLf;
2428 $XML_SEPA_INFO .=
' <SeqTp>'.$format.
'</SeqTp>'.$CrLf;
2429 $XML_SEPA_INFO .=
' </PmtTpInf>'.$CrLf;
2430 $XML_SEPA_INFO .=
' <ReqdColltnDt>'.$dateTime_ETAD.
'</ReqdColltnDt>'.$CrLf;
2431 $XML_SEPA_INFO .=
' <Cdtr>'.$CrLf;
2433 $XML_SEPA_INFO .=
' <PstlAdr>'.$CrLf;
2434 $XML_SEPA_INFO .=
' <Ctry>'.$country[1].
'</Ctry>'.$CrLf;
2435 $addressline1 = strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(CHR(13) =>
", ", CHR(10) =>
""));
2436 $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) =>
""));
2437 if ($addressline1) {
2440 if ($addressline2) {
2443 $XML_SEPA_INFO .=
' </PstlAdr>'.$CrLf;
2444 $XML_SEPA_INFO .=
' </Cdtr>'.$CrLf;
2445 $XML_SEPA_INFO .=
' <CdtrAcct>'.$CrLf;
2446 $XML_SEPA_INFO .=
' <Id>'.$CrLf;
2447 $XML_SEPA_INFO .=
' <IBAN>'.preg_replace(
'/\s/',
'', $this->emetteur_iban).
'</IBAN>'.$CrLf;
2448 $XML_SEPA_INFO .=
' </Id>'.$CrLf;
2449 $XML_SEPA_INFO .=
' </CdtrAcct>'.$CrLf;
2450 $XML_SEPA_INFO .=
' <CdtrAgt>'.$CrLf;
2451 $XML_SEPA_INFO .=
' <FinInstnId>'.$CrLf;
2452 $XML_SEPA_INFO .=
' <BIC>'.$this->emetteur_bic.
'</BIC>'.$CrLf;
2453 $XML_SEPA_INFO .=
' </FinInstnId>'.$CrLf;
2454 $XML_SEPA_INFO .=
' </CdtrAgt>'.$CrLf;
2463 $XML_SEPA_INFO .=
' <ChrgBr>SLEV</ChrgBr>'.$CrLf;
2464 $XML_SEPA_INFO .=
' <CdtrSchmeId>'.$CrLf;
2465 $XML_SEPA_INFO .=
' <Id>'.$CrLf;
2466 $XML_SEPA_INFO .=
' <PrvtId>'.$CrLf;
2467 $XML_SEPA_INFO .=
' <Othr>'.$CrLf;
2468 $XML_SEPA_INFO .=
' <Id>'.$this->emetteur_ics.
'</Id>'.$CrLf;
2469 $XML_SEPA_INFO .=
' <SchmeNm>'.$CrLf;
2470 $XML_SEPA_INFO .=
' <Prtry>SEPA</Prtry>'.$CrLf;
2471 $XML_SEPA_INFO .=
' </SchmeNm>'.$CrLf;
2472 $XML_SEPA_INFO .=
' </Othr>'.$CrLf;
2473 $XML_SEPA_INFO .=
' </PrvtId>'.$CrLf;
2474 $XML_SEPA_INFO .=
' </Id>'.$CrLf;
2475 $XML_SEPA_INFO .=
' </CdtrSchmeId>'.$CrLf;
2478 $XML_SEPA_INFO =
'';
2479 $XML_SEPA_INFO .=
' <PmtInf>'.$CrLf;
2480 $XML_SEPA_INFO .=
' <PmtInfId>'.(
'TRF/'.$dateTime_YMD.
'/ID'.$IdBon.
'-'.$RefBon).
'</PmtInfId>'.$CrLf;
2481 $XML_SEPA_INFO .=
' <PmtMtd>TRF</PmtMtd>'.$CrLf;
2483 $XML_SEPA_INFO .=
' <NbOfTxs>'.$nombre.
'</NbOfTxs>'.$CrLf;
2484 $XML_SEPA_INFO .=
' <CtrlSum>'.$total.
'</CtrlSum>'.$CrLf;
2485 if (!empty($this->sepa_xml_pti_in_ctti) && !empty($format)) {
2486 $XML_SEPA_INFO .=
' <PmtTpInf>' . $CrLf;
2487 $XML_SEPA_INFO .=
' <SvcLvl>' . $CrLf;
2488 $XML_SEPA_INFO .=
' <Cd>SEPA</Cd>' . $CrLf;
2489 $XML_SEPA_INFO .=
' </SvcLvl>' . $CrLf;
2490 $XML_SEPA_INFO .=
' <LclInstrm>' . $CrLf;
2491 $XML_SEPA_INFO .=
' <Cd>CORE</Cd>' . $CrLf;
2492 $XML_SEPA_INFO .=
' </LclInstrm>' . $CrLf;
2493 $XML_SEPA_INFO .=
' <SeqTp>' . $format .
'</SeqTp>' . $CrLf;
2494 $XML_SEPA_INFO .=
' </PmtTpInf>' . $CrLf;
2496 $XML_SEPA_INFO .=
' <ReqdExctnDt>'.dol_print_date($dateTime_ETAD,
'dayrfc').
'</ReqdExctnDt>'.$CrLf;
2497 $XML_SEPA_INFO .=
' <Dbtr>'.$CrLf;
2499 $XML_SEPA_INFO .=
' <PstlAdr>'.$CrLf;
2500 $XML_SEPA_INFO .=
' <Ctry>'.$country[1].
'</Ctry>'.$CrLf;
2501 $addressline1 = strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(CHR(13) =>
", ", CHR(10) =>
""));
2502 $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) =>
""));
2503 if ($addressline1) {
2506 if ($addressline2) {
2509 $XML_SEPA_INFO .=
' </PstlAdr>'.$CrLf;
2510 $XML_SEPA_INFO .=
' </Dbtr>'.$CrLf;
2511 $XML_SEPA_INFO .=
' <DbtrAcct>'.$CrLf;
2512 $XML_SEPA_INFO .=
' <Id>'.$CrLf;
2513 $XML_SEPA_INFO .=
' <IBAN>'.preg_replace(
'/\s/',
'', $this->emetteur_iban).
'</IBAN>'.$CrLf;
2514 $XML_SEPA_INFO .=
' </Id>'.$CrLf;
2515 $XML_SEPA_INFO .=
' </DbtrAcct>'.$CrLf;
2516 $XML_SEPA_INFO .=
' <DbtrAgt>'.$CrLf;
2517 $XML_SEPA_INFO .=
' <FinInstnId>'.$CrLf;
2518 $XML_SEPA_INFO .=
' <BIC>'.$this->emetteur_bic.
'</BIC>'.$CrLf;
2519 $XML_SEPA_INFO .=
' </FinInstnId>'.$CrLf;
2520 $XML_SEPA_INFO .=
' </DbtrAgt>'.$CrLf;
2529 $XML_SEPA_INFO .=
' <ChrgBr>SLEV</ChrgBr>'.$CrLf;
2544 fputs($this->file,
'INCORRECT EMETTEUR '.$this->raison_sociale.$CrLf);
2545 $XML_SEPA_INFO =
'';
2547 return $XML_SEPA_INFO;
2560 fputs($this->file,
"08");
2561 fputs($this->file,
"08");
2563 fputs($this->file,
" ");
2565 fputs($this->file, $this->emetteur_ics);
2569 fputs($this->file, substr(
" ", 0, 12));
2574 fputs($this->file, substr(
" ", 0, 24));
2578 fputs($this->file, substr(
" ", 0, 24));
2582 fputs($this->file, substr(
" ", 0, 8));
2586 fputs($this->file, substr(
" ", 0, 5));
2590 fputs($this->file, substr(
" ", 0, 11));
2594 $montant = ($total * 100);
2596 fputs($this->file, substr(
"000000000000000".$montant, -16));
2600 fputs($this->file, substr(
" ", 0, 31));
2604 fputs($this->file, substr(
" ", 0, 5));
2608 fputs($this->file, substr(
" ", 0, 5));
2610 fputs($this->file,
"\n");
2635 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
2638 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'StatusWaiting');
2639 $this->labelStatus[self::STATUS_TRANSFERED] = $langs->transnoentitiesnoconv(
'StatusTrans');
2640 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'StatusWaiting');
2641 $this->labelStatusShort[self::STATUS_TRANSFERED] = $langs->transnoentitiesnoconv(
'StatusTrans');
2642 if ($this->
type ==
'bank-transfer') {
2643 $this->labelStatus[self::STATUS_DEBITED] = $langs->transnoentitiesnoconv(
'StatusDebited');
2644 $this->labelStatusShort[self::STATUS_DEBITED] = $langs->transnoentitiesnoconv(
'StatusDebited');
2646 $this->labelStatus[self::STATUS_CREDITED] = $langs->transnoentitiesnoconv(
'StatusCredited');
2647 $this->labelStatusShort[self::STATUS_CREDITED] = $langs->transnoentitiesnoconv(
'StatusCredited');
2651 $statusType =
'status1';
2652 if ($status == self::STATUS_TRANSFERED) {
2653 $statusType =
'status3';
2655 if ($status == self::STATUS_CREDITED || $status == self::STATUS_DEBITED) {
2656 $statusType =
'status6';
2659 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
2745 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2747 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2748 $return .=
'<div class="info-box info-box-sm">';
2749 $return .=
'<span class="info-box-icon bg-infobox-action">';
2751 $return .=
'</span>';
2752 $return .=
'<div class="info-box-content">';
2753 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
2754 if ($selected >= 0) {
2755 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
2757 if (property_exists($this,
'date_echeance')) {
2758 $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>';
2760 if (property_exists($this,
'total')) {
2761 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Amount").
'</span> : <span class="amount">'.
price($this->total).
'</span>';
2763 if (method_exists($this,
'LibStatut')) {
2764 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
2766 $return .=
'</div>';
2767 $return .=
'</div>';
2768 $return .=
'</div>';
2779 if (!empty($this->
id)) {
2785 $sql =
"SELECT COUNT(*) AS nb FROM ".MAIN_DB_PREFIX.
"prelevement_lignes";
2786 $sql .=
" WHERE fk_prelevement_bons = ".((int) $id);
2787 $sql .=
" AND fk_soc = 0";
2788 $sql .=
" AND fk_user IS NOT NULL";
2791 $resql = $this->db->query($sql);
2793 $obj = $this->db->fetch_object($resql);
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
checkSwiftForAccount(Account $account=null, $swift=null)
Check SWIFT informations for a bank account.
checkIbanForAccount(Account $account=null, $ibantocheck=null)
Check IBAN number informations for a bank account.
Class to manage bank accounts.
Class to manage withdrawal receipts.
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
SommeAPrelever($mode='direct-debit', $type='')
Returns amount waiting for direct debit payment or credit transfer payment.
static buildRumNumber($row_code_client, $row_datec, $row_drum)
Generate dynamically a RUM number for a customer bank account.
EnregEmetteur($type='direct-debit')
Write sender of request (me).
update(User $user, $notrigger=false)
Update object into database.
checkIfSalaryBonPrelevement()
Check if is bon prelevement for salary invoice.
EnregTotal($total)
Write end.
NbFactureAPrelever($type='direct-debit', $forsalary=0)
Get number of invoices to pay.
fetch($rowid, $ref='')
Get object and lines from database.
getListInvoices($amounts=0, $type='')
Get invoice or salary list (with amount or not)
deleteNotificationById($rowid)
Delete a notification def by id.
AddFacture($invoice_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $type='debit-order', $sourcetype='')
Add invoice to withdrawal.
__construct($db)
Constructor.
EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $ref, $facid, $rib_dom='', $type='direct-debit')
Write recipient of request (customer)
getKanbanView($option='', $arraydata=null)
Return 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.
generate($format='ALL', $executiondate=0, $type='direct-debit', $fk_bank_account=0, $user_dest=0)
Generate a direct debit or credit transfer file.
EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf='\n', $format='FRST', $type='direct-debit', $fk_bank_account=0)
Write sender of request (me).
set_infocredit($user, $date, $type='')
Set direct debit or credit transfer order to "paid" status.
addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype='')
Add line to withdrawal.
getLibStatut($mode=0)
Return status label of object.
EnregDestinataireSEPA($row_code_client, $row_nom, $row_address, $row_zip, $row_town, $row_country_code, $row_cb, $row_cg, $row_cc, $row_somme, $row_ref, $row_idfac, $row_iban, $row_bic, $row_datec, $row_drum, $row_rum, $type='direct-debit', $row_comment='')
Write recipient (thirdparty concerned by request)
addNotification($db, $user, $action)
Add a notification.
nbOfInvoiceToPay($mode='direct-debit', $type='')
Get number of invoices waiting for payment.
create($banque=0, $agence=0, $mode='real', $format='ALL', $executiondate='', $notrigger=0, $type='direct-debit', $did=0, $fk_bank_account=0, $sourcetype='invoice')
Create a BAN payment order:
deleteNotification($user, $action)
Delete a notification.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
updateCommon(User $user, $notrigger=false)
Update object into database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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 payments of salaries.
Class to manage salary payments.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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)
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type