dolibarr 24.0.0-beta
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 ? $this->fk_user_modif : $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
402 public function delete($user)
403 {
404 global $conf, $langs;
405
406 $error = 0;
407
408 // Call trigger
409 $result = $this->call_trigger('TVA_DELETE', $user);
410 if ($result < 0) {
411 return -1;
412 }
413 // End call triggers
414
415 $sql = "DELETE FROM ".MAIN_DB_PREFIX."tva";
416 $sql .= " WHERE rowid=".((int) $this->id);
417
418 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
419 $resql = $this->db->query($sql);
420 if (!$resql) {
421 $this->error = "Error ".$this->db->lasterror();
422 return -1;
423 }
424
425
426 return 1;
427 }
428
429
437 public function initAsSpecimen()
438 {
439 $this->id = 0;
440
441 $this->tms = dol_now();
442 $this->datep = dol_now();
443 $this->datev = dol_now();
444 $this->amount = 100.0;
445 $this->label = '';
446 $this->note = '';
447 $this->fk_bank = 0;
448 $this->fk_user_creat = 0;
449 $this->fk_user_modif = 0;
450
451 return 1;
452 }
453
454
461 public function solde($year = 0)
462 {
463 $reglee = $this->tva_sum_reglee($year);
464
465 $payee = $this->tva_sum_payee($year);
466 $collectee = $this->tva_sum_collectee($year);
467
468 $solde = $reglee - ($collectee - $payee);
469
470 return $solde;
471 }
472
473 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
480 public function tva_sum_collectee($year = 0)
481 {
482 // phpcs:enable
483
484 $sql = "SELECT sum(f.total_tva) as amount";
485 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f WHERE f.paye = 1";
486 if ($year) {
487 $sql .= " AND f.datef >= '".((int) $year)."-01-01' AND f.datef <= '".((int) $year)."-12-31' ";
488 }
489
490 $result = $this->db->query($sql);
491 if ($result) {
492 if ($this->db->num_rows($result)) {
493 $obj = $this->db->fetch_object($result);
494 $ret = $obj->amount;
495 $this->db->free($result);
496 return $ret;
497 } else {
498 $this->db->free($result);
499 return 0;
500 }
501 } else {
502 print $this->db->lasterror();
503 return -1;
504 }
505 }
506
507 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
514 public function tva_sum_payee($year = 0)
515 {
516 // phpcs:enable
517
518 $sql = "SELECT sum(f.total_tva) as total_tva";
519 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
520 if ($year) {
521 $sql .= " WHERE f.datef >= '".((int) $year)."-01-01' AND f.datef <= '".((int) $year)."-12-31' ";
522 }
523
524 $result = $this->db->query($sql);
525 if ($result) {
526 if ($this->db->num_rows($result)) {
527 $obj = $this->db->fetch_object($result);
528 $ret = $obj->total_tva;
529 $this->db->free($result);
530 return $ret;
531 } else {
532 $this->db->free($result);
533 return 0;
534 }
535 } else {
536 print $this->db->lasterror();
537 return -1;
538 }
539 }
540
541
542 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
549 public function tva_sum_reglee($year = 0)
550 {
551 // phpcs:enable
552
553 $sql = "SELECT sum(f.amount) as amount";
554 $sql .= " FROM ".MAIN_DB_PREFIX."tva as f";
555
556 if ($year) {
557 $sql .= " WHERE f.datev >= '".((int) $year)."-01-01' AND f.datev <= '".((int) $year)."-12-31' ";
558 }
559
560 $result = $this->db->query($sql);
561 if ($result) {
562 if ($this->db->num_rows($result)) {
563 $obj = $this->db->fetch_object($result);
564 $ret = $obj->amount;
565 $this->db->free($result);
566 return $ret;
567 } else {
568 $this->db->free($result);
569 return 0;
570 }
571 } else {
572 print $this->db->lasterror();
573 return -1;
574 }
575 }
576
577
584 public function addPayment($user)
585 {
586 global $conf, $langs;
587
588 $this->db->begin();
589
590 // Clean parameters
591 $this->amount = (float) price2num($this->amount);
592 $this->label = trim($this->label);
593 $this->note = trim($this->note);
594 $this->num_payment = trim($this->num_payment);
595 $this->fk_bank = (int) $this->fk_bank;
596 $this->fk_user_creat = (int) $this->fk_user_creat;
597 $this->fk_user_modif = (int) $this->fk_user_modif;
598 if (empty($this->datec)) {
599 $this->datec = dol_now();
600 }
601
602 // Check parameters
603 if (!$this->label) {
604 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
605 return -3;
606 }
607 if ($this->amount == '') {
608 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
609 return -4;
610 }
611 if (isModEnabled("bank") && (empty($this->accountid) || $this->accountid <= 0)) {
612 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("BankAccount"));
613 return -5;
614 }
615 if (isModEnabled("bank") && (empty($this->type_payment) || $this->type_payment <= 0)) {
616 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
617 return -5;
618 }
619
620 // Insert into llx_tva
621 $sql = "INSERT INTO ".MAIN_DB_PREFIX."tva (";
622 $sql .= "datec";
623 $sql .= ", datep";
624 $sql .= ", datev";
625 $sql .= ", amount";
626 $sql .= ", fk_typepayment";
627 $sql .= ", num_payment";
628 if ($this->note) {
629 $sql .= ", note";
630 }
631 if ($this->label) {
632 $sql .= ", label";
633 }
634 $sql .= ", fk_user_creat";
635 $sql .= ", fk_bank";
636 $sql .= ", entity";
637 $sql .= ") ";
638 $sql .= " VALUES (";
639 $sql .= " '".$this->db->idate($this->datec)."'";
640 $sql .= ", '".$this->db->idate($this->datep)."'";
641 $sql .= ", '".$this->db->idate($this->datev)."'";
642 $sql .= ", ".((float) $this->amount);
643 $sql .= ", '".$this->db->escape((string) $this->type_payment)."'";
644 $sql .= ", '".$this->db->escape($this->num_payment)."'";
645 if ($this->note) {
646 $sql .= ", '".$this->db->escape($this->note)."'";
647 }
648 if ($this->label) {
649 $sql .= ", '".$this->db->escape($this->label)."'";
650 }
651 $sql .= ", '".$this->db->escape((string) $user->id)."'";
652 $sql .= ", NULL";
653 $sql .= ", ".((int) $conf->entity);
654 $sql .= ")";
655
656 dol_syslog(get_class($this)."::addPayment", LOG_DEBUG);
657 $result = $this->db->query($sql);
658 if ($result) {
659 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."tva"); // TODO should be called 'payment_vat'
660
661 // Call trigger
662 //XXX: Should be done just before commit no ?
663 $result = $this->call_trigger('TVA_ADDPAYMENT', $user);
664 if ($result < 0) {
665 $this->id = 0;
666 $ok = 0;
667 }
668 // End call triggers
669
670 if ($this->id > 0) {
671 $ok = 1;
672 if (isModEnabled("bank") && !empty($this->amount)) {
673 // Insert into llx_bank
674 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
675
676 $acc = new Account($this->db);
677 $result = $acc->fetch($this->accountid);
678 if ($result <= 0) {
679 dol_print_error($this->db);
680 }
681
682 if ($this->amount > 0) {
683 $bank_line_id = $acc->addline($this->datep, (string) $this->type_payment, $this->label, -abs((float) $this->amount), $this->num_payment, 0, $user);
684 } else {
685 $bank_line_id = $acc->addline($this->datep, (string) $this->type_payment, $this->label, abs((float) $this->amount), $this->num_payment, 0, $user);
686 }
687
688 // Update fk_bank into llx_tva. So we know vat line used to generate bank transaction
689 if ($bank_line_id > 0) {
690 $this->update_fk_bank($bank_line_id);
691 } else {
692 $this->error = $acc->error;
693 $ok = 0;
694 }
695
696 // Update links
697 $result = $acc->add_url_line($bank_line_id, $this->id, DOL_URL_ROOT.'/compta/tva/card.php?id=', "(VATPayment)", "payment_vat");
698 if ($result < 0) {
699 $this->error = $acc->error;
700 $ok = 0;
701 }
702 }
703
704 if ($ok) {
705 $this->db->commit();
706 return $this->id;
707 } else {
708 $this->db->rollback();
709 return -3;
710 }
711 } else {
712 $this->db->rollback();
713 return -2;
714 }
715 } else {
716 $this->error = $this->db->error();
717 $this->db->rollback();
718 return -1;
719 }
720 }
721
722 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
729 public function update_fk_bank($id_bank)
730 {
731 // phpcs:enable
732 $sql = 'UPDATE '.MAIN_DB_PREFIX.'tva SET fk_bank = '.(int) $id_bank;
733 $sql .= ' WHERE rowid = '.(int) $this->id;
734 $result = $this->db->query($sql);
735 if ($result) {
736 return 1;
737 } else {
738 dol_print_error($this->db);
739 return -1;
740 }
741 }
742
753 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
754 {
755 global $langs, $conf;
756
757 if (!empty($conf->dol_no_mouse_hover)) {
758 $notooltip = 1; // Force disable tooltips
759 }
760
761 $result = '';
762
763 $label = '<u>'.$langs->trans("ShowVatPayment").'</u>';
764 $label .= '<br>';
765 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
766 if (!empty($this->label)) {
767 $label .= '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
768 }
769
770 $url = DOL_URL_ROOT.'/compta/tva/card.php?id='.$this->id;
771
772 if ($option != 'nolink') {
773 // Add param to save lastsearch_values or not
774 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
775 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
776 $add_save_lastsearch_values = 1;
777 }
778 if ($add_save_lastsearch_values) {
779 $url .= '&save_lastsearch_values=1';
780 }
781 }
782
783 $linkclose = '';
784 if (empty($notooltip)) {
785 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
786 $label = $langs->trans("ShowMyObject");
787 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
788 }
789 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
790 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
791 } else {
792 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
793 }
794
795 $linkstart = '<a href="'.$url.'"';
796 $linkstart .= $linkclose.'>';
797 $linkend = '</a>';
798
799 $picto = 'payment';
800
801 $result .= $linkstart;
802 if ($withpicto) {
803 $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);
804 }
805 if ($withpicto != 2) {
806 $result .= $this->ref;
807 }
808 $result .= $linkend;
809
810 return $result;
811 }
812
818 public function getSommePaiement()
819 {
820 $sql = 'SELECT sum(amount) as amount';
821 $sql .= ' FROM '.MAIN_DB_PREFIX."payment_vat";
822 $sql .= " WHERE fk_tva = ".((int) $this->id);
823
824 dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG);
825 $resql = $this->db->query($sql);
826 if ($resql) {
827 $amount = 0;
828
829 $obj = $this->db->fetch_object($resql);
830 if ($obj) {
831 $amount = $obj->amount ? $obj->amount : 0;
832 }
833
834 $this->db->free($resql);
835 return $amount;
836 } else {
837 return -1;
838 }
839 }
840
847 public function info($id)
848 {
849 $sql = "SELECT t.rowid, t.tms, t.fk_user_modif, t.datec, t.fk_user_creat";
850 $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
851 $sql .= " WHERE t.rowid = ".(int) $id;
852
853 dol_syslog(get_class($this)."::info", LOG_DEBUG);
854 $result = $this->db->query($sql);
855 if ($result) {
856 if ($this->db->num_rows($result)) {
857 $obj = $this->db->fetch_object($result);
858
859 $this->id = $obj->rowid;
860
861 $this->user_creation_id = $obj->fk_user_creat;
862 $this->user_modification_id = $obj->fk_user_modif;
863 $this->date_creation = $this->db->jdate($obj->datec);
864 $this->date_modification = $this->db->jdate($obj->tms);
865 }
866
867 $this->db->free($result);
868 } else {
869 dol_print_error($this->db);
870 }
871 }
872
880 public function getLibStatut($mode = 0, $alreadypaid = -1)
881 {
882 return $this->LibStatut($this->paye, $mode, $alreadypaid);
883 }
884
885 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
894 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
895 {
896 // phpcs:enable
897 global $langs;
898
899 // Load translation files required by the page
900 $langs->loadLangs(array("customers", "bills"));
901
902 // We reinit status array to force to redefine them because label may change according to properties values.
903 $this->labelStatus = array();
904 $this->labelStatusShort = array();
905
906 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
907 global $langs;
908 //$langs->load("mymodule");
909 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
910 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
911 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
912 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
913 }
914 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
915 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
916 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
917 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
918 }
919 }
920
921 $statusType = 'status1';
922 if ($status == 0 && $alreadypaid != 0) {
923 $statusType = 'status3';
924 }
925 if ($status == 1) {
926 $statusType = 'status6';
927 }
928
929 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
930 }
931
939 public function getKanbanView($option = '', $arraydata = null)
940 {
941 global $langs;
942
943 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
944
945 $return = '<div class="box-flex-item box-flex-grow-zero">';
946 $return .= '<div class="info-box info-box-sm">';
947 $return .= '<span class="info-box-icon bg-infobox-action">';
948 $return .= img_picto('', $this->picto);
949 //$return .= '<i class="fa fa-dol-action"></i>'; // Can be image
950 $return .= '</span>';
951 $return .= '<div class="info-box-content">';
952 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</span>';
953 if ($selected >= 0) {
954 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
955 }
956 if (property_exists($this, 'amount')) {
957 $return .= ' | <span class="opacitymedium">'.$langs->trans("Amount").'</span> : <span class="info-box-label amount">'.price($this->amount).'</span>';
958 }
959 if (property_exists($this, 'type_payment')) {
960 $return .= '<br><span class="opacitymedium">'.$langs->trans("Payment").'</span> : <span class="info-box-label">'.$this->type_payment.'</span>';
961 }
962 if (property_exists($this, 'datev')) {
963 $return .= '<br><span class="opacitymedium">'.$langs->trans("DateEnd").'</span> : <span class="info-box-label" >'.dol_print_date($this->datev).'</span>';
964 }
965 if (method_exists($this, 'LibStatut')) {
966 $return .= '<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3, (float) $this->alreadypaid).'</div>';
967 }
968 $return .= '</div>';
969 $return .= '</div>';
970 $return .= '</div>';
971 return $return;
972 }
973
980 public function getIdForLabel($label)
981 {
982 $id = 0;
983 $sql = "SELECT t.rowid";
984 $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
985 $sql .= " WHERE t.label = '".$this->db->escape($label)."'";
986
987 dol_syslog(get_class($this)."::getIdForLabel", LOG_DEBUG);
988 $result = $this->db->query($sql);
989 if ($result) {
990 if ($this->db->num_rows($result)) {
991 $obj = $this->db->fetch_object($result);
992 $id = $obj->rowid;
993 }
994 $this->db->free($result);
995 } else {
996 dol_print_error($this->db);
997 }
998 return $id;
999 }
1000}
$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
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.
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:489