dolibarr 20.0.2
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
53 public $num;
54 public $intitule;
56 public $errno;
57
58 public $type = 'CHQ'; // 'CHQ', 'TRA', ...
59
60 public $amount;
61 public $date_bordereau;
62 public $account_id;
63 public $account_label;
64 public $author_id;
65 public $nbcheque;
66
70 public $ref;
71
72 const STATUS_DRAFT = 0;
73 const STATUS_VALIDATED = 1;
74
75
81 public function __construct($db)
82 {
83 $this->db = $db;
84 }
85
93 public function fetch($id, $ref = '')
94 {
95 global $conf;
96
97 $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,";
98 $sql .= " bc.date_bordereau as date_bordereau, bc.type,";
99 $sql .= " ba.label as account_label";
100 $sql .= " FROM ".MAIN_DB_PREFIX."bordereau_cheque as bc";
101 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON bc.fk_bank_account = ba.rowid";
102 $sql .= " WHERE bc.entity = ".$conf->entity;
103 if ($id) {
104 $sql .= " AND bc.rowid = ".((int) $id);
105 }
106 if ($ref) {
107 $sql .= " AND bc.ref = '".$this->db->escape($ref)."'";
108 }
109
110 dol_syslog("RemiseCheque::fetch", LOG_DEBUG);
111 $resql = $this->db->query($sql);
112 if ($resql) {
113 if ($obj = $this->db->fetch_object($resql)) {
114 $this->id = $obj->rowid;
115 $this->amount = $obj->amount;
116 $this->date_bordereau = $this->db->jdate($obj->date_bordereau);
117 $this->account_id = $obj->fk_bank_account;
118 $this->account_label = $obj->account_label;
119 $this->author_id = $obj->fk_user_author;
120 $this->nbcheque = $obj->nbcheque;
121 $this->statut = $obj->statut;
122 $this->ref_ext = $obj->ref_ext;
123 $this->type = $obj->type;
124
125 if ($this->statut == 0) {
126 $this->ref = "(PROV".$this->id.")";
127 } else {
128 $this->ref = $obj->ref;
129 }
130 }
131 $this->db->free($resql);
132
133 return 1;
134 } else {
135 $this->error = $this->db->lasterror();
136 return -1;
137 }
138 }
139
149 public function create($user, $account_id, $limit, $toRemise)
150 {
151 global $conf;
152
153 $this->errno = 0;
154 $this->id = 0;
155
156 $now = dol_now();
157
158 dol_syslog("RemiseCheque::Create start", LOG_DEBUG);
159
160 // Clean parameters
161 if (empty($this->type)) {
162 $this->type = 'CHQ';
163 }
164
165 $this->db->begin();
166
167 $sql = "INSERT INTO ".MAIN_DB_PREFIX."bordereau_cheque (";
168 $sql .= "datec";
169 $sql .= ", date_bordereau";
170 $sql .= ", fk_user_author";
171 $sql .= ", fk_bank_account";
172 $sql .= ", statut";
173 $sql .= ", amount";
174 $sql .= ", ref";
175 $sql .= ", entity";
176 $sql .= ", nbcheque";
177 $sql .= ", ref_ext";
178 $sql .= ", type";
179 $sql .= ") VALUES (";
180 $sql .= "'".$this->db->idate($now)."'";
181 $sql .= ", '".$this->db->idate($now)."'";
182 $sql .= ", ".((int) $user->id);
183 $sql .= ", ".((int) $account_id);
184 $sql .= ", 0";
185 $sql .= ", 0";
186 $sql .= ", 0";
187 $sql .= ", ".((int) $conf->entity);
188 $sql .= ", 0";
189 $sql .= ", ''";
190 $sql .= ", '".$this->db->escape($this->type)."'";
191 $sql .= ")";
192
193 $resql = $this->db->query($sql);
194 if ($resql) {
195 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bordereau_cheque");
196 if ($this->id == 0) {
197 $this->errno = -1024;
198 dol_syslog("Remisecheque::Create Error read id ".$this->errno, LOG_ERR);
199 }
200
201 if ($this->id > 0 && $this->errno == 0) {
202 $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
203 $sql .= " SET ref = '(PROV".$this->id.")'";
204 $sql .= " WHERE rowid=".((int) $this->id);
205
206 $resql = $this->db->query($sql);
207 if (!$resql) {
208 $this->errno = -1025;
209 dol_syslog("RemiseCheque::Create Error update ".$this->errno, LOG_ERR);
210 }
211 }
212
213 $lines = array();
214
215 if ($this->id > 0 && $this->errno == 0) {
216 $sql = "SELECT b.rowid";
217 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
218 $sql .= " WHERE b.fk_type = '".$this->db->escape($this->type)."'";
219 $sql .= " AND b.amount > 0";
220 $sql .= " AND b.fk_bordereau = 0";
221 $sql .= " AND b.fk_account = ".((int) $account_id);
222 if ($limit) {
223 $sql .= $this->db->plimit($limit);
224 }
225
226 dol_syslog("RemiseCheque::Create", LOG_DEBUG);
227 $resql = $this->db->query($sql);
228 if ($resql) {
229 while ($row = $this->db->fetch_row($resql)) {
230 array_push($lines, $row[0]);
231 }
232 $this->db->free($resql);
233 } else {
234 $this->errno = -1026;
235 dol_syslog("RemiseCheque::Create Error ".$this->errno, LOG_ERR);
236 }
237 }
238
239 if ($this->id > 0 && $this->errno == 0) {
240 foreach ($lines as $lineid) {
241 $checkremise = false;
242 foreach ($toRemise as $linetoremise) {
243 if ($linetoremise == $lineid) {
244 $checkremise = true;
245 }
246 }
247
248 if ($checkremise) {
249 $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
250 $sql .= " SET fk_bordereau = ".((int) $this->id);
251 $sql .= " WHERE rowid = ".((int) $lineid);
252
253 $resql = $this->db->query($sql);
254 if (!$resql) {
255 $this->errno = -18;
256 dol_syslog("RemiseCheque::Create Error update bank ".$this->errno, LOG_ERR);
257 }
258 }
259 }
260 }
261
262 if ($this->id > 0 && $this->errno == 0) {
263 if ($this->updateAmount() != 0) {
264 $this->errno = -1027;
265 dol_syslog("RemiseCheque::Create Error update amount ".$this->errno, LOG_ERR);
266 }
267 }
268 } else {
269 $this->errno = -1;
270 $this->error = $this->db->lasterror();
271 $this->errno = $this->db->lasterrno();
272 }
273
274 if (!$this->errno && (getDolGlobalString('MAIN_DISABLEDRAFTSTATUS') || getDolGlobalString('MAIN_DISABLEDRAFTSTATUS_CHEQUE'))) {
275 $res = $this->validate($user);
276 //if ($res < 0) $error++;
277 }
278
279 if (!$this->errno) {
280 $this->db->commit();
281 dol_syslog("RemiseCheque::Create end", LOG_DEBUG);
282 return $this->id;
283 } else {
284 $this->db->rollback();
285 dol_syslog("RemiseCheque::Create end", LOG_DEBUG);
286 return $this->errno;
287 }
288 }
289
296 public function delete($user)
297 {
298 global $conf;
299
300 $this->errno = 0;
301
302 $this->db->begin();
303
304 $sql = "DELETE FROM ".MAIN_DB_PREFIX."bordereau_cheque";
305 $sql .= " WHERE rowid = ".((int) $this->id);
306 $sql .= " AND entity = ".$conf->entity;
307
308 $resql = $this->db->query($sql);
309 if ($resql) {
310 $num = $this->db->affected_rows($resql);
311
312 if ($num != 1) {
313 $this->errno = -2;
314 dol_syslog("Remisecheque::Delete Erreur Lecture ID ($this->errno)");
315 }
316
317 if ($this->errno === 0) {
318 $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
319 $sql .= " SET fk_bordereau = 0";
320 $sql .= " WHERE fk_bordereau = ".((int) $this->id);
321
322 $resql = $this->db->query($sql);
323 if (!$resql) {
324 $this->errno = -1028;
325 dol_syslog("RemiseCheque::Delete ERREUR UPDATE ($this->errno)");
326 }
327 }
328 }
329
330 if ($this->errno === 0) {
331 $this->db->commit();
332 } else {
333 $this->db->rollback();
334 dol_syslog("RemiseCheque::Delete ROLLBACK ($this->errno)");
335 }
336
337 return $this->errno;
338 }
339
346 public function validate($user)
347 {
348 global $conf;
349
350 $this->errno = 0;
351
352 $this->db->begin();
353
354 $numref = $this->getNextNumRef();
355
356 if ($this->errno == 0 && $numref) {
357 $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
358 $sql .= " SET statut = 1, ref = '".$this->db->escape($numref)."'";
359 $sql .= " WHERE rowid = ".((int) $this->id);
360 $sql .= " AND entity = ".((int) $conf->entity);
361 $sql .= " AND statut = 0";
362
363 dol_syslog("RemiseCheque::Validate", LOG_DEBUG);
364 $resql = $this->db->query($sql);
365 if ($resql) {
366 $num = $this->db->affected_rows($resql);
367
368 if ($num == 1) {
369 $this->ref = $numref;
370 $this->statut = 1;
371 $this->status = 1;
372 } else {
373 $this->errno = -1029;
374 dol_syslog("Remisecheque::validate Error ".$this->errno, LOG_ERR);
375 }
376 } else {
377 $this->errno = -1033;
378 $this->error = $this->db->lasterror();
379 dol_syslog("Remisecheque::validate Error ".$this->errno, LOG_ERR);
380 }
381 }
382
383 // Commit/Rollback
384 if ($this->errno == 0) {
385 $this->db->commit();
386 return 1;
387 } else {
388 $this->db->rollback();
389 dol_syslog("RemiseCheque::Validate ".$this->errno, LOG_ERR);
390 return $this->errno;
391 }
392 }
393
401 public function getNextNumRef($mode = 'next')
402 {
403 global $conf, $db, $langs, $mysoc;
404 $langs->load("bills");
405
406 // Clean parameters (if not defined or using deprecated value)
407 if (!getDolGlobalString('CHEQUERECEIPTS_ADDON')) {
408 $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_mint';
409 } elseif (getDolGlobalString('CHEQUERECEIPTS_ADDON') == 'thyme') {
410 $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_thyme';
411 } elseif (getDolGlobalString('CHEQUERECEIPTS_ADDON') == 'mint') {
412 $conf->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_mint';
413 }
414
415 if (getDolGlobalString('CHEQUERECEIPTS_ADDON')) {
416 $mybool = false;
417
418 $file = getDolGlobalString('CHEQUERECEIPTS_ADDON') . ".php";
419 $classname = getDolGlobalString('CHEQUERECEIPTS_ADDON');
420
421 // Include file with class
422 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
423
424 foreach ($dirmodels as $reldir) {
425 $dir = dol_buildpath($reldir."core/modules/cheque/");
426
427 // Load file with numbering class (if found)
428 if (is_file($dir.$file) && is_readable($dir.$file)) {
429 $mybool = (include_once $dir.$file) || $mybool;
430 }
431 }
432
433 // For compatibility
434 if (!$mybool) {
435 $file = getDolGlobalString('CHEQUERECEIPTS_ADDON') . ".php";
436 $classname = "mod_chequereceipt_" . getDolGlobalString('CHEQUERECEIPTS_ADDON');
437 $classname = preg_replace('/\-.*$/', '', $classname);
438 // Include file with class
439 foreach ($conf->file->dol_document_root as $dirroot) {
440 $dir = $dirroot."/core/modules/cheque/";
441
442 // Load file with numbering class (if found)
443 if (is_file($dir.$file) && is_readable($dir.$file)) {
444 $mybool = (include_once $dir.$file) || $mybool;
445 }
446 }
447 }
448
449 if (!$mybool) {
450 dol_print_error(null, "Failed to include file ".$file);
451 return '';
452 }
453
454 $obj = new $classname();
455 '@phan-var-force CommonNumRefGenerator $obj';
456 $numref = "";
457 $numref = $obj->getNextValue($mysoc, $this);
458
463 if ($mode != 'last' && !$numref) {
464 dol_print_error($db, "ChequeReceipts::getNextNumRef ".$obj->error);
465 return "";
466 }
467
468 return $numref;
469 } else {
470 $langs->load("errors");
471 print $langs->trans("Error")." ".$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Bank"));
472 return "";
473 }
474 }
475
476
477 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
485 public function load_board($user, $type = 'CHQ')
486 {
487 // phpcs:enable
488 global $conf, $langs;
489
490 if ($user->socid) {
491 return -1; // protection pour eviter appel par utilisateur externe
492 }
493
494 $sql = "SELECT b.rowid, b.datev as datefin";
495 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
496 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
497 $sql .= " WHERE b.fk_account = ba.rowid";
498 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
499 $sql .= " AND b.fk_type = '".$this->db->escape($type)."'";
500 $sql .= " AND b.fk_bordereau = 0";
501 $sql .= " AND b.amount > 0";
502
503 $resql = $this->db->query($sql);
504 if ($resql) {
505 $langs->load("banks");
506 $now = dol_now();
507
508 $response = new WorkboardResponse();
509 $response->warning_delay = $conf->bank->cheque->warning_delay / 60 / 60 / 24;
510 $response->label = $langs->trans("BankChecksToReceipt");
511 $response->labelShort = $langs->trans("BankChecksToReceiptShort");
512 $response->url = DOL_URL_ROOT.'/compta/paiement/cheque/index.php?leftmenu=checks&amp;mainmenu=bank';
513 $response->img = img_object('', "payment");
514
515 while ($obj = $this->db->fetch_object($resql)) {
516 $response->nbtodo++;
517
518 if ($this->db->jdate($obj->datefin) < ($now - $conf->bank->cheque->warning_delay)) {
519 $response->nbtodolate++;
520 }
521 }
522
523 return $response;
524 } else {
525 dol_print_error($this->db);
526 $this->error = $this->db->error();
527 return -1;
528 }
529 }
530
531
538 public function loadStateBoard($type = 'CHQ')
539 {
540 global $user;
541
542 if ($user->socid) {
543 return -1; // protection pour eviter appel par utilisateur externe
544 }
545
546 $sql = "SELECT count(b.rowid) as nb";
547 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
548 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
549 $sql .= " WHERE b.fk_account = ba.rowid";
550 $sql .= " AND ba.entity IN (".getEntity('bank_account').")";
551 $sql .= " AND b.fk_type = '".$this->db->escape($type)."'";
552 $sql .= " AND b.amount > 0";
553
554 $resql = $this->db->query($sql);
555 if ($resql) {
556 while ($obj = $this->db->fetch_object($resql)) {
557 $this->nb["cheques"] = $obj->nb;
558 }
559 $this->db->free($resql);
560 return 1;
561 } else {
562 dol_print_error($this->db);
563 $this->error = $this->db->error();
564 return -1;
565 }
566 }
567
568
576 public function generatePdf($model, $outputlangs)
577 {
578 global $langs, $conf;
579
580 if (empty($model)) {
581 $model = 'blochet';
582 }
583
584 dol_syslog("RemiseCheque::generatePdf model=".$model." id=".$this->id, LOG_DEBUG);
585
586 $dir = DOL_DOCUMENT_ROOT."/core/modules/cheque/doc/";
587
588 // Charge le modele
589 $file = "pdf_".$model.".class.php";
590 if (file_exists($dir.$file)) {
591 include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
592 include_once $dir.$file;
593
594 $classname = 'BordereauCheque'.ucfirst($model);
595 $docmodel = new $classname($this->db);
596 '@phan-var-force CommonDocGenerator $module';
597
598 $sql = "SELECT b.banque, b.emetteur, b.amount, b.num_chq";
599 $sql .= " FROM ".MAIN_DB_PREFIX."bank as b";
600 $sql .= ", ".MAIN_DB_PREFIX."bank_account as ba";
601 $sql .= ", ".MAIN_DB_PREFIX."bordereau_cheque as bc";
602 $sql .= " WHERE b.fk_account = ba.rowid";
603 $sql .= " AND b.fk_bordereau = bc.rowid";
604 $sql .= " AND bc.rowid = ".((int) $this->id);
605 $sql .= " AND bc.entity = ".$conf->entity;
606 $sql .= " ORDER BY b.dateo ASC, b.rowid ASC";
607
608 dol_syslog("RemiseCheque::generatePdf", LOG_DEBUG);
609 $result = $this->db->query($sql);
610 if ($result) {
611 $i = 0;
612 while ($objp = $this->db->fetch_object($result)) {
613 $docmodel->lines[$i] = new stdClass();
614 $docmodel->lines[$i]->bank_chq = $objp->banque;
615 $docmodel->lines[$i]->emetteur_chq = $objp->emetteur;
616 $docmodel->lines[$i]->amount_chq = $objp->amount;
617 $docmodel->lines[$i]->num_chq = $objp->num_chq;
618 $i++;
619 }
620 }
621 $docmodel->nbcheque = $this->nbcheque;
622 $docmodel->ref = $this->ref;
623 $docmodel->amount = $this->amount;
624 $docmodel->date = $this->date_bordereau;
625
626 $account = new Account($this->db);
627 $account->fetch($this->account_id);
628
629 $docmodel->account = &$account;
630
631 // We save charset_output to restore it because write_file can change it if needed for
632 // output format that does not support UTF8.
633 $sav_charset_output = $outputlangs->charset_output;
634
635 $result = $docmodel->write_file($this, $conf->bank->dir_output.'/checkdeposits', $this->ref, $outputlangs);
636 if ($result > 0) {
637 //$outputlangs->charset_output=$sav_charset_output;
638 return 1;
639 } else {
640 //$outputlangs->charset_output=$sav_charset_output;
641 dol_syslog("Error");
642 dol_print_error($this->db, $docmodel->error);
643 return 0;
644 }
645 } else {
646 $this->error = $langs->trans("ErrorFileDoesNotExists", $dir.$file);
647 return -1;
648 }
649 }
650
656 public function updateAmount()
657 {
658 global $conf;
659
660 $this->errno = 0;
661
662 $this->db->begin();
663 $total = 0;
664 $nb = 0;
665 $sql = "SELECT amount ";
666 $sql .= " FROM ".MAIN_DB_PREFIX."bank";
667 $sql .= " WHERE fk_bordereau = ".((int) $this->id);
668
669 $resql = $this->db->query($sql);
670 if ($resql) {
671 while ($row = $this->db->fetch_row($resql)) {
672 $total += $row[0];
673 $nb++;
674 }
675
676 $this->db->free($resql);
677
678 $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
679 $sql .= " SET amount = ".price2num($total);
680 $sql .= ", nbcheque = ".((int) $nb);
681 $sql .= " WHERE rowid = ".((int) $this->id);
682 $sql .= " AND entity = ".((int) $conf->entity);
683
684 $resql = $this->db->query($sql);
685 if (!$resql) {
686 $this->errno = -1030;
687 dol_syslog("RemiseCheque::updateAmount ERREUR UPDATE ($this->errno)");
688 }
689 } else {
690 $this->errno = -1031;
691 dol_syslog("RemiseCheque::updateAmount ERREUR SELECT ($this->errno)");
692 }
693
694 if ($this->errno === 0) {
695 $this->db->commit();
696 } else {
697 $this->db->rollback();
698 dol_syslog("RemiseCheque::updateAmount ROLLBACK ($this->errno)");
699 }
700
701 return $this->errno;
702 }
703
710 public function removeCheck($account_id)
711 {
712 $this->errno = 0;
713
714 if ($this->id > 0) {
715 $sql = "UPDATE ".MAIN_DB_PREFIX."bank";
716 $sql .= " SET fk_bordereau = 0";
717 $sql .= " WHERE rowid = ".((int) $account_id);
718 $sql .= " AND fk_bordereau = ".((int) $this->id);
719
720 $resql = $this->db->query($sql);
721 if ($resql) {
722 $this->updateAmount();
723 } else {
724 $this->errno = -1032;
725 dol_syslog("RemiseCheque::removeCheck ERREUR UPDATE ($this->errno)");
726 }
727 }
728 return 0;
729 }
730
739 public function rejectCheck($bank_id, $rejection_date)
740 {
741 global $db, $user;
742
743 $payment = new Paiement($db);
744 $payment->fetch(0, 0, $bank_id);
745
746 $bankline = new AccountLine($db);
747 $bankline->fetch($bank_id);
748
749 /* Reconciliation is allowed because when check is returned, a new line is created onto bank transaction log.
750 if ($bankline->rappro)
751 {
752 $this->error='ActionRefusedLineAlreadyConciliated';
753 return -1;
754 }*/
755
756 $this->db->begin();
757
758 // Not reconciled, we can delete it
759 //$bankline->delete($user); // We delete
760
761 $bankaccount = $payment->fk_account;
762
763 // Get invoices list to reopen them
764 $sql = 'SELECT pf.fk_facture, pf.amount';
765 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf';
766 $sql .= ' WHERE pf.fk_paiement = '.((int) $payment->id);
767
768 $resql = $this->db->query($sql);
769 if ($resql) {
770 $rejectedPayment = new Paiement($this->db);
771 $rejectedPayment->amounts = array();
772 $rejectedPayment->datepaye = $rejection_date;
773 $rejectedPayment->paiementid = dol_getIdFromCode($this->db, 'CHQ', 'c_paiement', 'code', 'id', 1);
774 $rejectedPayment->num_payment = $payment->num_payment;
775
776 while ($obj = $this->db->fetch_object($resql)) {
777 $invoice = new Facture($this->db);
778 $invoice->fetch($obj->fk_facture);
779 $invoice->setUnpaid($user);
780
781 $rejectedPayment->amounts[$obj->fk_facture] = price2num($obj->amount) * -1;
782 }
783
784 $result = $rejectedPayment->create($user);
785 if ($result > 0) {
786 // We created a negative payment, we also add the line as bank transaction
787 $result = $rejectedPayment->addPaymentToBank($user, 'payment', '(CheckRejected)', $bankaccount, '', '');
788 if ($result > 0) {
789 $result = $payment->reject();
790 if ($result > 0) {
791 $this->db->commit();
792 return $rejectedPayment->id;
793 } else {
794 $this->db->rollback();
795 return -1;
796 }
797 } else {
798 $this->error = $rejectedPayment->error;
799 $this->errors = $rejectedPayment->errors;
800 $this->db->rollback();
801 return -1;
802 }
803 } else {
804 $this->error = $rejectedPayment->error;
805 $this->errors = $rejectedPayment->errors;
806 $this->db->rollback();
807 return -1;
808 }
809 } else {
810 $this->error = $this->db->lasterror();
811 $this->db->rollback();
812 return -1;
813 }
814 }
815
816 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
824 public function set_date($user, $date)
825 {
826 // phpcs:enable
827 if ($user->hasRight('banque', 'cheque')) {
828 $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
829 $sql .= " SET date_bordereau = ".($date ? "'".$this->db->idate($date)."'" : 'null');
830 $sql .= " WHERE rowid = ".((int) $this->id);
831
832 dol_syslog("RemiseCheque::set_date", LOG_DEBUG);
833 $resql = $this->db->query($sql);
834 if ($resql) {
835 $this->date_bordereau = $date;
836 return 1;
837 } else {
838 $this->error = $this->db->error();
839 return -1;
840 }
841 } else {
842 return -2;
843 }
844 }
845
846 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
854 public function set_number($user, $ref)
855 {
856 // phpcs:enable
857 if ($user->hasRight('banque', 'cheque')) {
858 $sql = "UPDATE ".MAIN_DB_PREFIX."bordereau_cheque";
859 $sql .= " SET ref = '".$this->db->escape($ref)."'";
860 $sql .= " WHERE rowid = ".((int) $this->id);
861
862 dol_syslog("RemiseCheque::set_number", LOG_DEBUG);
863 $resql = $this->db->query($sql);
864 if ($resql) {
865 return 1;
866 } else {
867 $this->error = $this->db->error();
868 return -1;
869 }
870 } else {
871 return -2;
872 }
873 }
874
883 public function initAsSpecimen($option = '')
884 {
885 global $user, $langs, $conf;
886
887 $now = dol_now();
888 $arraynow = dol_getdate($now);
889 $nownotime = dol_mktime(0, 0, 0, $arraynow['mon'], $arraynow['mday'], $arraynow['year']);
890
891 // Initialize parameters
892 $this->id = 0;
893 $this->ref = 'SPECIMEN';
894 $this->specimen = 1;
895 $this->date_bordereau = $nownotime;
896
897 return 1;
898 }
899
910 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
911 {
912 global $conf, $langs;
913
914 $result = '';
915
916 $label = '<u>'.$langs->trans("ShowCheckReceipt").'</u>';
917 $label .= '<br>';
918 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
919
920 $url = DOL_URL_ROOT.'/compta/paiement/cheque/card.php?id='.$this->id;
921
922 if ($option != 'nolink') {
923 // Add param to save lastsearch_values or not
924 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
925 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
926 $add_save_lastsearch_values = 1;
927 }
928 if ($add_save_lastsearch_values) {
929 $url .= '&save_lastsearch_values=1';
930 }
931 }
932
933 $linkclose = '';
934 if (empty($notooltip)) {
935 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
936 $label = $langs->trans("ShowCheckReceipt");
937 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
938 }
939 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
940 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
941 } else {
942 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
943 }
944
945 $linkstart = '<a href="'.$url.'"';
946 $linkstart .= $linkclose.'>';
947 $linkend = '</a>';
948
949 $result .= $linkstart;
950 if ($withpicto) {
951 $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);
952 }
953 if ($withpicto != 2) {
954 $result .= $this->ref;
955 }
956 $result .= $linkend;
957
958 return $result;
959 }
960
967 public function getLibStatut($mode = 0)
968 {
969 return $this->LibStatut($this->statut, $mode);
970 }
971
972 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
980 public function LibStatut($status, $mode = 0)
981 {
982 // phpcs:enable
983 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
984 global $langs;
985 $langs->load('compta');
986 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('ToValidate');
987 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
988 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('ToValidate');
989 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Validated');
990 }
991
992 $statusType = 'status'.$status;
993 if ($status == self::STATUS_VALIDATED) {
994 $statusType = 'status4';
995 }
996
997 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
998 }
999
1007 public function getKanbanView($option = '', $arraydata = null)
1008 {
1009 global $langs;
1010
1011 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
1012
1013 $return = '<div class="box-flex-item box-flex-grow-zero">';
1014 $return .= '<div class="info-box info-box-sm">';
1015 $return .= '<span class="info-box-icon bg-infobox-action">';
1016 $return .= img_picto('', $this->picto);
1017 $return .= '</span>';
1018 $return .= '<div class="info-box-content">';
1019 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).'</span>';
1020 if ($selected >= 0) {
1021 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
1022 }
1023 if (property_exists($this, 'date_bordereau')) {
1024 $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>';
1025 }
1026 if (property_exists($this, 'nbcheque')) {
1027 $return .= '<br><span class="opacitymedium">'.$langs->trans("Cheque", '', '', '', '', 5).'</span> : <span class="info-box-label">'.$this->nbcheque.'</span>';
1028 }
1029 if (property_exists($this, 'account_id')) {
1030 $return .= ' | <span class="info-box-label">'.$this->account_id.'</span>';
1031 }
1032 if (method_exists($this, 'LibStatut')) {
1033 $return .= '<br><div style="display:inline-block" class="info-box-status margintoponly">'.$this->getLibStatut(3).'</div>';
1034 }
1035 if (property_exists($this, 'amount')) {
1036 $return .= ' | <div style="display:inline-block"><span class="opacitymedium">'.$langs->trans("Amount").'</span> : <span class="amount">'.price($this->amount).'</div>';
1037 }
1038 $return .= '</div>';
1039 $return .= '</div>';
1040 $return .= '</div>';
1041 return $return;
1042 }
1043}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:637
$object ref
Definition info.php:79
Class to manage bank accounts.
Class to manage bank transaction lines.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Class to manage invoices.
Class to manage payments of customer invoices.
Class to manage cheque delivery receipts.
removeCheck($account_id)
Insere la remise en base.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return clicable name (with picto eventually)
$errno
Numero d'erreur Plage 1024-1279.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
generatePdf($model, $outputlangs)
Build document.
LibStatut($status, $mode=0)
Return the label of a given status.
__construct($db)
Constructor.
getLibStatut($mode=0)
Return the label of the status.
set_date($user, $date)
Set the creation date.
rejectCheck($bank_id, $rejection_date)
Check return management Reopen linked invoices and create a new negative payment.
validate($user)
Validate a receipt.
set_number($user, $ref)
Set the ref of bordereau.
load_board($user, $type='CHQ')
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
getNextNumRef($mode='next')
Return next reference of cheque receipts not already used (or last reference) according to numbering ...
fetch($id, $ref='')
Load record.
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.
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).
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 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.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:137
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e e e e e statut
Definition invoice.php:2010