28 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
39 public $element =
'tva';
44 public $table_element =
'tva';
49 public $picto =
'payment';
76 public $fk_user_creat;
81 public $fk_user_modif;
102 global $conf, $langs;
108 $this->amount = trim($this->amount);
109 $this->label = trim($this->label);
111 $this->fk_bank = (int) $this->fk_bank;
112 $this->fk_user_creat = (int) $this->fk_user_creat;
113 $this->fk_user_modif = (int) $this->fk_user_modif;
121 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"tva(";
129 $sql .=
"fk_user_creat,";
130 $sql .=
"fk_user_modif";
131 $sql .=
") VALUES (";
132 $sql .=
" '".$this->db->idate($now).
"',";
133 $sql .=
" '".$this->db->idate($this->datep).
"',";
134 $sql .=
" '".$this->db->idate($this->datev).
"',";
135 $sql .=
" '".$this->db->escape($this->amount).
"',";
136 $sql .=
" '".$this->db->escape($this->label).
"',";
137 $sql .=
" '".$this->db->escape($this->
note).
"',";
138 $sql .=
" ".($this->fk_bank <= 0 ?
"NULL" :
"'".$this->db->escape($this->fk_bank).
"'").
",";
139 $sql .=
" '".$this->db->escape($this->fk_user_creat).
"',";
140 $sql .=
" '".$this->db->escape($this->fk_user_modif).
"'";
143 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
147 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"tva");
151 if ($result < 0) $error++;
159 $this->
db->rollback();
163 $this->error =
"Error ".$this->db->lasterror();
164 $this->
db->rollback();
176 public function update($user, $notrigger = 0)
178 global $conf, $langs;
183 $this->amount = trim($this->amount);
184 $this->label = trim($this->label);
186 $this->fk_bank = (int) $this->fk_bank;
187 $this->fk_user_creat = (int) $this->fk_user_creat;
188 $this->fk_user_modif = (int) $this->fk_user_modif;
196 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"tva SET";
197 $sql .=
" tms='".$this->db->idate($this->tms).
"',";
198 $sql .=
" datep='".$this->db->idate($this->datep).
"',";
199 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
200 $sql .=
" amount=".price2num($this->amount).
",";
201 $sql .=
" label='".$this->db->escape($this->label).
"',";
202 $sql .=
" note='".$this->db->escape($this->
note).
"',";
203 $sql .=
" fk_bank=".$this->fk_bank.
",";
204 $sql .=
" fk_user_creat=".$this->fk_user_creat.
",";
205 $sql .=
" fk_user_modif=".($this->fk_user_modif > 0 ? $this->fk_user_modif : $user->id).
"";
206 $sql .=
" WHERE rowid=".$this->id;
208 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
212 $this->error =
"Error ".$this->db->lasterror();
216 if (!$error && !$notrigger)
220 if ($result < 0) $error++;
229 $this->
db->rollback();
242 public function fetch($id, $user = null)
251 $sql .=
" t.amount,";
252 $sql .=
" t.fk_typepayment,";
253 $sql .=
" t.num_payment,";
256 $sql .=
" t.fk_bank,";
257 $sql .=
" t.fk_user_creat,";
258 $sql .=
" t.fk_user_modif,";
259 $sql .=
" b.fk_account,";
260 $sql .=
" b.fk_type,";
263 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
264 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON t.fk_bank = b.rowid";
265 $sql .=
" WHERE t.rowid = ".$id;
267 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
273 $obj = $this->
db->fetch_object(
$resql);
275 $this->
id = $obj->rowid;
276 $this->ref = $obj->rowid;
277 $this->tms = $this->
db->jdate($obj->tms);
278 $this->datep = $this->
db->jdate($obj->datep);
279 $this->datev = $this->
db->jdate($obj->datev);
280 $this->amount = $obj->amount;
281 $this->type_payment = $obj->fk_typepayment;
282 $this->num_payment = $obj->num_payment;
283 $this->label = $obj->label;
284 $this->
note = $obj->note;
285 $this->fk_bank = $obj->fk_bank;
286 $this->fk_user_creat = $obj->fk_user_creat;
287 $this->fk_user_modif = $obj->fk_user_modif;
288 $this->fk_account = $obj->fk_account;
289 $this->fk_type = $obj->fk_type;
290 $this->rappro = $obj->rappro;
296 $this->error =
"Error ".$this->db->lasterror();
308 public function delete($user)
310 global $conf, $langs;
316 if ($result < 0)
return -1;
319 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"tva";
320 $sql .=
" WHERE rowid=".$this->id;
322 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
326 $this->error =
"Error ".$this->db->lasterror();
353 $this->fk_user_creat =
'';
354 $this->fk_user_modif =
'';
372 $solde = $reglee - ($collectee - $payee);
388 $sql =
"SELECT sum(f.tva) as amount";
389 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.paye = 1";
392 $sql .=
" AND f.datef >= '".$this->db->escape($year).
"-01-01' AND f.datef <= '".$this->
db->escape($year).
"-12-31' ";
395 $result = $this->
db->query($sql);
398 if ($this->
db->num_rows($result))
400 $obj = $this->
db->fetch_object($result);
402 $this->
db->free($result);
405 $this->
db->free($result);
425 $sql =
"SELECT sum(f.total_tva) as total_tva";
426 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
429 $sql .=
" WHERE f.datef >= '".$this->db->escape($year).
"-01-01' AND f.datef <= '".$this->
db->escape($year).
"-12-31' ";
432 $result = $this->
db->query($sql);
435 if ($this->
db->num_rows($result))
437 $obj = $this->
db->fetch_object($result);
438 $ret = $obj->total_tva;
439 $this->
db->free($result);
442 $this->
db->free($result);
463 $sql =
"SELECT sum(f.amount) as amount";
464 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as f";
468 $sql .=
" WHERE f.datev >= '".$this->db->escape($year).
"-01-01' AND f.datev <= '".$this->
db->escape($year).
"-12-31' ";
471 $result = $this->
db->query($sql);
474 if ($this->
db->num_rows($result))
476 $obj = $this->
db->fetch_object($result);
478 $this->
db->free($result);
481 $this->
db->free($result);
499 global $conf, $langs;
504 $this->amount =
price2num(trim($this->amount));
505 $this->label = trim($this->label);
507 $this->num_payment = trim($this->num_payment);
508 $this->fk_bank = (int) $this->fk_bank;
509 $this->fk_user_creat = (int) $this->fk_user_creat;
510 $this->fk_user_modif = (int) $this->fk_user_modif;
511 if (empty($this->datec)) $this->datec =
dol_now();
516 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
519 if ($this->amount ==
'')
521 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
524 if (!empty($conf->banque->enabled) && (empty($this->accountid) || $this->accountid <= 0))
526 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Account"));
529 if (!empty($conf->banque->enabled) && (empty($this->type_payment) || $this->type_payment <= 0))
531 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
536 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"tva (";
541 $sql .=
", fk_typepayment";
542 $sql .=
", num_payment";
543 if ($this->
note) $sql .=
", note";
544 if ($this->label) $sql .=
", label";
545 $sql .=
", fk_user_creat";
550 $sql .=
" '".$this->db->idate($this->datec).
"'";
551 $sql .=
", '".$this->db->idate($this->datep).
"'";
552 $sql .=
", '".$this->db->idate($this->datev).
"'";
553 $sql .=
", ".$this->amount;
554 $sql .=
", '".$this->db->escape($this->type_payment).
"'";
555 $sql .=
", '".$this->db->escape($this->num_payment).
"'";
556 if ($this->
note) $sql .=
", '".$this->db->escape($this->
note).
"'";
557 if ($this->label) $sql .=
", '".$this->db->escape($this->label).
"'";
558 $sql .=
", '".$this->db->escape($user->id).
"'";
560 $sql .=
", ".$conf->entity;
563 dol_syslog(get_class($this).
"::addPayment", LOG_DEBUG);
564 $result = $this->
db->query($sql);
567 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"tva");
582 if (!empty($conf->banque->enabled) && !empty($this->amount))
585 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
588 $result = $acc->fetch($this->accountid);
591 if ($this->amount > 0) {
592 $bank_line_id = $acc->addline($this->datep, $this->type_payment, $this->label, -abs($this->amount), $this->num_payment,
'', $user);
594 $bank_line_id = $acc->addline($this->datep, $this->type_payment, $this->label, abs($this->amount), $this->num_payment,
'', $user);
598 if ($bank_line_id > 0)
602 $this->error = $acc->error;
607 $result = $acc->add_url_line($bank_line_id, $this->
id, DOL_URL_ROOT.
'/compta/tva/card.php?id=',
"(VATPayment)",
"payment_vat");
610 $this->error = $acc->error;
620 $this->
db->rollback();
624 $this->
db->rollback();
628 $this->error = $this->
db->error();
629 $this->
db->rollback();
644 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'tva SET fk_bank = '.(int) $id_bank;
645 $sql .=
' WHERE rowid = '.(int) $this->
id;
646 $result = $this->
db->query($sql);
665 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'')
667 global $langs, $conf;
669 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
673 $label =
'<u>'.$langs->trans(
"ShowVatPayment").
'</u>';
675 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
677 $url = DOL_URL_ROOT.
'/compta/tva/card.php?id='.$this->id;
680 if (empty($notooltip))
682 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
684 $label = $langs->trans(
"ShowMyObject");
685 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
687 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
688 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
689 }
else $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
691 $linkstart =
'<a href="'.$url.
'"';
692 $linkstart .= $linkclose.
'>';
697 $result .= $linkstart;
698 if ($withpicto) $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);
699 if ($withpicto != 2) $result .= $this->ref;
712 $table =
'paiementcharge';
713 $field =
'fk_charge';
715 $sql =
'SELECT sum(amount) as amount';
716 $sql .=
' FROM '.MAIN_DB_PREFIX.$table;
717 $sql .=
' WHERE '.$field.
' = '.$this->id;
719 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
725 $obj = $this->
db->fetch_object(
$resql);
726 if ($obj) $amount = $obj->amount ? $obj->amount : 0;
743 $sql =
"SELECT t.rowid, t.tms, t.fk_user_modif, t.datec, t.fk_user_creat";
744 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
745 $sql .=
" WHERE t.rowid = ".(int) $id;
747 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
748 $result = $this->
db->query($sql);
751 if ($this->
db->num_rows($result))
753 $obj = $this->
db->fetch_object($result);
755 $this->
id = $obj->rowid;
757 if ($obj->fk_user_creat) {
758 $cuser =
new User($this->
db);
759 $cuser->fetch($obj->fk_user_creat);
760 $this->user_creation = $cuser;
763 if ($obj->fk_user_modif) {
764 $muser =
new User($this->
db);
765 $muser->fetch($obj->fk_user_modif);
766 $this->user_modification = $muser;
769 $this->date_creation = $this->
db->jdate($obj->datec);
770 $this->date_modification = $this->
db->jdate($obj->tms);
771 $this->import_key = $obj->import_key;
774 $this->
db->free($result);
addPayment($user)
Create in database.
__construct($db)
Constructor.
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
update($user, $notrigger=0)
Update database.
tva_sum_payee($year=0)
Total of VAT paid into invoice.
LibStatut($status, $mode=0)
Renvoi le libelle d'un statut donne.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
info($id)
Informations of vat payment object.
initAsSpecimen()
Initialise an instance with random values.
tva_sum_collectee($year=0)
Total of the VAT from invoices emitted by the thirdparty.
$conf db
API class for accounts.
Class to manage bank accounts.
Put here description of your class.
solde($year=0)
Balance of VAT.
getLibStatut($mode=0)
Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee) ...
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
fetch($id, $user=null)
Load object in memory from database.
create($user)
Create in database.
print
Draft customers invoices.
call_trigger($triggerName, $user)
Call trigger based on this instance.
getSommePaiement()
Return amount of payments already done.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
tva_sum_reglee($year=0)
Total of the VAT paid.
update_fk_bank($id_bank)
Update link between payment tva and line generate into llx_bank.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
if(!empty($search_group)) natural_search(array("g.nom"g note
getNomUrl($withpicto=0, $option= '', $notooltip=0, $morecss= '')
Send name clicable (with possibly the picto)