dolibarr 19.0.3
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
27require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
28require_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 $type = 'CHQ'; // 'CHQ', 'TRA', ...
57
58 public $amount;
59 public $date_bordereau;
60 public $account_id;
61 public $account_label;
62 public $author_id;
63 public $nbcheque;
64
68 public $ref;
69
70 const STATUS_DRAFT = 0;
71 const STATUS_VALIDATED = 1;
72
73
79 public function __construct($db)
80 {
81 $this->db = $db;
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, bc.type,";
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 $this->type = $obj->type;
122
123 if ($this->statut == 0) {
124 $this->ref = "(PROV".$this->id.")";
125 } else {
126 $this->ref = $obj->ref;
127 }
128 }
129 $this->db->free($resql);
130
131 return 1;
132 } else {
133 $this->error = $this->db->lasterror();
134 return -1;
135 }
136 }
137
147 public function create($user, $account_id, $limit, $toRemise)
148 {
149 global $conf;
150
151 $this->errno = 0;
152 $this->id = 0;
153
154 $now = dol_now();
155
156 dol_syslog("RemiseCheque::Create start", LOG_DEBUG);
157
158 // Clean parameters
159 if (empty($this->type)) {
160 $this->type = 'CHQ';
161 }
162
163 $this->db->begin();
164
165 $sql = "INSERT INTO ".MAIN_DB_PREFIX."bordereau_cheque (";
166 $sql .= "datec";
167 $sql .= ", date_bordereau";
168 $sql .= ", fk_user_author";
169 $sql .= ", fk_bank_account";
170 $sql .= ", statut";
171 $sql .= ", amount";
172 $sql .= ", ref";
173 $sql .= ", entity";
174 $sql .= ", nbcheque";
175 $sql .= ", ref_ext";
176 $sql .= ", type";
177 $sql .= ") VALUES (";
178 $sql .= "'".$this->db->idate($now)."'";
179 $sql .= ", '".$this->db->idate($now)."'";
180 $sql .= ", ".((int) $user->id);
181 $sql .= ", ".((int) $account_id);
182 $sql .= ", 0";
183 $sql .= ", 0";
184 $sql .= ", 0";
185 $sql .= ", ".((int) $conf->entity);
186 $sql .= ", 0";
187 $sql .= ", ''";
188 $sql .= ", '".$this->db->escape($this->type)."'";
189 $sql .= ")";
190
191 $resql = $this->db->query($sql);
192 if ($resql) {
193 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bordereau_cheque");
194 if ($this->id == 0) {
195 $this->errno = -1024;
196 dol_syslog("Remisecheque::Create Error read id ".$this->errno, LOG_ERR);
197 }
198
199 if ($this->id > 0 && $this->errno == 0) {
200 $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
201 $sql .= " SET ref = '(PROV".$this->id.")'";
202 $sql .= " WHERE rowid=".((int) $this->id);
203
204 $resql = $this->db->query($sql);
205 if (!$resql) {
206 $this->errno = -1025;
207 dol_syslog("RemiseCheque::Create Error update ".$this->errno, LOG_ERR);
208 }
209 }
210
211 $lines = array();
212
213 if ($this->id > 0 && $this->errno == 0) {
214 $sql = "SELECT b.rowid";
215 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
216 $sql .= " WHERE b.fk_type = '".$this->db->escape($this->type)."'";
217 $sql .= " AND b.amount > 0";
218 $sql .= " AND b.fk_bordereau = 0";
219 $sql .= " AND b.fk_account = ".((int) $account_id);
220 if ($limit) {
221 $sql .= $this->db->plimit($limit);
222 }
223
224 dol_syslog("RemiseCheque::Create", LOG_DEBUG);
225 $resql = $this->db->query($sql);
226 if ($resql) {
227 while ($row = $this->db->fetch_row($resql)) {
228 array_push($lines, $row[0]);
229 }
230 $this->db->free($resql);
231 } else {
232 $this->errno = -1026;
233 dol_syslog("RemiseCheque::Create Error ".$this->errno, LOG_ERR);
234 }
235 }
236
237 if ($this->id > 0 && $this->errno == 0) {
238 foreach ($lines as $lineid) {
239 $checkremise = false;
240 foreach ($toRemise as $linetoremise) {
241 if ($linetoremise == $lineid) {
242 $checkremise = true;
243 }
244 }
245
246 if ($checkremise) {
247 $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
248 $sql .= " SET fk_bordereau = ".((int) $this->id);
249 $sql .= " WHERE rowid = ".((int) $lineid);
250
251 $resql = $this->db->query($sql);
252 if (!$resql) {
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 if ($this->updateAmount() != 0) {
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 && (getDolGlobalString('MAIN_DISABLEDRAFTSTATUS') || getDolGlobalString('MAIN_DISABLEDRAFTSTATUS_CHEQUE'))) {
273 $res = $this->validate($user);
274 //if ($res < 0) $error++;
275 }
276
277 if (!$this->errno) {
278 $this->db->commit();
279 dol_syslog("RemiseCheque::Create end", LOG_DEBUG);
280 return $this->id;
281 } else {
282 $this->db->rollback();
283 dol_syslog("RemiseCheque::Create end", LOG_DEBUG);
284 return $this->errno;
285 }
286 }
287
294 public function delete($user = null)
295 {
296 global $conf;
297
298 $this->errno = 0;
299
300 $this->db->begin();
301
302 $sql = "DELETE FROM ".MAIN_DB_PREFIX."bordereau_cheque";
303 $sql .= " WHERE rowid = ".((int) $this->id);
304 $sql .= " AND entity = ".$conf->entity;
305
306 $resql = $this->db->query($sql);
307 if ($resql) {
308 $num = $this->db->affected_rows($resql);
309
310 if ($num != 1) {
311 $this->errno = -2;
312 dol_syslog("Remisecheque::Delete Erreur Lecture ID ($this->errno)");
313 }
314
315 if ($this->errno === 0) {
316 $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
317 $sql .= " SET fk_bordereau = 0";
318 $sql .= " WHERE fk_bordereau = ".((int) $this->id);
319
320 $resql = $this->db->query($sql);
321 if (!$resql) {
322 $this->errno = -1028;
323 dol_syslog("RemiseCheque::Delete ERREUR UPDATE ($this->errno)");
324 }
325 }
326 }
327
328 if ($this->errno === 0) {
329 $this->db->commit();
330 } else {
331 $this->db->rollback();
332 dol_syslog("RemiseCheque::Delete ROLLBACK ($this->errno)");
333 }
334
335 return $this->errno;
336 }
337
344 public function validate($user)
345 {
346 global $langs, $conf;
347
348 $this->errno = 0;
349
350 $this->db->begin();
351
352 $numref = $this->getNextNumRef();
353
354 if ($this->errno == 0 && $numref) {
355 $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
356 $sql .= " SET statut = 1, ref = '".$this->db->escape($numref)."'";
357 $sql .= " WHERE rowid = ".((int) $this->id);
358 $sql .= " AND entity = ".$conf->entity;
359 $sql .= " AND statut = 0";
360
361 dol_syslog("RemiseCheque::Validate", LOG_DEBUG);
362 $resql = $this->db->query($sql);
363 if ($resql) {
364 $num = $this->db->affected_rows($resql);
365
366 if ($num == 1) {
367 $this->ref = $numref;
368 $this->statut = 1;
369 } else {
370 $this->errno = -1029;
371 dol_syslog("Remisecheque::Validate Error ".$this->errno, LOG_ERR);
372 }
373 } else {
374 $this->errno = -1033;
375 dol_syslog("Remisecheque::Validate Error ".$this->errno, LOG_ERR);
376 }
377 }
378
379 // Commit/Rollback
380 if ($this->errno == 0) {
381 $this->db->commit();
382 return 1;
383 } else {
384 $this->db->rollback();
385 dol_syslog("RemiseCheque::Validate ".$this->errno, LOG_ERR);
386 return $this->errno;
387 }
388 }
389
397 public function getNextNumRef($mode = 'next')
398 {
399 global $conf, $db, $langs, $mysoc;
400 $langs->load("bills");
401
402 // Clean parameters (if not defined or using deprecated value)
403 if (!getDolGlobalString('CHEQUERECEIPTS_ADDON')) {
404 $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_mint';
405 } elseif (getDolGlobalString('CHEQUERECEIPTS_ADDON') == 'thyme') {
406 $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_thyme';
407 } elseif (getDolGlobalString('CHEQUERECEIPTS_ADDON') == 'mint') {
408 $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_mint';
409 }
410
411 if (getDolGlobalString('CHEQUERECEIPTS_ADDON')) {
412 $mybool = false;
413
414 $file = getDolGlobalString('CHEQUERECEIPTS_ADDON') . ".php";
415 $classname = $conf->global->CHEQUERECEIPTS_ADDON;
416
417 // Include file with class
418 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
419
420 foreach ($dirmodels as $reldir) {
421 $dir = dol_buildpath($reldir."core/modules/cheque/");
422
423 // Load file with numbering class (if found)
424 if (is_file($dir.$file) && is_readable($dir.$file)) {
425 $mybool |= include_once $dir.$file;
426 }
427 }
428
429 // For compatibility
430 if (!$mybool) {
431 $file = getDolGlobalString('CHEQUERECEIPTS_ADDON') . ".php";
432 $classname = "mod_chequereceipt_" . getDolGlobalString('CHEQUERECEIPTS_ADDON');
433 $classname = preg_replace('/\-.*$/', '', $classname);
434 // Include file with class
435 foreach ($conf->file->dol_document_root as $dirroot) {
436 $dir = $dirroot."/core/modules/cheque/";
437
438 // Load file with numbering class (if found)
439 if (is_file($dir.$file) && is_readable($dir.$file)) {
440 $mybool |= include_once $dir.$file;
441 }
442 }
443 }
444
445 if (!$mybool) {
446 dol_print_error('', "Failed to include file ".$file);
447 return '';
448 }
449
450 $obj = new $classname();
451 $numref = "";
452 $numref = $obj->getNextValue($mysoc, $this);
453
458 if ($mode != 'last' && !$numref) {
459 dol_print_error($db, "ChequeReceipts::getNextNumRef ".$obj->error);
460 return "";
461 }
462
463 return $numref;
464 } else {
465 $langs->load("errors");
466 print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Bank"));
467 return "";
468 }
469 }
470
471
472 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
480 public function load_board($user, $type = 'CHQ')
481 {
482 // phpcs:enable
483 global $conf, $langs;
484
485 if ($user->socid) {
486 return -1; // protection pour eviter appel par utilisateur externe
487 }
488
489 $sql = "SELECT b.rowid, b.datev as datefin";
490 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
491 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
492 $sql .= " WHERE b.fk_account = ba.rowid";
493 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
494 $sql .= " AND b.fk_type = '".$this->db->escape($type)."'";
495 $sql .= " AND b.fk_bordereau = 0";
496 $sql .= " AND b.amount > 0";
497
498 $resql = $this->db->query($sql);
499 if ($resql) {
500 $langs->load("banks");
501 $now = dol_now();
502
503 $response = new WorkboardResponse();
504 $response->warning_delay = $conf->bank->cheque->warning_delay / 60 / 60 / 24;
505 $response->label = $langs->trans("BankChecksToReceipt");
506 $response->labelShort = $langs->trans("BankChecksToReceiptShort");
507 $response->url = DOL_URL_ROOT.'/compta/paiement/cheque/index.php?leftmenu=checks&amp;mainmenu=bank';
508 $response->img = img_object('', "payment");
509
510 while ($obj = $this->db->fetch_object($resql)) {
511 $response->nbtodo++;
512
513 if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->cheque->warning_delay)) {
514 $response->nbtodolate++;
515 }
516 }
517
518 return $response;
519 } else {
520 dol_print_error($this->db);
521 $this->error = $this->db->error();
522 return -1;
523 }
524 }
525
526
527 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
534 public function load_state_board($type = 'CHQ')
535 {
536 // phpcs:enable
537 global $user;
538
539 if ($user->socid) {
540 return -1; // protection pour eviter appel par utilisateur externe
541 }
542
543 $sql = "SELECT count(b.rowid) as nb";
544 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
545 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
546 $sql .= " WHERE b.fk_account = ba.rowid";
547 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
548 $sql .= " AND b.fk_type = '".$this->db->escape($type)."'";
549 $sql .= " AND b.amount > 0";
550
551 $resql = $this->db->query($sql);
552 if ($resql) {
553 while ($obj = $this->db->fetch_object($resql)) {
554 $this->nb["cheques"] = $obj->nb;
555 }
556 $this->db->free($resql);
557 return 1;
558 } else {
559 dol_print_error($this->db);
560 $this->error = $this->db->error();
561 return -1;
562 }
563 }
564
565
573 public function generatePdf($model, $outputlangs)
574 {
575 global $langs, $conf;
576
577 if (empty($model)) {
578 $model = 'blochet';
579 }
580
581 dol_syslog("RemiseCheque::generatePdf model=".$model." id=".$this->id, LOG_DEBUG);
582
583 $dir = DOL_DOCUMENT_ROOT."/core/modules/cheque/doc/";
584
585 // Charge le modele
586 $file = "pdf_".$model.".class.php";
587 if (file_exists($dir.$file)) {
588 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
589 include_once $dir.$file;
590
591 $classname = 'BordereauCheque'.ucfirst($model);
592 $docmodel = new $classname($this->db);
593
594 $sql = "SELECT b.banque, b.emetteur, b.amount, b.num_chq";
595 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
596 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
597 $sql .= ", ".MAIN_DB_PREFIX."bordereau_cheque as bc";
598 $sql .= " WHERE b.fk_account = ba.rowid";
599 $sql .= " AND b.fk_bordereau = bc.rowid";
600 $sql .= " AND bc.rowid = ".((int) $this->id);
601 $sql .= " AND bc.entity = ".$conf->entity;
602 $sql .= " ORDER BY b.dateo ASC, b.rowid ASC";
603
604 dol_syslog("RemiseCheque::generatePdf", LOG_DEBUG);
605 $result = $this->db->query($sql);
606 if ($result) {
607 $i = 0;
608 while ($objp = $this->db->fetch_object($result)) {
609 $docmodel->lines[$i] = new stdClass();
610 $docmodel->lines[$i]->bank_chq = $objp->banque;
611 $docmodel->lines[$i]->emetteur_chq = $objp->emetteur;
612 $docmodel->lines[$i]->amount_chq = $objp->amount;
613 $docmodel->lines[$i]->num_chq = $objp->num_chq;
614 $i++;
615 }
616 }
617 $docmodel->nbcheque = $this->nbcheque;
618 $docmodel->ref = $this->ref;
619 $docmodel->amount = $this->amount;
620 $docmodel->date = $this->date_bordereau;
621
622 $account = new Account($this->db);
623 $account->fetch($this->account_id);
624
625 $docmodel->account = &$account;
626
627 // We save charset_output to restore it because write_file can change it if needed for
628 // output format that does not support UTF8.
629 $sav_charset_output = $outputlangs->charset_output;
630
631 $result = $docmodel->write_file($this, $conf->bank->dir_output.'/checkdeposits', $this->ref, $outputlangs);
632 if ($result > 0) {
633 //$outputlangs->charset_output=$sav_charset_output;
634 return 1;
635 } else {
636 //$outputlangs->charset_output=$sav_charset_output;
637 dol_syslog("Error");
638 dol_print_error($this->db, $docmodel->error);
639 return 0;
640 }
641 } else {
642 $this->error = $langs->trans("ErrorFileDoesNotExists", $dir.$file);
643 return -1;
644 }
645 }
646
652 public function updateAmount()
653 {
654 global $conf;
655
656 $this->errno = 0;
657
658 $this->db->begin();
659 $total = 0;
660 $nb = 0;
661 $sql = "SELECT amount ";
662 $sql .= " FROM ".MAIN_DB_PREFIX."bank";
663 $sql .= " WHERE fk_bordereau = ".((int) $this->id);
664
665 $resql = $this->db->query($sql);
666 if ($resql) {
667 while ($row = $this->db->fetch_row($resql)) {
668 $total += $row[0];
669 $nb++;
670 }
671
672 $this->db->free($resql);
673
674 $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
675 $sql .= " SET amount = ".price2num($total);
676 $sql .= ", nbcheque = ".((int) $nb);
677 $sql .= " WHERE rowid = ".((int) $this->id);
678 $sql .= " AND entity = ".((int) $conf->entity);
679
680 $resql = $this->db->query($sql);
681 if (!$resql) {
682 $this->errno = -1030;
683 dol_syslog("RemiseCheque::updateAmount ERREUR UPDATE ($this->errno)");
684 }
685 } else {
686 $this->errno = -1031;
687 dol_syslog("RemiseCheque::updateAmount ERREUR SELECT ($this->errno)");
688 }
689
690 if ($this->errno === 0) {
691 $this->db->commit();
692 } else {
693 $this->db->rollback();
694 dol_syslog("RemiseCheque::updateAmount ROLLBACK ($this->errno)");
695 }
696
697 return $this->errno;
698 }
699
706 public function removeCheck($account_id)
707 {
708 $this->errno = 0;
709
710 if ($this->id > 0) {
711 $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
712 $sql .= " SET fk_bordereau = 0";
713 $sql .= " WHERE rowid = ".((int) $account_id);
714 $sql .= " AND fk_bordereau = ".((int) $this->id);
715
716 $resql = $this->db->query($sql);
717 if ($resql) {
718 $this->updateAmount();
719 } else {
720 $this->errno = -1032;
721 dol_syslog("RemiseCheque::removeCheck ERREUR UPDATE ($this->errno)");
722 }
723 }
724 return 0;
725 }
726
735 public function rejectCheck($bank_id, $rejection_date)
736 {
737 global $db, $user;
738
739 $payment = new Paiement($db);
740 $payment->fetch(0, 0, $bank_id);
741
742 $bankline = new AccountLine($db);
743 $bankline->fetch($bank_id);
744
745 /* Reconciliation is allowed because when check is returned, a new line is created onto bank transaction log.
746 if ($bankline->rappro)
747 {
748 $this->error='ActionRefusedLineAlreadyConciliated';
749 return -1;
750 }*/
751
752 $this->db->begin();
753
754 // Not reconciled, we can delete it
755 //$bankline->delete($user); // We delete
756
757 $bankaccount = $payment->fk_account;
758
759 // Get invoices list to reopen them
760 $sql = 'SELECT pf.fk_facture, pf.amount';
761 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
762 $sql .= ' WHERE pf.fk_paiement = '.((int) $payment->id);
763
764 $resql = $this->db->query($sql);
765 if ($resql) {
766 $rejectedPayment = new Paiement($this->db);
767 $rejectedPayment->amounts = array();
768 $rejectedPayment->datepaye = $rejection_date;
769 $rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement', 'code', 'id', 1);
770 $rejectedPayment->num_payment = $payment->num_payment;
771
772 while ($obj = $this->db->fetch_object($resql)) {
773 $invoice = new Facture($this->db);
774 $invoice->fetch($obj->fk_facture);
775 $invoice->setUnpaid($user);
776
777 $rejectedPayment->amounts[$obj->fk_facture] = price2num($obj->amount) * -1;
778 }
779
780 $result = $rejectedPayment->create($user);
781 if ($result > 0) {
782 // We created a negative payment, we also add the line as bank transaction
783 $result = $rejectedPayment->addPaymentToBank($user, 'payment', '(CheckRejected)', $bankaccount, '', '');
784 if ($result > 0) {
785 $result = $payment->reject();
786 if ($result > 0) {
787 $this->db->commit();
788 return $rejectedPayment->id;
789 } else {
790 $this->db->rollback();
791 return -1;
792 }
793 } else {
794 $this->error = $rejectedPayment->error;
795 $this->errors = $rejectedPayment->errors;
796 $this->db->rollback();
797 return -1;
798 }
799 } else {
800 $this->error = $rejectedPayment->error;
801 $this->errors = $rejectedPayment->errors;
802 $this->db->rollback();
803 return -1;
804 }
805 } else {
806 $this->error = $this->db->lasterror();
807 $this->db->rollback();
808 return -1;
809 }
810 }
811
812 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
820 public function set_date($user, $date)
821 {
822 // phpcs:enable
823 if ($user->hasRight('banque', 'cheque')) {
824 $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
825 $sql .= " SET date_bordereau = ".($date ? "'".$this->db->idate($date)."'" : 'null');
826 $sql .= " WHERE rowid = ".((int) $this->id);
827
828 dol_syslog("RemiseCheque::set_date", LOG_DEBUG);
829 $resql = $this->db->query($sql);
830 if ($resql) {
831 $this->date_bordereau = $date;
832 return 1;
833 } else {
834 $this->error = $this->db->error();
835 return -1;
836 }
837 } else {
838 return -2;
839 }
840 }
841
842 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
850 public function set_number($user, $ref)
851 {
852 // phpcs:enable
853 if ($user->hasRight('banque', 'cheque')) {
854 $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
855 $sql .= " SET ref = '".$this->db->escape($ref)."'";
856 $sql .= " WHERE rowid = ".((int) $this->id);
857
858 dol_syslog("RemiseCheque::set_number", LOG_DEBUG);
859 $resql = $this->db->query($sql);
860 if ($resql) {
861 return 1;
862 } else {
863 $this->error = $this->db->error();
864 return -1;
865 }
866 } else {
867 return -2;
868 }
869 }
870
879 public function initAsSpecimen($option = '')
880 {
881 global $user, $langs, $conf;
882
883 $now = dol_now();
884 $arraynow = dol_getdate($now);
885 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
886
887 // Initialize parameters
888 $this->id = 0;
889 $this->ref = 'SPECIMEN';
890 $this->specimen = 1;
891 $this->date_bordereau = $nownotime;
892 }
893
904 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
905 {
906 global $conf, $langs;
907
908 $result = '';
909
910 $label = '<u>'.$langs->trans("ShowCheckReceipt").'</u>';
911 $label .= '<br>';
912 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
913
914 $url = DOL_URL_ROOT.'/compta/paiement/cheque/card.php?id='.$this->id;
915
916 if ($option != 'nolink') {
917 // Add param to save lastsearch_values or not
918 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
919 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
920 $add_save_lastsearch_values = 1;
921 }
922 if ($add_save_lastsearch_values) {
923 $url .= '&save_lastsearch_values=1';
924 }
925 }
926
927 $linkclose = '';
928 if (empty($notooltip)) {
929 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
930 $label = $langs->trans("ShowCheckReceipt");
931 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
932 }
933 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
934 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
935 } else {
936 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
937 }
938
939 $linkstart = '<a href="'.$url.'"';
940 $linkstart .= $linkclose.'>';
941 $linkend = '</a>';
942
943 $result .= $linkstart;
944 if ($withpicto) {
945 $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);
946 }
947 if ($withpicto != 2) {
948 $result .= $this->ref;
949 }
950 $result .= $linkend;
951
952 return $result;
953 }
954
961 public function getLibStatut($mode = 0)
962 {
963 return $this->LibStatut($this->statut, $mode);
964 }
965
966 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
974 public function LibStatut($status, $mode = 0)
975 {
976 // phpcs:enable
977 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
978 global $langs;
979 $langs->load('compta');
980 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('ToValidate');
981 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
982 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('ToValidate');
983 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
984 }
985
986 $statusType = 'status'.$status;
987 if ($status == self::STATUS_VALIDATED) {
988 $statusType = 'status4';
989 }
990
991 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
992 }
993
1001 public function getKanbanView($option = '', $arraydata = null)
1002 {
1003 global $langs;
1004
1005 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1006
1007 $return = '<div class="box-flex-item box-flex-grow-zero">';
1008 $return .= '<div class="info-box info-box-sm">';
1009 $return .= '<span class="info-box-icon bg-infobox-action">';
1010 $return .= img_picto('', $this->picto);
1011 $return .= '</span>';
1012 $return .= '<div class="info-box-content">';
1013 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1014 if ($selected >= 0) {
1015 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1016 }
1017 if (property_exists($this, 'date_bordereau')) {
1018 $return .= '<br><span class="opacitymedium">'.$langs->trans("DateCreation").'</span> : <span class="info-box-label">'.dol_print_date($this->db->jdate($this->date_bordereau), 'day').'</span>';
1019 }
1020 if (property_exists($this, 'nbcheque')) {
1021 $return .= '<br><span class="opacitymedium">'.$langs->trans("Cheque", '', '', '', '', 5).'</span> : <span class="info-box-label">'.$this->nbcheque.'</span>';
1022 }
1023 if (property_exists($this, 'account_id')) {
1024 $return .= ' | <span class="info-box-label">'.$this->account_id.'</span>';
1025 }
1026 if (method_exists($this, 'LibStatut')) {
1027 $return .= '<br><div style="display:inline-block" class="info-box-status margintoponly">'.$this->getLibStatut(3).'</div>';
1028 }
1029 if (property_exists($this, 'amount')) {
1030 $return .= ' | <div style="display:inline-block"><span class="opacitymedium">'.$langs->trans("Amount").'</span> : <span class="amount">'.price($this->amount).'</div>';
1031 }
1032 $return .= '</div>';
1033 $return .= '</div>';
1034 $return .= '</div>';
1035 return $return;
1036 }
1037}
$object ref
Definition info.php:79
Class to manage bank accounts.
Class to manage bank transaction lines.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Class to manage invoices.
Class to manage payments of customer invoices.
Class to manage cheque delivery receipts.
removeCheck($account_id)
Insere la remise en base.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
$errno
Numero d'erreur Plage 1024-1279.
load_state_board($type='CHQ')
Charge indicateurs this->nb de tableau de bord.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
generatePdf($model, $outputlangs)
Build document.
LibStatut($status, $mode=0)
Return the label of a given status.
__construct($db)
Constructor.
getLibStatut($mode=0)
Return the label of the status.
set_date($user, $date)
Set the creation date.
rejectCheck($bank_id, $rejection_date)
Check return management Reopen linked invoices and create a new negative payment.
validate($user)
Validate a receipt.
set_number($user, $ref)
Set the ref of bordereau.
load_board($user, $type='CHQ')
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
getNextNumRef($mode='next')
Return next reference of cheque receipts not already used (or last reference) according to numbering ...
fetch($id, $ref='')
Load record.
create($user, $account_id, $limit, $toRemise)
Create a receipt to send cheques.
updateAmount()
Mets a jour le montant total.
initAsSpecimen($option='')
Initialise an instance with random values.
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...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut
Definition invoice.php:1926
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:121