dolibarr 25.0.0-alpha
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 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
29require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
31
32
37{
41 public $element = 'chequereceipt';
42
46 public $table_element = 'bordereau_cheque';
47
51 public $picto = 'payment';
52
56 public $num;
60 public $intitule;
64 public $errno;
65
69 public $type = 'CHQ'; // 'CHQ', 'TRA', ...
70
74 public $amount;
78 public $date_bordereau;
82 public $account_id;
86 public $account_label;
90 public $author_id;
94 public $nbcheque;
95
99 public $ref;
100
101 const STATUS_DRAFT = 0;
102 const STATUS_VALIDATED = 1;
103
104
110 public function __construct($db)
111 {
112 $this->db = $db;
113 }
114
122 public function fetch($id, $ref = '')
123 {
124 global $conf;
125
126 $sql = "SELECT bc.rowid, bc.datec, bc.fk_user_author, bc.fk_bank_account, bc.amount, bc.ref, bc.statut as status, bc.nbcheque, bc.ref_ext,";
127 $sql .= " bc.date_bordereau as date_bordereau, bc.type,";
128 $sql .= " ba.label as account_label";
129 $sql .= " FROM ".MAIN_DB_PREFIX."bordereau_cheque as bc";
130 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON bc.fk_bank_account = ba.rowid";
131 $sql .= " WHERE bc.entity = ".((int) $conf->entity);
132 if ($id) {
133 $sql .= " AND bc.rowid = ".((int) $id);
134 }
135 if ($ref) {
136 $sql .= " AND bc.ref = '".$this->db->escape($ref)."'";
137 }
138
139 dol_syslog("RemiseCheque::fetch", LOG_DEBUG);
140 $resql = $this->db->query($sql);
141 if ($resql) {
142 if ($obj = $this->db->fetch_object($resql)) {
143 $this->id = $obj->rowid;
144 $this->amount = $obj->amount;
145 $this->date_bordereau = $this->db->jdate($obj->date_bordereau);
146 $this->account_id = $obj->fk_bank_account;
147 $this->account_label = $obj->account_label;
148 $this->author_id = $obj->fk_user_author;
149 $this->nbcheque = $obj->nbcheque;
150 $this->statut = $obj->status;
151 $this->status = $obj->status;
152 $this->ref_ext = $obj->ref_ext;
153 $this->type = $obj->type;
154
155 if ($this->status == 0) {
156 $this->ref = "(PROV".$this->id.")";
157 } else {
158 $this->ref = $obj->ref;
159 }
160 }
161 $this->db->free($resql);
162
163 return 1;
164 } else {
165 $this->error = $this->db->lasterror();
166 return -1;
167 }
168 }
169
180 public function create($user, $account_id, $limit, $toRemise, $notrigger = 0)
181 {
182 global $conf;
183
184 $this->errno = 0;
185 $this->id = 0;
186
187 $now = dol_now();
188
189 dol_syslog("RemiseCheque::Create start", LOG_DEBUG);
190
191 // Clean parameters
192 if (empty($this->type)) {
193 $this->type = 'CHQ';
194 }
195
196 $this->db->begin();
197
198 $sql = "INSERT INTO ".MAIN_DB_PREFIX."bordereau_cheque (";
199 $sql .= "datec";
200 $sql .= ", date_bordereau";
201 $sql .= ", fk_user_author";
202 $sql .= ", fk_bank_account";
203 $sql .= ", statut";
204 $sql .= ", amount";
205 $sql .= ", ref";
206 $sql .= ", entity";
207 $sql .= ", nbcheque";
208 $sql .= ", ref_ext";
209 $sql .= ", type";
210 $sql .= ") VALUES (";
211 $sql .= "'".$this->db->idate($now)."'";
212 $sql .= ", '".$this->db->idate($now)."'";
213 $sql .= ", ".((int) $user->id);
214 $sql .= ", ".((int) $account_id);
215 $sql .= ", 0";
216 $sql .= ", 0";
217 $sql .= ", 0";
218 $sql .= ", ".((int) $conf->entity);
219 $sql .= ", 0";
220 $sql .= ", ''";
221 $sql .= ", '".$this->db->escape($this->type)."'";
222 $sql .= ")";
223
224 $resql = $this->db->query($sql);
225 if ($resql) {
226 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bordereau_cheque");
227 if ($this->id == 0) {
228 $this->errno = -1024;
229 dol_syslog("Remisecheque::Create Error read id ".$this->errno, LOG_ERR);
230 }
231
232 if ($this->id > 0 && $this->errno == 0) {
233 $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
234 $sql .= " SET ref = '(PROV".((int) $this->id).")'";
235 $sql .= " WHERE rowid=".((int) $this->id);
236
237 $resql = $this->db->query($sql);
238 if (!$resql) {
239 $this->errno = -1025;
240 dol_syslog("RemiseCheque::Create Error update ".$this->errno, LOG_ERR);
241 }
242 }
243
244 $lines = array();
245
246 if ($this->id > 0 && $this->errno == 0) {
247 $sql = "SELECT b.rowid";
248 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
249 $sql .= " WHERE b.fk_type = '".$this->db->escape($this->type)."'";
250 $sql .= " AND b.amount > 0";
251 $sql .= " AND b.fk_bordereau = 0";
252 $sql .= " AND b.fk_account = ".((int) $account_id);
253 if ($limit) {
254 $sql .= $this->db->plimit($limit);
255 }
256
257 dol_syslog("RemiseCheque::Create", LOG_DEBUG);
258 $resql = $this->db->query($sql);
259 if ($resql) {
260 while ($row = $this->db->fetch_row($resql)) {
261 array_push($lines, $row[0]);
262 }
263 $this->db->free($resql);
264 } else {
265 $this->errno = -1026;
266 dol_syslog("RemiseCheque::Create Error ".$this->errno, LOG_ERR);
267 }
268 }
269
270 if ($this->id > 0 && $this->errno == 0) {
271 foreach ($lines as $lineid) {
272 $checkremise = false;
273 foreach ($toRemise as $linetoremise) {
274 if ($linetoremise == $lineid) {
275 $checkremise = true;
276 }
277 }
278
279 if ($checkremise) {
280 $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
281 $sql .= " SET fk_bordereau = ".((int) $this->id);
282 $sql .= " WHERE rowid = ".((int) $lineid);
283
284 $resql = $this->db->query($sql);
285 if (!$resql) {
286 $this->errno = -18;
287 dol_syslog("RemiseCheque::Create Error update bank ".$this->errno, LOG_ERR);
288 }
289 }
290 }
291 }
292
293 if ($this->id > 0 && $this->errno == 0) {
294 if ($this->updateAmount() != 0) {
295 $this->errno = -1027;
296 dol_syslog("RemiseCheque::Create Error update amount ".$this->errno, LOG_ERR);
297 }
298 }
299 } else {
300 $this->errno = -1;
301 $this->error = $this->db->lasterror();
302 // $this->errno = $this->db->lasterrno();
303 }
304
305 if (!$this->errno && (getDolGlobalString('MAIN_DISABLEDRAFTSTATUS') || getDolGlobalString('MAIN_DISABLEDRAFTSTATUS_CHEQUE'))) {
306 $res = $this->validate($user);
307 //if ($res < 0) $error++;
308 }
309
310 if (!$this->errno && !$notrigger) {
311 // Call trigger
312 $result = $this->call_trigger('REMISECHEQUE_CREATE', $user);
313 if ($result < 0) {
314 $this->errno = -1029;
315 }
316 // End call triggers
317 }
318
319 if (!$this->errno) {
320 $this->db->commit();
321 dol_syslog("RemiseCheque::Create end", LOG_DEBUG);
322 return $this->id;
323 } else {
324 $this->db->rollback();
325 dol_syslog("RemiseCheque::Create end", LOG_DEBUG);
326 return $this->errno;
327 }
328 }
329
337 public function delete($user, $notrigger = 0)
338 {
339 global $conf;
340
341 $this->errno = 0;
342
343 $this->db->begin();
344
345 $sql = "DELETE FROM ".MAIN_DB_PREFIX."bordereau_cheque";
346 $sql .= " WHERE rowid = ".((int) $this->id);
347 $sql .= " AND entity = ".((int) $conf->entity);
348
349 $resql = $this->db->query($sql);
350 if ($resql) {
351 $num = $this->db->affected_rows($resql);
352
353 if ($num != 1) {
354 $this->errno = -2;
355 dol_syslog("Remisecheque::Delete Erreur Lecture ID ($this->errno)");
356 }
357
358 if ($this->errno === 0) {
359 $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
360 $sql .= " SET fk_bordereau = 0";
361 $sql .= " WHERE fk_bordereau = ".((int) $this->id);
362
363 $resql = $this->db->query($sql);
364 if (!$resql) {
365 $this->errno = -1028;
366 dol_syslog("RemiseCheque::Delete ERREUR UPDATE ($this->errno)");
367 }
368 }
369 }
370
371 if ($this->errno === 0 && !$notrigger) {
372 // Call trigger
373 $result = $this->call_trigger('REMISECHEQUE_DELETE', $user);
374 if ($result < 0) {
375 $this->errno = -1029;
376 }
377 // End call triggers
378 }
379
380 if ($this->errno === 0) {
381 $this->db->commit();
382 } else {
383 $this->db->rollback();
384 dol_syslog("RemiseCheque::Delete ROLLBACK ($this->errno)");
385 }
386
387 return $this->errno;
388 }
389
396 public function validate($user)
397 {
398 global $conf;
399
400 $this->errno = 0;
401
402 $this->db->begin();
403
404 $numref = $this->getNextNumRef();
405
406 if ($this->errno == 0 && $numref) {
407 $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
408 $sql .= " SET statut = 1, ref = '".$this->db->escape($numref)."'";
409 $sql .= " WHERE rowid = ".((int) $this->id);
410 $sql .= " AND entity = ".((int) $conf->entity);
411 $sql .= " AND statut = 0";
412
413 dol_syslog("RemiseCheque::Validate", LOG_DEBUG);
414 $resql = $this->db->query($sql);
415 if ($resql) {
416 $num = $this->db->affected_rows($resql);
417
418 if ($num == 1) {
419 $this->ref = $numref;
420 $this->statut = 1;
421 $this->status = 1;
422 } else {
423 $this->errno = -1029;
424 dol_syslog("Remisecheque::validate Error ".$this->errno, LOG_ERR);
425 }
426 } else {
427 $this->errno = -1033;
428 $this->error = $this->db->lasterror();
429 dol_syslog("Remisecheque::validate Error ".$this->errno, LOG_ERR);
430 }
431 }
432
433 // Commit/Rollback
434 if ($this->errno == 0) {
435 $this->db->commit();
436 return 1;
437 } else {
438 $this->db->rollback();
439 dol_syslog("RemiseCheque::Validate ".$this->errno, LOG_ERR);
440 return $this->errno;
441 }
442 }
443
451 public function getNextNumRef($mode = 'next')
452 {
453 global $conf, $db, $langs, $mysoc;
454 $langs->load("bills");
455
456 // Clean parameters (if not defined or using deprecated value)
457 if (!getDolGlobalString('CHEQUERECEIPTS_ADDON')) {
458 $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_mint';
459 } elseif (getDolGlobalString('CHEQUERECEIPTS_ADDON') == 'thyme') {
460 $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_thyme';
461 } elseif (getDolGlobalString('CHEQUERECEIPTS_ADDON') == 'mint') {
462 $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_mint';
463 }
464
465 if (getDolGlobalString('CHEQUERECEIPTS_ADDON')) {
466 $mybool = false;
467
468 $file = getDolGlobalString('CHEQUERECEIPTS_ADDON') . ".php";
469 $classname = getDolGlobalString('CHEQUERECEIPTS_ADDON');
470
471 // Include file with class
472 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
473
474 foreach ($dirmodels as $reldir) {
475 $dir = dol_buildpath($reldir."core/modules/cheque/");
476
477 // Load file with numbering class (if found)
478 if (is_file($dir.$file) && is_readable($dir.$file)) {
479 $mybool = (include_once $dir.$file) || $mybool;
480 }
481 }
482
483 // For compatibility
484 if (!$mybool) {
485 $file = getDolGlobalString('CHEQUERECEIPTS_ADDON') . ".php";
486 $classname = "mod_chequereceipt_" . getDolGlobalString('CHEQUERECEIPTS_ADDON');
487 $classname = preg_replace('/\-.*$/', '', $classname);
488 // Include file with class
489 foreach ($conf->file->dol_document_root as $dirroot) {
490 $dir = $dirroot."/core/modules/cheque/";
491
492 // Load file with numbering class (if found)
493 if (is_file($dir.$file) && is_readable($dir.$file)) {
494 $mybool = (include_once $dir.$file) || $mybool;
495 }
496 }
497 }
498
499 if (!$mybool) {
500 dol_print_error(null, "Failed to include file ".$file);
501 return '';
502 }
503
504 $obj = new $classname();
505 '@phan-var-force ModeleNumRefChequeReceipts $obj';
506
507 $numref = "";
508 $numref = $obj->getNextValue($mysoc, $this);
509
514 if ($mode != 'last' && !$numref) {
515 dol_print_error($db, "ChequeReceipts::getNextValue ".$obj->error);
516 return "";
517 }
518
519 return $numref;
520 } else {
521 $langs->load("errors");
522 print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Bank"));
523 return "";
524 }
525 }
526
527
528 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
536 public function load_board($user, $type = 'CHQ')
537 {
538 // phpcs:enable
539 global $conf, $langs;
540
541 if ($user->socid) {
542 return -1; // Protection to prevent calls by external users
543 }
544
545 $now = dol_now();
546
547 // The count and the number of late cheques are computed by the database instead of reading every cheque. A cheque is late
548 // when its value date is before now minus the warning delay (a cheque without value date was counted as late, this is kept).
549 $sql = "SELECT COUNT(b.rowid) as nb,";
550 $sql .= " SUM(CASE WHEN b.datev IS NULL OR b.datev < '".$this->db->idate($now - $conf->bank->cheque->warning_delay)."' THEN 1 ELSE 0 END) as nblate";
551 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
552 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
553 $sql .= " WHERE b.fk_account = ba.rowid";
554 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
555 $sql .= " AND b.fk_type = '".$this->db->escape($type)."'";
556 $sql .= " AND b.fk_bordereau = 0";
557 $sql .= " AND b.amount > 0";
558
559 $resql = $this->db->query($sql);
560 if ($resql) {
561 $langs->load("banks");
562
563 $response = new WorkboardResponse();
564 $response->warning_delay = $conf->bank->cheque->warning_delay / 60 / 60 / 24;
565 $response->label = $langs->trans("BankChecksToReceipt");
566 $response->labelShort = $langs->trans("BankChecksToReceiptShort");
567 $response->url = DOL_URL_ROOT.'/compta/paiement/cheque/index.php?leftmenu=checks&amp;mainmenu=bank';
568 $response->img = img_object('', "payment");
569
570 $obj = $this->db->fetch_object($resql);
571 if ($obj) {
572 $response->nbtodo = (int) $obj->nb;
573 $response->nbtodolate = (int) $obj->nblate;
574 }
575
576 return $response;
577 } else {
578 dol_print_error($this->db);
579 $this->error = $this->db->error();
580 return -1;
581 }
582 }
583
584
591 public function loadStateBoard($type = 'CHQ')
592 {
593 global $user;
594
595 if ($user->socid) {
596 return -1; // Protection to prevent calls by external users
597 }
598
599 $sql = "SELECT count(b.rowid) as nb";
600 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
601 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
602 $sql .= " WHERE b.fk_account = ba.rowid";
603 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
604 $sql .= " AND b.fk_type = '".$this->db->escape($type)."'";
605 $sql .= " AND b.amount > 0";
606
607 $resql = $this->db->query($sql);
608 if ($resql) {
609 while ($obj = $this->db->fetch_object($resql)) {
610 $this->nb["cheques"] = $obj->nb;
611 }
612 $this->db->free($resql);
613 return 1;
614 } else {
615 dol_print_error($this->db);
616 $this->error = $this->db->error();
617 return -1;
618 }
619 }
620
621
629 public function generatePdf($model, $outputlangs)
630 {
631 global $langs, $conf;
632
633 if (empty($model)) {
634 $model = 'blochet';
635 }
636
637 dol_syslog("RemiseCheque::generatePdf model=".$model." id=".$this->id, LOG_DEBUG);
638
639 $dir = DOL_DOCUMENT_ROOT."/core/modules/cheque/doc/";
640
641 // Charge le modele
642 $file = "pdf_".$model.".class.php";
643 if (file_exists($dir.$file)) {
644 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
645 include_once $dir.$file;
646
647 $classname = 'BordereauCheque'.ucfirst($model);
648 $docmodel = new $classname($this->db);
649 '@phan-var-force ModeleChequeReceipts $docmodel';
650
651 $sql = "SELECT b.banque, b.emetteur, b.amount, b.num_chq";
652 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
653 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
654 $sql .= ", ".MAIN_DB_PREFIX."bordereau_cheque as bc";
655 $sql .= " WHERE b.fk_account = ba.rowid";
656 $sql .= " AND b.fk_bordereau = bc.rowid";
657 $sql .= " AND bc.rowid = ".((int) $this->id);
658 $sql .= " AND bc.entity = ".((int) $conf->entity);
659 $sql .= " ORDER BY b.dateo ASC, b.rowid ASC";
660
661 dol_syslog("RemiseCheque::generatePdf", LOG_DEBUG);
662 $result = $this->db->query($sql);
663 if ($result) {
664 $i = 0;
665 while ($objp = $this->db->fetch_object($result)) {
666 $docmodel->lines[$i] = new stdClass();
667 $docmodel->lines[$i]->bank_chq = $objp->banque;
668 $docmodel->lines[$i]->emetteur_chq = $objp->emetteur;
669 $docmodel->lines[$i]->amount_chq = $objp->amount;
670 $docmodel->lines[$i]->num_chq = $objp->num_chq;
671 $i++;
672 }
673 }
674 $docmodel->nbcheque = $this->nbcheque;
675 $docmodel->ref = $this->ref;
676 $docmodel->amount = $this->amount;
677 $docmodel->date = $this->date_bordereau;
678
679 $account = new Account($this->db);
680 $account->fetch($this->account_id);
681
682 $docmodel->account = &$account;
683
684 // We save charset_output to restore it because write_file can change it if needed for
685 // output format that does not support UTF8.
686 $sav_charset_output = $outputlangs->charset_output;
687
688 $result = $docmodel->write_file($this, $outputlangs, $conf->bank->dir_output.'/checkdeposits', $this->ref);
689 if ($result > 0) {
690 //$outputlangs->charset_output=$sav_charset_output;
691 return 1;
692 } else {
693 //$outputlangs->charset_output=$sav_charset_output;
694 dol_syslog("Error");
695 dol_print_error($this->db, $docmodel->error);
696 return 0;
697 }
698 } else {
699 $this->error = $langs->trans("ErrorFileDoesNotExists", $dir.$file);
700 return -1;
701 }
702 }
703
709 public function updateAmount()
710 {
711 global $conf;
712
713 $this->errno = 0;
714
715 $this->db->begin();
716 $total = 0;
717 $nb = 0;
718 $sql = "SELECT amount ";
719 $sql .= " FROM ".MAIN_DB_PREFIX."bank";
720 $sql .= " WHERE fk_bordereau = ".((int) $this->id);
721
722 $resql = $this->db->query($sql);
723 if ($resql) {
724 while ($row = $this->db->fetch_row($resql)) {
725 $total += $row[0];
726 $nb++;
727 }
728
729 $this->db->free($resql);
730
731 $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
732 $sql .= " SET amount = ".price2num($total);
733 $sql .= ", nbcheque = ".((int) $nb);
734 $sql .= " WHERE rowid = ".((int) $this->id);
735 $sql .= " AND entity = ".((int) $conf->entity);
736
737 $resql = $this->db->query($sql);
738 if (!$resql) {
739 $this->errno = -1030;
740 dol_syslog("RemiseCheque::updateAmount ERREUR UPDATE ($this->errno)");
741 }
742 } else {
743 $this->errno = -1031;
744 dol_syslog("RemiseCheque::updateAmount ERREUR SELECT ($this->errno)");
745 }
746
747 if ($this->errno === 0) {
748 $this->db->commit();
749 } else {
750 $this->db->rollback();
751 dol_syslog("RemiseCheque::updateAmount ROLLBACK ($this->errno)");
752 }
753
754 return $this->errno;
755 }
756
763 public function removeCheck($account_id)
764 {
765 $this->errno = 0;
766
767 if ($this->id > 0) {
768 $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
769 $sql .= " SET fk_bordereau = 0";
770 $sql .= " WHERE rowid = ".((int) $account_id);
771 $sql .= " AND fk_bordereau = ".((int) $this->id);
772
773 $resql = $this->db->query($sql);
774 if ($resql) {
775 $this->updateAmount();
776 } else {
777 $this->errno = -1032;
778 dol_syslog("RemiseCheque::removeCheck ERREUR UPDATE ($this->errno)");
779 }
780 }
781 return 0;
782 }
783
792 public function rejectCheck($bank_id, $rejection_date)
793 {
794 global $db, $user;
795
796 $payment = new Paiement($db);
797 $payment->fetch(0, '0', $bank_id);
798
799 $bankline = new AccountLine($db);
800 $bankline->fetch($bank_id);
801
802 /* Reconciliation is allowed because when check is returned, a new line is created onto bank transaction log.
803 if ($bankline->rappro)
804 {
805 $this->error='ActionRefusedLineAlreadyConciliated';
806 return -1;
807 }*/
808
809 $this->db->begin();
810
811 // Not reconciled, we can delete it
812 //$bankline->delete($user); // We delete
813
814 $bankaccount = $payment->fk_account;
815
816 // Get invoices list to reopen them
817 $sql = 'SELECT pf.fk_facture, pf.amount';
818 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
819 $sql .= ' WHERE pf.fk_paiement = '.((int) $payment->id);
820
821 $resql = $this->db->query($sql);
822 if ($resql) {
823 $rejectedPayment = new Paiement($this->db);
824 $rejectedPayment->amounts = array();
825 $rejectedPayment->datepaye = $rejection_date;
826 $rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement', 'code', 'id', 1);
827 $rejectedPayment->num_payment = $payment->num_payment;
828
829 while ($obj = $this->db->fetch_object($resql)) {
830 $invoice = new Facture($this->db);
831 $invoice->fetch($obj->fk_facture);
832 $invoice->setUnpaid($user);
833
834 $rejectedPayment->amounts[$obj->fk_facture] = (float) price2num($obj->amount) * -1;
835 }
836
837 $result = $rejectedPayment->create($user);
838 if ($result > 0) {
839 // We created a negative payment, we also add the line as bank transaction
840 $result = $rejectedPayment->addPaymentToBank($user, 'payment', '(CheckRejected)', (int) $bankaccount, '', '');
841 if ($result > 0) {
842 $result = $payment->reject();
843 if ($result > 0) {
844 $this->db->commit();
845 return $rejectedPayment->id;
846 } else {
847 $this->db->rollback();
848 return -1;
849 }
850 } else {
851 $this->error = $rejectedPayment->error;
852 $this->errors = $rejectedPayment->errors;
853 $this->db->rollback();
854 return -1;
855 }
856 } else {
857 $this->error = $rejectedPayment->error;
858 $this->errors = $rejectedPayment->errors;
859 $this->db->rollback();
860 return -1;
861 }
862 } else {
863 $this->error = $this->db->lasterror();
864 $this->db->rollback();
865 return -1;
866 }
867 }
868
869 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
877 public function set_date($user, $date)
878 {
879 // phpcs:enable
880 if ($user->hasRight('banque', 'cheque')) {
881 $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
882 $sql .= " SET date_bordereau = ".($date ? "'".$this->db->idate($date)."'" : 'null');
883 $sql .= " WHERE rowid = ".((int) $this->id);
884
885 dol_syslog("RemiseCheque::set_date", LOG_DEBUG);
886 $resql = $this->db->query($sql);
887 if ($resql) {
888 $this->date_bordereau = $date;
889 return 1;
890 } else {
891 $this->error = $this->db->error();
892 return -1;
893 }
894 } else {
895 return -2;
896 }
897 }
898
899 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
907 public function set_number($user, $ref)
908 {
909 // phpcs:enable
910 if ($user->hasRight('banque', 'cheque')) {
911 $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
912 $sql .= " SET ref = '".$this->db->escape((string) $ref)."'";
913 $sql .= " WHERE rowid = ".((int) $this->id);
914
915 dol_syslog("RemiseCheque::set_number", LOG_DEBUG);
916 $resql = $this->db->query($sql);
917 if ($resql) {
918 return 1;
919 } else {
920 $this->error = $this->db->error();
921 return -1;
922 }
923 } else {
924 return -2;
925 }
926 }
927
936 public function initAsSpecimen($option = '')
937 {
938 global $user, $langs, $conf;
939
940 $now = dol_now();
941 $arraynow = dol_getdate($now);
942 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
943
944 // Initialize parameters
945 $this->id = 0;
946 $this->ref = 'SPECIMEN';
947 $this->specimen = 1;
948 $this->date_bordereau = $nownotime;
949
950 return 1;
951 }
952
963 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
964 {
965 global $conf, $langs;
966
967 $result = '';
968
969 $label = '<u>'.$langs->trans("ShowCheckReceipt").'</u>';
970 $label .= '<br>';
971 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
972
973 $url = DOL_URL_ROOT.'/compta/paiement/cheque/card.php?id='.$this->id;
974
975 if ($option != 'nolink') {
976 // Add param to save lastsearch_values or not
977 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
978 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
979 $add_save_lastsearch_values = 1;
980 }
981 if ($add_save_lastsearch_values) {
982 $url .= '&save_lastsearch_values=1';
983 }
984 }
985
986 $linkclose = '';
987 if (empty($notooltip)) {
988 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
989 $label = $langs->trans("ShowCheckReceipt");
990 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
991 }
992 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
993 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
994 } else {
995 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
996 }
997
998 $linkstart = '<a href="'.$url.'"';
999 $linkstart .= $linkclose.'>';
1000 $linkend = '</a>';
1001
1002 $result .= $linkstart;
1003 if ($withpicto) {
1004 $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);
1005 }
1006 if ($withpicto != 2) {
1007 $result .= $this->ref;
1008 }
1009 $result .= $linkend;
1010
1011 global $action, $hookmanager;
1012 $hookmanager->initHooks(array($this->element . 'dao'));
1013 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
1014 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1015 if ($reshook > 0) {
1016 $result = $hookmanager->resPrint;
1017 } else {
1018 $result .= $hookmanager->resPrint;
1019 }
1020
1021 return $result;
1022 }
1023
1030 public function getLibStatut($mode = 0)
1031 {
1032 return $this->LibStatut($this->statut, $mode);
1033 }
1034
1035 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1043 public function LibStatut($status, $mode = 0)
1044 {
1045 // phpcs:enable
1046 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1047 global $langs;
1048 $langs->load('compta');
1049 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('ToValidate');
1050 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
1051 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('ToValidate');
1052 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
1053 }
1054
1055 $statusType = 'status'.$status;
1056 if ($status == self::STATUS_VALIDATED) {
1057 $statusType = 'status4';
1058 }
1059
1060 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
1061 }
1062
1070 public function getKanbanView($option = '', $arraydata = null)
1071 {
1072 global $langs;
1073
1074 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1075
1076 $return = '<div class="box-flex-item box-flex-grow-zero">';
1077 $return .= '<div class="info-box info-box-sm">';
1078 $return .= '<span class="info-box-icon bg-infobox-action">';
1079 $return .= img_picto('', $this->picto);
1080 $return .= '</span>';
1081 $return .= '<div class="info-box-content">';
1082 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1083 if ($selected >= 0) {
1084 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1085 }
1086 if (property_exists($this, 'date_bordereau')) {
1087 $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>';
1088 }
1089 if (property_exists($this, 'nbcheque')) {
1090 $return .= '<br><span class="opacitymedium">'.$langs->trans("Cheque", '', '', '', '', 5).'</span> : <span class="info-box-label">'.$this->nbcheque.'</span>';
1091 }
1092 if (property_exists($this, 'account_id')) {
1093 $return .= ' | <span class="info-box-label">'.$this->account_id.'</span>';
1094 }
1095 if (method_exists($this, 'LibStatut')) {
1096 $return .= '<br><div style="display:inline-block" class="info-box-status margintoponly">'.$this->getLibStatut(3).'</div>';
1097 }
1098 if (property_exists($this, 'amount')) {
1099 $return .= ' | <div style="display:inline-block"><span class="opacitymedium">'.$langs->trans("Amount").'</span> : <span class="amount">'.price($this->amount).'</div>';
1100 }
1101 $return .= '</div>';
1102 $return .= '</div>';
1103 $return .= '</div>';
1104 return $return;
1105 }
1106}
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:280
$object ref
Definition info.php:90
Class to manage bank accounts.
Class to manage bank transaction lines.
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 clickable name (with picto eventually)
getKanbanView($option='', $arraydata=null)
Return clickable 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 ...
create($user, $account_id, $limit, $toRemise, $notrigger=0)
Create a receipt to send cheques.
fetch($id, $ref='')
Load record.
loadStateBoard($type='CHQ')
Load indicators this->nb for the state board.
updateAmount()
Update the total amount.
initAsSpecimen($option='')
Initialise an instance with random values.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:169
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a 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.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount
Definition receipt.php:494