95 throw new Exception(
_(
"Format date invalide").
$date_start);
115 throw new Exception(
_(
"Format date invalide").
$date_end);
127 $sql=
"select count(*)
131 j_id in (select j_id from jrnx
133 jrnx.j_jrn_def in (select jrn_def_id from jrn_def where jrn_def_type = 'VEN')
134 and j_date >= to_date($1,'DD.MM.YYYY')
135 and j_date <= to_date($2,'DD.MM.YYYY')
138 $cnt=$this->
db->get_value(
$sql, [$this->date_start, $this->date_end]);
139 $cnt_ledger=$this->
db->get_value(
"
140 select count(*) from jrnx
142 jrnx.j_jrn_def in (select jrn_def_id from jrn_def where jrn_def_type = 'VEN')
143 and j_date >= to_date($1,'DD.MM.YYYY')
144 and j_date <= to_date($2,'DD.MM.YYYY')
145 ", [$this->date_start, $this->date_end]);
146 if ($cnt==0 && $cnt_ledger !=0)
148 throw new Exception(
'TX148:'.
_(
"Données manquantes"),100);
152 $sql=
"select count(*)
156 j_id in (select j_id from jrnx
158 jrnx.j_jrn_def in (select jrn_def_id from jrn_def where jrn_def_type = 'ACH')
159 and j_date >= to_date($1,'DD.MM.YYYY')
160 and j_date <= to_date($2,'DD.MM.YYYY')
163 $cnt=$this->
db->get_value(
$sql, [$this->date_start, $this->date_end]);
165 $cnt_ledger=$this->
db->get_value(
"
166 select count(*) from jrnx
168 jrnx.j_jrn_def in (select jrn_def_id from jrn_def where jrn_def_type = 'ACH')
169 and j_date >= to_date($1,'DD.MM.YYYY')
170 and j_date <= to_date($2,'DD.MM.YYYY')
171 ", [$this->date_start, $this->date_end]);
173 if ($cnt ==0 && $cnt_ledger !=0)
175 throw new Exception(
'TX175'.
_(
"Données manquantes"),100);
181 $sql_ledger=
$g_user->get_ledger_sql(
'ALL', 3);
192 $sql_ledger=
$g_user->get_ledger_sql(
'ACH', 3);
194 if ( $p_group_ledger )
196 $group_ledger=
'j_jrn_def,';
199 $sql=
"with detail_tva as (
201 sum(qp_vat) as amount_vat,
202 sum(qp_vat_sided) as amount_sided,
203 sum(qp_price) as amount_wovat,
204 sum(qp_nd_amount) as amount_noded_amount,
205 sum(qp_nd_tva) as amount_noded_tax,
206 sum(qp_nd_tva_recup) as amount_noded_return,
207 sum(qp_dep_priv) as amount_private,
212 join tva_rate on (qp_vat_code=tva_rate.tva_id)
213 join jrnx on (quant_purchase.j_id=jrnx.j_id)
214 join jrn_def on (jrn_def.jrn_def_id=jrnx.j_jrn_def)
215 join jrn on (jrn.jr_grpt_id=jrnx.j_grpt)
217 if ( $this->tva_type==
"O")
221 j_date >= to_date($1,'DD.MM.YYYY')
222 and j_date <= to_date($2,'DD.MM.YYYY')
224 group by {$group_ledger} qp_vat_code) ";
225 }
elseif ($this->tva_type==
"P") {
228 coalesce(to_char(jr_date_paid,'YYYYMMDD'),'00000000') >=
229 to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
230 and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'99999999') <=
231 to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
233 group by {$group_ledger} qp_vat_code) ";
234 }
elseif ($this->tva_type==
"T") {
236 ( tva_rate.tva_payment_purchase='P'
237 and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'00000000') >=
238 to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
239 and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'99999999') <=
240 to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
243 ( tva_rate.tva_payment_purchase='O'
244 and coalesce(to_char(jr_date,'YYYYMMDD'),'00000000') >=
245 to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
246 and coalesce(to_char(jr_date,'YYYYMMDD'),'99999999') <=
247 to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
250 group by {$group_ledger} qp_vat_code) ";
253 throw new Exception(
_(
"Exig TVA invalide"),1001);
268 $sql_ledger=
$g_user->get_ledger_sql(
'VEN', 3);
270 if ( $p_group_ledger )
272 $group_ledger=
'j_jrn_def,';
274 $sql=
"with detail_tva as (
276 sum(qs_vat) as amount_vat,
277 sum(qs_vat_sided) as amount_sided,
278 sum(qs_price) as amount_wovat,
283 join tva_rate on (qs_vat_code=tva_rate.tva_id)
284 join jrnx on (quant_sold.j_id=jrnx.j_id)
285 join jrn_def on (jrn_def.jrn_def_id=jrnx.j_jrn_def)
286 join jrn on (jrn.jr_grpt_id=jrnx.j_grpt)";
287 if ( $this->tva_type==
"O")
291 j_date >= to_date($1,'DD.MM.YYYY')
292 and j_date <= to_date($2,'DD.MM.YYYY')
294 group by {$group_ledger} qs_vat_code) ";
296 }
elseif ($this->tva_type==
"P") {
299 coalesce(to_char(jr_date_paid,'YYYYMMDD'),'00000000') >=
300 to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
301 and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'99999999') <=
302 to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
304 group by {$group_ledger} qs_vat_code) ";
306 }
elseif ($this->tva_type==
"T") {
309 ( tva_rate.tva_payment_sale='P'
310 and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'00000000') >=
311 to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
312 and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'99999999') <=
313 to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
316 ( tva_rate.tva_payment_sale='O'
317 and coalesce(to_char(jr_date,'YYYYMMDD'),'00000000') >=
318 to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
319 and coalesce(to_char(jr_date,'YYYYMMDD'),'99999999') <=
320 to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
323 group by {$group_ledger} qs_vat_code)
327 throw new Exception(
_(
"Exig TVA invalide"),1001);
340 tva_code ||' ('||tva_rate.tva_label||')' tva_label,
347 tva_payment_sale as tva_type,
351 join tva_rate on (tva_rate.tva_id=qs_vat_code)
352 join jrn_def on (jrn_def.jrn_def_id=j_jrn_def)
353 order by jrn_def.jrn_def_id,jrn_def_name, tva_code ||' ('||tva_rate.tva_label||')'";
355 $array=$this->
db->get_array(
$sql, [$this->date_start, $this->date_end]);
367 tva_code ||' ('||tva_rate.tva_label||')' tva_label,
381 join tva_rate on (tva_rate.tva_id=qp_vat_code)
382 join jrn_def on (jrn_def.jrn_def_id=j_jrn_def)
383 order by jrn_def.jrn_def_id,jrn_def_name, tva_code ||' ('||tva_rate.tva_label||')'";
384 $array=$this->
db->get_array(
$sql, [$this->date_start, $this->date_end]);
395 tva_code ||' ('||tva_rate.tva_label||')' tva_label,
402 tva_rate.tva_payment_sale
405 join tva_rate on (tva_rate.tva_id=qs_vat_code)
406 order by tva_code ||' ('||tva_rate.tva_label||')'";
407 $array=$this->
db->get_array(
$sql, [$this->date_start, $this->date_end]);
419 tva_code ||' ('||tva_rate.tva_label||')' tva_label,
432 join tva_rate on (tva_rate.tva_id=qp_vat_code)
433 order by tva_code ||' ('||tva_rate.tva_label||')'";
434 $array=$this->
db->get_array(
$sql, [$this->date_start, $this->date_end]);
444 require_once NOALYSS_INCLUDE.
"/template/tax_summary_display.php";
453 $id=uniqid(
"export_");
454 echo
'<form method="GET" action="export.php" ';
455 printf(
'id="%s" onsubmit="download_document_form(\'%s\')">',
$id,
$id);
456 echo Dossier::hidden();
457 echo HtmlInput::hidden(
"act",
'CSV:printtva');
458 echo HtmlInput::hidden(
"date_start", $this->date_start);
459 echo HtmlInput::hidden(
"date_end", $this->date_end);
460 echo HtmlInput::hidden(
"tva_type", $this->tva_type);
462 echo HtmlInput::submit(
"CSV:printtva",
_(
"Export CSV"));
472 $id=uniqid(
"export_");
473 echo
'<form method="GET" action="export.php" ';
474 printf(
'id="%s" onsubmit="download_document_form(\'%s\')">',
$id,
$id);
475 echo Dossier::hidden();
476 echo HtmlInput::hidden(
"act",
'PDF:printtva');
477 echo HtmlInput::hidden(
"date_start", $this->date_start);
478 echo HtmlInput::hidden(
"date_end", $this->date_end);
479 echo HtmlInput::hidden(
"tva_type", $this->tva_type);
480 echo HtmlInput::submit(
"PDF:printtva",
_(
"Export PDF"));
496 $js=sprintf(
"tax_detail_view('%s','%s','%s','%s','%s')",
497 $dossier_id,$this->date_start,$this->date_end,$nLedger_id,$nVAT_id);
global $g_user
if no group available , then stop
_("actif, passif,charge,...")
contains the class for connecting to Noalyss
Compute , display and export the tax summary.
check()
depends of quant_* table, so we must check first that everything is in these tables
form_export_pdf()
display a form to export in PDF
build_link_detail($dossier_id, $dateStart, $DateeEd, $nLedger_id, $nVAT_id)
Build a link to show the detail of a VAT ID.
__construct(Database $db, $p_start, $p_end)
$tva_type
exigibility of VAT : operation , payment date or depending of setting in tva_rate
get_row_sale()
Total for each sales ledger.
display()
display the summary of VAT in the range of date
build_sql_sale($p_group_ledger=TRUE)
Build the SQL for sale vat.
build_sql_purchase($p_group_ledger)
Build the SQL for sale vat.
set_date_start($date_start)
get_summary_sale()
Summary for all sales ledger.
get_summary_purchase()
Summary for all purchase ledgers.
get_row_purchase()
Total for each purchase ledger.
form_export_csv()
display a form to export in CSV
if( $delta< 0) elseif( $delta==0)