noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
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*/
31#[AllowDynamicProperties]
32class Print_Ledger extends PDF
33{
34 protected $filter_operation; //!< See Acc_Ledger_History::filter_operation
35
36 protected $ledger ; //!< concerned Ledger
37 protected $from ; //<! integer parm_periode.p_id , start periode;
38 protected $to ; //<! integer parm_periode.p_id , end periode;
39
40 /**************************************************************************
41 *internal variables for computing sum on PDF Listing
42 *************************************************************************/
43 protected $previous;//! $previous (array) see Acc_Ledger->previous_amount
44 protected $rap_htva; //!< $rap_htva (float) previous price w/o VAT
45 protected $rap_tvac; //!< $rap_tvac (float) previous amount
46 //All Tax Include (full price)
47 protected $rap_tva; //!< $rap_tva array(tva_id,amount)
48 protected $rap_priv; //!< $rap_priv (float) personal expense
49 protected $rap_other_tax; //!< $rap_other_tav, amount to report for other tax than VAT
50 protected $other_tax_previous;//! $other_tax_previous (array)
51 //see Acc_Ledger->previous_other_tax
52 protected $a_Tva; //!< $a_Tva array ( tva_id,tva_label,tva_poste ) of existing_vat
53 protected $jrn_type; //<! $jrn_type (string) 'VEN','ACH','ODS','FIN'
54 protected $rap_nd; //!< $rap_nd (float) $no-deductible tax
55 protected $rap_tva_np; //!< $rap_tva_np VAT not deductible
56
57 protected $flag_other_tax; //!< $flag_other_tax(bool) true if other tax exists
58 protected $tp_htva; //!< $tp_htva (float) total page price w/o VAT
59 protected $tp_tva; //!< $tp_tva (float) total page VAT
60 protected $tp_tvac; //!< $tp_tvac (float) total page full price All Tax Incl.
61 protected $tp_priv;//!< $tp_priv (float) total page personal expense
62 protected $tp_nd;//!< $tp_nd (float) total page price w/o VAT
63 protected $tp_tva_np;//!< $tp_tva_np (float) total page not deductible
64 protected $show_col;
65 protected $rap_other; //!< VAT when page starts
66
67 public function __construct(\Database $p_cn,
68 $orientation,
69 $unit,
70 $format,
71 Acc_Ledger $p_ledger,
72 $p_from,
73 $p_to,
74 $p_filter_operation)
75 {
76 parent::__construct($p_cn, $orientation, $unit, $format);
77 $this->ledger=$p_ledger;
78 $this->from=$p_from;
79 $this->to=$p_to;
80 $this->set_filter_operation($p_filter_operation);
81 }
82 public function get_ledger()
83 {
84 return $this->ledger;
85 }
86
87 public function get_from()
88 {
89 return $this->from;
90 }
91
92 public function get_to()
93 {
94 return $this->to;
95 }
96
97 public function set_ledger($ledger)
98 {
99 $this->ledger=$ledger;
100 return $this;
101 }
102
103 public function set_from($from)
104 {
105 $this->from=$from;
106 return $this;
107 }
108
109 public function set_to($to)
110 {
111 $this->to=$to;
112 return $this;
113 }
115 {
117 }
118 /**
119 * Filter the operations ,
120 * @param string $filter_operation : all , paid, unpaid
121 * @return $this
122 * @throws Exception 5 , if filter invalid
123 */
125 {
126 if (in_array($filter_operation,['all','paid','unpaid']))
127 {
128 $this->filter_operation=$filter_operation;
129 return $this;
130 }
131 throw new Exception(_("Filter invalide ".$filter_operation),5);
132 }
133 /**
134 * Create an object Print_Ledger* depending on $p_type_export ( 0 => accounting
135 * 1-> one row per operation 2-> detail of item)
136 * @param Database $cn
137 * @param char $p_type_export E(xtended) L(isting) A(ccounting) D(etail)
138 * @param Acc_Ledger $ledger
139 */
140 static function factory(Database $cn, $p_type_export, Acc_Ledger $p_ledger,$p_from,$p_to,$p_filter_operation)
141 {
142 /**
143 * @Bug
144 * Strange PHP Bug when autoloader is not used , the require_once doesn't seems to
145 * work properly and does not include the files , except if you put them here
146 *
147 * if you put them on the top of this file, export_ledger_pdf.php will include the files
148 * but not export_ledger_csv.php
149 */
150
151 /**
152 * For PDF output
153 */
154 switch ($p_type_export) {
155 case 'D':
157 $jrn_type=$p_ledger->get_type();
158 //---------------------------------------------
159 // Detailled Printing (accounting )
160 //---------------------------------------------
161 if ($jrn_type=='ACH'||$jrn_type=='VEN')
162 {
163 if (
164 ($jrn_type=='ACH'&&$cn->get_value('select count(qp_id) from quant_purchase')
165 ==0)||
166 ($jrn_type=='VEN'&&$cn->get_value('select count(qs_id) from quant_sold')
167 ==0)
168 )
169 {
170 $pdf=new Print_Ledger_Simple_without_vat($cn,
171 $p_ledger,$p_from,$p_to,$p_filter_operation);
172 $pdf->set_error(_('Ce journal ne peut être imprimé en mode simple'));
173 return $pdf;
174 }
175 if ($own->MY_TVA_USE=='Y')
176 {
177 $pdf=new Print_Ledger_Simple($cn, $p_ledger,$p_from,$p_to,$p_filter_operation);
178 return $pdf;
179 }
180 if ($own->MY_TVA_USE=='N')
181 {
182 $pdf=new Print_Ledger_Simple_without_vat($cn,
183 $p_ledger,$p_from,$p_to,$p_filter_operation);
184 return $pdf;
185 }
186 }
187 elseif ($jrn_type=='FIN')
188 {
189 $pdf=new Print_Ledger_Financial($cn, $p_ledger,$p_from,$p_to);
190 return $pdf;
191 } else
192 {
193 return new Print_Ledger_Detail($cn, $p_ledger,$p_from,$p_to);
194 }
195 break;
196
197 case 'L':
198 //----------------------------------------------------------------------
199 // Simple Printing Purchase Ledger
200 //---------------------------------------------------------------------
202 $jrn_type=$p_ledger->get_type();
203
204
205 if ($jrn_type=='ACH'||$jrn_type=='VEN')
206 {
207 if (
208 ($jrn_type=='ACH'&&$cn->get_value('select count(qp_id) from quant_purchase')
209 ==0)||
210 ($jrn_type=='VEN'&&$cn->get_value('select count(qs_id) from quant_sold')
211 ==0)
212 )
213 {
214 $pdf=new Print_Ledger_Simple_without_vat($cn,
215 $p_ledger,$p_from,$p_to,$p_filter_operation);
216 $pdf->set_error(_('Ce journal ne peut être imprimé en mode simple'));
217 return $pdf;
218 }
219 if ($own->MY_TVA_USE=='Y')
220 {
221 $pdf=new Print_Ledger_Simple($cn, $p_ledger,$p_from,$p_to,$p_filter_operation);
222 return $pdf;
223 }
224 if ($own->MY_TVA_USE=='N')
225 {
226 $pdf=new Print_Ledger_Simple_without_vat($cn,
227 $p_ledger,$p_from,$p_to,$p_filter_operation);
228 return $pdf;
229 }
230 }
231
232 if ($jrn_type=='FIN')
233 {
234 $pdf=new Print_Ledger_Financial($cn, $p_ledger,$p_from,$p_to);
235 return $pdf;
236 }
237 $pdf=new Print_Ledger_Misc($cn, $p_ledger,$p_from,$p_to);
238 return $pdf;
239 break;
240 case 'E':
241 /**********************************************************
242 * Print Detail Operation + Item
243 * ********************************************************* */
245 $jrn_type=$p_ledger->get_type();
246 if ($jrn_type=='FIN')
247 {
248 $pdf=new Print_Ledger_Detail($cn, $p_ledger,$p_from,$p_to);
249 return $pdf;
250 }
251 if ($jrn_type=='ODS'||$p_ledger->id==0)
252 {
253 $pdf=new Print_Ledger_Detail($cn, $p_ledger,$p_from,$p_to);
254 return $pdf;
255 }
256 if (
257 ($jrn_type=='ACH'&&$cn->get_value('select count(qp_id) from quant_purchase')
258 ==0)||
259 ($jrn_type=='VEN'&&$cn->get_value('select count(qs_id) from quant_sold')
260 ==0)
261 )
262 {
263 $pdf=new Print_Ledger_Simple_without_vat($cn, $p_ledger,$p_from,$p_to,$p_filter_operation);
264 $pdf->set_error('Ce journal ne peut être imprimé en mode simple');
265 return $pdf;
266 }
267 $pdf=new Print_Ledger_Detail_Item($cn, $p_ledger,$p_from,$p_to,$p_filter_operation);
268 return $pdf;
269 case 'A':
270 /***********************************************************
271 * Accounting
272 */
273 $pdf=new Print_Ledger_Detail($cn, $p_ledger,$p_from,$p_to);
274 return $pdf;
275 break;
276 } // end switch
277 }
278
279// end function
280 /**
281 * @brief find all the active ledger for the exerice of the periode
282 * and readable by the current user
283 * @global type $g_user
284 * @param int $get_from_periode
285 * @return array of ledger id
286 */
288 {
289 global $g_user;
290 $cn=Dossier::connect();
291 // Find periode
292 $periode=new Periode($cn, $get_from_periode);
293 $exercice=$periode->get_exercice($get_from_periode);
294
295 if ($g_user->Admin()==0&&$g_user->is_local_admin()==0&&$g_user->get_status_security_ledger()
296 ==1)
297 {
298 $sql="select jrn_def_id
299 from jrn_def join jrn_type on jrn_def_type=jrn_type_id
300 join user_sec_jrn on uj_jrn_id=jrn_def_id
301 where
302 uj_login=$1
303 and uj_priv in ('R','W')
304 and ( jrn_enable=1
305 or
306 exists (select 1 from jrn
307 where
308 jr_def_id=jrn_def_id
309 and jr_tech_per in (select p_id from parm_periode where p_exercice=$2)))
310 order by jrn_def_name
311 ";
312 $a_jrn=$cn->get_array($sql, array($g_user->login, $exercice));
313 }
314 else
315 {
316 $a_jrn=$cn->get_array("select jrn_def_id
317 from jrn_def join jrn_type on jrn_def_type=jrn_type_id
318 where
319 jrn_enable=1
320 or exists(select 1 from jrn
321 where
322 jr_def_id=jrn_def_id
323 and jr_tech_per in (select p_id from parm_periode where p_exercice=$1))
324 order by jrn_def_name
325 ", [$exercice]);
326 }
327 $a=[];
328 $nb_jrn=count($a_jrn);
329 for ($i=0; $i<$nb_jrn; $i++)
330 {
331 $a[]=$a_jrn[$i]['jrn_def_id'];
332 }
333 return $a;
334 }
335 /**
336 * Build a SQL clause to filter operation depending if they are paid, unpaid or no filter
337 * @return string SQL Clause
338 */
339 protected function build_filter_operation()
340 {
341 switch ($this->get_filter_operation())
342 {
343 case 'all':
344 $sql_filter="";
345 break;
346 case 'paid':
347 $sql_filter=" and (jr_date_paid is not null or jr_rapt ='paid' ) ";
348 break;
349 case 'unpaid':
350 $sql_filter=" and (jr_date_paid is null and coalesce(jr_rapt,'x') <> 'paid' ) ";
351 break;
352 default:
353 throw new Exception(_("Filtre invalide", 5));
354 }
355 return $sql_filter;
356 }
357}
358
359?>
global $g_user
if no group available , then stop
catch(Exception $e) $exercice
$anc_grandlivre to
$anc_grandlivre from
_("actif, passif,charge,...")
Class for jrn, class acc_ledger for manipulating the ledger AND some acc.
get_type()
Return the type of a ledger (ACH,VEN,ODS or FIN) or GL.
contains the class for connecting to Noalyss
Class to manage the company parameter (address, name...)
API for creating PDF, unicode, based on tfpdf.
Definition pdf.class.php:34
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.
$rap_other_tax
$rap_other_tav, amount to report for other tax than VAT
$previous
internal variables for computing sum on PDF Listing
$tp_tva_np
$tp_tva_np (float) total page not deductible
$flag_other_tax
$flag_other_tax(bool) true if other tax exists
$rap_tva_np
$rap_tva_np VAT not deductible
$tp_nd
$tp_nd (float) total page price w/o VAT
$rap_priv
$rap_priv (float) personal expense
$rap_other
VAT when page starts.
$filter_operation
See Acc_Ledger_History::filter_operation.
$rap_tvac
$rap_tvac (float) previous amount
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 ,.
$rap_nd
$rap_nd (float) $no-deductible tax
$tp_priv
$tp_priv (float) total page personal expense
$tp_tva
$tp_tva (float) total page VAT
__construct(\Database $p_cn, $orientation, $unit, $format, Acc_Ledger $p_ledger, $p_from, $p_to, $p_filter_operation)
$tp_tvac
$tp_tvac (float) total page full price All Tax Incl.
$rap_htva
$previous (array) see Acc_Ledger->previous_amount
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...
$tp_htva
$tp_htva (float) total page price w/o VAT
$a_Tva
$other_tax_previous (array)
$rap_tva
$rap_tva array(tva_id,amount)
$get_from_periode
if( $delta< 0) elseif( $delta==0)
$sql_filter
Definition preod.inc.php:43