dolibarr  9.0.0
remisecheque.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2007-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2011-2016 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2015 Marcos GarcĂ­a <marcosgdf@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
27 require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
29 
30 
35 {
39  public $element='chequereceipt';
40 
44  public $table_element='bordereau_cheque';
45 
49  public $picto = 'payment';
50 
51  public $num;
52  public $intitule;
54  public $errno;
55 
56  public $amount;
57  public $date_bordereau;
58  public $account_id;
59  public $account_label;
60  public $author_id;
61  public $nbcheque;
62 
66  public $ref;
67 
73  function __construct($db)
74  {
75  $this->db = $db;
76  $this->next_id = 0;
77  $this->previous_id = 0;
78  }
79 
87  function fetch($id,$ref='')
88  {
89  global $conf;
90 
91  $sql = "SELECT bc.rowid, bc.datec, bc.fk_user_author, bc.fk_bank_account, bc.amount, bc.ref, bc.statut, bc.nbcheque, bc.ref_ext";
92  $sql.= ", bc.date_bordereau as date_bordereau";
93  $sql.= ", ba.label as account_label";
94  $sql.= " FROM ".MAIN_DB_PREFIX."bordereau_cheque as bc";
95  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON bc.fk_bank_account = ba.rowid";
96  $sql.= " WHERE bc.entity = ".$conf->entity;
97  if ($id) $sql.= " AND bc.rowid = ".$id;
98  if ($ref) $sql.= " AND bc.ref = '".$this->db->escape($ref)."'";
99 
100  dol_syslog("RemiseCheque::fetch", LOG_DEBUG);
101  $resql = $this->db->query($sql);
102  if ($resql)
103  {
104  if ($obj = $this->db->fetch_object($resql) )
105  {
106  $this->id = $obj->rowid;
107  $this->amount = $obj->amount;
108  $this->date_bordereau = $this->db->jdate($obj->date_bordereau);
109  $this->account_id = $obj->fk_bank_account;
110  $this->account_label = $obj->account_label;
111  $this->author_id = $obj->fk_user_author;
112  $this->nbcheque = $obj->nbcheque;
113  $this->statut = $obj->statut;
114  $this->ref_ext = $obj->ref_ext;
115 
116  if ($this->statut == 0)
117  {
118  $this->ref = "(PROV".$this->id.")";
119  }
120  else
121  {
122  $this->ref = $obj->ref;
123  }
124  }
125  $this->db->free($resql);
126 
127  return 1;
128  }
129  else
130  {
131  $this->error=$this->db->lasterror();
132  return -1;
133  }
134  }
135 
145  function create($user, $account_id, $limit, $toRemise)
146  {
147  global $conf;
148 
149  $this->errno = 0;
150  $this->id = 0;
151 
152  $now=dol_now();
153 
154  dol_syslog("RemiseCheque::Create start", LOG_DEBUG);
155 
156  $this->db->begin();
157 
158  $sql = "INSERT INTO ".MAIN_DB_PREFIX."bordereau_cheque (";
159  $sql.= "datec";
160  $sql.= ", date_bordereau";
161  $sql.= ", fk_user_author";
162  $sql.= ", fk_bank_account";
163  $sql.= ", statut";
164  $sql.= ", amount";
165  $sql.= ", ref";
166  $sql.= ", entity";
167  $sql.= ", nbcheque";
168  $sql.= ", ref_ext";
169  $sql.= ") VALUES (";
170  $sql.= "'".$this->db->idate($now)."'";
171  $sql.= ", '".$this->db->idate($now)."'";
172  $sql.= ", ".$user->id;
173  $sql.= ", ".$account_id;
174  $sql.= ", 0";
175  $sql.= ", 0";
176  $sql.= ", 0";
177  $sql.= ", ".$conf->entity;
178  $sql.= ", 0";
179  $sql.= ", ''";
180  $sql.= ")";
181 
182  $resql = $this->db->query($sql);
183  if ( $resql )
184  {
185  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bordereau_cheque");
186  if ($this->id == 0)
187  {
188  $this->errno = -1024;
189  dol_syslog("Remisecheque::Create Error read id ".$this->errno, LOG_ERR);
190  }
191 
192  if ($this->id > 0 && $this->errno == 0)
193  {
194  $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
195  $sql.= " SET ref='(PROV".$this->id.")'";
196  $sql.= " WHERE rowid=".$this->id."";
197 
198  $resql = $this->db->query($sql);
199  if (! $resql)
200  {
201  $this->errno = -1025;
202  dol_syslog("RemiseCheque::Create Error update ".$this->errno, LOG_ERR);
203  }
204  }
205 
206  if ($this->id > 0 && $this->errno == 0)
207  {
208  $lines = array();
209  $sql = "SELECT b.rowid";
210  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
211  $sql.= " WHERE b.fk_type = 'CHQ'";
212  $sql.= " AND b.amount > 0";
213  $sql.= " AND b.fk_bordereau = 0";
214  $sql.= " AND b.fk_account='".$account_id."'";
215  if ($limit) $sql.= $this->db->plimit($limit);
216 
217  dol_syslog("RemiseCheque::Create", LOG_DEBUG);
218  $resql = $this->db->query($sql);
219  if ($resql)
220  {
221  while ($row = $this->db->fetch_row($resql) )
222  {
223  array_push($lines, $row[0]);
224  }
225  $this->db->free($resql);
226  }
227  else
228  {
229  $this->errno = -1026;
230  dol_syslog("RemiseCheque::Create Error ".$this->errno, LOG_ERR);
231  }
232  }
233 
234  if ($this->id > 0 && $this->errno == 0)
235  {
236  foreach ($lines as $lineid)
237  {
238  $checkremise=false;
239  foreach ($toRemise as $linetoremise)
240  {
241  if($linetoremise==$lineid) $checkremise=true;
242  }
243 
244  if ($checkremise)
245  {
246  $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
247  $sql.= " SET fk_bordereau = ".$this->id;
248  $sql.= " WHERE rowid = ".$lineid;
249 
250  $resql = $this->db->query($sql);
251  if (!$resql)
252  {
253  $this->errno = -18;
254  dol_syslog("RemiseCheque::Create Error update bank ".$this->errno, LOG_ERR);
255  }
256  }
257  }
258  }
259 
260  if ($this->id > 0 && $this->errno == 0)
261  {
262  if ($this->updateAmount() <> 0)
263  {
264  $this->errno = -1027;
265  dol_syslog("RemiseCheque::Create Error update amount ".$this->errno, LOG_ERR);
266  }
267  }
268  }
269  else
270  {
271  $this->errno = -1;
272  $this->error=$this->db->lasterror();
273  $this->errno=$this->db->lasterrno();
274  }
275 
276  if (! $this->errno && ! empty($conf->global->MAIN_DISABLEDRAFTSTATUS))
277  {
278  $res=$this->validate($user);
279  //if ($res < 0) $error++;
280  }
281 
282  if (! $this->errno)
283  {
284  $this->db->commit();
285  dol_syslog("RemiseCheque::Create end", LOG_DEBUG);
286  return $this->id;
287  }
288  else
289  {
290  $this->db->rollback();
291  dol_syslog("RemiseCheque::Create end", LOG_DEBUG);
292  return $this->errno;
293  }
294  }
295 
302  function delete($user='')
303  {
304  global $conf;
305 
306  $this->errno = 0;
307  $this->db->begin();
308 
309  $sql = "DELETE FROM ".MAIN_DB_PREFIX."bordereau_cheque";
310  $sql.= " WHERE rowid = ".$this->id;
311  $sql.= " AND entity = ".$conf->entity;
312 
313  $resql = $this->db->query($sql);
314  if ( $resql )
315  {
316  $num = $this->db->affected_rows($resql);
317 
318  if ($num <> 1) {
319  $this->errno = -2;
320  dol_syslog("Remisecheque::Delete Erreur Lecture ID ($this->errno)");
321  }
322 
323  if ( $this->errno === 0) {
324  $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
325  $sql.= " SET fk_bordereau = 0";
326  $sql.= " WHERE fk_bordereau = ".$this->id;
327 
328  $resql = $this->db->query($sql);
329  if (!$resql)
330  {
331  $this->errno = -1028;
332  dol_syslog("RemiseCheque::Delete ERREUR UPDATE ($this->errno)");
333  }
334  }
335  }
336 
337  if ($this->errno === 0)
338  {
339  $this->db->commit();
340  }
341  else
342  {
343  $this->db->rollback();
344  dol_syslog("RemiseCheque::Delete ROLLBACK ($this->errno)");
345  }
346 
347  return $this->errno;
348  }
349 
356  function validate($user)
357  {
358  global $langs,$conf;
359 
360  $this->errno = 0;
361 
362  $this->db->begin();
363 
364  $numref = $this->getNextNumRef();
365 
366  if ($this->errno == 0 && $numref)
367  {
368  $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
369  $sql.= " SET statut = 1, ref = '".$numref."'";
370  $sql.= " WHERE rowid = ".$this->id;
371  $sql.= " AND entity = ".$conf->entity;
372  $sql.= " AND statut = 0";
373 
374  dol_syslog("RemiseCheque::Validate", LOG_DEBUG);
375  $resql = $this->db->query($sql);
376  if ( $resql )
377  {
378  $num = $this->db->affected_rows($resql);
379 
380  if ($num == 1)
381  {
382  $this->ref = $numref;
383  $this->statut = 1;
384  }
385  else
386  {
387  $this->errno = -1029;
388  dol_syslog("Remisecheque::Validate Error ".$this->errno, LOG_ERR);
389  }
390  }
391  else
392  {
393  $this->errno = -1033;
394  dol_syslog("Remisecheque::Validate Error ".$this->errno, LOG_ERR);
395  }
396  }
397 
398  // Commit/Rollback
399  if ($this->errno == 0)
400  {
401  $this->db->commit();
402  return 1;
403  }
404  else
405  {
406  $this->db->rollback();
407  dol_syslog("RemiseCheque::Validate ".$this->errno, LOG_ERR);
408  return $this->errno;
409  }
410  }
411 
419  function getNextNumRef($mode='next')
420  {
421  global $conf, $db, $langs, $mysoc;
422  $langs->load("bills");
423 
424  // Clean parameters (if not defined or using deprecated value)
425  if (empty($conf->global->CHEQUERECEIPTS_ADDON)) $conf->global->CHEQUERECEIPTS_ADDON='mod_chequereceipt_mint';
426  else if ($conf->global->CHEQUERECEIPTS_ADDON=='thyme') $conf->global->CHEQUERECEIPTS_ADDON='mod_chequereceipt_thyme';
427  else if ($conf->global->CHEQUERECEIPTS_ADDON=='mint') $conf->global->CHEQUERECEIPTS_ADDON='mod_chequereceipt_mint';
428 
429  if (! empty($conf->global->CHEQUERECEIPTS_ADDON))
430  {
431  $mybool=false;
432 
433  $file = $conf->global->CHEQUERECEIPTS_ADDON.".php";
434  $classname = $conf->global->CHEQUERECEIPTS_ADDON;
435 
436  // Include file with class
437  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
438 
439  foreach ($dirmodels as $reldir) {
440 
441  $dir = dol_buildpath($reldir."core/modules/cheque/");
442 
443  // Load file with numbering class (if found)
444  if (is_file($dir.$file) && is_readable($dir.$file))
445  {
446  $mybool |= include_once $dir . $file;
447  }
448  }
449 
450  // For compatibility
451  if (! $mybool)
452  {
453  $file = $conf->global->CHEQUERECEIPTS_ADDON.".php";
454  $classname = "mod_chequereceipt_".$conf->global->CHEQUERECEIPTS_ADDON;
455  $classname = preg_replace('/\-.*$/','',$classname);
456  // Include file with class
457  foreach ($conf->file->dol_document_root as $dirroot)
458  {
459  $dir = $dirroot."/core/modules/cheque/";
460 
461  // Load file with numbering class (if found)
462  if (is_file($dir.$file) && is_readable($dir.$file)) {
463  $mybool |= include_once $dir . $file;
464  }
465  }
466  }
467 
468  if (! $mybool)
469  {
470  dol_print_error('',"Failed to include file ".$file);
471  return '';
472  }
473 
474  $obj = new $classname();
475  $numref = "";
476  $numref = $obj->getNextValue($mysoc,$this);
477 
482  if ($mode != 'last' && !$numref) {
483  dol_print_error($db,"ChequeReceipts::getNextNumRef ".$obj->error);
484  return "";
485  }
486 
487  return $numref;
488  }
489  else
490  {
491  $langs->load("errors");
492  print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete");
493  return "";
494  }
495  }
496 
497 
498  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
505  function load_board($user)
506  {
507  // phpcs:enable
508  global $conf, $langs;
509 
510  if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe
511 
512  $sql = "SELECT b.rowid, b.datev as datefin";
513  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
514  $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
515  $sql.= " WHERE b.fk_account = ba.rowid";
516  $sql.= " AND ba.entity IN (".getEntity('bank_account').")";
517  $sql.= " AND b.fk_type = 'CHQ'";
518  $sql.= " AND b.fk_bordereau = 0";
519  $sql.= " AND b.amount > 0";
520 
521  $resql=$this->db->query($sql);
522  if ($resql)
523  {
524  $langs->load("banks");
525  $now=dol_now();
526 
527  $response = new WorkboardResponse();
528  $response->warning_delay=$conf->bank->cheque->warning_delay/60/60/24;
529  $response->label=$langs->trans("BankChecksToReceipt");
530  $response->url=DOL_URL_ROOT.'/compta/paiement/cheque/index.php?leftmenu=checks&amp;mainmenu=bank';
531  $response->img=img_object('',"payment");
532 
533  while ($obj=$this->db->fetch_object($resql))
534  {
535  $response->nbtodo++;
536 
537  if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->cheque->warning_delay)) {
538  $response->nbtodolate++;
539  }
540  }
541 
542  return $response;
543  }
544  else
545  {
546  dol_print_error($this->db);
547  $this->error=$this->db->error();
548  return -1;
549  }
550  }
551 
552 
553  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
559  function load_state_board()
560  {
561  // phpcs:enable
562  global $user;
563 
564  if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe
565 
566  $sql = "SELECT count(b.rowid) as nb";
567  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
568  $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
569  $sql.= " WHERE b.fk_account = ba.rowid";
570  $sql.= " AND ba.entity IN (".getEntity('bank_account').")";
571  $sql.= " AND b.fk_type = 'CHQ'";
572  $sql.= " AND b.amount > 0";
573 
574  $resql=$this->db->query($sql);
575  if ($resql)
576  {
577 
578  while ($obj=$this->db->fetch_object($resql))
579  {
580  $this->nb["cheques"]=$obj->nb;
581  }
582  $this->db->free($resql);
583  return 1;
584  }
585  else
586  {
587  dol_print_error($this->db);
588  $this->error=$this->db->error();
589  return -1;
590  }
591  }
592 
593 
601  function generatePdf($model, $outputlangs)
602  {
603  global $langs,$conf;
604 
605  if (empty($model)) $model='blochet';
606 
607  dol_syslog("RemiseCheque::generatePdf model=".$model." id=".$this->id, LOG_DEBUG);
608 
609  $dir=DOL_DOCUMENT_ROOT ."/core/modules/cheque/doc/";
610 
611  // Charge le modele
612  $file = "pdf_".$model.".class.php";
613  if (file_exists($dir.$file))
614  {
615  include_once DOL_DOCUMENT_ROOT .'/compta/bank/class/account.class.php';
616  include_once $dir.$file;
617 
618  $classname='BordereauCheque'.ucfirst($model);
619  $docmodel = new $classname($this->db);
620 
621  $sql = "SELECT b.banque, b.emetteur, b.amount, b.num_chq";
622  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
623  $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
624  $sql.= ", ".MAIN_DB_PREFIX."bordereau_cheque as bc";
625  $sql.= " WHERE b.fk_account = ba.rowid";
626  $sql.= " AND b.fk_bordereau = bc.rowid";
627  $sql.= " AND bc.rowid = ".$this->id;
628  $sql.= " AND bc.entity = ".$conf->entity;
629  $sql.= " ORDER BY b.dateo ASC, b.rowid ASC";
630 
631  dol_syslog("RemiseCheque::generatePdf", LOG_DEBUG);
632  $result = $this->db->query($sql);
633  if ($result)
634  {
635  $i = 0;
636  while ($objp = $this->db->fetch_object($result))
637  {
638  $docmodel->lines[$i] = new stdClass();
639  $docmodel->lines[$i]->bank_chq = $objp->banque;
640  $docmodel->lines[$i]->emetteur_chq = $objp->emetteur;
641  $docmodel->lines[$i]->amount_chq = $objp->amount;
642  $docmodel->lines[$i]->num_chq = $objp->num_chq;
643  $i++;
644  }
645  }
646  $docmodel->nbcheque = $this->nbcheque;
647  $docmodel->ref = $this->ref;
648  $docmodel->amount = $this->amount;
649  $docmodel->date = $this->date_bordereau;
650 
651  $account = new Account($this->db);
652  $account->fetch($this->account_id);
653 
654  $docmodel->account = &$account;
655 
656  // We save charset_output to restore it because write_file can change it if needed for
657  // output format that does not support UTF8.
658  $sav_charseSupprimert_output=$outputlangs->charset_output;
659  $result=$docmodel->write_file($this, $conf->bank->dir_output.'/checkdeposits', $this->ref, $outputlangs);
660  if ($result > 0)
661  {
662  //$outputlangs->charset_output=$sav_charset_output;
663  return 1;
664  }
665  else
666  {
667  //$outputlangs->charset_output=$sav_charset_output;
668  dol_syslog("Error");
669  dol_print_error($this->db,$docmodel->error);
670  return 0;
671  }
672  }
673  else
674  {
675  $this->error=$langs->trans("ErrorFileDoesNotExists",$dir.$file);
676  return -1;
677  }
678  }
679 
685  function updateAmount()
686  {
687  global $conf;
688 
689  $this->errno = 0;
690  $this->db->begin();
691  $total = 0;
692  $nb = 0;
693  $sql = "SELECT amount ";
694  $sql.= " FROM ".MAIN_DB_PREFIX."bank";
695  $sql.= " WHERE fk_bordereau = ".$this->id;
696 
697  $resql = $this->db->query($sql);
698  if ( $resql )
699  {
700  while ( $row = $this->db->fetch_row($resql) )
701  {
702  $total += $row[0];
703  $nb++;
704  }
705 
706  $this->db->free($resql);
707 
708  $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
709  $sql.= " SET amount = '".price2num($total)."'";
710  $sql.= ", nbcheque = ".$nb;
711  $sql.= " WHERE rowid = ".$this->id;
712  $sql.= " AND entity = ".$conf->entity;
713 
714  $resql = $this->db->query($sql);
715  if (!$resql)
716  {
717  $this->errno = -1030;
718  dol_syslog("RemiseCheque::updateAmount ERREUR UPDATE ($this->errno)");
719  }
720  }
721  else
722  {
723  $this->errno = -1031;
724  dol_syslog("RemiseCheque::updateAmount ERREUR SELECT ($this->errno)");
725  }
726 
727  if ($this->errno === 0)
728  {
729  $this->db->commit();
730  }
731  else
732  {
733  $this->db->rollback();
734  dol_syslog("RemiseCheque::updateAmount ROLLBACK ($this->errno)");
735  }
736 
737  return $this->errno;
738  }
739 
746  function removeCheck($account_id)
747  {
748  $this->errno = 0;
749 
750  if ($this->id > 0)
751  {
752  $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
753  $sql.= " SET fk_bordereau = 0";
754  $sql.= " WHERE rowid = '".$account_id."'";
755  $sql.= " AND fk_bordereau = ".$this->id;
756 
757  $resql = $this->db->query($sql);
758  if ($resql)
759  {
760  $this->updateAmount();
761  }
762  else
763  {
764  $this->errno = -1032;
765  dol_syslog("RemiseCheque::removeCheck ERREUR UPDATE ($this->errno)");
766  }
767  }
768  return 0;
769  }
770 
779  function rejectCheck($bank_id, $rejection_date)
780  {
781  global $db, $user;
782 
783  $payment = new Paiement($db);
784  $payment->fetch(0,0,$bank_id);
785 
786  $bankline = new AccountLine($db);
787  $bankline->fetch($bank_id);
788 
789  /* Conciliation is allowed because when check is returned, a new line is created onto bank transaction log.
790  if ($bankline->rappro)
791  {
792  $this->error='ActionRefusedLineAlreadyConciliated';
793  return -1;
794  }*/
795 
796  $this->db->begin();
797 
798  // Not conciliated, we can delete it
799  //$bankline->delete($user); // We delete
800 
801  $bankaccount = $payment->fk_account;
802 
803  // Get invoices list to reopen them
804  $sql = 'SELECT pf.fk_facture, pf.amount';
805  $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
806  $sql.= ' WHERE pf.fk_paiement = '.$payment->id;
807 
808  $resql=$db->query($sql);
809  if ($resql)
810  {
811  $rejectedPayment = new Paiement($db);
812  $rejectedPayment->amounts = array();
813  $rejectedPayment->datepaye = $rejection_date;
814  $rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement','code','id',1);
815  $rejectedPayment->num_paiement = $payment->numero;
816 
817  while($obj = $db->fetch_object($resql))
818  {
819  $invoice = new Facture($db);
820  $invoice->fetch($obj->fk_facture);
821  $invoice->set_unpaid($user);
822 
823  $rejectedPayment->amounts[$obj->fk_facture] = price2num($obj->amount) * -1;
824  }
825 
826  $result = $rejectedPayment->create($user);
827  if ($result > 0)
828  {
829  // We created a negative payment, we also add the line as bank transaction
830  $result=$rejectedPayment->addPaymentToBank($user,'payment','(CheckRejected)',$bankaccount,'','');
831  if ($result > 0)
832  {
833  $result = $payment->reject();
834  if ($result > 0)
835  {
836  $this->db->commit();
837  return $rejectedPayment->id;
838  }
839  else
840  {
841  $this->db->rollback();
842  return -1;
843  }
844  }
845  else
846  {
847  $this->error = $rejectedPayment->error;
848  $this->errors = $rejectedPayment->errors;
849  $this->db->rollback();
850  return -1;
851  }
852  }
853  else
854  {
855  $this->error = $rejectedPayment->error;
856  $this->errors = $rejectedPayment->errors;
857  $this->db->rollback();
858  return -1;
859  }
860  }
861  else
862  {
863  $this->error=$this->db->lasterror();
864  $this->db->rollback();
865  return -1;
866  }
867  }
868 
869  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
876  {
877  // phpcs:enable
878  global $conf;
879 
880  $this->errno = 0;
881 
882  $sql = "SELECT MAX(rowid)";
883  $sql.= " FROM ".MAIN_DB_PREFIX."bordereau_cheque";
884  $sql.= " WHERE rowid < ".$this->id;
885  $sql.= " AND entity = ".$conf->entity;
886 
887  $result = $this->db->query($sql);
888  if (! $result)
889  {
890  $this->errno = -1035;
891  }
892  $row = $this->db->fetch_row($result);
893  $this->previous_id = $row[0];
894 
895  $sql = "SELECT MIN(rowid)";
896  $sql.= " FROM ".MAIN_DB_PREFIX."bordereau_cheque";
897  $sql.= " WHERE rowid > ".$this->id;
898  $sql.= " AND entity = ".$conf->entity;
899 
900  $result = $this->db->query($sql);
901  if (! $result)
902  {
903  $this->errno = -1035;
904  }
905  $row = $this->db->fetch_row($result);
906  $this->next_id = $row[0];
907 
908  return $this->errno;
909  }
910 
911 
912  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
920  function set_date($user, $date)
921  {
922  // phpcs:enable
923  if ($user->rights->banque->cheque)
924  {
925  $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
926  $sql.= " SET date_bordereau = ".($date ? "'".$this->db->idate($date)."'" : 'null');
927  $sql.= " WHERE rowid = ".$this->id;
928 
929  dol_syslog("RemiseCheque::set_date", LOG_DEBUG);
930  $resql=$this->db->query($sql);
931  if ($resql)
932  {
933  $this->date_bordereau = $date;
934  return 1;
935  }
936  else
937  {
938  $this->error=$this->db->error();
939  return -1;
940  }
941  }
942  else
943  {
944  return -2;
945  }
946  }
947 
948  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
956  function set_number($user, $ref)
957  {
958  // phpcs:enable
959  if ($user->rights->banque->cheque)
960  {
961  $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
962  $sql.= " SET ref = '".$ref."'" ;
963  $sql.= " WHERE rowid = ".$this->id;
964 
965  dol_syslog("RemiseCheque::set_number", LOG_DEBUG);
966  $resql=$this->db->query($sql);
967  if ($resql)
968  {
969  return 1;
970  }
971  else
972  {
973  $this->error=$this->db->error();
974  return -1;
975  }
976  }
977  else
978  {
979  return -2;
980  }
981  }
982 
991  function initAsSpecimen($option='')
992  {
993  global $user,$langs,$conf;
994 
995  $now=dol_now();
996  $arraynow=dol_getdate($now);
997  $nownotime=dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
998 
999  // Initialize parameters
1000  $this->id=0;
1001  $this->ref = 'SPECIMEN';
1002  $this->specimen=1;
1003  $this->date_bordereau = $nownotime;
1004  }
1005 
1016  function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
1017  {
1018  global $conf, $langs;
1019 
1020  $result='';
1021 
1022  $label = '<u>'.$langs->trans("ShowCheckReceipt").'</u>';
1023  $label.= '<br>';
1024  $label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
1025 
1026  $url = DOL_URL_ROOT.'/compta/paiement/cheque/card.php?id='.$this->id;
1027 
1028  if ($option != 'nolink')
1029  {
1030  // Add param to save lastsearch_values or not
1031  $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
1032  if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
1033  if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
1034  }
1035 
1036  $linkclose='';
1037  if (empty($notooltip))
1038  {
1039  if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1040  {
1041  $label=$langs->trans("ShowCheckReceipt");
1042  $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
1043  }
1044  $linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
1045  $linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
1046  }
1047  else $linkclose = ($morecss?' class="'.$morecss.'"':'');
1048 
1049  $linkstart = '<a href="'.$url.'"';
1050  $linkstart.=$linkclose.'>';
1051  $linkend='</a>';
1052 
1053  $result .= $linkstart;
1054  if ($withpicto) $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);
1055  if ($withpicto != 2) $result.= $this->ref;
1056  $result .= $linkend;
1057 
1058  return $result;
1059  }
1060 
1067  function getLibStatut($mode=0)
1068  {
1069  return $this->LibStatut($this->statut,$mode);
1070  }
1071 
1072  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1080  function LibStatut($status,$mode=0)
1081  {
1082  // phpcs:enable
1083  global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage
1084  $langs->load('compta');
1085  if ($mode == 0)
1086  {
1087  if ($status == 0) return $langs->trans('ToValidate');
1088  if ($status == 1) return $langs->trans('Validated');
1089  }
1090  elseif ($mode == 1)
1091  {
1092  if ($status == 0) return $langs->trans('ToValidate');
1093  if ($status == 1) return $langs->trans('Validated');
1094  }
1095  elseif ($mode == 2)
1096  {
1097  if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut0').' '.$langs->trans('ToValidate');
1098  if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
1099  }
1100  elseif ($mode == 3)
1101  {
1102  if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut0');
1103  if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
1104  }
1105  elseif ($mode == 4)
1106  {
1107  if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut0').' '.$langs->trans('ToValidate');
1108  if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
1109  }
1110  elseif ($mode == 5)
1111  {
1112  if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut0');
1113  if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
1114  }
1115  elseif ($mode == 6)
1116  {
1117  if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut0');
1118  if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
1119  }
1120  return $langs->trans('Unknown');
1121  }
1122 }
set_date($user, $date)
Set the creation date.
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
fetch($id, $ref='')
Load record.
print
Draft customers invoices.
Definition: index.php:91
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
LibStatut($status, $mode=0)
Return label of a status.
$errno
Numero d&#39;erreur Plage 1024-1279.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0)
Return an id or code from a code or id.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
getNextNumRef($mode='next')
Return next reference of cheque receipts not already used (or last reference) according to numbering ...
load_previous_next_id()
Charge les proprietes ref_previous et ref_next.
Class to manage bank transaction lines.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Class to manage bank accounts.
validate($user)
Validate a receipt.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
removeCheck($account_id)
Insere la remise en base.
Class to manage payments of customer invoices.
initAsSpecimen($option='')
Initialise an instance with random values.
dol_now($mode='gmt')
Return date for now.
updateAmount()
Mets a jour le montant total.
getLibStatut($mode=0)
Retourne le libelle du statut d&#39;une facture (brouillon, validee, abandonnee, payee) ...
set_number($user, $ref)
Set the ref of bordereau.
load_state_board()
Charge indicateurs this->nb de tableau de bord.
Class to manage invoices.
dol_getdate($timestamp, $fast=false)
Return an array with locale date info.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
Class to manage cheque delivery receipts.
rejectCheck($bank_id, $rejection_date)
Check return management Reopen linked invoices and create a new negative payment. ...
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
create($user, $account_id, $limit, $toRemise)
Create a receipt to send cheques.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
generatePdf($model, $outputlangs)
Build document.
__construct($db)
Constructor.