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;
110 public $ismultientitymanaged = 1;
131 global
$conf, $langs;
137 $this->label = trim($this->label);
138 $this->note = trim($this->note);
141 if (empty($this->entity)) {
142 $this->entity =
$conf->entity;
146 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"localtax(";
147 $sql .=
"localtaxtype,";
156 $sql .=
"fk_user_creat,";
157 $sql .=
"fk_user_modif";
158 $sql .=
") VALUES (";
159 $sql .=
" ".((int) $this->ltt).
",";
160 $sql .=
" '".$this->db->idate($this->tms).
"',";
161 $sql .=
" '".$this->db->idate($this->datep).
"',";
162 $sql .=
" '".$this->db->idate($this->datev).
"',";
163 $sql .=
" '".$this->db->escape($this->
amount).
"',";
164 $sql .=
" '".$this->db->escape($this->label).
"',";
165 $sql .=
" '".$this->db->escape($this->note).
"',";
166 $sql .=
" ".((int) $this->entity).
",";
167 $sql .=
" ".($this->fk_bank <= 0 ?
"NULL" : (int) $this->fk_bank).
",";
168 $sql .=
" ".((int) $this->fk_user_creat).
",";
169 $sql .=
" ".((int) $this->fk_user_modif);
172 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
173 $resql = $this->db->query($sql);
175 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"localtax");
178 $result = $this->call_trigger(
'LOCALTAX_CREATE', $user);
188 $this->db->rollback();
192 $this->error =
"Error ".$this->db->lasterror();
193 $this->db->rollback();
207 global
$conf, $langs;
213 $this->label = trim($this->label);
214 $this->note = trim($this->note);
219 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"localtax SET";
220 $sql .=
" localtaxtype=".((int) $this->ltt).
",";
221 $sql .=
" tms='".$this->db->idate($this->tms).
"',";
222 $sql .=
" datep='".$this->db->idate($this->datep).
"',";
223 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
224 $sql .=
" amount='".$this->db->escape($this->
amount).
"',";
225 $sql .=
" label='".$this->db->escape($this->label).
"',";
226 $sql .=
" note='".$this->db->escape($this->note).
"',";
227 $sql .=
" entity=".((int) $this->entity).
",";
228 $sql .=
" fk_bank=".(int) $this->fk_bank.
",";
229 $sql .=
" fk_user_creat=".(int) $this->fk_user_creat.
",";
230 $sql .=
" fk_user_modif=".(int) $this->fk_user_modif;
231 $sql .=
" WHERE rowid=".((int) $this->
id);
233 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
234 $resql = $this->db->query($sql);
236 $this->error =
"Error ".$this->db->lasterror();
240 if (!$error && !$notrigger) {
242 $result = $this->call_trigger(
'LOCALTAX_MODIFY', $user);
253 $this->db->rollback();
269 $sql .=
" t.localtaxtype,";
273 $sql .=
" t.amount,";
275 $sql .=
" t.note as note_private,";
276 $sql .=
" t.entity,";
277 $sql .=
" t.fk_bank,";
278 $sql .=
" t.fk_user_creat,";
279 $sql .=
" t.fk_user_modif,";
280 $sql .=
" b.fk_account,";
281 $sql .=
" b.fk_type,";
283 $sql .=
" FROM ".MAIN_DB_PREFIX.
"localtax as t";
284 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON t.fk_bank = b.rowid";
285 $sql .=
" WHERE t.rowid = ".((int) $id);
287 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
288 $resql = $this->db->query($sql);
290 if ($this->db->num_rows($resql)) {
291 $obj = $this->db->fetch_object($resql);
293 $this->
id = $obj->rowid;
294 $this->
ref = $obj->rowid;
295 $this->ltt = $obj->localtaxtype;
296 $this->tms = $this->db->jdate($obj->tms);
297 $this->datep = $this->db->jdate($obj->datep);
298 $this->datev = $this->db->jdate($obj->datev);
299 $this->
amount = $obj->amount;
300 $this->label = $obj->label;
301 $this->note = $obj->note_private;
302 $this->note_private = $obj->note_private;
303 $this->entity = $obj->entity;
304 $this->fk_bank = $obj->fk_bank;
305 $this->fk_user_creat = $obj->fk_user_creat;
306 $this->fk_user_modif = $obj->fk_user_modif;
307 $this->fk_account = $obj->fk_account;
308 $this->fk_type = $obj->fk_type;
309 $this->rappro = $obj->rappro;
311 $this->db->free($resql);
315 $this->error =
"Error ".$this->db->lasterror();
327 public function delete($user)
330 $result = $this->call_trigger(
'LOCALTAX_DELETE', $user);
336 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"localtax";
337 $sql .=
" WHERE rowid=".((int) $this->
id);
339 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
340 $resql = $this->db->query($sql);
342 $this->error =
"Error ".$this->db->lasterror();
370 $this->entity =
$conf->entity;
372 $this->fk_user_creat = $user->id;
373 $this->fk_user_modif = $user->id;
392 $solde = $reglee - ($collectee - $payee);
407 $sql =
"SELECT sum(f.localtax) as amount";
408 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
409 $sql .=
" WHERE f.paye = 1";
414 $result = $this->db->query($sql);
416 if ($this->db->num_rows($result)) {
417 $obj = $this->db->fetch_object($result);
419 $this->db->free($result);
422 $this->db->free($result);
426 print $this->db->lasterror();
442 $sql =
"SELECT sum(f.total_localtax) as total_localtax";
443 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
448 $result = $this->db->query($sql);
450 if ($this->db->num_rows($result)) {
451 $obj = $this->db->fetch_object($result);
452 $ret = $obj->total_localtax;
453 $this->db->free($result);
456 $this->db->free($result);
460 print $this->db->lasterror();
477 $sql =
"SELECT sum(f.amount) as amount";
478 $sql .=
" FROM ".MAIN_DB_PREFIX.
"localtax as f";
483 $result = $this->db->query($sql);
485 if ($this->db->num_rows($result)) {
486 $obj = $this->db->fetch_object($result);
488 $this->db->free($result);
491 $this->db->free($result);
495 print $this->db->lasterror();
509 global
$conf, $langs;
516 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
520 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
523 if (
isModEnabled(
"bank") && (empty($this->accountid) || $this->accountid <= 0)) {
524 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"BankAccount"));
527 if (
isModEnabled(
"bank") && (empty($this->paymenttype) || $this->paymenttype <= 0)) {
528 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
533 if (empty($this->entity)) {
534 $this->entity =
$conf->entity;
538 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"localtax(localtaxtype, datep, datev, amount";
545 $sql .=
", entity, fk_user_creat, fk_bank";
547 $sql .=
" VALUES(".((int) $this->ltt).
", '".$this->db->idate($this->datep).
"', ";
548 $sql .=
"'".$this->db->idate($this->datev).
"', ".((float) $this->
amount);
550 $sql .=
", '".$this->db->escape($this->note).
"'";
553 $sql .=
", '".$this->db->escape($this->label).
"'";
555 $sql .=
", ".((int) $this->entity).
", ".((int) $user->id).
", NULL";
558 dol_syslog(get_class($this).
"::addPayment", LOG_DEBUG);
559 $result = $this->db->query($sql);
561 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"localtax");
566 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
569 $result = $acc->fetch($this->accountid);
574 $bank_line_id = $acc->addline($this->datep, $this->paymenttype, $this->label, -abs((
float) $this->amount),
'', 0, $user);
577 if ($bank_line_id > 0) {
580 $this->error = $acc->error;
585 $result = $acc->add_url_line($bank_line_id, $this->
id, DOL_URL_ROOT.
'/compta/localtax/card.php?id=',
"(VATPayment)",
"payment_vat");
587 $this->error = $acc->error;
596 $this->db->rollback();
600 $this->error = $this->db->lasterror();
601 $this->db->rollback();
605 $this->error = $this->db->lasterror();
606 $this->db->rollback();
621 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'localtax SET fk_bank = '.((int) $id);
622 $sql .=
' WHERE rowid = '.((int) $this->
id);
623 $result = $this->db->query($sql);
645 $label = $langs->trans(
"ShowVatPayment").
': '.$this->ref;
647 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/localtax/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
653 $result .= ($link.img_object($label, $picto,
'class="classfortooltip"').$linkend);
655 if ($withpicto && $withpicto != 2) {
658 if ($withpicto != 2) {
659 $result .= $link.$this->ref.$linkend;
672 return $this->
LibStatut($this->statut, $mode);
702 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
704 $return =
'<div class="box-flex-item box-flex-grow-zero">';
705 $return .=
'<div class="info-box info-box-sm">';
706 $return .=
'<span class="info-box-icon bg-infobox-action">';
708 $return .=
'</span>';
709 $return .=
'<div class="info-box-content">';
710 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
711 if ($selected >= 0) {
712 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
714 if (property_exists($this,
'label')) {
715 $return .=
' | <span class="info-box-label">'.$this->label.
'</span>';
717 if (property_exists($this,
'datev')) {
718 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"DateEnd").
'</span> : <span class="info-box-label">'.
dol_print_date($this->db->jdate($this->datev),
'day').
'</span>';
720 if (property_exists($this,
'datep')) {
721 $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>';
723 if (property_exists($this,
'amount')) {
724 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Amount").
'</span> : <span class="info-box-label amount">'.
price($this->
amount).
'</span>';
Class to manage bank accounts.
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 of invoices localtax emitted by the company.
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.
dol_now($mode='gmt')
Return date for now.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount