noalyss Version-9
export_balance_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 * 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/*! \file
20 * \brief Print the balance in pdf format
21 * \param received parameters
22 * \param e_date element 01.01.2003
23 * \param e_client element 3
24 * \param nb_item element 2
25 * \param e_march0 element 11
26 * \param e_quant0 element 1
27 * \param e_march1 element 6
28 * \param e_quant1 element 2
29 * \param e_comment invoice number
30 */
31// Copyright Author Dany De Bontridder danydb@aevalys.eu
32if (!defined('ALLOWED')) die('Appel direct ne sont pas permis');
33include_once("lib/ac_common.php");
34include_once("class/acc_balance.class.php");
35require_once NOALYSS_INCLUDE . '/header_print.php';
37
39bcscale(4);
41$rep = new Database();
42$g_user->Check();
43
45try {
46 $from_periode = $http->request("from_periode");
47 $to_periode = $http->request("to_periode");
48 $from_poste = $http->request("from_poste");
49 $to_poste = $http->request("to_poste");
50 $p_filter = $http->request("p_filter", "string");
51} catch (Exception $exc) {
52 error_log("Missing parameters");
53 error_log($exc->getTraceAsString());
54 return;
55}
56
57// Compute for the summary
58$summary_tab = $bal->summary_init();
59$summary_prev_tab = $bal->summary_init();
60$is_summary = $http->get("summary", "string", 0);
61
62$bal->jrn = null;
63switch ($p_filter) {
64 case 0:
65 $bal->jrn = null;
66 break;
67 case 1:
68 if (isset($_GET['r_jrn'])) {
69 $selected = $http->get("r_jrn");
70 $array_ledger = $g_user->get_ledger('ALL', 3);
71 $array = get_array_column($array_ledger, 'jrn_def_id');
72 for ($e = 0; $e < count($selected); $e++) {
73 if (isset ($selected[$e])
74 && isNumber($selected[$e]) == 1
75 && in_array($selected[$e], $array)) {
76 $bal->jrn[] = $selected[$e];
77 }
78 }
79 }
80 break;
81 case 2:
82 if (isset($_GET['r_cat'])) $bal->filter_cat($http->get("r_cat"));
83 break;
84}
85
86$bal->from_poste = $from_poste;
87$bal->to_poste = $to_poste;
88if (isset($_GET['unsold'])) $bal->unsold = true;
89$previous = (isset($_GET['previous_exc'])) ? 1 : 0;
90
92
93$previous = (isset ($array[0]['sum_cred_previous'])) ? 1 : 0;
94
95
96if (sizeof($array) == 0) {
97 exit();
98
99}
100
102$a = $pPeriode->get_date_limit($from_periode);
103$b = $pPeriode->get_date_limit($to_periode);
104$per_text = sprintf(_("Du %s au %s" ), $a['p_start'] ,$b['p_end']);
105
106// If compare with previous exercice ,
107// we use the landscape mode
108if ($previous == 1) {
109 $pdf = new PDFLand($cn);
110} else {
111 $pdf = new PDF($cn);
112}
113
114$pdf->setDossierInfo(" Balance " . $per_text);
115$pdf->AliasNbPages();
116$pdf->AddPage();
117$pdf->SetAuthor('NOALYSS');
118$pdf->SetFont('DejaVuCond', '', 7);
119$pdf->setTitle(_("Balance comptable"), true);
120$pdf->write_cell(30, 6, _('poste'));
121$pdf->LongLine(60, 6, _('Libellé'));
122if ($previous == 1) {
123 $pdf->write_cell(20, 6, 'Débit N-1', 0, 0, 'R');
124 $pdf->write_cell(20, 6, 'Crédit N-1', 0, 0, 'R');
125 $pdf->write_cell(20, 6, 'Solde N-1', 0, 0, 'R');
126}
127$pdf->write_cell(25, 6, _('Ouverture'), 0, 0, 'R');
128$pdf->write_cell(25, 6, _('Total Débit'), 0, 0, 'R');
129$pdf->write_cell(25, 6, _('Total Crédit'), 0, 0, 'R');
130$pdf->write_cell(25, 6, _('Solde'), 0, 0, 'R');
131$pdf->line_new();
132
133$pdf->SetFont('DejaVuCond', '', 8);
143if ($previous == 1) {
144 $a_sum = array('sum_cred', 'sum_deb', 'solde_deb', 'solde_cred', 'sum_cred_previous', 'sum_deb_previous', 'solde_deb_previous', 'solde_cred_previous', 'sum_cred_ope', 'sum_deb_ope');
145} else {
146 $a_sum = array('sum_cred', 'sum_deb', 'solde_deb', 'solde_cred', 'sum_cred_ope', 'sum_deb_ope');
147}
148foreach ($a_sum as $a) {
149 $nlvl1[$a] = 0;
150 $nlvl2[$a] = 0;
151 $nlvl3[$a] = 0;
152}
156
157bcscale(2);
158if (!empty($array)) {
159 $i = 0;
160 foreach ($array as $key => $value) {
161 $i++;
162 /*
163 * level x
164 */
165 if ($value['poste'] == '') continue;
166 foreach (array(3, 2, 1) as $ind) {
167 $r = $value;
168 if (!isset($_GET['lvl' . $ind])) continue;
169
170 if (${'lvl' . $ind . '_old'} == '') ${'lvl' . $ind . '_old'} = substr($r['poste'], 0, $ind);
171 if (${'lvl' . $ind . '_old'} != substr($r['poste'], 0, $ind)) {
172 $pdf->SetFont('DejaVu', 'B', 7);
173 $strTotal=sprintf(_("Totaux %s "),${'lvl' . $ind . '_old'});
174 $pdf->LongLine(30, 6, $strTotal,"TB");
175 $delta = bcsub(${'nlvl' . $ind}['solde_cred'], ${'nlvl' . $ind}['solde_deb']);
176 $side = ($delta < 0) ? "D" : "C";
177 if ($previous == 1) {
178 $delta_previous = bcsub(${'nlvl' . $ind}['solde_cred_previous'], ${'nlvl' . $ind}['solde_deb_previous']);
179 $side_previous = ($delta_previous < 0) ? "D" : "C";
180 $pdf->write_cell(60, 6, sprintf(_("niveau %s"),$ind), "TB", 0, 'R');
181 $pdf->write_cell(22, 6, nbm(${'nlvl' . $ind}['sum_deb_previous']), "TB", 0, 'R');
182 $pdf->write_cell(22, 6, nbm(${'nlvl' . $ind}['sum_cred_previous']), "TB", 0, 'R');
183 $pdf->write_cell(22, 6, nbm(abs($delta_previous)) . " $side_previous", "TB", 0, 'R');
184
185 } else {
186 $pdf->write_cell(60, 6, sprintf(_("niveau %s"),$ind), "TB", 0, 'R');
187
188 }
189 $solde_lv = bcsub(${'nlvl' . $ind}['sum_deb_ope'], ${'nlvl' . $ind}['sum_cred_ope']);
190 $side_lv = ($solde_lv < 0) ? " C" : " D";
191 $side_lv = ($solde_lv == 0) ? " " : $side_lv;
192 $pdf->write_cell(25, 6, nbm(abs($solde_lv)) . $side_lv, "TB", 0, 'R');
193 $pdf->write_cell(25, 6, nbm(bcsub(${'nlvl' . $ind}['sum_deb'], ${'nlvl' . $ind}['sum_deb_ope'])), "TB", 0, 'R');
194 $pdf->write_cell(25, 6, nbm(bcsub(${'nlvl' . $ind}['sum_cred'], ${'nlvl' . $ind}['sum_cred_ope'])), "TB", 0, 'R');
195 $solde_lv = bcsub(${'nlvl' . $ind}['solde_deb'], ${'nlvl' . $ind}['solde_cred']);
196 $side_lv = ($solde_lv > 0) ? "D" : "C";
197 $side_lv = ($solde_lv == 0) ? "" : $side_lv;
198 $pdf->write_cell(25, 6, nbm(abs($solde_lv)) . " $side_lv", "TB", 0, 'R');
199 $pdf->line_new();
200 $pdf->SetFont('DejaVuCond', '', 7);
201 ${'lvl' . $ind . '_old'} = substr($r['poste'], 0, $ind);
202 foreach ($a_sum as $a) {
203 ${'nlvl' . $ind}[$a] = 0;
204 }
205 }
206 }
207 foreach ($a_sum as $a) {
208 $nlvl1[$a] = bcadd($nlvl1[$a], $r[$a]);
209 $nlvl2[$a] = bcadd($nlvl2[$a], $r[$a]);
210 $nlvl3[$a] = bcadd($nlvl3[$a], $r[$a]);
211 }
212
213 $fill=$pdf->is_fill($i);
214
215 $label=$value['poste'];
216 if (in_array($r['type'],array('CHA','ACT','PASINV','PROINV')) && $value['sum_deb']<$value['sum_cred'])
217 {
218
219 $label.=" ".mb_chr(0x26a0);
220 }
221 if (in_array($r['type'],array('PRO','PAS','ACTINV','CHAINV')) && $value['sum_deb']>$value['sum_cred'])
222 {
223
224 $label.=" ".mb_chr(0x26a0);
225 }
226 $pdf->LongLine(30, 6, $label, 0, 'L', $fill);
227 $pdf->LongLine(60, 6, $value['label'], 0, 'L', $fill);
228 $summary_tab = $bal->summary_add($summary_tab, $value['poste'],
229 $value['sum_deb'],
230 $value['sum_cred']);
231 if ($previous == 1) {
232 $pdf->write_cell(22, 6, nbm($value['sum_deb_previous']), 0, 0, 'R', $fill);
233 $pdf->write_cell(22, 6, nbm($value['sum_cred_previous']), 0, 0, 'R', $fill);
234
235// $pdf->write_cell(22,6,nbm($value['solde_deb_previous']),0,0,'R',$fill);
236// $pdf->write_cell(22,6,nbm($value['solde_cred_previous']),0,0,'R',$fill);
237 $solde_previous = bcsub($value['solde_cred_previous'], $value['solde_deb_previous']);
238 $side_previous = ($solde_previous < 0) ? " D" : " C";
239 $side_previous = ($solde_previous == 0) ? "" : $side_previous;
240
241 $pdf->write_cell(22, 6, nbm(abs($solde_previous)) . $side_previous, 0, 0, 'R', $fill);
242
243 $tp_deb_previous = bcadd($tp_deb_previous, $value['sum_deb_previous']);
244 $tp_cred_previous = bcadd($tp_cred_previous, $value['sum_cred_previous']);
245 $tp_sold_previous = bcadd($tp_sold_previous, $value['solde_deb_previous']);
246 $tp_solc_previous = bcadd($tp_solc_previous, $value['solde_cred_previous']);
248 $value['poste'],
249 $value['sum_deb_previous'],
250 $value['sum_cred_previous']);
251 }
252 $solde_ope = bcsub($value['sum_deb_ope'], $value['sum_cred_ope']);
253 $tot_opening=bcadd($tot_opening,$solde_ope);
254
255 $side_ope = ($solde_ope > 0) ? " D" : "C";
256 $side_ope = ($solde_ope == 0) ? " " : $side_ope;
257 // compute column value
258 $deb = bcsub($value['sum_deb'], $value['sum_deb_ope']);
259 $cred = bcsub($value['sum_cred'], $value['sum_cred_ope']);
260 $pdf->write_cell(25, 6, nbm(abs($solde_ope)) . $side_ope, 0, 0, 'R', $fill);
261 $pdf->write_cell(25, 6, nbm($deb), 0, 0, 'R', $fill);
262 $pdf->write_cell(25, 6, nbm($cred), 0, 0, 'R', $fill);
263 $solde = bcsub($value['sum_deb'], $value['sum_cred']);
264 $side = ($solde > 0) ? "D" : "C";
265 $side = ($solde == 0) ? "" : $side;
266 $pdf->write_cell(25, 6, nbm(abs($solde)) . $side, 0, 0, 'R', $fill);
267 $pdf->line_new();
268 $tp_deb = bcadd($tp_deb, $deb);
269 $tp_cred = bcadd($tp_cred, $cred);
270 $tp_sold = bcadd($tp_sold, $value['solde_deb']);
271 $tp_solc = bcadd($tp_solc, $value['solde_cred']);
272
273 }
274 foreach (array(3, 2, 1) as $ind) {
275 $r = $value;
276 if (!isset($_GET['lvl' . $ind])) continue;
277
278 if (${'lvl' . $ind . '_old'} == '') ${'lvl' . $ind . '_old'} = substr($r['poste'], 0, $ind);
279 if (${'lvl' . $ind . '_old'} != substr($r['poste'], 0, $ind)) {
280 $pdf->SetFont('DejaVu', 'B', 7);
281 $pdf->write_cell(30, 6, "Totaux " . $ind);
282 $pdf->write_cell(60, 6, ${'lvl' . $ind . '_old'});
283 if ($previous == 1) {
284 $pdf->write_cell(22, 6, nbm(${'nlvl' . $ind}['sum_deb_previous']), 0, 0, 'R');
285 $pdf->write_cell(22, 6, nbm(${'nlvl' . $ind}['sum_cred_previous']), 0, 0, 'R');
286 $pdf->write_cell(22, 6, nbm(${'nlvl' . $ind}['solde_deb_previous']), 0, 0, 'R');
287 $pdf->write_cell(22, 6, nbm(${'nlvl' . $ind}['solde_cred_previous']), 0, 0, 'R');
288 }
289 $pdf->write_cell(25, 6, nbm(${'nlvl' . $ind}['sum_deb']), 0, 0, 'R');
290 $pdf->write_cell(25, 6, nbm(${'nlvl' . $ind}['sum_cred']), 0, 0, 'R');
291 $solde_lv = bcsub(${'nlvl' . $ind}['solde_deb'], ${'nlvl' . $ind}['solde_cred']);
292 $side_lv = findSide($solde_lv );
293 $pdf->write_cell(25, 6, nbm(abs($solde_lv)) . " $side_lv", 0, 0, 'R');
294 $pdf->line_new();
295 $pdf->SetFont('DejaVuCond', '', 7);
296 ${'lvl' . $ind . '_old'} = substr($r['poste'], 0, $ind);
297 foreach ($a_sum as $a) {
298 ${'nlvl' . $ind}[$a] = 0;
299 }
300 }
301 }
302
303 // Totaux
304 $pdf->SetFont('DejaVuCond', 'B', 8);
305 $pdf->write_cell(90, 6, $r['label']);
306 if ($previous == 1) {
307 $pdf->write_cell(22, 6, nbm($tp_deb_previous), 'T', 0, 'R', 0);
308 $pdf->write_cell(22, 6, nbm($tp_cred_previous), 'T', 0, 'R', 0);
309 $pdf->write_cell(22, 6, nbm($tp_sold_previous), 'T', 0, 'R', 0);
310 $pdf->write_cell(22, 6, nbm($tp_solc_previous), 'T', 0, 'R', 0);
311 }
312 $solde = bcsub($tp_sold,$tp_solc);
313
314 $solde_side = findSide($solde);
315 $tot_opening_side = findSide($tot_opening);
316 // ---------------
317 // Footer column
318 // ---------------
319 $pdf->write_cell(25, 6, nbm(abs($tot_opening))." ".$tot_opening_side, 'T', 0, 'R', 0);
320 $pdf->write_cell(25, 6, nbm($tp_deb), 'T', 0, 'R', 0);
321 $pdf->write_cell(25, 6, nbm($tp_cred), 'T', 0, 'R', 0);
322 $pdf->write_cell(25, 6, nbm(abs($solde)).$solde_side, 'T', 0, 'R', 0);
323 $pdf->line_new();
324}
325/** empty */
326// display the summary
327if ($is_summary == 1) {
328 if ($previous == 1) {
329 $pdf->SetFont('DejaVuCond', 'B', 8);
330 $pdf->write_cell(50, 8, _("Résumé Exercice précédent"));
331 $pdf->line_new();
332 $pdf->SetFont('DejaVuCond', '', 7);
333 $bal->summary_display_pdf($summary_prev_tab, $pdf);
334 $pdf->line_new();
335 }
336 $pdf->SetFont('DejaVuCond', 'B', 8);
337 $pdf->write_cell(50, 8, _("Résumé Exercice courant"));
338 $pdf->line_new();
339 $pdf->SetFont('DejaVuCond', '', 7);
340 $bal->summary_display_pdf($summary_tab, $pdf);
341}
342
343$fDate = date('dmy-Hi');
344$pdf->Output('balance-' . $fDate . '.pdf', 'D');
345
346
347?>
isNumber($p_int)
Definition: ac_common.php:215
findSide($p_number)
return D if the number is smaller than 0 , C if bigger and an empty string if equal to 0.
Definition: ac_common.php:121
get_array_column($p_array, $key)
Definition: ac_common.php:1278
nbm($p_number, $p_dec=2)
format the number with a sep.
Definition: ac_common.php:137
global $g_user
if no group available , then stop
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$array_ledger
$selected
$input_from id
Definition: balance.inc.php:63
for($i=0;$i<=6;$i++) $ind
Definition: calendar.php:34
$_GET['qcode']
Class for manipulating data to print the balance of account.
contains the class for connecting to Noalyss
static connect()
manage the http input (get , post, request) and extract from an array
API for creating PDF, unicode, based on tfpdf.
Definition: pdf.class.php:34
PDF in landscape mode.
For the periode tables parm_periode and jrn_periode.
$tp_sold_previous
$tp_solc_previous
catch(Exception $exc) $summary_tab
foreach($a_sum as $a) $lvl1_old
if(!empty( $array)) if($is_summary==1) $fDate
empty
$tp_deb_previous
$summary_prev_tab
$tp_cred_previous
if(sizeof($array)==0) $pPeriode
for($e=0; $e< count($afiche); $e++) exit
for($e=2;$e< $nb_col;$e++) $a_sum
$side
for($i=0;$i< $nb_jrn;$i++) $deb