dolibarr 22.0.5
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-2025 MDW <mdeweerd@users.noreply.github.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
29// Put here all includes required by your class file
30require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
31
32
37class Tva extends CommonObject
38{
42 public $element = 'tva';
43
47 public $table_element = 'tva';
48
52 public $picto = 'payment';
53
59 public $total;
60
64 public $datep;
65
69 public $datev;
70
74 public $amount;
75
79 public $type_payment;
80
85 public $num_payment;
86
90 public $datec;
91
95 public $fk_type;
96
100 public $paye;
101
105 public $rappro;
106
110 public $label;
111
115 public $fk_bank;
116
120 public $accountid;
121
125 public $fk_user_creat;
126
130 public $fk_user_modif;
131
135 public $paiementtype;
136
137
138 const STATUS_UNPAID = 0;
139 const STATUS_PAID = 1;
140
146 public function __construct($db)
147 {
148 $this->db = $db;
149 }
150
151
158 public function create($user)
159 {
160 global $conf, $langs;
161
162 $error = 0;
163 $now = dol_now();
164
165 // Clean parameters
166 $this->amount = (float) price2num($this->amount);
167 $this->label = trim($this->label);
168 $this->type_payment = (int) $this->type_payment;
169 $this->note = trim($this->note);
170 $this->fk_account = (int) $this->fk_account;
171 $this->fk_user_creat = (int) $this->fk_user_creat;
172 $this->fk_user_modif = (int) $this->fk_user_modif;
173
174 // Check parameters
175 // Put here code to add control on parameters values
176
177 $this->db->begin();
178
179 // Insert request
180 $sql = "INSERT INTO ".MAIN_DB_PREFIX."tva(";
181 $sql .= "entity,";
182 $sql .= "datec,";
183 $sql .= "datep,";
184 $sql .= "datev,";
185 $sql .= "amount,";
186 $sql .= "label,";
187 $sql .= "note,";
188 $sql .= "fk_account,";
189 $sql .= "fk_typepayment,";
190 $sql .= "fk_user_creat,";
191 $sql .= "fk_user_modif";
192 $sql .= ") VALUES (";
193 $sql .= " ".((int) $conf->entity).", ";
194 $sql .= " '".$this->db->idate($now)."',";
195 $sql .= " '".$this->db->idate($this->datep)."',";
196 $sql .= " '".$this->db->idate($this->datev)."',";
197 $sql .= " '".$this->db->escape((string) $this->amount)."',";
198 $sql .= " '".$this->db->escape($this->label)."',";
199 $sql .= " '".$this->db->escape($this->note)."',";
200 $sql .= " '".$this->db->escape((string) $this->fk_account)."',";
201 $sql .= " '".$this->db->escape((string) $this->type_payment)."',";
202 $sql .= " ".($this->fk_user_creat > 0 ? (int) $this->fk_user_creat : (int) $user->id).",";
203 $sql .= " ".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : (int) $user->id);
204 $sql .= ")";
205
206 dol_syslog(get_class($this)."::create", LOG_DEBUG);
207 $resql = $this->db->query($sql);
208 if ($resql) {
209 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."tva");
210
211 // Call trigger
212 $result = $this->call_trigger('TVA_CREATE', $user);
213 if ($result < 0) {
214 $error++;
215 }
216 // End call triggers
217
218 if (!$error) {
219 $this->db->commit();
220 return $this->id;
221 } else {
222 $this->db->rollback();
223 return -1;
224 }
225 } else {
226 $this->error = "Error ".$this->db->lasterror();
227 $this->db->rollback();
228 return -1;
229 }
230 }
231
239 public function update($user, $notrigger = 0)
240 {
241 global $conf, $langs;
242
243 $error = 0;
244
245 // Clean parameters
246 $this->amount = (float) price2num($this->amount);
247 $this->label = trim($this->label);
248 $this->note = trim($this->note);
249 $this->fk_user_creat = (int) $this->fk_user_creat;
250 $this->fk_user_modif = (int) $this->fk_user_modif;
251
252 // Check parameters
253 // Put here code to add control on parameters values
254
255 $this->db->begin();
256
257 // Update request
258 $sql = "UPDATE ".MAIN_DB_PREFIX."tva SET";
259 $sql .= " tms='".$this->db->idate($this->tms)."',";
260 $sql .= " datep='".$this->db->idate($this->datep)."',";
261 $sql .= " datev='".$this->db->idate($this->datev)."',";
262 $sql .= " amount=".price2num($this->amount).",";
263 $sql .= " label='".$this->db->escape($this->label)."',";
264 $sql .= " note='".$this->db->escape($this->note)."',";
265 $sql .= " fk_user_creat=".((int) $this->fk_user_creat).",";
266 $sql .= " fk_user_modif=".((int) ($this->fk_user_modif > 0 ? $this->fk_user_modif : $user->id));
267 $sql .= " WHERE rowid=".((int) $this->id);
268
269 dol_syslog(get_class($this)."::update", LOG_DEBUG);
270 $resql = $this->db->query($sql);
271 if (!$resql) {
272 $this->error = "Error ".$this->db->lasterror();
273 $error++;
274 }
275
276 if (!$error && !$notrigger) {
277 // Call trigger
278 $result = $this->call_trigger('TVA_MODIFY', $user);
279 if ($result < 0) {
280 $error++;
281 }
282 // End call triggers
283 }
284
285 if (!$error) {
286 $this->db->commit();
287 return 1;
288 } else {
289 $this->db->rollback();
290 return -1;
291 }
292 }
293
300 public function setPaid($user)
301 {
302 // phpcs:enable
303 $sql = "UPDATE ".MAIN_DB_PREFIX."tva SET";
304 $sql .= " paye = 1";
305 $sql .= " WHERE rowid = ".((int) $this->id);
306 $resql = $this->db->query($sql);
307 if ($resql) {
308 return 1;
309 } else {
310 return -1;
311 }
312 }
313
320 public function setUnpaid($user)
321 {
322 // phpcs:enable
323 $sql = "UPDATE ".MAIN_DB_PREFIX."tva SET";
324 $sql .= " paye = 0";
325 $sql .= " WHERE rowid = ".((int) $this->id);
326 $resql = $this->db->query($sql);
327 if ($resql) {
328 return 1;
329 } else {
330 return -1;
331 }
332 }
333
334
342 public function fetch($id, $ref = '')
343 {
344 $sql = "SELECT";
345 $sql .= " t.rowid,";
346 $sql .= " t.tms,";
347 $sql .= " t.datep,";
348 $sql .= " t.datev,";
349 $sql .= " t.amount,";
350 $sql .= " t.fk_typepayment,";
351 $sql .= " t.num_payment,";
352 $sql .= " t.label,";
353 $sql .= " t.note,";
354 $sql .= " t.paye,";
355 $sql .= " t.fk_user_creat,";
356 $sql .= " t.fk_user_modif,";
357 $sql .= " t.fk_account";
358 $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
359 $sql .= " WHERE t.rowid = ".((int) $id);
360
361 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
362
363 $resql = $this->db->query($sql);
364 if ($resql) {
365 if ($this->db->num_rows($resql)) {
366 $obj = $this->db->fetch_object($resql);
367
368 $this->id = $obj->rowid;
369 $this->ref = $obj->rowid;
370 $this->tms = $this->db->jdate($obj->tms);
371 $this->datep = $this->db->jdate($obj->datep);
372 $this->datev = $this->db->jdate($obj->datev);
373 $this->amount = $obj->amount;
374 $this->type_payment = $obj->fk_typepayment;
375 $this->num_payment = $obj->num_payment;
376 $this->label = $obj->label;
377 $this->paye = $obj->paye;
378 $this->note = $obj->note;
379 $this->fk_user_creat = $obj->fk_user_creat;
380 $this->fk_user_modif = $obj->fk_user_modif;
381 $this->fk_account = $obj->fk_account;
382 $this->fk_type = empty($obj->fk_type) ? "" : $obj->fk_type;
383 $this->rappro = empty($obj->rappro) ? "" : $obj->rappro;
384 }
385 $this->db->free($resql);
386
387 return 1;
388 } else {
389 $this->error = "Error ".$this->db->lasterror();
390 return -1;
391 }
392 }
393
394
395 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
401 public function is_erasable()
402 {
403 // phpcs:enable
404 $totalpaid = $this->getSommePaiement();
405 if ($totalpaid < 0) {
406 return -1;
407 }
408 return (empty($totalpaid) ? 1 : 0);
409 }
410
417 public function delete($user)
418 {
419 global $conf, $langs;
420
421 $error = 0;
422
423 if ($this->is_erasable() <= 0) {
424 $this->error = 'ErrorRecordHasChildren';
425 return -1;
426 }
427
428 // Call trigger
429 $result = $this->call_trigger('TVA_DELETE', $user);
430 if ($result < 0) {
431 return -1;
432 }
433 // End call triggers
434
435 $sql = "DELETE FROM ".MAIN_DB_PREFIX."tva";
436 $sql .= " WHERE rowid=".((int) $this->id);
437
438 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
439 $resql = $this->db->query($sql);
440 if (!$resql) {
441 $this->error = "Error ".$this->db->lasterror();
442 return -1;
443 }
444
445
446 return 1;
447 }
448
449
457 public function initAsSpecimen()
458 {
459 $this->id = 0;
460
461 $this->tms = dol_now();
462 $this->datep = dol_now();
463 $this->datev = dol_now();
464 $this->amount = 100.0;
465 $this->label = '';
466 $this->note = '';
467 $this->fk_bank = 0;
468 $this->fk_user_creat = 0;
469 $this->fk_user_modif = 0;
470
471 return 1;
472 }
473
474
481 public function solde($year = 0)
482 {
483 $reglee = $this->tva_sum_reglee($year);
484
485 $payee = $this->tva_sum_payee($year);
486 $collectee = $this->tva_sum_collectee($year);
487
488 $solde = $reglee - ($collectee - $payee);
489
490 return $solde;
491 }
492
493 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
500 public function tva_sum_collectee($year = 0)
501 {
502 // phpcs:enable
503
504 $sql = "SELECT sum(f.total_tva) as amount";
505 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f WHERE f.paye = 1";
506 if ($year) {
507 $sql .= " AND f.datef >= '".((int) $year)."-01-01' AND f.datef <= '".((int) $year)."-12-31' ";
508 }
509
510 $result = $this->db->query($sql);
511 if ($result) {
512 if ($this->db->num_rows($result)) {
513 $obj = $this->db->fetch_object($result);
514 $ret = $obj->amount;
515 $this->db->free($result);
516 return $ret;
517 } else {
518 $this->db->free($result);
519 return 0;
520 }
521 } else {
522 print $this->db->lasterror();
523 return -1;
524 }
525 }
526
527 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
534 public function tva_sum_payee($year = 0)
535 {
536 // phpcs:enable
537
538 $sql = "SELECT sum(f.total_tva) as total_tva";
539 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
540 if ($year) {
541 $sql .= " WHERE f.datef >= '".((int) $year)."-01-01' AND f.datef <= '".((int) $year)."-12-31' ";
542 }
543
544 $result = $this->db->query($sql);
545 if ($result) {
546 if ($this->db->num_rows($result)) {
547 $obj = $this->db->fetch_object($result);
548 $ret = $obj->total_tva;
549 $this->db->free($result);
550 return $ret;
551 } else {
552 $this->db->free($result);
553 return 0;
554 }
555 } else {
556 print $this->db->lasterror();
557 return -1;
558 }
559 }
560
561
562 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
569 public function tva_sum_reglee($year = 0)
570 {
571 // phpcs:enable
572
573 $sql = "SELECT sum(f.amount) as amount";
574 $sql .= " FROM ".MAIN_DB_PREFIX."tva as f";
575
576 if ($year) {
577 $sql .= " WHERE f.datev >= '".((int) $year)."-01-01' AND f.datev <= '".((int) $year)."-12-31' ";
578 }
579
580 $result = $this->db->query($sql);
581 if ($result) {
582 if ($this->db->num_rows($result)) {
583 $obj = $this->db->fetch_object($result);
584 $ret = $obj->amount;
585 $this->db->free($result);
586 return $ret;
587 } else {
588 $this->db->free($result);
589 return 0;
590 }
591 } else {
592 print $this->db->lasterror();
593 return -1;
594 }
595 }
596
597
604 public function addPayment($user)
605 {
606 global $conf, $langs;
607
608 $this->db->begin();
609
610 // Clean parameters
611 $this->amount = (float) price2num($this->amount);
612 $this->label = trim($this->label);
613 $this->note = trim($this->note);
614 $this->num_payment = trim($this->num_payment);
615 $this->fk_bank = (int) $this->fk_bank;
616 $this->fk_user_creat = (int) $this->fk_user_creat;
617 $this->fk_user_modif = (int) $this->fk_user_modif;
618 if (empty($this->datec)) {
619 $this->datec = dol_now();
620 }
621
622 // Check parameters
623 if (!$this->label) {
624 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
625 return -3;
626 }
627 if ($this->amount == '') {
628 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
629 return -4;
630 }
631 if (isModEnabled("bank") && (empty($this->accountid) || $this->accountid <= 0)) {
632 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("BankAccount"));
633 return -5;
634 }
635 if (isModEnabled("bank") && (empty($this->type_payment) || $this->type_payment <= 0)) {
636 $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
637 return -5;
638 }
639
640 // Insert into llx_tva
641 $sql = "INSERT INTO ".MAIN_DB_PREFIX."tva (";
642 $sql .= "datec";
643 $sql .= ", datep";
644 $sql .= ", datev";
645 $sql .= ", amount";
646 $sql .= ", fk_typepayment";
647 $sql .= ", num_payment";
648 if ($this->note) {
649 $sql .= ", note";
650 }
651 if ($this->label) {
652 $sql .= ", label";
653 }
654 $sql .= ", fk_user_creat";
655 $sql .= ", fk_bank";
656 $sql .= ", entity";
657 $sql .= ") ";
658 $sql .= " VALUES (";
659 $sql .= " '".$this->db->idate($this->datec)."'";
660 $sql .= ", '".$this->db->idate($this->datep)."'";
661 $sql .= ", '".$this->db->idate($this->datev)."'";
662 $sql .= ", ".((float) $this->amount);
663 $sql .= ", '".$this->db->escape((string) $this->type_payment)."'";
664 $sql .= ", '".$this->db->escape($this->num_payment)."'";
665 if ($this->note) {
666 $sql .= ", '".$this->db->escape($this->note)."'";
667 }
668 if ($this->label) {
669 $sql .= ", '".$this->db->escape($this->label)."'";
670 }
671 $sql .= ", '".$this->db->escape((string) $user->id)."'";
672 $sql .= ", NULL";
673 $sql .= ", ".((int) $conf->entity);
674 $sql .= ")";
675
676 dol_syslog(get_class($this)."::addPayment", LOG_DEBUG);
677 $result = $this->db->query($sql);
678 if ($result) {
679 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."tva"); // TODO should be called 'payment_vat'
680
681 // Call trigger
682 //XXX: Should be done just before commit no ?
683 $result = $this->call_trigger('TVA_ADDPAYMENT', $user);
684 if ($result < 0) {
685 $this->id = 0;
686 $ok = 0;
687 }
688 // End call triggers
689
690 if ($this->id > 0) {
691 $ok = 1;
692 if (isModEnabled("bank") && !empty($this->amount)) {
693 // Insert into llx_bank
694 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
695
696 $acc = new Account($this->db);
697 $result = $acc->fetch($this->accountid);
698 if ($result <= 0) {
699 dol_print_error($this->db);
700 }
701
702 if ($this->amount > 0) {
703 $bank_line_id = $acc->addline($this->datep, (string) $this->type_payment, $this->label, -abs((float) $this->amount), $this->num_payment, 0, $user);
704 } else {
705 $bank_line_id = $acc->addline($this->datep, (string) $this->type_payment, $this->label, abs((float) $this->amount), $this->num_payment, 0, $user);
706 }
707
708 // Update fk_bank into llx_tva. So we know vat line used to generate bank transaction
709 if ($bank_line_id > 0) {
710 $this->update_fk_bank($bank_line_id);
711 } else {
712 $this->error = $acc->error;
713 $ok = 0;
714 }
715
716 // Update links
717 $result = $acc->add_url_line($bank_line_id, $this->id, DOL_URL_ROOT.'/compta/tva/card.php?id=', "(VATPayment)", "payment_vat");
718 if ($result < 0) {
719 $this->error = $acc->error;
720 $ok = 0;
721 }
722 }
723
724 if ($ok) {
725 $this->db->commit();
726 return $this->id;
727 } else {
728 $this->db->rollback();
729 return -3;
730 }
731 } else {
732 $this->db->rollback();
733 return -2;
734 }
735 } else {
736 $this->error = $this->db->error();
737 $this->db->rollback();
738 return -1;
739 }
740 }
741
742 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
749 public function update_fk_bank($id_bank)
750 {
751 // phpcs:enable
752 $sql = 'UPDATE '.MAIN_DB_PREFIX.'tva SET fk_bank = '.(int) $id_bank;
753 $sql .= ' WHERE rowid = '.(int) $this->id;
754 $result = $this->db->query($sql);
755 if ($result) {
756 return 1;
757 } else {
758 dol_print_error($this->db);
759 return -1;
760 }
761 }
762
773 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
774 {
775 global $langs, $conf;
776
777 if (!empty($conf->dol_no_mouse_hover)) {
778 $notooltip = 1; // Force disable tooltips
779 }
780
781 $result = '';
782
783 $label = '<u>'.$langs->trans("ShowVatPayment").'</u>';
784 $label .= '<br>';
785 $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
786 if (!empty($this->label)) {
787 $label .= '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
788 }
789
790 $url = DOL_URL_ROOT.'/compta/tva/card.php?id='.$this->id;
791
792 if ($option != 'nolink') {
793 // Add param to save lastsearch_values or not
794 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
795 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
796 $add_save_lastsearch_values = 1;
797 }
798 if ($add_save_lastsearch_values) {
799 $url .= '&save_lastsearch_values=1';
800 }
801 }
802
803 $linkclose = '';
804 if (empty($notooltip)) {
805 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
806 $label = $langs->trans("ShowMyObject");
807 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
808 }
809 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
810 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
811 } else {
812 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
813 }
814
815 $linkstart = '<a href="'.$url.'"';
816 $linkstart .= $linkclose.'>';
817 $linkend = '</a>';
818
819 $picto = 'payment';
820
821 $result .= $linkstart;
822 if ($withpicto) {
823 $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);
824 }
825 if ($withpicto != 2) {
826 $result .= $this->ref;
827 }
828 $result .= $linkend;
829
830 return $result;
831 }
832
838 public function getSommePaiement()
839 {
840 $table = 'payment_vat';
841 $field = 'fk_tva';
842
843 $sql = 'SELECT sum(amount) as amount';
844 $sql .= ' FROM '.MAIN_DB_PREFIX.$table;
845 $sql .= " WHERE ".$field." = ".((int) $this->id);
846
847 dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG);
848 $resql = $this->db->query($sql);
849 if ($resql) {
850 $amount = 0;
851
852 $obj = $this->db->fetch_object($resql);
853 if ($obj) {
854 $amount = $obj->amount ? $obj->amount : 0;
855 }
856
857 $this->db->free($resql);
858 return $amount;
859 } else {
860 return -1;
861 }
862 }
863
870 public function info($id)
871 {
872 $sql = "SELECT t.rowid, t.tms, t.fk_user_modif, t.datec, t.fk_user_creat";
873 $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
874 $sql .= " WHERE t.rowid = ".(int) $id;
875
876 dol_syslog(get_class($this)."::info", LOG_DEBUG);
877 $result = $this->db->query($sql);
878 if ($result) {
879 if ($this->db->num_rows($result)) {
880 $obj = $this->db->fetch_object($result);
881
882 $this->id = $obj->rowid;
883
884 $this->user_creation_id = $obj->fk_user_creat;
885 $this->user_modification_id = $obj->fk_user_modif;
886 $this->date_creation = $this->db->jdate($obj->datec);
887 $this->date_modification = $this->db->jdate($obj->tms);
888 }
889
890 $this->db->free($result);
891 } else {
892 dol_print_error($this->db);
893 }
894 }
895
903 public function getLibStatut($mode = 0, $alreadypaid = -1)
904 {
905 return $this->LibStatut($this->paye, $mode, $alreadypaid);
906 }
907
908 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
917 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
918 {
919 // phpcs:enable
920 global $langs;
921
922 // Load translation files required by the page
923 $langs->loadLangs(array("customers", "bills"));
924
925 // We reinit status array to force to redefine them because label may change according to properties values.
926 $this->labelStatus = array();
927 $this->labelStatusShort = array();
928
929 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
930 global $langs;
931 //$langs->load("mymodule");
932 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
933 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
934 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
935 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
936 }
937 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
938 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
939 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
940 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
941 }
942 }
943
944 $statusType = 'status1';
945 if ($status == 0 && $alreadypaid != 0) {
946 $statusType = 'status3';
947 }
948 if ($status == 1) {
949 $statusType = 'status6';
950 }
951
952 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
953 }
954
962 public function getKanbanView($option = '', $arraydata = null)
963 {
964 global $langs;
965
966 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
967
968 $return = '<div class="box-flex-item box-flex-grow-zero">';
969 $return .= '<div class="info-box info-box-sm">';
970 $return .= '<span class="info-box-icon bg-infobox-action">';
971 $return .= img_picto('', $this->picto);
972 //$return .= '<i class="fa fa-dol-action"></i>'; // Can be image
973 $return .= '</span>';
974 $return .= '<div class="info-box-content">';
975 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</span>';
976 if ($selected >= 0) {
977 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
978 }
979 if (property_exists($this, 'amount')) {
980 $return .= ' | <span class="opacitymedium">'.$langs->trans("Amount").'</span> : <span class="info-box-label amount">'.price($this->amount).'</span>';
981 }
982 if (property_exists($this, 'type_payment')) {
983 $return .= '<br><span class="opacitymedium">'.$langs->trans("Payement").'</span> : <span class="info-box-label">'.$this->type_payment.'</span>';
984 }
985 if (property_exists($this, 'datev')) {
986 $return .= '<br><span class="opacitymedium">'.$langs->trans("DateEnd").'</span> : <span class="info-box-label" >'.dol_print_date($this->datev).'</span>';
987 }
988 if (method_exists($this, 'LibStatut')) {
989 $return .= '<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3, $this->alreadypaid).'</div>';
990 }
991 $return .= '</div>';
992 $return .= '</div>';
993 $return .= '</div>';
994 return $return;
995 }
996}
$object ref
Definition info.php:90
Class to manage bank accounts.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage VAT - Value-added tax (also known in French as TVA - Taxe sur la valeur ajoutée)
Definition tva.class.php:38
is_erasable()
Return if a VAT declaration can be deleted: not once a payment exists, as for invoices.
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.
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_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79