noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
Tax_Summary Class Reference

Compute , display and export the tax summary. More...

+ Collaboration diagram for Tax_Summary:

Public Member Functions

 __construct (Database $db, $p_start, $p_end)
 
 build_link_detail ($dossier_id, $dateStart, $DateeEd, $nLedger_id, $nVAT_id)
 Build a link to show the detail of a VAT ID.
 
 check ()
 depends of quant_* table, so we must check first that everything is in these tables
 
 display ()
 display the summary of VAT in the range of date
 
 form_export_csv ()
 display a form to export in CSV
 
 form_export_pdf ()
 display a form to export in PDF
 
 get_date_end ()
 
 get_date_start ()
 
 get_db ()
 
 get_row_purchase ()
 Total for each purchase ledger.
 
 get_row_sale ()
 Total for each sales ledger.
 
 get_summary_purchase ()
 Summary for all purchase ledgers.
 
 get_summary_sale ()
 Summary for all sales ledger.
 
 get_tva_type ()
 
 set_date_end ($date_end)
 
 set_date_start ($date_start)
 
 set_db ($db)
 
 set_tva_type ($tva_type)
 

Private Member Functions

 build_exigibility ()
 
 build_sql_purchase ($p_group_ledger)
 Build the SQL for sale vat.
 
 build_sql_sale ($p_group_ledger=TRUE)
 Build the SQL for sale vat.
 

Private Attributes

 $date_end
 
 $date_start
 
 $db
 
 $tva_type
 exigibility of VAT : operation , payment date or depending of setting in tva_rate
 

Detailed Description

Compute , display and export the tax summary.

Definition at line 35 of file tax_summary.class.php.

Constructor & Destructor Documentation

◆ __construct()

Tax_Summary::__construct ( Database $db,
$p_start,
$p_end )

Definition at line 43 of file tax_summary.class.php.

44 {
45 $this->db=$db;
47 $this->set_date_end($p_end);
48
49 // By default the TVA is computed by parameter in tva_rate.tva_payment_purchase or tva_rate.tva_payment_sale
50 $this->set_tva_type("T");
51 }
set_tva_type($tva_type)
set_date_end($date_end)
set_date_start($date_start)
$SecUser db

References $db, $p_end, $p_start, db, set_date_end(), set_date_start(), and set_tva_type().

+ Here is the call graph for this function:

Member Function Documentation

◆ build_exigibility()

Tax_Summary::build_exigibility ( )
private

Definition at line 178 of file tax_summary.class.php.

179 {
180 global $g_user;
181 $sql_ledger=$g_user->get_ledger_sql('ALL', 3);
182
183 }
global $g_user
if no group available , then stop

References $g_user.

◆ build_link_detail()

Tax_Summary::build_link_detail ( $dossier_id,
$dateStart,
$DateeEd,
$nLedger_id,
$nVAT_id )

Build a link to show the detail of a VAT ID.

Parameters
$dateStartdate from format 'DD.MM.YYYY'
$DateeEddate to format 'DD.MM.YYYY'
$nLedger_idinteger JRN_DEF.JRN_DEF_ID
$nVAT_idinteger TVA_RATE.TVA_ID
Returns
javascript string

Definition at line 492 of file tax_summary.class.php.

493 {
494
495
496 $js=sprintf("tax_detail_view('%s','%s','%s','%s','%s')",
497 $dossier_id,$this->date_start,$this->date_end,$nLedger_id,$nVAT_id);
498
499 return $js;
500
501
502 }
$dossier_id

References $dossier_id, and $js.

◆ build_sql_purchase()

Tax_Summary::build_sql_purchase ( $p_group_ledger)
private

Build the SQL for sale vat.

Returns
string

Definition at line 189 of file tax_summary.class.php.

190 {
191 global $g_user;
192 $sql_ledger=$g_user->get_ledger_sql('ACH', 3);
193 $group_ledger="";
194 if ( $p_group_ledger )
195 {
196 $group_ledger='j_jrn_def,';
197 }
198
199 $sql="with detail_tva as (
200 select
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,
208 {$group_ledger}
209 qp_vat_code
210 from
211 quant_purchase
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)
216 ";
217 if ( $this->tva_type=="O")
218 {
219 $sql=$sql."
220 where
221 j_date >= to_date($1,'DD.MM.YYYY')
222 and j_date <= to_date($2,'DD.MM.YYYY')
223 and {$sql_ledger}
224 group by {$group_ledger} qp_vat_code) ";
225 } elseif ($this->tva_type=="P") {
226 $sql=$sql."
227 where
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')
232 and {$sql_ledger}
233 group by {$group_ledger} qp_vat_code) ";
234 }elseif ($this->tva_type=="T") {
235 $sql=$sql." where
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')
241 )
242 or
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')
248 )
249 and {$sql_ledger}
250 group by {$group_ledger} qp_vat_code) ";
251
252 } else {
253 throw new Exception(_("Exig TVA invalide"),1001);
254 }
255 return $sql;
256 }
_("actif, passif,charge,...")
if( $delta< 0) elseif( $delta==0)

References $g_user, $sql, _, and elseif.

Referenced by get_row_purchase(), and get_summary_purchase().

◆ build_sql_sale()

Tax_Summary::build_sql_sale ( $p_group_ledger = TRUE)
private

Build the SQL for sale vat.

Parameters
$p_group_ledgerbool true group by ledgers
Returns
string

Definition at line 265 of file tax_summary.class.php.

266 {
267 global $g_user;
268 $sql_ledger=$g_user->get_ledger_sql('VEN', 3);
269 $group_ledger="";
270 if ( $p_group_ledger )
271 {
272 $group_ledger='j_jrn_def,';
273 }
274 $sql="with detail_tva as (
275 select
276 sum(qs_vat) as amount_vat,
277 sum(qs_vat_sided) as amount_sided,
278 sum(qs_price) as amount_wovat,
279 {$group_ledger}
280 qs_vat_code
281 from
282 quant_sold
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")
288 {
289 $sql=$sql."
290 where
291 j_date >= to_date($1,'DD.MM.YYYY')
292 and j_date <= to_date($2,'DD.MM.YYYY')
293 and {$sql_ledger}
294 group by {$group_ledger} qs_vat_code) ";
295
296 } elseif ($this->tva_type=="P") {
297 $sql=$sql."
298 where
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')
303 and {$sql_ledger}
304 group by {$group_ledger} qs_vat_code) ";
305
306 } elseif ($this->tva_type=="T") {
307 $sql=$sql."
308 where
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')
314 )
315 or
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')
321 )
322 and {$sql_ledger}
323 group by {$group_ledger} qs_vat_code)
324 ";
325 }
326 else {
327 throw new Exception(_("Exig TVA invalide"),1001);
328 }
329 return $sql;
330 }

References $g_user, $sql, _, and elseif.

Referenced by get_row_sale(), and get_summary_sale().

◆ check()

Tax_Summary::check ( )

depends of quant_* table, so we must check first that everything is in these tables

Definition at line 124 of file tax_summary.class.php.

125 {
126 /* -------------SALE --------------------------------- */
127 $sql="select count(*)
128 from
129 quant_sold
130 where
131 j_id in (select j_id from jrnx
132 where
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')
136 )
137 ";
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
141 where
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)
147 {
148 throw new Exception('TX148:'._("Données manquantes"),100);
149 }
150 /* -------------Purchase --------------------------------- */
151
152 $sql="select count(*)
153 from
154 quant_purchase
155 where
156 j_id in (select j_id from jrnx
157 where
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')
161 )
162 ";
163 $cnt=$this->db->get_value($sql, [$this->date_start, $this->date_end]);
164
165 $cnt_ledger=$this->db->get_value("
166 select count(*) from jrnx
167 where
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]);
172
173 if ($cnt ==0 && $cnt_ledger !=0)
174 {
175 throw new Exception('TX175'._("Données manquantes"),100);
176 }
177 }

References $sql, _, and db.

◆ display()

Tax_Summary::display ( )

display the summary of VAT in the range of date

Definition at line 442 of file tax_summary.class.php.

443 {
444 require_once NOALYSS_INCLUDE."/template/tax_summary_display.php";
445 }

◆ form_export_csv()

Tax_Summary::form_export_csv ( )

display a form to export in CSV

See also
export_printtva_csv.php

Definition at line 451 of file tax_summary.class.php.

452 {
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);
461
462 echo HtmlInput::submit("CSV:printtva", _("Export CSV"));
463 echo '</form>';
464 }
static hidden()
return a string to set gDossier into a FORM
static hidden($p_name, $p_value, $p_id="")
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")

References $id, and _.

◆ form_export_pdf()

Tax_Summary::form_export_pdf ( )

display a form to export in PDF

See also
export_printtva_pdf.php

Definition at line 470 of file tax_summary.class.php.

471 {
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"));
481 echo '</form>';
482 }

References $id, and _.

◆ get_date_end()

Tax_Summary::get_date_end ( )
Returns
mixed

Definition at line 103 of file tax_summary.class.php.

104 {
105 return $this->date_end;
106
107 }

References $date_end.

◆ get_date_start()

Tax_Summary::get_date_start ( )
Returns
mixed

Definition at line 84 of file tax_summary.class.php.

85 {
86 return $this->date_start;
87 }

References $date_start.

◆ get_db()

Tax_Summary::get_db ( )
Returns
Database

Definition at line 67 of file tax_summary.class.php.

68 {
69 return $this->db;
70 }

References $db.

◆ get_row_purchase()

Tax_Summary::get_row_purchase ( )

Total for each purchase ledger.

Returns
array

Definition at line 363 of file tax_summary.class.php.

364 {
365 $sql=$this->build_sql_purchase(TRUE)."
366 select jrn_def_name,
367 tva_code ||' ('||tva_rate.tva_label||')' tva_label,
368 tva_rate,
369 tva_both_side,
370 qp_vat_code,
371 amount_vat,
372 amount_wovat,
373 amount_sided,
374 amount_noded_amount,
375 amount_noded_tax,
376 amount_noded_return,
377 amount_private,
378 jrn_def.jrn_def_id
379 from
380 detail_tva
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]);
385 return $array;
386 }
build_sql_purchase($p_group_ledger)
Build the SQL for sale vat.

References $array, $sql, build_sql_purchase(), and db.

+ Here is the call graph for this function:

◆ get_row_sale()

Tax_Summary::get_row_sale ( )

Total for each sales ledger.

Returns
array

Definition at line 335 of file tax_summary.class.php.

336 {
337 $sql=$this->build_sql_sale(TRUE);
338 $sql.="
339 select jrn_def_name,
340 tva_code ||' ('||tva_rate.tva_label||')' tva_label,
341 qs_vat_code,
342 tva_rate,
343 tva_both_side,
344 amount_vat,
345 amount_wovat,
346 amount_sided,
347 tva_payment_sale as tva_type,
348 jrn_def.jrn_def_id
349 from
350 detail_tva
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||')'";
354
355 $array=$this->db->get_array($sql, [$this->date_start, $this->date_end]);
356 return $array;
357 }
build_sql_sale($p_group_ledger=TRUE)
Build the SQL for sale vat.

References $array, $sql, build_sql_sale(), and db.

+ Here is the call graph for this function:

◆ get_summary_purchase()

Tax_Summary::get_summary_purchase ( )

Summary for all purchase ledgers.

Definition at line 414 of file tax_summary.class.php.

415 {
416
417 $sql=$this->build_sql_purchase(FALSE)."
418 select
419 tva_code ||' ('||tva_rate.tva_label||')' tva_label,
420 tva_rate,
421 tva_both_side,
422 qp_vat_code,
423 amount_vat,
424 amount_wovat,
425 amount_sided,
426 amount_noded_amount,
427 amount_noded_tax,
428 amount_noded_return,
429 amount_private
430 from
431 detail_tva
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]);
435
436 return $array;
437 }

References $array, $sql, build_sql_purchase(), and db.

+ Here is the call graph for this function:

◆ get_summary_sale()

Tax_Summary::get_summary_sale ( )

Summary for all sales ledger.

Definition at line 391 of file tax_summary.class.php.

392 {
393 $sql=$this->build_sql_sale(FALSE);
394 $sql.="select
395 tva_code ||' ('||tva_rate.tva_label||')' tva_label,
396 qs_vat_code,
397 tva_rate,
398 tva_both_side,
399 amount_vat,
400 amount_wovat,
401 amount_sided,
402 tva_rate.tva_payment_sale
403 from
404 detail_tva
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]);
408 return $array;
409 }

References $array, $sql, build_sql_sale(), and db.

+ Here is the call graph for this function:

◆ get_tva_type()

Tax_Summary::get_tva_type ( )

Definition at line 53 of file tax_summary.class.php.

54 {
55 return $this->tva_type;
56 }
$tva_type
exigibility of VAT : operation , payment date or depending of setting in tva_rate

References $tva_type.

◆ set_date_end()

Tax_Summary::set_date_end ( $date_end)
Parameters
mixed$date_end

Definition at line 112 of file tax_summary.class.php.

113 {
114 if (isDate($date_end)==NULL)
115 throw new Exception(_("Format date invalide").$date_end);
116 $this->date_end=$date_end;
117 return $this;
118 }
isDate($p_date)

References $date_end, _, and isDate().

Referenced by __construct().

+ Here is the call graph for this function:

◆ set_date_start()

Tax_Summary::set_date_start ( $date_start)
Parameters
mixed$date_start

Definition at line 92 of file tax_summary.class.php.

93 {
94 if (isDate($date_start)==NULL)
95 throw new Exception(_("Format date invalide").$date_start);
96 $this->date_start=$date_start;
97 return $this;
98 }

References $date_start, _, and isDate().

Referenced by __construct().

+ Here is the call graph for this function:

◆ set_db()

Tax_Summary::set_db ( $db)
Parameters
Database$db

Definition at line 75 of file tax_summary.class.php.

76 {
77 $this->db=$db;
78 return $this;
79 }

References $db, and db.

◆ set_tva_type()

Tax_Summary::set_tva_type ( $tva_type)

Definition at line 58 of file tax_summary.class.php.

59 {
60 $this->tva_type=$tva_type;
61 return $this;
62 }

References $tva_type.

Referenced by __construct().

Field Documentation

◆ $date_end

Tax_Summary::$date_end
private

Definition at line 39 of file tax_summary.class.php.

Referenced by get_date_end(), and set_date_end().

◆ $date_start

Tax_Summary::$date_start
private

Definition at line 38 of file tax_summary.class.php.

Referenced by get_date_start(), and set_date_start().

◆ $db

Tax_Summary::$db
private

Definition at line 40 of file tax_summary.class.php.

Referenced by __construct(), get_db(), and set_db().

◆ $tva_type

Tax_Summary::$tva_type
private

exigibility of VAT : operation , payment date or depending of setting in tva_rate

Definition at line 41 of file tax_summary.class.php.

Referenced by get_tva_type(), and set_tva_type().


The documentation for this class was generated from the following file: