dolibarr 24.0.2
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 $sql .= " tms='".$this->db->idate($this->tms)."',";
261 $sql .= " datep='".$this->db->idate($this->datep)."',";
262 $sql .= " datev='".$this->db->idate($this->datev)."',";
263 $sql .= " amount=".price2num($this->amount).",";
264 $sql .= " label='".$this->db->escape($this->label)."',";
265 $sql .= " note='".$this->db->escape($this->note)."',";
266 $sql .= " fk_user_creat=".((int) $this->fk_user_creat).",";
267 $sql .= " fk_user_modif=".((int) ($this->fk_user_modif > 0 ? ((int) $this->fk_user_modif) : ((int) $user->id)));
268 $sql .= " WHERE rowid=".((int) $this->id);
269
270 dol_syslog(get_class($this)."::update", LOG_DEBUG);
271 $resql = $this->db->query($sql);
272 if (!$resql) {
273 $this->error = "Error ".$this->db->lasterror();
274 $error++;
275 }
276
277 if (!$error && !$notrigger) {
278 // Call trigger
279 $result = $this->call_trigger('TVA_MODIFY', $user);
280 if ($result < 0) {
281 $error++;
282 }
283 // End call triggers
284 }
285
286 if (!$error) {
287 $this->db->commit();
288 return 1;
289 } else {
290 $this->db->rollback();
291 return -1;
292 }
293 }
294
301 public function setPaid($user)
302 {
303 // phpcs:enable
304 $sql = "UPDATE ".MAIN_DB_PREFIX."tva SET";
305 $sql .= " paye = 1";
306 $sql .= " WHERE rowid = ".((int) $this->id);
307 $resql = $this->db->query($sql);
308 if ($resql) {
309 return 1;
310 } else {
311 return -1;
312 }
313 }
314
321 public function setUnpaid($user)
322 {
323 // phpcs:enable
324 $sql = "UPDATE ".MAIN_DB_PREFIX."tva SET";
325 $sql .= " paye = 0";
326 $sql .= " WHERE rowid = ".((int) $this->id);
327 $resql = $this->db->query($sql);
328 if ($resql) {
329 return 1;
330 } else {
331 return -1;
332 }
333 }
334
335
343 public function fetch($id, $ref = '')
344 {
345 $sql = "SELECT";
346 $sql .= " t.rowid,";
347 $sql .= " t.tms,";
348 $sql .= " t.datep,";
349 $sql .= " t.datev,";
350 $sql .= " t.amount,";
351 $sql .= " t.fk_typepayment,";
352 $sql .= " t.num_payment,";
353 $sql .= " t.label,";
354 $sql .= " t.note,";
355 $sql .= " t.paye,";
356 $sql .= " t.fk_user_creat,";
357 $sql .= " t.fk_user_modif,";
358 $sql .= " t.fk_account";
359 $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
360 $sql .= " WHERE t.rowid = ".((int) $id);
361
362 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
363
364 $resql = $this->db->query($sql);
365 if ($resql) {
366 if ($this->db->num_rows($resql)) {
367 $obj = $this->db->fetch_object($resql);
368
369 $this->id = $obj->rowid;
370 $this->ref = $obj->rowid;
371 $this->tms = $this->db->jdate($obj->tms);
372 $this->datep = $this->db->jdate($obj->datep);
373 $this->datev = $this->db->jdate($obj->datev);
374 $this->amount = $obj->amount;
375 $this->type_payment = $obj->fk_typepayment;
376 $this->num_payment = $obj->num_payment;
377 $this->label = $obj->label;
378 $this->paye = $obj->paye;
379 $this->note = $obj->note;
380 $this->fk_user_creat = $obj->fk_user_creat;
381 $this->fk_user_modif = $obj->fk_user_modif;
382 $this->fk_account = $obj->fk_account;
383 $this->fk_type = empty($obj->fk_type) ? "" : $obj->fk_type;
384 $this->rappro = empty($obj->rappro) ? "" : $obj->rappro;
385 }
386 $this->db->free($resql);
387
388 return 1;
389 } else {
390 $this->error = "Error ".$this->db->lasterror();
391 return -1;
392 }
393 }
394
395
396 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
402 public function is_erasable()
403 {
404 // phpcs:enable
405 $totalpaid = $this->getSommePaiement();
406 if ($totalpaid < 0) {
407 return -1;
408 }
409 return (empty($totalpaid) ? 1 : 0);
410 }
411
418 public function delete($user)
419 {
420 global $conf, $langs;
421
422 $error = 0;
423
424 if ($this->is_erasable() <= 0) {
425 $this->error = 'ErrorRecordHasChildren';
426 return -1;
427 }
428
429 // Call trigger
430 $result = $this->call_trigger('TVA_DELETE', $user);
431 if ($result < 0) {
432 return -1;
433 }
434 // End call triggers
435
436 $sql = "DELETE FROM ".MAIN_DB_PREFIX."tva";
437 $sql .= " WHERE rowid=".((int) $this->id);
438
439 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
440 $resql = $this->db->query($sql);
441 if (!$resql) {
442 $this->error = "Error ".$this->db->lasterror();
443 return -1;
444 }
445
446
447 return 1;
448 }
449
450
458 public function initAsSpecimen()
459 {
460 $this->id = 0;
461
462 $this->tms = dol_now();
463 $this->datep = dol_now();
464 $this->datev = dol_now();
465 $this->amount = 100.0;
466 $this->label = '';
467 $this->note = '';
468 $this->fk_bank = 0;
469 $this->fk_user_creat = 0;
470 $this->fk_user_modif = 0;
471
472 return 1;
473 }
474
475
482 public function solde($year = 0)
483 {
484 $reglee = $this->tva_sum_reglee($year);
485
486 $payee = $this->tva_sum_payee($year);
487 $collectee = $this->tva_sum_collectee($year);
488
489 $solde = $reglee - ($collectee - $payee);
490
491 return $solde;
492 }
493
494 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
501 public function tva_sum_collectee($year = 0)
502 {
503 // phpcs:enable
504
505 $sql = "SELECT sum(f.total_tva) as amount";
506 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f WHERE f.paye = 1";
507 if ($year) {
508 $sql .= " AND f.datef >= '".((int) $year)."-01-01' AND f.datef <= '".((int) $year)."-12-31' ";
509 }
510
511 $result = $this->db->query($sql);
512 if ($result) {
513 if ($this->db->num_rows($result)) {
514 $obj = $this->db->fetch_object($result);
515 $ret = $obj->amount;
516 $this->db->free($result);
517 return $ret;
518 } else {
519 $this->db->free($result);
520 return 0;
521 }
522 } else {
523 print $this->db->lasterror();
524 return -1;
525 }
526 }
527
528 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
535 public function tva_sum_payee($year = 0)
536 {
537 // phpcs:enable
538
539 $sql = "SELECT sum(f.total_tva) as total_tva";
540 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
541 if ($year) {
542 $sql .= " WHERE f.datef >= '".((int) $year)."-01-01' AND f.datef <= '".((int) $year)."-12-31' ";
543 }
544
545 $result = $this->db->query($sql);
546 if ($result) {
547 if ($this->db->num_rows($result)) {
548 $obj = $this->db->fetch_object($result);
549 $ret = $obj->total_tva;
550 $this->db->free($result);
551 return $ret;
552 } else {
553 $this->db->free($result);
554 return 0;
555 }
556 } else {
557 print $this->db->lasterror();
558 return -1;
559 }
560 }
561
562
563 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
570 public function tva_sum_reglee($year = 0)
571 {
572 // phpcs:enable
573
574 $sql = "SELECT sum(f.amount) as amount";
575 $sql .= " FROM ".MAIN_DB_PREFIX."tva as f";
576
577 if ($year) {
578 $sql .= " WHERE f.datev >= '".((int) $year)."-01-01' AND f.datev <= '".((int) $year)."-12-31' ";
579 }
580
581 $result = $this->db->query($sql);
582 if ($result) {
583 if ($this->db->num_rows($result)) {
584 $obj = $this->db->fetch_object($result);
585 $ret = $obj->amount;
586 $this->db->free($result);
587 return $ret;
588 } else {
589 $this->db->free($result);
590 return 0;
591 }
592 } else {
593 print $this->db->lasterror();
594 return -1;
595 }
596 }
597
598
605 public function addPayment($user)
606 {
607 global $conf, $langs;
608
609 $this->db->begin();
610
611 // Clean parameters
612 $this->amount = (float) price2num($this->amount);
613 $this->label = trim($this->label);
614 $this->note = trim($this->note);
615 $this->num_payment = trim($this->num_payment);
616 $this->fk_bank = (int) $this->fk_bank;
617 $this->fk_user_creat = (int) $this->fk_user_creat;
618 $this->fk_user_modif = (int) $this->fk_user_modif;
619 if (empty($this->datec)) {
620 $this->datec = dol_now();
621 }
622
623 // Check parameters
624 if (!$this->label) {
625 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
626 return -3;
627 }
628 if ($this->amount == '') {
629 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
630 return -4;
631 }
632 if (isModEnabled("bank") && (empty($this->accountid) || $this->accountid <= 0)) {
633 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("BankAccount"));
634 return -5;
635 }
636 if (isModEnabled("bank") && (empty($this->type_payment) || $this->type_payment <= 0)) {
637 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
638 return -5;
639 }
640
641 // Insert into llx_tva
642 $sql = "INSERT INTO ".MAIN_DB_PREFIX."tva (";
643 $sql .= "datec";
644 $sql .= ", datep";
645 $sql .= ", datev";
646 $sql .= ", amount";
647 $sql .= ", fk_typepayment";
648 $sql .= ", num_payment";
649 if ($this->note) {
650 $sql .= ", note";
651 }
652 if ($this->label) {
653 $sql .= ", label";
654 }
655 $sql .= ", fk_user_creat";
656 $sql .= ", fk_bank";
657 $sql .= ", entity";
658 $sql .= ") ";
659 $sql .= " VALUES (";
660 $sql .= " '".$this->db->idate($this->datec)."'";
661 $sql .= ", '".$this->db->idate($this->datep)."'";
662 $sql .= ", '".$this->db->idate($this->datev)."'";
663 $sql .= ", ".((float) $this->amount);
664 $sql .= ", '".$this->db->escape((string) $this->type_payment)."'";
665 $sql .= ", '".$this->db->escape($this->num_payment)."'";
666 if ($this->note) {
667 $sql .= ", '".$this->db->escape($this->note)."'";
668 }
669 if ($this->label) {
670 $sql .= ", '".$this->db->escape($this->label)."'";
671 }
672 $sql .= ", '".$this->db->escape((string) $user->id)."'";
673 $sql .= ", NULL";
674 $sql .= ", ".((int) $conf->entity);
675 $sql .= ")";
676
677 dol_syslog(get_class($this)."::addPayment", LOG_DEBUG);
678 $result = $this->db->query($sql);
679 if ($result) {
680 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."tva"); // TODO should be called 'payment_vat'
681
682 // Call trigger
683 //XXX: Should be done just before commit no ?
684 $result = $this->call_trigger('TVA_ADDPAYMENT', $user);
685 if ($result < 0) {
686 $this->id = 0;
687 $ok = 0;
688 }
689 // End call triggers
690
691 if ($this->id > 0) {
692 $ok = 1;
693 if (isModEnabled("bank") && !empty($this->amount)) {
694 // Insert into llx_bank
695 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
696
697 $acc = new Account($this->db);
698 $result = $acc->fetch($this->accountid);
699 if ($result <= 0) {
700 dol_print_error($this->db);
701 }
702
703 if ($this->amount > 0) {
704 $bank_line_id = $acc->addline($this->datep, (string) $this->type_payment, $this->label, -abs((float) $this->amount), $this->num_payment, 0, $user);
705 } else {
706 $bank_line_id = $acc->addline($this->datep, (string) $this->type_payment, $this->label, abs((float) $this->amount), $this->num_payment, 0, $user);
707 }
708
709 // Update fk_bank into llx_tva. So we know vat line used to generate bank transaction
710 if ($bank_line_id > 0) {
711 $this->update_fk_bank($bank_line_id);
712 } else {
713 $this->error = $acc->error;
714 $ok = 0;
715 }
716
717 // Update links
718 $result = $acc->add_url_line($bank_line_id, $this->id, DOL_URL_ROOT.'/compta/tva/card.php?id=', "(VATPayment)", "payment_vat");
719 if ($result < 0) {
720 $this->error = $acc->error;
721 $ok = 0;
722 }
723 }
724
725 if ($ok) {
726 $this->db->commit();
727 return $this->id;
728 } else {
729 $this->db->rollback();
730 return -3;
731 }
732 } else {
733 $this->db->rollback();
734 return -2;
735 }
736 } else {
737 $this->error = $this->db->error();
738 $this->db->rollback();
739 return -1;
740 }
741 }
742
743 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
750 public function update_fk_bank($id_bank)
751 {
752 // phpcs:enable
753 $sql = 'UPDATE '.MAIN_DB_PREFIX.'tva SET fk_bank = '.(int) $id_bank;
754 $sql .= ' WHERE rowid = '.(int) $this->id;
755 $result = $this->db->query($sql);
756 if ($result) {
757 return 1;
758 } else {
759 dol_print_error($this->db);
760 return -1;
761 }
762 }
763
774 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
775 {
776 global $langs, $conf;
777
778 if (!empty($conf->dol_no_mouse_hover)) {
779 $notooltip = 1; // Force disable tooltips
780 }
781
782 $result = '';
783
784 $label = '<u>'.$langs->trans("ShowVatPayment").'</u>';
785 $label .= '<br>';
786 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
787 if (!empty($this->label)) {
788 $label .= '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
789 }
790
791 $url = DOL_URL_ROOT.'/compta/tva/card.php?id='.$this->id;
792
793 if ($option != 'nolink') {
794 // Add param to save lastsearch_values or not
795 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
796 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
797 $add_save_lastsearch_values = 1;
798 }
799 if ($add_save_lastsearch_values) {
800 $url .= '&save_lastsearch_values=1';
801 }
802 }
803
804 $linkclose = '';
805 if (empty($notooltip)) {
806 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
807 $label = $langs->trans("ShowMyObject");
808 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
809 }
810 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
811 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
812 } else {
813 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
814 }
815
816 $linkstart = '<a href="'.$url.'"';
817 $linkstart .= $linkclose.'>';
818 $linkend = '</a>';
819
820 $picto = 'payment';
821
822 $result .= $linkstart;
823 if ($withpicto) {
824 $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);
825 }
826 if ($withpicto != 2) {
827 $result .= $this->ref;
828 }
829 $result .= $linkend;
830
831 return $result;
832 }
833
839 public function getSommePaiement()
840 {
841 $sql = 'SELECT sum(amount) as amount';
842 $sql .= ' FROM '.MAIN_DB_PREFIX."payment_vat";
843 $sql .= " WHERE fk_tva = ".((int) $this->id);
844
845 dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG);
846 $resql = $this->db->query($sql);
847 if ($resql) {
848 $amount = 0;
849
850 $obj = $this->db->fetch_object($resql);
851 if ($obj) {
852 $amount = $obj->amount ? $obj->amount : 0;
853 }
854
855 $this->db->free($resql);
856 return $amount;
857 } else {
858 return -1;
859 }
860 }
861
868 public function info($id)
869 {
870 $sql = "SELECT t.rowid, t.tms, t.fk_user_modif, t.datec, t.fk_user_creat";
871 $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
872 $sql .= " WHERE t.rowid = ".(int) $id;
873
874 dol_syslog(get_class($this)."::info", LOG_DEBUG);
875 $result = $this->db->query($sql);
876 if ($result) {
877 if ($this->db->num_rows($result)) {
878 $obj = $this->db->fetch_object($result);
879
880 $this->id = $obj->rowid;
881
882 $this->user_creation_id = $obj->fk_user_creat;
883 $this->user_modification_id = $obj->fk_user_modif;
884 $this->date_creation = $this->db->jdate($obj->datec);
885 $this->date_modification = $this->db->jdate($obj->tms);
886 }
887
888 $this->db->free($result);
889 } else {
890 dol_print_error($this->db);
891 }
892 }
893
901 public function getLibStatut($mode = 0, $alreadypaid = -1)
902 {
903 return $this->LibStatut($this->paye, $mode, $alreadypaid);
904 }
905
906 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
915 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
916 {
917 // phpcs:enable
918 global $langs;
919
920 // Load translation files required by the page
921 $langs->loadLangs(array("customers", "bills"));
922
923 // We reinit status array to force to redefine them because label may change according to properties values.
924 $this->labelStatus = array();
925 $this->labelStatusShort = array();
926
927 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
928 global $langs;
929 //$langs->load("mymodule");
930 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
931 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
932 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
933 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
934 }
935 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
936 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
937 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
938 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
939 }
940 }
941
942 $statusType = 'status1';
943 if ($status == 0 && $alreadypaid != 0) {
944 $statusType = 'status3';
945 }
946 if ($status == 1) {
947 $statusType = 'status6';
948 }
949
950 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
951 }
952
960 public function getKanbanView($option = '', $arraydata = null)
961 {
962 global $langs;
963
964 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
965
966 $return = '<div class="box-flex-item box-flex-grow-zero">';
967 $return .= '<div class="info-box info-box-sm">';
968 $return .= '<span class="info-box-icon bg-infobox-action">';
969 $return .= img_picto('', $this->picto);
970 //$return .= '<i class="fa fa-dol-action"></i>'; // Can be image
971 $return .= '</span>';
972 $return .= '<div class="info-box-content">';
973 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</span>';
974 if ($selected >= 0) {
975 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
976 }
977 if (property_exists($this, 'amount')) {
978 $return .= ' | <span class="opacitymedium">'.$langs->trans("Amount").'</span> : <span class="info-box-label amount">'.price($this->amount).'</span>';
979 }
980 if (property_exists($this, 'type_payment')) {
981 $return .= '<br><span class="opacitymedium">'.$langs->trans("Payment").'</span> : <span class="info-box-label">'.$this->type_payment.'</span>';
982 }
983 if (property_exists($this, 'datev')) {
984 $return .= '<br><span class="opacitymedium">'.$langs->trans("DateEnd").'</span> : <span class="info-box-label" >'.dol_print_date($this->datev).'</span>';
985 }
986 if (method_exists($this, 'LibStatut')) {
987 $return .= '<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3, (float) $this->alreadypaid).'</div>';
988 }
989 $return .= '</div>';
990 $return .= '</div>';
991 $return .= '</div>';
992 return $return;
993 }
994
1001 public function getIdForLabel($label)
1002 {
1003 $id = 0;
1004 $sql = "SELECT t.rowid";
1005 $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
1006 $sql .= " WHERE t.label = '".$this->db->escape($label)."'";
1007
1008 dol_syslog(get_class($this)."::getIdForLabel", LOG_DEBUG);
1009 $result = $this->db->query($sql);
1010 if ($result) {
1011 if ($this->db->num_rows($result)) {
1012 $obj = $this->db->fetch_object($result);
1013 $id = $obj->rowid;
1014 }
1015 $this->db->free($result);
1016 } else {
1017 dol_print_error($this->db);
1018 }
1019 return $id;
1020 }
1021}
$object ref
Definition info.php:90
Class to manage bank accounts.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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).
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.
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