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