noalyss Version-9
export_fiche_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
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!\file
23 * \brief Called by impress->category, export in PDF the history of a category or balance
24 * of card
25 */
26if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
27// Security we check if user does exist and his privilege
28require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
29
30/* Security */
33$g_user->Check();
34$g_user->check_dossier($gDossier);
35
37
38$cat = $http->get("cat");
39$histo = $http->get("histo");
40
41$name=$cn->get_value('select fd_label from fiche_def where fd_id=$1',array($cat));
42
44$pdf->setDossierInfo(" Periode : ".$http->get('start')." - ".$http->get('end'));
45$pdf->AliasNbPages();
46$pdf->AddPage();
47
48$pdf->SetTitle($name,1);
49$pdf->SetAuthor('NOALYSS');
50/* balance */
51$allcard=(isset($_GET['allcard']))?1:0;
52/*
53 * Balance
54 */
55if ($histo == 4 || $histo==5)
56{
57 $fd=new Fiche_Def($cn,$http->request('cat'));
58 if ($allcard==1 && $fd->hasAttribute(ATTR_DEF_ACCOUNT) == false )
59 {
60 $pdf->write_cell(0,10, "Cette catégorie n'ayant pas de poste comptable n'a pas de balance");
61 //Save PDF to file
62 $fDate=date('dmy-Hi');
63 $pdf->Output("category-$fDate.pdf", 'D');
64 exit;
65 }
66 // all card
67 if ($allcard==1)
68 {
69 $afiche=$cn->get_array("select fd_id from vw_fiche_def where ad_id=".ATTR_DEF_ACCOUNT." order by fd_label asc");
70 }
71 else
72 {
73 $afiche[0]=array('fd_id'=>$http->request('cat'));
74 }
75
76 if ( $allcard==0 && empty($afiche))
77 {
78 $pdf->write_cell(0,10, "Aucune fiche trouvée");//Save PDF to file
79 $fDate=date('dmy-Hi');
80 $pdf->Output("category-$fDate.pdf", 'D');
81 exit;
82 }
83 for ($e = 0; $e < count($afiche); $e++)
84 {
85 $aCard=$cn->get_array("select f_id,ad_value from fiche join fiche_Detail using (f_id) where ad_id=1 and fd_id=$1 order by 2 ",array($afiche[$e]['fd_id']));
86 $name=$cn->get_value('select fd_label from fiche_def where fd_id=$1',array($afiche[$e]['fd_id']));
87 $pdf->SetFont('DejaVu','BI',14);
88 $pdf->write_cell(0,8,$name,0,1,'C');
89
90 $pdf->SetFont('DejaVuCond','',7);
91 $pdf->LongLine(30,7,'Quick Code',0,'L',0);
92 $pdf->LongLine(80,7,'Libellé',0,'L',0);
93 $pdf->write_cell(20,7,'Débit',0,0,'R',0);
94 $pdf->write_cell(20,7,'Crédit',0,0,'R',0);
95 $pdf->write_cell(20,7,'Solde',0,0,'R',0);
96 $pdf->write_cell(20,7,'D/C',0,0,'C',0);
97 $pdf->line_new();
98
99 if (empty($aCard)) continue;
100
101
102 $idx=0;$sum_deb=0;$sum_cred=0;bcscale(4);
103 for ($i=0;$i < count($aCard);$i++)
104 {
105 if ( isDate($http->request('start')) == null || isDate ($http->request('end')) == null ) exit;
106 $filter= " (j_date >= to_date('".$http->request('start')."','DD.MM.YYYY') ".
107 " and j_date <= to_date('".$http->request('end')."','DD.MM.YYYY')) ";
108 $oCard=new Fiche($cn,$aCard[$i]['f_id']);
109 $solde=$oCard->get_solde_detail($filter);
110 if ( $solde['debit'] == 0 && $solde['credit']==0) continue;
111 /* only not purged card */
112 if ($histo == 5 && $solde['debit'] == $solde['credit']) continue;
113 $fill=$pdf->is_fill($idx);
114 $idx++;
115 $side='';
116 if(bcsub($solde['credit'],$solde['debit']) < 0) $side='Deb.';
117 if(bcsub($solde['credit'],$solde['debit']) > 0) $side='Cred.';
118
119 $sum_cred=bcadd($sum_cred,$solde['credit']);
120 $sum_deb=bcadd($sum_deb,$solde['debit']);
121 $sum_solde=bcsub($sum_deb,$sum_cred);
122
123 $pdf->write_cell(30,7,$oCard->strAttribut(ATTR_DEF_QUICKCODE),0,0,'L',$fill);
124 $pdf->LongLine(80,7,$oCard->strAttribut(ATTR_DEF_NAME)." (".$oCard->strAttribut(ATTR_DEF_ACCOUNT).")",0,'L',$fill);
125 $pdf->write_cell(20,7,nbm($solde['debit']),0,0,'R',$fill);
126 $pdf->write_cell(20,7,nbm($solde['credit']),0,0,'R',$fill);
127 $pdf->write_cell(20,7,nbm(abs($solde['solde'])),0,0,'R',$fill);
128 $pdf->write_cell(20,7,$side,0,0,'C',$fill);
129 $pdf->line_new();
130 }
131 $fill=$pdf->is_fill($idx);
132
133 $idx++;
134 // Sum by category
135 $pdf->write_cell(30,7,"",0,0,'L',$fill);
136 $pdf->write_cell(80,7,_("Totaux"),0,0,'L',$fill);
137 $pdf->write_cell(20,7,nbm($sum_deb),0,0,'R',$fill);
138 $pdf->write_cell(20,7,nbm($sum_cred),0,0,'R',$fill);
139 $pdf->write_cell(20,7,nbm(abs($sum_solde)),0,0,'R',$fill);
140 $side=" = ";
141 if ( $sum_solde > 0 )
142 {
143 $side='Deb.';
144 }
145 else if ( $sum_solde < 0)
146 {
147 $side='Cred.';
148 }
149
150 $pdf->write_cell(20,7,$side,0,0,'C',$fill);
151 $pdf->line_new();
152 }
153}
154else
155{
156 // History
157 // all card
158 if ($allcard == 1)
159 {
160 $afiche = $cn->get_array("select fd_id from vw_fiche_def where ad_id=" . ATTR_DEF_ACCOUNT . " order by fd_label asc");
161 }
162 else
163 {
164 $afiche[0] = array('fd_id' => $http->request('cat'));
165 }
166 $fic=new Fiche($cn);
167 for ($e = 0; $e < count($afiche); $e++)
168 {
169 $array = Fiche::get_fiche_def($cn,$afiche[$e]['fd_id'] , 'name_asc');
170 /*
171 * You show now the result
172 */
173 if ($array == null)
174 {
175 continue;
176 }
177 $tab = array(12, 20, 20,68, 20, 20, 10, 20);
178 $align = array('L', 'C', 'L', 'L', 'R','R', 'R', 'R');
179
180 foreach ($array as $row_fiche)
181 {
182 $fic = new Fiche($cn, $row_fiche['f_id']);
184 $letter->set_parameter('quick_code', $fic->strAttribut(ATTR_DEF_QUICKCODE));
185 $letter->set_parameter('start',$http->request('start'));
186 $letter->set_parameter('end',$http->request('end'));
187 // all
188 if ($histo == 0)
189 {
190 $letter->get_all();
191 }
192
193 // lettered
194 if ($histo == 1)
195 {
196 $letter->get_letter();
197 }
198 // unlettered
199 if ($histo == 2)
200 {
201 $letter->get_unletter();
202 }
203 if ($histo == 6)
204 {
205 $letter->get_letter_diff();
206 }
207 /* skip if nothing to display */
208 if (count($letter->content) == 0)
209 continue;
210 $pdf->SetFont('DejaVuCond', '', 10);
211 $fiche = new Fiche($cn, $row_fiche['f_id']);
212 $pdf->write_cell(0, 7, $fiche->strAttribut(ATTR_DEF_NAME)." [".$fiche->strAttribut(ATTR_DEF_QUICKCODE).":".$fiche->strAttribut(ATTR_DEF_ACCOUNT)."]", 1, 'C');
213
214 $pdf->SetFont('DejaVuCond', '', 7);
215 $pdf->line_new();
216 $pdf->write_cell($tab[0], 7, 'Date');
217 $pdf->write_cell($tab[1], 7, 'ref');
218 $pdf->write_cell($tab[2], 7, 'Internal');
219 $pdf->write_cell($tab[3], 7, 'Comm');
220 $pdf->write_cell($tab[4], 7, 'Montant', 0, 0, 'C');
221 $pdf->write_cell($tab[5], 7, 'Prog.', 0, 0, 'R');
222 $pdf->write_cell($tab[6], 7, 'Let.', 0, 0, 'R');
223 $pdf->write_cell($tab[7], 7, 'Diff. Let.', 0, 0, 'R');
224 $pdf->line_new();
225
226 $amount_deb = 0;
227 $amount_cred = 0;
228 $prog=0;
229 for ($i = 0; $i < count($letter->content); $i++)
230 {
231 $fill=$pdf->is_fill($i);
232 $pdf->SetFont('DejaVuCond', '', 7);
233 $row = $letter->content[$i];
234 $str_date = shrink_date($row['j_date_fmt']);
235
236 $pdf->LongLine($tab[0], 4, $str_date, 0, $align[0], $fill);
237 $pdf->write_cell($tab[1], 4, $row['jr_pj_number'], 0, 0, $align[1], $fill);
238 $pdf->LongLine($tab[2], 4, $row['jr_internal'], 0, $align[1], $fill);
239 $pdf->LongLine($tab[3], 4, $row['jr_comment'], 0, $align[2], $fill);
240 if ($row['j_debit'] == 't')
241 {
242 $prog=bcadd($prog,$row['j_montant']);
243 $pdf->write_cell($tab[4], 4, sprintf('%s D', nbm($row['j_montant'])), 0, 0, $align[4], $fill);
244 $amount_deb+=$row['j_montant'];
245 $str_prog=sprintf("%s %s",nbm(abs($prog)),$fic->get_amount_side($prog));
246 $pdf->write_cell($tab[5], 4, $str_prog, 0, 0, $align[5], $fill);
247 }
248 else
249 {
250 $prog=bcsub($prog,$row['j_montant']);
251 $pdf->write_cell($tab[4], 4, sprintf('%s C', nbm($row['j_montant'])), 0, 0, $align[4], $fill);
252 $amount_cred+=$row['j_montant'];
253 $str_prog=sprintf("%s %s",nbm(abs($prog)),$fic->get_amount_side($prog));
254 $pdf->write_cell($tab[5], 4, $str_prog, 0, 0, $align[5], $fill);
255 }
256 if ($row['letter'] != -1)
257 {
258 $pdf->write_cell($tab[6], 4, strtoupper(base_convert($row['letter'],10,36)), 0, 0, $align[6], $fill);
259 // get sum for this lettering
260
261 $pdf->write_cell($tab[7], 4, sprintf('%s', nbm($row['letter_diff'])), '0', '0', $align[7], $fill);
262 }
263 else
264 $pdf->write_cell($tab[6], 4, "", 0, 0, 'R', $fill);
265 $pdf->line_new();
266 }
267 $pdf->SetFillColor(0, 0, 0);
268 $pdf->SetFont('DejaVuCond', 'B', 8);
269 $debit = sprintf('Debit : %s', nbm($amount_deb));
270 $credit = sprintf('Credit : %s', nbm($amount_cred));
272 $s = 'solde débiteur';
273 else
274 $s = 'solde crediteur';
275 $solde = sprintf('%s : %s', $s, nbm(abs(round($amount_cred - $amount_deb, 2))));
276
277 $pdf->write_cell(0, 6, $debit, 0, 0, 'R');
278 $pdf->line_new(4);
279 $pdf->write_cell(0, 6, $credit, 0, 0, 'R');
280 $pdf->line_new(4);
281 $pdf->write_cell(0, 6, $solde, 0, 0, 'R');
282 $pdf->line_new(4);
283
284 $pdf->line_new();
285 }
286 }
287}
288//Save PDF to file
289$fDate=date('dmy-Hi');
290$pdf->Output("category-$fDate.pdf", 'D');
isDate($p_date)
Definition: ac_common.php:236
shrink_date($p_date)
shrink the date, make a date shorter for the printing
Definition: ac_common.php:826
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
$idx
$filter
$input_from id
Definition: balance.inc.php:63
$_GET['qcode']
static connect()
define Class fiche and fiche def, those class are using class attribut
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: fiche.class.php:38
static get_fiche_def($p_cn, $pFd_id, $p_order='')
get all the card from a categorie
manage the http input (get , post, request) and extract from an array
only for operation retrieved thanks a quick_code manage the accounting entries for a given card
API for creating PDF, unicode, based on tfpdf.
Definition: pdf.class.php:34
const ATTR_DEF_NAME
Definition: constant.php:216
const ATTR_DEF_QUICKCODE
Definition: constant.php:237
const ATTR_DEF_ACCOUNT
Definition: constant.php:215
for($e=0; $e< count($afiche); $e++) $fDate
$afiche[0]
Definition: fiche.inc.php:482
$amount_cred
Definition: letter_all.php:6
$amount_deb
Definition: letter_all.php:6
$side