noalyss Version-9
print_ledger.class.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * NOALYSS 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 * NOALYSS 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 NOALYSS; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/**
22 * Parent class for the print_ledger class
23 *
24 * @author danydb
25 */
26
27/**
28 * @brief Strategie class for the print_ledger class
29 *
30*/
31class Print_Ledger extends PDF
32{
33 protected $filter_operation; // See Acc_Ledger_History::filter_operation
34 private $ledger ; //!< concerned Ledger
35 private $from ; //! integer parm_periode.p_id , start periode;
36 private $to ; //! integer parm_periode.p_id , end periode;
37 public function __construct(\Database $p_cn,
38 $orientation,
39 $unit,
40 $format,
41 Acc_Ledger $p_ledger,
42 $p_from,
43 $p_to,
44 $p_filter_operation)
45 {
46 parent::__construct($p_cn, $orientation, $unit, $format);
47 $this->ledger=$p_ledger;
48 $this->from=$p_from;
49 $this->to=$p_to;
50 $this->set_filter_operation($p_filter_operation);
51 }
52 public function get_ledger()
53 {
54 return $this->ledger;
55 }
56
57 public function get_from()
58 {
59 return $this->from;
60 }
61
62 public function get_to()
63 {
64 return $this->to;
65 }
66
67 public function set_ledger($ledger)
68 {
69 $this->ledger=$ledger;
70 return $this;
71 }
72
73 public function set_from($from)
74 {
75 $this->from=$from;
76 return $this;
77 }
78
79 public function set_to($to)
80 {
81 $this->to=$to;
82 return $this;
83 }
85 {
87 }
88 /**
89 * Filter the operations ,
90 * @param string $filter_operation : all , paid, unpaid
91 * @return $this
92 * @throws Exception 5 , if filter invalid
93 */
95 {
96 if (in_array($filter_operation,['all','paid','unpaid']))
97 {
98 $this->filter_operation=$filter_operation;
99 return $this;
100 }
101 throw new Exception(_("Filter invalide ".$filter_operation),5);
102 }
103 /**
104 * Create an object Print_Ledger* depending on $p_type_export ( 0 => accounting
105 * 1-> one row per operation 2-> detail of item)
106 * @param Database $cn
107 * @param char $p_type_export E(xtended) L(isting) A(ccounting) D(etail)
108 * @param Acc_Ledger $ledger
109 */
110 static function factory(Database $cn, $p_type_export, Acc_Ledger $p_ledger,$p_from,$p_to,$p_filter_operation)
111 {
112 /**
113 * @Bug
114 * Strange PHP Bug when autoloader is not used , the require_once doesn't seems to
115 * work properly and does not include the files , except if you put them here
116 *
117 * if you put them on the top of this file, export_ledger_pdf.php will include the files
118 * but not export_ledger_csv.php
119 */
120
121 /**
122 * For PDF output
123 */
124 switch ($p_type_export) {
125 case 'D':
127 $jrn_type=$p_ledger->get_type();
128 //---------------------------------------------
129 // Detailled Printing (accounting )
130 //---------------------------------------------
131 if ($jrn_type=='ACH'||$jrn_type=='VEN')
132 {
133 if (
134 ($jrn_type=='ACH'&&$cn->get_value('select count(qp_id) from quant_purchase')
135 ==0)||
136 ($jrn_type=='VEN'&&$cn->get_value('select count(qs_id) from quant_sold')
137 ==0)
138 )
139 {
140 $pdf=new Print_Ledger_Simple_without_vat($cn,
141 $p_ledger,$p_from,$p_to,$p_filter_operation);
142 $pdf->set_error(_('Ce journal ne peut être imprimé en mode simple'));
143 return $pdf;
144 }
145 if ($own->MY_TVA_USE=='Y')
146 {
147 $pdf=new Print_Ledger_Simple($cn, $p_ledger,$p_from,$p_to,$p_filter_operation);
148 return $pdf;
149 }
150 if ($own->MY_TVA_USE=='N')
151 {
152 $pdf=new Print_Ledger_Simple_without_vat($cn,
153 $p_ledger,$p_from,$p_to,$p_filter_operation);
154 return $pdf;
155 }
156 }
157 elseif ($jrn_type=='FIN')
158 {
159 $pdf=new Print_Ledger_Financial($cn, $p_ledger,$p_from,$p_to);
160 return $pdf;
161 } else
162 {
163 return new Print_Ledger_Detail($cn, $p_ledger,$p_from,$p_to);
164 }
165 break;
166
167 case 'L':
168 //----------------------------------------------------------------------
169 // Simple Printing Purchase Ledger
170 //---------------------------------------------------------------------
172 $jrn_type=$p_ledger->get_type();
173
174
175 if ($jrn_type=='ACH'||$jrn_type=='VEN')
176 {
177 if (
178 ($jrn_type=='ACH'&&$cn->get_value('select count(qp_id) from quant_purchase')
179 ==0)||
180 ($jrn_type=='VEN'&&$cn->get_value('select count(qs_id) from quant_sold')
181 ==0)
182 )
183 {
184 $pdf=new Print_Ledger_Simple_without_vat($cn,
185 $p_ledger,$p_from,$p_to,$p_filter_operation);
186 $pdf->set_error(_('Ce journal ne peut être imprimé en mode simple'));
187 return $pdf;
188 }
189 if ($own->MY_TVA_USE=='Y')
190 {
191 $pdf=new Print_Ledger_Simple($cn, $p_ledger,$p_from,$p_to,$p_filter_operation);
192 return $pdf;
193 }
194 if ($own->MY_TVA_USE=='N')
195 {
196 $pdf=new Print_Ledger_Simple_without_vat($cn,
197 $p_ledger,$p_from,$p_to,$p_filter_operation);
198 return $pdf;
199 }
200 }
201
202 if ($jrn_type=='FIN')
203 {
204 $pdf=new Print_Ledger_Financial($cn, $p_ledger,$p_from,$p_to);
205 return $pdf;
206 }
207 $pdf=new Print_Ledger_Misc($cn, $p_ledger,$p_from,$p_to);
208 return $pdf;
209 break;
210 case 'E':
211 /**********************************************************
212 * Print Detail Operation + Item
213 * ********************************************************* */
215 $jrn_type=$p_ledger->get_type();
216 if ($jrn_type=='FIN')
217 {
218 $pdf=new Print_Ledger_Detail($cn, $p_ledger,$p_from,$p_to);
219 return $pdf;
220 }
221 if ($jrn_type=='ODS'||$p_ledger->id==0)
222 {
223 $pdf=new Print_Ledger_Detail($cn, $p_ledger,$p_from,$p_to);
224 return $pdf;
225 }
226 if (
227 ($jrn_type=='ACH'&&$cn->get_value('select count(qp_id) from quant_purchase')
228 ==0)||
229 ($jrn_type=='VEN'&&$cn->get_value('select count(qs_id) from quant_sold')
230 ==0)
231 )
232 {
233 $pdf=new Print_Ledger_Simple_without_vat($cn, $p_ledger,$p_from,$p_to,$p_filter_operation);
234 $pdf->set_error('Ce journal ne peut être imprimé en mode simple');
235 return $pdf;
236 }
237 $pdf=new Print_Ledger_Detail_Item($cn, $p_ledger,$p_from,$p_to,$p_filter_operation);
238 return $pdf;
239 case 'A':
240 /***********************************************************
241 * Accounting
242 */
243 $pdf=new Print_Ledger_Detail($cn, $p_ledger,$p_from,$p_to);
244 return $pdf;
245 break;
246 } // end switch
247 }
248
249// end function
250 /**
251 * @brief find all the active ledger for the exerice of the periode
252 * and readable by the current user
253 * @global type $g_user
254 * @param int $get_from_periode
255 * @return array of ledger id
256 */
258 {
259 global $g_user;
261 // Find periode
263 $exercice=$periode->get_exercice($get_from_periode);
264
265 if ($g_user->Admin()==0&&$g_user->is_local_admin()==0&&$g_user->get_status_security_ledger()
266 ==1)
267 {
268 $sql="select jrn_def_id
269 from jrn_def join jrn_type on jrn_def_type=jrn_type_id
270 join user_sec_jrn on uj_jrn_id=jrn_def_id
271 where
272 uj_login=$1
273 and uj_priv in ('R','W')
274 and ( jrn_enable=1
275 or
276 exists (select 1 from jrn
277 where
278 jr_def_id=jrn_def_id
279 and jr_tech_per in (select p_id from parm_periode where p_exercice=$2)))
280 order by jrn_def_name
281 ";
282 $a_jrn=$cn->get_array($sql, array($g_user->login, $exercice));
283 }
284 else
285 {
286 $a_jrn=$cn->get_array("select jrn_def_id
287 from jrn_def join jrn_type on jrn_def_type=jrn_type_id
288 where
289 jrn_enable=1
290 or exists(select 1 from jrn
291 where
292 jr_def_id=jrn_def_id
293 and jr_tech_per in (select p_id from parm_periode where p_exercice=$1))
294 order by jrn_def_name
295 ", [$exercice]);
296 }
297 $a=[];
298 $nb_jrn=count($a_jrn);
299 for ($i=0; $i<$nb_jrn; $i++)
300 {
301 $a[]=$a_jrn[$i]['jrn_def_id'];
302 }
303 return $a;
304 }
305 /**
306 * Build a SQL clause to filter operation depending if they are paid, unpaid or no filter
307 * @return string SQL Clause
308 */
309 protected function build_filter_operation()
310 {
311 switch ($this->get_filter_operation())
312 {
313 case 'all':
314 $sql_filter="";
315 break;
316 case 'paid':
317 $sql_filter=" and (jr_date_paid is not null or jr_rapt ='paid' ) ";
318 break;
319 case 'unpaid':
320 $sql_filter=" and (jr_date_paid is null and coalesce(jr_rapt,'x') <> 'paid' ) ";
321 break;
322 default:
323 throw new Exception(_("Filtre invalide", 5));
324 }
325 return $sql_filter;
326 }
327}
328
329?>
global $g_user
if no group available , then stop
catch(Exception $e) $exercice
$anc_grandlivre to
$anc_grandlivre from
get_type()
Return the type of a ledger (ACH,VEN,ODS or FIN) or GL.
contains the class for connecting to Noalyss
static connect()
Class to manage the company parameter (address, name...)
API for creating PDF, unicode, based on tfpdf.
Definition: pdf.class.php:34
$own
Definition: pdf.class.php:36
For the periode tables parm_periode and jrn_periode.
Print detail of operation PURCHASE or SOLD plus the items There is no report of the different amounts...
this class extends PDF and let you export the detailled printing of any ledgers
print a listing of financial
print a listing of Miscelleaneous operation
this class extends PDF and let you export the detailled printing of any ledgers
Parent class for the print_ledger class.
$to
integer parm_periode.p_id , start periode;
static factory(Database $cn, $p_type_export, Acc_Ledger $p_ledger, $p_from, $p_to, $p_filter_operation)
Create an object Print_Ledger* depending on $p_type_export ( 0 => accounting 1-> one row per operatio...
build_filter_operation()
Build a SQL clause to filter operation depending if they are paid, unpaid or no filter.
$ledger
concerned Ledger
set_filter_operation($filter_operation)
Filter the operations ,.
__construct(\Database $p_cn, $orientation, $unit, $format, Acc_Ledger $p_ledger, $p_from, $p_to, $p_filter_operation)
integer parm_periode.p_id , end periode;
static available_ledger($get_from_periode)
find all the active ledger for the exerice of the periode and readable by the current user @global ty...
$jrn_type[]
$get_from_periode
if( $delta< 0) elseif( $delta==0)
$sql_filter
Definition: preod.inc.php:43