dolibarr  16.0.5
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) {
102  $sql .= " AND bc.rowid = ".((int) $id);
103  }
104  if ($ref) {
105  $sql .= " AND bc.ref = '".$this->db->escape($ref)."'";
106  }
107 
108  dol_syslog("RemiseCheque::fetch", LOG_DEBUG);
109  $resql = $this->db->query($sql);
110  if ($resql) {
111  if ($obj = $this->db->fetch_object($resql)) {
112  $this->id = $obj->rowid;
113  $this->amount = $obj->amount;
114  $this->date_bordereau = $this->db->jdate($obj->date_bordereau);
115  $this->account_id = $obj->fk_bank_account;
116  $this->account_label = $obj->account_label;
117  $this->author_id = $obj->fk_user_author;
118  $this->nbcheque = $obj->nbcheque;
119  $this->statut = $obj->statut;
120  $this->ref_ext = $obj->ref_ext;
121 
122  if ($this->statut == 0) {
123  $this->ref = "(PROV".$this->id.")";
124  } else {
125  $this->ref = $obj->ref;
126  }
127  }
128  $this->db->free($resql);
129 
130  return 1;
131  } else {
132  $this->error = $this->db->lasterror();
133  return -1;
134  }
135  }
136 
146  public function create($user, $account_id, $limit, $toRemise)
147  {
148  global $conf;
149 
150  $this->errno = 0;
151  $this->id = 0;
152 
153  $now = dol_now();
154 
155  dol_syslog("RemiseCheque::Create start", LOG_DEBUG);
156 
157  $this->db->begin();
158 
159  $sql = "INSERT INTO ".MAIN_DB_PREFIX."bordereau_cheque (";
160  $sql .= "datec";
161  $sql .= ", date_bordereau";
162  $sql .= ", fk_user_author";
163  $sql .= ", fk_bank_account";
164  $sql .= ", statut";
165  $sql .= ", amount";
166  $sql .= ", ref";
167  $sql .= ", entity";
168  $sql .= ", nbcheque";
169  $sql .= ", ref_ext";
170  $sql .= ") VALUES (";
171  $sql .= "'".$this->db->idate($now)."'";
172  $sql .= ", '".$this->db->idate($now)."'";
173  $sql .= ", ".((int) $user->id);
174  $sql .= ", ".((int) $account_id);
175  $sql .= ", 0";
176  $sql .= ", 0";
177  $sql .= ", 0";
178  $sql .= ", ".((int) $conf->entity);
179  $sql .= ", 0";
180  $sql .= ", ''";
181  $sql .= ")";
182 
183  $resql = $this->db->query($sql);
184  if ($resql) {
185  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bordereau_cheque");
186  if ($this->id == 0) {
187  $this->errno = -1024;
188  dol_syslog("Remisecheque::Create Error read id ".$this->errno, LOG_ERR);
189  }
190 
191  if ($this->id > 0 && $this->errno == 0) {
192  $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
193  $sql .= " SET ref='(PROV".$this->id.")'";
194  $sql .= " WHERE rowid=".((int) $this->id)."";
195 
196  $resql = $this->db->query($sql);
197  if (!$resql) {
198  $this->errno = -1025;
199  dol_syslog("RemiseCheque::Create Error update ".$this->errno, LOG_ERR);
200  }
201  }
202 
203  $lines = array();
204 
205  if ($this->id > 0 && $this->errno == 0) {
206  $sql = "SELECT b.rowid";
207  $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
208  $sql .= " WHERE b.fk_type = 'CHQ'";
209  $sql .= " AND b.amount > 0";
210  $sql .= " AND b.fk_bordereau = 0";
211  $sql .= " AND b.fk_account = ".((int) $account_id);
212  if ($limit) {
213  $sql .= $this->db->plimit($limit);
214  }
215 
216  dol_syslog("RemiseCheque::Create", LOG_DEBUG);
217  $resql = $this->db->query($sql);
218  if ($resql) {
219  while ($row = $this->db->fetch_row($resql)) {
220  array_push($lines, $row[0]);
221  }
222  $this->db->free($resql);
223  } else {
224  $this->errno = -1026;
225  dol_syslog("RemiseCheque::Create Error ".$this->errno, LOG_ERR);
226  }
227  }
228 
229  if ($this->id > 0 && $this->errno == 0) {
230  foreach ($lines as $lineid) {
231  $checkremise = false;
232  foreach ($toRemise as $linetoremise) {
233  if ($linetoremise == $lineid) {
234  $checkremise = true;
235  }
236  }
237 
238  if ($checkremise) {
239  $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
240  $sql .= " SET fk_bordereau = ".((int) $this->id);
241  $sql .= " WHERE rowid = ".((int) $lineid);
242 
243  $resql = $this->db->query($sql);
244  if (!$resql) {
245  $this->errno = -18;
246  dol_syslog("RemiseCheque::Create Error update bank ".$this->errno, LOG_ERR);
247  }
248  }
249  }
250  }
251 
252  if ($this->id > 0 && $this->errno == 0) {
253  if ($this->updateAmount() <> 0) {
254  $this->errno = -1027;
255  dol_syslog("RemiseCheque::Create Error update amount ".$this->errno, LOG_ERR);
256  }
257  }
258  } else {
259  $this->errno = -1;
260  $this->error = $this->db->lasterror();
261  $this->errno = $this->db->lasterrno();
262  }
263 
264  if (!$this->errno && !empty($conf->global->MAIN_DISABLEDRAFTSTATUS)) {
265  $res = $this->validate($user);
266  //if ($res < 0) $error++;
267  }
268 
269  if (!$this->errno) {
270  $this->db->commit();
271  dol_syslog("RemiseCheque::Create end", LOG_DEBUG);
272  return $this->id;
273  } else {
274  $this->db->rollback();
275  dol_syslog("RemiseCheque::Create end", LOG_DEBUG);
276  return $this->errno;
277  }
278  }
279 
286  public function delete($user = '')
287  {
288  global $conf;
289 
290  $this->errno = 0;
291  $this->db->begin();
292 
293  $sql = "DELETE FROM ".MAIN_DB_PREFIX."bordereau_cheque";
294  $sql .= " WHERE rowid = ".((int) $this->id);
295  $sql .= " AND entity = ".$conf->entity;
296 
297  $resql = $this->db->query($sql);
298  if ($resql) {
299  $num = $this->db->affected_rows($resql);
300 
301  if ($num <> 1) {
302  $this->errno = -2;
303  dol_syslog("Remisecheque::Delete Erreur Lecture ID ($this->errno)");
304  }
305 
306  if ($this->errno === 0) {
307  $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
308  $sql .= " SET fk_bordereau = 0";
309  $sql .= " WHERE fk_bordereau = ".((int) $this->id);
310 
311  $resql = $this->db->query($sql);
312  if (!$resql) {
313  $this->errno = -1028;
314  dol_syslog("RemiseCheque::Delete ERREUR UPDATE ($this->errno)");
315  }
316  }
317  }
318 
319  if ($this->errno === 0) {
320  $this->db->commit();
321  } else {
322  $this->db->rollback();
323  dol_syslog("RemiseCheque::Delete ROLLBACK ($this->errno)");
324  }
325 
326  return $this->errno;
327  }
328 
335  public function validate($user)
336  {
337  global $langs, $conf;
338 
339  $this->errno = 0;
340 
341  $this->db->begin();
342 
343  $numref = $this->getNextNumRef();
344 
345  if ($this->errno == 0 && $numref) {
346  $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
347  $sql .= " SET statut = 1, ref = '".$this->db->escape($numref)."'";
348  $sql .= " WHERE rowid = ".((int) $this->id);
349  $sql .= " AND entity = ".$conf->entity;
350  $sql .= " AND statut = 0";
351 
352  dol_syslog("RemiseCheque::Validate", LOG_DEBUG);
353  $resql = $this->db->query($sql);
354  if ($resql) {
355  $num = $this->db->affected_rows($resql);
356 
357  if ($num == 1) {
358  $this->ref = $numref;
359  $this->statut = 1;
360  } else {
361  $this->errno = -1029;
362  dol_syslog("Remisecheque::Validate Error ".$this->errno, LOG_ERR);
363  }
364  } else {
365  $this->errno = -1033;
366  dol_syslog("Remisecheque::Validate Error ".$this->errno, LOG_ERR);
367  }
368  }
369 
370  // Commit/Rollback
371  if ($this->errno == 0) {
372  $this->db->commit();
373  return 1;
374  } else {
375  $this->db->rollback();
376  dol_syslog("RemiseCheque::Validate ".$this->errno, LOG_ERR);
377  return $this->errno;
378  }
379  }
380 
388  public function getNextNumRef($mode = 'next')
389  {
390  global $conf, $db, $langs, $mysoc;
391  $langs->load("bills");
392 
393  // Clean parameters (if not defined or using deprecated value)
394  if (empty($conf->global->CHEQUERECEIPTS_ADDON)) {
395  $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_mint';
396  } elseif ($conf->global->CHEQUERECEIPTS_ADDON == 'thyme') {
397  $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_thyme';
398  } elseif ($conf->global->CHEQUERECEIPTS_ADDON == 'mint') {
399  $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_mint';
400  }
401 
402  if (!empty($conf->global->CHEQUERECEIPTS_ADDON)) {
403  $mybool = false;
404 
405  $file = $conf->global->CHEQUERECEIPTS_ADDON.".php";
406  $classname = $conf->global->CHEQUERECEIPTS_ADDON;
407 
408  // Include file with class
409  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
410 
411  foreach ($dirmodels as $reldir) {
412  $dir = dol_buildpath($reldir."core/modules/cheque/");
413 
414  // Load file with numbering class (if found)
415  if (is_file($dir.$file) && is_readable($dir.$file)) {
416  $mybool |= include_once $dir.$file;
417  }
418  }
419 
420  // For compatibility
421  if (!$mybool) {
422  $file = $conf->global->CHEQUERECEIPTS_ADDON.".php";
423  $classname = "mod_chequereceipt_".$conf->global->CHEQUERECEIPTS_ADDON;
424  $classname = preg_replace('/\-.*$/', '', $classname);
425  // Include file with class
426  foreach ($conf->file->dol_document_root as $dirroot) {
427  $dir = $dirroot."/core/modules/cheque/";
428 
429  // Load file with numbering class (if found)
430  if (is_file($dir.$file) && is_readable($dir.$file)) {
431  $mybool |= include_once $dir.$file;
432  }
433  }
434  }
435 
436  if (!$mybool) {
437  dol_print_error('', "Failed to include file ".$file);
438  return '';
439  }
440 
441  $obj = new $classname();
442  $numref = "";
443  $numref = $obj->getNextValue($mysoc, $this);
444 
449  if ($mode != 'last' && !$numref) {
450  dol_print_error($db, "ChequeReceipts::getNextNumRef ".$obj->error);
451  return "";
452  }
453 
454  return $numref;
455  } else {
456  $langs->load("errors");
457  print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Bank"));
458  return "";
459  }
460  }
461 
462 
463  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
470  public function load_board($user)
471  {
472  // phpcs:enable
473  global $conf, $langs;
474 
475  if ($user->socid) {
476  return -1; // protection pour eviter appel par utilisateur externe
477  }
478 
479  $sql = "SELECT b.rowid, b.datev as datefin";
480  $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
481  $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
482  $sql .= " WHERE b.fk_account = ba.rowid";
483  $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
484  $sql .= " AND b.fk_type = 'CHQ'";
485  $sql .= " AND b.fk_bordereau = 0";
486  $sql .= " AND b.amount > 0";
487 
488  $resql = $this->db->query($sql);
489  if ($resql) {
490  $langs->load("banks");
491  $now = dol_now();
492 
493  $response = new WorkboardResponse();
494  $response->warning_delay = $conf->bank->cheque->warning_delay / 60 / 60 / 24;
495  $response->label = $langs->trans("BankChecksToReceipt");
496  $response->labelShort = $langs->trans("BankChecksToReceiptShort");
497  $response->url = DOL_URL_ROOT.'/compta/paiement/cheque/index.php?leftmenu=checks&amp;mainmenu=bank';
498  $response->img = img_object('', "payment");
499 
500  while ($obj = $this->db->fetch_object($resql)) {
501  $response->nbtodo++;
502 
503  if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->cheque->warning_delay)) {
504  $response->nbtodolate++;
505  }
506  }
507 
508  return $response;
509  } else {
510  dol_print_error($this->db);
511  $this->error = $this->db->error();
512  return -1;
513  }
514  }
515 
516 
517  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
523  public function load_state_board()
524  {
525  // phpcs:enable
526  global $user;
527 
528  if ($user->socid) {
529  return -1; // protection pour eviter appel par utilisateur externe
530  }
531 
532  $sql = "SELECT count(b.rowid) as nb";
533  $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
534  $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
535  $sql .= " WHERE b.fk_account = ba.rowid";
536  $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
537  $sql .= " AND b.fk_type = 'CHQ'";
538  $sql .= " AND b.amount > 0";
539 
540  $resql = $this->db->query($sql);
541  if ($resql) {
542  while ($obj = $this->db->fetch_object($resql)) {
543  $this->nb["cheques"] = $obj->nb;
544  }
545  $this->db->free($resql);
546  return 1;
547  } else {
548  dol_print_error($this->db);
549  $this->error = $this->db->error();
550  return -1;
551  }
552  }
553 
554 
562  public function generatePdf($model, $outputlangs)
563  {
564  global $langs, $conf;
565 
566  if (empty($model)) {
567  $model = 'blochet';
568  }
569 
570  dol_syslog("RemiseCheque::generatePdf model=".$model." id=".$this->id, LOG_DEBUG);
571 
572  $dir = DOL_DOCUMENT_ROOT."/core/modules/cheque/doc/";
573 
574  // Charge le modele
575  $file = "pdf_".$model.".class.php";
576  if (file_exists($dir.$file)) {
577  include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
578  include_once $dir.$file;
579 
580  $classname = 'BordereauCheque'.ucfirst($model);
581  $docmodel = new $classname($this->db);
582 
583  $sql = "SELECT b.banque, b.emetteur, b.amount, b.num_chq";
584  $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
585  $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
586  $sql .= ", ".MAIN_DB_PREFIX."bordereau_cheque as bc";
587  $sql .= " WHERE b.fk_account = ba.rowid";
588  $sql .= " AND b.fk_bordereau = bc.rowid";
589  $sql .= " AND bc.rowid = ".((int) $this->id);
590  $sql .= " AND bc.entity = ".$conf->entity;
591  $sql .= " ORDER BY b.dateo ASC, b.rowid ASC";
592 
593  dol_syslog("RemiseCheque::generatePdf", LOG_DEBUG);
594  $result = $this->db->query($sql);
595  if ($result) {
596  $i = 0;
597  while ($objp = $this->db->fetch_object($result)) {
598  $docmodel->lines[$i] = new stdClass();
599  $docmodel->lines[$i]->bank_chq = $objp->banque;
600  $docmodel->lines[$i]->emetteur_chq = $objp->emetteur;
601  $docmodel->lines[$i]->amount_chq = $objp->amount;
602  $docmodel->lines[$i]->num_chq = $objp->num_chq;
603  $i++;
604  }
605  }
606  $docmodel->nbcheque = $this->nbcheque;
607  $docmodel->ref = $this->ref;
608  $docmodel->amount = $this->amount;
609  $docmodel->date = $this->date_bordereau;
610 
611  $account = new Account($this->db);
612  $account->fetch($this->account_id);
613 
614  $docmodel->account = &$account;
615 
616  // We save charset_output to restore it because write_file can change it if needed for
617  // output format that does not support UTF8.
618  $sav_charseSupprimert_output = $outputlangs->charset_output;
619 
620  $result = $docmodel->write_file($this, $conf->bank->dir_output.'/checkdeposits', $this->ref, $outputlangs);
621  if ($result > 0) {
622  //$outputlangs->charset_output=$sav_charset_output;
623  return 1;
624  } else {
625  //$outputlangs->charset_output=$sav_charset_output;
626  dol_syslog("Error");
627  dol_print_error($this->db, $docmodel->error);
628  return 0;
629  }
630  } else {
631  $this->error = $langs->trans("ErrorFileDoesNotExists", $dir.$file);
632  return -1;
633  }
634  }
635 
641  public function updateAmount()
642  {
643  global $conf;
644 
645  $this->errno = 0;
646 
647  $this->db->begin();
648  $total = 0;
649  $nb = 0;
650  $sql = "SELECT amount ";
651  $sql .= " FROM ".MAIN_DB_PREFIX."bank";
652  $sql .= " WHERE fk_bordereau = ".((int) $this->id);
653 
654  $resql = $this->db->query($sql);
655  if ($resql) {
656  while ($row = $this->db->fetch_row($resql)) {
657  $total += $row[0];
658  $nb++;
659  }
660 
661  $this->db->free($resql);
662 
663  $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
664  $sql .= " SET amount = ".price2num($total);
665  $sql .= ", nbcheque = ".((int) $nb);
666  $sql .= " WHERE rowid = ".((int) $this->id);
667  $sql .= " AND entity = ".$conf->entity;
668 
669  $resql = $this->db->query($sql);
670  if (!$resql) {
671  $this->errno = -1030;
672  dol_syslog("RemiseCheque::updateAmount ERREUR UPDATE ($this->errno)");
673  }
674  } else {
675  $this->errno = -1031;
676  dol_syslog("RemiseCheque::updateAmount ERREUR SELECT ($this->errno)");
677  }
678 
679  if ($this->errno === 0) {
680  $this->db->commit();
681  } else {
682  $this->db->rollback();
683  dol_syslog("RemiseCheque::updateAmount ROLLBACK ($this->errno)");
684  }
685 
686  return $this->errno;
687  }
688 
695  public function removeCheck($account_id)
696  {
697  $this->errno = 0;
698 
699  if ($this->id > 0) {
700  $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
701  $sql .= " SET fk_bordereau = 0";
702  $sql .= " WHERE rowid = ".((int) $account_id);
703  $sql .= " AND fk_bordereau = ".((int) $this->id);
704 
705  $resql = $this->db->query($sql);
706  if ($resql) {
707  $this->updateAmount();
708  } else {
709  $this->errno = -1032;
710  dol_syslog("RemiseCheque::removeCheck ERREUR UPDATE ($this->errno)");
711  }
712  }
713  return 0;
714  }
715 
724  public function rejectCheck($bank_id, $rejection_date)
725  {
726  global $db, $user;
727 
728  $payment = new Paiement($db);
729  $payment->fetch(0, 0, $bank_id);
730 
731  $bankline = new AccountLine($db);
732  $bankline->fetch($bank_id);
733 
734  /* Reconciliation is allowed because when check is returned, a new line is created onto bank transaction log.
735  if ($bankline->rappro)
736  {
737  $this->error='ActionRefusedLineAlreadyConciliated';
738  return -1;
739  }*/
740 
741  $this->db->begin();
742 
743  // Not reconciled, we can delete it
744  //$bankline->delete($user); // We delete
745 
746  $bankaccount = $payment->fk_account;
747 
748  // Get invoices list to reopen them
749  $sql = 'SELECT pf.fk_facture, pf.amount';
750  $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
751  $sql .= ' WHERE pf.fk_paiement = '.((int) $payment->id);
752 
753  $resql = $this->db->query($sql);
754  if ($resql) {
755  $rejectedPayment = new Paiement($this->db);
756  $rejectedPayment->amounts = array();
757  $rejectedPayment->datepaye = $rejection_date;
758  $rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement', 'code', 'id', 1);
759  $rejectedPayment->num_payment = $payment->num_payment;
760 
761  while ($obj = $this->db->fetch_object($resql)) {
762  $invoice = new Facture($this->db);
763  $invoice->fetch($obj->fk_facture);
764  $invoice->setUnpaid($user);
765 
766  $rejectedPayment->amounts[$obj->fk_facture] = price2num($obj->amount) * -1;
767  }
768 
769  $result = $rejectedPayment->create($user);
770  if ($result > 0) {
771  // We created a negative payment, we also add the line as bank transaction
772  $result = $rejectedPayment->addPaymentToBank($user, 'payment', '(CheckRejected)', $bankaccount, '', '');
773  if ($result > 0) {
774  $result = $payment->reject();
775  if ($result > 0) {
776  $this->db->commit();
777  return $rejectedPayment->id;
778  } else {
779  $this->db->rollback();
780  return -1;
781  }
782  } else {
783  $this->error = $rejectedPayment->error;
784  $this->errors = $rejectedPayment->errors;
785  $this->db->rollback();
786  return -1;
787  }
788  } else {
789  $this->error = $rejectedPayment->error;
790  $this->errors = $rejectedPayment->errors;
791  $this->db->rollback();
792  return -1;
793  }
794  } else {
795  $this->error = $this->db->lasterror();
796  $this->db->rollback();
797  return -1;
798  }
799  }
800 
801  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
807  public function load_previous_next_id()
808  {
809  // phpcs:enable
810  global $conf;
811 
812  $this->errno = 0;
813 
814  $sql = "SELECT MAX(rowid)";
815  $sql .= " FROM ".MAIN_DB_PREFIX."bordereau_cheque";
816  $sql .= " WHERE rowid < ".$this->id;
817  $sql .= " AND entity = ".$conf->entity;
818 
819  $result = $this->db->query($sql);
820  if (!$result) {
821  $this->errno = -1035;
822  }
823  $row = $this->db->fetch_row($result);
824  $this->previous_id = $row[0];
825 
826  $sql = "SELECT MIN(rowid)";
827  $sql .= " FROM ".MAIN_DB_PREFIX."bordereau_cheque";
828  $sql .= " WHERE rowid > ".$this->id;
829  $sql .= " AND entity = ".$conf->entity;
830 
831  $result = $this->db->query($sql);
832  if (!$result) {
833  $this->errno = -1035;
834  }
835  $row = $this->db->fetch_row($result);
836  $this->next_id = $row[0];
837 
838  return $this->errno;
839  }
840 
841 
842  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
850  public function set_date($user, $date)
851  {
852  // phpcs:enable
853  if ($user->rights->banque->cheque) {
854  $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
855  $sql .= " SET date_bordereau = ".($date ? "'".$this->db->idate($date)."'" : 'null');
856  $sql .= " WHERE rowid = ".((int) $this->id);
857 
858  dol_syslog("RemiseCheque::set_date", LOG_DEBUG);
859  $resql = $this->db->query($sql);
860  if ($resql) {
861  $this->date_bordereau = $date;
862  return 1;
863  } else {
864  $this->error = $this->db->error();
865  return -1;
866  }
867  } else {
868  return -2;
869  }
870  }
871 
872  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
880  public function set_number($user, $ref)
881  {
882  // phpcs:enable
883  if ($user->rights->banque->cheque) {
884  $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
885  $sql .= " SET ref = '".$this->db->escape($ref)."'";
886  $sql .= " WHERE rowid = ".((int) $this->id);
887 
888  dol_syslog("RemiseCheque::set_number", LOG_DEBUG);
889  $resql = $this->db->query($sql);
890  if ($resql) {
891  return 1;
892  } else {
893  $this->error = $this->db->error();
894  return -1;
895  }
896  } else {
897  return -2;
898  }
899  }
900 
909  public function initAsSpecimen($option = '')
910  {
911  global $user, $langs, $conf;
912 
913  $now = dol_now();
914  $arraynow = dol_getdate($now);
915  $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
916 
917  // Initialize parameters
918  $this->id = 0;
919  $this->ref = 'SPECIMEN';
920  $this->specimen = 1;
921  $this->date_bordereau = $nownotime;
922  }
923 
934  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
935  {
936  global $conf, $langs;
937 
938  $result = '';
939 
940  $label = '<u>'.$langs->trans("ShowCheckReceipt").'</u>';
941  $label .= '<br>';
942  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
943 
944  $url = DOL_URL_ROOT.'/compta/paiement/cheque/card.php?id='.$this->id;
945 
946  if ($option != 'nolink') {
947  // Add param to save lastsearch_values or not
948  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
949  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
950  $add_save_lastsearch_values = 1;
951  }
952  if ($add_save_lastsearch_values) {
953  $url .= '&save_lastsearch_values=1';
954  }
955  }
956 
957  $linkclose = '';
958  if (empty($notooltip)) {
959  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
960  $label = $langs->trans("ShowCheckReceipt");
961  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
962  }
963  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
964  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
965  } else {
966  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
967  }
968 
969  $linkstart = '<a href="'.$url.'"';
970  $linkstart .= $linkclose.'>';
971  $linkend = '</a>';
972 
973  $result .= $linkstart;
974  if ($withpicto) {
975  $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);
976  }
977  if ($withpicto != 2) {
978  $result .= $this->ref;
979  }
980  $result .= $linkend;
981 
982  return $result;
983  }
984 
991  public function getLibStatut($mode = 0)
992  {
993  return $this->LibStatut($this->statut, $mode);
994  }
995 
996  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1004  public function LibStatut($status, $mode = 0)
1005  {
1006  // phpcs:enable
1007  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1008  global $langs;
1009  $langs->load('compta');
1010  $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('ToValidate');
1011  $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
1012  $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('ToValidate');
1013  $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
1014  }
1015 
1016  $statusType = 'status'.$status;
1017  if ($status == self::STATUS_VALIDATED) {
1018  $statusType = 'status4';
1019  }
1020 
1021  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
1022  }
1023 }
RemiseCheque\$errno
$errno
Numero d'erreur Plage 1024-1279.
Definition: remisecheque.class.php:54
dol_getdate
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
Definition: functions.lib.php:2713
RemiseCheque\getNomUrl
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
Definition: remisecheque.class.php:934
db
$conf db
API class for accounts.
Definition: inc.php:41
RemiseCheque\getNextNumRef
getNextNumRef($mode='next')
Return next reference of cheque receipts not already used (or last reference) according to numbering ...
Definition: remisecheque.class.php:388
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
RemiseCheque\load_previous_next_id
load_previous_next_id()
Charge les proprietes ref_previous et ref_next.
Definition: remisecheque.class.php:807
RemiseCheque\validate
validate($user)
Validate a receipt.
Definition: remisecheque.class.php:335
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
ref
$object ref
Definition: info.php:77
RemiseCheque\LibStatut
LibStatut($status, $mode=0)
Return label of a status.
Definition: remisecheque.class.php:1004
RemiseCheque\removeCheck
removeCheck($account_id)
Insere la remise en base.
Definition: remisecheque.class.php:695
Facture
Class to manage invoices.
Definition: facture.class.php:60
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:44
RemiseCheque\set_date
set_date($user, $date)
Set the creation date.
Definition: remisecheque.class.php:850
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5661
RemiseCheque\updateAmount
updateAmount()
Mets a jour le montant total.
Definition: remisecheque.class.php:641
RemiseCheque\load_board
load_board($user)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
Definition: remisecheque.class.php:470
RemiseCheque\fetch
fetch($id, $ref='')
Load record.
Definition: remisecheque.class.php:91
WorkboardResponse
Definition: workboardresponse.class.php:25
RemiseCheque\initAsSpecimen
initAsSpecimen($option='')
Initialise an instance with random values.
Definition: remisecheque.class.php:909
dol_getIdFromCode
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
Definition: functions.lib.php:8535
RemiseCheque\getLibStatut
getLibStatut($mode=0)
Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee)
Definition: remisecheque.class.php:991
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
RemiseCheque\load_state_board
load_state_board()
Charge indicateurs this->nb de tableau de bord.
Definition: remisecheque.class.php:523
Paiement
Class to manage payments of customer invoices.
Definition: paiement.class.php:41
RemiseCheque\rejectCheck
rejectCheck($bank_id, $rejection_date)
Check return management Reopen linked invoices and create a new negative payment.
Definition: remisecheque.class.php:724
RemiseCheque\set_number
set_number($user, $ref)
Set the ref of bordereau.
Definition: remisecheque.class.php:880
RemiseCheque\create
create($user, $account_id, $limit, $toRemise)
Create a receipt to send cheques.
Definition: remisecheque.class.php:146
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10338
RemiseCheque
Class to manage cheque delivery receipts.
Definition: remisecheque.class.php:34
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
AccountLine
Class to manage bank transaction lines.
Definition: account.class.php:1779
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
RemiseCheque\generatePdf
generatePdf($model, $outputlangs)
Build document.
Definition: remisecheque.class.php:562
dol_mktime
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...
Definition: functions.lib.php:2757
RemiseCheque\__construct
__construct($db)
Constructor.
Definition: remisecheque.class.php:77
Account
Class to manage bank accounts.
Definition: account.class.php:38