dolibarr 25.0.0-alpha
tva.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2011-2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
5 * Copyright (C) 2018 Philippe Grand <philippe.grand@atoo-net.com>
6 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
8 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2025 Lenin Rivas <lenin.rivas777@gmail.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
30// Put here all includes required by your class file
31require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
32
33
38class Tva extends CommonObject
39{
43 public $element = 'tva';
44
48 public $table_element = 'tva';
49
53 public $picto = 'payment';
54
60 public $total;
61
65 public $datep;
66
70 public $datev;
71
75 public $amount;
76
80 public $type_payment;
81
86 public $num_payment;
87
91 public $datec;
92
96 public $fk_type;
97
101 public $paye;
102
106 public $rappro;
107
111 public $label;
112
116 public $fk_bank;
117
121 public $accountid;
122
126 public $fk_user_creat;
127
131 public $fk_user_modif;
132
136 public $paiementtype;
137
138
139 const STATUS_UNPAID = 0;
140 const STATUS_PAID = 1;
141
147 public function __construct($db)
148 {
149 $this->db = $db;
150 }
151
152
159 public function create($user)
160 {
161 global $conf, $langs;
162
163 $error = 0;
164 $now = dol_now();
165
166 // Clean parameters
167 $this->amount = (float) price2num($this->amount);
168 $this->label = trim($this->label);
169 $this->type_payment = (int) $this->type_payment;
170 $this->note = trim($this->note);
171 $this->fk_account = (int) $this->fk_account;
172 $this->fk_user_creat = (int) $this->fk_user_creat;
173 $this->fk_user_modif = (int) $this->fk_user_modif;
174
175 // Check parameters
176 // Put here code to add control on parameters values
177
178 $this->db->begin();
179
180 // Insert request
181 $sql = "INSERT INTO ".MAIN_DB_PREFIX."tva(";
182 $sql .= "entity,";
183 $sql .= "datec,";
184 $sql .= "datep,";
185 $sql .= "datev,";
186 $sql .= "amount,";
187 $sql .= "label,";
188 $sql .= "note,";
189 $sql .= "fk_account,";
190 $sql .= "fk_typepayment,";
191 $sql .= "fk_user_creat,";
192 $sql .= "fk_user_modif";
193 $sql .= ") VALUES (";
194 $sql .= " ".((int) $conf->entity).", ";
195 $sql .= " '".$this->db->idate($now)."',";
196 $sql .= " '".$this->db->idate($this->datep)."',";
197 $sql .= " '".$this->db->idate($this->datev)."',";
198 $sql .= " '".$this->db->escape((string) $this->amount)."',";
199 $sql .= " '".$this->db->escape($this->label)."',";
200 $sql .= " '".$this->db->escape($this->note)."',";
201 $sql .= " '".$this->db->escape((string) $this->fk_account)."',";
202 $sql .= " '".$this->db->escape((string) $this->type_payment)."',";
203 $sql .= " ".($this->fk_user_creat > 0 ? (int) $this->fk_user_creat : (int) $user->id).",";
204 $sql .= " ".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : (int) $user->id);
205 $sql .= ")";
206
207 dol_syslog(get_class($this)."::create", LOG_DEBUG);
208 $resql = $this->db->query($sql);
209 if ($resql) {
210 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."tva");
211
212 // Call trigger
213 $result = $this->call_trigger('TVA_CREATE', $user);
214 if ($result < 0) {
215 $error++;
216 }
217 // End call triggers
218
219 if (!$error) {
220 $this->db->commit();
221 return $this->id;
222 } else {
223 $this->db->rollback();
224 return -1;
225 }
226 } else {
227 $this->error = "Error ".$this->db->lasterror();
228 $this->db->rollback();
229 return -1;
230 }
231 }
232
240 public function update($user, $notrigger = 0)
241 {
242 global $conf, $langs;
243
244 $error = 0;
245
246 // Clean parameters
247 $this->amount = (float) price2num($this->amount);
248 $this->label = trim($this->label);
249 $this->note = trim($this->note);
250 $this->fk_user_creat = (int) $this->fk_user_creat;
251 $this->fk_user_modif = (int) $this->fk_user_modif;
252
253 // Check parameters
254 // Put here code to add control on parameters values
255
256 $this->db->begin();
257
258 // Update request
259 $sql = "UPDATE ".MAIN_DB_PREFIX."tva SET";
260 if (!empty($this->tms)) {
261 $sql .= " tms='".$this->db->idate($this->tms)."',";
262 }
263 $sql .= " datep = '".$this->db->idate($this->datep)."',";
264 $sql .= " datev = '".$this->db->idate($this->datev)."',";
265 $sql .= " amount = ".(float) price2num($this->amount).",";
266 $sql .= " label = '".$this->db->escape($this->label)."',";
267 $sql .= " note = '".$this->db->escape($this->note)."',";
268 $sql .= " fk_user_creat = ".((int) $this->fk_user_creat).",";
269 $sql .= " fk_user_modif = ".((int) ($this->fk_user_modif > 0 ? ((int) $this->fk_user_modif) : ((int) $user->id)));
270 $sql .= " WHERE rowid=".((int) $this->id);
271
272 dol_syslog(get_class($this)."::update", LOG_DEBUG);
273 $resql = $this->db->query($sql);
274 if (!$resql) {
275 $this->error = "Error ".$this->db->lasterror();
276 $error++;
277 }
278
279 if (!$error && !$notrigger) {
280 // Call trigger
281 $result = $this->call_trigger('TVA_MODIFY', $user);
282 if ($result < 0) {
283 $error++;
284 }
285 // End call triggers
286 }
287
288 if (!$error) {
289 $this->db->commit();
290 return 1;
291 } else {
292 $this->db->rollback();
293 return -1;
294 }
295 }
296
303 public function setPaid($user)
304 {
305 // phpcs:enable
306 $sql = "UPDATE ".MAIN_DB_PREFIX."tva SET";
307 $sql .= " paye = 1";
308 $sql .= " WHERE rowid = ".((int) $this->id);
309 $resql = $this->db->query($sql);
310 if ($resql) {
311 return 1;
312 } else {
313 return -1;
314 }
315 }
316
323 public function setUnpaid($user)
324 {
325 // phpcs:enable
326 $sql = "UPDATE ".MAIN_DB_PREFIX."tva SET";
327 $sql .= " paye = 0";
328 $sql .= " WHERE rowid = ".((int) $this->id);
329 $resql = $this->db->query($sql);
330 if ($resql) {
331 return 1;
332 } else {
333 return -1;
334 }
335 }
336
337
345 public function fetch($id, $ref = '')
346 {
347 $sql = "SELECT";
348 $sql .= " t.rowid,";
349 $sql .= " t.tms,";
350 $sql .= " t.datep,";
351 $sql .= " t.datev,";
352 $sql .= " t.amount,";
353 $sql .= " t.fk_typepayment,";
354 $sql .= " t.num_payment,";
355 $sql .= " t.label,";
356 $sql .= " t.note,";
357 $sql .= " t.paye,";
358 $sql .= " t.fk_user_creat,";
359 $sql .= " t.fk_user_modif,";
360 $sql .= " t.fk_account";
361 $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
362 $sql .= " WHERE t.rowid = ".((int) $id);
363
364 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
365
366 $resql = $this->db->query($sql);
367 if ($resql) {
368 if ($this->db->num_rows($resql)) {
369 $obj = $this->db->fetch_object($resql);
370
371 $this->id = $obj->rowid;
372 $this->ref = $obj->rowid;
373 $this->tms = $this->db->jdate($obj->tms);
374 $this->datep = $this->db->jdate($obj->datep);
375 $this->datev = $this->db->jdate($obj->datev);
376 $this->amount = $obj->amount;
377 $this->type_payment = $obj->fk_typepayment;
378 $this->num_payment = $obj->num_payment;
379 $this->label = $obj->label;
380 $this->paye = $obj->paye;
381 $this->note = $obj->note;
382 $this->fk_user_creat = $obj->fk_user_creat;
383 $this->fk_user_modif = $obj->fk_user_modif;
384 $this->fk_account = $obj->fk_account;
385 $this->fk_type = empty($obj->fk_type) ? "" : $obj->fk_type;
386 $this->rappro = empty($obj->rappro) ? "" : $obj->rappro;
387 }
388 $this->db->free($resql);
389
390 return 1;
391 } else {
392 $this->error = "Error ".$this->db->lasterror();
393 return -1;
394 }
395 }
396
397
398 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
404 public function is_erasable()
405 {
406 // phpcs:enable
407 $totalpaid = $this->getSommePaiement();
408 if ($totalpaid < 0) {
409 return -1;
410 }
411 return (empty($totalpaid) ? 1 : 0);
412 }
413
420 public function delete($user)
421 {
422 global $conf, $langs;
423
424 $error = 0;
425
426 if ($this->is_erasable() <= 0) {
427 $this->error = 'ErrorRecordHasChildren';
428 return -1;
429 }
430
431 // Call trigger
432 $result = $this->call_trigger('TVA_DELETE', $user);
433 if ($result < 0) {
434 return -1;
435 }
436 // End call triggers
437
438 $sql = "DELETE FROM ".MAIN_DB_PREFIX."tva";
439 $sql .= " WHERE rowid=".((int) $this->id);
440
441 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
442 $resql = $this->db->query($sql);
443 if (!$resql) {
444 $this->error = "Error ".$this->db->lasterror();
445 return -1;
446 }
447
448
449 return 1;
450 }
451
452
460 public function initAsSpecimen()
461 {
462 $this->id = 0;
463
464 $this->tms = dol_now();
465 $this->datep = dol_now();
466 $this->datev = dol_now();
467 $this->amount = 100.0;
468 $this->label = '';
469 $this->note = '';
470 $this->fk_bank = 0;
471 $this->fk_user_creat = 0;
472 $this->fk_user_modif = 0;
473
474 return 1;
475 }
476
477
484 public function solde($year = 0)
485 {
486 $reglee = $this->tva_sum_reglee($year);
487
488 $payee = $this->tva_sum_payee($year);
489 $collectee = $this->tva_sum_collectee($year);
490
491 $solde = $reglee - ($collectee - $payee);
492
493 return $solde;
494 }
495
496 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
503 public function tva_sum_collectee($year = 0)
504 {
505 // phpcs:enable
506
507 $sql = "SELECT sum(f.total_tva) as amount";
508 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f WHERE f.paye = 1";
509 if ($year) {
510 $sql .= " AND f.datef >= '".((int) $year)."-01-01' AND f.datef <= '".((int) $year)."-12-31' ";
511 }
512
513 $result = $this->db->query($sql);
514 if ($result) {
515 if ($this->db->num_rows($result)) {
516 $obj = $this->db->fetch_object($result);
517 $ret = $obj->amount;
518 $this->db->free($result);
519 return $ret;
520 } else {
521 $this->db->free($result);
522 return 0;
523 }
524 } else {
525 print $this->db->lasterror();
526 return -1;
527 }
528 }
529
530 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
537 public function tva_sum_payee($year = 0)
538 {
539 // phpcs:enable
540
541 $sql = "SELECT sum(f.total_tva) as total_tva";
542 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
543 if ($year) {
544 $sql .= " WHERE f.datef >= '".((int) $year)."-01-01' AND f.datef <= '".((int) $year)."-12-31' ";
545 }
546
547 $result = $this->db->query($sql);
548 if ($result) {
549 if ($this->db->num_rows($result)) {
550 $obj = $this->db->fetch_object($result);
551 $ret = $obj->total_tva;
552 $this->db->free($result);
553 return $ret;
554 } else {
555 $this->db->free($result);
556 return 0;
557 }
558 } else {
559 print $this->db->lasterror();
560 return -1;
561 }
562 }
563
564
565 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
572 public function tva_sum_reglee($year = 0)
573 {
574 // phpcs:enable
575
576 $sql = "SELECT sum(f.amount) as amount";
577 $sql .= " FROM ".MAIN_DB_PREFIX."tva as f";
578
579 if ($year) {
580 $sql .= " WHERE f.datev >= '".((int) $year)."-01-01' AND f.datev <= '".((int) $year)."-12-31' ";
581 }
582
583 $result = $this->db->query($sql);
584 if ($result) {
585 if ($this->db->num_rows($result)) {
586 $obj = $this->db->fetch_object($result);
587 $ret = $obj->amount;
588 $this->db->free($result);
589 return $ret;
590 } else {
591 $this->db->free($result);
592 return 0;
593 }
594 } else {
595 print $this->db->lasterror();
596 return -1;
597 }
598 }
599
600
607 public function addPayment($user)
608 {
609 global $conf, $langs;
610
611 $this->db->begin();
612
613 // Clean parameters
614 $this->amount = (float) price2num($this->amount);
615 $this->label = trim($this->label);
616 $this->note = trim($this->note);
617 $this->num_payment = trim($this->num_payment);
618 $this->fk_bank = (int) $this->fk_bank;
619 $this->fk_user_creat = (int) $this->fk_user_creat;
620 $this->fk_user_modif = (int) $this->fk_user_modif;
621 if (empty($this->datec)) {
622 $this->datec = dol_now();
623 }
624
625 // Check parameters
626 if (!$this->label) {
627 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
628 return -3;
629 }
630 if ($this->amount == '') {
631 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
632 return -4;
633 }
634 if (isModEnabled("bank") && (empty($this->accountid) || $this->accountid <= 0)) {
635 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("BankAccount"));
636 return -5;
637 }
638 if (isModEnabled("bank") && (empty($this->type_payment) || $this->type_payment <= 0)) {
639 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
640 return -5;
641 }
642
643 // Insert into llx_tva
644 $sql = "INSERT INTO ".MAIN_DB_PREFIX."tva (";
645 $sql .= "datec";
646 $sql .= ", datep";
647 $sql .= ", datev";
648 $sql .= ", amount";
649 $sql .= ", fk_typepayment";
650 $sql .= ", num_payment";
651 if ($this->note) {
652 $sql .= ", note";
653 }
654 if ($this->label) {
655 $sql .= ", label";
656 }
657 $sql .= ", fk_user_creat";
658 $sql .= ", fk_bank";
659 $sql .= ", entity";
660 $sql .= ") ";
661 $sql .= " VALUES (";
662 $sql .= " '".$this->db->idate($this->datec)."'";
663 $sql .= ", '".$this->db->idate($this->datep)."'";
664 $sql .= ", '".$this->db->idate($this->datev)."'";
665 $sql .= ", ".((float) $this->amount);
666 $sql .= ", '".$this->db->escape((string) $this->type_payment)."'";
667 $sql .= ", '".$this->db->escape($this->num_payment)."'";
668 if ($this->note) {
669 $sql .= ", '".$this->db->escape($this->note)."'";
670 }
671 if ($this->label) {
672 $sql .= ", '".$this->db->escape($this->label)."'";
673 }
674 $sql .= ", '".$this->db->escape((string) $user->id)."'";
675 $sql .= ", NULL";
676 $sql .= ", ".((int) $conf->entity);
677 $sql .= ")";
678
679 dol_syslog(get_class($this)."::addPayment", LOG_DEBUG);
680 $result = $this->db->query($sql);
681 if ($result) {
682 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."tva"); // TODO should be called 'payment_vat'
683
684 // Call trigger
685 //XXX: Should be done just before commit no ?
686 $result = $this->call_trigger('TVA_ADDPAYMENT', $user);
687 if ($result < 0) {
688 $this->id = 0;
689 $ok = 0;
690 }
691 // End call triggers
692
693 if ($this->id > 0) {
694 $ok = 1;
695 if (isModEnabled("bank") && !empty($this->amount)) {
696 // Insert into llx_bank
697 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
698
699 $acc = new Account($this->db);
700 $result = $acc->fetch($this->accountid);
701 if ($result <= 0) {
702 dol_print_error($this->db);
703 }
704
705 if ($this->amount > 0) {
706 $bank_line_id = $acc->addline($this->datep, (string) $this->type_payment, $this->label, -abs((float) $this->amount), $this->num_payment, 0, $user);
707 } else {
708 $bank_line_id = $acc->addline($this->datep, (string) $this->type_payment, $this->label, abs((float) $this->amount), $this->num_payment, 0, $user);
709 }
710
711 // Update fk_bank into llx_tva. So we know vat line used to generate bank transaction
712 if ($bank_line_id > 0) {
713 $this->update_fk_bank($bank_line_id);
714 } else {
715 $this->error = $acc->error;
716 $ok = 0;
717 }
718
719 // Update links
720 $result = $acc->add_url_line($bank_line_id, $this->id, DOL_URL_ROOT.'/compta/tva/card.php?id=', "(VATPayment)", "payment_vat");
721 if ($result < 0) {
722 $this->error = $acc->error;
723 $ok = 0;
724 }
725 }
726
727 if ($ok) {
728 $this->db->commit();
729 return $this->id;
730 } else {
731 $this->db->rollback();
732 return -3;
733 }
734 } else {
735 $this->db->rollback();
736 return -2;
737 }
738 } else {
739 $this->error = $this->db->error();
740 $this->db->rollback();
741 return -1;
742 }
743 }
744
745 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
752 public function update_fk_bank($id_bank)
753 {
754 // phpcs:enable
755 $sql = 'UPDATE '.MAIN_DB_PREFIX.'tva SET fk_bank = '.(int) $id_bank;
756 $sql .= ' WHERE rowid = '.(int) $this->id;
757 $result = $this->db->query($sql);
758 if ($result) {
759 return 1;
760 } else {
761 dol_print_error($this->db);
762 return -1;
763 }
764 }
765
776 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
777 {
778 global $langs, $conf;
779
780 if (!empty($conf->dol_no_mouse_hover)) {
781 $notooltip = 1; // Force disable tooltips
782 }
783
784 $result = '';
785
786 $label = '<u>'.$langs->trans("ShowVatPayment").'</u>';
787 $label .= '<br>';
788 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
789 if (!empty($this->label)) {
790 $label .= '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
791 }
792
793 $url = DOL_URL_ROOT.'/compta/tva/card.php?id='.$this->id;
794
795 if ($option != 'nolink') {
796 // Add param to save lastsearch_values or not
797 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
798 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
799 $add_save_lastsearch_values = 1;
800 }
801 if ($add_save_lastsearch_values) {
802 $url .= '&save_lastsearch_values=1';
803 }
804 }
805
806 $linkclose = '';
807 if (empty($notooltip)) {
808 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
809 $label = $langs->trans("ShowMyObject");
810 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
811 }
812 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
813 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
814 } else {
815 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
816 }
817
818 $linkstart = '<a href="'.$url.'"';
819 $linkstart .= $linkclose.'>';
820 $linkend = '</a>';
821
822 $picto = 'payment';
823
824 $result .= $linkstart;
825 if ($withpicto) {
826 $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);
827 }
828 if ($withpicto != 2) {
829 $result .= $this->ref;
830 }
831 $result .= $linkend;
832
833 global $action, $hookmanager;
834 $hookmanager->initHooks(array($this->element . 'dao'));
835 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
836 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
837 if ($reshook > 0) {
838 $result = $hookmanager->resPrint;
839 } else {
840 $result .= $hookmanager->resPrint;
841 }
842
843 return $result;
844 }
845
851 public function getSommePaiement()
852 {
853 $sql = 'SELECT sum(amount) as amount';
854 $sql .= ' FROM '.MAIN_DB_PREFIX."payment_vat";
855 $sql .= " WHERE fk_tva = ".((int) $this->id);
856
857 dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG);
858 $resql = $this->db->query($sql);
859 if ($resql) {
860 $amount = 0;
861
862 $obj = $this->db->fetch_object($resql);
863 if ($obj) {
864 $amount = $obj->amount ? $obj->amount : 0;
865 }
866
867 $this->db->free($resql);
868 return $amount;
869 } else {
870 return -1;
871 }
872 }
873
880 public function info($id)
881 {
882 $sql = "SELECT t.rowid, t.tms, t.fk_user_modif, t.datec, t.fk_user_creat";
883 $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
884 $sql .= " WHERE t.rowid = ".(int) $id;
885
886 dol_syslog(get_class($this)."::info", LOG_DEBUG);
887 $result = $this->db->query($sql);
888 if ($result) {
889 if ($this->db->num_rows($result)) {
890 $obj = $this->db->fetch_object($result);
891
892 $this->id = $obj->rowid;
893
894 $this->user_creation_id = $obj->fk_user_creat;
895 $this->user_modification_id = $obj->fk_user_modif;
896 $this->date_creation = $this->db->jdate($obj->datec);
897 $this->date_modification = $this->db->jdate($obj->tms);
898 }
899
900 $this->db->free($result);
901 } else {
902 dol_print_error($this->db);
903 }
904 }
905
913 public function getLibStatut($mode = 0, $alreadypaid = -1)
914 {
915 return $this->LibStatut($this->paye, $mode, $alreadypaid);
916 }
917
918 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
927 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
928 {
929 // phpcs:enable
930 global $langs;
931
932 // Load translation files required by the page
933 $langs->loadLangs(array("customers", "bills"));
934
935 // We reinit status array to force to redefine them because label may change according to properties values.
936 $this->labelStatus = array();
937 $this->labelStatusShort = array();
938
939 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
940 global $langs;
941 //$langs->load("mymodule");
942 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
943 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
944 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
945 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
946 }
947 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
948 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
949 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
950 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
951 }
952 }
953
954 $statusType = 'status1';
955 if ($status == 0 && $alreadypaid != 0) {
956 $statusType = 'status3';
957 }
958 if ($status == 1) {
959 $statusType = 'status6';
960 }
961
962 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
963 }
964
972 public function getKanbanView($option = '', $arraydata = null)
973 {
974 global $langs;
975
976 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
977
978 $return = '<div class="box-flex-item box-flex-grow-zero">';
979 $return .= '<div class="info-box info-box-sm">';
980 $return .= '<span class="info-box-icon bg-infobox-action">';
981 $return .= img_picto('', $this->picto);
982 //$return .= '<i class="fa fa-dol-action"></i>'; // Can be image
983 $return .= '</span>';
984 $return .= '<div class="info-box-content">';
985 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</span>';
986 if ($selected >= 0) {
987 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
988 }
989 if (property_exists($this, 'amount')) {
990 $return .= ' | <span class="opacitymedium">'.$langs->trans("Amount").'</span> : <span class="info-box-label amount">'.price($this->amount).'</span>';
991 }
992 if (property_exists($this, 'type_payment')) {
993 $return .= '<br><span class="opacitymedium">'.$langs->trans("Payment").'</span> : <span class="info-box-label">'.$this->type_payment.'</span>';
994 }
995 if (property_exists($this, 'datev')) {
996 $return .= '<br><span class="opacitymedium">'.$langs->trans("DateEnd").'</span> : <span class="info-box-label" >'.dol_print_date($this->datev).'</span>';
997 }
998 if (method_exists($this, 'LibStatut')) {
999 $return .= '<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3, (float) $this->totalpaid).'</div>';
1000 }
1001 $return .= '</div>';
1002 $return .= '</div>';
1003 $return .= '</div>';
1004 return $return;
1005 }
1006
1013 public function getIdForLabel($label)
1014 {
1015 $id = 0;
1016 $sql = "SELECT t.rowid";
1017 $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
1018 $sql .= " WHERE t.label = '".$this->db->escape($label)."'";
1019
1020 dol_syslog(get_class($this)."::getIdForLabel", LOG_DEBUG);
1021 $result = $this->db->query($sql);
1022 if ($result) {
1023 if ($this->db->num_rows($result)) {
1024 $obj = $this->db->fetch_object($result);
1025 $id = $obj->rowid;
1026 }
1027 $this->db->free($result);
1028 } else {
1029 dol_print_error($this->db);
1030 }
1031 return $id;
1032 }
1033}
$object ref
Definition info.php:90
Class to manage bank accounts.
Class to manage VAT - Value-added tax (also known in French as TVA)
Definition tva.class.php:39
is_erasable()
Return if a VAT declaration can be deleted: not once a payment exists, as for invoices.
getIdForLabel($label)
Id of vat payment object.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
tva_sum_collectee($year=0)
Total of the VAT from invoices emitted by the thirdparty.
LibStatut($status, $mode=0, $alreadypaid=-1)
Return the label of a given VAT status.
tva_sum_payee($year=0)
VAT paid.
setUnpaid($user)
Remove tag paid on TVA.
__construct($db)
Constructor.
update($user, $notrigger=0)
Update database.
solde($year=0)
Balance of VAT.
getSommePaiement()
Return amount of payments already done.
addPayment($user)
Create in database.
getLibStatut($mode=0, $alreadypaid=-1)
Return the label of the VAT status f object.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Send name clickable (with possibly the picto)
fetch($id, $ref='')
Load object in memory from database.
update_fk_bank($id_bank)
Update link between payment tva and line generate into llx_bank.
setPaid($user)
Tag TVA as paid completely.
initAsSpecimen()
Initialise an instance with random values.
info($id)
Information of vat payment object.
create($user)
Create in database.
tva_sum_reglee($year=0)
Total of the VAT paid.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
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_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.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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