noalyss Version-9
Public Member Functions | Private Member Functions | Private Attributes
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)
 
 check ()
 depends of quant_* table, so we must check first that everything is in these tables More...
 
 display ()
 display the summary of VAT in the range of date More...
 
 form_export_csv ()
 display a form to export in CSV More...
 
 form_export_pdf ()
 display a form to export in PDF More...
 
 get_date_end ()
 
 get_date_start ()
 
 get_db ()
 
 get_row_purchase ()
 Total for each purchase ledger. More...
 
 get_row_sale ()
 Total for each sales ledger. More...
 
 get_summary_purchase ()
 Summary for all purchase ledger. More...
 
 get_summary_sale ()
 Summary for all sales ledger. More...
 
 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. More...
 
 build_sql_sale ($p_group_ledger=TRUE)
 Build the SQL for sale vat. More...
 

Private Attributes

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

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)
$p_end
$p_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 163 of file tax_summary.class.php.

164 {
165 global $g_user;
166 $sql_ledger=$g_user->get_ledger_sql('ALL', 3);
167
168 }
global $g_user
if no group available , then stop

References $g_user.

◆ build_sql_purchase()

Tax_Summary::build_sql_purchase (   $p_group_ledger)
private

Build the SQL for sale vat.

Returns
string

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

175 {
176 global $g_user;
177 $sql_ledger=$g_user->get_ledger_sql('ACH', 3);
178 $group_ledger="";
179 if ( $p_group_ledger )
180 {
181 $group_ledger='j_jrn_def,';
182 }
183
184 $sql="with detail_tva as (
185 select
186 sum(qp_vat) as amount_vat,
187 sum(qp_vat_sided) as amount_sided,
188 sum(qp_price) as amount_wovat,
189 sum(qp_nd_amount) as amount_noded_amount,
190 sum(qp_nd_tva) as amount_noded_tax,
191 sum(qp_nd_tva_recup) as amount_noded_return,
192 sum(qp_dep_priv) as amount_private,
193 {$group_ledger}
194 qp_vat_code
195 from
196 quant_purchase
197 join tva_rate on (qp_vat_code=tva_rate.tva_id)
198 join jrnx on (quant_purchase.j_id=jrnx.j_id)
199 join jrn_def on (jrn_def.jrn_def_id=jrnx.j_jrn_def)
200 join jrn on (jrn.jr_grpt_id=jrnx.j_grpt)
201 ";
202 if ( $this->tva_type=="O")
203 {
204 $sql=$sql."
205 where
206 j_date >= to_date($1,'DD.MM.YYYY')
207 and j_date <= to_date($2,'DD.MM.YYYY')
208 and {$sql_ledger}
209 group by {$group_ledger} qp_vat_code) ";
210 } elseif ($this->tva_type=="P") {
211 $sql=$sql."
212 where
213 coalesce(to_char(jr_date_paid,'YYYYMMDD'),'00000000') >=
214 to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
215 and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'99999999') <=
216 to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
217 and {$sql_ledger}
218 group by {$group_ledger} qp_vat_code) ";
219 }elseif ($this->tva_type=="T") {
220 $sql=$sql." where
221 ( tva_rate.tva_payment_purchase='P'
222 and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'00000000') >=
223 to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
224 and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'99999999') <=
225 to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
226 )
227 or
228 ( tva_rate.tva_payment_purchase='O'
229 and coalesce(to_char(jr_date,'YYYYMMDD'),'00000000') >=
230 to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
231 and coalesce(to_char(jr_date,'YYYYMMDD'),'99999999') <=
232 to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
233 )
234 and {$sql_ledger}
235 group by {$group_ledger} qp_vat_code) ";
236
237 } else {
238 throw new Exception(_("Exig TVA invalide"),1001);
239 }
240 return $sql;
241 }
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
groupby ledger
Returns
string

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

251 {
252 global $g_user;
253 $sql_ledger=$g_user->get_ledger_sql('VEN', 3);
254 $group_ledger="";
255 if ( $p_group_ledger )
256 {
257 $group_ledger='j_jrn_def,';
258 }
259 $sql="with detail_tva as (
260 select
261 sum(qs_vat) as amount_vat,
262 sum(qs_vat_sided) as amount_sided,
263 sum(qs_price) as amount_wovat,
264 {$group_ledger}
265 qs_vat_code
266 from
267 quant_sold
268 join tva_rate on (qs_vat_code=tva_rate.tva_id)
269 join jrnx on (quant_sold.j_id=jrnx.j_id)
270 join jrn_def on (jrn_def.jrn_def_id=jrnx.j_jrn_def)
271 join jrn on (jrn.jr_grpt_id=jrnx.j_grpt)";
272 if ( $this->tva_type=="O")
273 {
274 $sql=$sql."
275 where
276 j_date >= to_date($1,'DD.MM.YYYY')
277 and j_date <= to_date($2,'DD.MM.YYYY')
278 and {$sql_ledger}
279 group by {$group_ledger} qs_vat_code) ";
280
281 } elseif ($this->tva_type=="P") {
282 $sql=$sql."
283 where
284 coalesce(to_char(jr_date_paid,'YYYYMMDD'),'00000000') >=
285 to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
286 and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'99999999') <=
287 to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
288 and {$sql_ledger}
289 group by {$group_ledger} qs_vat_code) ";
290
291 } elseif ($this->tva_type=="T") {
292 $sql=$sql."
293 where
294 ( tva_rate.tva_payment_sale='P'
295 and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'00000000') >=
296 to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
297 and coalesce(to_char(jr_date_paid,'YYYYMMDD'),'99999999') <=
298 to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
299 )
300 or
301 ( tva_rate.tva_payment_sale='O'
302 and coalesce(to_char(jr_date,'YYYYMMDD'),'00000000') >=
303 to_char(to_date($1,'DD.MM.YYYY'),'YYYYMMDD')
304 and coalesce(to_char(jr_date,'YYYYMMDD'),'99999999') <=
305 to_char(to_date($2,'DD.MM.YYYY'),'YYYYMMDD')
306 )
307 and {$sql_ledger}
308 group by {$group_ledger} qs_vat_code)
309 ";
310 }
311 else {
312 throw new Exception(_("Exig TVA invalide"),1001);
313 }
314 return $sql;
315 }

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 126 of file tax_summary.class.php.

127 {
128 /* -------------SALE --------------------------------- */
129 $sql="select count(*)
130 from
131 quant_sold
132 where
133 j_id in (select j_id from jrnx
134 where
135 jrnx.j_jrn_def in (select jrn_def_id from jrn_def where jrn_def_type = 'VEN')
136 and j_date >= to_date($1,'DD.MM.YYYY')
137 and j_date <= to_date($2,'DD.MM.YYYY')
138 )
139 ";
140 $cnt=$this->db->get_value($sql, [$this->date_start, $this->date_end]);
141 if ($cnt==0)
142 {
143 throw new Exception(_("Données manquantes"),100);
144 }
145 /* -------------Purchase --------------------------------- */
146 $sql="select count(*)
147 from
148 quant_purchase
149 where
150 j_id in (select j_id from jrnx
151 where
152 jrnx.j_jrn_def in (select jrn_def_id from jrn_def where jrn_def_type = 'VEN')
153 and j_date >= to_date($1,'DD.MM.YYYY')
154 and j_date <= to_date($2,'DD.MM.YYYY')
155 )
156 ";
157 $cnt=$this->db->get_value($sql, [$this->date_start, $this->date_end]);
158 if ($cnt>0)
159 {
160 throw new Exception(_("Données manquantes"),100);
161 }
162 }

References $sql, and db.

◆ display()

Tax_Summary::display ( )

display the summary of VAT in the range of date

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

426 {
427 require_once NOALYSS_INCLUDE."/template/tax_summary_display.php";
428 }

◆ form_export_csv()

Tax_Summary::form_export_csv ( )

display a form to export in CSV

See also
export_printtva_csv.php

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

435 {
436 $id=uniqid("export_");
437 echo '<form method="GET" action="export.php" ';
438 printf( 'id="%s" onsubmit="download_document_form(\'%s\')">',$id,$id);
439 echo Dossier::hidden();
440 echo HtmlInput::hidden("act", 'CSV:printtva');
441 echo HtmlInput::hidden("date_start", $this->date_start);
442 echo HtmlInput::hidden("date_end", $this->date_end);
443 echo HtmlInput::hidden("tva_type", $this->tva_type);
444
445 echo HtmlInput::submit("CSV:printtva", _("Export CSV"));
446 echo '</form>';
447 }
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, HtmlInput\hidden(), Dossier\hidden(), and HtmlInput\submit().

+ Here is the call graph for this function:

◆ form_export_pdf()

Tax_Summary::form_export_pdf ( )

display a form to export in PDF

See also
export_printtva_pdf.php

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

454 {
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", 'PDF: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);
463 echo HtmlInput::submit("PDF:printtva", _("Export PDF"));
464 echo '</form>';
465 }

References $id, HtmlInput\hidden(), Dossier\hidden(), and HtmlInput\submit().

+ Here is the call graph for this function:

◆ get_date_end()

Tax_Summary::get_date_end ( )
Returns
mixed

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

106 {
107 return $this->date_end;
108 return $this;
109 }

References $date_end.

◆ get_date_start()

Tax_Summary::get_date_start ( )
Returns
mixed

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

86 {
87 return $this->date_start;
88 return $this;
89 }

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 return $this;
71 }

References $db.

◆ get_row_purchase()

Tax_Summary::get_row_purchase ( )

Total for each purchase ledger.

Returns
array

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

348 {
349 $sql=$this->build_sql_purchase(TRUE)."
350 select jrn_def_name,
351 tva_label ,
352 tva_rate,
353 tva_both_side,
354 qp_vat_code,
355 amount_vat,
356 amount_wovat,
357 amount_sided,
358 amount_noded_amount,
359 amount_noded_tax,
360 amount_noded_return,
361 amount_private
362 from
363 detail_tva
364 join tva_rate on (tva_rate.tva_id=qp_vat_code)
365 join jrn_def on (jrn_def.jrn_def_id=j_jrn_def)
366 order by jrn_def_name,tva_label";
367 $array=$this->db->get_array($sql, [$this->date_start, $this->date_end]);
368 return $array;
369 }
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 320 of file tax_summary.class.php.

321 {
322 $sql=$this->build_sql_sale(TRUE);
323 $sql.="
324 select jrn_def_name,
325 tva_label ,
326 qs_vat_code,
327 tva_rate,
328 tva_both_side,
329 amount_vat,
330 amount_wovat,
331 amount_sided,
332 tva_payment_sale as tva_type
333 from
334 detail_tva
335 join tva_rate on (tva_rate.tva_id=qs_vat_code)
336 join jrn_def on (jrn_def.jrn_def_id=j_jrn_def)
337 order by jrn_def_name,tva_label";
338
339 $array=$this->db->get_array($sql, [$this->date_start, $this->date_end]);
340 return $array;
341 }
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 ledger.

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

398 {
399
400 $sql=$this->build_sql_purchase(FALSE)."
401 select
402 tva_label ,
403 tva_rate,
404 tva_both_side,
405 qp_vat_code,
406 amount_vat,
407 amount_wovat,
408 amount_sided,
409 amount_noded_amount,
410 amount_noded_tax,
411 amount_noded_return,
412 amount_private
413 from
414 detail_tva
415 join tva_rate on (tva_rate.tva_id=qp_vat_code)
416 order by tva_label";
417 $array=$this->db->get_array($sql, [$this->date_start, $this->date_end]);
418
419 return $array;
420 }

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 374 of file tax_summary.class.php.

375 {
376 $sql=$this->build_sql_sale(FALSE);
377 $sql.="select
378 tva_label ,
379 qs_vat_code,
380 tva_rate,
381 tva_both_side,
382 amount_vat,
383 amount_wovat,
384 amount_sided,
385 tva_rate.tva_payment_sale
386 from
387 detail_tva
388 join tva_rate on (tva_rate.tva_id=qs_vat_code)
389 order by tva_label";
390 $array=$this->db->get_array($sql, [$this->date_start, $this->date_end]);
391 return $array;
392 }

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 114 of file tax_summary.class.php.

115 {
116 if (isDate($date_end)==NULL)
117 throw new Exception(_("Format date invalide").$date_end);
118 $this->date_end=$date_end;
119 return $this;
120 }
isDate($p_date)
Definition: ac_common.php:236

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 94 of file tax_summary.class.php.

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

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 76 of file tax_summary.class.php.

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

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: