29require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40 public $element =
'tva';
45 public $table_element =
'tva';
50 public $picto =
'payment';
108 public $fk_user_creat;
113 public $fk_user_modif;
118 public $paiementtype;
121 const STATUS_UNPAID = 0;
122 const STATUS_PAID = 1;
143 global $conf, $langs;
149 $this->amount = trim($this->amount);
150 $this->label = trim($this->label);
151 $this->type_payment = (int) $this->type_payment;
152 $this->note = trim($this->note);
153 $this->fk_account = (int) $this->fk_account;
154 $this->fk_user_creat = (int) $this->fk_user_creat;
155 $this->fk_user_modif = (int) $this->fk_user_modif;
163 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"tva(";
171 $sql .=
"fk_account,";
172 $sql .=
"fk_typepayment,";
173 $sql .=
"fk_user_creat,";
174 $sql .=
"fk_user_modif";
175 $sql .=
") VALUES (";
176 $sql .=
" ".((int) $conf->entity).
", ";
177 $sql .=
" '".$this->db->idate($now).
"',";
178 $sql .=
" '".$this->db->idate($this->datep).
"',";
179 $sql .=
" '".$this->db->idate($this->datev).
"',";
180 $sql .=
" '".$this->db->escape($this->amount).
"',";
181 $sql .=
" '".$this->db->escape($this->label).
"',";
182 $sql .=
" '".$this->db->escape($this->note).
"',";
183 $sql .=
" '".$this->db->escape($this->fk_account).
"',";
184 $sql .=
" '".$this->db->escape($this->type_payment).
"',";
185 $sql .=
" ".($this->fk_user_creat > 0 ? (int) $this->fk_user_creat : (int) $user->id).
",";
186 $sql .=
" ".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : (int) $user->id);
189 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
190 $resql = $this->db->query($sql);
192 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"tva");
205 $this->db->rollback();
209 $this->error =
"Error ".$this->db->lasterror();
210 $this->db->rollback();
222 public function update($user, $notrigger = 0)
224 global $conf, $langs;
229 $this->amount = trim($this->amount);
230 $this->label = trim($this->label);
231 $this->note = trim($this->note);
232 $this->fk_user_creat = (int) $this->fk_user_creat;
233 $this->fk_user_modif = (int) $this->fk_user_modif;
241 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"tva SET";
242 $sql .=
" tms='".$this->db->idate($this->tms).
"',";
243 $sql .=
" datep='".$this->db->idate($this->datep).
"',";
244 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
245 $sql .=
" amount=".price2num($this->amount).
",";
246 $sql .=
" label='".$this->db->escape($this->label).
"',";
247 $sql .=
" note='".$this->db->escape($this->note).
"',";
248 $sql .=
" fk_user_creat=".((int) $this->fk_user_creat).
",";
249 $sql .=
" fk_user_modif=".((int) ($this->fk_user_modif > 0 ? $this->fk_user_modif : $user->id));
250 $sql .=
" WHERE rowid=".((int) $this->
id);
252 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
253 $resql = $this->db->query($sql);
255 $this->error =
"Error ".$this->db->lasterror();
259 if (!$error && !$notrigger) {
272 $this->db->rollback();
286 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"tva SET";
288 $sql .=
" WHERE rowid = ".((int) $this->
id);
289 $resql = $this->db->query($sql);
306 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"tva SET";
308 $sql .=
" WHERE rowid = ".((int) $this->
id);
309 $resql = $this->db->query($sql);
325 public function fetch($id, $ref =
'')
332 $sql .=
" t.amount,";
333 $sql .=
" t.fk_typepayment,";
334 $sql .=
" t.num_payment,";
338 $sql .=
" t.fk_user_creat,";
339 $sql .=
" t.fk_user_modif,";
340 $sql .=
" t.fk_account";
341 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
342 $sql .=
" WHERE t.rowid = ".((int) $id);
344 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
346 $resql = $this->db->query($sql);
348 if ($this->db->num_rows($resql)) {
349 $obj = $this->db->fetch_object($resql);
351 $this->
id = $obj->rowid;
352 $this->
ref = $obj->rowid;
353 $this->tms = $this->db->jdate($obj->tms);
354 $this->datep = $this->db->jdate($obj->datep);
355 $this->datev = $this->db->jdate($obj->datev);
356 $this->amount = $obj->amount;
357 $this->type_payment = $obj->fk_typepayment;
358 $this->num_payment = $obj->num_payment;
359 $this->label = $obj->label;
360 $this->paye = $obj->paye;
361 $this->note = $obj->note;
362 $this->fk_user_creat = $obj->fk_user_creat;
363 $this->fk_user_modif = $obj->fk_user_modif;
364 $this->fk_account = $obj->fk_account;
365 $this->fk_type = empty($obj->fk_type) ?
"" : $obj->fk_type;
366 $this->rappro = empty($obj->rappro) ?
"" : $obj->rappro;
368 $this->db->free($resql);
372 $this->error =
"Error ".$this->db->lasterror();
384 public function delete($user)
386 global $conf, $langs;
397 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"tva";
398 $sql .=
" WHERE rowid=".((int) $this->
id);
400 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
401 $resql = $this->db->query($sql);
403 $this->error =
"Error ".$this->db->lasterror();
430 $this->fk_user_creat =
'';
431 $this->fk_user_modif =
'';
448 $solde = $reglee - ($collectee - $payee);
464 $sql =
"SELECT sum(f.total_tva) as amount";
465 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.paye = 1";
467 $sql .=
" AND f.datef >= '".$this->db->escape($year).
"-01-01' AND f.datef <= '".$this->db->escape($year).
"-12-31' ";
470 $result = $this->db->query($sql);
472 if ($this->db->num_rows($result)) {
473 $obj = $this->db->fetch_object($result);
475 $this->db->free($result);
478 $this->db->free($result);
482 print $this->db->lasterror();
498 $sql =
"SELECT sum(f.total_tva) as total_tva";
499 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
501 $sql .=
" WHERE f.datef >= '".$this->db->escape($year).
"-01-01' AND f.datef <= '".$this->db->escape($year).
"-12-31' ";
504 $result = $this->db->query($sql);
506 if ($this->db->num_rows($result)) {
507 $obj = $this->db->fetch_object($result);
508 $ret = $obj->total_tva;
509 $this->db->free($result);
512 $this->db->free($result);
516 print $this->db->lasterror();
533 $sql =
"SELECT sum(f.amount) as amount";
534 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as f";
537 $sql .=
" WHERE f.datev >= '".$this->db->escape($year).
"-01-01' AND f.datev <= '".$this->db->escape($year).
"-12-31' ";
540 $result = $this->db->query($sql);
542 if ($this->db->num_rows($result)) {
543 $obj = $this->db->fetch_object($result);
545 $this->db->free($result);
548 $this->db->free($result);
552 print $this->db->lasterror();
566 global $conf, $langs;
571 $this->amount =
price2num(trim($this->amount));
572 $this->label = trim($this->label);
573 $this->note = trim($this->note);
574 $this->num_payment = trim($this->num_payment);
575 $this->fk_bank = (int) $this->fk_bank;
576 $this->fk_user_creat = (int) $this->fk_user_creat;
577 $this->fk_user_modif = (int) $this->fk_user_modif;
578 if (empty($this->datec)) {
584 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
587 if ($this->amount ==
'') {
588 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
591 if (isModEnabled(
"banque") && (empty($this->accountid) || $this->accountid <= 0)) {
592 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Account"));
595 if (isModEnabled(
"banque") && (empty($this->type_payment) || $this->type_payment <= 0)) {
596 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
601 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"tva (";
606 $sql .=
", fk_typepayment";
607 $sql .=
", num_payment";
614 $sql .=
", fk_user_creat";
619 $sql .=
" '".$this->db->idate($this->datec).
"'";
620 $sql .=
", '".$this->db->idate($this->datep).
"'";
621 $sql .=
", '".$this->db->idate($this->datev).
"'";
622 $sql .=
", ".((float) $this->amount);
623 $sql .=
", '".$this->db->escape($this->type_payment).
"'";
624 $sql .=
", '".$this->db->escape($this->num_payment).
"'";
626 $sql .=
", '".$this->db->escape($this->note).
"'";
629 $sql .=
", '".$this->db->escape($this->label).
"'";
631 $sql .=
", '".$this->db->escape($user->id).
"'";
633 $sql .=
", ".((int) $conf->entity);
636 dol_syslog(get_class($this).
"::addPayment", LOG_DEBUG);
637 $result = $this->db->query($sql);
639 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"tva");
652 if (isModEnabled(
"banque") && !empty($this->amount)) {
654 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
657 $result = $acc->fetch($this->accountid);
662 if ($this->amount > 0) {
663 $bank_line_id = $acc->addline($this->datep, $this->type_payment, $this->label, -abs($this->amount), $this->num_payment,
'', $user);
665 $bank_line_id = $acc->addline($this->datep, $this->type_payment, $this->label, abs($this->amount), $this->num_payment,
'', $user);
669 if ($bank_line_id > 0) {
672 $this->error = $acc->error;
677 $result = $acc->add_url_line($bank_line_id, $this->
id, DOL_URL_ROOT.
'/compta/tva/card.php?id=',
"(VATPayment)",
"payment_vat");
679 $this->error = $acc->error;
688 $this->db->rollback();
692 $this->db->rollback();
696 $this->error = $this->db->error();
697 $this->db->rollback();
712 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'tva SET fk_bank = '.(int) $id_bank;
713 $sql .=
' WHERE rowid = '.(int) $this->
id;
714 $result = $this->db->query($sql);
733 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
735 global $langs, $conf;
737 if (!empty($conf->dol_no_mouse_hover)) {
743 $label =
'<u>'.$langs->trans(
"ShowVatPayment").
'</u>';
745 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
746 if (!empty($this->label)) {
747 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
750 $url = DOL_URL_ROOT.
'/compta/tva/card.php?id='.$this->id;
752 if ($option !=
'nolink') {
754 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
755 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
756 $add_save_lastsearch_values = 1;
758 if ($add_save_lastsearch_values) {
759 $url .=
'&save_lastsearch_values=1';
764 if (empty($notooltip)) {
766 $label = $langs->trans(
"ShowMyObject");
767 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
769 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
770 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
772 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
775 $linkstart =
'<a href="'.$url.
'"';
776 $linkstart .= $linkclose.
'>';
781 $result .= $linkstart;
783 $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);
785 if ($withpicto != 2) {
786 $result .= $this->ref;
800 $table =
'payment_vat';
803 $sql =
'SELECT sum(amount) as amount';
804 $sql .=
' FROM '.MAIN_DB_PREFIX.$table;
805 $sql .=
" WHERE ".$field.
" = ".((int) $this->
id);
807 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
808 $resql = $this->db->query($sql);
812 $obj = $this->db->fetch_object($resql);
814 $amount = $obj->amount ? $obj->amount : 0;
817 $this->db->free($resql);
832 $sql =
"SELECT t.rowid, t.tms, t.fk_user_modif, t.datec, t.fk_user_creat";
833 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
834 $sql .=
" WHERE t.rowid = ".(int) $id;
836 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
837 $result = $this->db->query($sql);
839 if ($this->db->num_rows($result)) {
840 $obj = $this->db->fetch_object($result);
842 $this->
id = $obj->rowid;
844 $this->user_creation_id = $obj->fk_user_creat;
845 $this->user_modification_id = $obj->fk_user_modif;
846 $this->date_creation = $this->db->jdate($obj->datec);
847 $this->date_modification = $this->db->jdate($obj->tms);
850 $this->db->free($result);
865 return $this->
LibStatut($this->paye, $mode, $alreadypaid);
877 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
883 $langs->loadLangs(array(
"customers",
"bills"));
886 $this->labelStatus = array();
887 $this->labelStatusShort = array();
889 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
892 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
893 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
894 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
895 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
897 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
898 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
899 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
900 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
904 $statusType =
'status1';
905 if ($status == 0 && $alreadypaid != 0) {
906 $statusType =
'status3';
909 $statusType =
'status6';
912 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
926 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
928 $return =
'<div class="box-flex-item box-flex-grow-zero">';
929 $return .=
'<div class="info-box info-box-sm">';
930 $return .=
'<span class="info-box-icon bg-infobox-action">';
933 $return .=
'</span>';
934 $return .=
'<div class="info-box-content">';
935 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
936 if ($selected >= 0) {
937 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
939 if (property_exists($this,
'amount')) {
940 $return .=
' | <span class="opacitymedium">'.$langs->trans(
"Amount").
'</span> : <span class="info-box-label amount">'.
price($this->amount).
'</span>';
942 if (property_exists($this,
'type_payment')) {
943 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Payement").
'</span> : <span class="info-box-label">'.$this->type_payment.
'</span>';
945 if (property_exists($this,
'datev')) {
946 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"DateEnd").
'</span> : <span class="info-box-label" >'.
dol_print_date($this->datev).
'</span>';
948 if (method_exists($this,
'LibStatut')) {
949 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3, $this->alreadypaid).
'</div>';
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.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
tva_sum_collectee($year=0)
Total of the VAT from invoices emitted by the thirdparty.
LibStatut($status, $mode=0, $alreadypaid=-1)
Return the label of a given VAT status.
tva_sum_payee($year=0)
VAT payed.
setUnpaid($user)
Remove tag payed on TVA.
__construct($db)
Constructor.
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)
Return the label of the VAT status f object.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Send name clicable (with possibly the picto)
fetch($id, $ref='')
Load object in memory from database.
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.
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)
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).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.