noalyss Version-10
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 180 of file tax_summary.class.php.

181 {
182 global $g_user;
183 $sql_ledger=$g_user->get_ledger_sql('ALL', 3);
184
185 }
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 494 of file tax_summary.class.php.

495 {
496
497
498 $js=sprintf("tax_detail_view('%s','%s','%s','%s','%s')",
499 $dossier_id,$this->date_start,$this->date_end,$nLedger_id,$nVAT_id);
500
501 return $js;
502
503
504 }
$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 191 of file tax_summary.class.php.

192 {
193 global $g_user;
194 $sql_ledger=$g_user->get_ledger_sql('ACH', 3);
195 $group_ledger="";
196 if ( $p_group_ledger )
197 {
198 $group_ledger='j_jrn_def,';
199 }
200
201 $sql="with detail_tva as (
202 select
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,
210 {$group_ledger}
211 qp_vat_code
212 from
213 quant_purchase
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)
218 ";
219 if ( $this->tva_type=="O")
220 {
221 $sql=$sql."
222 where
223 j_date >= to_date($1,'DD.MM.YYYY')
224 and j_date <= to_date($2,'DD.MM.YYYY')
225 and {$sql_ledger}
226 group by {$group_ledger} qp_vat_code) ";
227 } elseif ($this->tva_type=="P") {
228 $sql=$sql."
229 where
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')
234 and {$sql_ledger}
235 group by {$group_ledger} qp_vat_code) ";
236 }elseif ($this->tva_type=="T") {
237 $sql=$sql." where
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')
243 )
244 or
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')
250 )
251 and {$sql_ledger}
252 group by {$group_ledger} qp_vat_code) ";
253
254 } else {
255 throw new Exception(_("Exig TVA invalide"),1001);
256 }
257 return $sql;
258 }
_("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 267 of file tax_summary.class.php.

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

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
149 throw new Exception('TX148:'._("Données manquantes"),100);
150
151 }
152 /* -------------Purchase --------------------------------- */
153
154 $sql="select count(*)
155 from
156 quant_purchase
157 where
158 j_id in (select j_id from jrnx
159 where
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')
163 )
164 ";
165 $cnt=$this->db->get_value($sql, [$this->date_start, $this->date_end]);
166
167 $cnt_ledger=$this->db->get_value("
168 select count(*) from jrnx
169 where
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]);
174
175 if ($cnt ==0 && $cnt_ledger !=0)
176 {
177 throw new Exception('TX175'._("Données manquantes"),100);
178 }
179 }
for($i=0; $i< $nb_vatex_code; $i++)($i % 2==0) ? " odd " $cnt

References $cnt, $sql, _, and db.

◆ display()

Tax_Summary::display ( )

display the summary of VAT in the range of date

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

445 {
446 require_once NOALYSS_INCLUDE."/template/tax_summary_display.php";
447 }

◆ form_export_csv()

Tax_Summary::form_export_csv ( )

display a form to export in CSV

See also
export_printtva_csv.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", '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);
463
464 echo HtmlInput::submit("CSV:printtva", _("Export CSV"));
465 echo '</form>';
466 }
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 472 of file tax_summary.class.php.

473 {
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"));
483 echo '</form>';
484 }

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

366 {
367 $sql=$this->build_sql_purchase(TRUE)."
368 select jrn_def_name,
369 tva_code ||' ('||tva_rate.tva_label||')' tva_label,
370 tva_rate,
371 tva_both_side,
372 qp_vat_code,
373 amount_vat,
374 amount_wovat,
375 amount_sided,
376 amount_noded_amount,
377 amount_noded_tax,
378 amount_noded_return,
379 amount_private,
380 jrn_def.jrn_def_id
381 from
382 detail_tva
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]);
387 return $array;
388 }
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 337 of file tax_summary.class.php.

338 {
339 $sql=$this->build_sql_sale(TRUE);
340 $sql.="
341 select jrn_def_name,
342 tva_code ||' ('||tva_rate.tva_label||')' tva_label,
343 qs_vat_code,
344 tva_rate,
345 tva_both_side,
346 amount_vat,
347 amount_wovat,
348 amount_sided,
349 tva_payment_sale as tva_type,
350 jrn_def.jrn_def_id
351 from
352 detail_tva
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||')'";
356
357 $array=$this->db->get_array($sql, [$this->date_start, $this->date_end]);
358 return $array;
359 }
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 416 of file tax_summary.class.php.

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

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

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

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)
Verifie qu'une date est bien formaté en d.m.y et est valable.

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: