noalyss  Version-9
export_fiche_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
24  * of card
25  * @bug NOT USED MUST BE REMOVED
26  */
27 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
28 // Security we check if user does exist and his privilege
29 require_once NOALYSS_INCLUDE.'/lib/ac_common.php';
30 
31 /* Security */
34 $g_user->Check();
35 $g_user->check_dossier($gDossier);
36 
37 $pdf=new PDF($cn);
38 $pdf->setDossierInfo(" Periode : ".$_GET['start']." - ".$_GET['end']);
39 $pdf->AliasNbPages();
40 $pdf->AddPage();
41 $name=$cn->get_value('select fd_label from fiche_def where fd_id=$1',array($_GET['cat']));
42 $pdf->SetFont('DejaVu','BI',14);
43 $pdf->write_cell(0,8,$name,0,1,'C');
44 $pdf->SetTitle($name,1);
45 $pdf->SetAuthor('NOALYSS');
47 $start=$http->request('start');
48 $end=$http->request('end');
49 if ( isDate($start) == null || isDate ($end) == null ) return;
50 
51 /* balance */
52 if ( $_GET['histo'] == 4 )
53 {
54  $cat=$http->request('cat');
55  $fd=new Fiche_Def($cn,$cat);
56  if ( $fd->hasAttribute(ATTR_DEF_ACCOUNT) == false )
57  {
58  $pdf->write_cell(0,10, _("Cette catégorie n'ayant pas de poste comptable n'a pas de balance"));
59  //Save PDF to file
60  $fDate=date('dmy-Hi');
61  $pdf->Output("category-$fDate.pdf", 'D');
62  exit;
63  }
64  $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($cat));
65 
66  if ( empty($aCard))
67  {
68  $pdf->write_cell(0,10, _("Aucune fiche trouvée"));//Save PDF to file
69  $fDate=date('dmy-Hi');
70  $pdf->Output("category-$fDate.pdf", 'D');
71  exit;
72  }
73  $pdf->SetFont('DejaVuCond','',7);
74  $pdf->write_cell(30,7,'Quick Code',0,0,'L',0);
75  $pdf->write_cell(80,7,'Libellé',0,0,'L',0);
76  $pdf->write_cell(20,7,'Débit',0,0,'R',0);
77  $pdf->write_cell(20,7,'Crédit',0,0,'R',0);
78  $pdf->write_cell(20,7,'Solde',0,0,'R',0);
79  $pdf->write_cell(20,7,'D/C',0,0,'C',0);
80  $pdf->line_new();
81  $idx=0;
82  $filter= " (j_date >= to_date('".$start."','DD.MM.YYYY') ".
83  " and j_date <= to_date('".$end."','DD.MM.YYYY')) ";
84  for ($i=0;$i < count($aCard);$i++)
85  {
86  $oCard=new Fiche($cn,$aCard[$i]['f_id']);
87  $solde=$oCard->get_solde_detail($filter);
88  if ( $solde['debit'] == 0 && $solde['credit']==0) continue;
89 
90  if ( $idx % 2 == 0 )
91  {
92  $pdf->SetFillColor(220,221,255);
93  $fill=1;
94  }
95  else
96  {
97  $pdf->SetFillColor(0,0,0);
98  $fill=0;
99  }
100  $idx++;
101 
102  $pdf->write_cell(30,7,$oCard->strAttribut(ATTR_DEF_QUICKCODE),0,0,'L',$fill);
103  $pdf->write_cell(80,7,$oCard->strAttribut(ATTR_DEF_NAME),0,0,'L',$fill);
104  $pdf->write_cell(20,7,sprintf('%.02f',$solde['debit']),0,0,'R',$fill);
105  $pdf->write_cell(20,7,sprintf('%.02f',$solde['credit']),0,0,'R',$fill);
106  $pdf->write_cell(20,7,sprintf('%.02f',abs($solde['solde'])),0,0,'R',$fill);
107  $pdf->write_cell(20,7,(($solde['solde']<0)?'CRED':'DEB'),0,0,'C',$fill);
108  $pdf->line_new();
109  }
110 }
111 else
112 {
113  $array=Fiche::get_fiche_def($cn,$_GET['cat'],'name_asc');
114  /*
115  * You show now the result
116  */
117  if ($array == null )
118  {
119  exit();
120  }
121  $tab=array(13,25,55,20,20,12,20);
122  $align=array('L','L','L','R','R','R','R');
123 
124  foreach($array as $row_fiche)
125  {
126  $row=new Fiche($cn,$row_fiche['f_id']);
128  $letter->set_parameter('quick_code',$row->strAttribut(ATTR_DEF_QUICKCODE));
129  $letter->set_parameter('start',$_GET['start']);
130  $letter->set_parameter('end',$_GET['end']);
131  // all
132  if ( $_GET['histo'] == 0 )
133  {
134  $letter->get_all();
135  }
136 
137  // lettered
138  if ( $_GET['histo'] == 1 )
139  {
140  $letter->get_letter();
141  }
142  // unlettered
143  if ( $_GET['histo'] == 2 )
144  {
145  $letter->get_unletter();
146  }
147  /* skip if nothing to display */
148  if (count($letter->content) == 0 ) continue;
149  $pdf->SetFont('DejaVuCond','',10);
150  $fiche=new Fiche($cn,$row_fiche['f_id']);
151  $pdf->write_cell(0,7,$fiche->strAttribut(ATTR_DEF_NAME),1,1,'C');
152 
153  $pdf->SetFont('DejaVuCond','',7);
154 
155  $pdf->write_cell($tab[0],7,'Date');
156  $pdf->write_cell($tab[1],7,'ref');
157  $pdf->write_cell($tab[1],7,'Int.');
158  $pdf->write_cell($tab[2],7,'Comm');
159  $pdf->write_cell(40,7,'Montant',0,0,'C');
160  $pdf->write_cell($tab[5],7,'Let.',0,0,'R');
161  $pdf->write_cell($tab[6],7,'Som. Let.',0,0,'R');
162  $pdf->line_new();
163 
164  $amount_deb=0;
165  $amount_cred=0;
166  for ($i=0;$i<count($letter->content);$i++)
167  {
168  if ( $i % 2 == 0 )
169  {
170  $pdf->SetFillColor(220,221,255);
171  $fill=1;
172  }
173  else
174  {
175  $pdf->SetFillColor(0,0,0);
176  $fill=0;
177  }
178  $pdf->SetFont('DejaVuCond','',7);
179  $row=$letter->content[$i];
180  $str_date=shrink_date($row['j_date_fmt']);
181 
182  $pdf->write_cell($tab[0],4,$str_date,0,0,$align[0],$fill);
183  $pdf->write_cell($tab[1],4,$row['jr_pj_number'],0,0,$align[1],$fill);
184  $pdf->write_cell($tab[1],4,$row['jr_internal'],0,0,$align[1],$fill);
185  $pdf->write_cell($tab[2],4,$row['jr_comment'],0,0,$align[2],$fill);
186  if ( $row['j_debit'] == 't')
187  {
188  $pdf->write_cell($tab[3],4,sprintf('%10.2f',$row['j_montant']),0,0,$align[4],$fill);
189  $amount_deb+=$row['j_montant'];
190  $pdf->write_cell($tab[4],4,"",0,0,'C',$fill);
191  }
192  else
193  {
194  $pdf->write_cell($tab[3],4,"",0,0,'C',$fill);
195  $pdf->write_cell($tab[4],4,sprintf('%10.2f',$row['j_montant']),0,0,$align[4],$fill);
196  $amount_cred+=$row['j_montant'];
197  }
198  if ($row['letter'] != -1 )
199  {
200  $pdf->write_cell($tab[5],4,strtoupper(base_convert($row['letter'],10,36)),0,0,$align[5],$fill);
201  // get sum for this lettering
202  $sql="select sum(j_montant) from jrnx where j_debit=$1 and j_id in ".
203  " (select j_id from jnt_letter join letter_deb using (jl_id) where jl_id=$2 union ".
204  " select j_id from jnt_letter join letter_cred using (jl_id) where jl_id=$3)";
205  $sum=$cn->get_value($sql,array($row['j_debit'],$row['letter'],$row['letter']));
206  $pdf->write_cell($tab[6],4,sprintf('%.2f',$sum),'0','0','R',$fill);
207  }
208  else
209  $pdf->write_cell($tab[5],4,"",0,0,'R',$fill);
210  $pdf->line_new();
211  }
212  $pdf->SetFillColor(0,0,0);
213  $pdf->SetFont('DejaVuCond','B',8);
214  $debit =sprintf('Debit : % 12.2f',$amount_deb);
215  $credit=sprintf('Credit : % 12.2f',$amount_cred);
216  if ( $amount_deb>$amount_cred) $s='solde débiteur';
217  else $s='solde crediteur';
218  $solde =sprintf('%s : % 12.2f',$s,(abs(round($amount_cred-$amount_deb,2))));
219 
220  $pdf->write_cell(0,6,$debit,0,0,'R');
221  $pdf->line_new(4);
222  $pdf->write_cell(0,6,$credit,0,0,'R');
223  $pdf->line_new(4);
224  $pdf->write_cell(0,6,$solde,0,0,'R');
225  $pdf->line_new(4);
226 
227  $pdf->line_new();
228  }
229 }
230 //Save PDF to file
231 $fDate=date('dmy-Hi');
232 $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:825
global $g_user
if no group available , then stop
$idx
$input_from id
Definition: balance.inc.php:63
$filter
$_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:206
const ATTR_DEF_QUICKCODE
Definition: constant.php:227
const ATTR_DEF_ACCOUNT
Definition: constant.php:205
foreach($array as $row_fiche) $fDate
if($array==null) $tab
$amount_cred
Definition: letter_all.php:6
$amount_deb
Definition: letter_all.php:6