dolibarr 21.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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024 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 = ".$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
179 public function create($user, $account_id, $limit, $toRemise)
180 {
181 global $conf;
182
183 $this->errno = 0;
184 $this->id = 0;
185
186 $now = dol_now();
187
188 dol_syslog("RemiseCheque::Create start", LOG_DEBUG);
189
190 // Clean parameters
191 if (empty($this->type)) {
192 $this->type = 'CHQ';
193 }
194
195 $this->db->begin();
196
197 $sql = "INSERT INTO ".MAIN_DB_PREFIX."bordereau_cheque (";
198 $sql .= "datec";
199 $sql .= ", date_bordereau";
200 $sql .= ", fk_user_author";
201 $sql .= ", fk_bank_account";
202 $sql .= ", statut";
203 $sql .= ", amount";
204 $sql .= ", ref";
205 $sql .= ", entity";
206 $sql .= ", nbcheque";
207 $sql .= ", ref_ext";
208 $sql .= ", type";
209 $sql .= ") VALUES (";
210 $sql .= "'".$this->db->idate($now)."'";
211 $sql .= ", '".$this->db->idate($now)."'";
212 $sql .= ", ".((int) $user->id);
213 $sql .= ", ".((int) $account_id);
214 $sql .= ", 0";
215 $sql .= ", 0";
216 $sql .= ", 0";
217 $sql .= ", ".((int) $conf->entity);
218 $sql .= ", 0";
219 $sql .= ", ''";
220 $sql .= ", '".$this->db->escape($this->type)."'";
221 $sql .= ")";
222
223 $resql = $this->db->query($sql);
224 if ($resql) {
225 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bordereau_cheque");
226 if ($this->id == 0) {
227 $this->errno = -1024;
228 dol_syslog("Remisecheque::Create Error read id ".$this->errno, LOG_ERR);
229 }
230
231 if ($this->id > 0 && $this->errno == 0) {
232 $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
233 $sql .= " SET ref = '(PROV".$this->id.")'";
234 $sql .= " WHERE rowid=".((int) $this->id);
235
236 $resql = $this->db->query($sql);
237 if (!$resql) {
238 $this->errno = -1025;
239 dol_syslog("RemiseCheque::Create Error update ".$this->errno, LOG_ERR);
240 }
241 }
242
243 $lines = array();
244
245 if ($this->id > 0 && $this->errno == 0) {
246 $sql = "SELECT b.rowid";
247 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
248 $sql .= " WHERE b.fk_type = '".$this->db->escape($this->type)."'";
249 $sql .= " AND b.amount > 0";
250 $sql .= " AND b.fk_bordereau = 0";
251 $sql .= " AND b.fk_account = ".((int) $account_id);
252 if ($limit) {
253 $sql .= $this->db->plimit($limit);
254 }
255
256 dol_syslog("RemiseCheque::Create", LOG_DEBUG);
257 $resql = $this->db->query($sql);
258 if ($resql) {
259 while ($row = $this->db->fetch_row($resql)) {
260 array_push($lines, $row[0]);
261 }
262 $this->db->free($resql);
263 } else {
264 $this->errno = -1026;
265 dol_syslog("RemiseCheque::Create Error ".$this->errno, LOG_ERR);
266 }
267 }
268
269 if ($this->id > 0 && $this->errno == 0) {
270 foreach ($lines as $lineid) {
271 $checkremise = false;
272 foreach ($toRemise as $linetoremise) {
273 if ($linetoremise == $lineid) {
274 $checkremise = true;
275 }
276 }
277
278 if ($checkremise) {
279 $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
280 $sql .= " SET fk_bordereau = ".((int) $this->id);
281 $sql .= " WHERE rowid = ".((int) $lineid);
282
283 $resql = $this->db->query($sql);
284 if (!$resql) {
285 $this->errno = -18;
286 dol_syslog("RemiseCheque::Create Error update bank ".$this->errno, LOG_ERR);
287 }
288 }
289 }
290 }
291
292 if ($this->id > 0 && $this->errno == 0) {
293 if ($this->updateAmount() != 0) {
294 $this->errno = -1027;
295 dol_syslog("RemiseCheque::Create Error update amount ".$this->errno, LOG_ERR);
296 }
297 }
298 } else {
299 $this->errno = -1;
300 $this->error = $this->db->lasterror();
301 // $this->errno = $this->db->lasterrno();
302 }
303
304 if (!$this->errno && (getDolGlobalString('MAIN_DISABLEDRAFTSTATUS') || getDolGlobalString('MAIN_DISABLEDRAFTSTATUS_CHEQUE'))) {
305 $res = $this->validate($user);
306 //if ($res < 0) $error++;
307 }
308
309 if (!$this->errno) {
310 $this->db->commit();
311 dol_syslog("RemiseCheque::Create end", LOG_DEBUG);
312 return $this->id;
313 } else {
314 $this->db->rollback();
315 dol_syslog("RemiseCheque::Create end", LOG_DEBUG);
316 return $this->errno;
317 }
318 }
319
326 public function delete($user)
327 {
328 global $conf;
329
330 $this->errno = 0;
331
332 $this->db->begin();
333
334 $sql = "DELETE FROM ".MAIN_DB_PREFIX."bordereau_cheque";
335 $sql .= " WHERE rowid = ".((int) $this->id);
336 $sql .= " AND entity = ".$conf->entity;
337
338 $resql = $this->db->query($sql);
339 if ($resql) {
340 $num = $this->db->affected_rows($resql);
341
342 if ($num != 1) {
343 $this->errno = -2;
344 dol_syslog("Remisecheque::Delete Erreur Lecture ID ($this->errno)");
345 }
346
347 if ($this->errno === 0) {
348 $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
349 $sql .= " SET fk_bordereau = 0";
350 $sql .= " WHERE fk_bordereau = ".((int) $this->id);
351
352 $resql = $this->db->query($sql);
353 if (!$resql) {
354 $this->errno = -1028;
355 dol_syslog("RemiseCheque::Delete ERREUR UPDATE ($this->errno)");
356 }
357 }
358 }
359
360 if ($this->errno === 0) {
361 $this->db->commit();
362 } else {
363 $this->db->rollback();
364 dol_syslog("RemiseCheque::Delete ROLLBACK ($this->errno)");
365 }
366
367 return $this->errno;
368 }
369
376 public function validate($user)
377 {
378 global $conf;
379
380 $this->errno = 0;
381
382 $this->db->begin();
383
384 $numref = $this->getNextNumRef();
385
386 if ($this->errno == 0 && $numref) {
387 $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
388 $sql .= " SET statut = 1, ref = '".$this->db->escape($numref)."'";
389 $sql .= " WHERE rowid = ".((int) $this->id);
390 $sql .= " AND entity = ".((int) $conf->entity);
391 $sql .= " AND statut = 0";
392
393 dol_syslog("RemiseCheque::Validate", LOG_DEBUG);
394 $resql = $this->db->query($sql);
395 if ($resql) {
396 $num = $this->db->affected_rows($resql);
397
398 if ($num == 1) {
399 $this->ref = $numref;
400 $this->statut = 1;
401 $this->status = 1;
402 } else {
403 $this->errno = -1029;
404 dol_syslog("Remisecheque::validate Error ".$this->errno, LOG_ERR);
405 }
406 } else {
407 $this->errno = -1033;
408 $this->error = $this->db->lasterror();
409 dol_syslog("Remisecheque::validate Error ".$this->errno, LOG_ERR);
410 }
411 }
412
413 // Commit/Rollback
414 if ($this->errno == 0) {
415 $this->db->commit();
416 return 1;
417 } else {
418 $this->db->rollback();
419 dol_syslog("RemiseCheque::Validate ".$this->errno, LOG_ERR);
420 return $this->errno;
421 }
422 }
423
431 public function getNextNumRef($mode = 'next')
432 {
433 global $conf, $db, $langs, $mysoc;
434 $langs->load("bills");
435
436 // Clean parameters (if not defined or using deprecated value)
437 if (!getDolGlobalString('CHEQUERECEIPTS_ADDON')) {
438 $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_mint';
439 } elseif (getDolGlobalString('CHEQUERECEIPTS_ADDON') == 'thyme') {
440 $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_thyme';
441 } elseif (getDolGlobalString('CHEQUERECEIPTS_ADDON') == 'mint') {
442 $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_mint';
443 }
444
445 if (getDolGlobalString('CHEQUERECEIPTS_ADDON')) {
446 $mybool = false;
447
448 $file = getDolGlobalString('CHEQUERECEIPTS_ADDON') . ".php";
449 $classname = getDolGlobalString('CHEQUERECEIPTS_ADDON');
450
451 // Include file with class
452 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
453
454 foreach ($dirmodels as $reldir) {
455 $dir = dol_buildpath($reldir."core/modules/cheque/");
456
457 // Load file with numbering class (if found)
458 if (is_file($dir.$file) && is_readable($dir.$file)) {
459 $mybool = (include_once $dir.$file) || $mybool;
460 }
461 }
462
463 // For compatibility
464 if (!$mybool) {
465 $file = getDolGlobalString('CHEQUERECEIPTS_ADDON') . ".php";
466 $classname = "mod_chequereceipt_" . getDolGlobalString('CHEQUERECEIPTS_ADDON');
467 $classname = preg_replace('/\-.*$/', '', $classname);
468 // Include file with class
469 foreach ($conf->file->dol_document_root as $dirroot) {
470 $dir = $dirroot."/core/modules/cheque/";
471
472 // Load file with numbering class (if found)
473 if (is_file($dir.$file) && is_readable($dir.$file)) {
474 $mybool = (include_once $dir.$file) || $mybool;
475 }
476 }
477 }
478
479 if (!$mybool) {
480 dol_print_error(null, "Failed to include file ".$file);
481 return '';
482 }
483
484 $obj = new $classname();
485 '@phan-var-force ModeleNumRefChequeReceipts $obj';
486
487 $numref = "";
488 $numref = $obj->getNextValue($mysoc, $this);
489
494 if ($mode != 'last' && !$numref) {
495 dol_print_error($db, "ChequeReceipts::getNextValue ".$obj->error);
496 return "";
497 }
498
499 return $numref;
500 } else {
501 $langs->load("errors");
502 print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Bank"));
503 return "";
504 }
505 }
506
507
508 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
516 public function load_board($user, $type = 'CHQ')
517 {
518 // phpcs:enable
519 global $conf, $langs;
520
521 if ($user->socid) {
522 return -1; // protection pour eviter appel par utilisateur externe
523 }
524
525 $sql = "SELECT b.rowid, b.datev as datefin";
526 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
527 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
528 $sql .= " WHERE b.fk_account = ba.rowid";
529 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
530 $sql .= " AND b.fk_type = '".$this->db->escape($type)."'";
531 $sql .= " AND b.fk_bordereau = 0";
532 $sql .= " AND b.amount > 0";
533
534 $resql = $this->db->query($sql);
535 if ($resql) {
536 $langs->load("banks");
537 $now = dol_now();
538
539 $response = new WorkboardResponse();
540 $response->warning_delay = $conf->bank->cheque->warning_delay / 60 / 60 / 24;
541 $response->label = $langs->trans("BankChecksToReceipt");
542 $response->labelShort = $langs->trans("BankChecksToReceiptShort");
543 $response->url = DOL_URL_ROOT.'/compta/paiement/cheque/index.php?leftmenu=checks&amp;mainmenu=bank';
544 $response->img = img_object('', "payment");
545
546 while ($obj = $this->db->fetch_object($resql)) {
547 $response->nbtodo++;
548
549 if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->cheque->warning_delay)) {
550 $response->nbtodolate++;
551 }
552 }
553
554 return $response;
555 } else {
556 dol_print_error($this->db);
557 $this->error = $this->db->error();
558 return -1;
559 }
560 }
561
562
569 public function loadStateBoard($type = 'CHQ')
570 {
571 global $user;
572
573 if ($user->socid) {
574 return -1; // protection pour eviter appel par utilisateur externe
575 }
576
577 $sql = "SELECT count(b.rowid) as nb";
578 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
579 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
580 $sql .= " WHERE b.fk_account = ba.rowid";
581 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
582 $sql .= " AND b.fk_type = '".$this->db->escape($type)."'";
583 $sql .= " AND b.amount > 0";
584
585 $resql = $this->db->query($sql);
586 if ($resql) {
587 while ($obj = $this->db->fetch_object($resql)) {
588 $this->nb["cheques"] = $obj->nb;
589 }
590 $this->db->free($resql);
591 return 1;
592 } else {
593 dol_print_error($this->db);
594 $this->error = $this->db->error();
595 return -1;
596 }
597 }
598
599
607 public function generatePdf($model, $outputlangs)
608 {
609 global $langs, $conf;
610
611 if (empty($model)) {
612 $model = 'blochet';
613 }
614
615 dol_syslog("RemiseCheque::generatePdf model=".$model." id=".$this->id, LOG_DEBUG);
616
617 $dir = DOL_DOCUMENT_ROOT."/core/modules/cheque/doc/";
618
619 // Charge le modele
620 $file = "pdf_".$model.".class.php";
621 if (file_exists($dir.$file)) {
622 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
623 include_once $dir.$file;
624
625 $classname = 'BordereauCheque'.ucfirst($model);
626 $docmodel = new $classname($this->db);
627 '@phan-var-force ModeleChequeReceipts $docmodel';
628
629 $sql = "SELECT b.banque, b.emetteur, b.amount, b.num_chq";
630 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
631 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
632 $sql .= ", ".MAIN_DB_PREFIX."bordereau_cheque as bc";
633 $sql .= " WHERE b.fk_account = ba.rowid";
634 $sql .= " AND b.fk_bordereau = bc.rowid";
635 $sql .= " AND bc.rowid = ".((int) $this->id);
636 $sql .= " AND bc.entity = ".$conf->entity;
637 $sql .= " ORDER BY b.dateo ASC, b.rowid ASC";
638
639 dol_syslog("RemiseCheque::generatePdf", LOG_DEBUG);
640 $result = $this->db->query($sql);
641 if ($result) {
642 $i = 0;
643 while ($objp = $this->db->fetch_object($result)) {
644 $docmodel->lines[$i] = new stdClass();
645 $docmodel->lines[$i]->bank_chq = $objp->banque;
646 $docmodel->lines[$i]->emetteur_chq = $objp->emetteur;
647 $docmodel->lines[$i]->amount_chq = $objp->amount;
648 $docmodel->lines[$i]->num_chq = $objp->num_chq;
649 $i++;
650 }
651 }
652 $docmodel->nbcheque = $this->nbcheque;
653 $docmodel->ref = $this->ref;
654 $docmodel->amount = $this->amount;
655 $docmodel->date = $this->date_bordereau;
656
657 $account = new Account($this->db);
658 $account->fetch($this->account_id);
659
660 $docmodel->account = &$account;
661
662 // We save charset_output to restore it because write_file can change it if needed for
663 // output format that does not support UTF8.
664 $sav_charset_output = $outputlangs->charset_output;
665
666 $result = $docmodel->write_file($this, $conf->bank->dir_output.'/checkdeposits', $this->ref, $outputlangs);
667 if ($result > 0) {
668 //$outputlangs->charset_output=$sav_charset_output;
669 return 1;
670 } else {
671 //$outputlangs->charset_output=$sav_charset_output;
672 dol_syslog("Error");
673 dol_print_error($this->db, $docmodel->error);
674 return 0;
675 }
676 } else {
677 $this->error = $langs->trans("ErrorFileDoesNotExists", $dir.$file);
678 return -1;
679 }
680 }
681
687 public function updateAmount()
688 {
689 global $conf;
690
691 $this->errno = 0;
692
693 $this->db->begin();
694 $total = 0;
695 $nb = 0;
696 $sql = "SELECT amount ";
697 $sql .= " FROM ".MAIN_DB_PREFIX."bank";
698 $sql .= " WHERE fk_bordereau = ".((int) $this->id);
699
700 $resql = $this->db->query($sql);
701 if ($resql) {
702 while ($row = $this->db->fetch_row($resql)) {
703 $total += $row[0];
704 $nb++;
705 }
706
707 $this->db->free($resql);
708
709 $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
710 $sql .= " SET amount = ".price2num($total);
711 $sql .= ", nbcheque = ".((int) $nb);
712 $sql .= " WHERE rowid = ".((int) $this->id);
713 $sql .= " AND entity = ".((int) $conf->entity);
714
715 $resql = $this->db->query($sql);
716 if (!$resql) {
717 $this->errno = -1030;
718 dol_syslog("RemiseCheque::updateAmount ERREUR UPDATE ($this->errno)");
719 }
720 } else {
721 $this->errno = -1031;
722 dol_syslog("RemiseCheque::updateAmount ERREUR SELECT ($this->errno)");
723 }
724
725 if ($this->errno === 0) {
726 $this->db->commit();
727 } else {
728 $this->db->rollback();
729 dol_syslog("RemiseCheque::updateAmount ROLLBACK ($this->errno)");
730 }
731
732 return $this->errno;
733 }
734
741 public function removeCheck($account_id)
742 {
743 $this->errno = 0;
744
745 if ($this->id > 0) {
746 $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
747 $sql .= " SET fk_bordereau = 0";
748 $sql .= " WHERE rowid = ".((int) $account_id);
749 $sql .= " AND fk_bordereau = ".((int) $this->id);
750
751 $resql = $this->db->query($sql);
752 if ($resql) {
753 $this->updateAmount();
754 } else {
755 $this->errno = -1032;
756 dol_syslog("RemiseCheque::removeCheck ERREUR UPDATE ($this->errno)");
757 }
758 }
759 return 0;
760 }
761
770 public function rejectCheck($bank_id, $rejection_date)
771 {
772 global $db, $user;
773
774 $payment = new Paiement($db);
775 $payment->fetch(0, 0, $bank_id);
776
777 $bankline = new AccountLine($db);
778 $bankline->fetch($bank_id);
779
780 /* Reconciliation is allowed because when check is returned, a new line is created onto bank transaction log.
781 if ($bankline->rappro)
782 {
783 $this->error='ActionRefusedLineAlreadyConciliated';
784 return -1;
785 }*/
786
787 $this->db->begin();
788
789 // Not reconciled, we can delete it
790 //$bankline->delete($user); // We delete
791
792 $bankaccount = $payment->fk_account;
793
794 // Get invoices list to reopen them
795 $sql = 'SELECT pf.fk_facture, pf.amount';
796 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
797 $sql .= ' WHERE pf.fk_paiement = '.((int) $payment->id);
798
799 $resql = $this->db->query($sql);
800 if ($resql) {
801 $rejectedPayment = new Paiement($this->db);
802 $rejectedPayment->amounts = array();
803 $rejectedPayment->datepaye = $rejection_date;
804 $rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement', 'code', 'id', 1);
805 $rejectedPayment->num_payment = $payment->num_payment;
806
807 while ($obj = $this->db->fetch_object($resql)) {
808 $invoice = new Facture($this->db);
809 $invoice->fetch($obj->fk_facture);
810 $invoice->setUnpaid($user);
811
812 $rejectedPayment->amounts[$obj->fk_facture] = (float) price2num($obj->amount) * -1;
813 }
814
815 $result = $rejectedPayment->create($user);
816 if ($result > 0) {
817 // We created a negative payment, we also add the line as bank transaction
818 $result = $rejectedPayment->addPaymentToBank($user, 'payment', '(CheckRejected)', $bankaccount, '', '');
819 if ($result > 0) {
820 $result = $payment->reject();
821 if ($result > 0) {
822 $this->db->commit();
823 return $rejectedPayment->id;
824 } else {
825 $this->db->rollback();
826 return -1;
827 }
828 } else {
829 $this->error = $rejectedPayment->error;
830 $this->errors = $rejectedPayment->errors;
831 $this->db->rollback();
832 return -1;
833 }
834 } else {
835 $this->error = $rejectedPayment->error;
836 $this->errors = $rejectedPayment->errors;
837 $this->db->rollback();
838 return -1;
839 }
840 } else {
841 $this->error = $this->db->lasterror();
842 $this->db->rollback();
843 return -1;
844 }
845 }
846
847 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
855 public function set_date($user, $date)
856 {
857 // phpcs:enable
858 if ($user->hasRight('banque', 'cheque')) {
859 $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
860 $sql .= " SET date_bordereau = ".($date ? "'".$this->db->idate($date)."'" : 'null');
861 $sql .= " WHERE rowid = ".((int) $this->id);
862
863 dol_syslog("RemiseCheque::set_date", LOG_DEBUG);
864 $resql = $this->db->query($sql);
865 if ($resql) {
866 $this->date_bordereau = $date;
867 return 1;
868 } else {
869 $this->error = $this->db->error();
870 return -1;
871 }
872 } else {
873 return -2;
874 }
875 }
876
877 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
885 public function set_number($user, $ref)
886 {
887 // phpcs:enable
888 if ($user->hasRight('banque', 'cheque')) {
889 $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
890 $sql .= " SET ref = '".$this->db->escape($ref)."'";
891 $sql .= " WHERE rowid = ".((int) $this->id);
892
893 dol_syslog("RemiseCheque::set_number", LOG_DEBUG);
894 $resql = $this->db->query($sql);
895 if ($resql) {
896 return 1;
897 } else {
898 $this->error = $this->db->error();
899 return -1;
900 }
901 } else {
902 return -2;
903 }
904 }
905
914 public function initAsSpecimen($option = '')
915 {
916 global $user, $langs, $conf;
917
918 $now = dol_now();
919 $arraynow = dol_getdate($now);
920 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
921
922 // Initialize parameters
923 $this->id = 0;
924 $this->ref = 'SPECIMEN';
925 $this->specimen = 1;
926 $this->date_bordereau = $nownotime;
927
928 return 1;
929 }
930
941 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
942 {
943 global $conf, $langs;
944
945 $result = '';
946
947 $label = '<u>'.$langs->trans("ShowCheckReceipt").'</u>';
948 $label .= '<br>';
949 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
950
951 $url = DOL_URL_ROOT.'/compta/paiement/cheque/card.php?id='.$this->id;
952
953 if ($option != 'nolink') {
954 // Add param to save lastsearch_values or not
955 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
956 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
957 $add_save_lastsearch_values = 1;
958 }
959 if ($add_save_lastsearch_values) {
960 $url .= '&save_lastsearch_values=1';
961 }
962 }
963
964 $linkclose = '';
965 if (empty($notooltip)) {
966 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
967 $label = $langs->trans("ShowCheckReceipt");
968 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
969 }
970 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
971 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
972 } else {
973 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
974 }
975
976 $linkstart = '<a href="'.$url.'"';
977 $linkstart .= $linkclose.'>';
978 $linkend = '</a>';
979
980 $result .= $linkstart;
981 if ($withpicto) {
982 $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);
983 }
984 if ($withpicto != 2) {
985 $result .= $this->ref;
986 }
987 $result .= $linkend;
988
989 return $result;
990 }
991
998 public function getLibStatut($mode = 0)
999 {
1000 return $this->LibStatut($this->statut, $mode);
1001 }
1002
1003 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1011 public function LibStatut($status, $mode = 0)
1012 {
1013 // phpcs:enable
1014 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1015 global $langs;
1016 $langs->load('compta');
1017 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('ToValidate');
1018 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
1019 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('ToValidate');
1020 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
1021 }
1022
1023 $statusType = 'status'.$status;
1024 if ($status == self::STATUS_VALIDATED) {
1025 $statusType = 'status4';
1026 }
1027
1028 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
1029 }
1030
1038 public function getKanbanView($option = '', $arraydata = null)
1039 {
1040 global $langs;
1041
1042 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1043
1044 $return = '<div class="box-flex-item box-flex-grow-zero">';
1045 $return .= '<div class="info-box info-box-sm">';
1046 $return .= '<span class="info-box-icon bg-infobox-action">';
1047 $return .= img_picto('', $this->picto);
1048 $return .= '</span>';
1049 $return .= '<div class="info-box-content">';
1050 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1051 if ($selected >= 0) {
1052 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1053 }
1054 if (property_exists($this, 'date_bordereau')) {
1055 $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>';
1056 }
1057 if (property_exists($this, 'nbcheque')) {
1058 $return .= '<br><span class="opacitymedium">'.$langs->trans("Cheque", '', '', '', '', 5).'</span> : <span class="info-box-label">'.$this->nbcheque.'</span>';
1059 }
1060 if (property_exists($this, 'account_id')) {
1061 $return .= ' | <span class="info-box-label">'.$this->account_id.'</span>';
1062 }
1063 if (method_exists($this, 'LibStatut')) {
1064 $return .= '<br><div style="display:inline-block" class="info-box-status margintoponly">'.$this->getLibStatut(3).'</div>';
1065 }
1066 if (property_exists($this, 'amount')) {
1067 $return .= ' | <div style="display:inline-block"><span class="opacitymedium">'.$langs->trans("Amount").'</span> : <span class="amount">'.price($this->amount).'</div>';
1068 }
1069 $return .= '</div>';
1070 $return .= '</div>';
1071 $return .= '</div>';
1072 return $return;
1073 }
1074}
$object ref
Definition info.php:89
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 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 ...
fetch($id, $ref='')
Load record.
loadStateBoard($type='CHQ')
Load indicators this->nb for the state board.
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.
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:171
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
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_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:150