noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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 */
31$gDossier=dossier::id();
32$cn=Dossier::connect();
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'a pas de poste comptable"));
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 $pdf->line_new();
90 $pdf->SetFont('DejaVuCond','',7);
91 $pdf->write_multi(30,3,'Quick Code',0,'L',0);
92 $pdf->write_multi(80,3,'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
124 $pdf->write_cell(30,7,$oCard->get_attribute(ATTR_DEF_QUICKCODE),0,0,'L',$fill);
125 $pdf->LongLine(80,7,$oCard->get_attribute(ATTR_DEF_NAME)." (".$oCard->get_attribute(ATTR_DEF_ACCOUNT).")",0,'L',$fill);
126
127 $pdf->write_cell(20,7,nbm($solde['debit']),0,0,'R',$fill);
128 $pdf->write_cell(20,7,nbm($solde['credit']),0,0,'R',$fill);
129 $pdf->write_cell(20,7,nbm(abs($solde['solde'])),0,0,'R',$fill);
130 $pdf->write_cell(20,7,$side,0,0,'C',$fill);
131 $pdf->line_new();
132 }
133 $fill=$pdf->is_fill($idx);
134
135 $idx++;
136 // Sum by category
137 $pdf->write_cell(30,7,"",0,0,'L',$fill);
138 $pdf->write_cell(80,7,_("Totaux"),0,0,'L',$fill);
139 $pdf->write_cell(20,7,nbm($sum_deb),0,0,'R',$fill);
140 $pdf->write_cell(20,7,nbm($sum_cred),0,0,'R',$fill);
141 $pdf->write_cell(20,7,nbm(abs($sum_solde)),0,0,'R',$fill);
142 $side=" = ";
143 if ( $sum_solde > 0 )
144 {
145 $side='Deb.';
146 }
147 else if ( $sum_solde < 0)
148 {
149 $side='Cred.';
150 }
151
152 $pdf->write_cell(20,7,$side,0,0,'C',$fill);
153 $pdf->line_new();
154 }
155}
156else
157{
158 // History
159 // all card
160 if ($allcard == 1)
161 {
162 $afiche = $cn->get_array("select fd_id from vw_fiche_def where ad_id=" . ATTR_DEF_ACCOUNT . " order by fd_label asc");
163 }
164 else
165 {
166 $afiche[0] = array('fd_id' => $http->request('cat'));
167 }
168 $fic=new Fiche($cn);
169 for ($e = 0; $e < count($afiche); $e++)
170 {
171 $array = Fiche::get_fiche_def($cn,$afiche[$e]['fd_id'] , 'name_asc');
172 /*
173 * You show now the result
174 */
175 if ($array == null)
176 {
177 continue;
178 }
179 $tab = array(12, 20, 20,68, 20, 20, 10, 20);
180 $align = array('L', 'C', 'L', 'L', 'R','R', 'R', 'R');
181
182 foreach ($array as $row_fiche)
183 {
184 $fic = new Fiche($cn, $row_fiche['f_id']);
186 $letter->set_parameter('quick_code', $fic->get_attribute(ATTR_DEF_QUICKCODE));
187 $letter->set_parameter('start',$http->request('start'));
188 $letter->set_parameter('end',$http->request('end'));
189 // all
190 if ($histo == 0)
191 {
192 $letter->get_all();
193 }
194
195 // lettered
196 if ($histo == 1)
197 {
198 $letter->get_letter();
199 }
200 // unlettered
201 if ($histo == 2)
202 {
203 $letter->get_unletter();
204 }
205 if ($histo == 6)
206 {
207 $letter->get_letter_diff();
208 }
209 /* skip if nothing to display */
210 if (count($letter->content) == 0)
211 continue;
212 $pdf->SetFont('DejaVuCond', '', 10);
213 $fiche = new Fiche($cn, $row_fiche['f_id']);
214 $pdf->write_cell(0, 7, $fiche->get_attribute(ATTR_DEF_NAME)." [".$fiche->get_attribute(ATTR_DEF_QUICKCODE).":".$fiche->get_attribute(ATTR_DEF_ACCOUNT)."]", 1, 'C');
215
216 $pdf->SetFont('DejaVuCond', '', 7);
217 $pdf->line_new();
218 $pdf->write_cell($tab[0], 7, 'Date');
219 $pdf->write_cell($tab[1], 7, 'ref');
220 $pdf->write_cell($tab[2], 7, 'Internal');
221 $pdf->write_cell($tab[3], 7, 'Comm');
222 $pdf->write_cell($tab[4], 7, 'Montant', 0, 0, 'C');
223 $pdf->write_cell($tab[5], 7, 'Prog.', 0, 0, 'R');
224 $pdf->write_cell($tab[6], 7, 'Let.', 0, 0, 'R');
225 $pdf->write_cell($tab[7], 7, 'Diff. Let.', 0, 0, 'R');
226 $pdf->line_new();
227
228 $amount_deb = 0;
229 $amount_cred = 0;
230 $prog=0;
231 for ($i = 0; $i < count($letter->content); $i++)
232 {
233 $fill=$pdf->is_fill($i);
234 $pdf->SetFont('DejaVuCond', '', 7);
235 $row = $letter->content[$i];
236 $str_date = shrink_date($row['j_date_fmt']);
237
238 $pdf->write_multi($tab[0], 3, $str_date, 0, $align[0], $fill);
239 $pdf->write_cell($tab[1], 4, $row['jr_pj_number'], 0, 0, $align[1], $fill);
240 $pdf->write_multi($tab[2], 3, $row['jr_internal'], 0, $align[1], $fill);
241 $pdf->write_multi($tab[3], 3, $row['jr_comment'], 0, $align[2], $fill);
242 if ($row['j_debit'] == 't')
243 {
244 $prog=bcadd($prog,$row['j_montant']);
245 $pdf->write_cell($tab[4], 4, sprintf('%s D', nbm($row['j_montant'])), 0, 0, $align[4], $fill);
246 $amount_deb+=$row['j_montant'];
247 $str_prog=sprintf("%s %s",nbm(abs($prog)),$fic->get_amount_side($prog));
248 $pdf->write_cell($tab[5], 4, $str_prog, 0, 0, $align[5], $fill);
249 }
250 else
251 {
252 $prog=bcsub($prog,$row['j_montant']);
253 $pdf->write_cell($tab[4], 4, sprintf('%s C', nbm($row['j_montant'])), 0, 0, $align[4], $fill);
254 $amount_cred+=$row['j_montant'];
255 $str_prog=sprintf("%s %s",nbm(abs($prog)),$fic->get_amount_side($prog));
256 $pdf->write_cell($tab[5], 4, $str_prog, 0, 0, $align[5], $fill);
257 }
258 if ($row['letter'] != -1)
259 {
260 $pdf->write_cell($tab[6], 4, strtoupper(base_convert($row['letter'],10,36)), 0, 0, $align[6], $fill);
261 // get sum for this lettering
262
263 $pdf->write_cell($tab[7], 4, sprintf('%s', nbm($row['letter_diff'])), '0', '0', $align[7], $fill);
264 }
265 else
266 $pdf->write_cell($tab[6], 4, "", 0, 0, 'R', $fill);
267 $pdf->line_new();
268 }
269 $pdf->fill_row(1);
270 $pdf->SetFont('DejaVuCond', 'B', 8);
271 $debit = sprintf('Debit : %s', nbm($amount_deb));
272 $credit = sprintf('Credit : %s', nbm($amount_cred));
274 $s = 'solde débiteur';
275 else
276 $s = 'solde crediteur';
277 $solde = sprintf('%s : %s', $s, nbm(abs(round($amount_cred - $amount_deb, 2))));
278
279 $pdf->write_cell(0, 6, $debit, 0, 0, 'R');
280 $pdf->line_new(4);
281 $pdf->write_cell(0, 6, $credit, 0, 0, 'R');
282 $pdf->line_new(4);
283 $pdf->write_cell(0, 6, $solde, 0, 0, 'R');
284 $pdf->line_new(4);
285
286 $pdf->line_new();
287 }
288 }
289}
290//Save PDF to file
291$fDate=date('dmy-Hi');
292$pdf->Output("category-$fDate.pdf", 'D');
isDate($p_date)
Verifie qu'une date est bien formaté en d.m.y et est valable.
shrink_date($p_date)
shrink the date, make a date shorter for the printing
nbm($p_number, $p_dec=2)
format the number with a sep.
global $g_user
if no group available , then stop
_("actif, passif,charge,...")
$_GET['qcode']
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...
static get_fiche_def($p_cn, $card_category_id, $p_order='', $inactive=1)
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:223
const ATTR_DEF_QUICKCODE
Definition constant.php:244
const ATTR_DEF_ACCOUNT
Definition constant.php:222
for($e=0; $e< count($afiche); $e++) exit
$afiche[0]
$amount_cred
Definition letter_all.php:6
$amount_deb
Definition letter_all.php:6
$side