noalyss Version-9
print_ledger_simple.class.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 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!
23 * \file
24 * \brief this class extends PDF and let you export the detailled printing
25 * of any ledgers
26 */
27/*!
28 * \class Print_Ledger_Simple
29 * \brief this class extends PDF and let you export the detailled printing
30 * of any ledgers
31 */
32
34{
35 public function __construct ($p_cn, Acc_Ledger $p_jrn,$p_from,$p_to,$p_filter_operation)
36 {
37
38 parent::__construct($p_cn,'L', 'mm', 'A4',$p_jrn,$p_from,$p_to,$p_filter_operation);
39
40 $this->a_Tva=$this->get_ledger()->existing_vat();
41 foreach($this->a_Tva as $line_tva)
42 {
43 //initialize Amount TVA
44 $tmp1=$line_tva['tva_id'];
45 $this->rap_tva[$tmp1]=0;
46 }
47 $this->rap_other_tax=0;
48 $this->jrn_type=$p_jrn->get_type();
49 //----------------------------------------------------------------------
50 /* report
51 *
52 * get rappel to initialize amount rap_xx
53 *the easiest way is to compute sum from quant_
54 */
55 $from_periode=$this->get_from();
56 $this->previous=$this->get_ledger()->previous_amount($from_periode);
57 $this->other_tax_previous=$this->get_ledger()->previous_other_tax($from_periode);
58
59 /* initialize the amount to report */
60 foreach($this->previous['tva'] as $line_tva)
61 {
62 //initialize Amount TVA
63 $tmp1=$line_tva['tva_id'];
64 $this->rap_tva[$tmp1]=$line_tva['sum_vat'];
65 }
66
67 $this->rap_htva=$this->previous['price'];
68 $this->rap_tvac=bcadd($this->previous['price'],$this->previous['vat']);
69 $this->rap_tvac=bcadd($this->rap_tvac,$this->previous['tva_nd']);
70 $this->rap_tvac=bcsub($this->rap_tvac,$this->previous['tva_np']);
71 $this->rap_tvac=bcsub($this->rap_tvac,$this->previous['reversed']);
72 $this->rap_priv=$this->previous['priv'];
73 $this->rap_nd=$this->previous['tva_nd'];
74 $this->rap_tva_np=$this->previous['tva_np'];
75 $this->flag_other_tax=false;
76
77 if ($this->jrn_type == 'ACH' || $this->jrn_type=='VEN') {
78 $periode=new Periode($p_cn,$p_from);
79 $first_date=$periode->first_day();
80 $periode=new Periode($p_cn,$p_to);
81 $last_date=$periode->last_day();
82
83 $count=$this->cn->get_value("
84 select count(*)
85 from jrn_tax join jrnx using (j_id)
86 join jrn on (j_grpt=jr_grpt_id) where
87 j_date >= to_date($1,'DD.MM.YYYY')
88 and j_date <= to_date($2,'DD.MM.YYYY')
89 and j_jrn_def=$3",
90 array($first_date,$last_date,$p_jrn->id));
91 if ($count>0) { $this->flag_other_tax=true;}
92 }
93 }
94
95 function setDossierInfo($dossier = "n/a")
96 {
97 $this->dossier = dossier::name()." ".$dossier;
98 }
99 /**
100 *@brief write the header of each page
101 */
102 function Header()
103 {
104 //Arial bold 12
105 $this->SetFont('DejaVu', 'B', 12);
106 //Title
107 $this->Cell(0,10,$this->dossier, 'B', 0, 'C');
108 //Line break
109 $this->Ln(20);
110 $this->SetFont('DejaVu', 'B', 8);
111 /* column header */
112 //----------------------------------------------------------------------
113 // Show column header, if $flag_tva is false then display vat as column
114 foreach($this->a_Tva as $line_tva)
115 {
116 //initialize Amount TVA
117 $tmp1=$line_tva['tva_id'];
118 $this->rap_tva[$tmp1]=(isset($this->rap_tva[$tmp1]))?$this->rap_tva[$tmp1]:0;
119 }
120 $this->Cell(15,6,_('Pièce'));
121 $this->Cell(10,6,_('Date'));
122 $this->Cell(13,6,_('ref'));
123 if ( $this->jrn_type=='ACH')
124 $this->Cell(40,6,_('Client'));
125 else
126 $this->Cell(40,6,_('Fournisseur'));
127
128 $flag_tva=(count($this->a_Tva) > 4)?true:false;
129 if ( !$flag_tva ) $this->Cell(65,6,_('Description'));
130
131 $this->Cell(15,6,_('HTVA'),0,0,'R');
132 if ( $this->jrn_type=='ACH')
133 {
134 $this->Cell(15,6,_('Priv/DNA'),0,0,'R');
135 $this->Cell(15,6,_('TVA ND'),0,0,'R');
136 }
137 $this->Cell(15,6,_('TVA NP'),0,0,'R'); // Unpaid TVA --> autoliquidation, NPR
138 foreach($this->a_Tva as $line_tva)
139 {
140 $this->Cell(15,6,$line_tva['tva_label'],0,0,'R');
141 }
142 if ($this->flag_other_tax) {
143 $this->Cell(15,6,'Autre Tx',0,0,'R');
144
145 }
146 $this->Cell(15,6,'TVAC',0,0,'R');
147 $this->Ln(5);
148
149 $this->SetFont('DejaVu','',6);
150 // page Header
151 if ( ! $flag_tva)
152 $this->Cell(143,6,'report',0,0,'R');
153 else
154 $this->Cell(78,6,'report',0,0,'R');
155 $this->Cell(15,6,nbm($this->rap_htva),0,0,'R'); /* HTVA */
156 if ( $this->jrn_type != 'VEN')
157 {
158 $this->Cell(15,6,nbm($this->rap_priv),0,0,'R'); /* prive */
159 $this->Cell(15,6,nbm($this->rap_nd),0,0,'R'); /* Tva ND */
160 }
161 $this->Cell(15,6,nbm($this->rap_tva_np),0,0,'R'); /* Tva ND */
162 foreach($this->rap_tva as $line_tva)
163 $this->Cell(15,6,nbm($line_tva),0,0,'R');
164 if ($this->flag_other_tax) {
165 $this->Cell(15, 6, nbm($this->rap_other_tax), 0, 0, 'R'); /* Other tax */
166 }
167 $this->Cell(15,6,nbm($this->rap_tvac),0,0,'R'); /* Tvac */
168
169 $this->Ln(6);
170 //total page
171 $this->tp_htva=0.0;
172 $this->tp_tvac=0.0;
173 $this->tp_priv=0;
174 $this->tp_nd=0;
175 $this->tp_tva_np=0;
176 $this->tp_other_tax=0;
177 foreach($this->a_Tva as $line_tva)
178 {
179 //initialize Amount TVA
180 $tmp1=$line_tva['tva_id'];
181 $this->tp_tva[$tmp1]=0.0;
182 }
183 }
184 /**
185 *@brief write the Footer
186 */
187 function Footer()
188 {
189 //Position at 3 cm from bottom
190 $this->SetY(-20);
191 /* write reporting */
192 $flag_tva=(count($this->a_Tva) > 4)?true:false;
193 if ( ! $flag_tva)
194 $this->Cell(143,6,'Total page ','T',0,'R'); /* HTVA */
195 else
196 $this->Cell(78,6,'Total page ','T',0,'R'); /* HTVA */
197
198 $this->Cell(15,6,nbm($this->tp_htva),'T',0,'R'); /* HTVA */
199 if ( $this->jrn_type !='VEN')
200 {
201 $this->Cell(15,6,nbm($this->tp_priv),'T',0,'R'); /* prive */
202 $this->Cell(15,6,nbm($this->tp_nd),'T',0,'R'); /* Tva ND */
203 }
204 $this->Cell(15,6,nbm($this->tp_tva_np),'T',0,'R'); /* Tva Unpaid */
205 foreach($this->a_Tva as $line_tva)
206 {
207 $l=$line_tva['tva_id'];
208 $this->Cell(15,6,nbm($this->tp_tva[$l]),'T',0,'R');
209 }
210 if ($this->flag_other_tax) {
211 $this->Cell(15, 6, nbm($this->tp_other_tax), 'T', 0, 'R'); /* Tvac */
212 }
213 $this->Cell(15,6,nbm($this->tp_tvac),'T',0,'R'); /* Tvac */
214 $this->Ln(2);
215 $flag_tva=(count($this->a_Tva) > 4)?true:false;
216
217 if ( ! $flag_tva)
218 $this->Cell(143,6,'report',0,0,'R');
219 else
220 $this->Cell(78,6,'report',0,0,'R');
221
222 $this->Cell(15,6,nbm($this->rap_htva),0,0,'R'); /* HTVA */
223 if ( $this->jrn_type !='VEN')
224 {
225 $this->Cell(15,6,nbm($this->rap_priv),0,0,'R'); /* prive */
226 $this->Cell(15,6,nbm($this->rap_nd),0,0,'R'); /* Tva ND */
227 }
228 $this->Cell(15,6,nbm($this->rap_tva_np),0,0,'R'); /* Tva ND */
229
230 foreach($this->a_Tva as $line_tva)
231 {
232 $l=$line_tva['tva_id'];
233 $this->Cell(15,6,nbm($this->rap_tva[$l]),0,0,'R');
234 }
235 if ($this->flag_other_tax) {
236 $this->Cell(15, 6, nbm($this->rap_other_tax), 0, 0, 'R'); /* Other tax */
237 }
238 $this->Cell(15,6,nbm($this->rap_tvac),0,0,'R'); /* Tvac */
239 $this->Ln(2);
240
241 //Arial italic 8
242 $this->SetFont('Arial', 'I', 8);
243 //Page number
244 $this->Cell(0,8,'Date '.$this->date." - Page ".$this->PageNo().'/{nb}',0,0,'L');
245 // Created by NOALYSS
246 $this->Cell(0,8,'Created by NOALYSS, online on https://www.noalyss.eu',0,0,'R',false,'https://www.noalyss.eu');
247 }
248
249
250 /**
251 *@brief export the ledger in PDF
252 */
253 function export()
254 {
255 bcscale(4);
256 $ledger=$this->get_ledger();
257 $ledger_history=Acc_Ledger_History::factory($this->cn,
258 array($ledger->id),
259 $this->get_from(),
260 $this->get_to(),
261 'D',
262 $this->get_filter_operation());
263 $ledger_history->get_row();
264 $a_jrn=$ledger_history->get_data();
265
266 if ( $a_jrn == null ) return;
267
268 // Count the number of VAT cols
269 $flag_tva=(count($this->a_Tva) > 4)?true:false;
270
271 // Prepare the query for reconcile date
272 $prepared_query=new Prepared_Query($ledger->db);
273 $prepared_query->prepare_reconcile_date();
274
275 for ( $i=0;$i<count($a_jrn);$i++)
276 {
277 /* initialize tva */
278 for ($f=0;$f<count($this->a_Tva);$f++)
279 {
280 $l=$this->a_Tva[$f]['tva_id'];
281 $atva_amount[$l]=0;
282 }
283
284 // retrieve info from ledger
285 $aAmountVat=$ledger->vat_operation($a_jrn[$i]['jr_grpt_id']);
286
287 // put vat into array
288 for ($f=0;$f<count($aAmountVat);$f++)
289 {
290 $l=$aAmountVat[$f]['tva_id'];
291 $atva_amount[$l]=bcadd($atva_amount[$l],$aAmountVat[$f]['sum_vat']);
292 $this->tp_tva[$l]=bcadd($this->tp_tva[$l],$aAmountVat[$f]['sum_vat']);
293 $this->rap_tva[$l]=bcadd($this->rap_tva[$l],$aAmountVat[$f]['sum_vat']);
294
295 }
296 $row=$a_jrn[$i];
297 $ret_reconcile=$ledger->db->execute('reconcile_date',array($row['jr_id']));
298 $this->LongLine(15,5,($row['jr_pj_number']),0);
299 $this->write_cell(10,5,$row['str_date_short'],0,0);
300 $this->write_cell(13,5,$row['jr_internal'],0,0);
301 list($qc,$name)=$this->get_tiers($row['jr_id'],$this->jrn_type);
302 $this->LongLine(40,5,"[".$qc."]".$name,0,'L');
303
304 if ( !$flag_tva ) {
305 $this->LongLine(65,5,mb_substr($row['jr_comment'],0,150),0,'L');
306 }
307
308 /* get other amount (without vat, total vat included, private, ND */
309 $other=$ledger->get_other_amount($a_jrn[$i]['jr_grpt_id']);
310
311 $this->write_cell(15,5,nbm($other['price']),0,0,'R');
312
313 if ( $ledger_history->get_ledger_type() !='VEN')
314 {
315 $this->write_cell(15,5,nbm($other['priv']),0,0,'R');
316 $this->write_cell(15,5,nbm($other['tva_nd']),0,0,'R');
317 }
318
319 $this->write_cell(15,5,nbm($other['tva_np']),0,0,'R');
320
321 foreach ($atva_amount as $row_atva_amount)
322 {
323 $this->write_cell(15, 5, nbm($row_atva_amount), 0, 0, 'R');
324 }
325
326 $l_tvac=bcadd($other['price'], bcsub($other['vat'],$other['tva_np']));
327 $l_tvac=bcadd($l_tvac,$other['tva_nd']);
328 $l_tvac=bcadd($l_tvac,$a_jrn[$i]['other_tax_amount']);
329 if ($this->flag_other_tax) {
330 $this->write_cell(15, 5, nbm($a_jrn[$i]['other_tax_amount']), 0, 0, 'R');
331 }
332 $this->write_cell(15,5,nbm($l_tvac),0,0,'R');
333 $this->line_new(2);
334 // Add the payment information on another row
336 $str_payment="";
337 if ($max > 0) {
338 $this->write_cell(15,5, _("Payé par"));
339 $sep="";
340 for ($e=0;$e<$max;$e++) {
342 $msg=( $row['qcode_bank'] != "")?"[".$row['qcode_bank']."]".$row['qcode_name']:$row['jr_internal'];
343 $str_payment=$row['jr_date'].$msg.$sep;
344 $sep=' , ';
345 }
346 $this->write_cell (120,5,$str_payment);
347 }
348
349
350 $this->line_new(3);
351 // Total page
352 $this->tp_htva=bcadd($this->tp_htva,$other['price']);
353 $this->tp_tvac=bcadd($this->tp_tvac,$other['price']);
354 $this->tp_tvac=bcadd($this->tp_tvac,$other['vat']);
355 $this->tp_tvac=bcadd($this->tp_tvac,$other['tva_nd']);
356 $this->tp_tvac=bcsub($this->tp_tvac,$other['tva_np']);
357 $this->tp_tva_np=bcadd($this->tp_tva_np,$other['tva_np']);
358 $this->tp_priv=bcadd($this->tp_priv,$other['priv']);
359 $this->tp_nd=bcadd($this->tp_nd,$other['tva_nd']);
360
361
362 // Total report
363 $this->rap_htva=bcadd($this->rap_htva,$other['price']);
364 $this->rap_tvac=bcadd($this->rap_tvac,$other['price']);
365 $this->rap_tvac=bcadd($this->rap_tvac,$other['vat']);
366 $this->rap_tvac=bcsub($this->rap_tvac,$other['tva_np']);
367 $this->rap_tvac=bcadd($this->rap_tvac,$other['tva_nd']);
368 $this->rap_priv=bcadd($this->rap_priv,$other['priv']);
369 $this->rap_nd=bcadd($this->rap_nd,$other['tva_nd']);
370 $this->rap_tva_np=bcadd($this->rap_tva_np,$other['tva_np']);
371
372 if ($this->flag_other_tax) {
373 $this->tp_other_tax = bcadd($this->tp_other_tax, $a_jrn[$i]['other_tax_amount']);
374 $this->rap_other_tax = bcadd($this->rap_other_tax, $a_jrn[$i]['other_tax_amount']);
375 }
376
377 }
378 }
379
380}
nbm($p_number, $p_dec=2)
format the number with a sep.
Definition: ac_common.php:137
$input_from cn
Definition: balance.inc.php:66
$from_poste name
static factory(Database $cn, $pa_ledger, $p_from, $p_to, $p_mode, $p_paid)
Build the right object.
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows
line_new($p_step=null)
Print all the cell stored and call Ln (new line)
LongLine($w, $h, $txt, $border=0, $align='', $fill=false)
write_cell($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='')
get_tiers($p_jr_id, $p_jrn_type)
retrieve the client name and quick_code
Definition: pdf.class.php:84
$dossier
Definition: pdf.class.php:38
For the periode tables parm_periode and jrn_periode.
contains prepared query used in different classes of the application
this class extends PDF and let you export the detailled printing of any ledgers
__construct($p_cn, Acc_Ledger $p_jrn, $p_from, $p_to, $p_filter_operation)
export()
export the ledger in PDF
Header()
write the header of each page
Parent class for the print_ledger class.
$ledger
concerned Ledger
$count