30require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
42 public $element =
'tva';
47 public $table_element =
'tva';
52 public $picto =
'payment';
125 public $fk_user_creat;
130 public $fk_user_modif;
135 public $paiementtype;
138 const STATUS_UNPAID = 0;
139 const STATUS_PAID = 1;
160 global $conf, $langs;
166 $this->amount = (float)
price2num($this->amount);
167 $this->label = trim($this->label);
168 $this->type_payment = (int) $this->type_payment;
169 $this->note = trim($this->note);
170 $this->fk_account = (int) $this->fk_account;
171 $this->fk_user_creat = (int) $this->fk_user_creat;
172 $this->fk_user_modif = (int) $this->fk_user_modif;
180 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"tva(";
188 $sql .=
"fk_account,";
189 $sql .=
"fk_typepayment,";
190 $sql .=
"fk_user_creat,";
191 $sql .=
"fk_user_modif";
192 $sql .=
") VALUES (";
193 $sql .=
" ".((int) $conf->entity).
", ";
194 $sql .=
" '".$this->db->idate($now).
"',";
195 $sql .=
" '".$this->db->idate($this->datep).
"',";
196 $sql .=
" '".$this->db->idate($this->datev).
"',";
197 $sql .=
" '".$this->db->escape($this->amount).
"',";
198 $sql .=
" '".$this->db->escape($this->label).
"',";
199 $sql .=
" '".$this->db->escape($this->note).
"',";
200 $sql .=
" '".$this->db->escape($this->fk_account).
"',";
201 $sql .=
" '".$this->db->escape($this->type_payment).
"',";
202 $sql .=
" ".($this->fk_user_creat > 0 ? (int) $this->fk_user_creat : (int) $user->id).
",";
203 $sql .=
" ".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : (int) $user->id);
206 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
207 $resql = $this->db->query($sql);
209 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"tva");
222 $this->db->rollback();
226 $this->error =
"Error ".$this->db->lasterror();
227 $this->db->rollback();
239 public function update($user, $notrigger = 0)
241 global $conf, $langs;
246 $this->amount = (float)
price2num($this->amount);
247 $this->label = trim($this->label);
248 $this->note = trim($this->note);
249 $this->fk_user_creat = (int) $this->fk_user_creat;
250 $this->fk_user_modif = (int) $this->fk_user_modif;
258 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"tva SET";
259 $sql .=
" tms='".$this->db->idate($this->tms).
"',";
260 $sql .=
" datep='".$this->db->idate($this->datep).
"',";
261 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
262 $sql .=
" amount=".price2num($this->amount).
",";
263 $sql .=
" label='".$this->db->escape($this->label).
"',";
264 $sql .=
" note='".$this->db->escape($this->note).
"',";
265 $sql .=
" fk_user_creat=".((int) $this->fk_user_creat).
",";
266 $sql .=
" fk_user_modif=".((int) ($this->fk_user_modif > 0 ? $this->fk_user_modif : $user->id));
267 $sql .=
" WHERE rowid=".((int) $this->
id);
269 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
270 $resql = $this->db->query($sql);
272 $this->error =
"Error ".$this->db->lasterror();
276 if (!$error && !$notrigger) {
289 $this->db->rollback();
303 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"tva SET";
305 $sql .=
" WHERE rowid = ".((int) $this->
id);
306 $resql = $this->db->query($sql);
323 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"tva SET";
325 $sql .=
" WHERE rowid = ".((int) $this->
id);
326 $resql = $this->db->query($sql);
342 public function fetch($id, $ref =
'')
349 $sql .=
" t.amount,";
350 $sql .=
" t.fk_typepayment,";
351 $sql .=
" t.num_payment,";
355 $sql .=
" t.fk_user_creat,";
356 $sql .=
" t.fk_user_modif,";
357 $sql .=
" t.fk_account";
358 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
359 $sql .=
" WHERE t.rowid = ".((int) $id);
361 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
363 $resql = $this->db->query($sql);
365 if ($this->db->num_rows($resql)) {
366 $obj = $this->db->fetch_object($resql);
368 $this->
id = $obj->rowid;
369 $this->
ref = $obj->rowid;
370 $this->tms = $this->db->jdate($obj->tms);
371 $this->datep = $this->db->jdate($obj->datep);
372 $this->datev = $this->db->jdate($obj->datev);
373 $this->amount = $obj->amount;
374 $this->type_payment = $obj->fk_typepayment;
375 $this->num_payment = $obj->num_payment;
376 $this->label = $obj->label;
377 $this->paye = $obj->paye;
378 $this->note = $obj->note;
379 $this->fk_user_creat = $obj->fk_user_creat;
380 $this->fk_user_modif = $obj->fk_user_modif;
381 $this->fk_account = $obj->fk_account;
382 $this->fk_type = empty($obj->fk_type) ?
"" : $obj->fk_type;
383 $this->rappro = empty($obj->rappro) ?
"" : $obj->rappro;
385 $this->db->free($resql);
389 $this->error =
"Error ".$this->db->lasterror();
401 public function delete($user)
403 global $conf, $langs;
414 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"tva";
415 $sql .=
" WHERE rowid=".((int) $this->
id);
417 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
418 $resql = $this->db->query($sql);
420 $this->error =
"Error ".$this->db->lasterror();
443 $this->amount = 100.0;
447 $this->fk_user_creat = 0;
448 $this->fk_user_modif = 0;
467 $solde = $reglee - ($collectee - $payee);
483 $sql =
"SELECT sum(f.total_tva) as amount";
484 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.paye = 1";
486 $sql .=
" AND f.datef >= '".$this->db->escape($year).
"-01-01' AND f.datef <= '".$this->db->escape($year).
"-12-31' ";
489 $result = $this->db->query($sql);
491 if ($this->db->num_rows($result)) {
492 $obj = $this->db->fetch_object($result);
494 $this->db->free($result);
497 $this->db->free($result);
501 print $this->db->lasterror();
517 $sql =
"SELECT sum(f.total_tva) as total_tva";
518 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
520 $sql .=
" WHERE f.datef >= '".$this->db->escape($year).
"-01-01' AND f.datef <= '".$this->db->escape($year).
"-12-31' ";
523 $result = $this->db->query($sql);
525 if ($this->db->num_rows($result)) {
526 $obj = $this->db->fetch_object($result);
527 $ret = $obj->total_tva;
528 $this->db->free($result);
531 $this->db->free($result);
535 print $this->db->lasterror();
552 $sql =
"SELECT sum(f.amount) as amount";
553 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as f";
556 $sql .=
" WHERE f.datev >= '".$this->db->escape($year).
"-01-01' AND f.datev <= '".$this->db->escape($year).
"-12-31' ";
559 $result = $this->db->query($sql);
561 if ($this->db->num_rows($result)) {
562 $obj = $this->db->fetch_object($result);
564 $this->db->free($result);
567 $this->db->free($result);
571 print $this->db->lasterror();
585 global $conf, $langs;
590 $this->amount = (float)
price2num($this->amount);
591 $this->label = trim($this->label);
592 $this->note = trim($this->note);
593 $this->num_payment = trim($this->num_payment);
594 $this->fk_bank = (int) $this->fk_bank;
595 $this->fk_user_creat = (int) $this->fk_user_creat;
596 $this->fk_user_modif = (int) $this->fk_user_modif;
597 if (empty($this->datec)) {
603 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
606 if ($this->amount ==
'') {
607 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
610 if (isModEnabled(
"bank") && (empty($this->accountid) || $this->accountid <= 0)) {
611 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"BankAccount"));
614 if (isModEnabled(
"bank") && (empty($this->type_payment) || $this->type_payment <= 0)) {
615 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
620 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"tva (";
625 $sql .=
", fk_typepayment";
626 $sql .=
", num_payment";
633 $sql .=
", fk_user_creat";
638 $sql .=
" '".$this->db->idate($this->datec).
"'";
639 $sql .=
", '".$this->db->idate($this->datep).
"'";
640 $sql .=
", '".$this->db->idate($this->datev).
"'";
641 $sql .=
", ".((float) $this->amount);
642 $sql .=
", '".$this->db->escape($this->type_payment).
"'";
643 $sql .=
", '".$this->db->escape($this->num_payment).
"'";
645 $sql .=
", '".$this->db->escape($this->note).
"'";
648 $sql .=
", '".$this->db->escape($this->label).
"'";
650 $sql .=
", '".$this->db->escape($user->id).
"'";
652 $sql .=
", ".((int) $conf->entity);
655 dol_syslog(get_class($this).
"::addPayment", LOG_DEBUG);
656 $result = $this->db->query($sql);
658 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"tva");
671 if (isModEnabled(
"bank") && !empty($this->amount)) {
673 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
676 $result = $acc->fetch($this->accountid);
681 if ($this->amount > 0) {
682 $bank_line_id = $acc->addline($this->datep, $this->type_payment, $this->label, -abs((
float) $this->amount), $this->num_payment, 0, $user);
684 $bank_line_id = $acc->addline($this->datep, $this->type_payment, $this->label, abs((
float) $this->amount), $this->num_payment, 0, $user);
688 if ($bank_line_id > 0) {
691 $this->error = $acc->error;
696 $result = $acc->add_url_line($bank_line_id, $this->
id, DOL_URL_ROOT.
'/compta/tva/card.php?id=',
"(VATPayment)",
"payment_vat");
698 $this->error = $acc->error;
707 $this->db->rollback();
711 $this->db->rollback();
715 $this->error = $this->db->error();
716 $this->db->rollback();
731 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'tva SET fk_bank = '.(int) $id_bank;
732 $sql .=
' WHERE rowid = '.(int) $this->
id;
733 $result = $this->db->query($sql);
752 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
754 global $langs, $conf;
756 if (!empty($conf->dol_no_mouse_hover)) {
762 $label =
'<u>'.$langs->trans(
"ShowVatPayment").
'</u>';
764 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
765 if (!empty($this->label)) {
766 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
769 $url = DOL_URL_ROOT.
'/compta/tva/card.php?id='.$this->id;
771 if ($option !=
'nolink') {
773 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
774 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
775 $add_save_lastsearch_values = 1;
777 if ($add_save_lastsearch_values) {
778 $url .=
'&save_lastsearch_values=1';
783 if (empty($notooltip)) {
785 $label = $langs->trans(
"ShowMyObject");
786 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
788 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
789 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
791 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
794 $linkstart =
'<a href="'.$url.
'"';
795 $linkstart .= $linkclose.
'>';
800 $result .= $linkstart;
802 $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);
804 if ($withpicto != 2) {
805 $result .= $this->ref;
819 $table =
'payment_vat';
822 $sql =
'SELECT sum(amount) as amount';
823 $sql .=
' FROM '.MAIN_DB_PREFIX.$table;
824 $sql .=
" WHERE ".$field.
" = ".((int) $this->
id);
826 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
827 $resql = $this->db->query($sql);
831 $obj = $this->db->fetch_object($resql);
833 $amount = $obj->amount ? $obj->amount : 0;
836 $this->db->free($resql);
851 $sql =
"SELECT t.rowid, t.tms, t.fk_user_modif, t.datec, t.fk_user_creat";
852 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
853 $sql .=
" WHERE t.rowid = ".(int) $id;
855 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
856 $result = $this->db->query($sql);
858 if ($this->db->num_rows($result)) {
859 $obj = $this->db->fetch_object($result);
861 $this->
id = $obj->rowid;
863 $this->user_creation_id = $obj->fk_user_creat;
864 $this->user_modification_id = $obj->fk_user_modif;
865 $this->date_creation = $this->db->jdate($obj->datec);
866 $this->date_modification = $this->db->jdate($obj->tms);
869 $this->db->free($result);
884 return $this->
LibStatut($this->paye, $mode, $alreadypaid);
896 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
902 $langs->loadLangs(array(
"customers",
"bills"));
905 $this->labelStatus = array();
906 $this->labelStatusShort = array();
908 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
911 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
912 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
913 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
914 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
916 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
917 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
918 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
919 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
923 $statusType =
'status1';
924 if ($status == 0 && $alreadypaid != 0) {
925 $statusType =
'status3';
928 $statusType =
'status6';
931 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
945 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
947 $return =
'<div class="box-flex-item box-flex-grow-zero">';
948 $return .=
'<div class="info-box info-box-sm">';
949 $return .=
'<span class="info-box-icon bg-infobox-action">';
952 $return .=
'</span>';
953 $return .=
'<div class="info-box-content">';
954 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
955 if ($selected >= 0) {
956 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
958 if (property_exists($this,
'amount')) {
959 $return .=
' | <span class="opacitymedium">'.$langs->trans(
"Amount").
'</span> : <span class="info-box-label amount">'.
price($this->amount).
'</span>';
961 if (property_exists($this,
'type_payment')) {
962 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Payement").
'</span> : <span class="info-box-label">'.$this->type_payment.
'</span>';
964 if (property_exists($this,
'datev')) {
965 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"DateEnd").
'</span> : <span class="info-box-label" >'.
dol_print_date($this->datev).
'</span>';
967 if (method_exists($this,
'LibStatut')) {
968 $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.
Class to manage VAT - Value-added tax (also known in French as TVA - Taxe sur la valeur ajoutée)
getKanbanView($option='', $arraydata=null)
Return clickable 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 clickable (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 a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.