dolibarr  7.0.0-beta
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@capnetworks.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 {
36  public $element='chequereceipt';
37  public $table_element='bordereau_cheque';
38  public $picto = 'payment';
39 
40  var $num;
41  var $intitule;
43  var $errno;
44 
45  public $amount;
46  public $date_bordereau;
47  public $account_id;
48  public $account_label;
49  public $author_id;
50  public $nbcheque;
51  public $ref;
52 
58  function __construct($db)
59  {
60  $this->db = $db;
61  $this->next_id = 0;
62  $this->previous_id = 0;
63  }
64 
72  function fetch($id,$ref='')
73  {
74  global $conf;
75 
76  $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";
77  $sql.= ", bc.date_bordereau as date_bordereau";
78  $sql.= ", ba.label as account_label";
79  $sql.= " FROM ".MAIN_DB_PREFIX."bordereau_cheque as bc";
80  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON bc.fk_bank_account = ba.rowid";
81  $sql.= " WHERE bc.entity = ".$conf->entity;
82  if ($id) $sql.= " AND bc.rowid = ".$id;
83  if ($ref) $sql.= " AND bc.ref = '".$this->db->escape($ref)."'";
84 
85  dol_syslog("RemiseCheque::fetch", LOG_DEBUG);
86  $resql = $this->db->query($sql);
87  if ($resql)
88  {
89  if ($obj = $this->db->fetch_object($resql) )
90  {
91  $this->id = $obj->rowid;
92  $this->amount = $obj->amount;
93  $this->date_bordereau = $this->db->jdate($obj->date_bordereau);
94  $this->account_id = $obj->fk_bank_account;
95  $this->account_label = $obj->account_label;
96  $this->author_id = $obj->fk_user_author;
97  $this->nbcheque = $obj->nbcheque;
98  $this->statut = $obj->statut;
99  $this->ref_ext = $obj->ref_ext;
100 
101  if ($this->statut == 0)
102  {
103  $this->ref = "(PROV".$this->id.")";
104  }
105  else
106  {
107  $this->ref = $obj->ref;
108  }
109 
110  }
111  $this->db->free($resql);
112 
113  return 1;
114  }
115  else
116  {
117  $this->error=$this->db->lasterror();
118  return -1;
119  }
120  }
121 
131  function create($user, $account_id, $limit, $toRemise)
132  {
133  global $conf;
134 
135  $this->errno = 0;
136  $this->id = 0;
137 
138  $now=dol_now();
139 
140  $this->db->begin();
141 
142  $sql = "INSERT INTO ".MAIN_DB_PREFIX."bordereau_cheque (";
143  $sql.= "datec";
144  $sql.= ", date_bordereau";
145  $sql.= ", fk_user_author";
146  $sql.= ", fk_bank_account";
147  $sql.= ", statut";
148  $sql.= ", amount";
149  $sql.= ", ref";
150  $sql.= ", entity";
151  $sql.= ", nbcheque";
152  $sql.= ", ref_ext";
153  $sql.= ") VALUES (";
154  $sql.= "'".$this->db->idate($now)."'";
155  $sql.= ", '".$this->db->idate($now)."'";
156  $sql.= ", ".$user->id;
157  $sql.= ", ".$account_id;
158  $sql.= ", 0";
159  $sql.= ", 0";
160  $sql.= ", 0";
161  $sql.= ", ".$conf->entity;
162  $sql.= ", 0";
163  $sql.= ", ''";
164  $sql.= ")";
165 
166  dol_syslog("RemiseCheque::Create", LOG_DEBUG);
167  $resql = $this->db->query($sql);
168  if ( $resql )
169  {
170  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bordereau_cheque");
171  if ($this->id == 0)
172  {
173  $this->errno = -1024;
174  dol_syslog("Remisecheque::Create Error read id ".$this->errno, LOG_ERR);
175  }
176 
177  if ($this->id > 0 && $this->errno == 0)
178  {
179  $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
180  $sql.= " SET ref='(PROV".$this->id.")'";
181  $sql.= " WHERE rowid=".$this->id."";
182 
183  dol_syslog("RemiseCheque::Create", LOG_DEBUG);
184  $resql = $this->db->query($sql);
185  if (! $resql)
186  {
187  $this->errno = -1025;
188  dol_syslog("RemiseCheque::Create Error update ".$this->errno, LOG_ERR);
189  }
190  }
191 
192  if ($this->id > 0 && $this->errno == 0)
193  {
194  $lines = array();
195  $sql = "SELECT b.rowid";
196  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
197  $sql.= " WHERE b.fk_type = 'CHQ'";
198  $sql.= " AND b.amount > 0";
199  $sql.= " AND b.fk_bordereau = 0";
200  $sql.= " AND b.fk_account='".$account_id."'";
201  if ($limit) $sql.= $this->db->plimit($limit);
202 
203  dol_syslog("RemiseCheque::Create", LOG_DEBUG);
204  $resql = $this->db->query($sql);
205  if ($resql)
206  {
207  while ($row = $this->db->fetch_row($resql) )
208  {
209  array_push($lines, $row[0]);
210  }
211  $this->db->free($resql);
212  }
213  else
214  {
215  $this->errno = -1026;
216  dol_syslog("RemiseCheque::Create Error ".$this->errno, LOG_ERR);
217  }
218  }
219 
220  if ($this->id > 0 && $this->errno == 0)
221  {
222  foreach ($lines as $lineid)
223  {
224  $checkremise=false;
225  foreach ($toRemise as $linetoremise)
226  {
227  if($linetoremise==$lineid) $checkremise=true;
228  }
229 
230  if($checkremise==true)
231  {
232  $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
233  $sql.= " SET fk_bordereau = ".$this->id;
234  $sql.= " WHERE rowid = ".$lineid;
235 
236  dol_syslog("RemiseCheque::Create", LOG_DEBUG);
237  $resql = $this->db->query($sql);
238  if (!$resql)
239  {
240  $this->errno = -18;
241  dol_syslog("RemiseCheque::Create Error update bank ".$this->errno, LOG_ERR);
242  }
243  }
244  }
245  }
246 
247  if ($this->id > 0 && $this->errno == 0)
248  {
249  if ($this->updateAmount() <> 0)
250  {
251  $this->errno = -1027;
252  dol_syslog("RemiseCheque::Create Error update amount ".$this->errno, LOG_ERR);
253  }
254  }
255  }
256  else
257  {
258  $this->errno = -1;
259  $this->error=$this->db->lasterror();
260  $this->errno=$this->db->lasterrno();
261  }
262 
263  if (! $this->errno && ! empty($conf->global->MAIN_DISABLEDRAFTSTATUS))
264  {
265  $res=$this->validate($user);
266  //if ($res < 0) $error++;
267  }
268 
269  if (! $this->errno)
270  {
271  $this->db->commit();
272  return $this->id;
273  }
274  else
275  {
276  $this->db->rollback();
277  return $this->errno;
278  }
279  }
280 
287  function delete($user='')
288  {
289  global $conf;
290 
291  $this->errno = 0;
292  $this->db->begin();
293 
294  $sql = "DELETE FROM ".MAIN_DB_PREFIX."bordereau_cheque";
295  $sql.= " WHERE rowid = ".$this->id;
296  $sql.= " AND entity = ".$conf->entity;
297 
298  $resql = $this->db->query($sql);
299  if ( $resql )
300  {
301  $num = $this->db->affected_rows($resql);
302 
303  if ($num <> 1) {
304  $this->errno = -2;
305  dol_syslog("Remisecheque::Delete Erreur Lecture ID ($this->errno)");
306  }
307 
308  if ( $this->errno === 0) {
309  $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
310  $sql.= " SET fk_bordereau = 0";
311  $sql.= " WHERE fk_bordereau = ".$this->id;
312 
313  $resql = $this->db->query($sql);
314  if (!$resql)
315  {
316  $this->errno = -1028;
317  dol_syslog("RemiseCheque::Delete ERREUR UPDATE ($this->errno)");
318  }
319  }
320  }
321 
322  if ($this->errno === 0)
323  {
324  $this->db->commit();
325  }
326  else
327  {
328  $this->db->rollback();
329  dol_syslog("RemiseCheque::Delete ROLLBACK ($this->errno)");
330  }
331 
332  return $this->errno;
333  }
334 
341  function validate($user)
342  {
343  global $langs,$conf;
344 
345  $this->errno = 0;
346 
347  $this->db->begin();
348 
349  $numref = $this->getNextNumRef();
350 
351  if ($this->errno == 0 && $numref)
352  {
353  $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
354  $sql.= " SET statut = 1, ref = '".$numref."'";
355  $sql.= " WHERE rowid = ".$this->id;
356  $sql.= " AND entity = ".$conf->entity;
357  $sql.= " AND statut = 0";
358 
359  dol_syslog("RemiseCheque::Validate", LOG_DEBUG);
360  $resql = $this->db->query($sql);
361  if ( $resql )
362  {
363  $num = $this->db->affected_rows($resql);
364 
365  if ($num == 1)
366  {
367  $this->ref = $numref;
368  $this->statut = 1;
369  }
370  else
371  {
372  $this->errno = -1029;
373  dol_syslog("Remisecheque::Validate Error ".$this->errno, LOG_ERR);
374  }
375  }
376  else
377  {
378  $this->errno = -1033;
379  dol_syslog("Remisecheque::Validate Error ".$this->errno, LOG_ERR);
380  }
381  }
382 
383  // Commit/Rollback
384  if ($this->errno == 0)
385  {
386  $this->db->commit();
387  return 1;
388  }
389  else
390  {
391  $this->db->rollback();
392  dol_syslog("RemiseCheque::Validate ".$this->errno, LOG_ERR);
393  return $this->errno;
394  }
395  }
396 
404  function getNextNumRef($mode='next')
405  {
406  global $conf, $db, $langs, $mysoc;
407  $langs->load("bills");
408 
409  // Clean parameters (if not defined or using deprecated value)
410  if (empty($conf->global->CHEQUERECEIPTS_ADDON)) $conf->global->CHEQUERECEIPTS_ADDON='mod_chequereceipt_mint';
411  else if ($conf->global->CHEQUERECEIPTS_ADDON=='thyme') $conf->global->CHEQUERECEIPTS_ADDON='mod_chequereceipt_thyme';
412  else if ($conf->global->CHEQUERECEIPTS_ADDON=='mint') $conf->global->CHEQUERECEIPTS_ADDON='mod_chequereceipt_mint';
413 
414  if (! empty($conf->global->CHEQUERECEIPTS_ADDON))
415  {
416  $mybool=false;
417 
418  $file = $conf->global->CHEQUERECEIPTS_ADDON.".php";
419  $classname = $conf->global->CHEQUERECEIPTS_ADDON;
420 
421  // Include file with class
422  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
423 
424  foreach ($dirmodels as $reldir) {
425 
426  $dir = dol_buildpath($reldir."core/modules/cheque/");
427 
428  // Load file with numbering class (if found)
429  if (is_file($dir.$file) && is_readable($dir.$file))
430  {
431  $mybool |= include_once $dir . $file;
432  }
433  }
434 
435  // For compatibility
436  if (! $mybool)
437  {
438  $file = $conf->global->CHEQUERECEIPTS_ADDON.".php";
439  $classname = "mod_chequereceipt_".$conf->global->CHEQUERECEIPTS_ADDON;
440  $classname = preg_replace('/\-.*$/','',$classname);
441  // Include file with class
442  foreach ($conf->file->dol_document_root as $dirroot)
443  {
444  $dir = $dirroot."/core/modules/cheque/";
445 
446  // Load file with numbering class (if found)
447  if (is_file($dir.$file) && is_readable($dir.$file)) {
448  $mybool |= include_once $dir . $file;
449  }
450  }
451  }
452 
453  if (! $mybool)
454  {
455  dol_print_error('',"Failed to include file ".$file);
456  return '';
457  }
458 
459  $obj = new $classname();
460  $numref = "";
461  $numref = $obj->getNextValue($mysoc,$this);
462 
467  if ($mode != 'last' && !$numref) {
468  dol_print_error($db,"ChequeReceipts::getNextNumRef ".$obj->error);
469  return "";
470  }
471 
472  return $numref;
473  }
474  else
475  {
476  $langs->load("errors");
477  print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete");
478  return "";
479  }
480  }
481 
482 
489  function load_board($user)
490  {
491  global $conf, $langs;
492 
493  if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe
494 
495  $sql = "SELECT b.rowid, b.datev as datefin";
496  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
497  $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
498  $sql.= " WHERE b.fk_account = ba.rowid";
499  $sql.= " AND ba.entity IN (".getEntity('bank_account').")";
500  $sql.= " AND b.fk_type = 'CHQ'";
501  $sql.= " AND b.fk_bordereau = 0";
502  $sql.= " AND b.amount > 0";
503 
504  $resql=$this->db->query($sql);
505  if ($resql)
506  {
507  $langs->load("banks");
508  $now=dol_now();
509 
510  $response = new WorkboardResponse();
511  $response->warning_delay=$conf->bank->cheque->warning_delay/60/60/24;
512  $response->label=$langs->trans("BankChecksToReceipt");
513  $response->url=DOL_URL_ROOT.'/compta/paiement/cheque/index.php?leftmenu=checks&amp;mainmenu=bank';
514  $response->img=img_object('',"payment");
515 
516  while ($obj=$this->db->fetch_object($resql))
517  {
518  $response->nbtodo++;
519 
520  if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->cheque->warning_delay)) {
521  $response->nbtodolate++;
522  }
523  }
524 
525  return $response;
526  }
527  else
528  {
529  dol_print_error($this->db);
530  $this->error=$this->db->error();
531  return -1;
532  }
533  }
534 
535 
541  function load_state_board()
542  {
543  global $user;
544 
545  if ($user->societe_id) return -1; // protection pour eviter appel par utilisateur externe
546 
547  $sql = "SELECT count(b.rowid) as nb";
548  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
549  $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
550  $sql.= " WHERE b.fk_account = ba.rowid";
551  $sql.= " AND ba.entity IN (".getEntity('bank_account').")";
552  $sql.= " AND b.fk_type = 'CHQ'";
553  $sql.= " AND b.amount > 0";
554 
555  $resql=$this->db->query($sql);
556  if ($resql)
557  {
558 
559  while ($obj=$this->db->fetch_object($resql))
560  {
561  $this->nb["cheques"]=$obj->nb;
562  }
563  $this->db->free($resql);
564  return 1;
565  }
566  else
567  {
568  dol_print_error($this->db);
569  $this->error=$this->db->error();
570  return -1;
571  }
572  }
573 
574 
582  function generatePdf($model, $outputlangs)
583  {
584  global $langs,$conf;
585 
586  if (empty($model)) $model='blochet';
587 
588  dol_syslog("RemiseCheque::generatePdf model=".$model." id=".$this->id, LOG_DEBUG);
589 
590  $dir=DOL_DOCUMENT_ROOT ."/core/modules/cheque/doc/";
591 
592  // Charge le modele
593  $file = "pdf_".$model.".class.php";
594  if (file_exists($dir.$file))
595  {
596  require_once DOL_DOCUMENT_ROOT .'/compta/bank/class/account.class.php';
597  require_once $dir.$file;
598 
599  $classname='BordereauCheque'.ucfirst($model);
600  $docmodel = new $classname($this->db);
601 
602  $sql = "SELECT b.banque, b.emetteur, b.amount, b.num_chq";
603  $sql.= " FROM ".MAIN_DB_PREFIX."bank as b";
604  $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba";
605  $sql.= ", ".MAIN_DB_PREFIX."bordereau_cheque as bc";
606  $sql.= " WHERE b.fk_account = ba.rowid";
607  $sql.= " AND b.fk_bordereau = bc.rowid";
608  $sql.= " AND bc.rowid = ".$this->id;
609  $sql.= " AND bc.entity = ".$conf->entity;
610  $sql.= " ORDER BY b.dateo ASC, b.rowid ASC";
611 
612  dol_syslog("RemiseCheque::generatePdf", LOG_DEBUG);
613  $result = $this->db->query($sql);
614  if ($result)
615  {
616  $i = 0;
617  while ($objp = $this->db->fetch_object($result))
618  {
619  $docmodel->lines[$i] = new stdClass();
620  $docmodel->lines[$i]->bank_chq = $objp->banque;
621  $docmodel->lines[$i]->emetteur_chq = $objp->emetteur;
622  $docmodel->lines[$i]->amount_chq = $objp->amount;
623  $docmodel->lines[$i]->num_chq = $objp->num_chq;
624  $i++;
625  }
626  }
627  $docmodel->nbcheque = $this->nbcheque;
628  $docmodel->ref = $this->ref;
629  $docmodel->amount = $this->amount;
630  $docmodel->date = $this->date_bordereau;
631 
632  $account = new Account($this->db);
633  $account->fetch($this->account_id);
634 
635  $docmodel->account = &$account;
636 
637  // We save charset_output to restore it because write_file can change it if needed for
638  // output format that does not support UTF8.
639  $sav_charseSupprimert_output=$outputlangs->charset_output;
640  $result=$docmodel->write_file($this, $conf->bank->dir_output.'/checkdeposits', $this->ref, $outputlangs);
641  if ($result > 0)
642  {
643  //$outputlangs->charset_output=$sav_charset_output;
644  return 1;
645  }
646  else
647  {
648  //$outputlangs->charset_output=$sav_charset_output;
649  dol_syslog("Error");
650  dol_print_error($this->db,$docmodel->error);
651  return 0;
652  }
653  }
654  else
655  {
656  $this->error=$langs->trans("ErrorFileDoesNotExists",$dir.$file);
657  return -1;
658  }
659  }
660 
666  function updateAmount()
667  {
668  global $conf;
669 
670  $this->errno = 0;
671  $this->db->begin();
672  $total = 0;
673  $nb = 0;
674  $sql = "SELECT amount ";
675  $sql.= " FROM ".MAIN_DB_PREFIX."bank";
676  $sql.= " WHERE fk_bordereau = ".$this->id;
677 
678  $resql = $this->db->query($sql);
679  if ( $resql )
680  {
681  while ( $row = $this->db->fetch_row($resql) )
682  {
683  $total += $row[0];
684  $nb++;
685  }
686 
687  $this->db->free($resql);
688 
689  $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
690  $sql.= " SET amount = '".price2num($total)."'";
691  $sql.= ", nbcheque = ".$nb;
692  $sql.= " WHERE rowid = ".$this->id;
693  $sql.= " AND entity = ".$conf->entity;
694 
695  $resql = $this->db->query($sql);
696  if (!$resql)
697  {
698  $this->errno = -1030;
699  dol_syslog("RemiseCheque::updateAmount ERREUR UPDATE ($this->errno)");
700  }
701  }
702  else
703  {
704  $this->errno = -1031;
705  dol_syslog("RemiseCheque::updateAmount ERREUR SELECT ($this->errno)");
706  }
707 
708  if ($this->errno === 0)
709  {
710  $this->db->commit();
711  }
712  else
713  {
714  $this->db->rollback();
715  dol_syslog("RemiseCheque::updateAmount ROLLBACK ($this->errno)");
716  }
717 
718  return $this->errno;
719  }
720 
727  function removeCheck($account_id)
728  {
729  $this->errno = 0;
730 
731  if ($this->id > 0)
732  {
733  $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
734  $sql.= " SET fk_bordereau = 0";
735  $sql.= " WHERE rowid = '".$account_id."'";
736  $sql.= " AND fk_bordereau = ".$this->id;
737 
738  $resql = $this->db->query($sql);
739  if ($resql)
740  {
741  $this->updateAmount();
742  }
743  else
744  {
745  $this->errno = -1032;
746  dol_syslog("RemiseCheque::removeCheck ERREUR UPDATE ($this->errno)");
747  }
748  }
749  return 0;
750  }
751 
760  function rejectCheck($bank_id, $rejection_date)
761  {
762  global $db, $user;
763 
764  $payment = new Paiement($db);
765  $payment->fetch(0,0,$bank_id);
766 
767  $bankline = new AccountLine($db);
768  $bankline->fetch($bank_id);
769 
770  /* Conciliation is allowed because when check is returned, a new line is created onto bank transaction log.
771  if ($bankline->rappro)
772  {
773  $this->error='ActionRefusedLineAlreadyConciliated';
774  return -1;
775  }*/
776 
777  $this->db->begin();
778 
779  // Not conciliated, we can delete it
780  //$bankline->delete($user); // We delete
781 
782  $bankaccount = $payment->fk_account;
783 
784  // Get invoices list to reopen them
785  $sql = 'SELECT pf.fk_facture, pf.amount';
786  $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
787  $sql.= ' WHERE pf.fk_paiement = '.$payment->id;
788 
789  $resql=$db->query($sql);
790  if ($resql)
791  {
792  $rejectedPayment = new Paiement($db);
793  $rejectedPayment->amounts = array();
794  $rejectedPayment->datepaye = $rejection_date;
795  $rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement','code','id',1);
796  $rejectedPayment->num_paiement = $payment->numero;
797 
798  while($obj = $db->fetch_object($resql))
799  {
800  $invoice = new Facture($db);
801  $invoice->fetch($obj->fk_facture);
802  $invoice->set_unpaid($user);
803 
804  $rejectedPayment->amounts[$obj->fk_facture] = price2num($obj->amount) * -1;
805  }
806 
807  $result = $rejectedPayment->create($user);
808  if ($result > 0)
809  {
810  // We created a negative payment, we also add the line as bank transaction
811  $result=$rejectedPayment->addPaymentToBank($user,'payment','(CheckRejected)',$bankaccount,'','');
812  if ($result > 0)
813  {
814  $result = $payment->reject();
815  if ($result > 0)
816  {
817  $this->db->commit();
818  return $rejectedPayment->id;
819  }
820  else
821  {
822  $this->db->rollback();
823  return -1;
824  }
825  }
826  else
827  {
828  $this->error = $rejectedPayment->error;
829  $this->errors = $rejectedPayment->errors;
830  $this->db->rollback();
831  return -1;
832  }
833  }
834  else
835  {
836  $this->error = $rejectedPayment->error;
837  $this->errors = $rejectedPayment->errors;
838  $this->db->rollback();
839  return -1;
840  }
841  }
842  else
843  {
844  $this->error=$this->db->lasterror();
845  $this->db->rollback();
846  return -1;
847  }
848  }
849 
856  {
857  global $conf;
858 
859  $this->errno = 0;
860 
861  $sql = "SELECT MAX(rowid)";
862  $sql.= " FROM ".MAIN_DB_PREFIX."bordereau_cheque";
863  $sql.= " WHERE rowid < ".$this->id;
864  $sql.= " AND entity = ".$conf->entity;
865 
866  $result = $this->db->query($sql);
867  if (! $result)
868  {
869  $this->errno = -1035;
870  }
871  $row = $this->db->fetch_row($result);
872  $this->previous_id = $row[0];
873 
874  $sql = "SELECT MIN(rowid)";
875  $sql.= " FROM ".MAIN_DB_PREFIX."bordereau_cheque";
876  $sql.= " WHERE rowid > ".$this->id;
877  $sql.= " AND entity = ".$conf->entity;
878 
879  $result = $this->db->query($sql);
880  if (! $result)
881  {
882  $this->errno = -1035;
883  }
884  $row = $this->db->fetch_row($result);
885  $this->next_id = $row[0];
886 
887  return $this->errno;
888  }
889 
890 
898  function set_date($user, $date)
899  {
900  if ($user->rights->banque->cheque)
901  {
902  $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
903  $sql.= " SET date_bordereau = ".($date ? "'".$this->db->idate($date)."'" : 'null');
904  $sql.= " WHERE rowid = ".$this->id;
905 
906  dol_syslog("RemiseCheque::set_date", LOG_DEBUG);
907  $resql=$this->db->query($sql);
908  if ($resql)
909  {
910  $this->date_bordereau = $date;
911  return 1;
912  }
913  else
914  {
915  $this->error=$this->db->error();
916  return -1;
917  }
918  }
919  else
920  {
921  return -2;
922  }
923  }
924 
932  function set_number($user, $ref)
933  {
934  if ($user->rights->banque->cheque)
935  {
936  $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
937  $sql.= " SET ref = '".$ref."'" ;
938  $sql.= " WHERE rowid = ".$this->id;
939 
940  dol_syslog("RemiseCheque::set_number", LOG_DEBUG);
941  $resql=$this->db->query($sql);
942  if ($resql)
943  {
944  return 1;
945  }
946  else
947  {
948  $this->error=$this->db->error();
949  return -1;
950  }
951  }
952  else
953  {
954  return -2;
955  }
956  }
957 
966  function initAsSpecimen($option='')
967  {
968  global $user,$langs,$conf;
969 
970  $now=dol_now();
971  $arraynow=dol_getdate($now);
972  $nownotime=dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
973 
974  // Initialize parameters
975  $this->id=0;
976  $this->ref = 'SPECIMEN';
977  $this->specimen=1;
978  $this->date_bordereau = $nownotime;
979  }
980 
988  function getNomUrl($withpicto=0,$option='')
989  {
990  global $langs;
991 
992  $result='';
993  $label = $langs->trans("ShowCheckReceipt").': '.$this->ref;
994 
995  $link = '<a href="'.DOL_URL_ROOT.'/compta/paiement/cheque/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
996  $linkend='</a>';
997 
998  if ($withpicto) $result.=($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend);
999  if ($withpicto && $withpicto != 2) $result.=' ';
1000  if ($withpicto != 2) $result.=$link.$this->ref.$linkend;
1001 
1002  return $result;
1003  }
1004 
1011  function getLibStatut($mode=0)
1012  {
1013  return $this->LibStatut($this->statut,$mode);
1014  }
1015 
1023  function LibStatut($status,$mode=0)
1024  {
1025  global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage
1026  $langs->load('compta');
1027  if ($mode == 0)
1028  {
1029  if ($status == 0) return $langs->trans('ToValidate');
1030  if ($status == 1) return $langs->trans('Validated');
1031  }
1032  if ($mode == 1)
1033  {
1034  if ($status == 0) return $langs->trans('ToValidate');
1035  if ($status == 1) return $langs->trans('Validated');
1036  }
1037  if ($mode == 2)
1038  {
1039  if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut0').' '.$langs->trans('ToValidate');
1040  if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
1041  }
1042  if ($mode == 3)
1043  {
1044  if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut0');
1045  if ($status == 1) return img_picto($langs->trans('Validated'),'statut4');
1046  }
1047  if ($mode == 4)
1048  {
1049  if ($status == 0) return img_picto($langs->trans('ToValidate'),'statut0').' '.$langs->trans('ToValidate');
1050  if ($status == 1) return img_picto($langs->trans('Validated'),'statut4').' '.$langs->trans('Validated');
1051  }
1052  if ($mode == 5)
1053  {
1054  if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut0');
1055  if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
1056  }
1057  if ($mode == 6)
1058  {
1059  if ($status == 0) return $langs->trans('ToValidate').' '.img_picto($langs->trans('ToValidate'),'statut0');
1060  if ($status == 1) return $langs->trans('Validated').' '.img_picto($langs->trans('Validated'),'statut4');
1061  }
1062  return $langs->trans('Unknown');
1063  }
1064 
1065 }
set_date($user, $date)
Set the creation date.
getNomUrl($withpicto=0, $option='')
Return clicable name (with picto eventually)
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
fetch($id, $ref='')
Load record.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
LibStatut($status, $mode=0)
Return label of a status.
$errno
Numero d'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.
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.
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...
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.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
initAsSpecimen($option='')
Initialise an instance with random values.
dol_now($mode='gmt')
Return date for now.
updateAmount()
Mets a jour le montant total.
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:1013
getLibStatut($mode=0)
Retourne le libelle du statut d'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.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...
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.
generatePdf($model, $outputlangs)
Build document.
__construct($db)
Constructor.