dolibarr  18.0.0
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 Frédéric France <frederic.france@netlogic.fr>
7  * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
28 // Put here all includes required by your class file
29 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
30 
31 
35 class Tva extends CommonObject
36 {
40  public $element = 'tva';
41 
45  public $table_element = 'tva';
46 
50  public $picto = 'payment';
51 
56  public $total;
57 
58  public $tms;
59  public $datep;
60  public $datev;
61  public $amount;
62  public $type_payment;
63  public $num_payment;
64 
68  public $totalpaid;
69 
73  public $label;
74 
78  public $fk_bank;
79 
83  public $accountid;
84 
88  public $fk_user_creat;
89 
93  public $fk_user_modif;
94 
98  public $paiementtype;
99 
100 
101  const STATUS_UNPAID = 0;
102  const STATUS_PAID = 1;
103 
109  public function __construct($db)
110  {
111  $this->db = $db;
112  }
113 
114 
121  public function create($user)
122  {
123  global $conf, $langs;
124 
125  $error = 0;
126  $now = dol_now();
127 
128  // Clean parameters
129  $this->amount = trim($this->amount);
130  $this->label = trim($this->label);
131  $this->type_payment = (int) $this->type_payment;
132  $this->note = trim($this->note);
133  $this->fk_account = (int) $this->fk_account;
134  $this->fk_user_creat = (int) $this->fk_user_creat;
135  $this->fk_user_modif = (int) $this->fk_user_modif;
136 
137  // Check parameters
138  // Put here code to add control on parameters values
139 
140  $this->db->begin();
141 
142  // Insert request
143  $sql = "INSERT INTO ".MAIN_DB_PREFIX."tva(";
144  $sql .= "entity,";
145  $sql .= "datec,";
146  $sql .= "datep,";
147  $sql .= "datev,";
148  $sql .= "amount,";
149  $sql .= "label,";
150  $sql .= "note,";
151  $sql .= "fk_account,";
152  $sql .= "fk_typepayment,";
153  $sql .= "fk_user_creat,";
154  $sql .= "fk_user_modif";
155  $sql .= ") VALUES (";
156  $sql .= " ".((int) $conf->entity).", ";
157  $sql .= " '".$this->db->idate($now)."',";
158  $sql .= " '".$this->db->idate($this->datep)."',";
159  $sql .= " '".$this->db->idate($this->datev)."',";
160  $sql .= " '".$this->db->escape($this->amount)."',";
161  $sql .= " '".$this->db->escape($this->label)."',";
162  $sql .= " '".$this->db->escape($this->note)."',";
163  $sql .= " '".$this->db->escape($this->fk_account)."',";
164  $sql .= " '".$this->db->escape($this->type_payment)."',";
165  $sql .= " ".($this->fk_user_creat > 0 ? (int) $this->fk_user_creat : (int) $user->id).",";
166  $sql .= " ".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : (int) $user->id);
167  $sql .= ")";
168 
169  dol_syslog(get_class($this)."::create", LOG_DEBUG);
170  $resql = $this->db->query($sql);
171  if ($resql) {
172  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."tva");
173 
174  // Call trigger
175  $result = $this->call_trigger('TVA_CREATE', $user);
176  if ($result < 0) {
177  $error++;
178  }
179  // End call triggers
180 
181  if (!$error) {
182  $this->db->commit();
183  return $this->id;
184  } else {
185  $this->db->rollback();
186  return -1;
187  }
188  } else {
189  $this->error = "Error ".$this->db->lasterror();
190  $this->db->rollback();
191  return -1;
192  }
193  }
194 
202  public function update($user, $notrigger = 0)
203  {
204  global $conf, $langs;
205 
206  $error = 0;
207 
208  // Clean parameters
209  $this->amount = trim($this->amount);
210  $this->label = trim($this->label);
211  $this->note = trim($this->note);
212  $this->fk_user_creat = (int) $this->fk_user_creat;
213  $this->fk_user_modif = (int) $this->fk_user_modif;
214 
215  // Check parameters
216  // Put here code to add control on parameters values
217 
218  $this->db->begin();
219 
220  // Update request
221  $sql = "UPDATE ".MAIN_DB_PREFIX."tva SET";
222  $sql .= " tms='".$this->db->idate($this->tms)."',";
223  $sql .= " datep='".$this->db->idate($this->datep)."',";
224  $sql .= " datev='".$this->db->idate($this->datev)."',";
225  $sql .= " amount=".price2num($this->amount).",";
226  $sql .= " label='".$this->db->escape($this->label)."',";
227  $sql .= " note='".$this->db->escape($this->note)."',";
228  $sql .= " fk_user_creat=".((int) $this->fk_user_creat).",";
229  $sql .= " fk_user_modif=".((int) ($this->fk_user_modif > 0 ? $this->fk_user_modif : $user->id));
230  $sql .= " WHERE rowid=".((int) $this->id);
231 
232  dol_syslog(get_class($this)."::update", LOG_DEBUG);
233  $resql = $this->db->query($sql);
234  if (!$resql) {
235  $this->error = "Error ".$this->db->lasterror();
236  $error++;
237  }
238 
239  if (!$error && !$notrigger) {
240  // Call trigger
241  $result = $this->call_trigger('TVA_MODIFY', $user);
242  if ($result < 0) {
243  $error++;
244  }
245  // End call triggers
246  }
247 
248  if (!$error) {
249  $this->db->commit();
250  return 1;
251  } else {
252  $this->db->rollback();
253  return -1;
254  }
255  }
256 
263  public function setPaid($user)
264  {
265  // phpcs:enable
266  $sql = "UPDATE ".MAIN_DB_PREFIX."tva SET";
267  $sql .= " paye = 1";
268  $sql .= " WHERE rowid = ".((int) $this->id);
269  $resql = $this->db->query($sql);
270  if ($resql) {
271  return 1;
272  } else {
273  return -1;
274  }
275  }
276 
283  public function setUnpaid($user)
284  {
285  // phpcs:enable
286  $sql = "UPDATE ".MAIN_DB_PREFIX."tva SET";
287  $sql .= " paye = 0";
288  $sql .= " WHERE rowid = ".((int) $this->id);
289  $resql = $this->db->query($sql);
290  if ($resql) {
291  return 1;
292  } else {
293  return -1;
294  }
295  }
296 
297 
305  public function fetch($id, $ref = '')
306  {
307  $sql = "SELECT";
308  $sql .= " t.rowid,";
309  $sql .= " t.tms,";
310  $sql .= " t.datep,";
311  $sql .= " t.datev,";
312  $sql .= " t.amount,";
313  $sql .= " t.fk_typepayment,";
314  $sql .= " t.num_payment,";
315  $sql .= " t.label,";
316  $sql .= " t.note,";
317  $sql .= " t.paye,";
318  $sql .= " t.fk_user_creat,";
319  $sql .= " t.fk_user_modif,";
320  $sql .= " t.fk_account";
321  $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
322  $sql .= " WHERE t.rowid = ".((int) $id);
323 
324  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
325 
326  $resql = $this->db->query($sql);
327  if ($resql) {
328  if ($this->db->num_rows($resql)) {
329  $obj = $this->db->fetch_object($resql);
330 
331  $this->id = $obj->rowid;
332  $this->ref = $obj->rowid;
333  $this->tms = $this->db->jdate($obj->tms);
334  $this->datep = $this->db->jdate($obj->datep);
335  $this->datev = $this->db->jdate($obj->datev);
336  $this->amount = $obj->amount;
337  $this->type_payment = $obj->fk_typepayment;
338  $this->num_payment = $obj->num_payment;
339  $this->label = $obj->label;
340  $this->paye = $obj->paye;
341  $this->note = $obj->note;
342  $this->fk_user_creat = $obj->fk_user_creat;
343  $this->fk_user_modif = $obj->fk_user_modif;
344  $this->fk_account = $obj->fk_account;
345  $this->fk_type = empty($obj->fk_type) ? "" : $obj->fk_type;
346  $this->rappro = empty($obj->rappro) ? "" : $obj->rappro;
347  }
348  $this->db->free($resql);
349 
350  return 1;
351  } else {
352  $this->error = "Error ".$this->db->lasterror();
353  return -1;
354  }
355  }
356 
357 
364  public function delete($user)
365  {
366  global $conf, $langs;
367 
368  $error = 0;
369 
370  // Call trigger
371  $result = $this->call_trigger('TVA_DELETE', $user);
372  if ($result < 0) {
373  return -1;
374  }
375  // End call triggers
376 
377  $sql = "DELETE FROM ".MAIN_DB_PREFIX."tva";
378  $sql .= " WHERE rowid=".((int) $this->id);
379 
380  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
381  $resql = $this->db->query($sql);
382  if (!$resql) {
383  $this->error = "Error ".$this->db->lasterror();
384  return -1;
385  }
386 
387 
388  return 1;
389  }
390 
391 
399  public function initAsSpecimen()
400  {
401  $this->id = 0;
402 
403  $this->tms = '';
404  $this->datep = '';
405  $this->datev = '';
406  $this->amount = '';
407  $this->label = '';
408  $this->note = '';
409  $this->fk_bank = '';
410  $this->fk_user_creat = '';
411  $this->fk_user_modif = '';
412  }
413 
414 
421  public function solde($year = 0)
422  {
423 
424  $reglee = $this->tva_sum_reglee($year);
425 
426  $payee = $this->tva_sum_payee($year);
427  $collectee = $this->tva_sum_collectee($year);
428 
429  $solde = $reglee - ($collectee - $payee);
430 
431  return $solde;
432  }
433 
434  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
441  public function tva_sum_collectee($year = 0)
442  {
443  // phpcs:enable
444 
445  $sql = "SELECT sum(f.total_tva) as amount";
446  $sql .= " FROM ".MAIN_DB_PREFIX."facture as f WHERE f.paye = 1";
447  if ($year) {
448  $sql .= " AND f.datef >= '".$this->db->escape($year)."-01-01' AND f.datef <= '".$this->db->escape($year)."-12-31' ";
449  }
450 
451  $result = $this->db->query($sql);
452  if ($result) {
453  if ($this->db->num_rows($result)) {
454  $obj = $this->db->fetch_object($result);
455  $ret = $obj->amount;
456  $this->db->free($result);
457  return $ret;
458  } else {
459  $this->db->free($result);
460  return 0;
461  }
462  } else {
463  print $this->db->lasterror();
464  return -1;
465  }
466  }
467 
468  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
475  public function tva_sum_payee($year = 0)
476  {
477  // phpcs:enable
478 
479  $sql = "SELECT sum(f.total_tva) as total_tva";
480  $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f";
481  if ($year) {
482  $sql .= " WHERE f.datef >= '".$this->db->escape($year)."-01-01' AND f.datef <= '".$this->db->escape($year)."-12-31' ";
483  }
484 
485  $result = $this->db->query($sql);
486  if ($result) {
487  if ($this->db->num_rows($result)) {
488  $obj = $this->db->fetch_object($result);
489  $ret = $obj->total_tva;
490  $this->db->free($result);
491  return $ret;
492  } else {
493  $this->db->free($result);
494  return 0;
495  }
496  } else {
497  print $this->db->lasterror();
498  return -1;
499  }
500  }
501 
502 
503  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
510  public function tva_sum_reglee($year = 0)
511  {
512  // phpcs:enable
513 
514  $sql = "SELECT sum(f.amount) as amount";
515  $sql .= " FROM ".MAIN_DB_PREFIX."tva as f";
516 
517  if ($year) {
518  $sql .= " WHERE f.datev >= '".$this->db->escape($year)."-01-01' AND f.datev <= '".$this->db->escape($year)."-12-31' ";
519  }
520 
521  $result = $this->db->query($sql);
522  if ($result) {
523  if ($this->db->num_rows($result)) {
524  $obj = $this->db->fetch_object($result);
525  $ret = $obj->amount;
526  $this->db->free($result);
527  return $ret;
528  } else {
529  $this->db->free($result);
530  return 0;
531  }
532  } else {
533  print $this->db->lasterror();
534  return -1;
535  }
536  }
537 
538 
545  public function addPayment($user)
546  {
547  global $conf, $langs;
548 
549  $this->db->begin();
550 
551  // Clean parameters
552  $this->amount = price2num(trim($this->amount));
553  $this->label = trim($this->label);
554  $this->note = trim($this->note);
555  $this->num_payment = trim($this->num_payment);
556  $this->fk_bank = (int) $this->fk_bank;
557  $this->fk_user_creat = (int) $this->fk_user_creat;
558  $this->fk_user_modif = (int) $this->fk_user_modif;
559  if (empty($this->datec)) {
560  $this->datec = dol_now();
561  }
562 
563  // Check parameters
564  if (!$this->label) {
565  $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
566  return -3;
567  }
568  if ($this->amount == '') {
569  $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
570  return -4;
571  }
572  if (isModEnabled("banque") && (empty($this->accountid) || $this->accountid <= 0)) {
573  $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Account"));
574  return -5;
575  }
576  if (isModEnabled("banque") && (empty($this->type_payment) || $this->type_payment <= 0)) {
577  $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
578  return -5;
579  }
580 
581  // Insert into llx_tva
582  $sql = "INSERT INTO ".MAIN_DB_PREFIX."tva (";
583  $sql .= "datec";
584  $sql .= ", datep";
585  $sql .= ", datev";
586  $sql .= ", amount";
587  $sql .= ", fk_typepayment";
588  $sql .= ", num_payment";
589  if ($this->note) {
590  $sql .= ", note";
591  }
592  if ($this->label) {
593  $sql .= ", label";
594  }
595  $sql .= ", fk_user_creat";
596  $sql .= ", fk_bank";
597  $sql .= ", entity";
598  $sql .= ") ";
599  $sql .= " VALUES (";
600  $sql .= " '".$this->db->idate($this->datec)."'";
601  $sql .= ", '".$this->db->idate($this->datep)."'";
602  $sql .= ", '".$this->db->idate($this->datev)."'";
603  $sql .= ", ".((float) $this->amount);
604  $sql .= ", '".$this->db->escape($this->type_payment)."'";
605  $sql .= ", '".$this->db->escape($this->num_payment)."'";
606  if ($this->note) {
607  $sql .= ", '".$this->db->escape($this->note)."'";
608  }
609  if ($this->label) {
610  $sql .= ", '".$this->db->escape($this->label)."'";
611  }
612  $sql .= ", '".$this->db->escape($user->id)."'";
613  $sql .= ", NULL";
614  $sql .= ", ".((int) $conf->entity);
615  $sql .= ")";
616 
617  dol_syslog(get_class($this)."::addPayment", LOG_DEBUG);
618  $result = $this->db->query($sql);
619  if ($result) {
620  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."tva"); // TODO should be called 'payment_vat'
621 
622  // Call trigger
623  //XXX: Should be done just befor commit no ?
624  $result = $this->call_trigger('TVA_ADDPAYMENT', $user);
625  if ($result < 0) {
626  $this->id = 0;
627  $ok = 0;
628  }
629  // End call triggers
630 
631  if ($this->id > 0) {
632  $ok = 1;
633  if (isModEnabled("banque") && !empty($this->amount)) {
634  // Insert into llx_bank
635  require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
636 
637  $acc = new Account($this->db);
638  $result = $acc->fetch($this->accountid);
639  if ($result <= 0) {
640  dol_print_error($this->db);
641  }
642 
643  if ($this->amount > 0) {
644  $bank_line_id = $acc->addline($this->datep, $this->type_payment, $this->label, -abs($this->amount), $this->num_payment, '', $user);
645  } else {
646  $bank_line_id = $acc->addline($this->datep, $this->type_payment, $this->label, abs($this->amount), $this->num_payment, '', $user);
647  }
648 
649  // Update fk_bank into llx_tva. So we know vat line used to generate bank transaction
650  if ($bank_line_id > 0) {
651  $this->update_fk_bank($bank_line_id);
652  } else {
653  $this->error = $acc->error;
654  $ok = 0;
655  }
656 
657  // Update links
658  $result = $acc->add_url_line($bank_line_id, $this->id, DOL_URL_ROOT.'/compta/tva/card.php?id=', "(VATPayment)", "payment_vat");
659  if ($result < 0) {
660  $this->error = $acc->error;
661  $ok = 0;
662  }
663  }
664 
665  if ($ok) {
666  $this->db->commit();
667  return $this->id;
668  } else {
669  $this->db->rollback();
670  return -3;
671  }
672  } else {
673  $this->db->rollback();
674  return -2;
675  }
676  } else {
677  $this->error = $this->db->error();
678  $this->db->rollback();
679  return -1;
680  }
681  }
682 
683  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
690  public function update_fk_bank($id_bank)
691  {
692  // phpcs:enable
693  $sql = 'UPDATE '.MAIN_DB_PREFIX.'tva SET fk_bank = '.(int) $id_bank;
694  $sql .= ' WHERE rowid = '.(int) $this->id;
695  $result = $this->db->query($sql);
696  if ($result) {
697  return 1;
698  } else {
699  dol_print_error($this->db);
700  return -1;
701  }
702  }
703 
714  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
715  {
716  global $langs, $conf;
717 
718  if (!empty($conf->dol_no_mouse_hover)) {
719  $notooltip = 1; // Force disable tooltips
720  }
721 
722  $result = '';
723 
724  $label = '<u>'.$langs->trans("ShowVatPayment").'</u>';
725  $label .= '<br>';
726  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
727  if (!empty($this->label)) {
728  $label .= '<br><b>'.$langs->trans('Label').':</b> '.$this->label;
729  }
730 
731  $url = DOL_URL_ROOT.'/compta/tva/card.php?id='.$this->id;
732 
733  if ($option != 'nolink') {
734  // Add param to save lastsearch_values or not
735  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
736  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
737  $add_save_lastsearch_values = 1;
738  }
739  if ($add_save_lastsearch_values) {
740  $url .= '&save_lastsearch_values=1';
741  }
742  }
743 
744  $linkclose = '';
745  if (empty($notooltip)) {
746  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
747  $label = $langs->trans("ShowMyObject");
748  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
749  }
750  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
751  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
752  } else {
753  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
754  }
755 
756  $linkstart = '<a href="'.$url.'"';
757  $linkstart .= $linkclose.'>';
758  $linkend = '</a>';
759 
760  $picto = 'payment';
761 
762  $result .= $linkstart;
763  if ($withpicto) {
764  $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);
765  }
766  if ($withpicto != 2) {
767  $result .= $this->ref;
768  }
769  $result .= $linkend;
770 
771  return $result;
772  }
773 
779  public function getSommePaiement()
780  {
781  $table = 'payment_vat';
782  $field = 'fk_tva';
783 
784  $sql = 'SELECT sum(amount) as amount';
785  $sql .= ' FROM '.MAIN_DB_PREFIX.$table;
786  $sql .= " WHERE ".$field." = ".((int) $this->id);
787 
788  dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG);
789  $resql = $this->db->query($sql);
790  if ($resql) {
791  $amount = 0;
792 
793  $obj = $this->db->fetch_object($resql);
794  if ($obj) {
795  $amount = $obj->amount ? $obj->amount : 0;
796  }
797 
798  $this->db->free($resql);
799  return $amount;
800  } else {
801  return -1;
802  }
803  }
804 
811  public function info($id)
812  {
813  $sql = "SELECT t.rowid, t.tms, t.fk_user_modif, t.datec, t.fk_user_creat";
814  $sql .= " FROM ".MAIN_DB_PREFIX."tva as t";
815  $sql .= " WHERE t.rowid = ".(int) $id;
816 
817  dol_syslog(get_class($this)."::info", LOG_DEBUG);
818  $result = $this->db->query($sql);
819  if ($result) {
820  if ($this->db->num_rows($result)) {
821  $obj = $this->db->fetch_object($result);
822 
823  $this->id = $obj->rowid;
824 
825  if ($obj->fk_user_creat) {
826  $cuser = new User($this->db);
827  $cuser->fetch($obj->fk_user_creat);
828  $this->user_creation = $cuser;
829  }
830 
831  if ($obj->fk_user_modif) {
832  $muser = new User($this->db);
833  $muser->fetch($obj->fk_user_modif);
834  $this->user_modification = $muser;
835  }
836 
837  $this->date_creation = $this->db->jdate($obj->datec);
838  $this->date_modification = $this->db->jdate($obj->tms);
839  $this->import_key = $obj->import_key;
840  }
841 
842  $this->db->free($result);
843  } else {
844  dol_print_error($this->db);
845  }
846  }
847 
855  public function getLibStatut($mode = 0, $alreadypaid = -1)
856  {
857  return $this->LibStatut($this->paye, $mode, $alreadypaid);
858  }
859 
860  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
869  public function LibStatut($status, $mode = 0, $alreadypaid = -1)
870  {
871  // phpcs:enable
872  global $langs;
873 
874  // Load translation files required by the page
875  $langs->loadLangs(array("customers", "bills"));
876 
877  // We reinit status array to force to redefine them because label may change according to properties values.
878  $this->labelStatus = array();
879  $this->labelStatusShort = array();
880 
881  if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
882  global $langs;
883  //$langs->load("mymodule");
884  $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
885  $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
886  if ($status == self::STATUS_UNPAID && $alreadypaid <> 0) {
887  $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
888  }
889  $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv('BillStatusNotPaid');
890  $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv('BillStatusPaid');
891  if ($status == self::STATUS_UNPAID && $alreadypaid <> 0) {
892  $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv("BillStatusStarted");
893  }
894  }
895 
896  $statusType = 'status1';
897  if ($status == 0 && $alreadypaid <> 0) {
898  $statusType = 'status3';
899  }
900  if ($status == 1) {
901  $statusType = 'status6';
902  }
903 
904  return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
905  }
906 
914  public function getKanbanView($option = '', $arraydata = null)
915  {
916  global $langs;
917 
918  $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
919 
920  $return = '<div class="box-flex-item box-flex-grow-zero">';
921  $return .= '<div class="info-box info-box-sm">';
922  $return .= '<span class="info-box-icon bg-infobox-action">';
923  $return .= img_picto('', $this->picto);
924  //$return .= '<i class="fa fa-dol-action"></i>'; // Can be image
925  $return .= '</span>';
926  $return .= '<div class="info-box-content">';
927  $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1) : $this->ref).'</span>';
928  $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
929  if (property_exists($this, 'amount')) {
930  $return .= ' | <span class="opacitymedium">'.$langs->trans("Amount").'</span> : <span class="info-box-label amount">'.price($this->amount).'</span>';
931  }
932  if (property_exists($this, 'type_payment')) {
933  $return .= '<br><span class="opacitymedium">'.$langs->trans("Payement").'</span> : <span class="info-box-label">'.$this->type_payment.'</span>';
934  }
935  if (property_exists($this, 'datev')) {
936  $return .= '<br><span class="opacitymedium">'.$langs->trans("DateEnd").'</span> : <span class="info-box-label" >'.dol_print_date($this->datev).'</span>';
937  }
938  if (method_exists($this, 'LibStatut')) {
939  $return .= '<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3, $this->alreadypaid).'</div>';
940  }
941  $return .= '</div>';
942  $return .= '</div>';
943  $return .= '</div>';
944  return $return;
945  }
946 }
Tva\getSommePaiement
getSommePaiement()
Return amount of payments already done.
Definition: tva.class.php:779
Tva\fetch
fetch($id, $ref='')
Load object in memory from database.
Definition: tva.class.php:305
Tva\getKanbanView
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
Definition: tva.class.php:914
Tva\initAsSpecimen
initAsSpecimen()
Initialise an instance with random values.
Definition: tva.class.php:399
Tva\solde
solde($year=0)
Balance of VAT.
Definition: tva.class.php:421
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:5107
Tva\__construct
__construct($db)
Constructor.
Definition: tva.class.php:109
Tva\create
create($user)
Create in database.
Definition: tva.class.php:121
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:45
Tva\setUnpaid
setUnpaid($user)
Remove tag payed on TVA.
Definition: tva.class.php:283
Tva\LibStatut
LibStatut($status, $mode=0, $alreadypaid=-1)
Return the label of a given VAT status.
Definition: tva.class.php:869
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5955
Tva\tva_sum_payee
tva_sum_payee($year=0)
VAT payed.
Definition: tva.class.php:475
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2675
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4135
Tva\addPayment
addPayment($user)
Create in database.
Definition: tva.class.php:545
Tva\setPaid
setPaid($user)
Tag TVA as payed completely.
Definition: tva.class.php:263
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1741
Tva\getLibStatut
getLibStatut($mode=0, $alreadypaid=-1)
Return the label of the VAT status f object.
Definition: tva.class.php:855
Tva\update
update($user, $notrigger=0)
Update database.
Definition: tva.class.php:202
Tva\tva_sum_collectee
tva_sum_collectee($year=0)
Total of the VAT from invoices emitted by the thirdparty.
Definition: tva.class.php:441
$sql
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
Tva\tva_sum_reglee
tva_sum_reglee($year=0)
Total of the VAT payed.
Definition: tva.class.php:510
Tva\update_fk_bank
update_fk_bank($id_bank)
Update link between payment tva and line generate into llx_bank.
Definition: tva.class.php:690
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:207
ref
$object ref
Definition: info.php:78
User
Class to manage Dolibarr users.
Definition: user.class.php:47
Tva\$total
$total
Definition: tva.class.php:56
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10967
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4473
Tva\info
info($id)
Informations of vat payment object.
Definition: tva.class.php:811
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:3056
price
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.
Definition: functions.lib.php:5829
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5770
Tva\getNomUrl
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Send name clicable (with possibly the picto)
Definition: tva.class.php:714
Account
Class to manage bank accounts.
Definition: account.class.php:40
Tva
Put here description of your class.
Definition: tva.class.php:35