noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
acc_account_ledger.class.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// Copyright Author Dany De Bontridder danydb@aevalys.eu
20/*! \file
21 * \brief Manage the account
22 */
23/*!
24 * \brief Manage the account from the table jrn, jrnx or tmp_pcmn
25 */
26
28{
29 var $db; /*!< $db database connection */
30 var $id; /*!< $id poste_id (pcm_val)*/
31 var $label; /*!< $label label of the poste */
32 var $parent; /*!< $parent parent account */
33 var $row; /*!< $row double array see get_row */
34 var $tot_deb; /*!< value set by get_row */
35 var $tot_cred; /*!< value by get_row */
36 var $name;
37
38 function __construct ($p_cn,$p_id)
39 {
40 $this->db=$p_cn;
41 $this->id=$p_id;
42 }
43 /**
44 *@brief get the row thanks the resource
45 *@return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
46 * (tot_deb,tot_credit)
47 * @deprecated since version 6920
48 */
49 private function get_row_sql_deprecated($Res)
50 {
51 $array=array();
52 $tot_cred=0.0;
53 $tot_deb=0.0;
55 if ( $Max == 0 ) return null;
56 for ($i=0;$i<$Max;$i++)
57 {
59 if ($array[$i]['j_debit']=='t')
60 {
61 $tot_deb+=$array[$i]['deb_montant'] ;
62 }
63 else
64 {
65 $tot_cred+=$array[$i]['cred_montant'] ;
66 }
67 }
68 $this->row=$array;
69 $this->tot_deb=$tot_deb;
70 $this->tot_cred=$tot_cred;
71 return array($array,$tot_deb,$tot_cred);
72
73 }
74 /*!
75 * \brief Get data for accounting entry between 2 periode
76 *
77 * \param $p_from periode from
78 * \param $p_to end periode
79 * \return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
80 * (tot_deb,tot_credit
81 *
82 */
83 function get_row($p_from,$p_to)
84 {
85 $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','jr_tech_per');
86
87 $this->row=$this->db->get_array("select distinct j_id,jr_id,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_date,".
88 "case when j_debit='t' then j_montant else 0 end as deb_montant,".
89 "case when j_debit='f' then j_montant else 0 end as cred_montant,".
90 " jr_comment as description,jrn_def_name as jrn_name,".
91 "j_debit, jr_internal,jr_pj_number ".
92 ",oc_amount,oc_vat_amount".
93 " from jrnx left join jrn_def on jrn_def_id=j_jrn_def ".
94 " left join operation_currency using (j_id) ".
95 " left join jrn on jr_grpt_id=j_grpt".
96 " where j_poste=$1 and $periode ".
97 " order by j_date",array($this->id));
98 $res_saldo = $this->db->exec_sql(
99 "select sum(deb_montant),sum(cred_montant) from
100 (select case when j_debit='t' then j_montant else 0 end as deb_montant,
101 case when j_debit='f' then j_montant else 0 end as cred_montant
102 from jrnx
103 left join jrn_def
104 on jrn_def_id=j_jrn_def
105 left join jrn on jr_grpt_id=j_grpt
106 where j_poste=$1 and $periode ) as m
107 ",array($this->id));
108 $this->tot_deb=$this->tot_cred=0;
109
110 if ( Database::num_row($res_saldo) > 0 ) {
111 $this->tot_deb=Database::fetch_result($res_saldo, 0, 0);
112 $this->tot_cred=Database::fetch_result($res_saldo, 0, 1);
113 }
114 return array($this->row,$this->tot_deb,$this->tot_cred);
115 }
116 /**
117 * @brief build the SQL for get_row_data
118 * @param $p_from date d.m.Y start date
119 * @param $p_to date d.m.Y until date
120 * @param $sql_let sql string for getting lettering info
121 * @param $filter_sql string SQL for filtering the ledgers , to respect security on ledgers
122 * @return sql SELECT
123 */
124 function make_sql_accounting_detail($p_from,$p_to,$sql_let,$filter_sql)
125 {
126
127 $sql = "
128 with sqlletter as (select j_id,jl_id from letter_cred union all select j_id , jl_id from letter_deb )
129 select j1.j_id,jr_id,to_char(j_date,'DD.MM.YYYY') as j_date_fmt,j_date,
130 j_qcode
131 ,case when j_debit='t' then j_montant else 0 end as deb_montant,
132 case when j_debit='f' then j_montant else 0 end as cred_montant,
133 case when j_text is null or j_text = '' then jr_comment
134 else jr_comment||' '||j_text end
135 as description,jrn_def_name as jrn_name,
136 j_debit, jr_internal,jr_pj_number
137 ,(select distinct jl_id from sqlletter where sqlletter.j_id=j1.j_id ) as letter
138 ,pcm_lib
139 ,jr_optype
140 ,jr_tech_per
141 ,p_exercice
142 ,jrn_def_name
143 ,jrn_def_code
144 ,(with cred as (select jl_id, sum(j_montant) as amount_cred from letter_cred left join jrnx using (j_id) group by jl_id )
145 , deb as (select jl_id, sum(j_montant) as amount_deb from letter_deb left join jrnx using (j_id) group by jl_id )
146 select amount_deb-amount_cred
147 from
148 cred
149 full join deb using (jl_id) where jl_id=(select distinct jl_id from sqlletter where sqlletter.j_id=j1.j_id )) as delta_letter
150 ,jrn.currency_rate
151 ,jrn.currency_rate_ref
152 ,jrn.currency_id
153 ,(select cr_code_iso from currency where id=jrn.currency_id) as cr_code_iso
154 ,j_montant
155 ,oc_amount
156 ,oc_vat_amount ,
157 case when exists(select 1 from operation_analytique oa where j1.j_id=oa.j_id) then 1 else 0 end as op_analytic
158 from jrnx as j1
159 left join operation_currency as va on (j1.j_id = va.j_id )
160 join jrn_def on (jrn_def_id=j_jrn_def )
161 join jrn on (jr_grpt_id=j_grpt)
162 join tmp_pcmn on (j1.j_poste=pcm_val)
163 join parm_periode on (p_id=jr_tech_per)
164 where j1.j_poste=$1 and
165 ( to_date($2,'DD.MM.YYYY') <= j_date and
166 to_date($3,'DD.MM.YYYY') >= j_date )
167 and $filter_sql $sql_let
168 order by j_date,substring(jr_pj_number,'[0-9]+$') asc";
169 return $sql;
170 }
171
172 /**
173 * @brief make the SQL for the balanced accounting
174 * @param $filter filter to respect the security on ledger
175 * @return sql SELECT
176 */
178 {
179 $bal_sql="select sum(amount_deb) as s_deb,sum(amount_cred) as s_cred, j_poste
180 from
181 (select case when j_debit='t' then j_montant else 0 end as amount_deb,
182 case when j_debit='f' then j_montant else 0 end as amount_cred,
183 j_poste
184 from jrnx join jrn on (j_grpt = jr_grpt_id)
185 where
186 j_poste=$1 and
187 $filter and
188 ( to_date($2,'DD.MM.YYYY') <= j_date and
189 to_date($3,'DD.MM.YYYY') >= j_date )) as signed_amount
190 group by j_poste
191 ";
192 return $bal_sql;
193 }
194
195 /**
196 * @brief make the SQL for the balance of an accounting
197 * @param $filter_sql filter to respect the security on ledger
198 * @param $sql_let string for getting lettering info
199 * @return sql SELECT
200 *
201 */
202 public function make_sql_saldo_account($filter_sql,$sql_let)
203 {
204 $sql_saldo="select sum(deb_montant) as deb,sum(cred_montant) as cred
205 from
206 (select case when j_debit='t' then j_montant else 0 end as deb_montant,
207 case when j_debit='f' then j_montant else 0 end as cred_montant
208 from jrnx j1
209 join jrn_def on (jrn_def_id=j_jrn_def )
210 join jrn on (jr_grpt_id=j_grpt)
211 join tmp_pcmn on (j_poste=pcm_val)
212 join parm_periode on (p_id=jr_tech_per)
213 where j_poste=$1 and
214 ( to_date($2,'DD.MM.YYYY') <= j_date and
215 to_date($3,'DD.MM.YYYY') >= j_date )
216 and $filter_sql $sql_let ) as m";
217 return $sql_saldo;
218 }
219 /*!
220 * \brief Get data for accounting entry between 2 date
221 *
222 *\param $p_from date from DD.MM.YYYY
223 *\param $p_to end date DD.MM.YYYY
224 *\param $let 0 means all rows, 1 only lettered, 2 only unlettered
225 *\param $solded 0 means all account, 1 means only accounts with a saldo <> 0
226 *\note the data are filtered by the access of the current user
227 * \return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal)
228 * (tot_deb,tot_credit
229 *
230 */
231 function get_row_date($p_from, $p_to, $let = 0, $solded = 0)
232 {
233 global $g_user;
234 $filter_sql = $g_user->get_ledger_sql('ALL', 3);
235 $sql_let = '';
236 switch ($let) {
237 case 0:
238 break;
239 case 1:
240 $sql_let = ' and j1.j_id in (select j_id from letter_cred union all select j_id from letter_deb)';
241 break;
242 case '2':
243 $sql_let = ' and j1.j_id not in (select j_id from letter_cred union all select j_id from letter_deb) ';
244 break;
245 }
246 // if accounting is balanced , D = C then returns an empty array
247 if ($solded == 1) {
248 if ($this->db->is_prepare("not_balanced_account") == false) {
249 $filter=noalyss_str_replace('jrn_def_id','jr_def_id',$filter_sql);
250 $sql_balanced = $this->make_sql_not_balanced_account($filter);
251 $this->db->prepare("not_balanced_account", $sql_balanced);
252 }
253
254 $ret_balanced = $this->db->execute("not_balanced_account", array($this->id, $p_from, $p_to));
255
256 $r = Database::fetch_all($ret_balanced);
257 if (empty($r)) return array();
258 if ($r[0]['s_deb'] == $r[0]['s_cred']) return array();
259 }
260
261 // get the detail of accouting
262 if (!$this->db->is_prepare("sql_accounting_detail")) {
263 $sql = $this->make_sql_accounting_detail($p_from, $p_to, $sql_let, $filter_sql);
264 $this->db->prepare("sql_accounting_detail", $sql);
265
266 }
267 $ret = $this->db->execute("sql_accounting_detail", array($this->id, $p_from, $p_to));
268 $this->row = Database::fetch_all($ret);
269
270 // $this->row=$this->db->get_array(,array($this->id,$p_from,$p_to));
271 if ($this->db->is_prepare("saldo_account") == false) {
272 $sql_saldo = $this->make_sql_saldo_account($filter_sql, $sql_let);
273 $this->db->prepare("saldo_account", $sql_saldo);
274 }
275 $res_saldo = $this->db->execute("saldo_account", array($this->id, $p_from, $p_to));
276 $result=Database::fetch_all($res_saldo);
277 $this->tot_deb = $this->tot_cred = 0;
278
279 if (! empty($result) > 0) {
280 $this->tot_deb = $result[0]['deb'];
281 $this->tot_cred = $result[0]['cred'];
282 }
283 return array($this->row, $this->tot_deb, $this->tot_cred);
284 }
285
286
287 /*!\brief Return the name of a account
288 * it doesn't change any data member
289 * \return string with the pcm_lib
290 */
291 function get_name()
292 {
293 $ret=$this->db->exec_sql(
294 "select pcm_lib from tmp_pcmn where
295 pcm_val=$1",array($this->id));
296 if ( Database::num_row($ret) != 0)
297 {
299 $this->name=$r['pcm_lib'];
300 }
301 else
302 {
303 $this->name=_("Poste inconnu");
304 }
305 return $this->name;
306 }
307 /*!
308 * \brief Return the type of a account
309 * \returns string ACT,ACTINV,CHA,CHAINV,CON,PAS,PRO
310 */
311 function get_type()
312 {
313 $type=$this->db->get_value(
314 "select pcm_type from tmp_pcmn where
315 pcm_val=$1",array($this->id));
316 return $type;
317 }
318
319 /*!\brief check if the poste exist in the tmp_pcmn
320 *\return the number of line (normally 1 or 0)
321 */
322 function do_exist()
323 {
324 $sql="select pcm_val from tmp_pcmn where pcm_val= $1";
325 $ret=$this->db->exec_sql($sql,array($this->id));
326 return Database::num_row($ret) ;
327 }
328 /*!\brief Get all the value for this object from the database
329 * the data member are set
330 * \return false if this account doesn't exist otherwise true
331 */
332 function load():bool
333 {
334 $ret=$this->db->exec_sql("select pcm_lib,pcm_val_parent from
335 tmp_pcmn where pcm_val=$1",array($this->id));
337
338 if ( ! $r ) return false;
339 $this->label=$r[0]['pcm_lib'];
340 $this->parent=$r[0]['pcm_val_parent'];
341 return true;
342
343 }
344
345
346 /*!
347 * \brief give the balance of an account
348 * \param $p_cond (text) a SQL Condition,
349 * \return
350 * balance of the account
351 *
352 */
353 function get_solde($p_cond=" true ")
354 {
355 if (DEBUGNOALYSS > 1 ) { echo __CLASS__.".".__FUNCTION__."p_cond {$p_cond}"; }
356
357 $Res=$this->db->exec_sql("select sum(deb) as sum_deb, sum(cred) as sum_cred from
358 ( select j_poste,
359 case when j_debit='t' then j_montant else 0 end as deb,
360 case when j_debit='f' then j_montant else 0 end as cred
361 from jrnx join tmp_pcmn on j_poste=pcm_val
362 where
363 j_poste::text like ('$this->id'::text) and
364 $p_cond
365 ) as m ");
366 if (DEBUGNOALYSS > 1 ) { echo $this->db->get_sql(); }
368 if ($Max==0) return 0;
370
371 return abs($r['sum_deb']-$r['sum_cred']);
372 }
373 /*!
374 * \brief give the balance of an account
375 * \return
376 * balance of the account
377 *
378 */
379 function get_solde_detail($p_cond="")
380 {
381 if ( $p_cond != "") $p_cond=" and ".$p_cond;
382
383 $sql="select sum(deb) as sum_deb, sum(cred) as sum_cred from
384 ( select j_poste,
385 case when j_debit='t' then j_montant else 0 end as deb,
386 case when j_debit='f' then j_montant else 0 end as cred
387 from jrnx
388 where
389 j_poste::text like ('$this->id'::text)
390 $p_cond
391 ) as m ";
392 if (DEBUGNOALYSS > 1 ) { tracedebug("impress.debug.log", "$sql", 'acc_account_ledger:get_solde_detail'); }
393 $Res=$this->db->exec_sql($sql);
395
396 if ($Max==0)
397 {
398 return array('debit'=>0,
399 'credit'=>0,
400 'solde'=>0) ;
401 }
403// if p_start is < p_end the query returns null to avoid any problem
404// we set it to 0
405 if ($r['sum_deb']=='')
406 $r['sum_deb']=0.0;
407 if ($r['sum_cred']=='')
408 $r['sum_cred']=0.0;
409
410 return array('debit'=>$r['sum_deb'],
411 'credit'=>$r['sum_cred'],
412 'solde'=>abs(bcsub($r['sum_deb'],$r['sum_cred'],2)));
413 }
414 /*!
415 * \brief isTva tell is a poste is used for VAT
416 * \param none
417 *
418 *
419 * \return 1 is Yes otherwise 0
420 */
421 function isTVA()
422 {
423 // Load TVA array
424 $a_TVA=$this->db->get_array('select tva_poste
425 from tva_rate');
426 foreach ( $a_TVA as $line_tva)
427 {
428 if ( $line_tva['tva_poste'] == '' )
429 continue;
430 list($tva_deb,$tva_cred)=explode(',',$line_tva['tva_poste']);
431 if ( $this->id == $tva_deb ||
432 $this->id == $tva_cred )
433 {
434 return 1;
435 }
436 }
437 return 0;
438
439 }
440
441 /*!
442 * \brief HtmlTable, display a HTML of a poste for the asked period
443 * \param $p_array array for filter
444 * \param $let lettering of operation 0
445 * \return -1 if nothing is found otherwise 0
446 */
447 function HtmlTable($p_array=null,$let=0 , $from_div=0)
448 {
449
450 if ( $p_array==null)$p_array=$_REQUEST;
451 global $g_parameter;
452 $this->get_name();
453 list($array,$tot_deb,$tot_cred)=$this->get_row_date( $p_array['from_periode'],
454 $p_array['to_periode'],$let
455 );
456
457 if ( count($this->row ) == 0 )
458 return -1;
459
460 $rep="";
461
462 $type =$this->get_type();
463 // label warning if the saldo is incorrect
464 $label="";
465 if (in_array($type,array('CHA','ACT','PASINV','PROINV')) && $tot_deb<$tot_cred)
466 {
467
468 $label.=_("Solde créditeur au lieu de débiteur").'<span class="icon">&#xe80e;</span>';
469 }
470 if (in_array($type,array('PRO','PAS','ACTINV','CHAINV')) && $tot_deb>$tot_cred)
471 {
472
473 $label.=_("Solde débiteur au lieu de créditeur")." ".'<span class="icon">&#xe80e;</span>';
474 }
475 if ( $label !="" )
476 echo '<span class="notice" >'.$label.'</span>';
477
478 if ( $from_div == 1)
479 echo "<TABLE id=\"tbpopup\" class=\"resultfooter\" style=\"border-collapse:separate;margin:1%;width:98%;\">";
480 else
481 echo "<TABLE id=\"tb".$from_div."\" class=\"resultfooter\" style=\"border-collapse:separate;margin:1%;width:98%;\">";
482 echo '<tbody>';
483 echo "<TR>".
484 "<TH style=\"text-align:left\">"._('Date')." </TH>".
485 "<TH style=\"text-align:left\">"._('Pièce')." </TH>".
486 "<TH style=\"text-align:left\">"._('Code')."</TH>".
487 "<TH style=\"text-align:left\">"._('Interne')." </TH>".
488 "<TH class=\"visible_gt800\" style=\"text-align:left\">"._('Tiers')." </TH>".
489 "<TH class=\"visible_gt800\" style=\"text-align:left\">"._('Description')."</TH>".
490 "<TH class=\"visible_gt800\" style=\"text-align:left\">"._('Type')."</TH>".
491 "<TH class=\"visible_gt800\" style=\"text-align:left\">"._('ISO')."</TH>".
492 "<TH class=\"visible_gt800\" style=\"text-align:right\">"._('Dev.')."</TH>".
493 "<TH style=\"text-align:right\">"._('Débit')."</TH>".
494 "<TH style=\"text-align:right\">"._("Crédit")."</TH>".
495 th('Prog.','style="text-align:right"').
496 th('Let.',' class="visible_gt800" '.'style="text-align:right"');
497 "</TR>"
498 ;
499 $progress=0;$sum_deb=0;$sum_cred=0;
500 bcscale(2);
501 $old_exercice="";
502 $idx=0;
503 $operation=new Acc_Operation($this->db);
504 foreach ( $this->row as $op )
505 {
506
507 $tiers=$operation->find_tiers($op['jr_id'],$op['j_id'],$op['j_qcode']);
508
509
510 $vw_operation = sprintf('<A class="detail" style="text-decoration:underline;color:red" HREF="javascript:modifyOperation(\'%s\',\'%s\')" >%s</A>', $op['jr_id'], dossier::id(), $op['jr_internal']);
511 $let = '';
512 $html_let = "";
513 if ($op['letter'] != 0)
514 {
515 $let = strtoupper(base_convert($op['letter'], 10, 36));
516 $html_let = HtmlInput::show_reconcile($from_div, $let);
517 if ( $op['delta_letter'] != 0) $html_let='<img src="image/warning.png" onmouseover="displayBulle(\'delta = '.$op['delta_letter'].'\')" onmouseleave="hideBulle()" style="height:12px"/>'.$html_let;
518 }
519 $tmp_diff=bcsub($op['deb_montant'],$op['cred_montant']);
520
521 /*
522 * reset prog. balance to zero if we change of exercice
523 */
524 if ($old_exercice != $op['p_exercice']) {
525 if ($old_exercice != '') {
526 $progress = bcsub($sum_deb, $sum_cred);
527 $side = "&nbsp;" . $this->get_amount_side($progress);
528 echo "<TR class=\"highlight\">" .
529 td($op['p_exercice']) .
530 td("", ' class="visible_gt800" ') .
531 td("", ' class="visible_gt800" ') .
532 td("", ' class="visible_gt800" ') .
533 td("", ' class="visible_gt800" ') .
534 td("", ' class="visible_gt800" ') .
535 td() .
536 "<TD >Totaux</TD>" . td("") .
537 "<TD style=\"text-align:right\">" . nbm($sum_deb) . "</TD>" .
538 "<TD style=\"text-align:right\">" . nbm($sum_cred) . "</TD>" .
539 td(nbm(abs($progress)).$side,'style="text-align:right;padding-left:10px;"').
540 td("", ' class="visible_gt800" ') .
541 "</TR>";
542
543
544 $sum_cred = 0;
545 $sum_deb = 0;
546 $progress = 0;
547 }
548 }
549 $progress=bcadd($progress,$tmp_diff);
550 $side="&nbsp;".$this->get_amount_side($progress);
551 $sum_cred=bcadd($sum_cred,$op['cred_montant']);
552 $sum_deb=bcadd($sum_deb,$op['deb_montant']);
553 $class=($idx%2 == 0)?'class="odd"':$class=' class="even"';
554 $idx++;
555 $op_analytic=($op['op_analytic']==1)?'<span style="float:right;background:black;color:white;">&ni;</span>':'';
556 echo "<TR $class name=\"tr_" . $let . "_" . $from_div . "\">" .
557 "<TD>".smaller_date(format_date($op['j_date']))."</TD>".
558 td(h($op['jr_pj_number'])).
559 "<TD>".\HtmlInput::card_detail($op['j_qcode'])."</TD>".
560 "<TD>".$vw_operation."</TD>".
561 "<TD class=\"visible_gt800\" >".$tiers."</TD>".
562 "<TD class=\"visible_gt800\" >".h($op['description']).$op_analytic."</TD>".
563 td($op['jr_optype'],' class="visible_gt800" ');
564 /// If the currency is not the default one , then show the amount
565 if ( $op['currency_id'] > 0 )
566 {
567 // some amount are not directly recorded into operation_currency, like VAT
568 $currency_val=($op['oc_amount'] == 0)?round(bcmul ($op['j_montant'],$op['currency_rate']),2):$op['oc_amount'] ;
569
570 echo td($op['cr_code_iso']).
571 td(nbm($currency_val,2),'style="text-align:right;padding-left:10px;"');
572 } else {
573 echo td('', 'class="visible_gt800" ').td('',' class="visible_gt800"' );
574 }
575
576 echo
577 "<TD style=\"text-align:right;padding-left:10px;\">".nbm($op['deb_montant'])."</TD>".
578 "<TD style=\"text-align:right;padding-left:10px;\">".nbm($op['cred_montant'])."</TD>".
579 td(nbm(abs($progress)).$side,'style="text-align:right"').
580
581 td($html_let, ' class="visible_gt800" '.' style="color:red;text-align:right"') .
582 "</TR>";
583 $old_exercice=$op['p_exercice'];
584 }
585 echo '<tfoot>';
586 $solde_type=($sum_deb>$sum_cred)?_("solde débiteur"):_("solde créditeur");
587 $diff=bcsub($sum_deb,$sum_cred);
588 $side="&nbsp;".$this->get_amount_side($diff);
589 echo "<TR class=\"highlight\">".
590 td($op['p_exercice']).
591 td("",' class="visible_gt800" ').
592 td("",' class="visible_gt800" ').
593 td("",' class="visible_gt800" ').
594 td("",' class="visible_gt800" ').
595 td("",' class="visible_gt800" ').
596 td().
597 "<TD >Totaux</TD>".td("").
598 "<TD style=\"text-align:right\">".nbm($sum_deb)."</TD>".
599 "<TD style=\"text-align:right\">".nbm($sum_cred)."</TD>".
600 "<TD style=\"text-align:right\">".nbm(abs($diff)).$side."</TD>".
601 td("",' class="visible_gt800" ').
602 "</TR>";
603 echo "<tr style=\"font-weight:bold\"><TD>$solde_type</TD><td></td>".
604 "<TD style=\"text-align:right\">".nbm(abs($diff))."</TD>".
605 "</TR>";
606 // take saldo from 1st day until last
607 if ($g_parameter->MY_REPORT=='N') {
608 $solde_until_now=$this->get_solde_detail(" j_date <= to_date('{$p_array['to_periode']}','DD.MM.YYYY') ");
609 echo '<tr style="font-weight:bold;color:orangered">';
610 echo td(_("Solde global"));
611 echo td("D : ".nbm($solde_until_now['debit']),'class="num"');
612 echo td("C : ".nbm($solde_until_now['credit']),'class="num"');
613 echo td("Delta : ".nbm($solde_until_now['solde'])." ".$this->get_amount_side($solde_until_now['debit']-$solde_until_now['credit']),'class="num"');
614 echo '</tr>';
615
616 }
617 echo '</tfoot>';
618 echo '</tbody>';
619
620 echo "</table>";
621 if ( DEBUGNOALYSS>1) echo \Noalyss\Dbg::hidden_info("variable", get_defined_vars());
622 if ( DEBUGNOALYSS>1) echo \Noalyss\Dbg::hidden_info("this", $this);
623
624 return;
625 }
626 /**
627 * return the letter C if amount is > 0, D if < 0 or =
628 * @param type $p_amount
629 * @return string
630 */
631 function get_amount_side($p_amount)
632 {
633 if ($p_amount == 0)
634 return "=";
635 if ($p_amount < 0)
636 return "C";
637 if ($p_amount > 0)
638 return "D";
639 }
640 /*!
641 * \brief Display HTML Table Header (button)
642 *
643 * \return none
644 */
645 static function HtmlTableHeader($actiontarget="poste")
646 {
647 $http=new \HttpInput();
648 switch($actiontarget)
649 {
650 case 'poste':
651 $action_csv='CSV:postedetail';
652 $action_pdf='PDF:postedetail';
653 break;
654 case 'gl_comptes':
655 $action_csv='CSV:glcompte';
656 $action_pdf='PDF:glcompte';
657 break;
658 default:
659 throw new Exception(" Fonction HtmlTableHeader argument actiontarget invalid");
660 }
661 $hid=new IHidden();
662
663 echo "<table >";
664 echo '<TR>';
665 $str_ople=(isset($_REQUEST['ople']))?HtmlInput::hidden('ople',$http->request('ople')):'';
666 if ($actiontarget=='poste')
667 {
668 echo '<TD><form method="GET" ACTION="export.php">'.
669 dossier::hidden().
670 HtmlInput::submit('bt_other',"Autre poste").
671 $hid->input("type","poste").$hid->input('ac',$http->request('ac'))."</form></TD>";
672 }
673
674 $id=uniqid("pdf_");
675 echo '<TD><form method="GET" ACTION="export.php" '.
676 'id="'.$id.'" onsubmit="return download_document_form(\''.$id.'\')">'.
677 dossier::hidden().
678 HtmlInput::submit('bt_pdf',"Export PDF").
679 HtmlInput::hidden('act',$action_pdf).
680 $hid->input("type","poste").$str_ople.
681 $hid->input('p_action','impress').
682 $hid->input("from_periode",$http->request('from_periode')).
683 $hid->input("to_periode",$http->request('to_periode'))
684 ;
685
686 if ( isset($_REQUEST['letter'] )) echo HtmlInput::hidden('letter','2');
687 if ( isset($_REQUEST['solded'] )) echo HtmlInput::hidden('solded','1');
688
689 if (isset($_REQUEST['from_poste']))
690 echo HtmlInput::hidden('from_poste',$http->request('from_poste'));
691
692 if (isset($_REQUEST['to_poste']))
693 echo HtmlInput::hidden('to_poste',$http->request('to_poste'));
694
695 if (isset($_REQUEST['poste_id']))
696 echo HtmlInput::hidden("poste_id",$http->request('poste_id'));
697
698 if (isset($_REQUEST['poste_fille']))
699 echo $hid->input('poste_fille','on');
700 if (isset($_REQUEST['oper_detail']))
701 echo $hid->input('oper_detail','on');
702
703 echo "</form></TD>";
704 $id=uniqid("csv_");
705 echo '<TD><form method="GET" ACTION="export.php" id="'.$id.'" onsubmit="download_document_form(\''.$id.'\')">'.
706 dossier::hidden().
707 HtmlInput::submit('bt_csv',"Export CSV").
708 HtmlInput::hidden('act',$action_csv).
709 $hid->input("type","poste").$str_ople.
710 $hid->input('p_action','impress').
711 $hid->input("from_periode",$http->request('from_periode')).
712 $hid->input("to_periode",$http->request('to_periode'));
713
714 if (isset($_REQUEST['from_poste']))
715 echo HtmlInput::hidden('from_poste',$http->request('from_poste'));
716
717 if (isset($_REQUEST['to_poste']))
718 echo HtmlInput::hidden('to_poste',$http->request('to_poste'));
719
720 if (isset($_REQUEST['poste_id']))
721 echo HtmlInput::hidden("poste_id",$http->request('poste_id'));
722
723 if ( isset($_REQUEST['letter'] )) echo HtmlInput::hidden('letter','2');
724 if ( isset($_REQUEST['solded'] )) echo HtmlInput::hidden('solded','1');
725
726 if (isset($_REQUEST['poste_fille']))
727 echo $hid->input('poste_fille','on');
728 if (isset($_REQUEST['oper_detail']))
729 echo $hid->input('oper_detail','on');
730 if (isset($_REQUEST['poste_id'])) echo $hid->input("poste_id",$http->request('poste_id'));
731
732 echo "</form></TD>";
733 echo '<td style="vertical-align:top">';
734 echo HtmlInput::print_window();
735 echo '</td>';
736 echo '</tr>';
737 echo "</table>";
738
739
740 }
741 /*!
742 * \brief verify that the accounting belong to a ledger
743 *
744 * \return 0 ok, -1 no
745 */
746 function belong_ledger($p_jrn)
747 {
748 $filter=$this->db->get_value("select jrn_def_class_cred from jrn_def where jrn_def_id=$1", array($p_jrn));
749 if ( noalyss_trim ($filter) == '')
750 return 0;
751
752 $valid_cred=explode(" ",$filter);
753 $sql="select count(*) as poste from tmp_pcmn where ";
754 // Creation query
755 $or="";
756 $SqlFilter="";
757 $SqlArray = array();
758 $SqlArrayN = 1;
759 foreach ( $valid_cred as $item_cred)
760 {
761 if ( strlen (trim($item_cred)))
762 {
763 if ( strstr($item_cred,"*") == true )
764 {
765 $SqlItem=$or . 'pcm_val::text like $' . $SqlArrayN++;
766 array_push($SqlArray, strtr($item_cred,"*","%"));
767 $or=" or ";
768 }
769 else
770 {
771 $SqlItem=$or . 'pcm_val::text = $' . $SqlArrayN++;
772 array_push($SqlArray, $item_cred);
773 $or=" or ";
774 }
775 $SqlFilter=$SqlFilter.$SqlItem;
776 }
777 }//foreach
778 $sql.=$SqlFilter . ' and pcm_val::text=$' . $SqlArrayN++;
779 array_push($SqlArray, $this->id);
780 $max=$this->db->get_value($sql, $SqlArray);
781 if ($max > 0 )
782 return 0;
783 else
784 return -1;
785 }
786 /*!\brief With the id of the ledger, get the col jrn_def_class_deb
787 *\param $p_jrn jrn_id
788 *\return array of value, or an empty array if nothing is found
789 *\note
790 *\see
791 */
792 function get_account_ledger($p_jrn)
793 {
794 $l=new Acc_Ledger($this->db,$p_jrn);
795 $row=$l->get_propertie();
796 if ($l->get_type() != 'ODS') { return [];}
797 if ( $row == null || noalyss_strlentrim($row['jrn_def_class_deb']) == 0 ) return array();
798 $valid_account=explode(" ",$row['jrn_def_class_deb']);
799 return $valid_account;
800 }
801 /*!\brief build a sql statement thanks a array found with get_account_ledger
802 *
803 *\param $p_jrn jrn_id
804 *\return an emty string if nothing is found or a valid SQL statement like
805 \code
806 pcm_val like ... or pcm_val like ...
807 \endcode
808 *\note
809 *\see get_account_ledger
810 */
811 function build_sql_account($p_jrn)
812 {
813 $array=$this->get_account_ledger($p_jrn);
814 if ( empty($array) ) return "";
815 $sql="";
816 foreach ( $array as $item_cred)
817 {
818 if ( strlen (trim($item_cred))>0 )
819 {
820 if ( strstr($item_cred,"*") == true )
821 {
822 $item_cred=strtr($item_cred,"*","%");
823 $sql_tmp=" pcm_val::text like '$item_cred' or";
824 }
825 else
826 {
827 $sql_tmp=" pcm_val::text = '$item_cred' or";
828 }
829 $sql.=$sql_tmp;
830 }
831 }//foreach
832 /* remove the last or */
833 $sql=substr($sql,0,strlen($sql)-2);
834 return $sql;
835 }
836 /**
837 * Find the id of the cards which are using the current account
838 *
839 * @return an array of f_id
840 */
841 function find_card()
842 {
843 $sql="select f_id from fiche_detail where ad_id=$1 and ad_value=$2";
844 $account=$this->db->get_array($sql,array(ATTR_DEF_ACCOUNT,$this->id));
845 return $account;
846 }
847 /**
848 * @brief Return a string with the HTML code to display a button to export the
849 * history in CSV
850 * @param type $p_from from date (DD.MM.YYYY)
851 * @param type $p_to to date (DD.MM.YYYY)
852 * @return HTML string
853 */
854 function button_csv($p_from,$p_to) {
855 $href="export.php?".http_build_query(
856 array(
857 "gDossier"=>Dossier::id(),
858 "poste_id"=>$this->id,
859 "ople"=>0,
860 "type"=>"poste",
861 "from_periode"=>$p_from,
862 "to_periode"=>$p_to,
863 "act"=>"CSV:postedetail"
864 )
865 );
866 return '<a class="smallbutton" style="display:inline-block" href="'.$href.'">'._("Export CSV").'</a>';
867
868 }
869 /**
870 * @brief Return a string with the HTML code to display a button to export the
871 * history in PDF
872 * @param type $p_from from date (DD.MM.YYYY)
873 * @param type $p_to to date (DD.MM.YYYY)
874 * @return HTML string
875 */
876 function button_pdf($p_from,$p_to) {
877 $href="export.php?".http_build_query(
878 array(
879 "gDossier"=>Dossier::id(),
880 "poste_id"=>$this->id,
881 "ople"=>0,
882 "type"=>"poste",
883 "from_periode"=>$p_from,
884 "to_periode"=>$p_to,
885 "act"=>"PDF:postedetail"
886 )
887 );
888 return '<a class="smallbutton" style="display:inline-block" href="'.$href.'">'._("Export PDF").'</a>';
889
890 }
891 /**
892 * @brief Filter in javascript the table with the history
893 * @param type $p_table_id id of the table containting the data to filter
894 * @return html string
895 */
896 function filter_history($p_table_id) {
897 return _('Filtre rapide').' '.HtmlInput::filter_table($p_table_id, '0,1,2,3,4,5,6,7,8,9,10', 1);
898 }
899
900 public static function get_used_accounting($from_date, $to_date, $from_accounting, $to_accounting)
901 {
902 // check date
903 if (isDate($from_date) != $from_date || isDate($to_date) != $to_date) {
904 return array();
905 }
906 // build query
907 $sql = "select pcm_val,pcm_lib from tmp_pcmn
908 where pcm_val in
909 (select j_poste from jrnx where j_date >= to_date('$from_date','DD.MM.YYYY')
910 and j_date <= to_date('$to_date','DD.MM.YYYY') ) ";
911 $cond_poste="";
912 if ($from_accounting != '') {
913 $cond_poste .= "and pcm_val >= upper ('" . Database::escape_string($from_accounting) . "')";
914 }
915
916 if ($to_accounting != '') {
917 $cond_poste .= " and pcm_val <= upper ('" . Database::escape_string($to_accounting) . "')";
918 }
919
920 $sql = $sql . $cond_poste . ' order by pcm_val::text';
921
922 // get array
923 $cn=Dossier::connect();
924 $a_poste = $cn->get_array($sql);
925 // return array
926 return $a_poste;
927
928 }
929}
format_date($p_date, $p_from_format='YYYY-MM-DD', $p_to_format='DD.MM.YYYY')
format the date, when taken from the database the format is MM-DD-YYYY
th($p_string, $p_extra='', $raw='')
Definition ac_common.php:58
sql_filter_per($p_cn, $p_from, $p_to, $p_form='p_id', $p_field='jr_tech_per')
Create the condition to filter on the j_tech_per thanks a from and to date.
noalyss_str_replace($search, $replace, $string)
td($p_string='', $p_extra='')
surround the string with td
Definition ac_common.php:83
nbm($p_number, $p_dec=2)
format the number with a sep.
global $g_parameter
for display
global $g_user
if no group available , then stop
$href
Definition adm.inc.php:31
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$op
h( $row[ 'oa_description'])
$ret label
$from_div
$anc_grandlivre from
$_REQUEST['ac']
margin jrn_def_id
$from_poste name
_("actif, passif,charge,...")
$input_from type
$class
Display the Plugin and for each profile were it is installed or not.
Manage the account from the table jrn, jrnx or tmp_pcmn.
get_solde_detail($p_cond="")
give the balance of an account
load()
Get all the value for this object from the database the data member are set.
get_amount_side($p_amount)
return the letter C if amount is > 0, D if < 0 or =
static HtmlTableHeader($actiontarget="poste")
Display HTML Table Header (button)
get_solde($p_cond=" true ")
give the balance of an account
get_name()
Return the name of a account it doesn't change any data member.
get_row($p_from, $p_to)
Get data for accounting entry between 2 periode.
make_sql_accounting_detail($p_from, $p_to, $sql_let, $filter_sql)
build the SQL for get_row_data
isTVA()
isTva tell is a poste is used for VAT
HtmlTable($p_array=null, $let=0, $from_div=0)
HtmlTable, display a HTML of a poste for the asked period.
get_type()
Return the type of a account.
get_row_sql_deprecated($Res)
get the row thanks the resource
get_row_date($p_from, $p_to, $let=0, $solded=0)
Get data for accounting entry between 2 date.
make_sql_not_balanced_account($filter)
make the SQL for the balanced accounting
do_exist()
check if the poste exist in the tmp_pcmn
make_sql_saldo_account($filter_sql, $sql_let)
make the SQL for the balance of an accounting
this file match the tables jrn & jrnx the purpose is to remove or save accountant writing to these ta...
static fetch_result($ret, $p_row=0, $p_col=0)
wrapper for the function pg_fetch_all
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static fetch_all($ret, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_all
static num_row($ret)
wrapper for the function pg_num_rows
Html Input.
API for creating PDF, unicode, based on tfpdf.
Definition pdf.class.php:34
$all table
foreach( $Fiche->row as $op) $solde_type
$SecUser db
$side