32require_once DOL_DOCUMENT_ROOT .
'/core/class/commonobject.class.php';
33require_once DOL_DOCUMENT_ROOT .
'/core/lib/bank.lib.php';
34require_once DOL_DOCUMENT_ROOT .
'/compta/bank/class/account.class.php';
35require_once DOL_DOCUMENT_ROOT .
'/compta/facture/class/facture.class.php';
36require_once DOL_DOCUMENT_ROOT .
'/compta/paiement/class/paiement.class.php';
37require_once DOL_DOCUMENT_ROOT .
'/fourn/class/fournisseur.facture.class.php';
38require_once DOL_DOCUMENT_ROOT .
'/fourn/class/paiementfourn.class.php';
39require_once DOL_DOCUMENT_ROOT .
'/salaries/class/salary.class.php';
40require_once DOL_DOCUMENT_ROOT .
'/salaries/class/paymentsalary.class.php';
41require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
42require_once DOL_DOCUMENT_ROOT .
'/user/class/userbankaccount.class.php';
53 public $element =
'widthdraw';
58 public $table_element =
'prelevement_bons';
63 public $picto =
'payment';
65 public $date_echeance;
66 public $raison_sociale;
67 public $reference_remise;
68 public $emetteur_code_guichet;
69 public $emetteur_numero_compte;
70 public $emetteur_code_banque;
71 public $emetteur_number_key;
72 public $sepa_xml_pti_in_ctti;
74 public $emetteur_iban;
83 public $labelStatus = array();
85 public $factures = array();
90 public $methodes_trans = array();
92 public $invoice_in_error = array();
93 public $thirdparty_in_error = array();
105 const STATUS_DRAFT = 0;
106 const STATUS_TRANSFERED = 1;
107 const STATUS_CREDITED = 2;
108 const STATUS_DEBITED = 2;
154 public $fields = array(
155 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'position' => 10,
'notnull' => 1,
'visible' => 0,),
156 'ref' => array(
'type' =>
'varchar(12)',
'label' =>
'Ref',
'enabled' => 1,
'position' => 15,
'notnull' => 0,
'visible' => -1,
'csslist' =>
'tdoverflowmax150',
'showoncombobox' => 1,),
157 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'position' => 25,
'notnull' => 0,
'visible' => -1,),
158 'amount' => array(
'type' =>
'double(24,8)',
'label' =>
'Amount',
'enabled' => 1,
'position' => 30,
'notnull' => 0,
'visible' => -1,),
159 'statut' => array(
'type' =>
'smallint(6)',
'label' =>
'Statut',
'enabled' => 1,
'position' => 500,
'notnull' => 0,
'visible' => -1,
'arrayofkeyval' => array(0 =>
'Wait', 1 =>
'Transfered', 2 =>
'Credited')),
160 'credite' => array(
'type' =>
'smallint(6)',
'label' =>
'Credite',
'enabled' => 1,
'position' => 40,
'notnull' => 0,
'visible' => -1,),
161 'note' => array(
'type' =>
'text',
'label' =>
'Note',
'enabled' => 1,
'position' => 45,
'notnull' => 0,
'visible' => -1,),
162 'date_trans' => array(
'type' =>
'datetime',
'label' =>
'Datetrans',
'enabled' => 1,
'position' => 50,
'notnull' => 0,
'visible' => -1,),
163 'method_trans' => array(
'type' =>
'smallint(6)',
'label' =>
'Methodtrans',
'enabled' => 1,
'position' => 55,
'notnull' => 0,
'visible' => -1,),
164 'fk_user_trans' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fkusertrans',
'enabled' => 1,
'position' => 60,
'notnull' => 0,
'visible' => -1,
'css' =>
'maxwidth500 widthcentpercentminusxx',
'csslist' =>
'tdoverflowmax150',),
165 'date_credit' => array(
'type' =>
'datetime',
'label' =>
'Datecredit',
'enabled' => 1,
'position' => 65,
'notnull' => 0,
'visible' => -1,),
166 'fk_user_credit' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Fkusercredit',
'enabled' => 1,
'position' => 70,
'notnull' => 0,
'visible' => -1,
'css' =>
'maxwidth500 widthcentpercentminusxx',
'csslist' =>
'tdoverflowmax150',),
167 'type' => array(
'type' =>
'varchar(16)',
'label' =>
'Type',
'enabled' => 1,
'position' => 75,
'notnull' => 0,
'visible' => -1,),
168 'fk_bank_account' => array(
'type' =>
'integer',
'label' =>
'Fkbankaccount',
'enabled' => 1,
'position' => 80,
'notnull' => 0,
'visible' => -1,
'css' =>
'maxwidth500 widthcentpercentminusxx',),
191 public $method_trans;
192 public $fk_user_trans;
194 public $fk_user_credit;
196 public $fk_bank_account;
210 $this->filename =
'';
212 $this->date_echeance =
dol_now();
213 $this->raison_sociale =
"";
214 $this->reference_remise =
"";
216 $this->emetteur_code_guichet =
"";
217 $this->emetteur_numero_compte =
"";
218 $this->emetteur_code_banque =
"";
219 $this->emetteur_number_key =
"";
220 $this->sepa_xml_pti_in_ctti =
false;
222 $this->emetteur_iban =
"";
223 $this->emetteur_bic =
"";
224 $this->emetteur_ics =
"";
226 $this->factures = array();
228 $this->methodes_trans = array(0 =>
'Internet', 2 =>
'Email', 3 =>
'Api');
249 public function AddFacture($invoice_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $type =
'debit-order', $sourcetype =
'')
256 $result = $this->
addline($line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype);
261 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"prelevement (";
262 if ($type !=
'bank-transfer') {
263 $sql .=
"fk_facture";
265 if ($sourcetype ==
'salary') {
268 $sql .=
"fk_facture_fourn";
271 $sql .=
",fk_prelevement_lignes";
272 $sql .=
") VALUES (";
273 $sql .= ((int) $invoice_id);
274 $sql .=
", " . ((int) $line_id);
277 if ($this->db->query($sql)) {
281 $this->errors[] = get_class($this) .
"::AddFacture " . $this->db->lasterror;
282 dol_syslog(get_class($this) .
"::AddFacture Error $result");
286 $this->errors[] = get_class($this) .
"::AddFacture linedid Empty";
287 dol_syslog(get_class($this) .
"::AddFacture Error $result");
291 dol_syslog(get_class($this) .
"::AddFacture Error $result");
311 public function addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype =
'')
320 $sql =
"SELECT rowid";
321 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_lignes";
322 $sql .=
" WHERE fk_prelevement_bons = " . ((int) $this->
id);
323 if ($sourcetype ==
'salary') {
324 $sql .=
" AND fk_soc = " . ((int) $client_id);
326 $sql .=
" AND fk_user = " . ((int) $client_id);
328 $sql .=
" AND code_banque = '" . $this->db->escape($code_banque) .
"'";
329 $sql .=
" AND code_guichet = '" . $this->db->escape($code_guichet) .
"'";
330 $sql .=
" AND number = '" . $this->db->escape($number) .
"'";
332 $resql = $this->db->query($sql);
334 $num = $this->db->num_rows($resql);
342 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"prelevement_lignes (";
343 $sql .=
"fk_prelevement_bons";
345 $sql .=
", client_nom";
347 $sql .=
", code_banque";
348 $sql .=
", code_guichet";
351 $sql .= ($sourcetype ==
'salary' ?
", fk_user" :
"");
352 $sql .=
") VALUES (";
354 $sql .=
", " . (($sourcetype !=
'salary') ? ((
int) $client_id) :
"0");
355 $sql .=
", '" . $this->db->escape($client_nom) .
"'";
356 $sql .=
", " . ((float)
price2num($amount));
357 $sql .=
", '" . $this->db->escape($code_banque) .
"'";
358 $sql .=
", '" . $this->db->escape($code_guichet) .
"'";
359 $sql .=
", '" . $this->db->escape($number) .
"'";
360 $sql .=
", '" . $this->db->escape($number_key) .
"'";
361 $sql .= (($sourcetype ==
'salary') ?
", " . ((
int) $client_id) :
'');
363 if ($this->db->query($sql)) {
364 $line_id = $this->db->last_insert_id(MAIN_DB_PREFIX .
"prelevement_lignes");
367 $this->errors[] = get_class($this) .
"::addline Error -2 " . $this->db->lasterror;
368 dol_syslog(get_class($this) .
"::addline Error -2");
388 $errors[1027] = $langs->trans(
"DateInvalid");
390 return $errors[abs($error)];
400 public function fetch($rowid, $ref =
'')
402 $sql =
"SELECT p.rowid, p.ref, p.amount, p.note";
403 $sql .=
", p.datec as dc";
404 $sql .=
", p.date_trans as date_trans";
405 $sql .=
", p.method_trans, p.fk_user_trans";
406 $sql .=
", p.date_credit as date_credit";
407 $sql .=
", p.fk_user_credit";
409 $sql .=
", p.fk_bank_account";
410 $sql .=
", p.statut as status";
411 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons as p";
412 $sql .=
" WHERE p.entity IN (" .
getEntity(
'invoice') .
")";
414 $sql .=
" AND p.rowid = " . ((int) $rowid);
416 $sql .=
" AND p.ref = '" . $this->db->escape($ref) .
"'";
419 dol_syslog(get_class($this) .
"::fetch", LOG_DEBUG);
420 $result = $this->db->query($sql);
422 if ($this->db->num_rows($result)) {
423 $obj = $this->db->fetch_object($result);
425 $this->
id = $obj->rowid;
426 $this->
ref = $obj->ref;
427 $this->amount = $obj->amount;
428 $this->note = $obj->note;
429 $this->datec = $this->db->jdate($obj->dc);
431 $this->date_trans = $this->db->jdate($obj->date_trans);
432 $this->method_trans = $obj->method_trans;
433 $this->user_trans = $obj->fk_user_trans;
435 $this->date_credit = $this->db->jdate($obj->date_credit);
436 $this->user_credit = $obj->fk_user_credit;
438 $this->
type = $obj->type;
439 $this->fk_bank_account = $obj->fk_bank_account;
441 $this->
status = $obj->status;
442 if (empty($this->
status)) {
445 $this->
statut = $this->status;
451 dol_syslog(get_class($this) .
"::Fetch no record found");
484 global $conf, $langs;
488 if ($this->fetched == 1) {
489 if ($date < $this->date_trans) {
490 $langs->load(
"errors");
491 $this->error = $langs->trans(
'ErrorDateOfMovementLowerThanDateOfFileTransmission');
492 dol_syslog(
"bon-prelevment::set_infocredit 1027 " . $this->error);
498 $sql =
" UPDATE " . MAIN_DB_PREFIX .
"prelevement_bons";
499 $sql .=
" SET fk_user_credit = " . ((int) $user->id);
500 $sql .=
", statut = " . self::STATUS_CREDITED;
501 $sql .=
", date_credit = '" . $this->db->idate($date) .
"'";
502 $sql .=
" WHERE rowid = " . ((int) $this->
id);
503 $sql .=
" AND entity = " . ((int) $conf->entity);
504 $sql .=
" AND statut = " . self::STATUS_TRANSFERED;
506 $resql = $this->db->query($sql);
508 $langs->load(
'withdrawals');
509 $subject = $langs->trans(
"InfoCreditSubject", $this->
ref);
510 $message = $langs->trans(
"InfoCreditMessage", $this->
ref,
dol_print_date($date,
'dayhour'));
513 $fk_bank_account = $this->fk_bank_account;
514 if (empty($fk_bank_account)) {
520 $amountsperthirdparty = array();
530 for ($i = 0; $i < $num; $i++) {
531 if ($this->
type ==
'bank-transfer') {
532 if ($type ==
'salary') {
533 $fac =
new Salary($this->db);
541 $result = $fac->fetch($facs[$i][0]);
543 $amounts[$fac->id] = $facs[$i][1];
544 if ($this->
type ==
'bank-transfer') {
545 if ($type ==
'salary') {
546 $amountsperthirdparty[$fac->fk_user][$fac->id] = $facs[$i][1];
548 $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
551 $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
554 $totalpaid = $fac->getSommePaiement();
555 $totalcreditnotes = 0;
556 if (method_exists($fac,
'getSumCreditNotesUsed')) {
557 $totalcreditnotes = $fac->getSumCreditNotesUsed();
560 if (method_exists($fac,
'getSumDepositsUsed')) {
561 $totaldeposits = $fac->getSumDepositsUsed();
563 $alreadypayed = $totalpaid + $totalcreditnotes + $totaldeposits;
567 $amountofdocument = $fac->total_ttc;
568 if ($type ==
'salary') {
569 $amountofdocument = $fac->amount;
571 if (
price2num($alreadypayed + $facs[$i][1],
'MT') ==
price2num($amountofdocument,
'MT')) {
572 $result = $fac->setPaid($user);
574 $this->error = $fac->error;
575 $this->errors = $fac->errors;
581 foreach ($amountsperthirdparty as $thirdpartyid => $cursoramounts) {
582 if ($this->
type ==
'bank-transfer') {
583 if ($type ==
'salary') {
589 $paiement =
new Paiement($this->db);
591 $paiement->datepaye = $date;
592 $paiement->amounts = $cursoramounts;
594 if ($this->
type ==
'bank-transfer') {
595 if ($type ==
'salary') {
596 $paiement->datep = $date;
598 $paiement->paiementid = 2;
599 $paiement->fk_typepayment = 2;
600 $paiement->paiementcode =
'VIR';
602 $paiement->paiementid = 2;
603 $paiement->paiementcode =
'VIR';
606 $paiement->paiementid = 3;
607 $paiement->paiementcode =
'PRE';
610 $paiement->num_payment = $this->ref;
611 $paiement->id_prelevement = $this->id;
613 $result = $paiement->create($user);
617 $this->error = $paiement->error;
618 $this->errors = $paiement->errors;
619 dol_syslog(get_class($this) .
"::set_infocredit AddPayment Error " . $this->error);
621 if ($this->
type ==
'bank-transfer') {
622 if ($type ==
'salary') {
623 $modeforaddpayment =
'payment_salary';
624 $labelforaddpayment =
'(SalaryPayment)';
625 $addbankurl =
'credit-transfer';
627 $modeforaddpayment =
'payment_supplier';
628 $labelforaddpayment =
'(SupplierInvoicePayment)';
629 $addbankurl =
'credit-transfer';
632 $modeforaddpayment =
'payment';
633 $labelforaddpayment =
'(CustomerInvoicePayment)';
634 $addbankurl =
'direct-debit';
637 $result = $paiement->addPaymentToBank($user, $modeforaddpayment, $labelforaddpayment, $fk_bank_account,
'',
'', 0,
'', $addbankurl);
641 $this->error = $paiement->error;
642 $this->errors = $paiement->errors;
643 dol_syslog(get_class($this) .
"::set_infocredit AddPaymentToBank Error " . $this->error);
651 $sql =
" UPDATE " . MAIN_DB_PREFIX .
"prelevement_lignes";
652 $sql .=
" SET statut = 2";
653 $sql .=
" WHERE fk_prelevement_bons = " . ((int) $this->
id);
655 if (!$this->db->query($sql)) {
656 dol_syslog(get_class($this) .
"::set_infocredit Update lines Error");
661 $this->error = $this->db->lasterror();
662 dol_syslog(get_class($this) .
"::set_infocredit Update Bons Error");
668 $this->date_credit = $date;
669 $this->
statut = self::STATUS_CREDITED;
670 $this->
status = self::STATUS_CREDITED;
675 $this->db->rollback();
695 global $conf, $langs;
699 dol_syslog(get_class($this) .
"::set_infotrans Start", LOG_INFO);
701 if ($this->db->begin()) {
702 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_bons ";
703 $sql .=
" SET fk_user_trans = " . $user->id;
704 $sql .=
" , date_trans = '" . $this->db->idate($date) .
"'";
705 $sql .=
" , method_trans = " . ((int) $method);
706 $sql .=
" , statut = " . self::STATUS_TRANSFERED;
707 $sql .=
" WHERE rowid = " . ((int) $this->
id);
708 $sql .=
" AND entity = " . ((int) $conf->entity);
709 $sql .=
" AND statut = " . self::STATUS_DRAFT;
711 if ($this->db->query($sql)) {
712 $this->method_trans = $method;
713 $langs->load(
'withdrawals');
714 $subject = $langs->trans(
"InfoTransSubject", $this->
ref);
715 $message = $langs->trans(
"InfoTransMessage", $this->
ref,
dolGetFirstLastname($user->firstname, $user->lastname));
716 $message .= $langs->trans(
"InfoTransData",
price($this->amount), $this->methodes_trans[$this->method_trans],
dol_print_date($date,
'day'));
724 $this->date_trans = $date;
725 $this->
statut = self::STATUS_TRANSFERED;
726 $this->
status = self::STATUS_TRANSFERED;
727 $this->user_trans = $user->id;
733 $this->db->rollback();
734 dol_syslog(get_class($this) .
"::set_infotrans ROLLBACK", LOG_ERR);
739 dol_syslog(get_class($this) .
"::set_infotrans Ouverture transaction SQL impossible", LOG_CRIT);
757 dol_syslog(get_class($this) .
"::getListInvoices");
761 if ($this->
type ==
'bank-transfer') {
762 if ($type ==
'salary') {
763 $sql .=
" p.fk_salary";
765 $sql .=
" p.fk_facture_fourn";
768 $sql .=
" p.fk_facture";
771 $sql .=
", SUM(pl.amount)";
773 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons as pb,";
774 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
775 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p";
776 $sql .=
" WHERE p.fk_prelevement_lignes = pl.rowid";
777 $sql .=
" AND pl.fk_prelevement_bons = pb.rowid";
778 $sql .=
" AND pb.rowid = " . ((int) $this->
id);
779 $sql .=
" AND pb.entity = " . ((int) $conf->entity);
781 if ($this->
type ==
'bank-transfer') {
782 if ($type ==
'salary') {
783 $sql .=
" GROUP BY p.fk_salary";
785 $sql .=
" GROUP BY p.fk_facture_fourn";
788 $sql .=
" GROUP BY p.fk_facture";
792 $resql = $this->db->query($sql);
794 $num = $this->db->num_rows($resql);
799 $row = $this->db->fetch_row($resql);
811 $this->db->free($resql);
813 $this->error = $this->db->lasterror();
830 $sql =
"SELECT sum(pd.amount) as nb";
831 if ($type !==
'salary') {
832 if ($mode !=
'bank-transfer') {
833 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f,";
835 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture_fourn as f,";
838 $sql .=
" FROM " . MAIN_DB_PREFIX .
"salary as s,";
840 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_demande as pd";
841 $sql .= ($type !==
'salary' ?
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")" :
" WHERE s.entity IN (" .
getEntity(
'salary') .
")");
843 $sql .= ($type !==
'salary' ?
" AND f.fk_statut = " .
Facture::STATUS_VALIDATED :
" AND s.paye = " . Salary::STATUS_UNPAID);
845 if ($type !==
'salary') {
846 if ($mode !=
'bank-transfer') {
847 $sql .=
" AND f.rowid = pd.fk_facture";
849 $sql .=
" AND f.rowid = pd.fk_facture_fourn";
852 $sql .=
" AND s.rowid = pd.fk_salary";
854 $sql .= ($type !==
'salary' ?
" AND f.paye = 0" :
"");
855 $sql .=
" AND pd.traite = 0";
856 $sql .=
" AND pd.ext_payment_id IS NULL";
857 $sql .= ($type !==
'salary' ?
" AND f.total_ttc > 0" :
"");
859 $resql = $this->db->query($sql);
861 $obj = $this->db->fetch_object($resql);
863 $this->db->free($resql);
868 dol_syslog(get_class($this) .
"::SommeAPrelever Erreur -1");
884 if ($type ===
'salary') {
902 if ($forsalary == 1) {
903 $sql =
"SELECT count(s.rowid) as nb";
904 $sql .=
" FROM " . MAIN_DB_PREFIX .
"salary as s";
906 $sql =
"SELECT count(f.rowid) as nb";
908 if ($type ==
'bank-transfer') {
909 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture_fourn as f";
911 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
914 $sql .=
", " . MAIN_DB_PREFIX .
"prelevement_demande as pd";
915 if ($forsalary == 1) {
916 $sql .=
" WHERE s.entity IN (" .
getEntity(
'invoice') .
")";
918 $sql .=
" AND s.paye = 0";
921 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
")";
926 if ($forsalary == 1) {
927 $sql .=
" AND s.rowid = pd.fk_salary";
929 if ($type ==
'bank-transfer') {
930 $sql .=
" AND f.rowid = pd.fk_facture_fourn";
932 $sql .=
" AND f.rowid = pd.fk_facture";
935 $sql .=
" AND pd.traite = 0";
936 $sql .=
" AND pd.ext_payment_id IS NULL";
937 if (!$forsalary == 1) {
938 $sql .=
" AND f.total_ttc > 0";
940 $sql .=
" AND s.paye = 0";
943 dol_syslog(get_class($this) .
"::NbFactureAPrelever");
944 $resql = $this->db->query($sql);
947 $obj = $this->db->fetch_object($resql);
948 $this->db->free($resql);
952 $this->error = get_class($this) .
"::NbFactureAPrelever Erreur -1 sql=" . $this->db->error();
979 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')
982 global $conf, $langs, $user;
984 dol_syslog(__METHOD__ .
" Bank=" . $banque .
" Office=" . $agence .
" mode=" . $mode .
" format=" . $format, LOG_DEBUG);
986 require_once DOL_DOCUMENT_ROOT .
"/compta/facture/class/facture.class.php";
987 require_once DOL_DOCUMENT_ROOT .
"/societe/class/societe.class.php";
990 if ($type !=
'bank-transfer') {
991 if (empty($format)) {
992 $this->error =
'ErrorBadParametersForDirectDebitFileCreate';
998 if (empty($fk_bank_account)) {
999 $fk_bank_account = ($type ==
'bank-transfer' ?
getDolGlobalInt(
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') :
getDolGlobalInt(
'PRELEVEMENT_ID_BANKACCOUNT'));
1004 $datetimeprev =
dol_now(
'gmt');
1006 if (!empty($executiondate)) {
1007 $datetimeprev = $executiondate;
1013 $this->invoice_in_error = array();
1014 $this->thirdparty_in_error = array();
1017 $factures = array();
1018 $factures_prev = array();
1019 $factures_result = array();
1020 $factures_prev_id = array();
1021 $factures_errors = array();
1023 dol_syslog(__METHOD__ .
" Read invoices for did=" . ((
int) $did), LOG_DEBUG);
1025 $sql =
"SELECT f.rowid, pd.rowid as pfdrowid";
1026 if ($sourcetype !=
'salary') {
1027 $sql .=
", f.fk_soc";
1029 $sql .=
", f.fk_user";
1031 $sql .=
", pd.code_banque, pd.code_guichet, pd.number, pd.cle_rib";
1032 $sql .=
", pd.amount";
1033 if ($sourcetype !=
'salary') {
1034 $sql .=
", s.nom as name";
1035 $sql .=
", f.ref, sr.bic, sr.iban_prefix, sr.frstrecur";
1037 $sql .=
", CONCAT(s.firstname,' ',s.lastname) as name";
1038 $sql .=
", f.ref, sr.bic, sr.iban_prefix, 'FRST' as frstrecur";
1040 if ($sourcetype !=
'salary') {
1041 if ($type !=
'bank-transfer') {
1042 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture as f";
1043 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"prelevement_demande as pd ON f.rowid = pd.fk_facture";
1045 $sql .=
" FROM " . MAIN_DB_PREFIX .
"facture_fourn as f";
1046 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"prelevement_demande as pd ON f.rowid = pd.fk_facture_fourn";
1048 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe as s ON s.rowid = f.fk_soc";
1049 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_rib as sr ON s.rowid = sr.fk_soc AND sr.default_rib = 1";
1051 $sql .=
" FROM " . MAIN_DB_PREFIX .
"salary as f";
1052 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"prelevement_demande as pd ON f.rowid = pd.fk_salary";
1053 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"user as s ON s.rowid = f.fk_user";
1054 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"user_rib as sr ON s.rowid = sr.fk_user";
1056 if ($sourcetype !=
'salary') {
1057 if ($type !=
'bank-transfer') {
1058 $sql .=
" WHERE f.entity IN (" .
getEntity(
'invoice') .
')';
1060 $sql .=
" WHERE f.entity IN (" .
getEntity(
'supplier_invoice') .
')';
1063 $sql .=
" WHERE f.entity IN (" .
getEntity(
'salary') .
')';
1065 if ($sourcetype !=
'salary') {
1066 $sql .=
" AND f.fk_statut = 1";
1067 $sql .=
" AND f.paye = 0";
1068 $sql .=
" AND f.total_ttc > 0";
1071 $sql .=
" AND f.paye = 0";
1072 $sql .=
" AND f.amount > 0";
1074 $sql .=
" AND pd.traite = 0";
1075 $sql .=
" AND pd.ext_payment_id IS NULL";
1076 if ($sourcetype !=
'salary') {
1077 $sql .=
" AND sr.type = 'ban'";
1080 $sql .=
" AND pd.rowid = " . ((int) $did);
1083 $resql = $this->db->query($sql);
1085 $num = $this->db->num_rows($resql);
1089 $row = $this->db->fetch_row($resql);
1090 $factures[$i] = $row;
1094 dol_syslog(__METHOD__ .
" Read invoices/salary error Found a null amount", LOG_ERR);
1095 $this->invoice_in_error[$row[0]] =
"Error for invoice or salary id " . $row[0] .
", found a null amount";
1101 $this->db->free($resql);
1102 dol_syslog(__METHOD__ .
" Read invoices/salary, " . $i .
" invoices/salary to withdraw", LOG_DEBUG);
1105 $this->error = $this->db->lasterror();
1106 dol_syslog(__METHOD__ .
" Read invoices/salary error " . $this->db->lasterror(), LOG_ERR);
1113 require_once DOL_DOCUMENT_ROOT .
'/societe/class/societe.class.php';
1114 require_once DOL_DOCUMENT_ROOT .
'/user/class/user.class.php';
1115 require_once DOL_DOCUMENT_ROOT .
'/societe/class/companybankaccount.class.php';
1116 require_once DOL_DOCUMENT_ROOT .
'/core/lib/bank.lib.php';
1118 $tmpsoc =
new Societe($this->db);
1119 $tmpuser =
new User($this->db);
1123 dol_syslog(__METHOD__ .
" Check BAN", LOG_DEBUG);
1125 if (count($factures) > 0) {
1126 foreach ($factures as $key => $fac) {
1138 if ($fac[8] !=
null) {
1139 if ($type !=
'bank-transfer') {
1140 if ($format ==
'FRST' && $fac[12] !=
'FRST') {
1143 if ($format ==
'RCUR' && $fac[12] !=
'RCUR') {
1154 $factures_prev[$i] = $fac;
1156 $factures_prev_id[$i] = $fac[0];
1160 if ($type !=
'bank-transfer') {
1161 $tmpsoc->id = $fac[2];
1162 $tmpsoc->name = $fac[8];
1163 $invoice_url =
"<a href='" . DOL_URL_ROOT .
'/compta/facture/card.php?facid=' . $fac[0] .
"'>" . $fac[9] .
"</a>";
1164 $this->invoice_in_error[$fac[0]] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1165 $this->thirdparty_in_error[$tmpsoc->id] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1168 if ($type ==
'bank-transfer' && $sourcetype !=
'salary') {
1169 $tmpsoc->id = $fac[2];
1170 $tmpsoc->name = $fac[8];
1171 $invoice_url =
"<a href='" . DOL_URL_ROOT .
'/fourn/facture/card.php?facid=' . $fac[0] .
"'>" . $fac[9] .
"</a>";
1172 $this->invoice_in_error[$fac[0]] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1173 $this->thirdparty_in_error[$tmpsoc->id] =
"Error on default bank number IBAN/BIC for invoice " . $invoice_url .
" for thirdparty " . $tmpsoc->getNomUrl(0);
1176 if ($type ==
'bank-transfer' && $sourcetype ==
'salary') {
1177 $tmpuser->id = $fac[2];
1178 $tmpuser->firstname = $fac[8];
1179 $salary_url =
"<a href='" . DOL_URL_ROOT .
'/salaries/card.php?id=' . $fac[0] .
"'>" . $fac[0] .
"</a>";
1180 $this->invoice_in_error[$fac[0]] =
"Error on default bank number IBAN/BIC for salary " . $salary_url .
" for employee " . $tmpuser->getNomUrl(0);
1181 $this->thirdparty_in_error[$tmpuser->id] =
"Error on default bank number IBAN/BIC for salary " . $salary_url .
" for employee " . $tmpuser->getNomUrl(0);
1184 dol_syslog(__METHOD__ .
" Check BAN Error on default bank number IBAN/BIC reported by verif(): " . implode(
', ', $fac), LOG_WARNING);
1187 dol_syslog(__METHOD__ .
" Check BAN Failed to read company", LOG_WARNING);
1196 dol_syslog(__METHOD__ .
" Check BAN No invoice to process", LOG_WARNING);
1203 $out = count($factures_prev) .
" invoices will be included.";
1216 if (count($factures_prev) > 0) {
1217 if ($mode ==
'real') {
1220 print $langs->trans(
"ModeWarning");
1237 $ref = substr($year, -2) . $month;
1240 $sql =
"SELECT substring(ref from char_length(ref) - 1)";
1241 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons";
1242 $sql .=
" WHERE ref LIKE '_" . $this->db->escape($ref) .
"%'";
1243 $sql .=
" AND entity = " . ((int) $conf->entity);
1244 $sql .=
" ORDER BY ref DESC LIMIT 1";
1246 dol_syslog(get_class($this) .
" get next free number", LOG_DEBUG);
1247 $resql = $this->db->query($sql);
1250 $row = $this->db->fetch_row($resql);
1253 $ref =
"T" . $ref . sprintf(
"%02d", (intval($row[0]) + 1));
1259 if ($type !=
'bank-transfer') {
1260 $dir = $conf->prelevement->dir_output .
'/receipts';
1262 $dir = $conf->paymentbybanktransfer->dir_output .
'/receipts';
1264 if (!is_dir($dir)) {
1268 if (isModEnabled(
'multicompany')) {
1269 $labelentity = $conf->entity;
1270 $this->filename = $dir .
'/' . $ref .
'-' . $labelentity .
'.xml';
1272 $this->filename = $dir .
'/' . $ref .
'.xml';
1276 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"prelevement_bons (";
1277 $sql .=
"ref, entity, datec, type, fk_bank_account";
1278 $sql .=
") VALUES (";
1279 $sql .=
"'" . $this->db->escape($ref) .
"'";
1280 $sql .=
", " . ((int) $conf->entity);
1281 $sql .=
", '" . $this->db->idate($now) .
"'";
1282 $sql .=
", '" . ($type ==
'bank-transfer' ?
'bank-transfer' :
'debit-order') .
"'";
1283 $sql .=
", " . ((int) $fk_bank_account);
1286 $resql = $this->db->query($sql);
1290 $prev_id = $this->db->last_insert_id(MAIN_DB_PREFIX .
"prelevement_bons");
1291 $this->
id = $prev_id;
1295 dol_syslog(__METHOD__ .
" Create withdraw receipt " . $this->db->lasterror(), LOG_ERR);
1299 dol_syslog(__METHOD__ .
" Get last withdraw receipt " . $this->db->lasterror(), LOG_ERR);
1304 dol_syslog(__METHOD__ .
" Now loop on each document to insert them in llx_prelevement_demande");
1307 if (count($factures_prev) > 0) {
1308 foreach ($factures_prev as $fac) {
1326 $ri = $this->
AddFacture($fac[0], $fac[2], $fac[8], $fac[7], $fac[3], $fac[4], $fac[5], $fac[6], $type, $sourcetype);
1333 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_demande";
1334 $sql .=
" SET traite = 1";
1335 $sql .=
", date_traite = '" . $this->db->idate($now) .
"'";
1336 $sql .=
", fk_prelevement_bons = " . ((int) $this->
id);
1337 $sql .=
" WHERE rowid = " . ((int) $fac[1]);
1339 $resql = $this->db->query($sql);
1342 $this->errors[] = $this->db->lasterror();
1343 dol_syslog(__METHOD__ .
" Update Error=" . $this->db->lasterror(), LOG_ERR);
1354 dol_syslog(__METHOD__ .
" Init direct debit or credit transfer file for " . count($factures_prev) .
" invoices", LOG_DEBUG);
1356 if (count($factures_prev) > 0) {
1357 $this->date_echeance = $datetimeprev;
1358 $this->reference_remise = $ref;
1360 $account =
new Account($this->db);
1361 if ($account->fetch($fk_bank_account) > 0) {
1362 $this->emetteur_code_banque = $account->code_banque;
1363 $this->emetteur_code_guichet = $account->code_guichet;
1364 $this->emetteur_numero_compte = $account->number;
1365 $this->emetteur_number_key = $account->cle_rib;
1366 $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
1367 $this->emetteur_iban = $account->iban;
1368 $this->emetteur_bic = $account->bic;
1370 $this->emetteur_ics = (($type ==
'bank-transfer' &&
getDolGlobalString(
"SEPA_USE_IDS")) ? $account->ics_transfer : $account->ics);
1372 $this->raison_sociale = $account->proprio;
1374 $this->factures = $factures_prev_id;
1375 $this->context[
'factures_prev'] = $factures_prev;
1379 if ($sourcetype ==
'salary') {
1380 $userid = $this->context[
'factures_prev'][0][2];
1382 $result = $this->
generate($format, $executiondate, $type, $fk_bank_account, $userid);
1389 dol_syslog(__METHOD__ .
" Bank order file has been generated under filename " . $this->filename, LOG_DEBUG);
1397 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_bons";
1398 $sql .=
" SET amount = " .
price2num($this->total);
1399 $sql .=
" WHERE rowid = " . ((int) $this->
id);
1400 $sql .=
" AND entity = " . ((int) $conf->entity);
1401 $resql = $this->db->query($sql);
1405 dol_syslog(__METHOD__ .
" Error update total: " . $this->db->error(), LOG_ERR);
1409 if (!$error && !$notrigger) {
1410 $triggername =
'DIRECT_DEBIT_ORDER_CREATE';
1411 if ($type !=
'bank-transfer') {
1412 $triggername =
'CREDIT_TRANSFER_ORDER_CREATE';
1424 $this->db->commit();
1425 return count($factures_prev);
1427 $this->db->rollback();
1443 public function delete($user =
null, $notrigger = 0)
1448 $resql1 = $resql2 = $resql3 = $resql4 = 0;
1451 $triggername =
'DIRECT_DEBIT_ORDER_DELETE';
1452 if ($this->
type ==
'bank-transfer') {
1453 $triggername =
'PAYMENTBYBANKTRANFER_DELETE';
1464 $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) .
")";
1465 $resql1 = $this->db->query($sql);
1472 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"prelevement_lignes WHERE fk_prelevement_bons = " . ((int) $this->
id);
1473 $resql2 = $this->db->query($sql);
1480 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"prelevement_bons WHERE rowid = " . ((int) $this->
id);
1481 $resql3 = $this->db->query($sql);
1488 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"prelevement_demande SET fk_prelevement_bons = NULL, traite = 0 WHERE fk_prelevement_bons = " . ((int) $this->
id);
1489 $resql4 = $this->db->query($sql);
1495 if ($resql1 && $resql2 && $resql3 && $resql4 && !$error) {
1496 $this->db->commit();
1499 $this->db->rollback();
1515 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1517 global $conf, $langs, $hookmanager;
1519 if (!empty($conf->dol_no_mouse_hover)) {
1525 $labeltoshow =
'PaymentByDirectDebit';
1526 if (!empty($this->
type) && $this->
type ==
'bank-transfer') {
1527 $labeltoshow =
'PaymentByBankTransfer';
1530 $label =
img_picto(
'', $this->picto) .
' <u>' . $langs->trans($labeltoshow) .
'</u> ' . $this->
getLibStatut(5);
1532 $label .=
'<b>' . $langs->trans(
'Ref') .
':</b> ' . $this->ref;
1533 if (isset($this->amount)) {
1534 $label .=
'<br><b>' . $langs->trans(
"Amount") .
":</b> " .
price($this->amount);
1536 if (isset($this->date_trans)) {
1537 $label .=
'<br><b>' . $langs->trans(
"TransData") .
":</b> " .
dol_print_date($this->date_trans,
'dayhour',
'tzuserrel');
1543 $url = DOL_URL_ROOT .
'/compta/prelevement/card.php?id=' . $this->id;
1544 if (!empty($this->
type) && $this->
type ==
'bank-transfer') {
1545 $url = DOL_URL_ROOT .
'/compta/prelevement/card.php?id=' . $this->id;
1548 if ($option !=
'nolink') {
1550 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1551 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1552 $add_save_lastsearch_values = 1;
1554 if ($add_save_lastsearch_values) {
1555 $url .=
'&save_lastsearch_values=1';
1560 if (empty($notooltip)) {
1562 $label = $langs->trans(
"ShowMyObject");
1566 $linkclose .=
' class="classfortooltip' . ($morecss ?
' ' . $morecss :
'') .
'"';
1568 $linkclose = ($morecss ?
' class="' . $morecss .
'"' :
'');
1571 $linkstart =
'<a href="' . $url .
'"';
1572 $linkstart .= $linkclose .
'>';
1575 $result .= $linkstart;
1577 $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);
1579 if ($withpicto != 2) {
1580 $result .= $this->ref;
1582 $result .= $linkend;
1584 global $action, $hookmanager;
1585 $hookmanager->initHooks(array(
'banktransferdao'));
1586 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1587 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1589 $result = $hookmanager->resPrint;
1591 $result .= $hookmanager->resPrint;
1606 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"notify_def";
1607 $sql .=
" WHERE rowid = " . ((int) $rowid);
1609 if ($this->db->query($sql)) {
1625 if (is_object($user)) {
1626 $userid = $user->id;
1631 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"notify_def";
1632 $sql .=
" WHERE fk_user=" . ((int) $userid) .
" AND fk_action='" . $this->db->escape($action) .
"'";
1634 if ($this->db->query($sql)) {
1655 if (is_object($user)) {
1656 $userid = $user->id;
1664 $sql =
"INSERT INTO " . MAIN_DB_PREFIX .
"notify_def (datec,fk_user, fk_soc, fk_contact, fk_action)";
1665 $sql .=
" VALUES ('" . $this->db->idate($now) .
"', " . ((int) $userid) .
", 'NULL', 'NULL', '" . $this->db->escape($action) .
"')";
1668 if ($this->db->query($sql)) {
1672 dol_syslog(get_class($this) .
"::addNotification Error $result");
1694 public function generate($format =
'ALL', $executiondate = 0, $type =
'direct-debit', $fk_bank_account = 0, $forsalary = 0)
1696 global $conf, $langs, $mysoc;
1701 if (empty($fk_bank_account)) {
1702 $fk_bank_account = ($type ==
'bank-transfer' ?
getDolGlobalInt(
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') :
getDolGlobalInt(
'PRELEVEMENT_ID_BANKACCOUNT'));
1707 dol_syslog(get_class($this) .
"::generate build file=" . $this->filename .
" type=" . $type);
1709 $this->file = fopen($this->filename,
"w");
1710 if ($this->file ==
false) {
1711 $this->error = $langs->trans(
'ErrorFailedToOpenFile', $this->filename);
1719 if ($mysoc->isInEEC()) {
1722 if ($type !=
'bank-transfer') {
1734 if (!empty($executiondate)) {
1735 $date_actu = $executiondate;
1740 $fileDebiteurSection =
'';
1741 $fileEmetteurSection =
'';
1748 $sql =
"SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
1749 $sql .=
" pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
1750 $sql .=
" f.ref as reffac, p.fk_facture as idfac,";
1751 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
1753 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
1754 $sql .=
" " . MAIN_DB_PREFIX .
"facture as f,";
1755 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p,";
1756 $sql .=
" " . MAIN_DB_PREFIX .
"societe as soc,";
1757 $sql .=
" " . MAIN_DB_PREFIX .
"c_country as c,";
1758 $sql .=
" " . MAIN_DB_PREFIX .
"societe_rib as rib";
1759 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
1760 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
1761 $sql .=
" AND p.fk_facture = f.rowid";
1762 $sql .=
" AND f.fk_soc = soc.rowid";
1763 $sql .=
" AND soc.fk_pays = c.rowid";
1764 $sql .=
" AND rib.fk_soc = f.fk_soc";
1765 $sql .=
" AND rib.default_rib = 1";
1766 $sql .=
" AND rib.type = 'ban'";
1769 $resql = $this->db->query($sql);
1771 $cachearraytotestduplicate = array();
1773 $num = $this->db->num_rows($resql);
1775 $obj = $this->db->fetch_object($resql);
1777 if (!empty($cachearraytotestduplicate[$obj->idfac])) {
1778 $this->error = $langs->trans(
'ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
1779 $this->invoice_in_error[$obj->idfac] = $this->error;
1783 $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
1785 $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
1787 $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);
1789 $this->total = $this->total + $obj->somme;
1792 $nbtotalDrctDbtTxInf = $i;
1794 $this->error = $this->db->lasterror();
1795 fwrite($this->file,
'ERROR DEBITOR ' . $sql . $CrLf);
1800 if ($result != -2) {
1801 $fileEmetteurSection .= $this->
EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type, $fk_bank_account);
1805 $this->total = number_format((
float)
price2num($this->total,
'MT'), 2,
".",
"");
1812 fwrite($this->file,
'<' .
'?xml version="1.0" encoding="UTF-8" standalone="yes"?' .
'>' . $CrLf);
1813 fwrite($this->file,
'<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.008.001.02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' . $CrLf);
1814 fwrite($this->file,
' <CstmrDrctDbtInitn>' . $CrLf);
1816 fwrite($this->file,
' <GrpHdr>' . $CrLf);
1817 fwrite($this->file,
' <MsgId>' . (
'DD/' . $dateTime_YMD .
'/REF' . $this->
id) .
'</MsgId>' . $CrLf);
1818 fwrite($this->file,
' <CreDtTm>' . $dateTime_ECMA .
'</CreDtTm>' . $CrLf);
1819 fwrite($this->file,
' <NbOfTxs>' . $i .
'</NbOfTxs>' . $CrLf);
1820 fwrite($this->file,
' <CtrlSum>' . $this->total .
'</CtrlSum>' . $CrLf);
1821 fwrite($this->file,
' <InitgPty>' . $CrLf);
1823 fwrite($this->file,
' <Id>' . $CrLf);
1824 fwrite($this->file,
' <PrvtId>' . $CrLf);
1825 fwrite($this->file,
' <Othr>' . $CrLf);
1826 fwrite($this->file,
' <Id>' . $this->emetteur_ics .
'</Id>' . $CrLf);
1827 fwrite($this->file,
' </Othr>' . $CrLf);
1828 fwrite($this->file,
' </PrvtId>' . $CrLf);
1829 fwrite($this->file,
' </Id>' . $CrLf);
1830 fwrite($this->file,
' </InitgPty>' . $CrLf);
1831 fwrite($this->file,
' </GrpHdr>' . $CrLf);
1833 if ($result != -2) {
1834 fwrite($this->file, $fileEmetteurSection);
1837 if ($result != -2) {
1838 fwrite($this->file, $fileDebiteurSection);
1841 fwrite($this->file,
' </PmtInf>' . $CrLf);
1842 fwrite($this->file,
' </CstmrDrctDbtInitn>' . $CrLf);
1843 fwrite($this->file,
'</Document>' . $CrLf);
1856 if (!empty($executiondate)) {
1857 $date_actu = $executiondate;
1862 $fileCrediteurSection =
'';
1863 $fileEmetteurSection =
'';
1869 if (!empty($forsalary)) {
1870 $sql =
"SELECT u.rowid as userId, u.address, u.zip, u.town, c.code as country_code, CONCAT(u.firstname,' ',u.lastname) as nom,";
1871 $sql .=
" pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
1872 $sql .=
" s.ref as reffac, p.fk_salary as idfac,";
1873 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, '' as rum, '' as date_rum";
1875 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
1876 $sql .=
" " . MAIN_DB_PREFIX .
"salary as s,";
1877 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p,";
1878 $sql .=
" " . MAIN_DB_PREFIX .
"user as u";
1879 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"c_country as c ON u.fk_country = c.rowid,";
1880 $sql .=
" " . MAIN_DB_PREFIX .
"user_rib as rib";
1881 $sql .=
" WHERE pl.fk_prelevement_bons=" . ((int) $this->
id);
1882 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
1883 $sql .=
" AND p.fk_salary = s.rowid";
1884 $sql .=
" AND s.fk_user = u.rowid";
1885 $sql .=
" AND rib.fk_user = s.fk_user";
1887 $sql =
"SELECT soc.rowid as socid, soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
1888 $sql .=
" pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
1889 $sql .=
" f.ref as reffac, f.ref_supplier as fac_ref_supplier, p.fk_facture_fourn as idfac,";
1890 $sql .=
" rib.rowid, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum, rib.rum, rib.date_rum";
1892 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
1893 $sql .=
" " . MAIN_DB_PREFIX .
"facture_fourn as f,";
1894 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p,";
1895 $sql .=
" " . MAIN_DB_PREFIX .
"societe as soc";
1896 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"c_country as c ON soc.fk_pays = c.rowid,";
1897 $sql .=
" " . MAIN_DB_PREFIX .
"societe_rib as rib";
1898 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
1899 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
1900 $sql .=
" AND p.fk_facture_fourn = f.rowid";
1901 $sql .=
" AND f.fk_soc = soc.rowid";
1902 $sql .=
" AND rib.fk_soc = f.fk_soc";
1903 $sql .=
" AND rib.default_rib = 1";
1904 $sql .=
" AND rib.type = 'ban'";
1907 $resql = $this->db->query($sql);
1909 $cachearraytotestduplicate = array();
1911 $num = $this->db->num_rows($resql);
1913 $obj = $this->db->fetch_object($resql);
1914 if (!empty($cachearraytotestduplicate[$obj->idfac])) {
1915 $this->error = $langs->trans(
'ErrorCompanyHasDuplicateDefaultBAN', $obj->socid);
1916 $this->invoice_in_error[$obj->idfac] = $this->error;
1920 $cachearraytotestduplicate[$obj->idfac] = $obj->rowid;
1922 $daterum = (!empty($obj->date_rum)) ? $this->db->jdate($obj->date_rum) : $this->db->jdate($obj->datec);
1923 $refobj = $obj->reffac;
1924 if (empty($refobj) && !empty($forsalary)) {
1925 $refobj =
"SAL" . $obj->idfac;
1928 $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);
1930 $this->total = $this->total + $obj->somme;
1933 $nbtotalDrctDbtTxInf = $i;
1935 $this->error = $this->db->lasterror();
1936 fwrite($this->file,
'ERROR CREDITOR ' . $sql . $CrLf);
1940 if ($result != -2) {
1941 $fileEmetteurSection .= $this->
EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format, $type);
1945 $this->total = number_format((
float)
price2num($this->total,
'MT'), 2,
".",
"");
1952 fwrite($this->file,
'<' .
'?xml version="1.0" encoding="UTF-8" standalone="yes"?' .
'>' . $CrLf);
1953 fwrite($this->file,
'<Document xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' . $CrLf);
1954 fwrite($this->file,
' <CstmrCdtTrfInitn>' . $CrLf);
1956 fwrite($this->file,
' <GrpHdr>' . $CrLf);
1957 fwrite($this->file,
' <MsgId>' . (
'TRF/' . $dateTime_YMD .
'/REF' . $this->
id) .
'</MsgId>' . $CrLf);
1958 fwrite($this->file,
' <CreDtTm>' . $dateTime_ECMA .
'</CreDtTm>' . $CrLf);
1959 fwrite($this->file,
' <NbOfTxs>' . $i .
'</NbOfTxs>' . $CrLf);
1960 fwrite($this->file,
' <CtrlSum>' . $this->total .
'</CtrlSum>' . $CrLf);
1961 fwrite($this->file,
' <InitgPty>' . $CrLf);
1963 fwrite($this->file,
' <Id>' . $CrLf);
1964 fwrite($this->file,
' <PrvtId>' . $CrLf);
1965 fwrite($this->file,
' <Othr>' . $CrLf);
1966 fwrite($this->file,
' <Id>' . $this->emetteur_ics .
'</Id>' . $CrLf);
1967 fwrite($this->file,
' </Othr>' . $CrLf);
1968 fwrite($this->file,
' </PrvtId>' . $CrLf);
1969 fwrite($this->file,
' </Id>' . $CrLf);
1970 fwrite($this->file,
' </InitgPty>' . $CrLf);
1971 fwrite($this->file,
' </GrpHdr>' . $CrLf);
1973 if ($result != -2) {
1974 fwrite($this->file, $fileEmetteurSection);
1977 if ($result != -2) {
1978 fwrite($this->file, $fileCrediteurSection);
1981 fwrite($this->file,
' </PmtInf>' . $CrLf);
1982 fwrite($this->file,
' </CstmrCdtTrfInitn>' . $CrLf);
1983 fwrite($this->file,
'</Document>' . $CrLf);
1989 if ($type !=
'bank-transfer') {
1990 $sql =
"SELECT pl.amount";
1992 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
1993 $sql .=
" " . MAIN_DB_PREFIX .
"facture as f,";
1994 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p";
1995 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
1996 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
1997 $sql .=
" AND p.fk_facture = f.rowid";
2001 $resql = $this->db->query($sql);
2003 $num = $this->db->num_rows($resql);
2006 $obj = $this->db->fetch_object($resql);
2007 $this->total = $this->total + $obj->amount;
2016 $sql =
"SELECT pl.amount";
2018 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement_lignes as pl,";
2019 $sql .=
" " . MAIN_DB_PREFIX .
"facture_fourn as f,";
2020 $sql .=
" " . MAIN_DB_PREFIX .
"prelevement as p";
2021 $sql .=
" WHERE pl.fk_prelevement_bons = " . ((int) $this->
id);
2022 $sql .=
" AND pl.rowid = p.fk_prelevement_lignes";
2023 $sql .=
" AND p.fk_facture_fourn = f.rowid";
2026 $resql = $this->db->query($sql);
2028 $num = $this->db->num_rows($resql);
2031 $obj = $this->db->fetch_object($resql);
2032 $this->total = $this->total + $obj->amount;
2042 $langs->load(
'withdrawals');
2045 fwrite($this->file, $langs->transnoentitiesnoconv(
'WithdrawalFileNotCapable', $mysoc->country_code));
2048 fclose($this->file);
2070 return $pre .
'-' .
dol_print_date($row_datec,
'dayhourlogsmall') .
'-' .
dol_trunc($row_drum . ($row_code_client ?
'-' . $row_code_client :
''), 13,
'right',
'UTF-8', 1);
2091 public function EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $ref, $facid, $rib_dom =
'', $type =
'direct-debit')
2094 fwrite($this->file,
"06");
2095 fwrite($this->file,
"08");
2097 fwrite($this->file,
" ");
2099 fwrite($this->file, $this->emetteur_ics);
2103 fwrite($this->file,
" ");
2104 fwrite($this->file,
dol_print_date($this->date_echeance,
"%d%m",
'gmt'));
2105 fwrite($this->file, substr(
dol_print_date($this->date_echeance,
"%y",
'gmt'), 1));
2109 fwrite($this->file, substr(strtoupper($client_nom) .
" ", 0, 24));
2112 $address = strtr($rib_dom, array(
" " =>
"-", chr(13) =>
" ", chr(10) =>
""));
2113 fwrite($this->file, substr($address .
" ", 0, 24));
2117 fwrite($this->file, substr(
" ", 0, 8));
2121 fwrite($this->file, $rib_guichet);
2125 fwrite($this->file, substr(
"000000000000000" . $rib_number, -11));
2129 $montant = (round($amount, 2) * 100);
2131 fwrite($this->file, substr(
"000000000000000" . $montant, -16));
2135 fwrite($this->file, substr(
"*_" . $ref .
"_RDVnet" . $rowid .
" ", 0, 31));
2139 fwrite($this->file, $rib_banque);
2143 fwrite($this->file, substr(
" ", 0, 5));
2145 fwrite($this->file,
"\n");
2175 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 =
'')
2181 $row_somme = number_format((
float)
price2num($row_somme,
'MT'), 2,
".",
"");
2183 $row_somme = round((
float) $row_somme, 2);
2186 include_once DOL_DOCUMENT_ROOT .
'/core/lib/functions2.lib.php';
2189 $Rowing = sprintf(
"%010d", $row_idfac);
2193 $Rum = (empty($row_rum) ? $this->
buildRumNumber($row_code_client, $row_datec, $row_drum) : $row_rum);
2198 if ($type !=
'bank-transfer') {
2201 $XML_DEBITOR .=
' <DrctDbtTxInf>' . $CrLf;
2202 $XML_DEBITOR .=
' <PmtId>' . $CrLf;
2204 $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;
2205 $XML_DEBITOR .=
' </PmtId>' . $CrLf;
2206 $XML_DEBITOR .=
' <InstdAmt Ccy="EUR">' . $row_somme .
'</InstdAmt>' . $CrLf;
2207 $XML_DEBITOR .=
' <DrctDbtTx>' . $CrLf;
2208 $XML_DEBITOR .=
' <MndtRltdInf>' . $CrLf;
2209 $XML_DEBITOR .=
' <MndtId>' . $Rum .
'</MndtId>' . $CrLf;
2210 $XML_DEBITOR .=
' <DtOfSgntr>' . $DtOfSgntr .
'</DtOfSgntr>' . $CrLf;
2211 $XML_DEBITOR .=
' <AmdmntInd>false</AmdmntInd>' . $CrLf;
2212 $XML_DEBITOR .=
' </MndtRltdInf>' . $CrLf;
2213 $XML_DEBITOR .=
' </DrctDbtTx>' . $CrLf;
2214 $XML_DEBITOR .=
' <DbtrAgt>' . $CrLf;
2215 $XML_DEBITOR .=
' <FinInstnId>' . $CrLf;
2216 $XML_DEBITOR .=
' <BIC>' . $row_bic .
'</BIC>' . $CrLf;
2217 $XML_DEBITOR .=
' </FinInstnId>' . $CrLf;
2218 $XML_DEBITOR .=
' </DbtrAgt>' . $CrLf;
2219 $XML_DEBITOR .=
' <Dbtr>' . $CrLf;
2221 $XML_DEBITOR .=
' <PstlAdr>' . $CrLf;
2222 $XML_DEBITOR .=
' <Ctry>' . $row_country_code .
'</Ctry>' . $CrLf;
2223 $addressline1 = strtr($row_address, array(chr(13) =>
", ", chr(10) =>
""));
2224 $addressline2 = strtr($row_zip . (($row_zip && $row_town) ?
' ' : (string) $row_town), array(chr(13) =>
", ", chr(10) =>
""));
2225 if (trim($addressline1)) {
2228 if (trim($addressline2)) {
2231 $XML_DEBITOR .=
' </PstlAdr>' . $CrLf;
2232 $XML_DEBITOR .=
' </Dbtr>' . $CrLf;
2233 $XML_DEBITOR .=
' <DbtrAcct>' . $CrLf;
2234 $XML_DEBITOR .=
' <Id>' . $CrLf;
2235 $XML_DEBITOR .=
' <IBAN>' . preg_replace(
'/\s/',
'', $row_iban) .
'</IBAN>' . $CrLf;
2236 $XML_DEBITOR .=
' </Id>' . $CrLf;
2237 $XML_DEBITOR .=
' </DbtrAcct>' . $CrLf;
2238 $XML_DEBITOR .=
' <RmtInf>' . $CrLf;
2241 $XML_DEBITOR .=
' </RmtInf>' . $CrLf;
2242 $XML_DEBITOR .=
' </DrctDbtTxInf>' . $CrLf;
2243 return $XML_DEBITOR;
2247 $XML_CREDITOR .=
' <CdtTrfTxInf>' . $CrLf;
2248 $XML_CREDITOR .=
' <PmtId>' . $CrLf;
2250 $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;
2251 $XML_CREDITOR .=
' </PmtId>' . $CrLf;
2252 if (!empty($this->sepa_xml_pti_in_ctti)) {
2253 $XML_CREDITOR .=
' <PmtTpInf>' . $CrLf;
2257 $instrprty =
'HIGH';
2259 $instrprty =
'NORM';
2261 $XML_CREDITOR .=
' <InstrPrty>' . $instrprty .
'</InstrPrty>' . $CrLf;
2262 $XML_CREDITOR .=
' <SvcLvl>' . $CrLf;
2263 $XML_CREDITOR .=
' <Cd>SEPA</Cd>' . $CrLf;
2264 $XML_CREDITOR .=
' </SvcLvl>' . $CrLf;
2265 $XML_CREDITOR .=
' <CtgyPurp>' . $CrLf;
2266 $XML_CREDITOR .=
' <Cd>CORE</Cd>' . $CrLf;
2267 $XML_CREDITOR .=
' </CtgyPurp>' . $CrLf;
2268 $XML_CREDITOR .=
' </PmtTpInf>' . $CrLf;
2270 $XML_CREDITOR .=
' <Amt>' . $CrLf;
2271 $XML_CREDITOR .=
' <InstdAmt Ccy="EUR">'.round((
float) $row_somme, 2).
'</InstdAmt>'.$CrLf;
2272 $XML_CREDITOR .=
' </Amt>' . $CrLf;
2283 $XML_CREDITOR .=
' <CdtrAgt>' . $CrLf;
2284 $XML_CREDITOR .=
' <FinInstnId>' . $CrLf;
2285 $XML_CREDITOR .=
' <BIC>' . $row_bic .
'</BIC>' . $CrLf;
2286 $XML_CREDITOR .=
' </FinInstnId>' . $CrLf;
2287 $XML_CREDITOR .=
' </CdtrAgt>' . $CrLf;
2288 $XML_CREDITOR .=
' <Cdtr>' . $CrLf;
2290 $XML_CREDITOR .=
' <PstlAdr>' . $CrLf;
2291 $XML_CREDITOR .=
' <Ctry>' . $row_country_code .
'</Ctry>' . $CrLf;
2292 $addressline1 = strtr($row_address, array(chr(13) =>
", ", chr(10) =>
""));
2293 $addressline2 = strtr($row_zip . (($row_zip && $row_town) ?
' ' : (string) $row_town), array(chr(13) =>
", ", chr(10) =>
""));
2294 if (trim($addressline1)) {
2297 if (trim($addressline2)) {
2300 $XML_CREDITOR .=
' </PstlAdr>' . $CrLf;
2301 $XML_CREDITOR .=
' </Cdtr>' . $CrLf;
2302 $XML_CREDITOR .=
' <CdtrAcct>' . $CrLf;
2303 $XML_CREDITOR .=
' <Id>' . $CrLf;
2304 $XML_CREDITOR .=
' <IBAN>' . preg_replace(
'/\s/',
'', $row_iban) .
'</IBAN>' . $CrLf;
2305 $XML_CREDITOR .=
' </Id>' . $CrLf;
2306 $XML_CREDITOR .=
' </CdtrAcct>' . $CrLf;
2307 $XML_CREDITOR .=
' <RmtInf>' . $CrLf;
2310 $XML_CREDITOR .=
' </RmtInf>' . $CrLf;
2311 $XML_CREDITOR .=
' </CdtTrfTxInf>' . $CrLf;
2312 return $XML_CREDITOR;
2328 fwrite($this->file,
"03");
2329 fwrite($this->file,
"08");
2331 fwrite($this->file,
" ");
2333 fwrite($this->file, $this->emetteur_ics);
2337 fwrite($this->file,
" ");
2338 fwrite($this->file,
dol_print_date($this->date_echeance,
"%d%m",
'gmt'));
2339 fwrite($this->file, substr(
dol_print_date($this->date_echeance,
"%y",
'gmt'), 1));
2343 fwrite($this->file, substr($this->raison_sociale .
" ", 0, 24));
2347 fwrite($this->file, substr($this->reference_remise .
" ", 0, 7));
2351 fwrite($this->file, substr(
" ", 0, 17));
2355 fwrite($this->file, substr(
" ", 0, 2));
2356 fwrite($this->file,
"E");
2357 fwrite($this->file, substr(
" ", 0, 5));
2361 fwrite($this->file, $this->emetteur_code_guichet);
2365 fwrite($this->file, substr(
"000000000000000" . $this->emetteur_numero_compte, -11));
2369 fwrite($this->file, substr(
" ", 0, 16));
2373 fwrite($this->file, substr(
" ", 0, 31));
2377 fwrite($this->file, $this->emetteur_code_banque);
2381 fwrite($this->file, substr(
" ", 0, 5));
2383 fwrite($this->file,
"\n");
2403 public function EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf =
'\n', $format =
'FRST', $type =
'direct-debit', $fk_bank_account = 0)
2413 if (empty($fk_bank_account)) {
2414 $fk_bank_account = ($type ==
'bank-transfer' ?
getDolGlobalInt(
'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT') :
getDolGlobalInt(
'PRELEVEMENT_ID_BANKACCOUNT'));
2418 $account =
new Account($this->db);
2419 if ($account->fetch($fk_bank_account) > 0) {
2420 $this->emetteur_code_banque = $account->code_banque;
2421 $this->emetteur_code_guichet = $account->code_guichet;
2422 $this->emetteur_numero_compte = $account->number;
2423 $this->emetteur_number_key = $account->cle_rib;
2424 $this->sepa_xml_pti_in_ctti = (bool) $account->pti_in_ctti;
2425 $this->emetteur_iban = $account->iban;
2426 $this->emetteur_bic = $account->bic;
2428 $this->emetteur_ics = (($type ==
'bank-transfer' &&
getDolGlobalString(
"SEPA_USE_IDS")) ? $account->ics_transfer : $account->ics);
2430 $this->raison_sociale = $account->proprio;
2434 $sql =
"SELECT rowid, ref";
2435 $sql .=
" FROM " . MAIN_DB_PREFIX .
"prelevement_bons as pb";
2436 $sql .=
" WHERE pb.rowid = " . ((int) $this->
id);
2438 $resql = $this->db->query($sql);
2440 $obj = $this->db->fetch_object($resql);
2442 $country = explode(
':', $configuration->global->MAIN_INFO_SOCIETE_COUNTRY);
2443 $IdBon = sprintf(
"%05d", $obj->rowid);
2444 $RefBon = $obj->ref;
2446 if (!empty($configuration->global->SEPA_FORCE_TWO_DECIMAL)) {
2447 $total = number_format((
float)
price2num($total,
'MT'), 2,
".",
"");
2450 if ($type !=
'bank-transfer') {
2452 $XML_SEPA_INFO =
'';
2453 $XML_SEPA_INFO .=
' <PmtInf>' . $CrLf;
2454 $XML_SEPA_INFO .=
' <PmtInfId>' . (
'DD/' . $dateTime_YMD .
'/ID' . $IdBon .
'-' . $RefBon) .
'</PmtInfId>' . $CrLf;
2455 $XML_SEPA_INFO .=
' <PmtMtd>DD</PmtMtd>' . $CrLf;
2456 $XML_SEPA_INFO .=
' <NbOfTxs>' . $nombre .
'</NbOfTxs>' . $CrLf;
2457 $XML_SEPA_INFO .=
' <CtrlSum>' . $total .
'</CtrlSum>' . $CrLf;
2458 $XML_SEPA_INFO .=
' <PmtTpInf>' . $CrLf;
2459 $XML_SEPA_INFO .=
' <SvcLvl>' . $CrLf;
2460 $XML_SEPA_INFO .=
' <Cd>SEPA</Cd>' . $CrLf;
2461 $XML_SEPA_INFO .=
' </SvcLvl>' . $CrLf;
2462 $XML_SEPA_INFO .=
' <LclInstrm>' . $CrLf;
2463 $XML_SEPA_INFO .=
' <Cd>CORE</Cd>' . $CrLf;
2464 $XML_SEPA_INFO .=
' </LclInstrm>' . $CrLf;
2465 $XML_SEPA_INFO .=
' <SeqTp>' . $format .
'</SeqTp>' . $CrLf;
2466 $XML_SEPA_INFO .=
' </PmtTpInf>' . $CrLf;
2467 $XML_SEPA_INFO .=
' <ReqdColltnDt>' . $dateTime_ETAD .
'</ReqdColltnDt>' . $CrLf;
2468 $XML_SEPA_INFO .=
' <Cdtr>' . $CrLf;
2470 $XML_SEPA_INFO .=
' <PstlAdr>' . $CrLf;
2471 $XML_SEPA_INFO .=
' <Ctry>' . $country[1] .
'</Ctry>' . $CrLf;
2472 $addressline1 = strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(chr(13) =>
", ", chr(10) =>
""));
2473 $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) =>
""));
2474 if ($addressline1) {
2477 if ($addressline2) {
2480 $XML_SEPA_INFO .=
' </PstlAdr>' . $CrLf;
2481 $XML_SEPA_INFO .=
' </Cdtr>' . $CrLf;
2482 $XML_SEPA_INFO .=
' <CdtrAcct>' . $CrLf;
2483 $XML_SEPA_INFO .=
' <Id>' . $CrLf;
2484 $XML_SEPA_INFO .=
' <IBAN>' . preg_replace(
'/\s/',
'', $this->emetteur_iban) .
'</IBAN>' . $CrLf;
2485 $XML_SEPA_INFO .=
' </Id>' . $CrLf;
2486 $XML_SEPA_INFO .=
' </CdtrAcct>' . $CrLf;
2487 $XML_SEPA_INFO .=
' <CdtrAgt>' . $CrLf;
2488 $XML_SEPA_INFO .=
' <FinInstnId>' . $CrLf;
2489 $XML_SEPA_INFO .=
' <BIC>' . $this->emetteur_bic .
'</BIC>' . $CrLf;
2490 $XML_SEPA_INFO .=
' </FinInstnId>' . $CrLf;
2491 $XML_SEPA_INFO .=
' </CdtrAgt>' . $CrLf;
2500 $XML_SEPA_INFO .=
' <ChrgBr>SLEV</ChrgBr>' . $CrLf;
2501 $XML_SEPA_INFO .=
' <CdtrSchmeId>' . $CrLf;
2502 $XML_SEPA_INFO .=
' <Id>' . $CrLf;
2503 $XML_SEPA_INFO .=
' <PrvtId>' . $CrLf;
2504 $XML_SEPA_INFO .=
' <Othr>' . $CrLf;
2505 $XML_SEPA_INFO .=
' <Id>' . $this->emetteur_ics .
'</Id>' . $CrLf;
2506 $XML_SEPA_INFO .=
' <SchmeNm>' . $CrLf;
2507 $XML_SEPA_INFO .=
' <Prtry>SEPA</Prtry>' . $CrLf;
2508 $XML_SEPA_INFO .=
' </SchmeNm>' . $CrLf;
2509 $XML_SEPA_INFO .=
' </Othr>' . $CrLf;
2510 $XML_SEPA_INFO .=
' </PrvtId>' . $CrLf;
2511 $XML_SEPA_INFO .=
' </Id>' . $CrLf;
2512 $XML_SEPA_INFO .=
' </CdtrSchmeId>' . $CrLf;
2515 $XML_SEPA_INFO =
'';
2516 $XML_SEPA_INFO .=
' <PmtInf>' . $CrLf;
2517 $XML_SEPA_INFO .=
' <PmtInfId>' . (
'TRF/' . $dateTime_YMD .
'/ID' . $IdBon .
'-' . $RefBon) .
'</PmtInfId>' . $CrLf;
2518 $XML_SEPA_INFO .=
' <PmtMtd>TRF</PmtMtd>' . $CrLf;
2520 $XML_SEPA_INFO .=
' <NbOfTxs>' . $nombre .
'</NbOfTxs>' . $CrLf;
2521 $XML_SEPA_INFO .=
' <CtrlSum>' . $total .
'</CtrlSum>' . $CrLf;
2522 if (!empty($this->sepa_xml_pti_in_ctti) && !empty($format)) {
2523 $XML_SEPA_INFO .=
' <PmtTpInf>' . $CrLf;
2524 $XML_SEPA_INFO .=
' <SvcLvl>' . $CrLf;
2525 $XML_SEPA_INFO .=
' <Cd>SEPA</Cd>' . $CrLf;
2526 $XML_SEPA_INFO .=
' </SvcLvl>' . $CrLf;
2527 $XML_SEPA_INFO .=
' <LclInstrm>' . $CrLf;
2528 $XML_SEPA_INFO .=
' <Cd>CORE</Cd>' . $CrLf;
2529 $XML_SEPA_INFO .=
' </LclInstrm>' . $CrLf;
2530 $XML_SEPA_INFO .=
' <SeqTp>' . $format .
'</SeqTp>' . $CrLf;
2531 $XML_SEPA_INFO .=
' </PmtTpInf>' . $CrLf;
2533 $XML_SEPA_INFO .=
' <ReqdExctnDt>' .
dol_print_date($dateTime_ETAD,
'dayrfc') .
'</ReqdExctnDt>' . $CrLf;
2534 $XML_SEPA_INFO .=
' <Dbtr>' . $CrLf;
2536 $XML_SEPA_INFO .=
' <PstlAdr>' . $CrLf;
2537 $XML_SEPA_INFO .=
' <Ctry>' . $country[1] .
'</Ctry>' . $CrLf;
2538 $addressline1 = strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(chr(13) =>
", ", chr(10) =>
""));
2539 $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) =>
""));
2540 if ($addressline1) {
2543 if ($addressline2) {
2546 $XML_SEPA_INFO .=
' </PstlAdr>' . $CrLf;
2547 $XML_SEPA_INFO .=
' </Dbtr>' . $CrLf;
2548 $XML_SEPA_INFO .=
' <DbtrAcct>' . $CrLf;
2549 $XML_SEPA_INFO .=
' <Id>' . $CrLf;
2550 $XML_SEPA_INFO .=
' <IBAN>' . preg_replace(
'/\s/',
'', $this->emetteur_iban) .
'</IBAN>' . $CrLf;
2551 $XML_SEPA_INFO .=
' </Id>' . $CrLf;
2552 $XML_SEPA_INFO .=
' </DbtrAcct>' . $CrLf;
2553 $XML_SEPA_INFO .=
' <DbtrAgt>' . $CrLf;
2554 $XML_SEPA_INFO .=
' <FinInstnId>' . $CrLf;
2555 $XML_SEPA_INFO .=
' <BIC>' . $this->emetteur_bic .
'</BIC>' . $CrLf;
2556 $XML_SEPA_INFO .=
' </FinInstnId>' . $CrLf;
2557 $XML_SEPA_INFO .=
' </DbtrAgt>' . $CrLf;
2566 $XML_SEPA_INFO .=
' <ChrgBr>SLEV</ChrgBr>' . $CrLf;
2581 fwrite($this->file,
'INCORRECT EMETTEUR ' . $this->raison_sociale . $CrLf);
2582 $XML_SEPA_INFO =
'';
2584 return $XML_SEPA_INFO;
2597 fwrite($this->file,
"08");
2598 fwrite($this->file,
"08");
2600 fwrite($this->file,
" ");
2602 fwrite($this->file, $this->emetteur_ics);
2606 fwrite($this->file, substr(
" ", 0, 12));
2611 fwrite($this->file, substr(
" ", 0, 24));
2615 fwrite($this->file, substr(
" ", 0, 24));
2619 fwrite($this->file, substr(
" ", 0, 8));
2623 fwrite($this->file, substr(
" ", 0, 5));
2627 fwrite($this->file, substr(
" ", 0, 11));
2631 $montant = ($total * 100);
2633 fwrite($this->file, substr(
"000000000000000" . $montant, -16));
2637 fwrite($this->file, substr(
" ", 0, 31));
2641 fwrite($this->file, substr(
" ", 0, 5));
2645 fwrite($this->file, substr(
" ", 0, 5));
2647 fwrite($this->file,
"\n");
2672 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
2675 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'StatusWaiting');
2676 $this->labelStatus[self::STATUS_TRANSFERED] = $langs->transnoentitiesnoconv(
'StatusTrans');
2677 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'StatusWaiting');
2678 $this->labelStatusShort[self::STATUS_TRANSFERED] = $langs->transnoentitiesnoconv(
'StatusTrans');
2679 if ($this->
type ==
'bank-transfer') {
2680 $this->labelStatus[self::STATUS_DEBITED] = $langs->transnoentitiesnoconv(
'StatusDebited');
2681 $this->labelStatusShort[self::STATUS_DEBITED] = $langs->transnoentitiesnoconv(
'StatusDebited');
2683 $this->labelStatus[self::STATUS_CREDITED] = $langs->transnoentitiesnoconv(
'StatusCredited');
2684 $this->labelStatusShort[self::STATUS_CREDITED] = $langs->transnoentitiesnoconv(
'StatusCredited');
2688 $statusType =
'status1';
2689 if ($status == self::STATUS_TRANSFERED) {
2690 $statusType =
'status3';
2692 if ($status == self::STATUS_CREDITED || $status == self::STATUS_DEBITED) {
2693 $statusType =
'status6';
2696 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
2782 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
2784 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2785 $return .=
'<div class="info-box info-box-sm">';
2786 $return .=
'<span class="info-box-icon bg-infobox-action">';
2788 $return .=
'</span>';
2789 $return .=
'<div class="info-box-content">';
2790 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . (method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref) .
'</span>';
2791 if ($selected >= 0) {
2792 $return .=
'<input id="cb' . $this->
id .
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="' . $this->
id .
'"' . ($selected ?
' checked="checked"' :
'') .
'>';
2794 if (property_exists($this,
'date_echeance')) {
2795 $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>';
2797 if (property_exists($this,
'total')) {
2798 $return .=
'<br><span class="opacitymedium">' . $langs->trans(
"Amount") .
'</span> : <span class="amount">' .
price($this->total) .
'</span>';
2800 if (method_exists($this,
'LibStatut')) {
2801 $return .=
'<br><div class="info-box-status">' . $this->
getLibStatut(3) .
'</div>';
2803 $return .=
'</div>';
2804 $return .=
'</div>';
2805 $return .=
'</div>';
2816 if (!empty($this->
id)) {
2822 $sql =
"SELECT COUNT(*) AS nb FROM " . MAIN_DB_PREFIX .
"prelevement_lignes";
2823 $sql .=
" WHERE fk_prelevement_bons = " . ((int) $id);
2824 $sql .=
" AND fk_soc = 0";
2825 $sql .=
" AND fk_user IS NOT NULL";
2828 $resql = $this->db->query($sql);
2830 $obj = $this->db->fetch_object($resql);
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
checkSwiftForAccount(Account $account=null, $swift=null)
Check SWIFT information for a bank account.
checkIbanForAccount(Account $account=null, $ibantocheck=null)
Check IBAN number information for a bank account.
Class to manage bank accounts.
Class to manage withdrawal receipts.
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
SommeAPrelever($mode='direct-debit', $type='')
Returns amount waiting for direct debit payment or credit transfer payment.
static buildRumNumber($row_code_client, $row_datec, $row_drum)
Generate dynamically a RUM number for a customer bank account.
EnregEmetteur($type='direct-debit')
Write sender of request (me).
checkIfSalaryBonPrelevement()
Check if is bon prelevement for salary invoice.
EnregTotal($total)
Write end.
NbFactureAPrelever($type='direct-debit', $forsalary=0)
Get number of invoices to pay.
generate($format='ALL', $executiondate=0, $type='direct-debit', $fk_bank_account=0, $forsalary=0)
Generate a direct debit or credit transfer file.
fetch($rowid, $ref='')
Get object and lines from database.
getListInvoices($amounts=0, $type='')
Get invoice or salary list (with amount or not)
deleteNotificationById($rowid)
Delete a notification def by id.
AddFacture($invoice_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $type='debit-order', $sourcetype='')
Add invoice to withdrawal.
__construct($db)
Constructor.
EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $ref, $facid, $rib_dom='', $type='direct-debit')
Write recipient of request (customer)
getKanbanView($option='', $arraydata=null)
Return 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.
update(User $user, $notrigger=0)
Update object into database.
set_infotrans($user, $date, $method)
Set withdrawal to transmitted status.
getErrorString($error)
Return error string.
EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf='\n', $format='FRST', $type='direct-debit', $fk_bank_account=0)
Write sender of request (me).
set_infocredit($user, $date, $type='')
Set direct debit or credit transfer order to "paid" status.
addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key, $sourcetype='')
Add line to withdrawal.
getLibStatut($mode=0)
Return status label of object.
EnregDestinataireSEPA($row_code_client, $row_nom, $row_address, $row_zip, $row_town, $row_country_code, $row_cb, $row_cg, $row_cc, $row_somme, $row_ref, $row_idfac, $row_iban, $row_bic, $row_datec, $row_drum, $row_rum, $type='direct-debit', $row_comment='')
Write recipient (thirdparty concerned by request)
addNotification($db, $user, $action)
Add a notification.
nbOfInvoiceToPay($mode='direct-debit', $type='')
Get number of invoices waiting for payment.
create($banque=0, $agence=0, $mode='real', $format='ALL', $executiondate='', $notrigger=0, $type='direct-debit', $did=0, $fk_bank_account=0, $sourcetype='invoice')
Create a BAN payment order:
deleteNotification($user, $action)
Delete a notification.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
updateCommon(User $user, $notrigger=0)
Update object into database.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage suppliers invoices.
Class to manage invoices.
const STATUS_VALIDATED
Validated (need to be paid)
Class to manage payments for supplier invoices.
Class to manage payments of customer invoices.
Class to manage payments of salaries.
Class to manage salary payments.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e e e e e statut