29 require_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);
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);
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);
286 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"tva SET";
288 $sql .=
" WHERE rowid = ".((int) $this->
id);
305 public function fetch($id, $user =
null)
314 $sql .=
" t.amount,";
315 $sql .=
" t.fk_typepayment,";
316 $sql .=
" t.num_payment,";
320 $sql .=
" t.fk_user_creat,";
321 $sql .=
" t.fk_user_modif,";
322 $sql .=
" t.fk_account";
324 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
326 $sql .=
" WHERE t.rowid = ".((int) $id);
328 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
332 $obj = $this->
db->fetch_object(
$resql);
334 $this->
id = $obj->rowid;
335 $this->
ref = $obj->rowid;
336 $this->tms = $this->
db->jdate($obj->tms);
337 $this->datep = $this->
db->jdate($obj->datep);
338 $this->datev = $this->
db->jdate($obj->datev);
339 $this->amount = $obj->amount;
340 $this->type_payment = $obj->fk_typepayment;
341 $this->num_payment = $obj->num_payment;
342 $this->label = $obj->label;
343 $this->paye = $obj->paye;
344 $this->note = $obj->note;
345 $this->fk_user_creat = $obj->fk_user_creat;
346 $this->fk_user_modif = $obj->fk_user_modif;
347 $this->fk_account = $obj->fk_account;
348 $this->fk_type = empty($obj->fk_type) ?
"" : $obj->fk_type;
349 $this->rappro = empty($obj->rappro) ?
"" : $obj->rappro;
355 $this->error =
"Error ".$this->db->lasterror();
367 public function delete($user)
369 global $conf, $langs;
380 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"tva";
381 $sql .=
" WHERE rowid=".((int) $this->
id);
383 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
386 $this->error =
"Error ".$this->db->lasterror();
413 $this->fk_user_creat =
'';
414 $this->fk_user_modif =
'';
432 $solde = $reglee - ($collectee - $payee);
448 $sql =
"SELECT sum(f.total_tva) as amount";
449 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.paye = 1";
451 $sql .=
" AND f.datef >= '".$this->db->escape($year).
"-01-01' AND f.datef <= '".$this->
db->escape($year).
"-12-31' ";
454 $result = $this->
db->query($sql);
456 if ($this->
db->num_rows($result)) {
457 $obj = $this->
db->fetch_object($result);
459 $this->
db->free($result);
462 $this->
db->free($result);
466 print $this->
db->lasterror();
482 $sql =
"SELECT sum(f.total_tva) as total_tva";
483 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
485 $sql .=
" WHERE f.datef >= '".$this->db->escape($year).
"-01-01' AND f.datef <= '".$this->
db->escape($year).
"-12-31' ";
488 $result = $this->
db->query($sql);
490 if ($this->
db->num_rows($result)) {
491 $obj = $this->
db->fetch_object($result);
492 $ret = $obj->total_tva;
493 $this->
db->free($result);
496 $this->
db->free($result);
500 print $this->
db->lasterror();
517 $sql =
"SELECT sum(f.amount) as amount";
518 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as f";
521 $sql .=
" WHERE f.datev >= '".$this->db->escape($year).
"-01-01' AND f.datev <= '".$this->
db->escape($year).
"-12-31' ";
524 $result = $this->
db->query($sql);
526 if ($this->
db->num_rows($result)) {
527 $obj = $this->
db->fetch_object($result);
529 $this->
db->free($result);
532 $this->
db->free($result);
536 print $this->
db->lasterror();
550 global $conf, $langs;
555 $this->amount =
price2num(trim($this->amount));
556 $this->label = trim($this->label);
557 $this->note = trim($this->note);
558 $this->num_payment = trim($this->num_payment);
559 $this->fk_bank = (int) $this->fk_bank;
560 $this->fk_user_creat = (int) $this->fk_user_creat;
561 $this->fk_user_modif = (int) $this->fk_user_modif;
562 if (empty($this->datec)) {
568 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
571 if ($this->amount ==
'') {
572 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
575 if (
isModEnabled(
"banque") && (empty($this->accountid) || $this->accountid <= 0)) {
576 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Account"));
579 if (
isModEnabled(
"banque") && (empty($this->type_payment) || $this->type_payment <= 0)) {
580 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
585 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"tva (";
590 $sql .=
", fk_typepayment";
591 $sql .=
", num_payment";
598 $sql .=
", fk_user_creat";
603 $sql .=
" '".$this->db->idate($this->datec).
"'";
604 $sql .=
", '".$this->db->idate($this->datep).
"'";
605 $sql .=
", '".$this->db->idate($this->datev).
"'";
606 $sql .=
", ".((float) $this->amount);
607 $sql .=
", '".$this->db->escape($this->type_payment).
"'";
608 $sql .=
", '".$this->db->escape($this->num_payment).
"'";
610 $sql .=
", '".$this->db->escape($this->note).
"'";
613 $sql .=
", '".$this->db->escape($this->label).
"'";
615 $sql .=
", '".$this->db->escape($user->id).
"'";
617 $sql .=
", ".((int) $conf->entity);
620 dol_syslog(get_class($this).
"::addPayment", LOG_DEBUG);
621 $result = $this->
db->query($sql);
623 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"tva");
638 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
641 $result = $acc->fetch($this->accountid);
646 if ($this->amount > 0) {
647 $bank_line_id = $acc->addline($this->datep, $this->type_payment, $this->label, -abs($this->amount), $this->num_payment,
'', $user);
649 $bank_line_id = $acc->addline($this->datep, $this->type_payment, $this->label, abs($this->amount), $this->num_payment,
'', $user);
653 if ($bank_line_id > 0) {
656 $this->error = $acc->error;
661 $result = $acc->add_url_line($bank_line_id, $this->
id, DOL_URL_ROOT.
'/compta/tva/card.php?id=',
"(VATPayment)",
"payment_vat");
663 $this->error = $acc->error;
672 $this->
db->rollback();
676 $this->
db->rollback();
680 $this->error = $this->
db->error();
681 $this->
db->rollback();
696 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'tva SET fk_bank = '.(int) $id_bank;
697 $sql .=
' WHERE rowid = '.(int) $this->
id;
698 $result = $this->
db->query($sql);
717 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
719 global $langs, $conf;
721 if (!empty($conf->dol_no_mouse_hover)) {
727 $label =
'<u>'.$langs->trans(
"ShowVatPayment").
'</u>';
729 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
730 if (!empty($this->label)) {
731 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
734 $url = DOL_URL_ROOT.
'/compta/tva/card.php?id='.$this->id;
736 if ($option !=
'nolink') {
738 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
739 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
740 $add_save_lastsearch_values = 1;
742 if ($add_save_lastsearch_values) {
743 $url .=
'&save_lastsearch_values=1';
748 if (empty($notooltip)) {
749 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
750 $label = $langs->trans(
"ShowMyObject");
751 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
753 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
754 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
756 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
759 $linkstart =
'<a href="'.$url.
'"';
760 $linkstart .= $linkclose.
'>';
765 $result .= $linkstart;
767 $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);
769 if ($withpicto != 2) {
770 $result .= $this->ref;
784 $table =
'payment_vat';
787 $sql =
'SELECT sum(amount) as amount';
788 $sql .=
' FROM '.MAIN_DB_PREFIX.$table;
789 $sql .=
" WHERE ".$field.
" = ".((int) $this->
id);
791 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
796 $obj = $this->
db->fetch_object(
$resql);
798 $amount = $obj->amount ? $obj->amount : 0;
816 $sql =
"SELECT t.rowid, t.tms, t.fk_user_modif, t.datec, t.fk_user_creat";
817 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
818 $sql .=
" WHERE t.rowid = ".(int) $id;
820 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
821 $result = $this->
db->query($sql);
823 if ($this->
db->num_rows($result)) {
824 $obj = $this->
db->fetch_object($result);
826 $this->
id = $obj->rowid;
828 if ($obj->fk_user_creat) {
829 $cuser =
new User($this->
db);
830 $cuser->fetch($obj->fk_user_creat);
831 $this->user_creation = $cuser;
834 if ($obj->fk_user_modif) {
835 $muser =
new User($this->
db);
836 $muser->fetch($obj->fk_user_modif);
837 $this->user_modification = $muser;
840 $this->date_creation = $this->
db->jdate($obj->datec);
841 $this->date_modification = $this->
db->jdate($obj->tms);
842 $this->import_key = $obj->import_key;
845 $this->
db->free($result);
860 return $this->
LibStatut($this->paye, $mode, $alreadypaid);
872 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
878 $langs->loadLangs(array(
"customers",
"bills"));
881 $this->labelStatus = array();
882 $this->labelStatusShort = array();
884 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
887 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
888 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
889 if ($status == self::STATUS_UNPAID && $alreadypaid <> 0) {
890 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
892 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
893 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
894 if ($status == self::STATUS_UNPAID && $alreadypaid <> 0) {
895 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
899 $statusType =
'status1';
900 if ($status == 0 && $alreadypaid <> 0) {
901 $statusType =
'status3';
904 $statusType =
'status6';
907 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
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.
tva_sum_collectee($year=0)
Total of the VAT from invoices emitted by the thirdparty.
LibStatut($status, $mode=0, $alreadypaid=-1)
Renvoi le libelle d'un statut donne.
tva_sum_payee($year=0)
VAT payed.
setUnpaid($user)
Remove tag payed on TVA.
__construct($db)
Constructor.
fetch($id, $user=null)
Load object in memory from database.
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)
Retourne le libelle du statut d'une TVA (impaye, payee)
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Send name clicable (with possibly the picto)
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.
if(isModEnabled('facture') &&!empty($user->rights->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') &&!empty($user->rights->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)) $resql
Social contributions to pay.
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)
dol_now($mode='auto')
Return date for now.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.