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 ? $this->fk_user_modif : $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();
402 public function delete($user)
404 global $conf, $langs;
409 $result = $this->call_trigger(
'TVA_DELETE', $user);
415 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"tva";
416 $sql .=
" WHERE rowid=".((int) $this->
id);
418 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
419 $resql = $this->db->query($sql);
421 $this->error =
"Error ".$this->db->lasterror();
448 $this->fk_user_creat = 0;
449 $this->fk_user_modif = 0;
468 $solde = $reglee - ($collectee - $payee);
484 $sql =
"SELECT sum(f.total_tva) as amount";
485 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture as f WHERE f.paye = 1";
487 $sql .=
" AND f.datef >= '".((int) $year).
"-01-01' AND f.datef <= '".((int) $year).
"-12-31' ";
490 $result = $this->db->query($sql);
492 if ($this->db->num_rows($result)) {
493 $obj = $this->db->fetch_object($result);
495 $this->db->free($result);
498 $this->db->free($result);
502 print $this->db->lasterror();
518 $sql =
"SELECT sum(f.total_tva) as total_tva";
519 $sql .=
" FROM ".MAIN_DB_PREFIX.
"facture_fourn as f";
521 $sql .=
" WHERE f.datef >= '".((int) $year).
"-01-01' AND f.datef <= '".((int) $year).
"-12-31' ";
524 $result = $this->db->query($sql);
526 if ($this->db->num_rows($result)) {
527 $obj = $this->db->fetch_object($result);
528 $ret = $obj->total_tva;
529 $this->db->free($result);
532 $this->db->free($result);
536 print $this->db->lasterror();
553 $sql =
"SELECT sum(f.amount) as amount";
554 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as f";
557 $sql .=
" WHERE f.datev >= '".((int) $year).
"-01-01' AND f.datev <= '".((int) $year).
"-12-31' ";
560 $result = $this->db->query($sql);
562 if ($this->db->num_rows($result)) {
563 $obj = $this->db->fetch_object($result);
565 $this->db->free($result);
568 $this->db->free($result);
572 print $this->db->lasterror();
586 global $conf, $langs;
592 $this->label = trim($this->label);
593 $this->note = trim($this->note);
594 $this->num_payment = trim($this->num_payment);
595 $this->fk_bank = (int) $this->fk_bank;
596 $this->fk_user_creat = (int) $this->fk_user_creat;
597 $this->fk_user_modif = (int) $this->fk_user_modif;
598 if (empty($this->datec)) {
604 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Label"));
607 if ($this->
amount ==
'') {
608 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Amount"));
611 if (
isModEnabled(
"bank") && (empty($this->accountid) || $this->accountid <= 0)) {
612 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"BankAccount"));
615 if (
isModEnabled(
"bank") && (empty($this->type_payment) || $this->type_payment <= 0)) {
616 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"PaymentMode"));
621 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"tva (";
626 $sql .=
", fk_typepayment";
627 $sql .=
", num_payment";
634 $sql .=
", fk_user_creat";
639 $sql .=
" '".$this->db->idate($this->datec).
"'";
640 $sql .=
", '".$this->db->idate($this->datep).
"'";
641 $sql .=
", '".$this->db->idate($this->datev).
"'";
642 $sql .=
", ".((float) $this->
amount);
643 $sql .=
", '".$this->db->escape((
string) $this->type_payment).
"'";
644 $sql .=
", '".$this->db->escape($this->num_payment).
"'";
646 $sql .=
", '".$this->db->escape($this->note).
"'";
649 $sql .=
", '".$this->db->escape($this->label).
"'";
651 $sql .=
", '".$this->db->escape((
string) $user->id).
"'";
653 $sql .=
", ".((int) $conf->entity);
656 dol_syslog(get_class($this).
"::addPayment", LOG_DEBUG);
657 $result = $this->db->query($sql);
659 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"tva");
663 $result = $this->call_trigger(
'TVA_ADDPAYMENT', $user);
674 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
677 $result = $acc->fetch($this->accountid);
683 $bank_line_id = $acc->addline($this->datep, (
string) $this->type_payment, $this->label, -abs((
float) $this->
amount), $this->num_payment, 0, $user);
685 $bank_line_id = $acc->addline($this->datep, (
string) $this->type_payment, $this->label, abs((
float) $this->
amount), $this->num_payment, 0, $user);
689 if ($bank_line_id > 0) {
692 $this->error = $acc->error;
697 $result = $acc->add_url_line($bank_line_id, $this->
id, DOL_URL_ROOT.
'/compta/tva/card.php?id=',
"(VATPayment)",
"payment_vat");
699 $this->error = $acc->error;
708 $this->db->rollback();
712 $this->db->rollback();
716 $this->error = $this->db->error();
717 $this->db->rollback();
732 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'tva SET fk_bank = '.(int) $id_bank;
733 $sql .=
' WHERE rowid = '.(int) $this->
id;
734 $result = $this->db->query($sql);
753 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
755 global $langs, $conf;
757 if (!empty($conf->dol_no_mouse_hover)) {
763 $label =
'<u>'.$langs->trans(
"ShowVatPayment").
'</u>';
765 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
766 if (!empty($this->label)) {
767 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
770 $url = DOL_URL_ROOT.
'/compta/tva/card.php?id='.$this->id;
772 if ($option !=
'nolink') {
774 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
775 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
776 $add_save_lastsearch_values = 1;
778 if ($add_save_lastsearch_values) {
779 $url .=
'&save_lastsearch_values=1';
784 if (empty($notooltip)) {
786 $label = $langs->trans(
"ShowMyObject");
787 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
789 $linkclose .=
' title="'.dolPrintHTMLForAttribute($label).
'"';
790 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
792 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
795 $linkstart =
'<a href="'.$url.
'"';
796 $linkstart .= $linkclose.
'>';
801 $result .= $linkstart;
803 $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);
805 if ($withpicto != 2) {
806 $result .= $this->ref;
820 $table =
'payment_vat';
823 $sql =
'SELECT sum(amount) as amount';
824 $sql .=
' FROM '.MAIN_DB_PREFIX.$table;
825 $sql .=
" WHERE ".$field.
" = ".((int) $this->
id);
827 dol_syslog(get_class($this).
"::getSommePaiement", LOG_DEBUG);
828 $resql = $this->db->query($sql);
832 $obj = $this->db->fetch_object($resql);
834 $amount = $obj->amount ? $obj->amount : 0;
837 $this->db->free($resql);
852 $sql =
"SELECT t.rowid, t.tms, t.fk_user_modif, t.datec, t.fk_user_creat";
853 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
854 $sql .=
" WHERE t.rowid = ".(int) $id;
856 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
857 $result = $this->db->query($sql);
859 if ($this->db->num_rows($result)) {
860 $obj = $this->db->fetch_object($result);
862 $this->
id = $obj->rowid;
864 $this->user_creation_id = $obj->fk_user_creat;
865 $this->user_modification_id = $obj->fk_user_modif;
866 $this->date_creation = $this->db->jdate($obj->datec);
867 $this->date_modification = $this->db->jdate($obj->tms);
870 $this->db->free($result);
885 return $this->
LibStatut($this->paye, $mode, $alreadypaid);
897 public function LibStatut($status, $mode = 0, $alreadypaid = -1)
903 $langs->loadLangs(array(
"customers",
"bills"));
906 $this->labelStatus = array();
907 $this->labelStatusShort = array();
909 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
912 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
913 $this->labelStatus[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
914 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
915 $this->labelStatus[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
917 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
'BillStatusNotPaid');
918 $this->labelStatusShort[self::STATUS_PAID] = $langs->transnoentitiesnoconv(
'BillStatusPaid');
919 if ($status == self::STATUS_UNPAID && $alreadypaid != 0) {
920 $this->labelStatusShort[self::STATUS_UNPAID] = $langs->transnoentitiesnoconv(
"BillStatusStarted");
924 $statusType =
'status1';
925 if ($status == 0 && $alreadypaid != 0) {
926 $statusType =
'status3';
929 $statusType =
'status6';
932 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
946 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
948 $return =
'<div class="box-flex-item box-flex-grow-zero">';
949 $return .=
'<div class="info-box info-box-sm">';
950 $return .=
'<span class="info-box-icon bg-infobox-action">';
953 $return .=
'</span>';
954 $return .=
'<div class="info-box-content">';
955 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
956 if ($selected >= 0) {
957 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
959 if (property_exists($this,
'amount')) {
960 $return .=
' | <span class="opacitymedium">'.$langs->trans(
"Amount").
'</span> : <span class="info-box-label amount">'.
price($this->
amount).
'</span>';
962 if (property_exists($this,
'type_payment')) {
963 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Payement").
'</span> : <span class="info-box-label">'.$this->type_payment.
'</span>';
965 if (property_exists($this,
'datev')) {
966 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"DateEnd").
'</span> : <span class="info-box-label" >'.
dol_print_date($this->datev).
'</span>';
968 if (method_exists($this,
'LibStatut')) {
969 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3, (
float) $this->alreadypaid).
'</div>';
986 $sql =
"SELECT t.rowid";
987 $sql .=
" FROM ".MAIN_DB_PREFIX.
"tva as t";
988 $sql .=
" WHERE t.label = '".$this->db->escape($label).
"'";
990 dol_syslog(get_class($this).
"::getIdForLabel", LOG_DEBUG);
991 $result = $this->db->query($sql);
993 if ($this->db->num_rows($result)) {
994 $obj = $this->db->fetch_object($result);
997 $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 - Taxe sur la valeur ajoutée)
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.
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left 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 PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount