dolibarr  13.0.2
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 <https://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 
68  const STATUS_DRAFT = 0;
69  const STATUS_VALIDATED = 1;
70 
71 
77  public function __construct($db)
78  {
79  $this->db = $db;
80  $this->next_id = 0;
81  $this->previous_id = 0;
82  }
83 
91  public function fetch($id, $ref = '')
92  {
93  global $conf;
94 
95  $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";
96  $sql .= ", bc.date_bordereau as date_bordereau";
97  $sql .= ", ba.label as account_label";
98  $sql .= " FROM ".MAIN_DB_PREFIX."bordereau_cheque as bc";
99  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON bc.fk_bank_account = ba.rowid";
100  $sql .= " WHERE bc.entity = ".$conf->entity;
101  if ($id) $sql .= " AND bc.rowid = ".((int) $id);
102  if ($ref) $sql .= " AND bc.ref = '".$this->db->escape($ref)."'";
103 
104  dol_syslog("RemiseCheque::fetch", LOG_DEBUG);
105  $resql = $this->db->query($sql);
106  if ($resql)
107  {
108  if ($obj = $this->db->fetch_object($resql))
109  {
110  $this->id = $obj->rowid;
111  $this->amount = $obj->amount;
112  $this->date_bordereau = $this->db->jdate($obj->date_bordereau);
113  $this->account_id = $obj->fk_bank_account;
114  $this->account_label = $obj->account_label;
115  $this->author_id = $obj->fk_user_author;
116  $this->nbcheque = $obj->nbcheque;
117  $this->statut = $obj->statut;
118  $this->ref_ext = $obj->ref_ext;
119 
120  if ($this->statut == 0)
121  {
122  $this->ref = "(PROV".$this->id.")";
123  } else {
124  $this->ref = $obj->ref;
125  }
126  }
127  $this->db->free($resql);
128 
129  return 1;
130  } else {
131  $this->error = $this->db->lasterror();
132  return -1;
133  }
134  }
135 
145  public 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 = ".((int) $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  } else {
227  $this->errno = -1026;
228  dol_syslog("RemiseCheque::Create Error ".$this->errno, LOG_ERR);
229  }
230  }
231 
232  if ($this->id > 0 && $this->errno == 0)
233  {
234  foreach ($lines as $lineid)
235  {
236  $checkremise = false;
237  foreach ($toRemise as $linetoremise)
238  {
239  if ($linetoremise == $lineid) $checkremise = true;
240  }
241 
242  if ($checkremise)
243  {
244  $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
245  $sql .= " SET fk_bordereau = ".$this->id;
246  $sql .= " WHERE rowid = ".$lineid;
247 
248  $resql = $this->db->query($sql);
249  if (!$resql)
250  {
251  $this->errno = -18;
252  dol_syslog("RemiseCheque::Create Error update bank ".$this->errno, LOG_ERR);
253  }
254  }
255  }
256  }
257 
258  if ($this->id > 0 && $this->errno == 0)
259  {
260  if ($this->updateAmount() <> 0)
261  {
262  $this->errno = -1027;
263  dol_syslog("RemiseCheque::Create Error update amount ".$this->errno, LOG_ERR);
264  }
265  }
266  } else {
267  $this->errno = -1;
268  $this->error = $this->db->lasterror();
269  $this->errno = $this->db->lasterrno();
270  }
271 
272  if (!$this->errno && !empty($conf->global->MAIN_DISABLEDRAFTSTATUS))
273  {
274  $res = $this->validate($user);
275  //if ($res < 0) $error++;
276  }
277 
278  if (!$this->errno)
279  {
280  $this->db->commit();
281  dol_syslog("RemiseCheque::Create end", LOG_DEBUG);
282  return $this->id;
283  } else {
284  $this->db->rollback();
285  dol_syslog("RemiseCheque::Create end", LOG_DEBUG);
286  return $this->errno;
287  }
288  }
289 
296  public function delete($user = '')
297  {
298  global $conf;
299 
300  $this->errno = 0;
301  $this->db->begin();
302 
303  $sql = "DELETE FROM ".MAIN_DB_PREFIX."bordereau_cheque";
304  $sql .= " WHERE rowid = ".$this->id;
305  $sql .= " AND entity = ".$conf->entity;
306 
307  $resql = $this->db->query($sql);
308  if ($resql)
309  {
310  $num = $this->db->affected_rows($resql);
311 
312  if ($num <> 1) {
313  $this->errno = -2;
314  dol_syslog("Remisecheque::Delete Erreur Lecture ID ($this->errno)");
315  }
316 
317  if ($this->errno === 0) {
318  $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
319  $sql .= " SET fk_bordereau = 0";
320  $sql .= " WHERE fk_bordereau = ".$this->id;
321 
322  $resql = $this->db->query($sql);
323  if (!$resql)
324  {
325  $this->errno = -1028;
326  dol_syslog("RemiseCheque::Delete ERREUR UPDATE ($this->errno)");
327  }
328  }
329  }
330 
331  if ($this->errno === 0)
332  {
333  $this->db->commit();
334  } else {
335  $this->db->rollback();
336  dol_syslog("RemiseCheque::Delete ROLLBACK ($this->errno)");
337  }
338 
339  return $this->errno;
340  }
341 
348  public function validate($user)
349  {
350  global $langs, $conf;
351 
352  $this->errno = 0;
353 
354  $this->db->begin();
355 
356  $numref = $this->getNextNumRef();
357 
358  if ($this->errno == 0 && $numref)
359  {
360  $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
361  $sql .= " SET statut = 1, ref = '".$this->db->escape($numref)."'";
362  $sql .= " WHERE rowid = ".$this->id;
363  $sql .= " AND entity = ".$conf->entity;
364  $sql .= " AND statut = 0";
365 
366  dol_syslog("RemiseCheque::Validate", LOG_DEBUG);
367  $resql = $this->db->query($sql);
368  if ($resql)
369  {
370  $num = $this->db->affected_rows($resql);
371 
372  if ($num == 1)
373  {
374  $this->ref = $numref;
375  $this->statut = 1;
376  } else {
377  $this->errno = -1029;
378  dol_syslog("Remisecheque::Validate Error ".$this->errno, LOG_ERR);
379  }
380  } else {
381  $this->errno = -1033;
382  dol_syslog("Remisecheque::Validate Error ".$this->errno, LOG_ERR);
383  }
384  }
385 
386  // Commit/Rollback
387  if ($this->errno == 0)
388  {
389  $this->db->commit();
390  return 1;
391  } else {
392  $this->db->rollback();
393  dol_syslog("RemiseCheque::Validate ".$this->errno, LOG_ERR);
394  return $this->errno;
395  }
396  }
397 
405  public function getNextNumRef($mode = 'next')
406  {
407  global $conf, $db, $langs, $mysoc;
408  $langs->load("bills");
409 
410  // Clean parameters (if not defined or using deprecated value)
411  if (empty($conf->global->CHEQUERECEIPTS_ADDON)) $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_mint';
412  elseif ($conf->global->CHEQUERECEIPTS_ADDON == 'thyme') $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_thyme';
413  elseif ($conf->global->CHEQUERECEIPTS_ADDON == 'mint') $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_mint';
414 
415  if (!empty($conf->global->CHEQUERECEIPTS_ADDON))
416  {
417  $mybool = false;
418 
419  $file = $conf->global->CHEQUERECEIPTS_ADDON.".php";
420  $classname = $conf->global->CHEQUERECEIPTS_ADDON;
421 
422  // Include file with class
423  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
424 
425  foreach ($dirmodels as $reldir) {
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  } else {
474  $langs->load("errors");
475  print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Bank"));
476  return "";
477  }
478  }
479 
480 
481  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
488  public function load_board($user)
489  {
490  // phpcs:enable
491  global $conf, $langs;
492 
493  if ($user->socid) 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->labelShort = $langs->trans("BankChecksToReceiptShort");
514  $response->url = DOL_URL_ROOT.'/compta/paiement/cheque/index.php?leftmenu=checks&amp;mainmenu=bank';
515  $response->img = img_object('', "payment");
516 
517  while ($obj = $this->db->fetch_object($resql))
518  {
519  $response->nbtodo++;
520 
521  if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->cheque->warning_delay)) {
522  $response->nbtodolate++;
523  }
524  }
525 
526  return $response;
527  } else {
528  dol_print_error($this->db);
529  $this->error = $this->db->error();
530  return -1;
531  }
532  }
533 
534 
535  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
541  public function load_state_board()
542  {
543  // phpcs:enable
544  global $user;
545 
546  if ($user->socid) return -1; // protection pour eviter appel par utilisateur externe
547 
548  $sql = "SELECT count(b.rowid) as nb";
549  $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
550  $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
551  $sql .= " WHERE b.fk_account = ba.rowid";
552  $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
553  $sql .= " AND b.fk_type = 'CHQ'";
554  $sql .= " AND b.amount > 0";
555 
556  $resql = $this->db->query($sql);
557  if ($resql)
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  } else {
566  dol_print_error($this->db);
567  $this->error = $this->db->error();
568  return -1;
569  }
570  }
571 
572 
580  public function generatePdf($model, $outputlangs)
581  {
582  global $langs, $conf;
583 
584  if (empty($model)) $model = 'blochet';
585 
586  dol_syslog("RemiseCheque::generatePdf model=".$model." id=".$this->id, LOG_DEBUG);
587 
588  $dir = DOL_DOCUMENT_ROOT."/core/modules/cheque/doc/";
589 
590  // Charge le modele
591  $file = "pdf_".$model.".class.php";
592  if (file_exists($dir.$file))
593  {
594  include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
595  include_once $dir.$file;
596 
597  $classname = 'BordereauCheque'.ucfirst($model);
598  $docmodel = new $classname($this->db);
599 
600  $sql = "SELECT b.banque, b.emetteur, b.amount, b.num_chq";
601  $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
602  $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
603  $sql .= ", ".MAIN_DB_PREFIX."bordereau_cheque as bc";
604  $sql .= " WHERE b.fk_account = ba.rowid";
605  $sql .= " AND b.fk_bordereau = bc.rowid";
606  $sql .= " AND bc.rowid = ".$this->id;
607  $sql .= " AND bc.entity = ".$conf->entity;
608  $sql .= " ORDER BY b.dateo ASC, b.rowid ASC";
609 
610  dol_syslog("RemiseCheque::generatePdf", LOG_DEBUG);
611  $result = $this->db->query($sql);
612  if ($result)
613  {
614  $i = 0;
615  while ($objp = $this->db->fetch_object($result))
616  {
617  $docmodel->lines[$i] = new stdClass();
618  $docmodel->lines[$i]->bank_chq = $objp->banque;
619  $docmodel->lines[$i]->emetteur_chq = $objp->emetteur;
620  $docmodel->lines[$i]->amount_chq = $objp->amount;
621  $docmodel->lines[$i]->num_chq = $objp->num_chq;
622  $i++;
623  }
624  }
625  $docmodel->nbcheque = $this->nbcheque;
626  $docmodel->ref = $this->ref;
627  $docmodel->amount = $this->amount;
628  $docmodel->date = $this->date_bordereau;
629 
630  $account = new Account($this->db);
631  $account->fetch($this->account_id);
632 
633  $docmodel->account = &$account;
634 
635  // We save charset_output to restore it because write_file can change it if needed for
636  // output format that does not support UTF8.
637  $sav_charseSupprimert_output = $outputlangs->charset_output;
638  $result = $docmodel->write_file($this, $conf->bank->dir_output.'/checkdeposits', $this->ref, $outputlangs);
639  if ($result > 0)
640  {
641  //$outputlangs->charset_output=$sav_charset_output;
642  return 1;
643  } else {
644  //$outputlangs->charset_output=$sav_charset_output;
645  dol_syslog("Error");
646  dol_print_error($this->db, $docmodel->error);
647  return 0;
648  }
649  } else {
650  $this->error = $langs->trans("ErrorFileDoesNotExists", $dir.$file);
651  return -1;
652  }
653  }
654 
660  public function updateAmount()
661  {
662  global $conf;
663 
664  $this->errno = 0;
665 
666  $this->db->begin();
667  $total = 0;
668  $nb = 0;
669  $sql = "SELECT amount ";
670  $sql .= " FROM ".MAIN_DB_PREFIX."bank";
671  $sql .= " WHERE fk_bordereau = ".$this->id;
672 
673  $resql = $this->db->query($sql);
674  if ($resql)
675  {
676  while ($row = $this->db->fetch_row($resql))
677  {
678  $total += $row[0];
679  $nb++;
680  }
681 
682  $this->db->free($resql);
683 
684  $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
685  $sql .= " SET amount = ".price2num($total);
686  $sql .= ", nbcheque = ".((int) $nb);
687  $sql .= " WHERE rowid = ".$this->id;
688  $sql .= " AND entity = ".$conf->entity;
689 
690  $resql = $this->db->query($sql);
691  if (!$resql)
692  {
693  $this->errno = -1030;
694  dol_syslog("RemiseCheque::updateAmount ERREUR UPDATE ($this->errno)");
695  }
696  } else {
697  $this->errno = -1031;
698  dol_syslog("RemiseCheque::updateAmount ERREUR SELECT ($this->errno)");
699  }
700 
701  if ($this->errno === 0)
702  {
703  $this->db->commit();
704  } else {
705  $this->db->rollback();
706  dol_syslog("RemiseCheque::updateAmount ROLLBACK ($this->errno)");
707  }
708 
709  return $this->errno;
710  }
711 
718  public function removeCheck($account_id)
719  {
720  $this->errno = 0;
721 
722  if ($this->id > 0)
723  {
724  $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
725  $sql .= " SET fk_bordereau = 0";
726  $sql .= " WHERE rowid = ".((int) $account_id);
727  $sql .= " AND fk_bordereau = ".((int) $this->id);
728 
729  $resql = $this->db->query($sql);
730  if ($resql)
731  {
732  $this->updateAmount();
733  } else {
734  $this->errno = -1032;
735  dol_syslog("RemiseCheque::removeCheck ERREUR UPDATE ($this->errno)");
736  }
737  }
738  return 0;
739  }
740 
749  public function rejectCheck($bank_id, $rejection_date)
750  {
751  global $db, $user;
752 
753  $payment = new Paiement($db);
754  $payment->fetch(0, 0, $bank_id);
755 
756  $bankline = new AccountLine($db);
757  $bankline->fetch($bank_id);
758 
759  /* Conciliation is allowed because when check is returned, a new line is created onto bank transaction log.
760  if ($bankline->rappro)
761  {
762  $this->error='ActionRefusedLineAlreadyConciliated';
763  return -1;
764  }*/
765 
766  $this->db->begin();
767 
768  // Not conciliated, we can delete it
769  //$bankline->delete($user); // We delete
770 
771  $bankaccount = $payment->fk_account;
772 
773  // Get invoices list to reopen them
774  $sql = 'SELECT pf.fk_facture, pf.amount';
775  $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
776  $sql .= ' WHERE pf.fk_paiement = '.$payment->id;
777 
778  $resql = $this->db->query($sql);
779  if ($resql)
780  {
781  $rejectedPayment = new Paiement($this->db);
782  $rejectedPayment->amounts = array();
783  $rejectedPayment->datepaye = $rejection_date;
784  $rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement', 'code', 'id', 1);
785  $rejectedPayment->num_payment = $payment->num_payment;
786 
787  while ($obj = $this->db->fetch_object($resql))
788  {
789  $invoice = new Facture($this->db);
790  $invoice->fetch($obj->fk_facture);
791  $invoice->set_unpaid($user);
792 
793  $rejectedPayment->amounts[$obj->fk_facture] = price2num($obj->amount) * -1;
794  }
795 
796  $result = $rejectedPayment->create($user);
797  if ($result > 0)
798  {
799  // We created a negative payment, we also add the line as bank transaction
800  $result = $rejectedPayment->addPaymentToBank($user, 'payment', '(CheckRejected)', $bankaccount, '', '');
801  if ($result > 0)
802  {
803  $result = $payment->reject();
804  if ($result > 0)
805  {
806  $this->db->commit();
807  return $rejectedPayment->id;
808  } else {
809  $this->db->rollback();
810  return -1;
811  }
812  } else {
813  $this->error = $rejectedPayment->error;
814  $this->errors = $rejectedPayment->errors;
815  $this->db->rollback();
816  return -1;
817  }
818  } else {
819  $this->error = $rejectedPayment->error;
820  $this->errors = $rejectedPayment->errors;
821  $this->db->rollback();
822  return -1;
823  }
824  } else {
825  $this->error = $this->db->lasterror();
826  $this->db->rollback();
827  return -1;
828  }
829  }
830 
831  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
837  public function load_previous_next_id()
838  {
839  // phpcs:enable
840  global $conf;
841 
842  $this->errno = 0;
843 
844  $sql = "SELECT MAX(rowid)";
845  $sql .= " FROM ".MAIN_DB_PREFIX."bordereau_cheque";
846  $sql .= " WHERE rowid < ".$this->id;
847  $sql .= " AND entity = ".$conf->entity;
848 
849  $result = $this->db->query($sql);
850  if (!$result)
851  {
852  $this->errno = -1035;
853  }
854  $row = $this->db->fetch_row($result);
855  $this->previous_id = $row[0];
856 
857  $sql = "SELECT MIN(rowid)";
858  $sql .= " FROM ".MAIN_DB_PREFIX."bordereau_cheque";
859  $sql .= " WHERE rowid > ".$this->id;
860  $sql .= " AND entity = ".$conf->entity;
861 
862  $result = $this->db->query($sql);
863  if (!$result)
864  {
865  $this->errno = -1035;
866  }
867  $row = $this->db->fetch_row($result);
868  $this->next_id = $row[0];
869 
870  return $this->errno;
871  }
872 
873 
874  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
882  public function set_date($user, $date)
883  {
884  // phpcs:enable
885  if ($user->rights->banque->cheque)
886  {
887  $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
888  $sql .= " SET date_bordereau = ".($date ? "'".$this->db->idate($date)."'" : 'null');
889  $sql .= " WHERE rowid = ".$this->id;
890 
891  dol_syslog("RemiseCheque::set_date", LOG_DEBUG);
892  $resql = $this->db->query($sql);
893  if ($resql)
894  {
895  $this->date_bordereau = $date;
896  return 1;
897  } else {
898  $this->error = $this->db->error();
899  return -1;
900  }
901  } else {
902  return -2;
903  }
904  }
905 
906  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
914  public function set_number($user, $ref)
915  {
916  // phpcs:enable
917  if ($user->rights->banque->cheque)
918  {
919  $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
920  $sql .= " SET ref = '".$ref."'";
921  $sql .= " WHERE rowid = ".$this->id;
922 
923  dol_syslog("RemiseCheque::set_number", LOG_DEBUG);
924  $resql = $this->db->query($sql);
925  if ($resql)
926  {
927  return 1;
928  } else {
929  $this->error = $this->db->error();
930  return -1;
931  }
932  } else {
933  return -2;
934  }
935  }
936 
945  public function initAsSpecimen($option = '')
946  {
947  global $user, $langs, $conf;
948 
949  $now = dol_now();
950  $arraynow = dol_getdate($now);
951  $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
952 
953  // Initialize parameters
954  $this->id = 0;
955  $this->ref = 'SPECIMEN';
956  $this->specimen = 1;
957  $this->date_bordereau = $nownotime;
958  }
959 
970  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
971  {
972  global $conf, $langs;
973 
974  $result = '';
975 
976  $label = '<u>'.$langs->trans("ShowCheckReceipt").'</u>';
977  $label .= '<br>';
978  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
979 
980  $url = DOL_URL_ROOT.'/compta/paiement/cheque/card.php?id='.$this->id;
981 
982  if ($option != 'nolink')
983  {
984  // Add param to save lastsearch_values or not
985  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
986  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
987  if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
988  }
989 
990  $linkclose = '';
991  if (empty($notooltip))
992  {
993  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
994  {
995  $label = $langs->trans("ShowCheckReceipt");
996  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
997  }
998  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
999  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
1000  } else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1001 
1002  $linkstart = '<a href="'.$url.'"';
1003  $linkstart .= $linkclose.'>';
1004  $linkend = '</a>';
1005 
1006  $result .= $linkstart;
1007  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);
1008  if ($withpicto != 2) $result .= $this->ref;
1009  $result .= $linkend;
1010 
1011  return $result;
1012  }
1013 
1020  public function getLibStatut($mode = 0)
1021  {
1022  return $this->LibStatut($this->statut, $mode);
1023  }
1024 
1025  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1033  public function LibStatut($status, $mode = 0)
1034  {
1035  // phpcs:enable
1036  if (empty($this->labelStatus) || empty($this->labelStatusShort))
1037  {
1038  global $langs;
1039  $langs->load('compta');
1040  $this->labelStatus[self::STATUS_DRAFT] = $langs->trans('ToValidate');
1041  $this->labelStatus[self::STATUS_VALIDATED] = $langs->trans('Validated');
1042  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->trans('ToValidate');
1043  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->trans('Validated');
1044  }
1045 
1046  $statusType = 'status'.$status;
1047  if ($status == self::STATUS_VALIDATED) $statusType = 'status4';
1048 
1049  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
1050  }
1051 }
set_date($user, $date)
Set the creation date.
load_board($user)
Load indicators for dashboard (this-&gt;nbtodo and this-&gt;nbtodolate)
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
LibStatut($status, $mode=0)
Return label of a status.
$errno
Numero d&#39;erreur Plage 1024-1279.
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
Definition: list.php:632
dol_now($mode= 'auto')
Return date for now.
load_previous_next_id()
Charge les proprietes ref_previous et ref_next.
Class to manage bank transaction lines.
getNextNumRef($mode= 'next')
Return next reference of cheque receipts not already used (or last reference) according to numbering ...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage bank accounts.
validate($user)
Validate a receipt.
getNomUrl($withpicto=0, $option= '', $notooltip=0, $morecss= '', $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
removeCheck($account_id)
Insere la remise en base.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Class to manage payments of customer invoices.
dol_getdate($timestamp, $fast=false, $forcetimezone= '')
Return an array with locale date info.
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.
fetch($id, $ref= '')
Load record.
updateAmount()
Mets a jour le montant total.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0)
Return an id or code from a code or id.
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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-&gt;nb de tableau de bord.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
Class to manage invoices.
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.