30require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
41 public $element =
'tva';
46 public $table_element =
'tva';
51 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 = 0;
431 $this->fk_user_modif = 0;
450 $solde = $reglee - ($collectee - $payee);
466 $sql =
"SELECT sum(f.total_tva) as amount";
467 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.paye = 1";
469 $sql .=
" AND f.datef >= '".$this->db->escape($year).
"-01-01' AND f.datef <= '".$this->db->escape($year).
"-12-31' ";
472 $result = $this->db->query($sql);
474 if ($this->db->num_rows($result)) {
475 $obj = $this->db->fetch_object($result);
477 $this->db->free($result);
480 $this->db->free($result);
484 print $this->db->lasterror();
500 $sql =
"SELECT sum(f.total_tva) as total_tva";
501 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
503 $sql .=
" WHERE f.datef >= '".$this->db->escape($year).
"-01-01' AND f.datef <= '".$this->db->escape($year).
"-12-31' ";
506 $result = $this->db->query($sql);
508 if ($this->db->num_rows($result)) {
509 $obj = $this->db->fetch_object($result);
510 $ret = $obj->total_tva;
511 $this->db->free($result);
514 $this->db->free($result);
518 print $this->db->lasterror();
535 $sql =
"SELECT sum(f.amount) as amount";
536 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as f";
539 $sql .=
" WHERE f.datev >= '".$this->db->escape($year).
"-01-01' AND f.datev <= '".$this->db->escape($year).
"-12-31' ";
542 $result = $this->db->query($sql);
544 if ($this->db->num_rows($result)) {
545 $obj = $this->db->fetch_object($result);
547 $this->db->free($result);
550 $this->db->free($result);
554 print $this->db->lasterror();
568 global $conf, $langs;
573 $this->amount =
price2num(trim($this->amount));
574 $this->label = trim($this->label);
575 $this->note = trim($this->note);
576 $this->num_payment = trim($this->num_payment);
577 $this->fk_bank = (int) $this->fk_bank;
578 $this->fk_user_creat = (int) $this->fk_user_creat;
579 $this->fk_user_modif = (int) $this->fk_user_modif;
580 if (empty($this->datec)) {
586 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
589 if ($this->amount ==
'') {
590 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
593 if (isModEnabled(
"bank") && (empty($this->accountid) || $this->accountid <= 0)) {
594 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"BankAccount"));
597 if (isModEnabled(
"bank") && (empty($this->type_payment) || $this->type_payment <= 0)) {
598 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
603 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"tva (";
608 $sql .=
", fk_typepayment";
609 $sql .=
", num_payment";
616 $sql .=
", fk_user_creat";
621 $sql .=
" '".$this->db->idate($this->datec).
"'";
622 $sql .=
", '".$this->db->idate($this->datep).
"'";
623 $sql .=
", '".$this->db->idate($this->datev).
"'";
624 $sql .=
", ".((float) $this->amount);
625 $sql .=
", '".$this->db->escape($this->type_payment).
"'";
626 $sql .=
", '".$this->db->escape($this->num_payment).
"'";
628 $sql .=
", '".$this->db->escape($this->note).
"'";
631 $sql .=
", '".$this->db->escape($this->label).
"'";
633 $sql .=
", '".$this->db->escape($user->id).
"'";
635 $sql .=
", ".((int) $conf->entity);
638 dol_syslog(get_class($this).
"::addPayment", LOG_DEBUG);
639 $result = $this->db->query($sql);
641 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"tva");
654 if (isModEnabled(
"bank") && !empty($this->amount)) {
656 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
659 $result = $acc->fetch($this->accountid);
664 if ($this->amount > 0) {
665 $bank_line_id = $acc->addline($this->datep, $this->type_payment, $this->label, -abs((
float) $this->amount), $this->num_payment,
'', $user);
667 $bank_line_id = $acc->addline($this->datep, $this->type_payment, $this->label, abs((
float) $this->amount), $this->num_payment,
'', $user);
671 if ($bank_line_id > 0) {
674 $this->error = $acc->error;
679 $result = $acc->add_url_line($bank_line_id, $this->
id, DOL_URL_ROOT.
'/compta/tva/card.php?id=',
"(VATPayment)",
"payment_vat");
681 $this->error = $acc->error;
690 $this->db->rollback();
694 $this->db->rollback();
698 $this->error = $this->db->error();
699 $this->db->rollback();
714 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'tva SET fk_bank = '.(int) $id_bank;
715 $sql .=
' WHERE rowid = '.(int) $this->
id;
716 $result = $this->db->query($sql);
735 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
737 global $langs, $conf;
739 if (!empty($conf->dol_no_mouse_hover)) {
745 $label =
'<u>'.$langs->trans(
"ShowVatPayment").
'</u>';
747 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
748 if (!empty($this->label)) {
749 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
752 $url = DOL_URL_ROOT.
'/compta/tva/card.php?id='.$this->id;
754 if ($option !=
'nolink') {
756 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
757 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
758 $add_save_lastsearch_values = 1;
760 if ($add_save_lastsearch_values) {
761 $url .=
'&save_lastsearch_values=1';
766 if (empty($notooltip)) {
768 $label = $langs->trans(
"ShowMyObject");
769 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
771 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
772 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
774 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
777 $linkstart =
'<a href="'.$url.
'"';
778 $linkstart .= $linkclose.
'>';
783 $result .= $linkstart;
785 $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);
787 if ($withpicto != 2) {
788 $result .= $this->ref;
802 $table =
'payment_vat';
805 $sql =
'SELECT sum(amount) as amount';
806 $sql .=
' FROM '.MAIN_DB_PREFIX.$table;
807 $sql .=
" WHERE ".$field.
" = ".((int) $this->
id);
809 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
810 $resql = $this->db->query($sql);
814 $obj = $this->db->fetch_object($resql);
816 $amount = $obj->amount ? $obj->amount : 0;
819 $this->db->free($resql);
834 $sql =
"SELECT t.rowid, t.tms, t.fk_user_modif, t.datec, t.fk_user_creat";
835 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
836 $sql .=
" WHERE t.rowid = ".(int) $id;
838 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
839 $result = $this->db->query($sql);
841 if ($this->db->num_rows($result)) {
842 $obj = $this->db->fetch_object($result);
844 $this->
id = $obj->rowid;
846 $this->user_creation_id = $obj->fk_user_creat;
847 $this->user_modification_id = $obj->fk_user_modif;
848 $this->date_creation = $this->db->jdate($obj->datec);
849 $this->date_modification = $this->db->jdate($obj->tms);
852 $this->db->free($result);
867 return $this->
LibStatut($this->paye, $mode, $alreadypaid);
879 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
885 $langs->loadLangs(array(
"customers",
"bills"));
888 $this->labelStatus = array();
889 $this->labelStatusShort = array();
891 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
894 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
895 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
896 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
897 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
899 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
900 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
901 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
902 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
906 $statusType =
'status1';
907 if ($status == 0 && $alreadypaid != 0) {
908 $statusType =
'status3';
911 $statusType =
'status6';
914 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
928 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
930 $return =
'<div class="box-flex-item box-flex-grow-zero">';
931 $return .=
'<div class="info-box info-box-sm">';
932 $return .=
'<span class="info-box-icon bg-infobox-action">';
935 $return .=
'</span>';
936 $return .=
'<div class="info-box-content">';
937 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
938 if ($selected >= 0) {
939 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
941 if (property_exists($this,
'amount')) {
942 $return .=
' | <span class="opacitymedium">'.$langs->trans(
"Amount").
'</span> : <span class="info-box-label amount">'.
price($this->amount).
'</span>';
944 if (property_exists($this,
'type_payment')) {
945 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Payement").
'</span> : <span class="info-box-label">'.$this->type_payment.
'</span>';
947 if (property_exists($this,
'datev')) {
948 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"DateEnd").
'</span> : <span class="info-box-label" >'.
dol_print_date($this->datev).
'</span>';
950 if (method_exists($this,
'LibStatut')) {
951 $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 paid.
setUnpaid($user)
Remove tag paid 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 paid completely.
initAsSpecimen()
Initialise an instance with random values.
info($id)
Information of vat payment object.
create($user)
Create in database.
tva_sum_reglee($year=0)
Total of the VAT paid.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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...
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.