noalyss Version-9
pdf_anc_acc_list.class.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * PhpCompta is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * PhpCompta is distributed in the hope that it will be useful,
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 PhpCompta; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20// Copyright (2002-2021) Author Dany De Bontridder <danydb@noalyss.eu>
21
22/**
23 * @file
24 * @brief
25 */
26/* !
27 * \class
28 * \brief export Anc_Acc_List (ANCBCC) to PDF
29 */
30
31class PDF_Anc_Acc_List extends PDF
32{
33
35 private $str_title;
36 private $a_size;
37
38 function __construct(Anc_Acc_List $p_anc_acc_list)
39 {
40 parent::__construct($p_anc_acc_list->db);
41 $this->anc_acc_list=$p_anc_acc_list;
42 $a_title=array(
43 1=>_('Comptabilité Analytique Fiche/Activité'),
44 2=>_("Comptabilité Analytique Poste comptable/Activité"),
45 3=>_('Comptabilité Analytique Activité/Fiche'),
46 4=>_('Comptabilité Analytique Activité/Poste Comptable'));
47 if (!isset($a_title[$p_anc_acc_list->card_poste]))
48 {
49 throw new Exception("PAAL.46 : invalid object");
50 }
51 $this->str_title=$a_title[$p_anc_acc_list->card_poste];
52 }
53 /**
54 * @brief Display the total amount
55 * @param type $p_pdf
56 * @param type $p_total
57 */
58 private function put_total($a_size,$p_pdf, $p_total)
59 {
60 $p_pdf->SetFont('DejaVu', 'B', 7);
61 $p_pdf->write_cell($a_size['po_name']+$a_size['po_description'], 5, _("Total"));
62 $p_pdf->write_cell($a_size['po_amount'], 5, nbm($p_total, 2), 0, 0, 'R');
63 $p_pdf->line_new(5);
64 }
65 /**
66 * @brief Print the title
67 * @param PDF $p_pdf
68 * @param int $n_row_idx , idx of anc_acc_list->arow
69 */
70 private function put_title($p_pdf, $n_row_idx)
71 {
72 $p_pdf->SetFont('DejaVu', 'BU', 10);
73 switch ($this->anc_acc_list->card_poste)
74 {
75 case 1:
76
77 $p_pdf->write_cell(190, 12,
78 $this->anc_acc_list->arow[$n_row_idx]['j_qcode']." ".
79 $this->anc_acc_list->arow[$n_row_idx]['name']);
80
81 break;
82 case 2:
83
84 $p_pdf->write_cell(190, 12,
85 $this->anc_acc_list->arow[$n_row_idx]['j_poste']." ".
86 $this->anc_acc_list->arow[$n_row_idx]['name']);
87
88 break;
89 case 3:
90
91 $p_pdf->write_cell(190, 12,
92 $this->anc_acc_list->arow[$n_row_idx]['po_name']." ".
93 $this->anc_acc_list->arow[$n_row_idx]['po_description']);
94
95 break;
96 case 4:
97
98 $p_pdf->write_cell(190, 12,
99 $this->anc_acc_list->arow[$n_row_idx]['po_name']." ".
100 $this->anc_acc_list->arow[$n_row_idx]['po_description']);
101
102 break;
103 default:
104 break;
105 }
106 $p_pdf->line_new();
107 }
108 /**
109 * @brief Return the previous item : card or account or activity depending of the crossing method
110 * @param type $n_row_idx
111 * @return type
112 */
113 private function get_previous($n_row_idx)
114 {
115 switch ($this->anc_acc_list->card_poste)
116 {
117 case 1:
118 return $this->anc_acc_list->arow[$n_row_idx]['f_id'];
119 break;
120 case 2:
121 return $this->anc_acc_list->arow[$n_row_idx]['j_poste'];
122 break;
123 case 3:
124 return $this->anc_acc_list->arow[$n_row_idx]['po_id'];
125 break;
126 case 4:
127 return $this->anc_acc_list->arow[$n_row_idx]['po_id'];
128 break;
129 }
130 }
131 /**
132 * @brief
133 * @return \PDF
134 */
135 private function pdf_card()
136 {
137 $pdf=new PDF($this->anc_acc_list->db);
138 $pdf->setDossierInfo(_("Balance croisée A/C"));
139 $pdf->SetTitle($this->str_title);
140 $pdf->AddPage();
141 $pdf->SetFont('DejaVu', 'B', 12);
142 $pdf->write_cell(190, 12, $this->str_title, 1);
143 $pdf->AliasNbPages();
144
145 $nb_row=count($this->anc_acc_list->arow);
146 $a_size=array("po_name"=>60, "po_description"=>100, "po_amount"=>30);
147 $pdf->line_new(20);
148 $pdf->SetFont('DejaVu', '', 7);
149 $tot_card=0; $tot_glob=0;
150 for ($i=0; $i<$nb_row; $i++)
151 {
152 $fill=$pdf->is_fill($i+1);
153 if ($i==0)
154 {
155 $prev=$this->get_previous($i);
156 $this->put_title($pdf, $i);
157 $pdf->SetFont('DejaVu', '', 7);
158 }
159 if ($prev!=$this->get_previous($i))
160 {
161 $prev=$this->get_previous($i);
162 $this->put_total($a_size,$pdf,$tot_card);
163
164 $this->put_title($pdf, $i);
165 $pdf->SetFont('DejaVu', '', 7);
166 $tot_card=0;
167 }
168 $this->anc_acc_list->arow[$i]['sum_amount']=($this->anc_acc_list->arow[$i]['sum_amount']=="")?0:
169 $this->anc_acc_list->arow[$i]['sum_amount'];
170
171 $tot_card=bcadd($tot_card, $this->anc_acc_list->arow[$i]['sum_amount'], 2);
172 $tot_glob=bcadd($tot_glob, $this->anc_acc_list->arow[$i]['sum_amount'], 2);
173 if ($this->anc_acc_list->card_poste<3)
174 {
175 $pdf->write_cell($a_size['po_name'], 4, $this->anc_acc_list->arow[$i]['po_name'], 0, 0, 'L', $fill);
176 $pdf->write_cell($a_size['po_description'], 4, $this->anc_acc_list->arow[$i]['po_description'], 0, 0,
177 'L', $fill);
178 $pdf->write_cell($a_size['po_amount'], 4, nbm($this->anc_acc_list->arow[$i]['sum_amount'], 2), 0, 0,
179 'R', $fill);
180 }
181 elseif ($this->anc_acc_list->card_poste==3)
182 {
183 $pdf->write_cell($a_size['po_name'], 4, $this->anc_acc_list->arow[$i]['j_qcode'], 0, 0, 'L', $fill);
184 $pdf->write_cell($a_size['po_description'], 4, $this->anc_acc_list->arow[$i]['name'], 0, 0, 'L', $fill);
185 $pdf->write_cell($a_size['po_amount'], 4, nbm($this->anc_acc_list->arow[$i]['sum_amount'], 2), 0, 0,
186 'R', $fill);
187 }
188 elseif ($this->anc_acc_list->card_poste==4)
189 {
190 $pdf->write_cell($a_size['po_name'], 4, $this->anc_acc_list->arow[$i]['j_poste'], 0, 0, 'L', $fill);
191 $pdf->write_cell($a_size['po_description'], 4, $this->anc_acc_list->arow[$i]['name'], 0, 0, 'L', $fill);
192 $pdf->write_cell($a_size['po_amount'], 4, nbm($this->anc_acc_list->arow[$i]['sum_amount'], 2), 0, 0,
193 'R', $fill);
194 }
195 $pdf->line_new();
196 }
197 $this->put_total($a_size,$pdf,$tot_card);
198 $pdf->SetFont('DejaVu', '', 7);
199
200 $pdf->line_new(5);
201 $pdf->write_cell($a_size['po_name']+$a_size['po_description'], 10, _("Total Global"),'LBT');
202 $pdf->write_cell($a_size['po_amount'], 10, nbm($tot_glob, 2), 'RBT', 0, 'R');
203 $pdf->line_new();
204 return $pdf;
205 }
206
207 public function get_a_size()
208 {
209 return $this->a_size;
210 }
211
213 {
214 $this->a_size=$a_size;
215 return $this;
216 }
217
218 public function get_anc_acc_list()
219 {
220 return $this->anc_acc_list;
221 }
222
223 public function get_str_title()
224 {
225 return $this->str_title;
226 }
227
229 {
230 $this->anc_acc_list=$anc_acc_list;
231 return $this;
232 }
233
235 {
236 $this->str_title=$str_title;
237 return $this;
238 }
239 /**
240 * @brief Main function , export the ANCBCC list to PDF, crossed by activity , account or card
241 * @return type
242 * @throws Exception
243 */
244 function export_pdf()
245 {
246
247 if ($this->anc_acc_list->check()!=0)
248 {
249 throw new Exception(_("date invalide"));
250 }
251 switch ($this->anc_acc_list->card_poste)
252 {
253 case 1:
254 // Card - Acc
255 $this->anc_acc_list->load_card();
256 return $this->pdf_card();
257 break;
258 case 2:
259 // Accountancy - Analytic
260 $this->anc_acc_list->load_poste();
261 return $this->pdf_card();
262 break;
263 case 3:
264 // Acc after card
265 $this->anc_acc_list->load_anc_card();
266 return $this->pdf_card();
267 break;
268 case 4:
269 // Analytic - Accountancy
270 $this->anc_acc_list->load_anc_account();
271 return $this->pdf_card();
272 break;
273 default:
274 throw new Exception('AAL700:unknown export');
275 }
276 return;
277 }
278
279}
nbm($p_number, $p_dec=2)
format the number with a sep.
Definition: ac_common.php:137
Manage the class for reporting about Analytic Accountancy and Accountancy : card - analytic account,...
__construct(Anc_Acc_List $p_anc_acc_list)
set_anc_acc_list($anc_acc_list)
put_total($a_size, $p_pdf, $p_total)
Display the total amount.
export_pdf()
Main function , export the ANCBCC list to PDF, crossed by activity , account or card.
get_previous($n_row_idx)
Return the previous item : card or account or activity depending of the crossing method.
put_title($p_pdf, $n_row_idx)
Print the title.
API for creating PDF, unicode, based on tfpdf.
Definition: pdf.class.php:34
if( $delta< 0) elseif( $delta==0)