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)
149 throw new Exception(
'TX148:'.
_(
"Données manquantes"),100);
154 $sql=
"select count(*)
158 j_id in (select j_id from jrnx
160 jrnx.j_jrn_def in (select jrn_def_id from jrn_def where jrn_def_type = 'ACH')
161 and j_date >= to_date($1,'DD.MM.YYYY')
162 and j_date <= to_date($2,'DD.MM.YYYY')
165 $cnt=$this->
db->get_value(
$sql, [$this->date_start, $this->date_end]);
167 $cnt_ledger=$this->
db->get_value(
"
168 select count(*) from jrnx
170 jrnx.j_jrn_def in (select jrn_def_id from jrn_def where jrn_def_type = 'ACH')
171 and j_date >= to_date($1,'DD.MM.YYYY')
172 and j_date <= to_date($2,'DD.MM.YYYY')
173 ", [$this->date_start, $this->date_end]);
175 if (
$cnt ==0 && $cnt_ledger !=0)
177 throw new Exception(
'TX175'.
_(
"Données manquantes"),100);
183 $sql_ledger=
$g_user->get_ledger_sql(
'ALL', 3);
194 $sql_ledger=
$g_user->get_ledger_sql(
'ACH', 3);
196 if ( $p_group_ledger )
198 $group_ledger=
'j_jrn_def,';
201 $sql=
"with detail_tva as (
203 sum(qp_vat) as amount_vat,
204 sum(qp_vat_sided) as amount_sided,
205 sum(qp_price) as amount_wovat,
206 sum(qp_nd_amount) as amount_noded_amount,
207 sum(qp_nd_tva) as amount_noded_tax,
208 sum(qp_nd_tva_recup) as amount_noded_return,
209 sum(qp_dep_priv) as amount_private,
214 join tva_rate on (qp_vat_code=tva_rate.tva_id)
215 join jrnx on (quant_purchase.j_id=jrnx.j_id)
216 join jrn_def on (jrn_def.jrn_def_id=jrnx.j_jrn_def)
217 join jrn on (jrn.jr_grpt_id=jrnx.j_grpt)
219 if ( $this->tva_type==
"O")
223 j_date >= to_date($1,'DD.MM.YYYY')
224 and j_date <= to_date($2,'DD.MM.YYYY')
226 group by {$group_ledger} qp_vat_code) ";
227 }
elseif ($this->tva_type==
"P") {
230 coalesce(to_char(jr_date_paid,'YYYYMMDD'),'00000000') >=
231 to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
232 and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'99999999') <=
233 to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
235 group by {$group_ledger} qp_vat_code) ";
236 }
elseif ($this->tva_type==
"T") {
238 ( tva_rate.tva_payment_purchase='P'
239 and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'00000000') >=
240 to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
241 and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'99999999') <=
242 to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
245 ( tva_rate.tva_payment_purchase='O'
246 and coalesce(to_char(jr_date,'YYYYMMDD'),'00000000') >=
247 to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
248 and coalesce(to_char(jr_date,'YYYYMMDD'),'99999999') <=
249 to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
252 group by {$group_ledger} qp_vat_code) ";
255 throw new Exception(
_(
"Exig TVA invalide"),1001);
270 $sql_ledger=
$g_user->get_ledger_sql(
'VEN', 3);
272 if ( $p_group_ledger )
274 $group_ledger=
'j_jrn_def,';
276 $sql=
"with detail_tva as (
278 sum(qs_vat) as amount_vat,
279 sum(qs_vat_sided) as amount_sided,
280 sum(qs_price) as amount_wovat,
285 join tva_rate on (qs_vat_code=tva_rate.tva_id)
286 join jrnx on (quant_sold.j_id=jrnx.j_id)
287 join jrn_def on (jrn_def.jrn_def_id=jrnx.j_jrn_def)
288 join jrn on (jrn.jr_grpt_id=jrnx.j_grpt)";
289 if ( $this->tva_type==
"O")
293 j_date >= to_date($1,'DD.MM.YYYY')
294 and j_date <= to_date($2,'DD.MM.YYYY')
296 group by {$group_ledger} qs_vat_code) ";
298 }
elseif ($this->tva_type==
"P") {
301 coalesce(to_char(jr_date_paid,'YYYYMMDD'),'00000000') >=
302 to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
303 and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'99999999') <=
304 to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
306 group by {$group_ledger} qs_vat_code) ";
308 }
elseif ($this->tva_type==
"T") {
311 ( tva_rate.tva_payment_sale='P'
312 and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'00000000') >=
313 to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
314 and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'99999999') <=
315 to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
318 ( tva_rate.tva_payment_sale='O'
319 and coalesce(to_char(jr_date,'YYYYMMDD'),'00000000') >=
320 to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
321 and coalesce(to_char(jr_date,'YYYYMMDD'),'99999999') <=
322 to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
325 group by {$group_ledger} qs_vat_code)
329 throw new Exception(
_(
"Exig TVA invalide"),1001);
342 tva_code ||' ('||tva_rate.tva_label||')' tva_label,
349 tva_payment_sale as tva_type,
353 join tva_rate on (tva_rate.tva_id=qs_vat_code)
354 join jrn_def on (jrn_def.jrn_def_id=j_jrn_def)
355 order by jrn_def.jrn_def_id,jrn_def_name, tva_code ||' ('||tva_rate.tva_label||')'";
357 $array=$this->
db->get_array(
$sql, [$this->date_start, $this->date_end]);
369 tva_code ||' ('||tva_rate.tva_label||')' tva_label,
383 join tva_rate on (tva_rate.tva_id=qp_vat_code)
384 join jrn_def on (jrn_def.jrn_def_id=j_jrn_def)
385 order by jrn_def.jrn_def_id,jrn_def_name, tva_code ||' ('||tva_rate.tva_label||')'";
386 $array=$this->
db->get_array(
$sql, [$this->date_start, $this->date_end]);
397 tva_code ||' ('||tva_rate.tva_label||')' tva_label,
404 tva_rate.tva_payment_sale
407 join tva_rate on (tva_rate.tva_id=qs_vat_code)
408 order by tva_code ||' ('||tva_rate.tva_label||')'";
409 $array=$this->
db->get_array(
$sql, [$this->date_start, $this->date_end]);
421 tva_code ||' ('||tva_rate.tva_label||')' tva_label,
434 join tva_rate on (tva_rate.tva_id=qp_vat_code)
435 order by tva_code ||' ('||tva_rate.tva_label||')'";
436 $array=$this->
db->get_array(
$sql, [$this->date_start, $this->date_end]);
446 require_once NOALYSS_INCLUDE.
"/template/tax_summary_display.php";
455 $id=uniqid(
"export_");
456 echo
'<form method="GET" action="export.php" ';
457 printf(
'id="%s" onsubmit="download_document_form(\'%s\')">',
$id,
$id);
458 echo Dossier::hidden();
459 echo HtmlInput::hidden(
"act",
'CSV:printtva');
460 echo HtmlInput::hidden(
"date_start", $this->date_start);
461 echo HtmlInput::hidden(
"date_end", $this->date_end);
462 echo HtmlInput::hidden(
"tva_type", $this->tva_type);
464 echo HtmlInput::submit(
"CSV:printtva",
_(
"Export CSV"));
474 $id=uniqid(
"export_");
475 echo
'<form method="GET" action="export.php" ';
476 printf(
'id="%s" onsubmit="download_document_form(\'%s\')">',
$id,
$id);
477 echo Dossier::hidden();
478 echo HtmlInput::hidden(
"act",
'PDF:printtva');
479 echo HtmlInput::hidden(
"date_start", $this->date_start);
480 echo HtmlInput::hidden(
"date_end", $this->date_end);
481 echo HtmlInput::hidden(
"tva_type", $this->tva_type);
482 echo HtmlInput::submit(
"PDF:printtva",
_(
"Export PDF"));
498 $js=sprintf(
"tax_detail_view('%s','%s','%s','%s','%s')",
499 $dossier_id,$this->date_start,$this->date_end,$nLedger_id,$nVAT_id);
isDate($p_date)
Verifie qu'une date est bien formaté en d.m.y et est valable.
global $g_user
if no group available , then stop
for($i=0; $i< $nb_vatex_code; $i++)($i % 2==0) ? " odd " $cnt
_("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)