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