29require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40 public $element =
'tva';
45 public $table_element =
'tva';
50 public $picto =
'payment';
88 public $fk_user_creat;
93 public $fk_user_modif;
101 const STATUS_UNPAID = 0;
102 const STATUS_PAID = 1;
123 global $conf, $langs;
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;
143 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"tva(";
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);
169 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
170 $resql = $this->db->query($sql);
172 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"tva");
185 $this->db->rollback();
189 $this->error =
"Error ".$this->db->lasterror();
190 $this->db->rollback();
202 public function update($user, $notrigger = 0)
204 global $conf, $langs;
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;
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);
232 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
233 $resql = $this->db->query($sql);
235 $this->error =
"Error ".$this->db->lasterror();
239 if (!$error && !$notrigger) {
252 $this->db->rollback();
266 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"tva SET";
268 $sql .=
" WHERE rowid = ".((int) $this->
id);
269 $resql = $this->db->query($sql);
286 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"tva SET";
288 $sql .=
" WHERE rowid = ".((int) $this->
id);
289 $resql = $this->db->query($sql);
305 public function fetch($id, $ref =
'')
312 $sql .=
" t.amount,";
313 $sql .=
" t.fk_typepayment,";
314 $sql .=
" t.num_payment,";
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);
324 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
326 $resql = $this->db->query($sql);
328 if ($this->db->num_rows($resql)) {
329 $obj = $this->db->fetch_object($resql);
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;
348 $this->db->free($resql);
352 $this->error =
"Error ".$this->db->lasterror();
364 public function delete($user)
366 global $conf, $langs;
377 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"tva";
378 $sql .=
" WHERE rowid=".((int) $this->
id);
380 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
381 $resql = $this->db->query($sql);
383 $this->error =
"Error ".$this->db->lasterror();
410 $this->fk_user_creat =
'';
411 $this->fk_user_modif =
'';
429 $solde = $reglee - ($collectee - $payee);
445 $sql =
"SELECT sum(f.total_tva) as amount";
446 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.paye = 1";
448 $sql .=
" AND f.datef >= '".$this->db->escape($year).
"-01-01' AND f.datef <= '".$this->db->escape($year).
"-12-31' ";
451 $result = $this->db->query($sql);
453 if ($this->db->num_rows($result)) {
454 $obj = $this->db->fetch_object($result);
456 $this->db->free($result);
459 $this->db->free($result);
463 print $this->db->lasterror();
479 $sql =
"SELECT sum(f.total_tva) as total_tva";
480 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
482 $sql .=
" WHERE f.datef >= '".$this->db->escape($year).
"-01-01' AND f.datef <= '".$this->db->escape($year).
"-12-31' ";
485 $result = $this->db->query($sql);
487 if ($this->db->num_rows($result)) {
488 $obj = $this->db->fetch_object($result);
489 $ret = $obj->total_tva;
490 $this->db->free($result);
493 $this->db->free($result);
497 print $this->db->lasterror();
514 $sql =
"SELECT sum(f.amount) as amount";
515 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as f";
518 $sql .=
" WHERE f.datev >= '".$this->db->escape($year).
"-01-01' AND f.datev <= '".$this->db->escape($year).
"-12-31' ";
521 $result = $this->db->query($sql);
523 if ($this->db->num_rows($result)) {
524 $obj = $this->db->fetch_object($result);
526 $this->db->free($result);
529 $this->db->free($result);
533 print $this->db->lasterror();
547 global $conf, $langs;
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)) {
565 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
568 if ($this->amount ==
'') {
569 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
572 if (isModEnabled(
"banque") && (empty($this->accountid) || $this->accountid <= 0)) {
573 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Account"));
576 if (isModEnabled(
"banque") && (empty($this->type_payment) || $this->type_payment <= 0)) {
577 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
582 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"tva (";
587 $sql .=
", fk_typepayment";
588 $sql .=
", num_payment";
595 $sql .=
", fk_user_creat";
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).
"'";
607 $sql .=
", '".$this->db->escape($this->note).
"'";
610 $sql .=
", '".$this->db->escape($this->label).
"'";
612 $sql .=
", '".$this->db->escape($user->id).
"'";
614 $sql .=
", ".((int) $conf->entity);
617 dol_syslog(get_class($this).
"::addPayment", LOG_DEBUG);
618 $result = $this->db->query($sql);
620 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"tva");
633 if (isModEnabled(
"banque") && !empty($this->amount)) {
635 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
638 $result = $acc->fetch($this->accountid);
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);
646 $bank_line_id = $acc->addline($this->datep, $this->type_payment, $this->label, abs($this->amount), $this->num_payment,
'', $user);
650 if ($bank_line_id > 0) {
653 $this->error = $acc->error;
658 $result = $acc->add_url_line($bank_line_id, $this->
id, DOL_URL_ROOT.
'/compta/tva/card.php?id=',
"(VATPayment)",
"payment_vat");
660 $this->error = $acc->error;
669 $this->db->rollback();
673 $this->db->rollback();
677 $this->error = $this->db->error();
678 $this->db->rollback();
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);
714 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
716 global $langs, $conf;
718 if (!empty($conf->dol_no_mouse_hover)) {
724 $label =
'<u>'.$langs->trans(
"ShowVatPayment").
'</u>';
726 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
727 if (!empty($this->label)) {
728 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
731 $url = DOL_URL_ROOT.
'/compta/tva/card.php?id='.$this->id;
733 if ($option !=
'nolink') {
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;
739 if ($add_save_lastsearch_values) {
740 $url .=
'&save_lastsearch_values=1';
745 if (empty($notooltip)) {
746 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
747 $label = $langs->trans(
"ShowMyObject");
748 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
750 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
751 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
753 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
756 $linkstart =
'<a href="'.$url.
'"';
757 $linkstart .= $linkclose.
'>';
762 $result .= $linkstart;
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);
766 if ($withpicto != 2) {
767 $result .= $this->ref;
781 $table =
'payment_vat';
784 $sql =
'SELECT sum(amount) as amount';
785 $sql .=
' FROM '.MAIN_DB_PREFIX.$table;
786 $sql .=
" WHERE ".$field.
" = ".((int) $this->
id);
788 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
789 $resql = $this->db->query($sql);
793 $obj = $this->db->fetch_object($resql);
795 $amount = $obj->amount ? $obj->amount : 0;
798 $this->db->free($resql);
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;
817 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
818 $result = $this->db->query($sql);
820 if ($this->db->num_rows($result)) {
821 $obj = $this->db->fetch_object($result);
823 $this->
id = $obj->rowid;
825 if ($obj->fk_user_creat) {
826 $cuser =
new User($this->db);
827 $cuser->fetch($obj->fk_user_creat);
828 $this->user_creation = $cuser;
831 if ($obj->fk_user_modif) {
832 $muser =
new User($this->db);
833 $muser->fetch($obj->fk_user_modif);
834 $this->user_modification = $muser;
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;
842 $this->db->free($result);
857 return $this->
LibStatut($this->paye, $mode, $alreadypaid);
869 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
875 $langs->loadLangs(array(
"customers",
"bills"));
878 $this->labelStatus = array();
879 $this->labelStatusShort = array();
881 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
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");
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");
896 $statusType =
'status1';
897 if ($status == 0 && $alreadypaid <> 0) {
898 $statusType =
'status3';
901 $statusType =
'status6';
904 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
918 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
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">';
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>';
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>';
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>';
938 if (method_exists($this,
'LibStatut')) {
939 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3, $this->alreadypaid).
'</div>';
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.
Put here description of your class.
getKanbanView($option='', $arraydata=null)
Return clicable 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 payed.
setUnpaid($user)
Remove tag payed 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 clicable (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 payed completely.
initAsSpecimen()
Initialise an instance with random values.
info($id)
Informations of vat payment object.
create($user)
Create in database.
tva_sum_reglee($year=0)
Total of the VAT payed.
Class to manage Dolibarr users.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
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='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.