noalyss Version-9
export_printtva_pdf.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with NOALYSS; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19*/
20
21// Copyright Author Dany De Bontridder danydb@noalyss.eu
22/**
23 * @file
24 * @brief export PDF
25 *
26 */
27if (!defined('ALLOWED')) die('Appel direct ne sont pas permis');
28bcscale(4);
30
31$from_periode = $http->request("date_start");
32$to_periode = $http->request("date_end");
33$tva_type = $http->request("tva_type");
34
35
37
38/* Security */
41$tax_summary->set_tva_type($tva_type);
43$pdf->setDossierInfo(sprintf(_("Date") . " : %s %s", $from_periode, $to_periode));
44$pdf->AliasNbPages();
45$pdf->AddPage();
46$pdf->SetAuthor('NOALYSS');
47$pdf->setTitle(_("Résumé TVA"), true);
48
49
50
51
52//-------------------------------------------------------------------------
53// Sales
54//-------------------------------------------------------------------------
55$a_sale_header = [_("Code TVA"), _("Taux"), _("Montant HT"), _("Montant TVA"),
56 _("Montant Autoliquidation")];
58$array = $tax_summary->get_row_sale();
59// Table header
65//-------------------------------------------------------------------------
66// For each sale ledger
67//-------------------------------------------------------------------------
68// Table with total
69$a_col=['tva_label','tva_rate','amount_wovat','amount_vat','amount_sided'];
72// initialize totals
73for ($e=2;$e<$nb_col;$e++){
74 $a_tot[$a_col[$e]]=0;
75}
76
77for ($i = 0; $i < $nb_array; $i++) {
78 for ($e=2;$e<$nb_col;$e++){
79 $colname=$a_col[$e];
80 $a_tot[$colname]=bcadd($a_tot[$colname],$array[$i][$colname]);
81 }
82
83 if ($i == 0) {
84 // Display ledger name
85
86 $ledger_name = $array[$i]['jrn_def_name'];
87 $pdf->SetFont('DejaVuCond', 'B', 10);
88 $pdf->write_cell(50, 8, $ledger_name);
89 $pdf->line_new();
90
91 // Display Header
92 $pdf->SetFont('DejaVuCond', 'B', 7);
93 for ($e=0;$e<$nb_col;$e++){
94 if ( $e == 0 ) {
95 $pdf->write_cell(40, 5,$a_sale_header[$e], 1, 0, 'L');
96 } else {
97 $pdf->write_cell(40, 5,$a_sale_header[$e], 1, 0, 'R');
98 }
99 $a_tot[$colname]=0;
100 }
101 $pdf->line_new();
102 $pdf->SetFont('DejaVuCond', '', 7);
103 }
104 if ($ledger_name != $array[$i]['jrn_def_name']) {
105 // Display totals
106 $pdf->SetFont('DejaVuCond', 'B', 7);
107 $pdf->write_cell(80, 5, "");
108 for ($e=2;$e<$nb_col;$e++){
109 $colname=$a_col[$e];
110 $pdf->write_cell(40, 5, nbm($a_tot[$colname]), 1, 0, 'R');
111 $a_tot[$colname]=0;
112 }
113 $pdf->line_new();
114
115 // Display ledger name
116 $ledger_name = $array[$i]['jrn_def_name'];
117 $pdf->SetFont('DejaVuCond', 'B', 10);
118 $pdf->write_cell(50, 8, $ledger_name);
119 $pdf->line_new();
120
121 // Display Header
122 $pdf->SetFont('DejaVuCond', 'B', 7);
123 for ($e=0;$e<$nb_col;$e++){
124 if ( $e == 0 ) {
125 $pdf->write_cell(40, 5,$a_sale_header[$e], 1, 0, 'L');
126 } else {
127 $pdf->write_cell(40, 5,$a_sale_header[$e], 1, 0, 'R');
128 }
129 $a_tot[$colname]=0;
130 }
131 $pdf->line_new();
132 $pdf->SetFont('DejaVuCond', '', 7);
133 }
134 for ($e=0;$e<$nb_col;$e++){
135 $colname=$a_col[$e];
136 if ( $e ==0 ) {
137 $pdf->write_cell(40, 5, $array[$i][$colname], 1, 0, 'L');
138 } elseif ($e == 1 ){
139 $pdf->write_cell(40, 5, nbm($array[$i][$colname]*100), 1, 0, 'R');
140 }else {
141 $pdf->write_cell(40, 5, nbm($array[$i][$colname]), 1, 0, 'R');
142 }
143 }
144 $pdf->line_new();
145}
146$pdf->SetFont('DejaVuCond', 'B', 7);
147$pdf->write_cell(80, 5, "");
148for ($e=2;$e<$nb_col;$e++){
149 $colname=$a_col[$e];
150 $pdf->write_cell(40, 5, nbm($a_tot[$colname]), 1, 0, 'R');
151}
152
153//-------------------------------------------------------------------------
154// Summary sales
155//-------------------------------------------------------------------------
156$a_sum = $tax_summary->get_summary_sale();
157$pdf->line_new();
158$pdf->SetFont('DejaVuCond', 'B', 10);
159$pdf->write_cell(50, 8, _("Résumé TVA vente"));
160$pdf->line_new();
161
162$pdf->SetFont('DejaVuCond', 'B', 7);
163for ($i = 0; $i < $nb_sale; $i++) {
164 if ($i > 0 ) {
165 $pdf->write_cell(40, 5, $a_sale_header[$i], 1, 0, 'R');
166 } else {
167 $pdf->write_cell(40, 5, $a_sale_header[$i], 1, 0, 'L');
168 }
169}
170$pdf->line_new();
171
172$nb_array = count($a_sum);
173// initialize totals
174for ($e=2;$e<$nb_col;$e++){
175 $a_tot[$a_col[$e]]=0;
176}
177$pdf->SetFont('DejaVuCond', '', 7);
178
179for ($i = 0; $i < $nb_array; $i++) {
180 // display each row
181 for ($e=0;$e<$nb_col;$e++){
182 $colname=$a_col[$e];
183 if ( $e ==0 ) {
184 // first column TVA_LABEL
185 $pdf->write_cell(40, 5, $a_sum[$i][$colname], 1, 0, 'L');
186 } elseif ($e == 1 ){
187 // Secund col. tva rate
188 $pdf->write_cell(40, 5, nbm($a_sum[$i][$colname]*100), 1, 0, 'R');
189 }else {
190 // Other cols,display amount and compute total
191 $a_tot[$colname] = bcadd($a_tot[$colname], $a_sum[$i][$colname]);
192 $pdf->write_cell(40, 5, nbm($a_sum[$i][$colname]), 1, 0, 'R');
193 }
194 }
195 $pdf->line_new();
196}
197$pdf->SetFont('DejaVuCond', 'B', 7);
198$pdf->write_cell(80, 5, "");
199for ($e=2;$e<$nb_col;$e++){
200 $colname=$a_col[$e];
201 $pdf->write_cell(40, 5, nbm($a_tot[$colname]), 1, 0, 'R');
202}
203$pdf->line_new();
204
205//------------------------------------------------------------------------------------------
206// Purchase
207//------------------------------------------------------------------------------------------
208$array = $tax_summary->get_row_purchase();
209$a_colp=['tva_label','tva_rate','amount_wovat','amount_private','amount_vat','amount_sided',
210 'amount_noded_amount','amount_noded_tax','amount_noded_return'];
211$a_purchase_header = [_("Code TVA"), _("Taux"), _("Montant HT"), _("Privée"), _("Montant TVA"),
212 _("Montant Autoliquidation"), _("Montant Non Déd"), _("TVA ND"), _("TVA ND récup")];
214
215$a_size=['tva_label'=>40,'tva_rate'=>10,'amount_wovat'=>32,'amount_private'=>32,'amount_vat'=>32,'amount_sided'=>32,
216 'amount_noded_amount'=>32,'amount_noded_tax'=>32,'amount_noded_return'=>32];
217$nb_col=count($a_colp);
218
219for ($e=2;$e<$nb_col;$e++){
220 $a_tot[$a_colp[$e]]=0;
221}
222$nb_array=count($array);
223for ($i = 0; $i < $nb_array; $i++) {
224 for ($e=2;$e<$nb_col;$e++){
225 $colname=$a_colp[$e];
226 $a_tot[$colname]=bcadd($a_tot[$colname],$array[$i][$colname]);
227 }
228
229 if ($i == 0) {
230 // Display ledger name
231
232 $ledger_name = $array[$i]['jrn_def_name'];
233 $pdf->SetFont('DejaVuCond', 'B', 10);
234 $pdf->write_cell(50, 8, $ledger_name);
235 $pdf->line_new();
236
237 // Display Header
238 $pdf->SetFont('DejaVuCond', 'B', 7);
239 for ($e=0;$e<$nb_col;$e++){
240 $t_idx=$a_colp[$e];
241
242 if ( $e == 0 ) {
243 $pdf->write_cell($a_size[$t_idx], 5,$a_purchase_header[$e], 1, 0, 'L');
244 } else {
245 $pdf->write_cell($a_size[$t_idx], 5,$a_purchase_header[$e], 1, 0, 'R');
246 }
247 $a_tot[$colname]=0;
248 }
249 $pdf->line_new();
250 $pdf->SetFont('DejaVuCond', '', 7);
251 }
252 if ($ledger_name != $array[$i]['jrn_def_name']) {
253 // Display totals
254 $pdf->SetFont('DejaVuCond', 'B', 7);
255 $pdf->write_cell($a_size['tva_label']+$a_size['tva_rate'], 5, "");
256 for ($e=2;$e<$nb_col;$e++){
257 $t_idx=$a_colp[$e];
258 $colname=$a_colp[$e];
259 $pdf->write_cell($a_size[$t_idx], 5, nbm($a_tot[$colname]), 1, 0, 'R');
260 $a_tot[$colname]=0;
261 }
262 $pdf->line_new();
263
264
265 // Display ledger name
266 $ledger_name = $array[$i]['jrn_def_name'];
267 $pdf->SetFont('DejaVuCond', 'B', 10);
268 $pdf->write_cell(50, 8, $ledger_name);
269 $pdf->line_new();
270 $pdf->SetFont('DejaVuCond', 'B', 7);
271
272 // Display Header
273 for ($e=0;$e<$nb_col;$e++){
274 $t_idx=$a_colp[$e];
275 if ( $e == 0 ) {
276 $pdf->write_cell($a_size[$t_idx], 5,$a_purchase_header[$e], 1, 0, 'L');
277 } else {
278 $pdf->write_cell($a_size[$t_idx], 5,$a_purchase_header[$e], 1, 0, 'R');
279 }
280 }
281 for ($e=2;$e<$nb_col;$e++){
282 $colname=$a_colp[$e];
283 $a_tot[$colname]=bcadd($a_tot[$colname],$array[$i][$colname]);
284 }
285 $pdf->line_new();
286 }
287 $pdf->SetFont('DejaVuCond', '', 7);
288 for ($e=0;$e<$nb_col;$e++){
289 $colname=$a_colp[$e];
290
291 if ( $e ==0 ) {
292 $pdf->write_cell($a_size[$colname], 5, $array[$i][$colname], 1, 0, 'L');
293 } elseif ($e == 1 ){
294 $pdf->write_cell($a_size[$colname], 5, nbm($array[$i][$colname]*100), 1, 0, 'R');
295 }else {
296 $pdf->write_cell($a_size[$colname], 5, nbm($array[$i][$colname]), 1, 0, 'R');
297 }
298 }
299 $pdf->line_new();
300}
301$pdf->SetFont('DejaVuCond', 'B', 7);
302$pdf->write_cell($a_size['tva_label']+$a_size['tva_rate'], 5, "");
303for ($e=2;$e<$nb_col;$e++){
304 $colname=$a_colp[$e];
305 $pdf->write_cell($a_size[$colname], 5, nbm($a_tot[$colname]), 1, 0, 'R');
306}
307
308//-------------------------------------------------------------------------
309// Summary Purchase
310//-------------------------------------------------------------------------
311$pdf->line_new();
312$pdf->SetFont('DejaVuCond', 'B', 10);
313$pdf->write_cell(50, 8, _("Résumé TVA Achat"));
314$pdf->line_new();
315
316$pdf->SetFont('DejaVuCond', 'B', 7);
317for ($e=0;$e<$nb_col;$e++){
318 $t_idx=$a_colp[$e];
319
320 if ( $e == 0 ) {
321 $pdf->write_cell($a_size[$t_idx], 5,$a_purchase_header[$e], 1, 0, 'L');
322 } else {
323 $pdf->write_cell($a_size[$t_idx], 5,$a_purchase_header[$e], 1, 0, 'R');
324 }
325 $a_tot[$colname]=0;
326}
327$pdf->line_new();
328
329$array=$tax_summary->get_summary_purchase();
330$nb_array = count($array);
331// initialize totals
332for ($e=2;$e<$nb_col;$e++){
333 $a_tot[$a_colp[$e]]=0;
334}
335$pdf->SetFont('DejaVuCond', '', 7);
336
337for ($i = 0; $i < $nb_array; $i++) {
338 // display each row
339 for ($e=0;$e<$nb_col;$e++){
340 $colname=$a_colp[$e];
341 if ( $e ==0 ) {
342 // first column TVA_LABEL
343 $pdf->write_cell($a_size[$colname], 5, $array[$i][$colname], 1, 0, 'L');
344 } elseif ($e == 1 ){
345 // Secund col. tva rate
346 $pdf->write_cell($a_size[$colname], 5, nbm($array[$i][$colname]*100), 1, 0, 'R');
347 }else {
348 // Other cols,display amount and compute total
349 $a_tot[$colname] = bcadd($a_tot[$colname], $array[$i][$colname]);
350 $pdf->write_cell($a_size[$colname], 5, nbm($array[$i][$colname]), 1, 0, 'R');
351 }
352 }
353 $pdf->line_new();
354}
355$pdf->SetFont('DejaVuCond', 'B', 7);
356$pdf->write_cell($a_size['tva_label']+$a_size['tva_rate'], 5, "");
357for ($e=2;$e<$nb_col;$e++){
358 $colname=$a_colp[$e];
359 $pdf->write_cell($a_size[$colname], 5, nbm($a_tot[$colname]), 1, 0, 'R');
360}
361$pdf->line_new();
362
363
364//---------------------------------- Output --------------------------------------------------
365
366$fDate = date('Ymd-Hi');
367
368$pdf->Output('tva-' . $fDate . '.pdf', 'D');
nbm($p_number, $p_dec=2)
format the number with a sep.
Definition: ac_common.php:137
$input_from id
Definition: balance.inc.php:63
static connect()
manage the http input (get , post, request) and extract from an array
PDF in landscape mode.
Compute , display and export the tax summary.
$a_purchase_header
for($e=2;$e< $nb_col;$e++) $a_sum
if( $delta< 0) elseif( $delta==0)