23require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
34 public $element =
'localtax';
39 public $table_element =
'localtax';
44 public $picto =
'payment';
83 public $fk_user_creat;
88 public $fk_user_modif;
109 global $conf, $langs;
114 $this->amount = trim($this->amount);
115 $this->label = trim($this->label);
116 $this->note = trim($this->note);
119 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"localtax(";
120 $sql .=
"localtaxtype,";
128 $sql .=
"fk_user_creat,";
129 $sql .=
"fk_user_modif";
130 $sql .=
") VALUES (";
131 $sql .=
" ".((int) $this->ltt).
",";
132 $sql .=
" '".$this->db->idate($this->tms).
"',";
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" : (int) $this->fk_bank).
",";
139 $sql .=
" ".((int) $this->fk_user_creat).
",";
140 $sql .=
" ".((int) $this->fk_user_modif);
143 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
144 $resql = $this->db->query($sql);
146 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"localtax");
149 $result = $this->
call_trigger(
'LOCALTAX_CREATE', $user);
159 $this->db->rollback();
163 $this->error =
"Error ".$this->db->lasterror();
164 $this->db->rollback();
178 global $conf, $langs;
183 $this->amount = trim($this->amount);
184 $this->label = trim($this->label);
185 $this->note = trim($this->note);
190 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"localtax SET";
191 $sql .=
" localtaxtype=".((int) $this->ltt).
",";
192 $sql .=
" tms='".$this->db->idate($this->tms).
"',";
193 $sql .=
" datep='".$this->db->idate($this->datep).
"',";
194 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
195 $sql .=
" amount=".price2num($this->amount).
",";
196 $sql .=
" label='".$this->db->escape($this->label).
"',";
197 $sql .=
" note='".$this->db->escape($this->note).
"',";
198 $sql .=
" fk_bank=".(int) $this->fk_bank.
",";
199 $sql .=
" fk_user_creat=".(int) $this->fk_user_creat.
",";
200 $sql .=
" fk_user_modif=".(int) $this->fk_user_modif;
201 $sql .=
" WHERE rowid=".((int) $this->
id);
203 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
204 $resql = $this->db->query($sql);
206 $this->error =
"Error ".$this->db->lasterror();
210 if (!$error && !$notrigger) {
212 $result = $this->
call_trigger(
'LOCALTAX_MODIFY', $user);
223 $this->db->rollback();
239 $sql .=
" t.localtaxtype,";
243 $sql .=
" t.amount,";
245 $sql .=
" t.note as note_private,";
246 $sql .=
" t.fk_bank,";
247 $sql .=
" t.fk_user_creat,";
248 $sql .=
" t.fk_user_modif,";
249 $sql .=
" b.fk_account,";
250 $sql .=
" b.fk_type,";
252 $sql .=
" FROM ".MAIN_DB_PREFIX.
"localtax as t";
253 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON t.fk_bank = b.rowid";
254 $sql .=
" WHERE t.rowid = ".((int) $id);
256 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
257 $resql = $this->db->query($sql);
259 if ($this->db->num_rows($resql)) {
260 $obj = $this->db->fetch_object($resql);
262 $this->
id = $obj->rowid;
263 $this->
ref = $obj->rowid;
264 $this->ltt = $obj->localtaxtype;
265 $this->tms = $this->db->jdate($obj->tms);
266 $this->datep = $this->db->jdate($obj->datep);
267 $this->datev = $this->db->jdate($obj->datev);
268 $this->amount = $obj->amount;
269 $this->label = $obj->label;
270 $this->note = $obj->note_private;
271 $this->note_private = $obj->note_private;
272 $this->fk_bank = $obj->fk_bank;
273 $this->fk_user_creat = $obj->fk_user_creat;
274 $this->fk_user_modif = $obj->fk_user_modif;
275 $this->fk_account = $obj->fk_account;
276 $this->fk_type = $obj->fk_type;
277 $this->rappro = $obj->rappro;
279 $this->db->free($resql);
283 $this->error =
"Error ".$this->db->lasterror();
295 public function delete($user)
298 $result = $this->
call_trigger(
'LOCALTAX_DELETE', $user);
304 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"localtax";
305 $sql .=
" WHERE rowid=".((int) $this->
id);
307 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
308 $resql = $this->db->query($sql);
310 $this->error =
"Error ".$this->db->lasterror();
339 $this->fk_user_creat = $user->id;
340 $this->fk_user_modif = $user->id;
357 $solde = $reglee - ($collectee - $payee);
372 $sql =
"SELECT sum(f.localtax) as amount";
373 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
374 $sql .=
" WHERE f.paye = 1";
379 $result = $this->db->query($sql);
381 if ($this->db->num_rows($result)) {
382 $obj = $this->db->fetch_object($result);
384 $this->db->free($result);
387 $this->db->free($result);
391 print $this->db->lasterror();
407 $sql =
"SELECT sum(f.total_localtax) as total_localtax";
408 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
413 $result = $this->db->query($sql);
415 if ($this->db->num_rows($result)) {
416 $obj = $this->db->fetch_object($result);
417 $ret = $obj->total_localtax;
418 $this->db->free($result);
421 $this->db->free($result);
425 print $this->db->lasterror();
442 $sql =
"SELECT sum(f.amount) as amount";
443 $sql .=
" FROM ".MAIN_DB_PREFIX.
"localtax as f";
448 $result = $this->db->query($sql);
450 if ($this->db->num_rows($result)) {
451 $obj = $this->db->fetch_object($result);
453 $this->db->free($result);
456 $this->db->free($result);
460 print $this->db->lasterror();
474 global $conf, $langs;
479 $this->amount =
price2num($this->amount);
481 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
484 if ($this->amount <= 0) {
485 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
488 if (isModEnabled(
"banque") && (empty($this->accountid) || $this->accountid <= 0)) {
489 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Account"));
492 if (isModEnabled(
"banque") && (empty($this->paymenttype) || $this->paymenttype <= 0)) {
493 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
498 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"localtax (localtaxtype, datep, datev, amount";
505 $sql .=
", fk_user_creat, fk_bank";
507 $sql .=
" VALUES (".$this->ltt.
", '".$this->db->idate($this->datep).
"',";
508 $sql .=
"'".$this->db->idate($this->datev).
"',".$this->amount;
510 $sql .=
", '".$this->db->escape($this->note).
"'";
513 $sql .=
", '".$this->db->escape($this->label).
"'";
515 $sql .=
", ".((int) $user->id).
", NULL";
518 dol_syslog(get_class($this).
"::addPayment", LOG_DEBUG);
519 $result = $this->db->query($sql);
521 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"localtax");
524 if (isModEnabled(
"banque")) {
526 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
529 $result = $acc->fetch($this->accountid);
534 $bank_line_id = $acc->addline($this->datep, $this->paymenttype, $this->label, -abs($this->amount),
'',
'', $user);
537 if ($bank_line_id > 0) {
540 $this->error = $acc->error;
545 $result = $acc->add_url_line($bank_line_id, $this->
id, DOL_URL_ROOT.
'/compta/localtax/card.php?id=',
"(VATPayment)",
"payment_vat");
547 $this->error = $acc->error;
556 $this->db->rollback();
560 $this->error = $this->db->lasterror();
561 $this->db->rollback();
565 $this->error = $this->db->lasterror();
566 $this->db->rollback();
581 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'localtax SET fk_bank = '.((int) $id);
582 $sql .=
' WHERE rowid = '.((int) $this->
id);
583 $result = $this->db->query($sql);
605 $label = $langs->trans(
"ShowVatPayment").
': '.$this->ref;
607 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/localtax/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
613 $result .= ($link.img_object($label, $picto,
'class="classfortooltip"').$linkend);
615 if ($withpicto && $withpicto != 2) {
618 if ($withpicto != 2) {
619 $result .= $link.$this->ref.$linkend;
662 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
664 $return =
'<div class="box-flex-item box-flex-grow-zero">';
665 $return .=
'<div class="info-box info-box-sm">';
666 $return .=
'<span class="info-box-icon bg-infobox-action">';
668 $return .=
'</span>';
669 $return .=
'<div class="info-box-content">';
670 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
671 if ($selected >= 0) {
672 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
674 if (property_exists($this,
'label')) {
675 $return .=
' | <span class="info-box-label">'.$this->label.
'</span>';
677 if (property_exists($this,
'datev')) {
678 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"DateEnd").
'</span> : <span class="info-box-label">'.
dol_print_date($this->db->jdate($this->datev),
'day').
'</span>';
680 if (property_exists($this,
'datep')) {
681 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"DatePayment",
'',
'',
'',
'', 5).
'</span> : <span class="info-box-label">'.
dol_print_date($this->db->jdate($this->datep),
'day').
'</span>';
683 if (property_exists($this,
'amount')) {
684 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Amount").
'</span> : <span class="info-box-label amount">'.
price($this->amount).
'</span>';
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 local tax.
fetch($id)
Load object in memory from database.
LibStatut($status, $mode=0)
Return the label of a given status.
addPayment($user)
Add a payment of localtax.
solde($year=0)
Hum la fonction s'appelle 'Solde' elle doit a mon avis calcluer le solde de localtax,...
localtax_sum_payee($year=0)
Total of localtax paid in invoice.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
initAsSpecimen()
Initialise an instance with random values.
getNomUrl($withpicto=0, $option='')
Returns clickable name.
update(User $user, $notrigger=0)
Update database.
__construct($db)
Constructor.
getLibStatut($mode=0)
Return the label of the status.
update_fk_bank($id)
Update the link betwen localtax payment and the line into llx_bank.
create($user)
Create in database.
localtax_sum_collectee($year=0)
Total de la localtax des factures emises par la societe.
localtax_sum_reglee($year=0)
Total of localtax paid.
Class to manage Dolibarr users.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
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...
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).
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut