25require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
36 public $element =
'localtax';
41 public $table_element =
'localtax';
46 public $picto =
'payment';
100 public $fk_user_creat;
105 public $fk_user_modif;
126 global
$conf, $langs;
131 $this->amount = trim($this->amount);
132 $this->label = trim($this->label);
133 $this->note = trim($this->note);
136 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"localtax(";
137 $sql .=
"localtaxtype,";
145 $sql .=
"fk_user_creat,";
146 $sql .=
"fk_user_modif";
147 $sql .=
") VALUES (";
148 $sql .=
" ".((int) $this->ltt).
",";
149 $sql .=
" '".$this->db->idate($this->tms).
"',";
150 $sql .=
" '".$this->db->idate($this->datep).
"',";
151 $sql .=
" '".$this->db->idate($this->datev).
"',";
152 $sql .=
" '".$this->db->escape($this->amount).
"',";
153 $sql .=
" '".$this->db->escape($this->label).
"',";
154 $sql .=
" '".$this->db->escape($this->note).
"',";
155 $sql .=
" ".($this->fk_bank <= 0 ?
"NULL" : (int) $this->fk_bank).
",";
156 $sql .=
" ".((int) $this->fk_user_creat).
",";
157 $sql .=
" ".((int) $this->fk_user_modif);
160 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
161 $resql = $this->db->query($sql);
163 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"localtax");
166 $result = $this->
call_trigger(
'LOCALTAX_CREATE', $user);
176 $this->db->rollback();
180 $this->error =
"Error ".$this->db->lasterror();
181 $this->db->rollback();
195 global
$conf, $langs;
200 $this->amount = trim($this->amount);
201 $this->label = trim($this->label);
202 $this->note = trim($this->note);
207 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"localtax SET";
208 $sql .=
" localtaxtype=".((int) $this->ltt).
",";
209 $sql .=
" tms='".$this->db->idate($this->tms).
"',";
210 $sql .=
" datep='".$this->db->idate($this->datep).
"',";
211 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
212 $sql .=
" amount=".price2num($this->amount).
",";
213 $sql .=
" label='".$this->db->escape($this->label).
"',";
214 $sql .=
" note='".$this->db->escape($this->note).
"',";
215 $sql .=
" fk_bank=".(int) $this->fk_bank.
",";
216 $sql .=
" fk_user_creat=".(int) $this->fk_user_creat.
",";
217 $sql .=
" fk_user_modif=".(int) $this->fk_user_modif;
218 $sql .=
" WHERE rowid=".((int) $this->
id);
220 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
221 $resql = $this->db->query($sql);
223 $this->error =
"Error ".$this->db->lasterror();
227 if (!$error && !$notrigger) {
229 $result = $this->
call_trigger(
'LOCALTAX_MODIFY', $user);
240 $this->db->rollback();
256 $sql .=
" t.localtaxtype,";
260 $sql .=
" t.amount,";
262 $sql .=
" t.note as note_private,";
263 $sql .=
" t.fk_bank,";
264 $sql .=
" t.fk_user_creat,";
265 $sql .=
" t.fk_user_modif,";
266 $sql .=
" b.fk_account,";
267 $sql .=
" b.fk_type,";
269 $sql .=
" FROM ".MAIN_DB_PREFIX.
"localtax as t";
270 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON t.fk_bank = b.rowid";
271 $sql .=
" WHERE t.rowid = ".((int) $id);
273 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
274 $resql = $this->db->query($sql);
276 if ($this->db->num_rows($resql)) {
277 $obj = $this->db->fetch_object($resql);
279 $this->
id = $obj->rowid;
280 $this->
ref = $obj->rowid;
281 $this->ltt = $obj->localtaxtype;
282 $this->tms = $this->db->jdate($obj->tms);
283 $this->datep = $this->db->jdate($obj->datep);
284 $this->datev = $this->db->jdate($obj->datev);
285 $this->amount = $obj->amount;
286 $this->label = $obj->label;
287 $this->note = $obj->note_private;
288 $this->note_private = $obj->note_private;
289 $this->fk_bank = $obj->fk_bank;
290 $this->fk_user_creat = $obj->fk_user_creat;
291 $this->fk_user_modif = $obj->fk_user_modif;
292 $this->fk_account = $obj->fk_account;
293 $this->fk_type = $obj->fk_type;
294 $this->rappro = $obj->rappro;
296 $this->db->free($resql);
300 $this->error =
"Error ".$this->db->lasterror();
312 public function delete($user)
315 $result = $this->
call_trigger(
'LOCALTAX_DELETE', $user);
321 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"localtax";
322 $sql .=
" WHERE rowid=".((int) $this->
id);
324 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
325 $resql = $this->db->query($sql);
327 $this->error =
"Error ".$this->db->lasterror();
356 $this->fk_user_creat = $user->id;
357 $this->fk_user_modif = $user->id;
376 $solde = $reglee - ($collectee - $payee);
391 $sql =
"SELECT sum(f.localtax) as amount";
392 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
393 $sql .=
" WHERE f.paye = 1";
398 $result = $this->db->query($sql);
400 if ($this->db->num_rows($result)) {
401 $obj = $this->db->fetch_object($result);
403 $this->db->free($result);
406 $this->db->free($result);
410 print $this->db->lasterror();
426 $sql =
"SELECT sum(f.total_localtax) as total_localtax";
427 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
432 $result = $this->db->query($sql);
434 if ($this->db->num_rows($result)) {
435 $obj = $this->db->fetch_object($result);
436 $ret = $obj->total_localtax;
437 $this->db->free($result);
440 $this->db->free($result);
444 print $this->db->lasterror();
461 $sql =
"SELECT sum(f.amount) as amount";
462 $sql .=
" FROM ".MAIN_DB_PREFIX.
"localtax as f";
467 $result = $this->db->query($sql);
469 if ($this->db->num_rows($result)) {
470 $obj = $this->db->fetch_object($result);
472 $this->db->free($result);
475 $this->db->free($result);
479 print $this->db->lasterror();
493 global
$conf, $langs;
498 $this->amount =
price2num($this->amount);
500 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
503 if ($this->amount <= 0) {
504 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
507 if (isModEnabled(
"bank") && (empty($this->accountid) || $this->accountid <= 0)) {
508 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"BankAccount"));
511 if (isModEnabled(
"bank") && (empty($this->paymenttype) || $this->paymenttype <= 0)) {
512 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
517 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"localtax (localtaxtype, datep, datev, amount";
524 $sql .=
", fk_user_creat, fk_bank";
526 $sql .=
" VALUES (".$this->ltt.
", '".$this->db->idate($this->datep).
"',";
527 $sql .=
"'".$this->db->idate($this->datev).
"',".$this->amount;
529 $sql .=
", '".$this->db->escape($this->note).
"'";
532 $sql .=
", '".$this->db->escape($this->label).
"'";
534 $sql .=
", ".((int) $user->id).
", NULL";
537 dol_syslog(get_class($this).
"::addPayment", LOG_DEBUG);
538 $result = $this->db->query($sql);
540 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"localtax");
543 if (isModEnabled(
"bank")) {
545 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
548 $result = $acc->fetch($this->accountid);
553 $bank_line_id = $acc->addline($this->datep, $this->paymenttype, $this->label, -abs((
float) $this->amount),
'', 0, $user);
556 if ($bank_line_id > 0) {
559 $this->error = $acc->error;
564 $result = $acc->add_url_line($bank_line_id, $this->
id, DOL_URL_ROOT.
'/compta/localtax/card.php?id=',
"(VATPayment)",
"payment_vat");
566 $this->error = $acc->error;
575 $this->db->rollback();
579 $this->error = $this->db->lasterror();
580 $this->db->rollback();
584 $this->error = $this->db->lasterror();
585 $this->db->rollback();
600 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'localtax SET fk_bank = '.((int) $id);
601 $sql .=
' WHERE rowid = '.((int) $this->
id);
602 $result = $this->db->query($sql);
624 $label = $langs->trans(
"ShowVatPayment").
': '.$this->ref;
626 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/localtax/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
632 $result .= ($link.img_object($label, $picto,
'class="classfortooltip"').$linkend);
634 if ($withpicto && $withpicto != 2) {
637 if ($withpicto != 2) {
638 $result .= $link.$this->ref.$linkend;
651 return $this->
LibStatut($this->statut, $mode);
681 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
683 $return =
'<div class="box-flex-item box-flex-grow-zero">';
684 $return .=
'<div class="info-box info-box-sm">';
685 $return .=
'<span class="info-box-icon bg-infobox-action">';
687 $return .=
'</span>';
688 $return .=
'<div class="info-box-content">';
689 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
690 if ($selected >= 0) {
691 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
693 if (property_exists($this,
'label')) {
694 $return .=
' | <span class="info-box-label">'.$this->label.
'</span>';
696 if (property_exists($this,
'datev')) {
697 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"DateEnd").
'</span> : <span class="info-box-label">'.
dol_print_date($this->db->jdate($this->datev),
'day').
'</span>';
699 if (property_exists($this,
'datep')) {
700 $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>';
702 if (property_exists($this,
'amount')) {
703 $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 function 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 clickable 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 between 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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...