23 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
34 public $element =
'localtax';
39 public $table_element =
'localtax';
44 public $picto =
'payment';
65 public $fk_user_creat;
70 public $fk_user_modif;
96 $this->amount = trim($this->amount);
97 $this->label = trim($this->label);
98 $this->note = trim($this->note);
101 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"localtax(";
102 $sql .=
"localtaxtype,";
110 $sql .=
"fk_user_creat,";
111 $sql .=
"fk_user_modif";
112 $sql .=
") VALUES (";
113 $sql .=
" ".((int) $this->ltt).
",";
114 $sql .=
" '".$this->db->idate($this->tms).
"',";
115 $sql .=
" '".$this->db->idate($this->datep).
"',";
116 $sql .=
" '".$this->db->idate($this->datev).
"',";
117 $sql .=
" '".$this->db->escape($this->amount).
"',";
118 $sql .=
" '".$this->db->escape($this->label).
"',";
119 $sql .=
" '".$this->db->escape($this->note).
"',";
120 $sql .=
" ".($this->fk_bank <= 0 ?
"NULL" : (int) $this->fk_bank).
",";
121 $sql .=
" ".((int) $this->fk_user_creat).
",";
122 $sql .=
" ".((int) $this->fk_user_modif);
125 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
126 $resql = $this->db->query(
$sql);
128 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"localtax");
131 $result = $this->
call_trigger(
'LOCALTAX_CREATE', $user);
141 $this->db->rollback();
145 $this->error =
"Error ".$this->db->lasterror();
146 $this->db->rollback();
160 global $conf, $langs;
165 $this->amount = trim($this->amount);
166 $this->label = trim($this->label);
167 $this->note = trim($this->note);
172 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"localtax SET";
173 $sql .=
" localtaxtype=".((int) $this->ltt).
",";
174 $sql .=
" tms='".$this->db->idate($this->tms).
"',";
175 $sql .=
" datep='".$this->db->idate($this->datep).
"',";
176 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
177 $sql .=
" amount=".price2num($this->amount).
",";
178 $sql .=
" label='".$this->db->escape($this->label).
"',";
179 $sql .=
" note='".$this->db->escape($this->note).
"',";
180 $sql .=
" fk_bank=".(int) $this->fk_bank.
",";
181 $sql .=
" fk_user_creat=".(int) $this->fk_user_creat.
",";
182 $sql .=
" fk_user_modif=".(int) $this->fk_user_modif;
183 $sql .=
" WHERE rowid=".((int) $this->
id);
185 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
186 $resql = $this->db->query(
$sql);
188 $this->error =
"Error ".$this->db->lasterror();
192 if (!$error && !$notrigger) {
194 $result = $this->
call_trigger(
'LOCALTAX_MODIFY', $user);
205 $this->db->rollback();
222 $sql .=
" t.localtaxtype,";
226 $sql .=
" t.amount,";
229 $sql .=
" t.fk_bank,";
230 $sql .=
" t.fk_user_creat,";
231 $sql .=
" t.fk_user_modif,";
232 $sql .=
" b.fk_account,";
233 $sql .=
" b.fk_type,";
235 $sql .=
" FROM ".MAIN_DB_PREFIX.
"localtax as t";
236 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"bank as b ON t.fk_bank = b.rowid";
237 $sql .=
" WHERE t.rowid = ".((int) $id);
239 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
240 $resql = $this->db->query(
$sql);
242 if ($this->db->num_rows($resql)) {
243 $obj = $this->db->fetch_object($resql);
245 $this->
id = $obj->rowid;
246 $this->
ref = $obj->rowid;
247 $this->ltt = $obj->localtaxtype;
248 $this->tms = $this->db->jdate($obj->tms);
249 $this->datep = $this->db->jdate($obj->datep);
250 $this->datev = $this->db->jdate($obj->datev);
251 $this->amount = $obj->amount;
252 $this->label = $obj->label;
253 $this->note = $obj->note;
254 $this->fk_bank = $obj->fk_bank;
255 $this->fk_user_creat = $obj->fk_user_creat;
256 $this->fk_user_modif = $obj->fk_user_modif;
257 $this->fk_account = $obj->fk_account;
258 $this->fk_type = $obj->fk_type;
259 $this->rappro = $obj->rappro;
261 $this->db->free($resql);
265 $this->error =
"Error ".$this->db->lasterror();
277 public function delete($user)
280 $result = $this->
call_trigger(
'LOCALTAX_DELETE', $user);
286 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"localtax";
287 $sql .=
" WHERE rowid=".((int) $this->
id);
289 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
290 $resql = $this->db->query(
$sql);
292 $this->error =
"Error ".$this->db->lasterror();
321 $this->fk_user_creat = $user->id;
322 $this->fk_user_modif = $user->id;
339 $solde = $reglee - ($collectee - $payee);
354 $sql =
"SELECT sum(f.localtax) as amount";
355 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f";
356 $sql .=
" WHERE f.paye = 1";
361 $result = $this->db->query(
$sql);
363 if ($this->db->num_rows($result)) {
364 $obj = $this->db->fetch_object($result);
366 $this->db->free($result);
369 $this->db->free($result);
373 print $this->db->lasterror();
389 $sql =
"SELECT sum(f.total_localtax) as total_localtax";
390 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
395 $result = $this->db->query(
$sql);
397 if ($this->db->num_rows($result)) {
398 $obj = $this->db->fetch_object($result);
399 $ret = $obj->total_localtax;
400 $this->db->free($result);
403 $this->db->free($result);
407 print $this->db->lasterror();
424 $sql =
"SELECT sum(f.amount) as amount";
425 $sql .=
" FROM ".MAIN_DB_PREFIX.
"localtax as f";
430 $result = $this->db->query(
$sql);
432 if ($this->db->num_rows($result)) {
433 $obj = $this->db->fetch_object($result);
435 $this->db->free($result);
438 $this->db->free($result);
442 print $this->db->lasterror();
456 global $conf, $langs;
461 $this->amount =
price2num($this->amount);
463 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
466 if ($this->amount <= 0) {
467 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
470 if (
isModEnabled(
"banque") && (empty($this->accountid) || $this->accountid <= 0)) {
471 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Account"));
474 if (
isModEnabled(
"banque") && (empty($this->paymenttype) || $this->paymenttype <= 0)) {
475 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
480 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"localtax (localtaxtype, datep, datev, amount";
487 $sql .=
", fk_user_creat, fk_bank";
489 $sql .=
" VALUES (".$this->ltt.
", '".$this->db->idate($this->datep).
"',";
490 $sql .=
"'".$this->db->idate($this->datev).
"',".$this->amount;
492 $sql .=
", '".$this->db->escape($this->note).
"'";
495 $sql .=
", '".$this->db->escape($this->label).
"'";
497 $sql .=
", ".((int) $user->id).
", NULL";
500 dol_syslog(get_class($this).
"::addPayment", LOG_DEBUG);
501 $result = $this->db->query(
$sql);
503 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"localtax");
508 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
511 $result = $acc->fetch($this->accountid);
516 $bank_line_id = $acc->addline($this->datep, $this->paymenttype, $this->label, -abs($this->amount),
'',
'', $user);
519 if ($bank_line_id > 0) {
522 $this->error = $acc->error;
527 $result = $acc->add_url_line($bank_line_id, $this->
id, DOL_URL_ROOT.
'/compta/localtax/card.php?id=',
"(VATPayment)",
"payment_vat");
529 $this->error = $acc->error;
538 $this->db->rollback();
542 $this->error = $this->db->lasterror();
543 $this->db->rollback();
547 $this->error = $this->db->lasterror();
548 $this->db->rollback();
563 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'localtax SET fk_bank = '.((int) $id);
564 $sql .=
' WHERE rowid = '.((int) $this->
id);
565 $result = $this->db->query(
$sql);
587 $label = $langs->trans(
"ShowVatPayment").
': '.$this->ref;
589 $link =
'<a href="'.DOL_URL_ROOT.
'/compta/localtax/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
595 $result .= ($link.img_object($label, $picto,
'class="classfortooltip"').$linkend);
597 if ($withpicto && $withpicto != 2) {
600 if ($withpicto != 2) {
601 $result .= $link.$this->ref.$linkend;
614 return $this->
LibStatut($this->statut, $mode);
644 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
646 $return =
'<div class="box-flex-item box-flex-grow-zero">';
647 $return .=
'<div class="info-box info-box-sm">';
648 $return .=
'<span class="info-box-icon bg-infobox-action">';
650 $return .=
'</span>';
651 $return .=
'<div class="info-box-content">';
652 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
653 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
654 if (property_exists($this,
'label')) {
655 $return .=
' | <span class="info-box-label">'.$this->label.
'</span>';
657 if (property_exists($this,
'datev')) {
658 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"DateEnd").
'</span> : <span class="info-box-label">'.
dol_print_date($this->db->jdate($this->datev),
'day').
'</span>';
660 if (property_exists($this,
'datep')) {
661 $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>';
663 if (property_exists($this,
'amount')) {
664 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Amount").
'</span> : <span class="info-box-label amount">'.
price($this->amount).
'</span>';