31require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
43 public $element =
'tva';
48 public $table_element =
'tva';
53 public $picto =
'payment';
126 public $fk_user_creat;
131 public $fk_user_modif;
136 public $paiementtype;
139 const STATUS_UNPAID = 0;
140 const STATUS_PAID = 1;
161 global
$conf, $langs;
168 $this->label = trim($this->label);
169 $this->type_payment = (int) $this->type_payment;
170 $this->note = trim($this->note);
171 $this->fk_account = (int) $this->fk_account;
172 $this->fk_user_creat = (int) $this->fk_user_creat;
173 $this->fk_user_modif = (int) $this->fk_user_modif;
181 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"tva(";
189 $sql .=
"fk_account,";
190 $sql .=
"fk_typepayment,";
191 $sql .=
"fk_user_creat,";
192 $sql .=
"fk_user_modif";
193 $sql .=
") VALUES (";
194 $sql .=
" ".((int)
$conf->entity).
", ";
195 $sql .=
" '".$this->db->idate($now).
"',";
196 $sql .=
" '".$this->db->idate($this->datep).
"',";
197 $sql .=
" '".$this->db->idate($this->datev).
"',";
198 $sql .=
" '".$this->db->escape((
string) $this->
amount).
"',";
199 $sql .=
" '".$this->db->escape($this->label).
"',";
200 $sql .=
" '".$this->db->escape($this->note).
"',";
201 $sql .=
" '".$this->db->escape((
string) $this->fk_account).
"',";
202 $sql .=
" '".$this->db->escape((
string) $this->type_payment).
"',";
203 $sql .=
" ".($this->fk_user_creat > 0 ? (int) $this->fk_user_creat : (int) $user->id).
",";
204 $sql .=
" ".($this->fk_user_modif > 0 ? (int) $this->fk_user_modif : (int) $user->id);
207 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
208 $resql = $this->db->query($sql);
210 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"tva");
213 $result = $this->call_trigger(
'TVA_CREATE', $user);
223 $this->db->rollback();
227 $this->error =
"Error ".$this->db->lasterror();
228 $this->db->rollback();
240 public function update($user, $notrigger = 0)
242 global
$conf, $langs;
248 $this->label = trim($this->label);
249 $this->note = trim($this->note);
250 $this->fk_user_creat = (int) $this->fk_user_creat;
251 $this->fk_user_modif = (int) $this->fk_user_modif;
259 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"tva SET";
260 $sql .=
" tms='".$this->db->idate($this->tms).
"',";
261 $sql .=
" datep='".$this->db->idate($this->datep).
"',";
262 $sql .=
" datev='".$this->db->idate($this->datev).
"',";
263 $sql .=
" amount=".price2num($this->
amount).
",";
264 $sql .=
" label='".$this->db->escape($this->label).
"',";
265 $sql .=
" note='".$this->db->escape($this->note).
"',";
266 $sql .=
" fk_user_creat=".((int) $this->fk_user_creat).
",";
267 $sql .=
" fk_user_modif=".((int) ($this->fk_user_modif > 0 ? ((
int) $this->fk_user_modif) : ((int) $user->id)));
268 $sql .=
" WHERE rowid=".((int) $this->
id);
270 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
271 $resql = $this->db->query($sql);
273 $this->error =
"Error ".$this->db->lasterror();
277 if (!$error && !$notrigger) {
279 $result = $this->call_trigger(
'TVA_MODIFY', $user);
290 $this->db->rollback();
304 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"tva SET";
306 $sql .=
" WHERE rowid = ".((int) $this->
id);
307 $resql = $this->db->query($sql);
324 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"tva SET";
326 $sql .=
" WHERE rowid = ".((int) $this->
id);
327 $resql = $this->db->query($sql);
343 public function fetch($id, $ref =
'')
350 $sql .=
" t.amount,";
351 $sql .=
" t.fk_typepayment,";
352 $sql .=
" t.num_payment,";
356 $sql .=
" t.fk_user_creat,";
357 $sql .=
" t.fk_user_modif,";
358 $sql .=
" t.fk_account";
359 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
360 $sql .=
" WHERE t.rowid = ".((int) $id);
362 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
364 $resql = $this->db->query($sql);
366 if ($this->db->num_rows($resql)) {
367 $obj = $this->db->fetch_object($resql);
369 $this->
id = $obj->rowid;
370 $this->
ref = $obj->rowid;
371 $this->tms = $this->db->jdate($obj->tms);
372 $this->datep = $this->db->jdate($obj->datep);
373 $this->datev = $this->db->jdate($obj->datev);
374 $this->
amount = $obj->amount;
375 $this->type_payment = $obj->fk_typepayment;
376 $this->num_payment = $obj->num_payment;
377 $this->label = $obj->label;
378 $this->paye = $obj->paye;
379 $this->note = $obj->note;
380 $this->fk_user_creat = $obj->fk_user_creat;
381 $this->fk_user_modif = $obj->fk_user_modif;
382 $this->fk_account = $obj->fk_account;
383 $this->fk_type = empty($obj->fk_type) ?
"" : $obj->fk_type;
384 $this->rappro = empty($obj->rappro) ?
"" : $obj->rappro;
386 $this->db->free($resql);
390 $this->error =
"Error ".$this->db->lasterror();
406 if ($totalpaid < 0) {
409 return (empty($totalpaid) ? 1 : 0);
418 public function delete($user)
420 global
$conf, $langs;
425 $this->error =
'ErrorRecordHasChildren';
430 $result = $this->call_trigger(
'TVA_DELETE', $user);
436 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"tva";
437 $sql .=
" WHERE rowid=".((int) $this->
id);
439 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
440 $resql = $this->db->query($sql);
442 $this->error =
"Error ".$this->db->lasterror();
469 $this->fk_user_creat = 0;
470 $this->fk_user_modif = 0;
489 $solde = $reglee - ($collectee - $payee);
505 $sql =
"SELECT sum(f.total_tva) as amount";
506 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.paye = 1";
508 $sql .=
" AND f.datef >= '".((int) $year).
"-01-01' AND f.datef <= '".((int) $year).
"-12-31' ";
511 $result = $this->db->query($sql);
513 if ($this->db->num_rows($result)) {
514 $obj = $this->db->fetch_object($result);
516 $this->db->free($result);
519 $this->db->free($result);
523 print $this->db->lasterror();
539 $sql =
"SELECT sum(f.total_tva) as total_tva";
540 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
542 $sql .=
" WHERE f.datef >= '".((int) $year).
"-01-01' AND f.datef <= '".((int) $year).
"-12-31' ";
545 $result = $this->db->query($sql);
547 if ($this->db->num_rows($result)) {
548 $obj = $this->db->fetch_object($result);
549 $ret = $obj->total_tva;
550 $this->db->free($result);
553 $this->db->free($result);
557 print $this->db->lasterror();
574 $sql =
"SELECT sum(f.amount) as amount";
575 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as f";
578 $sql .=
" WHERE f.datev >= '".((int) $year).
"-01-01' AND f.datev <= '".((int) $year).
"-12-31' ";
581 $result = $this->db->query($sql);
583 if ($this->db->num_rows($result)) {
584 $obj = $this->db->fetch_object($result);
586 $this->db->free($result);
589 $this->db->free($result);
593 print $this->db->lasterror();
607 global
$conf, $langs;
613 $this->label = trim($this->label);
614 $this->note = trim($this->note);
615 $this->num_payment = trim($this->num_payment);
616 $this->fk_bank = (int) $this->fk_bank;
617 $this->fk_user_creat = (int) $this->fk_user_creat;
618 $this->fk_user_modif = (int) $this->fk_user_modif;
619 if (empty($this->datec)) {
625 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
628 if ($this->
amount ==
'') {
629 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
632 if (
isModEnabled(
"bank") && (empty($this->accountid) || $this->accountid <= 0)) {
633 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"BankAccount"));
636 if (
isModEnabled(
"bank") && (empty($this->type_payment) || $this->type_payment <= 0)) {
637 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
642 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"tva (";
647 $sql .=
", fk_typepayment";
648 $sql .=
", num_payment";
655 $sql .=
", fk_user_creat";
660 $sql .=
" '".$this->db->idate($this->datec).
"'";
661 $sql .=
", '".$this->db->idate($this->datep).
"'";
662 $sql .=
", '".$this->db->idate($this->datev).
"'";
663 $sql .=
", ".((float) $this->
amount);
664 $sql .=
", '".$this->db->escape((
string) $this->type_payment).
"'";
665 $sql .=
", '".$this->db->escape($this->num_payment).
"'";
667 $sql .=
", '".$this->db->escape($this->note).
"'";
670 $sql .=
", '".$this->db->escape($this->label).
"'";
672 $sql .=
", '".$this->db->escape((
string) $user->id).
"'";
674 $sql .=
", ".((int)
$conf->entity);
677 dol_syslog(get_class($this).
"::addPayment", LOG_DEBUG);
678 $result = $this->db->query($sql);
680 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"tva");
684 $result = $this->call_trigger(
'TVA_ADDPAYMENT', $user);
695 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
698 $result = $acc->fetch($this->accountid);
704 $bank_line_id = $acc->addline($this->datep, (
string) $this->type_payment, $this->label, -abs((
float) $this->
amount), $this->num_payment, 0, $user);
706 $bank_line_id = $acc->addline($this->datep, (
string) $this->type_payment, $this->label, abs((
float) $this->
amount), $this->num_payment, 0, $user);
710 if ($bank_line_id > 0) {
713 $this->error = $acc->error;
718 $result = $acc->add_url_line($bank_line_id, $this->
id, DOL_URL_ROOT.
'/compta/tva/card.php?id=',
"(VATPayment)",
"payment_vat");
720 $this->error = $acc->error;
729 $this->db->rollback();
733 $this->db->rollback();
737 $this->error = $this->db->error();
738 $this->db->rollback();
753 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'tva SET fk_bank = '.(int) $id_bank;
754 $sql .=
' WHERE rowid = '.(int) $this->
id;
755 $result = $this->db->query($sql);
774 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
776 global $langs,
$conf;
778 if (!empty(
$conf->dol_no_mouse_hover)) {
784 $label =
'<u>'.$langs->trans(
"ShowVatPayment").
'</u>';
786 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
787 if (!empty($this->label)) {
788 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
791 $url = DOL_URL_ROOT.
'/compta/tva/card.php?id='.$this->id;
793 if ($option !=
'nolink') {
795 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
796 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
797 $add_save_lastsearch_values = 1;
799 if ($add_save_lastsearch_values) {
800 $url .=
'&save_lastsearch_values=1';
805 if (empty($notooltip)) {
807 $label = $langs->trans(
"ShowMyObject");
808 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
810 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
811 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
813 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
816 $linkstart =
'<a href="'.$url.
'"';
817 $linkstart .= $linkclose.
'>';
822 $result .= $linkstart;
824 $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);
826 if ($withpicto != 2) {
827 $result .= $this->ref;
841 $sql =
'SELECT sum(amount) as amount';
842 $sql .=
' FROM '.MAIN_DB_PREFIX.
"payment_vat";
843 $sql .=
" WHERE fk_tva = ".((int) $this->
id);
845 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
846 $resql = $this->db->query($sql);
850 $obj = $this->db->fetch_object($resql);
852 $amount = $obj->amount ? $obj->amount : 0;
855 $this->db->free($resql);
870 $sql =
"SELECT t.rowid, t.tms, t.fk_user_modif, t.datec, t.fk_user_creat";
871 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
872 $sql .=
" WHERE t.rowid = ".(int) $id;
874 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
875 $result = $this->db->query($sql);
877 if ($this->db->num_rows($result)) {
878 $obj = $this->db->fetch_object($result);
880 $this->
id = $obj->rowid;
882 $this->user_creation_id = $obj->fk_user_creat;
883 $this->user_modification_id = $obj->fk_user_modif;
884 $this->date_creation = $this->db->jdate($obj->datec);
885 $this->date_modification = $this->db->jdate($obj->tms);
888 $this->db->free($result);
903 return $this->
LibStatut($this->paye, $mode, $alreadypaid);
915 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
921 $langs->loadLangs(array(
"customers",
"bills"));
924 $this->labelStatus = array();
925 $this->labelStatusShort = array();
927 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
930 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
931 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
932 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
933 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
935 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
936 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
937 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
938 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
942 $statusType =
'status1';
943 if ($status == 0 && $alreadypaid != 0) {
944 $statusType =
'status3';
947 $statusType =
'status6';
950 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
964 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
966 $return =
'<div class="box-flex-item box-flex-grow-zero">';
967 $return .=
'<div class="info-box info-box-sm">';
968 $return .=
'<span class="info-box-icon bg-infobox-action">';
971 $return .=
'</span>';
972 $return .=
'<div class="info-box-content">';
973 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
974 if ($selected >= 0) {
975 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
977 if (property_exists($this,
'amount')) {
978 $return .=
' | <span class="opacitymedium">'.$langs->trans(
"Amount").
'</span> : <span class="info-box-label amount">'.
price($this->
amount).
'</span>';
980 if (property_exists($this,
'type_payment')) {
981 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Payment").
'</span> : <span class="info-box-label">'.$this->type_payment.
'</span>';
983 if (property_exists($this,
'datev')) {
984 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"DateEnd").
'</span> : <span class="info-box-label" >'.
dol_print_date($this->datev).
'</span>';
986 if (method_exists($this,
'LibStatut')) {
987 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3, (
float) $this->alreadypaid).
'</div>';
1004 $sql =
"SELECT t.rowid";
1005 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
1006 $sql .=
" WHERE t.label = '".$this->db->escape($label).
"'";
1008 dol_syslog(get_class($this).
"::getIdForLabel", LOG_DEBUG);
1009 $result = $this->db->query($sql);
1011 if ($this->db->num_rows($result)) {
1012 $obj = $this->db->fetch_object($result);
1015 $this->db->free($result);
Class to manage bank accounts.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Class to manage VAT - Value-added tax (also known in French as TVA)
is_erasable()
Return if a VAT declaration can be deleted: not once a payment exists, as for invoices.
getIdForLabel($label)
Id of vat payment object.
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.
dol_now($mode='gmt')
Return date for now.
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)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
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.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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).
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.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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