dolibarr  9.0.0
bonprelevement.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2010-2015 Juanjo Menent <jmenent@2byte.es>
5  * Copyright (C) 2010-2014 Laurent Destailleur <eldy@users.sourceforge.net>
6  * Copyright (C) 2014-2016 Ferran Marcet <fmarcet@2byte.es>
7  * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
29 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
34 
35 
36 
41 {
45  public $element='widthdraw';
46 
50  public $table_element='prelevement_bons';
51 
55  public $picto = 'payment';
56 
57  public $date_echeance;
58  public $raison_sociale;
59  public $reference_remise;
60  public $emetteur_code_guichet;
61  public $emetteur_numero_compte;
62  public $emetteur_code_banque;
63  public $emetteur_number_key;
64 
65  public $emetteur_iban;
66  public $emetteur_bic;
67  public $emetteur_ics;
68 
69  public $total;
70  public $fetched;
71  public $statut; // 0-Wait, 1-Trans, 2-Done
72  public $labelstatut=array();
73 
74  public $invoice_in_error=array();
75  public $thirdparty_in_error=array();
76 
77 
84  function __construct($db, $filename='')
85  {
86  global $conf,$langs;
87 
88  $error = 0;
89  $this->db = $db;
90 
91  $this->filename=$filename;
92 
93  $this->date_echeance = time();
94  $this->raison_sociale = "";
95  $this->reference_remise = "";
96 
97  $this->emetteur_code_guichet = "";
98  $this->emetteur_numero_compte = "";
99  $this->emetteur_code_banque = "";
100  $this->emetteur_number_key = "";
101 
102  $this->emetteur_iban = "";
103  $this->emetteur_bic = "";
104  $this->emetteur_ics = "";
105 
106  $this->factures = array();
107 
108  $this->methodes_trans = array();
109 
110  $this->methodes_trans[0] = "Internet";
111 
112  $this->fetched = 0;
113  }
114 
115  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
129  function AddFacture($facture_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key)
130  {
131  // phpcs:enable
132  $result = 0;
133  $line_id = 0;
134 
135  $result = $this->addline($line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key);
136 
137  if ($result == 0)
138  {
139  if ($line_id > 0)
140  {
141  $sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_facture (";
142  $sql.= "fk_facture";
143  $sql.= ",fk_prelevement_lignes";
144  $sql.= ") VALUES (";
145  $sql.= $facture_id;
146  $sql.= ", ".$line_id;
147  $sql.= ")";
148 
149  if ($this->db->query($sql))
150  {
151  $result = 0;
152  }
153  else
154  {
155  $result = -1;
156  dol_syslog(get_class($this)."::AddFacture Erreur $result");
157  }
158  }
159  else
160  {
161  $result = -2;
162  dol_syslog(get_class($this)."::AddFacture Erreur $result");
163  }
164  }
165  else
166  {
167  $result = -3;
168  dol_syslog(get_class($this)."::AddFacture Erreur $result");
169  }
170 
171  return $result;
172  }
173 
187  function addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key)
188  {
189  $result = -1;
190  $concat = 0;
191 
192  if ($concat == 1)
193  {
194  /*
195  * We aggregate the lines
196  */
197  $sql = "SELECT rowid";
198  $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes";
199  $sql.= " WHERE fk_prelevement_bons = ".$this->id;
200  $sql.= " AND fk_soc =".$client_id;
201  $sql.= " AND code_banque ='".$code_banque."'";
202  $sql.= " AND code_guichet ='".$code_guichet."'";
203  $sql.= " AND number ='".$number."'";
204 
205  $resql=$this->db->query($sql);
206  if ($resql)
207  {
208  $num = $this->db->num_rows($resql);
209  }
210  else
211  {
212  $result = -1;
213  }
214  }
215  else
216  {
217  /*
218  * No aggregate
219  */
220  $sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_lignes (";
221  $sql.= "fk_prelevement_bons";
222  $sql.= ", fk_soc";
223  $sql.= ", client_nom";
224  $sql.= ", amount";
225  $sql.= ", code_banque";
226  $sql.= ", code_guichet";
227  $sql.= ", number";
228  $sql.= ", cle_rib";
229  $sql.= ") VALUES (";
230  $sql.= $this->id;
231  $sql.= ", ".$client_id;
232  $sql.= ", '".$this->db->escape($client_nom)."'";
233  $sql.= ", '".price2num($amount)."'";
234  $sql.= ", '".$code_banque."'";
235  $sql.= ", '".$code_guichet."'";
236  $sql.= ", '".$number."'";
237  $sql.= ", '".$number_key."'";
238  $sql.= ")";
239 
240  if ($this->db->query($sql))
241  {
242  $line_id = $this->db->last_insert_id(MAIN_DB_PREFIX."prelevement_lignes");
243  $result = 0;
244  }
245  else
246  {
247  dol_syslog(get_class($this)."::addline Error -2");
248  $result = -2;
249  }
250  }
251 
252  return $result;
253  }
254 
261  function getErrorString($error)
262  {
263  global $langs;
264 
265  $errors = array();
266 
267  $errors[1027] = $langs->trans("DateInvalid");
268 
269  return $errors[abs($error)];
270  }
271 
279  function fetch($rowid, $ref='')
280  {
281  global $conf;
282 
283  $sql = "SELECT p.rowid, p.ref, p.amount, p.note";
284  $sql.= ", p.datec as dc";
285  $sql.= ", p.date_trans as date_trans";
286  $sql.= ", p.method_trans, p.fk_user_trans";
287  $sql.= ", p.date_credit as date_credit";
288  $sql.= ", p.fk_user_credit";
289  $sql.= ", p.statut";
290  $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
291  $sql.= " WHERE p.entity IN (".getEntity('facture').")";
292  if ($rowid > 0) $sql.= " AND p.rowid = ".$rowid;
293  else $sql.= " AND p.ref = '".$this->db->escape($ref)."'";
294 
295  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
296  $result=$this->db->query($sql);
297  if ($result)
298  {
299  if ($this->db->num_rows($result))
300  {
301  $obj = $this->db->fetch_object($result);
302 
303  $this->id = $obj->rowid;
304  $this->ref = $obj->ref;
305  $this->amount = $obj->amount;
306  $this->note = $obj->note;
307  $this->datec = $this->db->jdate($obj->dc);
308 
309  $this->date_trans = $this->db->jdate($obj->date_trans);
310  $this->method_trans = $obj->method_trans;
311  $this->user_trans = $obj->fk_user_trans;
312 
313  $this->date_credit = $this->db->jdate($obj->date_credit);
314  $this->user_credit = $obj->fk_user_credit;
315 
316  $this->statut = $obj->statut;
317 
318  $this->fetched = 1;
319 
320  return 1;
321  }
322  else
323  {
324  dol_syslog(get_class($this)."::Fetch Erreur aucune ligne retournee");
325  return -1;
326  }
327  }
328  else
329  {
330  return -2;
331  }
332  }
333 
334  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
340  function set_credite()
341  {
342  // phpcs:enable
343  global $user,$conf;
344 
345  $error = 0;
346 
347  if ($this->db->begin())
348  {
349  $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_bons";
350  $sql.= " SET statut = 1";
351  $sql.= " WHERE rowid = ".$this->id;
352  $sql.= " AND entity = ".$conf->entity;
353 
354  $result=$this->db->query($sql);
355  if (! $result)
356  {
357  dol_syslog(get_class($this)."::set_credite Erreur 1");
358  $error++;
359  }
360 
361  if (! $error)
362  {
363  $facs = array();
364  $facs = $this->getListInvoices();
365 
366  $num=count($facs);
367  for ($i = 0; $i < $num; $i++)
368  {
369  /* Tag invoice as payed */
370  dol_syslog(get_class($this)."::set_credite set_paid fac ".$facs[$i]);
371  $fac = new Facture($this->db);
372  $fac->fetch($facs[$i]);
373  $result = $fac->set_paid($user);
374  }
375  }
376 
377  if (! $error)
378  {
379  $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_lignes";
380  $sql.= " SET statut = 2";
381  $sql.= " WHERE fk_prelevement_bons = ".$this->id;
382 
383  if (! $this->db->query($sql))
384  {
385  dol_syslog(get_class($this)."::set_credite Erreur 1");
386  $error++;
387  }
388  }
389 
390  /*
391  * End of procedure
392  */
393  if (! $error)
394  {
395  $this->db->commit();
396  return 0;
397  }
398  else
399  {
400  $this->db->rollback();
401  dol_syslog(get_class($this)."::set_credite ROLLBACK ");
402 
403  return -1;
404  }
405  }
406  else
407  {
408  dol_syslog(get_class($this)."::set_credite Ouverture transaction SQL impossible ");
409  return -2;
410  }
411  }
412 
413  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
421  function set_infocredit($user, $date)
422  {
423  // phpcs:enable
424  global $conf,$langs;
425 
426  $error = 0;
427 
428  if ($this->fetched == 1)
429  {
430  if ($date >= $this->date_trans)
431  {
432  if ($this->db->begin())
433  {
434  $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_bons ";
435  $sql.= " SET fk_user_credit = ".$user->id;
436  $sql.= ", statut = 2";
437  $sql.= ", date_credit = '".$this->db->idate($date)."'";
438  $sql.= " WHERE rowid=".$this->id;
439  $sql.= " AND entity = ".$conf->entity;
440  $sql.= " AND statut = 1";
441 
442  if ($this->db->query($sql))
443  {
444 
445  $langs->load('withdrawals');
446  $subject = $langs->trans("InfoCreditSubject", $this->ref);
447  $message = $langs->trans("InfoCreditMessage", $this->ref, dol_print_date($date,'dayhour'));
448 
449  //Add payment of withdrawal into bank
450  $bankaccount = $conf->global->PRELEVEMENT_ID_BANKACCOUNT;
451  $facs = array();
452  $amounts = array();
453  $amountsperthirdparty = array();
454 
455  $facs = $this->getListInvoices(1);
456 
457  // Loop on each invoice. $facs=array(0=>id, 1=>amount requested)
458  $num=count($facs);
459  for ($i = 0; $i < $num; $i++)
460  {
461  $fac = new Facture($this->db);
462  $fac->fetch($facs[$i][0]);
463  $amounts[$fac->id] = $facs[$i][1];
464  $amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
465 
466  $totalpaye = $fac->getSommePaiement();
467  $totalcreditnotes = $fac->getSumCreditNotesUsed();
468  $totaldeposits = $fac->getSumDepositsUsed();
469  $alreadypayed = $totalpaye + $totalcreditnotes + $totaldeposits;
470 
471  if (price2num($alreadypayed + $facs[$i][1], 'MT') == $fac->total_ttc) {
472  $result = $fac->set_paid($user);
473  }
474  }
475 
476  // Make one payment per customer
477  foreach ($amountsperthirdparty as $thirdpartyid => $cursoramounts)
478  {
479  $paiement = new Paiement($this->db);
480  $paiement->datepaye = $date;
481  $paiement->amounts = $cursoramounts; // Array with detail of dispatching of payments for each invoice
482  $paiement->paiementid = 3; //
483  $paiement->num_paiement = $this->ref; // Set ref of direct debit note
484  $paiement->id_prelevement = $this->id;
485 
486  $paiement_id = $paiement->create($user);
487  if ($paiement_id < 0)
488  {
489  dol_syslog(get_class($this)."::set_infocredit AddPayment Error");
490  $error++;
491  }
492  else
493  {
494  $result=$paiement->addPaymentToBank($user,'payment','(WithdrawalPayment)',$bankaccount,'','');
495  if ($result < 0)
496  {
497  dol_syslog(get_class($this)."::set_infocredit AddPaymentToBank Error");
498  $error++;
499  }
500  }
501  //var_dump($paiement->amounts);
502  //var_dump($thirdpartyid);
503  //var_dump($cursoramounts);
504  }
505 
506  // Update withdrawal line
507  // TODO: Translate to ligneprelevement.class.php
508  $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_lignes";
509  $sql.= " SET statut = 2";
510  $sql.= " WHERE fk_prelevement_bons = ".$this->id;
511 
512  if (! $this->db->query($sql))
513  {
514  dol_syslog(get_class($this)."::set_infocredit Update lines Error");
515  $error++;
516  }
517  }
518  else
519  {
520  dol_syslog(get_class($this)."::set_infocredit Update Bons Error");
521  $error++;
522  }
523 
524  /*
525  * End of procedure
526  */
527  if ($error == 0)
528  {
529  $this->date_credit = $date;
530  $this->statut = 1;
531 
532  $this->db->commit();
533  return 0;
534  }
535  else
536  {
537  $this->db->rollback();
538  dol_syslog("bon-prelevment::set_infocredit ROLLBACK ");
539  return -1;
540  }
541  }
542  else
543  {
544  dol_syslog(get_class($this)."::set_infocredit 1025 Open SQL transaction impossible ");
545  return -1025;
546  }
547  }
548  else
549  {
550  dol_syslog("bon-prelevment::set_infocredit 1027 Date de credit < Date de trans ");
551  return -1027;
552  }
553  }
554  else
555  {
556  return -1026;
557  }
558  }
559 
560  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
569  function set_infotrans($user, $date, $method)
570  {
571  // phpcs:enable
572  global $conf,$langs;
573 
574  $error = 0;
575 
576  dol_syslog(get_class($this)."::set_infotrans Start",LOG_INFO);
577  if ($this->db->begin())
578  {
579  $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_bons ";
580  $sql.= " SET fk_user_trans = ".$user->id;
581  $sql.= " , date_trans = '".$this->db->idate($date)."'";
582  $sql.= " , method_trans = ".$method;
583  $sql.= " , statut = 1";
584  $sql.= " WHERE rowid = ".$this->id;
585  $sql.= " AND entity = ".$conf->entity;
586  $sql.= " AND statut = 0";
587 
588  if ($this->db->query($sql))
589  {
590  $this->method_trans = $method;
591  $langs->load('withdrawals');
592  $subject = $langs->trans("InfoTransSubject", $this->ref);
593  $message = $langs->trans("InfoTransMessage", $this->ref, dolGetFirstLastname($user->firstname, $user->lastname));
594  $message .=$langs->trans("InfoTransData", price($this->amount), $this->methodes_trans[$this->method_trans], dol_print_date($date,'day'));
595 
596  // TODO Call trigger to create a notification using notification module
597  }
598  else
599  {
600  $error++;
601  }
602 
603  if ($error == 0)
604  {
605  $this->date_trans = $date;
606  $this->statut = 1;
607  $this->db->commit();
608 
609  return 0;
610  }
611  else
612  {
613  $this->db->rollback();
614  dol_syslog(get_class($this)."::set_infotrans ROLLBACK", LOG_ERR);
615 
616  return -1;
617  }
618  }
619  else
620  {
621 
622  dol_syslog(get_class($this)."::set_infotrans Ouverture transaction SQL impossible", LOG_CRIT);
623  return -2;
624  }
625  }
626 
633  private function getListInvoices($amounts=0)
634  {
635  global $conf;
636 
637  $arr = array();
638 
639  /*
640  * Returns all invoices presented
641  * within a withdrawal receipt
642  */
643  $sql = "SELECT fk_facture";
644  if ($amounts) $sql .= ", SUM(pl.amount)";
645  $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
646  $sql.= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
647  $sql.= " , ".MAIN_DB_PREFIX."prelevement_facture as pf";
648  $sql.= " WHERE pf.fk_prelevement_lignes = pl.rowid";
649  $sql.= " AND pl.fk_prelevement_bons = p.rowid";
650  $sql.= " AND p.rowid = ".$this->id;
651  $sql.= " AND p.entity = ".$conf->entity;
652  if ($amounts) $sql.= " GROUP BY fk_facture";
653 
654  $resql=$this->db->query($sql);
655  if ($resql)
656  {
657  $num = $this->db->num_rows($resql);
658 
659  if ($num)
660  {
661  $i = 0;
662  while ($i < $num)
663  {
664  $row = $this->db->fetch_row($resql);
665  if (!$amounts) $arr[$i] = $row[0];
666  else
667  {
668  $arr[$i] = array(
669  $row[0],
670  $row[1]
671  );
672  }
673  $i++;
674  }
675  }
676  $this->db->free($resql);
677  }
678  else
679  {
680  dol_syslog(get_class($this)."::getListInvoices Erreur");
681  }
682 
683  return $arr;
684  }
685 
686  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
692  function SommeAPrelever()
693  {
694  // phpcs:enable
695  global $conf;
696 
697  $sql = "SELECT sum(pfd.amount) as nb";
698  $sql.= " FROM ".MAIN_DB_PREFIX."facture as f,";
699  $sql.= " ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
700  //$sql.= " ,".MAIN_DB_PREFIX."c_paiement as cp";
701  $sql.= " WHERE f.fk_statut = 1";
702  $sql.= " AND f.entity = ".$conf->entity;
703  $sql.= " AND f.rowid = pfd.fk_facture";
704  $sql.= " AND f.paye = 0";
705  $sql.= " AND pfd.traite = 0";
706  $sql.= " AND f.total_ttc > 0";
707 
708  $resql = $this->db->query($sql);
709  if ( $resql )
710  {
711  $obj = $this->db->fetch_object($resql);
712 
713  $this->db->free($resql);
714 
715  return $obj->nb;
716  }
717  else
718  {
719  $error = 1;
720  dol_syslog(get_class($this)."::SommeAPrelever Erreur -1");
721  dol_syslog($this->db->error());
722  }
723  }
724 
725  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
734  function NbFactureAPrelever($banque=0,$agence=0)
735  {
736  // phpcs:enable
737  global $conf;
738 
739  $sql = "SELECT count(f.rowid) as nb";
740  $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
741  $sql.= ", ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
742  $sql.= " WHERE f.fk_statut = 1";
743  $sql.= " AND f.entity = ".$conf->entity;
744  $sql.= " AND f.rowid = pfd.fk_facture";
745  $sql.= " AND f.paye = 0";
746  $sql.= " AND pfd.traite = 0";
747  $sql.= " AND f.total_ttc > 0";
748 
749  dol_syslog(get_class($this)."::SommeAPrelever");
750  $resql = $this->db->query($sql);
751 
752  if ( $resql )
753  {
754  $obj = $this->db->fetch_object($resql);
755 
756  $this->db->free($resql);
757 
758  return $obj->nb;
759  }
760  else
761  {
762  $this->error=get_class($this)."::SommeAPrelever Erreur -1 sql=".$this->db->error();
763  return -1;
764  }
765  }
766 
767 
768  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
780  function Create($banque=0, $agence=0, $mode='real', $format='ALL',$executiondate='')
781  {
782  // phpcs:enable
783  global $conf,$langs;
784 
785  dol_syslog(__METHOD__."::Bank=".$banque." Office=".$agence." mode=".$mode." format=".$format, LOG_DEBUG);
786 
787  require_once DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php";
788  require_once DOL_DOCUMENT_ROOT."/societe/class/societe.class.php";
789 
790  if (empty($format)) return 'ErrorBadParametersForDirectDebitFileCreate';
791 
792  $error = 0;
793 
794  $datetimeprev = time();
795  //Choice the date of the execution direct debit
796  if(!empty($executiondate)) $datetimeprev = $executiondate;
797 
798  $month = strftime("%m", $datetimeprev);
799  $year = strftime("%Y", $datetimeprev);
800 
801  $puser = new User($this->db, $conf->global->PRELEVEMENT_USER);
802 
803  $this->invoice_in_error = array();
804  $this->thirdparty_in_error = array();
805 
806  // Read invoices
807  $factures = array();
808  $factures_prev = array();
809  $factures_result = array();
810  $factures_prev_id=array();
811  $factures_errors=array();
812 
813  if (! $error)
814  {
815  $sql = "SELECT f.rowid, pfd.rowid as pfdrowid, f.fk_soc";
816  $sql.= ", pfd.code_banque, pfd.code_guichet, pfd.number, pfd.cle_rib";
817  $sql.= ", pfd.amount";
818  $sql.= ", s.nom as name";
819  $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
820  $sql.= ", ".MAIN_DB_PREFIX."societe as s";
821  $sql.= ", ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
822  $sql.= " WHERE f.rowid = pfd.fk_facture";
823  $sql.= " AND f.entity IN (".getEntity('facture').')';
824  $sql.= " AND s.rowid = f.fk_soc";
825  //if ($banque || $agence) $sql.= " AND s.rowid = sr.fk_soc";
826  $sql.= " AND f.fk_statut = 1";
827  $sql.= " AND f.paye = 0";
828  $sql.= " AND pfd.traite = 0";
829  $sql.= " AND f.total_ttc > 0";
830  //if ($banque) $sql.= " AND sr.code_banque = '".$conf->global->PRELEVEMENT_CODE_BANQUE."'";
831  //if ($agence) $sql.= " AND sr.code_guichet = '".$conf->global->PRELEVEMENT_CODE_GUICHET."'";
832 
833  dol_syslog(__METHOD__."::Read invoices, sql=".$sql, LOG_DEBUG);
834 
835  $resql = $this->db->query($sql);
836  if ($resql)
837  {
838  $num = $this->db->num_rows($resql);
839  $i = 0;
840 
841  while ($i < $num)
842  {
843  $row = $this->db->fetch_row($resql);
844  $factures[$i] = $row; // All fields
845  $i++;
846  }
847  $this->db->free($resql);
848  dol_syslog(__METHOD__."::Read invoices, ".$i." invoices to withdraw", LOG_DEBUG);
849  }
850  else
851  {
852  $error++;
853  dol_syslog(__METHOD__."::Read invoices error ".$this->db->error(), LOG_ERR);
854  }
855  }
856 
857  if (! $error)
858  {
859  require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
860  $soc = new Societe($this->db);
861 
862  // Check RIB
863  $i = 0;
864  dol_syslog(__METHOD__."::Check RIB", LOG_DEBUG);
865 
866  if (count($factures) > 0)
867  {
868  foreach ($factures as $key => $fac)
869  {
870  $fact = new Facture($this->db);
871  $resfetch = $fact->fetch($fac[0]);
872  if ($resfetch >= 0) // Field 0 of $fac is rowid of invoice
873  {
874  if ($soc->fetch($fact->socid) >= 0)
875  {
876  $bac = new CompanyBankAccount($this->db);
877  $bac->fetch(0, $soc->id);
878 
879  if ($format == 'FRST' && $bac->frstrecur != 'FRST')
880  {
881  continue;
882  }
883  if ($format == 'RCUR' && ($bac->frstrecur != 'RCUR' && $bac->frstrecur != 'RECUR'))
884  {
885  continue;
886  }
887 
888  if ($bac->verif() >= 1)
889  {
890  $factures_prev[$i] = $fac;
891  /* second tableau necessaire pour BonPrelevement */
892  $factures_prev_id[$i] = $fac[0];
893  $i++;
894  //dol_syslog(__METHOD__."::RIB is ok", LOG_DEBUG);
895  }
896  else
897  {
898  dol_syslog(__METHOD__."::Check RIB Error on default bank number IBAN/BIC for thirdparty reported by verif() ".$fact->socid." ".$soc->name, LOG_WARNING);
899  $this->invoice_in_error[$fac[0]]="Error on default bank number IBAN/BIC for invoice ".$fact->getNomUrl(0)." for thirdparty ".$soc->getNomUrl(0);
900  $this->thirdparty_in_error[$soc->id]="Error on default bank number IBAN/BIC for invoice ".$fact->getNomUrl(0)." for thirdparty ".$soc->getNomUrl(0);
901  }
902  }
903  else
904  {
905  dol_syslog(__METHOD__."::Check RIB Failed to read company", LOG_WARNING);
906  }
907  }
908  else
909  {
910  dol_syslog(__METHOD__."::Check RIB Failed to read invoice", LOG_WARNING);
911  }
912  }
913  }
914  else
915  {
916  dol_syslog(__METHOD__."::Check RIB No invoice to process", LOG_WARNING);
917  }
918  }
919 
920  $ok=0;
921 
922  // Withdraw invoices in factures_prev array
923  $out=count($factures_prev)." invoices will be withdrawn.";
924  //print $out."\n";
925  dol_syslog($out);
926 
927  // Return warning
928  /*$i=0;
929  foreach ($this->thirdparty_in_error as $key => $val)
930  {
931  if ($i < 10) setEventMessages($val, null, 'warnings');
932  else setEventMessages('More error were discarded...', null, 'warnings');
933  $i++;
934  }*/
935 
936  if (count($factures_prev) > 0)
937  {
938  if ($mode=='real')
939  {
940  $ok=1;
941  }
942  else
943  {
944  print $langs->trans("ModeWarning"); //"Option for real mode was not set, we stop after this simulation\n";
945  }
946  }
947 
948 
949  if ($ok)
950  {
951  /*
952  * We are in real mode.
953  * We create withdraw receipt and build withdraw into disk
954  */
955  $this->db->begin();
956 
957  $now=dol_now();
958 
959  /*
960  * Traitements
961  */
962  if (!$error)
963  {
964  $ref = substr($year,-2).$month;
965 
966  $sql = "SELECT substring(ref from char_length(ref) - 1)";
967  $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons";
968  $sql.= " WHERE ref LIKE '%".$this->db->escape($ref)."%'";
969  $sql.= " AND entity = ".$conf->entity;
970  $sql.= " ORDER BY ref DESC LIMIT 1";
971 
972  dol_syslog(get_class($this)."::Create sql=".$sql, LOG_DEBUG);
973  $resql = $this->db->query($sql);
974 
975  if ($resql)
976  {
977  $row = $this->db->fetch_row($resql);
978  $ref = "T".$ref.str_pad(dol_substr("00".intval($row[0])+1,0,2),2,"0",STR_PAD_LEFT);
979 
980  $dir=$conf->prelevement->dir_output.'/receipts';
981  if (! is_dir($dir)) dol_mkdir($dir);
982 
983  $this->filename = $dir.'/'.$ref.'.xml';
984 
985  // Create withdraw receipt in database
986  $sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_bons (";
987  $sql.= " ref, entity, datec";
988  $sql.= ") VALUES (";
989  $sql.= "'".$this->db->escape($ref)."'";
990  $sql.= ", ".$conf->entity;
991  $sql.= ", '".$this->db->idate($now)."'";
992  $sql.= ")";
993 
994  $resql = $this->db->query($sql);
995  if ($resql)
996  {
997  $prev_id = $this->db->last_insert_id(MAIN_DB_PREFIX."prelevement_bons");
998  $this->id = $prev_id;
999  $this->ref = $ref;
1000  }
1001  else
1002  {
1003  $error++;
1004  dol_syslog(__METHOD__."::Create withdraw receipt ".$this->db->lasterror(), LOG_ERR);
1005  }
1006  }
1007  else
1008  {
1009  $error++;
1010  dol_syslog(__METHOD__."::Get last withdraw receipt ".$this->db->lasterror(), LOG_ERR);
1011  }
1012  }
1013 
1014  if (!$error)
1015  {
1016  /*
1017  * Create withdrawal receipt in database
1018  */
1019  if (count($factures_prev) > 0)
1020  {
1021  foreach ($factures_prev as $fac) // Add a link in database for each invoice
1022  {
1023  // Fetch invoice
1024  $fact = new Facture($this->db);
1025  $fact->fetch($fac[0]);
1026  /*
1027  * Add standing order
1028  *
1029  *
1030  * $fac[3] : banque
1031  * $fac[4] : guichet
1032  * $fac[5] : number
1033  * $fac[6] : cle rib
1034  * $fac[7] : amount
1035  * $fac[8] : client nom
1036  * $fac[2] : client id
1037  */
1038  $ri = $this->AddFacture($fac[0], $fac[2], $fac[8], $fac[7], $fac[3], $fac[4], $fac[5], $fac[6]);
1039  if ($ri <> 0)
1040  {
1041  $error++;
1042  }
1043 
1044  // Update invoice requests as done
1045  $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_facture_demande";
1046  $sql.= " SET traite = 1";
1047  $sql.= ", date_traite = '".$this->db->idate($now)."'";
1048  $sql.= ", fk_prelevement_bons = ".$this->id;
1049  $sql.= " WHERE rowid = ".$fac[1];
1050 
1051  dol_syslog(__METHOD__."::Update Orders::Sql=".$sql, LOG_DEBUG);
1052  $resql=$this->db->query($sql);
1053 
1054  if (! $resql)
1055  {
1056  $error++;
1057  dol_syslog(__METHOD__."::Update Orders::Error=".$this->db->error(), LOG_ERR);
1058  }
1059  }
1060  }
1061  }
1062 
1063  if (!$error)
1064  {
1065  /*
1066  * Create direct debit order in a XML file
1067  */
1068 
1069  dol_syslog(__METHOD__."::Init withdraw receipt for ".count($factures_prev)." invoices", LOG_DEBUG);
1070 
1071 
1072  if (count($factures_prev) > 0)
1073  {
1074  $this->date_echeance = $datetimeprev;
1075  $this->reference_remise = $ref;
1076 
1077  $id=$conf->global->PRELEVEMENT_ID_BANKACCOUNT;
1078  $account = new Account($this->db);
1079  if ($account->fetch($id)>0)
1080  {
1081  $this->emetteur_code_banque = $account->code_banque;
1082  $this->emetteur_code_guichet = $account->code_guichet;
1083  $this->emetteur_numero_compte = $account->number;
1084  $this->emetteur_number_key = $account->cle_rib;
1085  $this->emetteur_iban = $account->iban;
1086  $this->emetteur_bic = $account->bic;
1087 
1088  $this->emetteur_ics = $conf->global->PRELEVEMENT_ICS; // Ex: PRELEVEMENT_ICS = "FR78ZZZ123456";
1089 
1090  $this->raison_sociale = $account->proprio;
1091  }
1092 
1093  $this->factures = $factures_prev_id;
1094 
1095  // Generation of SEPA file $this->filename
1096  $this->generate($format,$executiondate);
1097  }
1098  dol_syslog(__METHOD__."::End withdraw receipt, file ".$this->filename, LOG_DEBUG);
1099  }
1100  //var_dump($factures_prev);exit;
1101 
1102  /*
1103  * Update total
1104  */
1105  $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_bons";
1106  $sql.= " SET amount = ".price2num($this->total);
1107  $sql.= " WHERE rowid = ".$this->id;
1108  $sql.= " AND entity = ".$conf->entity;
1109 
1110  $resql=$this->db->query($sql);
1111  if (! $resql)
1112  {
1113  $error++;
1114  dol_syslog(__METHOD__."::Error update total: ".$this->db->error(), LOG_ERR);
1115  }
1116 
1117  if (!$error)
1118  {
1119  $this->db->commit();
1120  }
1121  else
1122  {
1123  $this->db->rollback();
1124  }
1125 
1126  return count($factures_prev);
1127  }
1128  else
1129  {
1130  return 0;
1131  }
1132  }
1133 
1134 
1141  function delete($user=null)
1142  {
1143  $this->db->begin();
1144 
1145  $sql = "DELETE FROM ".MAIN_DB_PREFIX."prelevement_facture WHERE fk_prelevement_lignes IN (SELECT rowid FROM ".MAIN_DB_PREFIX."prelevement_lignes WHERE fk_prelevement_bons = ".$this->id.")";
1146  $resql1=$this->db->query($sql);
1147  if (! $resql1) dol_print_error($this->db);
1148 
1149  $sql = "DELETE FROM ".MAIN_DB_PREFIX."prelevement_lignes WHERE fk_prelevement_bons = ".$this->id;
1150  $resql2=$this->db->query($sql);
1151  if (! $resql2) dol_print_error($this->db);
1152 
1153  $sql = "DELETE FROM ".MAIN_DB_PREFIX."prelevement_bons WHERE rowid = ".$this->id;
1154  $resql3=$this->db->query($sql);
1155  if (! $resql3) dol_print_error($this->db);
1156 
1157  $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_facture_demande SET fk_prelevement_bons = NULL, traite = 0 WHERE fk_prelevement_bons = ".$this->id;
1158  $resql4=$this->db->query($sql);
1159  if (! $resql4) dol_print_error($this->db);
1160 
1161  if ($resql1 && $resql2 && $resql3)
1162  {
1163  $this->db->commit();
1164  return 1;
1165  }
1166  else
1167  {
1168  $this->db->rollback();
1169  return -1;
1170  }
1171  }
1172 
1173 
1181  function getNomUrl($withpicto=0,$option='')
1182  {
1183  global $langs;
1184 
1185  $result='';
1186  $label = $langs->trans("ShowWithdraw").': '.$this->ref;
1187 
1188  $link = '<a href="'.DOL_URL_ROOT.'/compta/prelevement/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
1189  $linkend='</a>';
1190 
1191  if ($option == 'xxx')
1192  {
1193  $link = '<a href="'.DOL_URL_ROOT.'/compta/prelevement/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
1194  $linkend='</a>';
1195  }
1196 
1197  if ($withpicto) $result.=($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' ');
1198  $result.=$link.$this->ref.$linkend;
1199  return $result;
1200  }
1201 
1202 
1203  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1210  function DeleteNotificationById($rowid)
1211  {
1212  // phpcs:enable
1213  $result = 0;
1214 
1215  $sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def";
1216  $sql.= " WHERE rowid = '".$rowid."'";
1217 
1218  if ($this->db->query($sql))
1219  {
1220  return 0;
1221  }
1222  else
1223  {
1224  return -1;
1225  }
1226  }
1227 
1228  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1236  function DeleteNotification($user, $action)
1237  {
1238  // phpcs:enable
1239  $result = 0;
1240 
1241  $sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def";
1242  $sql .= " WHERE fk_user=".$user." AND fk_action='".$action."'";
1243 
1244  if ($this->db->query($sql))
1245  {
1246  return 0;
1247  }
1248  else
1249  {
1250  return -1;
1251  }
1252  }
1253 
1254  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1263  function AddNotification($db, $user, $action)
1264  {
1265  // phpcs:enable
1266  $result = 0;
1267 
1268  if ($this->DeleteNotification($user, $action) == 0)
1269  {
1270  $now=dol_now();
1271 
1272  $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify_def (datec,fk_user, fk_soc, fk_contact, fk_action)";
1273  $sql .= " VALUES (".$db->idate($now).",".$user.", 'NULL', 'NULL', '".$action."')";
1274 
1275  dol_syslog("adnotiff: ".$sql);
1276  if ($this->db->query($sql))
1277  {
1278  $result = 0;
1279  }
1280  else
1281  {
1282  $result = -1;
1283  dol_syslog(get_class($this)."::AddNotification Error $result");
1284  }
1285  }
1286 
1287  return $result;
1288  }
1289 
1290 
1302  function generate($format='ALL',$executiondate='')
1303  {
1304  global $conf,$langs,$mysoc;
1305 
1306  //TODO: Optimize code to read lines in a single function
1307 
1308  $result = 0;
1309 
1310  dol_syslog(get_class($this)."::generate build file ".$this->filename);
1311 
1312  $this->file = fopen($this->filename,"w");
1313  if (empty($this->file))
1314  {
1315  $this->error=$langs->trans('ErrorFailedToOpenFile', $this->filename);
1316  return -1;
1317  }
1318 
1319  $found=0;
1320 
1321  // Build file for European countries
1322  if ($mysoc->isInEEC())
1323  {
1324  $found++;
1325 
1329  // SEPA Initialisation
1330  $CrLf = "\n";
1331 
1332  $now = dol_now();
1333 
1334  $dateTime_ECMA = dol_print_date($now, '%Y-%m-%dT%H:%M:%S');
1335 
1336  $date_actu = $now;
1337  if (!empty($executiondate)) $date_actu=$executiondate;
1338 
1339  $dateTime_YMD = dol_print_date($date_actu, '%Y%m%d');
1340  $dateTime_YMDHMS = dol_print_date($date_actu, '%Y%m%d%H%M%S');
1341  $fileDebiteurSection = '';
1342  $fileEmetteurSection = '';
1343  $i = 0;
1344  $this->total = 0;
1345 
1346  /*
1347  * section Debiteur (sepa Debiteurs bloc lines)
1348  */
1349 
1350  $sql = "SELECT soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,";
1351  $sql.= " pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,";
1352  $sql.= " f.facnumber as fac, pf.fk_facture as idfac, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum";
1353  $sql.= " FROM";
1354  $sql.= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,";
1355  $sql.= " ".MAIN_DB_PREFIX."facture as f,";
1356  $sql.= " ".MAIN_DB_PREFIX."prelevement_facture as pf,";
1357  $sql.= " ".MAIN_DB_PREFIX."societe as soc,";
1358  $sql.= " ".MAIN_DB_PREFIX."c_country as c,";
1359  $sql.= " ".MAIN_DB_PREFIX."societe_rib as rib";
1360  $sql.= " WHERE pl.fk_prelevement_bons = ".$this->id;
1361  $sql.= " AND pl.rowid = pf.fk_prelevement_lignes";
1362  $sql.= " AND pf.fk_facture = f.rowid";
1363  $sql.= " AND soc.fk_pays = c.rowid";
1364  $sql.= " AND soc.rowid = f.fk_soc";
1365  $sql.= " AND rib.fk_soc = f.fk_soc";
1366  $sql.= " AND rib.default_rib = 1";
1367  $sql.= " AND rib.type = 'ban'";
1368  //print $sql;
1369 
1370  // Define $fileDebiteurSection. One section DrctDbtTxInf per invoice.
1371  $resql=$this->db->query($sql);
1372  if ($resql)
1373  {
1374  $num = $this->db->num_rows($resql);
1375  while ($i < $num)
1376  {
1377  $obj = $this->db->fetch_object($resql);
1378  $fileDebiteurSection .= $this->EnregDestinataireSEPA($obj->code, $obj->nom, $obj->address, $obj->zip, $obj->town, $obj->country_code, $obj->cb, $obj->cg, $obj->cc, $obj->somme, $obj->fac, $obj->idfac, $obj->iban, $obj->bic, $this->db->jdate($obj->datec), $obj->drum);
1379  $this->total = $this->total + $obj->somme;
1380  $i++;
1381  }
1382  $nbtotalDrctDbtTxInf = $i;
1383  }
1384  else
1385  {
1386  fputs($this->file, 'ERROR DEBITOR '.$sql.$CrLf); // DEBITOR = Customers
1387  $result = -2;
1388  }
1389 
1390  // Define $fileEmetteurSection. Start of bloc PmtInf. Will contains all DrctDbtTxInf
1391  if ($result != -2)
1392  {
1393  $fileEmetteurSection .= $this->EnregEmetteurSEPA($conf, $date_actu, $nbtotalDrctDbtTxInf, $this->total, $CrLf, $format);
1394  }
1395  else
1396  {
1397  fputs($this->file, 'ERROR CREDITOR'.$CrLf); // CREDITOR = My company
1398  }
1399 
1403  // SEPA File Header
1404  fputs($this->file, '<'.'?xml version="1.0" encoding="UTF-8" standalone="yes"?'.'>'.$CrLf);
1405  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);
1406  fputs($this->file, ' <CstmrDrctDbtInitn>'.$CrLf);
1407  // SEPA Group header
1408  fputs($this->file, ' <GrpHdr>'.$CrLf);
1409  fputs($this->file, ' <MsgId>'.('PREL'.$dateTime_YMD.'/REF'.$this->id).'</MsgId>'.$CrLf);
1410  fputs($this->file, ' <CreDtTm>'.$dateTime_ECMA.'</CreDtTm>'.$CrLf);
1411  fputs($this->file, ' <NbOfTxs>'.$i.'</NbOfTxs>'.$CrLf);
1412  fputs($this->file, ' <CtrlSum>'.$this->total.'</CtrlSum>'.$CrLf);
1413  fputs($this->file, ' <InitgPty>'.$CrLf);
1414  fputs($this->file, ' <Nm>'.strtoupper(dol_string_unaccent($this->raison_sociale)).'</Nm>'.$CrLf);
1415  fputs($this->file, ' <Id>'.$CrLf);
1416  fputs($this->file, ' <PrvtId>'.$CrLf);
1417  fputs($this->file, ' <Othr>'.$CrLf);
1418  fputs($this->file, ' <Id>'.$conf->global->PRELEVEMENT_ICS.'</Id>'.$CrLf);
1419  fputs($this->file, ' </Othr>'.$CrLf);
1420  fputs($this->file, ' </PrvtId>'.$CrLf);
1421  fputs($this->file, ' </Id>'.$CrLf);
1422  fputs($this->file, ' </InitgPty>'.$CrLf);
1423  fputs($this->file, ' </GrpHdr>'.$CrLf);
1424  // SEPA File Emetteur
1425  if ($result != -2)
1426  { fputs($this-> file, $fileEmetteurSection);}
1427  // SEPA File Debiteurs
1428  if ($result != -2)
1429  { fputs($this-> file, $fileDebiteurSection);}
1430  // SEPA FILE FOOTER
1431  fputs($this->file, ' </PmtInf>'.$CrLf);
1432  fputs($this->file, ' </CstmrDrctDbtInitn>'.$CrLf);
1433  fputs($this->file, '</Document>'.$CrLf);
1434  }
1435 
1436  // Build file for Other Countries with unknow format
1437  if (! $found)
1438  {
1439  $this->total = 0;
1440  $sql = "SELECT pl.amount";
1441  $sql.= " FROM";
1442  $sql.= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,";
1443  $sql.= " ".MAIN_DB_PREFIX."facture as f,";
1444  $sql.= " ".MAIN_DB_PREFIX."prelevement_facture as pf";
1445  $sql.= " WHERE pl.fk_prelevement_bons = ".$this->id;
1446  $sql.= " AND pl.rowid = pf.fk_prelevement_lignes";
1447  $sql.= " AND pf.fk_facture = f.rowid";
1448 
1449  //Lines
1450  $i = 0;
1451  $resql=$this->db->query($sql);
1452  if ($resql)
1453  {
1454  $num = $this->db->num_rows($resql);
1455 
1456  while ($i < $num)
1457  {
1458  $obj = $this->db->fetch_object($resql);
1459  $this->total = $this->total + $obj->amount;
1460  $i++;
1461  }
1462  }
1463  else
1464  {
1465  $result = -2;
1466  }
1467 
1468  $langs->load('withdrawals');
1469 
1470  // TODO Add here code to generate a generic file
1471  fputs($this->file, $langs->trans('WithdrawalFileNotCapable', $mysoc->country_code));
1472  }
1473 
1474  fclose($this->file);
1475  if (! empty($conf->global->MAIN_UMASK))
1476  @chmod($this->file, octdec($conf->global->MAIN_UMASK));
1477  return $result;
1478  }
1479 
1480 
1481  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1496  function EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $facnumber, $facid, $rib_dom='')
1497  {
1498  // phpcs:enable
1499  fputs($this->file, "06");
1500  fputs($this->file, "08"); // Prelevement ordinaire
1501 
1502  fputs($this->file, " "); // Zone Reservee B2
1503 
1504  fputs($this->file, $this->emetteur_ics); // ICS
1505 
1506  // Date d'echeance C1
1507 
1508  fputs($this->file, " ");
1509  fputs($this->file, strftime("%d%m", $this->date_echeance));
1510  fputs($this->file, substr(strftime("%y", $this->date_echeance),1));
1511 
1512  // Raison Sociale Destinataire C2
1513 
1514  fputs($this->file, substr(strtoupper($client_nom)." ",0,24));
1515 
1516  // Domiciliation facultative D1
1517  $domiciliation = strtr($rib_dom, array(" " => "-", CHR(13) => " ", CHR(10) => ""));
1518  fputs($this->file, substr($domiciliation." ",0,24));
1519 
1520  // Zone Reservee D2
1521 
1522  fputs($this->file, substr(" ",0,8));
1523 
1524  // Code Guichet D3
1525 
1526  fputs($this->file, $rib_guichet);
1527 
1528  // Numero de compte D4
1529 
1530  fputs($this->file, substr("000000000000000".$rib_number, -11));
1531 
1532  // Zone E Montant
1533 
1534  $montant = (round($amount,2) * 100);
1535 
1536  fputs($this->file, substr("000000000000000".$montant, -16));
1537 
1538  // Libelle F
1539 
1540  fputs($this->file, substr("*_".$facnumber."_RDVnet".$rowid." ", 0, 31));
1541 
1542  // Code etablissement G1
1543 
1544  fputs($this->file, $rib_banque);
1545 
1546  // Zone Reservee G2
1547 
1548  fputs($this->file, substr(" ", 0, 5));
1549 
1550  fputs($this->file, "\n");
1551  }
1552 
1553 
1562  static function buildRumNumber($row_code_client, $row_datec, $row_drum)
1563  {
1564  global $langs;
1565  $pre = $langs->trans('RUM').'-';
1566  return $pre.$row_code_client.'-'.$row_drum.'-'.date('U', $row_datec);
1567  }
1568 
1569  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1591  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_facnumber, $row_idfac, $row_iban, $row_bic, $row_datec, $row_drum)
1592  {
1593  // phpcs:enable
1594  global $conf;
1595  $CrLf = "\n";
1596  $Rowing = sprintf("%06d", $row_idfac);
1597 
1598  // Define value for RUM
1599  // Example: RUMCustomerCode-CustomerBankAccountId-01424448606 (note: Date is date of creation of CustomerBankAccountId)
1600  $Rum = $this->buildRumNumber($row_code_client, $row_datec, $row_drum);
1601 
1602  // Define date of RUM signature
1603  $DtOfSgntr = dol_print_date($row_datec, '%Y-%m-%d');
1604 
1605  $XML_DEBITOR ='';
1606  $XML_DEBITOR .=' <DrctDbtTxInf>'.$CrLf;
1607  $XML_DEBITOR .=' <PmtId>'.$CrLf;
1608  // $XML_DEBITOR .=' <EndToEndId>'.('AS-'.dol_trunc($row_facnumber,20).'-'.$Rowing).'</EndToEndId>'.$CrLf; // ISO20022 states that EndToEndId has a MaxLength of 35 characters
1609  $XML_DEBITOR .=' <EndToEndId>'.(($conf->global->END_TO_END != "" ) ? $conf->global->END_TO_END : ('AS-'.dol_trunc($row_facnumber,20)).'-'.$Rowing).'</EndToEndId>'.$CrLf; // ISO20022 states that EndToEndId has a MaxLength of 35 characters
1610  $XML_DEBITOR .=' </PmtId>'.$CrLf;
1611  $XML_DEBITOR .=' <InstdAmt Ccy="EUR">'.round($row_somme, 2).'</InstdAmt>'.$CrLf;
1612  $XML_DEBITOR .=' <DrctDbtTx>'.$CrLf;
1613  $XML_DEBITOR .=' <MndtRltdInf>'.$CrLf;
1614  $XML_DEBITOR .=' <MndtId>'.$Rum.'</MndtId>'.$CrLf;
1615  $XML_DEBITOR .=' <DtOfSgntr>'.$DtOfSgntr.'</DtOfSgntr>'.$CrLf;
1616  $XML_DEBITOR .=' <AmdmntInd>false</AmdmntInd>'.$CrLf;
1617  $XML_DEBITOR .=' </MndtRltdInf>'.$CrLf;
1618  $XML_DEBITOR .=' </DrctDbtTx>'.$CrLf;
1619  $XML_DEBITOR .=' <DbtrAgt>'.$CrLf;
1620  $XML_DEBITOR .=' <FinInstnId>'.$CrLf;
1621  $XML_DEBITOR .=' <BIC>'.$row_bic.'</BIC>'.$CrLf;
1622  $XML_DEBITOR .=' </FinInstnId>'.$CrLf;
1623  $XML_DEBITOR .=' </DbtrAgt>'.$CrLf;
1624  $XML_DEBITOR .=' <Dbtr>'.$CrLf;
1625  $XML_DEBITOR .=' <Nm>'.dolEscapeXML(strtoupper(dol_string_unaccent($row_nom))).'</Nm>'.$CrLf;
1626  $XML_DEBITOR .=' <PstlAdr>'.$CrLf;
1627  $XML_DEBITOR .=' <Ctry>'.$row_country_code.'</Ctry>'.$CrLf;
1628  $addressline1 = dol_string_unaccent(strtr($row_address, array(CHR(13) => ", ", CHR(10) => "")));
1629  $addressline2 = dol_string_unaccent(strtr($row_zip.(($row_zip && $row_town)?' ':''.$row_town), array(CHR(13) => ", ", CHR(10) => "")));
1630  if (trim($addressline1)) $XML_DEBITOR .=' <AdrLine>'.dolEscapeXML(dol_trunc($addressline1,70,'right','UTF-8',true)).'</AdrLine>'.$CrLf;
1631  if (trim($addressline2)) $XML_DEBITOR .=' <AdrLine>'.dolEscapeXML(dol_trunc($addressline2,70,'right','UTF-8',true)).'</AdrLine>'.$CrLf;
1632  $XML_DEBITOR .=' </PstlAdr>'.$CrLf;
1633  $XML_DEBITOR .=' </Dbtr>'.$CrLf;
1634  $XML_DEBITOR .=' <DbtrAcct>'.$CrLf;
1635  $XML_DEBITOR .=' <Id>'.$CrLf;
1636  $XML_DEBITOR .=' <IBAN>'.preg_replace('/\s/', '', $row_iban).'</IBAN>'.$CrLf;
1637  $XML_DEBITOR .=' </Id>'.$CrLf;
1638  $XML_DEBITOR .=' </DbtrAcct>'.$CrLf;
1639  $XML_DEBITOR .=' <RmtInf>'.$CrLf;
1640  // $XML_DEBITOR .=' <Ustrd>'.($row_facnumber.'/'.$Rowing.'/'.$Rum).'</Ustrd>'.$CrLf;
1641  // $XML_DEBITOR .=' <Ustrd>'.dol_trunc($row_facnumber, 135).'</Ustrd>'.$CrLf; // 140 max
1642  $XML_DEBITOR .=' <Ustrd>'.(($conf->global->USTRD != "" ) ? $conf->global->USTRD : dol_trunc($row_facnumber, 135) ).'</Ustrd>'.$CrLf; // 140 max
1643  $XML_DEBITOR .=' </RmtInf>'.$CrLf;
1644  $XML_DEBITOR .=' </DrctDbtTxInf>'.$CrLf;
1645  return $XML_DEBITOR;
1646  }
1647 
1648 
1649  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1655  function EnregEmetteur()
1656  {
1657  // phpcs:enable
1658  fputs($this->file, "03");
1659  fputs($this->file, "08"); // Prelevement ordinaire
1660 
1661  fputs($this->file, " "); // Zone Reservee B2
1662 
1663  fputs($this->file, $this->emetteur_ics); // ICS
1664 
1665  // Date d'echeance C1
1666 
1667  fputs($this->file, " ");
1668  fputs($this->file, strftime("%d%m", $this->date_echeance));
1669  fputs($this->file, substr(strftime("%y", $this->date_echeance),1));
1670 
1671  // Raison Sociale C2
1672 
1673  fputs($this->file, substr($this->raison_sociale. " ",0,24));
1674 
1675  // Reference de la remise creancier D1 sur 7 caracteres
1676 
1677  fputs($this->file, substr($this->reference_remise. " ",0,7));
1678 
1679  // Zone Reservee D1-2
1680 
1681  fputs($this->file, substr(" ",0,17));
1682 
1683  // Zone Reservee D2
1684 
1685  fputs($this->file, substr(" ",0,2));
1686  fputs($this->file, "E");
1687  fputs($this->file, substr(" ",0,5));
1688 
1689  // Code Guichet D3
1690 
1691  fputs($this->file, $this->emetteur_code_guichet);
1692 
1693  // Numero de compte D4
1694 
1695  fputs($this->file, substr("000000000000000".$this->emetteur_numero_compte, -11));
1696 
1697  // Zone Reservee E
1698 
1699  fputs($this->file, substr(" ",0,16));
1700 
1701  // Zone Reservee F
1702 
1703  fputs($this->file, substr(" ",0,31));
1704 
1705  // Code etablissement
1706 
1707  fputs($this->file, $this->emetteur_code_banque);
1708 
1709  // Zone Reservee G
1710 
1711  fputs($this->file, substr(" ",0,5));
1712 
1713  fputs($this->file, "\n");
1714  }
1715 
1716  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1729  function EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf='\n', $format='FRST')
1730  {
1731  // phpcs:enable
1732  // SEPA INITIALISATION
1733  global $conf;
1734 
1735  $dateTime_YMD = dol_print_date($ladate, '%Y%m%d');
1736  $dateTime_ETAD = dol_print_date($ladate, '%Y-%m-%d');
1737  $dateTime_YMDHMS = dol_print_date($ladate, '%Y-%m-%dT%H:%M:%S');
1738 
1739  // Get data of bank account
1740  $id=$configuration->global->PRELEVEMENT_ID_BANKACCOUNT;
1741  $account = new Account($this->db);
1742  if ($account->fetch($id)>0)
1743  {
1744  $this->emetteur_code_banque = $account->code_banque;
1745  $this->emetteur_code_guichet = $account->code_guichet;
1746  $this->emetteur_numero_compte = $account->number;
1747  $this->emetteur_number_key = $account->cle_rib;
1748  $this->emetteur_iban = $account->iban;
1749  $this->emetteur_bic = $account->bic;
1750 
1751  $this->emetteur_ics = $conf->global->PRELEVEMENT_ICS; // Ex: PRELEVEMENT_ICS = "FR78ZZZ123456";
1752 
1753  $this->raison_sociale = $account->proprio;
1754  }
1755 
1756  // Récupération info demandeur
1757  $sql = "SELECT rowid, ref";
1758  $sql.= " FROM";
1759  $sql.= " ".MAIN_DB_PREFIX."prelevement_bons as pb";
1760  $sql.= " WHERE pb.rowid = ".$this->id;
1761 
1762  $resql=$this->db->query($sql);
1763  if ($resql)
1764  {
1765  $obj = $this->db->fetch_object($resql);
1766 
1767  // DONNEES BRUTES : par la suite Rows['XXX'] de la requete au dessus
1768  $country = explode(':', $configuration->global->MAIN_INFO_SOCIETE_COUNTRY);
1769  $IdBon = sprintf("%05d", $obj->rowid);
1770  $RefBon = $obj->ref;
1771 
1772  // SEPA Paiement Information
1773  $XML_SEPA_INFO = '';
1774  $XML_SEPA_INFO .= ' <PmtInf>'.$CrLf;
1775  $XML_SEPA_INFO .= ' <PmtInfId>'.('PREL'.$dateTime_YMD.'/ID'.$IdBon.'-'.$RefBon).'</PmtInfId>'.$CrLf;
1776  $XML_SEPA_INFO .= ' <PmtMtd>DD</PmtMtd>'.$CrLf;
1777  $XML_SEPA_INFO .= ' <NbOfTxs>'.$nombre.'</NbOfTxs>'.$CrLf;
1778  $XML_SEPA_INFO .= ' <CtrlSum>'.$total.'</CtrlSum>'.$CrLf;
1779  $XML_SEPA_INFO .= ' <PmtTpInf>'.$CrLf;
1780  $XML_SEPA_INFO .= ' <SvcLvl>'.$CrLf;
1781  $XML_SEPA_INFO .= ' <Cd>SEPA</Cd>'.$CrLf;
1782  $XML_SEPA_INFO .= ' </SvcLvl>'.$CrLf;
1783  $XML_SEPA_INFO .= ' <LclInstrm>'.$CrLf;
1784  $XML_SEPA_INFO .= ' <Cd>CORE</Cd>'.$CrLf;
1785  $XML_SEPA_INFO .= ' </LclInstrm>'.$CrLf;
1786  $XML_SEPA_INFO .= ' <SeqTp>'.$format.'</SeqTp>'.$CrLf;
1787  $XML_SEPA_INFO .= ' </PmtTpInf>'.$CrLf;
1788  $XML_SEPA_INFO .= ' <ReqdColltnDt>'.$dateTime_ETAD.'</ReqdColltnDt>'.$CrLf;
1789  $XML_SEPA_INFO .= ' <Cdtr>'.$CrLf;
1790  $XML_SEPA_INFO .= ' <Nm>'.strtoupper(dol_string_unaccent($this->raison_sociale)).'</Nm>'.$CrLf;
1791  $XML_SEPA_INFO .= ' <PstlAdr>'.$CrLf;
1792  $XML_SEPA_INFO .= ' <Ctry>'.$country[1].'</Ctry>'.$CrLf;
1793  $addressline1 = dol_string_unaccent(strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(CHR(13) => ", ", CHR(10) => "")));
1794  $addressline2 = dol_string_unaccent(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) => "")));
1795  if ($addressline1) $XML_SEPA_INFO .= ' <AdrLine>'.$addressline1.'</AdrLine>'.$CrLf;
1796  if ($addressline2) $XML_SEPA_INFO .= ' <AdrLine>'.$addressline2.'</AdrLine>'.$CrLf;
1797  $XML_SEPA_INFO .= ' </PstlAdr>'.$CrLf;
1798  $XML_SEPA_INFO .= ' </Cdtr>'.$CrLf;
1799  $XML_SEPA_INFO .= ' <CdtrAcct>'.$CrLf;
1800  $XML_SEPA_INFO .= ' <Id>'.$CrLf;
1801  $XML_SEPA_INFO .= ' <IBAN>'.preg_replace('/\s/', '', $this->emetteur_iban).'</IBAN>'.$CrLf;
1802  $XML_SEPA_INFO .= ' </Id>'.$CrLf;
1803  $XML_SEPA_INFO .= ' </CdtrAcct>'.$CrLf;
1804  $XML_SEPA_INFO .= ' <CdtrAgt>'.$CrLf;
1805  $XML_SEPA_INFO .= ' <FinInstnId>'.$CrLf;
1806  $XML_SEPA_INFO .= ' <BIC>'.$this->emetteur_bic.'</BIC>'.$CrLf;
1807  $XML_SEPA_INFO .= ' </FinInstnId>'.$CrLf;
1808  $XML_SEPA_INFO .= ' </CdtrAgt>'.$CrLf;
1809 /* $XML_SEPA_INFO .= ' <UltmtCdtr>'.$CrLf;
1810  $XML_SEPA_INFO .= ' <Nm>'.$this->raison_sociale.'</Nm>'.$CrLf;
1811  $XML_SEPA_INFO .= ' <PstlAdr>'.$CrLf;
1812  $XML_SEPA_INFO .= ' <Ctry>'.$country[1].'</Ctry>'.$CrLf;
1813  $XML_SEPA_INFO .= ' <AdrLine>'.$conf->global->MAIN_INFO_SOCIETE_ADDRESS.'</AdrLine>'.$CrLf;
1814  $XML_SEPA_INFO .= ' <AdrLine>'.$conf->global->MAIN_INFO_SOCIETE_ZIP.' '.$conf->global->MAIN_INFO_SOCIETE_TOWN.'</AdrLine>'.$CrLf;
1815  $XML_SEPA_INFO .= ' </PstlAdr>'.$CrLf;
1816  $XML_SEPA_INFO .= ' </UltmtCdtr>'.$CrLf;
1817 */ $XML_SEPA_INFO .= ' <ChrgBr>SLEV</ChrgBr>'.$CrLf;
1818  $XML_SEPA_INFO .= ' <CdtrSchmeId>'.$CrLf;
1819  $XML_SEPA_INFO .= ' <Id>'.$CrLf;
1820  $XML_SEPA_INFO .= ' <PrvtId>'.$CrLf;
1821  $XML_SEPA_INFO .= ' <Othr>'.$CrLf;
1822  $XML_SEPA_INFO .= ' <Id>'.$this->emetteur_ics.'</Id>'.$CrLf;
1823  $XML_SEPA_INFO .= ' <SchmeNm>'.$CrLf;
1824  $XML_SEPA_INFO .= ' <Prtry>SEPA</Prtry>'.$CrLf;
1825  $XML_SEPA_INFO .= ' </SchmeNm>'.$CrLf;
1826  $XML_SEPA_INFO .= ' </Othr>'.$CrLf;
1827  $XML_SEPA_INFO .= ' </PrvtId>'.$CrLf;
1828  $XML_SEPA_INFO .= ' </Id>'.$CrLf;
1829  $XML_SEPA_INFO .= ' </CdtrSchmeId>'.$CrLf;
1830  }
1831  else
1832  {
1833  fputs($this->file, 'INCORRECT EMETTEUR '.$XML_SEPA_INFO.$CrLf);
1834  $result = -2;
1835  }
1836  return $XML_SEPA_INFO;
1837  }
1838 
1839  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1846  function EnregTotal($total)
1847  {
1848  // phpcs:enable
1849  fputs($this->file, "08");
1850  fputs($this->file, "08"); // Prelevement ordinaire
1851 
1852  fputs($this->file, " "); // Zone Reservee B2
1853 
1854  fputs($this->file, $this->emetteur_ics); // ICS
1855 
1856  // Reserve C1
1857 
1858  fputs($this->file, substr(" ",0,12));
1859 
1860 
1861  // Raison Sociale C2
1862 
1863  fputs($this->file, substr(" ",0,24));
1864 
1865  // D1
1866 
1867  fputs($this->file, substr(" ",0,24));
1868 
1869  // Zone Reservee D2
1870 
1871  fputs($this->file, substr(" ",0,8));
1872 
1873  // Code Guichet D3
1874 
1875  fputs($this->file, substr(" ",0,5));
1876 
1877  // Numero de compte D4
1878 
1879  fputs($this->file, substr(" ",0,11));
1880 
1881  // Zone E Montant
1882 
1883  $montant = ($total * 100);
1884 
1885  fputs($this->file, substr("000000000000000".$montant, -16));
1886 
1887  // Zone Reservee F
1888 
1889  fputs($this->file, substr(" ",0,31));
1890 
1891  // Code etablissement
1892 
1893  fputs($this->file, substr(" ",0,5));
1894 
1895  // Zone Reservee F
1896 
1897  fputs($this->file, substr(" ",0,5));
1898 
1899  fputs($this->file, "\n");
1900  }
1901 
1908  function getLibStatut($mode=0)
1909  {
1910  return $this->LibStatut($this->statut,$mode);
1911  }
1912 
1913  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1921  function LibStatut($statut,$mode=0)
1922  {
1923  // phpcs:enable
1924  if (empty($this->labelstatut))
1925  {
1926  global $langs;
1927  $langs->load("withdrawals");
1928  $this->labelstatut[0]=$langs->trans("StatusWaiting");
1929  $this->labelstatut[1]=$langs->trans("StatusTrans");
1930  $this->labelstatut[2]=$langs->trans("StatusCredited");
1931  }
1932 
1933  if ($mode == 0 || $mode == 1)
1934  {
1935  return $this->labelstatut[$statut];
1936  }
1937  elseif ($mode == 2)
1938  {
1939  if ($statut==0) return img_picto($this->labelstatut[$statut],'statut1').' '.$this->labelstatut[$statut];
1940  if ($statut==1) return img_picto($this->labelstatut[$statut],'statut3').' '.$this->labelstatut[$statut];
1941  if ($statut==2) return img_picto($this->labelstatut[$statut],'statut6').' '.$this->labelstatut[$statut];
1942  }
1943  elseif ($mode == 3)
1944  {
1945  if ($statut==0) return img_picto($this->labelstatut[$statut],'statut1');
1946  if ($statut==1) return img_picto($this->labelstatut[$statut],'statut3');
1947  if ($statut==2) return img_picto($this->labelstatut[$statut],'statut6');
1948  }
1949  elseif ($mode == 4)
1950  {
1951  if ($statut==0) return img_picto($this->labelstatut[$statut],'statut1').' '.$this->labelstatut[$statut];
1952  if ($statut==1) return img_picto($this->labelstatut[$statut],'statut3').' '.$this->labelstatut[$statut];
1953  if ($statut==2) return img_picto($this->labelstatut[$statut],'statut6').' '.$this->labelstatut[$statut];
1954  }
1955  elseif ($mode == 5)
1956  {
1957  if ($statut==0) return $this->labelstatut[$statut].' '.img_picto($this->labelstatut[$statut],'statut1');
1958  if ($statut==1) return $this->labelstatut[$statut].' '.img_picto($this->labelstatut[$statut],'statut3');
1959  if ($statut==2) return $this->labelstatut[$statut].' '.img_picto($this->labelstatut[$statut],'statut6');
1960  }
1961  elseif ($mode == 6)
1962  {
1963  if ($statut==0) return $this->labelstatut[$statut].' '.img_picto($this->labelstatut[$statut],'statut1');
1964  if ($statut==1) return $this->labelstatut[$statut].' '.img_picto($this->labelstatut[$statut],'statut3');
1965  if ($statut==2) return $this->labelstatut[$statut].' '.img_picto($this->labelstatut[$statut],'statut6');
1966  }
1967  }
1968 }
addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key)
Add line to withdrawal.
EnregTotal($total)
Write end.
EnregDestinataireSEPA($row_code_client, $row_nom, $row_address, $row_zip, $row_town, $row_country_code, $row_cb, $row_cg, $row_cc, $row_somme, $row_facnumber, $row_idfac, $row_iban, $row_bic, $row_datec, $row_drum)
Write recipient of request (customer)
print
Draft customers invoices.
Definition: index.php:91
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
EnregEmetteur()
Write sender of request (me)
if(! empty($search_group)) natural_search(array("g.nom" g note
Definition: list.php:123
set_credite()
Set credite and set status of linked invoices.
Class to manage Dolibarr users.
Definition: user.class.php:41
static buildRumNumber($row_code_client, $row_datec, $row_drum)
Build RUM number for a customer bank account.
Class to manage bank accounts description of third parties.
set_infotrans($user, $date, $method)
Set withdrawal to transmited status.
dol_substr($string, $start, $length, $stringencoding='', $trunconbytes=0)
Make a substring.
AddNotification($db, $user, $action)
Add a notification.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
set_infocredit($user, $date)
Set direct debit order to "credited" status.
getListInvoices($amounts=0)
Get invoice list.
Class to manage bank accounts.
generate($format='ALL', $executiondate='')
Generate a withdrawal file.
LibStatut($statut, $mode=0)
Return status label for a status.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
NbFactureAPrelever($banque=0, $agence=0)
Get number of invoices to withdrawal TODO delete params banque and agence when not necesary...
Class to manage withdrawal receipts.
getErrorString($error)
Return error string.
__construct($db, $filename='')
Constructor.
SommeAPrelever()
Returns amount of withdrawal.
Class to manage payments of customer invoices.
fetch($rowid, $ref='')
Get object and lines from database.
dol_string_unaccent($str)
Clean a string from all accent characters to be used as ref, login or by dol_sanitizeFileName.
dol_now($mode='gmt')
Return date for now.
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='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getLibStatut($mode=0)
Return status label of object.
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
Class to manage invoices.
EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf='\n', $format='FRST')
Write sender of request (me).
DeleteNotification($user, $action)
Delete a notification.
getNomUrl($withpicto=0, $option='')
Returns clickable name (with picto)
AddFacture($facture_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key)
Add invoice to withdrawal.
DeleteNotificationById($rowid)
Delete a notification def by id.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
EnregDestinataire($rowid, $client_nom, $rib_banque, $rib_guichet, $rib_number, $amount, $facnumber, $facid, $rib_dom='')
Write recipient of request (customer)
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Create($banque=0, $agence=0, $mode='real', $format='ALL', $executiondate='')
Create a withdraw TODO delete params banque and agence when not necesary.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.