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