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