noalyss Version-9
acc_ledger_history_generic.class.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * PhpCompta 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 PhpCompta; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20// Copyright (2018) Author Dany De Bontridder <dany@alchimerys.be>
21
22/**
23 * @file
24 * @brief class for Ledger's history, list of operation for MISC, FIN, ACH and VEN
25 *
26 */
27
28/**
29 * @brief manage the list of operation when we need several ledger with a different
30 * type or from Misceleaneous ledger
31 * @include acc_ledger_historyTest.php
32 */
34{
35
36 private $data; //!< array of rows
37
38 /**
39 * Constructor
40 * @param Database $cn
41 * @param type $pa_ledger
42 * @param type $p_from
43 * @param type $p_to
44 * @param type $p_mode
45 * @example acc_ledger_historyTest.php
46 */
47
48 function __construct(Database $cn, $pa_ledger, $p_from, $p_to, $p_mode)
49 {
50 parent::__construct($cn, $pa_ledger, $p_from, $p_to, $p_mode);
51 $this->data=[];
52 $this->ledger_type='ODS';
53 }
54
55 /**
56 * @brief get_detail gives the detail of row
57 * this array must contains at least the field
58 * <ul>
59 * <li> montant</li>
60 * <li> grpt_id
61 * </ul>
62 * the following field will be added
63 * <ul>
64 * <li> HTVA
65 * <li> TVAC
66 * <li> TVA array with
67 * <ul>
68 * <li> field 0 idx
69 * <li> array containing tva_id,tva_label and tva_amount
70 * </ul>
71 * </ul>
72 *
73 * @paramp_array the structure is set in get_rowSimple, this array is
74 * modified,
75 @verbatim
76 jrn.jr_id as jr_id ,
77 jrn.jr_id as num ,
78 jrn.jr_def_id as jr_def_id,
79 jrn.jr_montant as montant,
80 substr(jrn.jr_comment,1,35) as comment,
81 to_char(jrn.jr_date,'DD-MM-YYYY') as date,
82 to_char(jrn.jr_date_paid,'DD-MM-YYYY') as date_paid,
83 jr_pj_number,
84 jr_internal,
85 jrn.jr_grpt_id as grpt_id,
86 jrn.jr_pj_name as pj,
87 jrn_def_type,
88 jrn.jr_tech_per
89 @endverbatim
90 *
91 * @param $trunc if the data must be truncated, usefull for pdf export
92 * @paramp_jrn_type is the type of the ledger (ACH or VEN)
93 * @param $a_TVA TVA Array (default null)
94 * @param $a_ParmCode Array (default null)
95 *
96 * @todo useless since only 2 modes are supported : oneline and extended (accounting writing) but
97 * can be used for ledger before 2007
98 * \return p_array
99 */
100 function get_detail(&$p_array, $p_jrn_type, $trunc=0, $a_TVA=null,
101 $a_ParmCode=null)
102 {
103 bcscale(2);
104
105 if ($a_TVA==null)
106 {
107 //Load TVA array
108 $a_TVA=$this->db->get_array('select tva_id,tva_label,tva_poste
109 from tva_rate where tva_rate != 0 order by tva_rate,tva_label,tva_id');
110 }
111 if ($a_ParmCode==null)
112 {
113 //Load Parm_code
114 $a_ParmCode=$this->db->get_array('select p_code,p_value from parm_code');
115 }
116 // init
117 $p_array['client']="";
118 $p_array['TVAC']=0;
119 $p_array['HTVA']=0;
120 $p_array['TVA']=array();
121 $p_array['AMOUNT_TVA']=0.0;
122 $p_array['dep_priv']=0;
123 $p_array['dna']=0;
124 $p_array['tva_dna']=0;
125 $p_array['tva_np']=0;
126 $dep_priv=0.0;
127
128
129 // if using the QUANT_* tables then get there the needed info
130 //
131 if ($this->use_quant_table($p_array['grpt_id'], $p_array['jrn_def_type'])
132 ==TRUE)
133 {
134 // Initialize amount for VAT
135 $nb_tva=count($a_TVA);
136 for ($i=0; $i<$nb_tva; $i++)
137 {
138 $p_array['TVA'][$i]=array($i,
139 array(
140 $a_TVA[$i]['tva_id'],
141 $a_TVA[$i]['tva_label'],
142 0)
143 );
144 }
145 switch ($p_array['jrn_def_type'])
146 {
147 case "ACH":
148 $sql="select
149 sum(coalesce(qp_price,0)) as htva,
150 sum(coalesce(qp_vat)) as vat,
151 sum(coalesce(qp_nd_tva)) as nd_tva,
152 sum(coalesce(qp_nd_tva_recup)) as nd_tva_recup,
153 sum(coalesce(qp_dep_priv)) as dep_priv,
154 qp_vat_code as tva_code,
155 qp_supplier as fiche_id,
156 qp_vat_sided as tva_sided
157 from
158 quant_purchase
159 where
160 qp_internal=$1
161 group by qp_supplier,qp_vat_code,qp_vat_sided ";
162 break;
163 case "VEN":
164 $sql="select
165 sum(coalesce(qs_price,0)) as htva,
166 sum(coalesce(qs_vat)) as vat,
167 sum(0) as nd_tva,
168 sum(0) as nd_tva_recup,
169 sum(0) as dep_priv,
170 qs_vat_code as tva_code,
171 qs_client as fiche_id,
172 qs_vat_sided as tva_sided
173 from
174 quant_sold
175 where
176 qs_internal=$1
177 group by qs_client,qs_vat_code,qs_vat_sided ";
178 break;
179
180 default:
181 break;
182 }
183 $a_detail=$this->db->get_array($sql, array($p_array['jr_internal']));
184 $nb_detail=count($a_detail);
185 for ($x=0; $x<$nb_detail; $x++)
186 {
187 $p_array['HTVA']=bcadd($p_array['HTVA'], $a_detail[$x]['htva']);
188 $p_array['tva_dna']=bcadd($p_array['tva_dna'],
189 $a_detail[$x]['nd_tva_recup']);
190 $p_array['tva_dna']=bcadd($p_array['tva_dna'],
191 $a_detail[$x]['nd_tva']);
192 $p_array['TVAC']=bcadd($p_array['TVAC'], $a_detail[$x]['htva']);
193 if ($a_detail[$x]['tva_sided']==0)
194 $p_array['TVAC']=bcadd($p_array['TVAC'],
195 $a_detail[$x]['vat']);
196 $p_array['TVAC']=bcadd($p_array['TVAC'], $a_detail[$x]['nd_tva']);
197 $p_array['TVAC']=bcadd($p_array['TVAC'],
198 $a_detail[$x]['nd_tva_recup']);
199 $p_array['dep_priv']=bcadd($p_array['dep_priv'],
200 $a_detail[$x]['dep_priv']);
201 $xdx=$a_detail[$x]['tva_code'];
202 // $p_array['TVA'][$xdx]=bcadd($p_array['TVA'][$xdx],$a_detail[$x]['vat']);
203 //--- Put VAT in the right place in the array $a_TVA
204 $nb_tva=count($a_TVA);
205 for ($j=0; $j<$nb_tva; $j++)
206 {
207 if ($xdx==$p_array['TVA'][$j][1][0])
208 {
209 $p_array['TVA'][$j][1][2]=bcadd($p_array['TVA'][$j][1][2],
210 $a_detail[$x]['vat']);
211 }
212 }
213 }
214 $fiche=new Fiche($this->db, $a_detail[0]['fiche_id']);
215 $p_array['client']=($trunc==0)?$fiche->getName():mb_substr($fiche->getName(),
216 0, 20);
217 return $p_array;
218 }
219 //
220 // Retrieve data from jrnx
221 // Order is important for TVA autoreversed
222 $sql="select j_id,j_poste,j_montant, j_debit,j_qcode from jrnx where ".
223 " j_grpt=$1 order by 1 desc";
224 $Res2=$this->db->exec_sql($sql, array($p_array['grpt_id']));
225 $data_jrnx=Database::fetch_all($Res2);
226 $c=0;
227
228 // Parse data from jrnx and fill diff. field
229 if ( $data_jrnx == FALSE ){
230 $data_jrnx=[];
231 }
232 foreach ($data_jrnx as $code)
233 {
234 $idx_tva=0;
235 $poste=new Acc_Account_Ledger($this->db, $code['j_poste']);
236
237 // if card retrieve name if the account is not a VAT account
238 if (noalyss_strlentrim($code['j_qcode'])!=0&&$poste->isTva()==0)
239 {
240 $fiche=new Fiche($this->db);
241 $fiche->get_by_qcode(trim($code['j_qcode']), false);
242 $fiche_def_id=$fiche->get_fiche_def_ref_id();
243 // Customer or supplier
244 if ($fiche_def_id==FICHE_TYPE_CLIENT||
245 $fiche_def_id==FICHE_TYPE_FOURNISSEUR||$fiche_def_id==FICHE_TYPE_ADM_TAX)
246 {
247 $p_array['TVAC']=$code['j_montant'];
248
249 $p_array['client']=($trunc==0)?$fiche->getName():mb_substr($fiche->getName(),
250 0, 20);
251 $p_array['reversed']=false;
252 if ($fiche_def_id==FICHE_TYPE_CLIENT&&$code['j_debit']=='f')
253 {
254 $p_array['reversed']=true;
255 $p_array['TVAC']*=-1;
256 }
257 if ($fiche_def_id==FICHE_TYPE_ADM_TAX&&$code['j_debit']=='f')
258 {
259 $p_array['reversed']=true;
260 $p_array['TVAC']*=-1;
261 }
262 if ($fiche_def_id==FICHE_TYPE_FOURNISSEUR&&$code['j_debit']=='t')
263 {
264 $p_array['reversed']=true;
265 $p_array['TVAC']*=-1;
266 }
267 }
268 else
269 {
270 // if we use the ledger ven / ach for others card than supplier and customer
271 if ($fiche_def_id!=FICHE_TYPE_VENTE&&
272 $fiche_def_id!=FICHE_TYPE_ACH_MAR&&
273 $fiche_def_id!=FICHE_TYPE_ACH_SER&&
274 $fiche_def_id!=FICHE_TYPE_ACH_MAT
275 )
276 {
277 $p_array['TVAC']=$code['j_montant'];
278
279 $p_array['client']=($trunc==0)?$fiche->getName():mb_substr($fiche->getName(),
280 0, 20);
281 $p_array['reversed']=false;
282 if ($p_jrn_type=='ACH'&&$code['j_debit']=='t')
283 {
284 $p_array['reversed']=true;
285 $p_array['TVAC']*=-1;
286 }
287 if ($p_jrn_type=='VEN'&&$code['j_debit']=='f')
288 {
289 $p_array['reversed']=true;
290 $p_array['TVAC']*=-1;
291 }
292 }
293 }
294 }
295 // if TVA, load amount, tva id and rate in array
296 foreach ($a_TVA as $line_tva)
297 {
298 list($tva_deb, $tva_cred)=explode(',', $line_tva['tva_poste']);
299 if ($code['j_poste']==$tva_deb||
300 $code['j_poste']==$tva_cred)
301 {
302
303 // For the reversed operation
304 if ($p_jrn_type=='ACH'&&$code['j_debit']=='f')
305 {
306 $code['j_montant']=-1*$code['j_montant'];
307 }
308 if ($p_jrn_type=='VEN'&&$code['j_debit']=='t')
309 {
310 $code['j_montant']=-1*$code['j_montant'];
311 }
312
313 $p_array['AMOUNT_TVA']+=$code['j_montant'];
314
315 $p_array['TVA'][$c]=array($idx_tva, array($line_tva['tva_id'],
316 $line_tva['tva_label'], $code['j_montant']));
317 $c++;
318
319 $idx_tva++;
320 }
321 }
322
323 // isDNA
324 // If operation is reversed then amount are negatif
325 /* if ND */
326 if ($p_array['jrn_def_type']=='ACH')
327 {
328 $qp_id=$this->get_value("select qp_id from quant_purchase where j_id=$1",[$code['j_id']]);
329 $purchase=new Quant_Purchase_SQL($this->db,$qp_id);
330
331 $dep_priv=bcadd ($dep_priv,$purchase->qp_dep_priv);
332 $p_array['dep_priv']=$dep_priv;
333 $p_array['dna']=bcadd($p_array['dna'], $purchase->qp_nd_amount);
334 $p_array['tva_dna']=bcadd($p_array['tva_dna'],
335 bcadd($purchase->qp_nd_tva, $purchase->qp_nd_tva_recup));
336 $p_array['tva_np']=bcadd($purchase->qp_vat_sided,
337 $p_array['tva_np']);
338 }
339 if ($p_array['jrn_def_type']=='VEN')
340 {
341 $qs_id=$this->db->get_value("select qs_id from quant_sold where j_id=$1",array($code['j_id']));
342 $sold=new Quant_Sold_SQL($this->db,$qs_id);
343 $p_array['tva_np']=bcadd($sold->qs_vat_sided, $p_array['tva_np']);
344 }
345 }
346 $p_array['TVAC']=sprintf('% 10.2f', $p_array['TVAC']);
347 $p_array['HTVA']=sprintf('% 10.2f',
348 $p_array['TVAC']-$p_array['AMOUNT_TVA']-$p_array['tva_dna']);
349 $r="";
350 $a_tva_amount=array();
351 // inline TVA (used for the PDF)
352 foreach ($p_array['TVA'] as $linetva)
353 {
354 foreach ($a_TVA as $tva)
355 {
356 if ($tva['tva_id']==$linetva[1][0])
357 {
358 $a=$tva['tva_id'];
359 $a_tva_amount[$a]=$linetva[1][2];
360 }
361 }
362 }
363 foreach ($a_TVA as $line_tva)
364 {
365 $a=$line_tva['tva_id'];
366 if (isset($a_tva_amount[$a]))
367 {
368 $tmp=sprintf("% 10.2f", $a_tva_amount[$a]);
369 $r.="$tmp";
370 }
371 else
372 $r.=sprintf("% 10.2f", 0);
373 }
374 $p_array['TVA_INLINE']=$r;
375
376 return $p_array;
377 }
378
379 /**
380 * @brief depending on the mode will call the right function
381 * - export_oneline_html for one line (mode=L)
382 * - export_accounting_html for accounting (mode=A,D,E)
383 */
384 function export_html()
385 {
386 switch ($this->m_mode)
387 {
388 case "E":
389 $this->export_accounting_html();
390 break;
391 case "D":
392 $this->export_accounting_html();
393 break;
394 case "L":
395 $this->export_oneline_html();
396 break;
397 case "A":
398 $this->export_accounting_html();
399 break;
400 default:
401 break;
402 }
403 }
404
405 /**
406 * @brief Get simplified row from ledger
407 *
408 * @param p_from periode
409 * @param p_to periode
410 * @param p_limit starting line
411 * @param p_offset number of lines
412 * @param trunc if data must be truncated (pdf export)
413 * @todo Prévoir aussi les journaux sans tables quant < 2007
414 * @return numbe of rows found
415 */
416 function get_rowSimple($trunc=0, $p_limit=-1, $p_offset=-1)
417 {
418 global $g_user;
419 $jrn=" jrn_def_id in (".join(',',$this->ma_ledger).")";
420
421 $periode=sql_filter_per($this->db, $this->m_from, $this->m_to, 'p_id',
422 'jr_tech_per');
423
424 $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:"";
425 //---
426 $sql="
427 SELECT jrn.jr_id as jr_id ,
428 jrn.jr_id as num ,
429 jrn.jr_def_id as jr_def_id,
430 jrn.jr_montant as montant,
431 substr(jrn.jr_comment,1,35) as comment,
432 to_char(jrn.jr_date,'DD-MM-YYYY') as date,
433 to_char(jrn.jr_date_paid,'DD-MM-YYYY') as date_paid,
434 jr_pj_number,
435 jr_internal,
436 jrn.jr_grpt_id as grpt_id,
437 jrn.jr_pj_name as pj,
438 jrn_def_type,
439 jrn.jr_tech_per,
440 jrn.currency_id,
441 jrn.currency_rate,
442 jrn.currency_rate_ref,
443 currency.cr_code_iso,
444 coalesce(sum_ocamount,0) as sum_ocamount,
445 coalesce(sum_ocvat_amount,0) as sum_ocvat_amount
446 FROM jrn join jrn_def on (jrn_def_id=jr_def_id)
447 join currency on (currency.id=jrn.currency_id)
448 left join (
449 select jrn2.jr_id , sum(coalesce(oc_amount,0)) as sum_ocamount,sum(coalesce(oc_vat_amount,0)) as sum_ocvat_amount
450 from operation_currency
451 join jrnx using (j_id)
452 join jrn as jrn2 on (j_grpt=jrn2.jr_grpt_Id)
453 where
454 j_id in (select j_id from jrnx where j_grpt=jrn2.jr_grpt_id)
455 group by jr_id
456 ) as OC1 using (jr_id)
457 WHERE $periode and $jrn order by jr_date,substring(jrn.jr_pj_number,'[0-9]+$')::numeric asc $cond_limite";
458 $Res=$this->db->exec_sql($sql);
460 if ($Max==0)
461 {
462 return 0;
463 }
464// @todo Pas nécessaire puisqu'on ne traite que les journaux d'opération diverses,
465// Il faudrait p-e prévoir un système pour les journaux avant 2007 qui n'utilisaient
466// pas les tables quant
467//
468// $type=$this->get_type();
469// // for type ACH and Ven we take more info
470// if ($type=='ACH'||$type=='VEN')
471// {
472// $a_ParmCode=$this->db->get_array('select p_code,p_value from parm_code');
473// $a_TVA=$this->db->get_array('select tva_id,tva_label,tva_poste
474// from tva_rate where tva_rate != 0 order by tva_rate,tva_label,tva_id ');
475// for ($i=0; $i<$Max; $i++)
476// {
477// $array[$i]=Database::fetch_array($Res, $i);
478// $p=$this->get_detail($array[$i], $type, $trunc, $a_TVA,
479// $a_ParmCode);
480// if ($array[$i]['dep_priv']!=0.0)
481// {
482// $array[$i]['comment'].="(priv. ".$array[$i]['dep_priv'].")";
483// }
484// }
485// }
486// else
487// {
489// }
490
491 $this->data=$array;
492 return $Max;
493 }
494
495 /**
496 * @brief set $this->data with the array of rows
497 *
498 *
499 * @param p_limit starting line
500 * @param p_offset number of lines
501 * @returns nb of rows found
502 *
503 */
504 function get_row($p_limit=-1, $p_offset=-1)
505 {
506 global $g_user;
507 $periode=sql_filter_per($this->db, $this->m_from, $this->m_to, 'p_id',
508 'jr_tech_per');
509
510 $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:"";
511
512 $ledger_list=join( ",",$this->ma_ledger);
513// Grand livre == 0
514 $Res=$this->db->exec_sql("select jr_id,j_id,j_id as int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date,
515 jr_internal,
516 case j_debit when 't' then j_montant else 0 end as deb_montant,
517 case j_debit when 'f' then j_montant else 0 end as cred_montant,
518 j_debit as debit,j_poste as poste,j_qcode,jr_montant , ".
519 "case when j_text='' or j_text is null then pcm_lib else j_text end as description,j_grpt as grp,
520 jr_comment||' ('||jr_internal||')' as jr_comment,
521 jr_pj_number,
522 j_qcode,
523 jrn_def_type,
524 jr_rapt as oc, j_tech_per as periode,
525 j_id,
526 jrn.currency_id,
527 jrn.currency_rate,
528 jrn.currency_rate_ref,
529 operation_currency.oc_amount,
530 operation_currency.oc_vat_amount
531 from jrnx
532 join jrn on (jr_grpt_id=j_grpt )
533 left join operation_currency using (j_id)
534 left join tmp_pcmn on pcm_val=j_poste
535 join jrn_def on (jrn_def_id=jr_def_id)
536 where j_jrn_def in (".$ledger_list.")
537 and ".$periode."
538 order by j_date::date asc,substring(jr_pj_number,'[0-9]+$')::numeric asc,j_grpt,j_debit desc ".
539 $cond_limite);
540
541 $array=array();
543 if ($Max==0)
544 return array();
545 $case="";
546 $tot_deb=0;
547 $tot_cred=0;
549 bcscale(2);
550 for ($i=0; $i<$Max; $i++)
551 {
552
553 $line=$row[$i];
554 $tot_deb=bcadd($tot_deb, $line['deb_montant']);
555 $tot_cred=bcadd($tot_cred, $line['cred_montant']);
556 $tot_op=$line['jr_montant'];
557
558 /* Check first if there is a quickcode */
559 if (noalyss_strlentrim($line['description'])==0&&noalyss_strlentrim($line['j_qcode'])
560 !=0)
561 {
562 $fiche=new Fiche($this->db);
563 if ($fiche->get_by_qcode($line['j_qcode'], false)==0)
564 {
565 $line['description']=$fiche->strAttribut(ATTR_DEF_NAME);
566 }
567 }
568 if ($case!=$line['grp'])
569 {
570 $case=$line['grp'];
571 // for financial, we show if the amount is or not in negative
572 if ($line['jrn_def_type']=='FIN')
573 {
574 $amount=$this->db->get_value('select qf_amount from quant_fin where jr_id=$1',
575 array($line['jr_id']));
576 /* if nothing is found */
577 if ($this->db->count()==0)
578 $tot_op=$line['jr_montant'];
579 else if ($amount<0)
580 {
581 $tot_op=$amount;
582 }
583 }
584 $array[]=array(
585 'jr_id'=>$line['jr_id'],
586 'int_j_id'=>$line['int_j_id'],
587 'j_id'=>$line['j_id'],
588 'j_date'=>$line['j_date'],
589 'internal'=>$line['jr_internal'],
590 'deb_montant'=>'',
591 'cred_montant'=>' ',
592 'description'=>'<b><i>'.h($line['jr_comment']).' ['.$tot_op.'] </i></b>',
593 'poste'=>$line['oc'],
594 'j_qcode'=>$line['j_qcode'],
595 'periode'=>$line['periode'],
596 'jr_pj_number'=>$line ['jr_pj_number'],
597 "ledger_type"=>$line['jrn_def_type']);
598
599 $array[]=array(
600 'jr_id'=>'',
601 'int_j_id'=>$line['int_j_id'],
602 'j_id'=>'',
603 'j_date'=>'',
604 'internal'=>'',
605 'deb_montant'=>$line['deb_montant'],
606 'cred_montant'=>$line['cred_montant'],
607 'description'=>$line['description'],
608 'poste'=>$line['poste'],
609 'j_qcode'=>$line['j_qcode'],
610 'periode'=>$line['periode'],
611 'jr_pj_number'=>'',
612 "ledger_type"=>$line['jrn_def_type']
613 );
614 }
615 else
616 {
617 $array[]=array(
618 'jr_id'=>$line['jr_id'],
619 'int_j_id'=>$line['int_j_id'],
620 'j_id'=>'',
621 'j_date'=>'',
622 'internal'=>'',
623 'deb_montant'=>$line['deb_montant'],
624 'cred_montant'=>$line['cred_montant'],
625 'description'=>$line['description'],
626 'poste'=>$line['poste'],
627 'j_qcode'=>$line['j_qcode'],
628 'periode'=>$line['periode'],
629 'jr_pj_number'=>'',
630 "ledger_type"=>$line['jrn_def_type']);
631 }
632 }
633 $this->data=array($array, $tot_deb, $tot_cred);
634 return $Max;
635 }
636
637 /**
638 * display in html the detail the list of operation
639 */
640 public function export_detail_html()
641 {
642 $this->export_accounting_html();
643 }
644
645 /**
646 * display in html with extended detail the list of operation
647 */
648 public function export_extended_html()
649 {
650 $this->export_accounting_html();
651 }
652
653 /**
654 * display in html the accounting of the list of operations
655 */
656 public function export_accounting_html()
657 {
658
659 $this->get_row();
660 echo '<TABLE class="result">';
661 // detailled printing
662 //---
663 if ( empty ($this->data)) return;
664 foreach ($this->data[0] as $op)
665 {
666 $class="";
667 if ($op['j_date']!='')
668 {
669 $class="odd";
670 }
671
672 echo "<TR class=\"$class\">";
673
674 echo "<TD>".$op['j_date']."</TD>";
675 echo "<TD >".$op['jr_pj_number']."</TD>";
676
677
678 if ($op['internal']!='')
679 echo "<TD>".HtmlInput::detail_op($op['jr_id'], $op['internal'])."</TD>";
680 else
681 echo td();
682
683 echo "<TD >".$op['poste']."</TD>".
684 "<TD >".$op['description']."</TD>".
685 "<TD style=\"text-align:right\">".nbm($op['deb_montant'])."</TD>".
686 "<TD style=\"text-align:right\">".nbm($op['cred_montant'])."</TD>".
687 "</TR>";
688 }// end loop
689 echo "</table>";
690
691// show the saldo
692//@todo use <li> instead of <br>
693 echo _("solde débiteur:").$this->data[1]."<br>";
694 echo _("solde créditeur:").$this->data[2];
695 }
696
697 /**
698 * @brief list operation on one line per operation
699 */
700 public function export_oneline_html()
701 {
702 $this->get_rowSimple();
703
704 echo \HtmlInput::filter_table("tb_print_ledger", "0,1,2,3,4,5,6", 1);
705 echo '<TABLE class="result" id="tb_print_ledger">';
706 echo "<TR>".
707 th(_("Date")).
708 th(_("n° pièce")).
709 th(_("internal")).
710 th(_("Tiers")).
711 th(_("Commentaire")).
712 th(_("Devise")).
713 th(_("Total opération")).
714 "</TR>";
715 // set a filter for the FIN
716 $i=0; $tot_amount=0;
717 bcscale(2);
718 foreach ($this->data as $line)
719 {
720 $i++;
721 $class=($i%2==0)?' class="even" ':' class="odd" ';
722 echo "<tr $class>";
723 echo "<TD>".$line['date']."</TD>";
724 echo "<TD>".h($line['jr_pj_number'])."</TD>";
725 echo "<TD>".HtmlInput::detail_op($line['jr_id'],
726 $line['jr_internal'])."</TD>";
727 $tiers=$this->get_tiers($line['jrn_def_type'], $line['jr_id']);
728 echo td($tiers);
729 echo "<TD>".h($line['comment'])."</TD>";
730 if ( $line['currency_id'] != 0) {
731 echo td(bcadd($line['sum_ocamount'],$line['sum_ocvat_amount'])." ".$line['cr_code_iso'],'class="num"');
732 } else {
733 echo td("");
734 }
735
736
737
738 // echo "<TD>".$line['pj']."</TD>";
739 // If the ledger is financial :
740 // the credit must be negative and written in red
741 // Get the jrn type
742 if ($line['jrn_def_type']=='FIN')
743 {
744 $positive=$this->db->get_value("select qf_amount from quant_fin where jr_id=$1",
745 array($line['jr_id']));
746 if ($this->db->count()==0)
747 $positive=1;
748 else
749 $positive=($positive>0)?1:0;
750
751 echo "<TD align=\"right\">";
752 echo ( $positive==0 )?"<font color=\"red\"> - ".nbm($line['montant'])."</font>":nbm($line['montant']);
753 echo "</TD>";
754 if ($positive==1)
755 {
756 $tot_amount=bcadd($tot_amount, $line['montant']);
757 }
758 else
759 {
760 $tot_amount=bcsub($tot_amount, $line['montant']);
761 }
762 }
763 else
764 {
765 echo "<TD align=\"right\">".nbm($line['montant'])."</TD>";
766 $tot_amount=bcadd($tot_amount, $line['montant']);
767 }
768
769 echo "</tr>";
770 }
771 echo '<tr class="highlight">';
772 echo '<td>'._('Totaux').'</td>';
773 echo td().td().td().td().td();
774 echo '<td class="num">'.nbm($tot_amount).'</td>';
775 echo '</tr>';
776 echo "</table>";
777 }
778
779 /**
780 * To get data
781 * @return array of rows
782 */
783 function get_data()
784 {
785 return $this->data;
786 }
787
788 /**
789 * export CSV
790 */
791 function export_csv()
792 {
793 $export=new Noalyss_Csv(_('journal'));
794 $export->send_header();
795
796 $this->get_row();
797 $title=array();
798 $title[]=_("operation");
799 $title[]=_("N° Pièce");
800 $title[]=_("Interne");
801 $title[]=_("Date");
802 $title[]=_("Poste");
803 $title[]=_("QuickCode");
804 $title[]=_("Libellé");
805 $title[]=_("Débit");
806 $title[]=_("Crédit");
807 $export->write_header($title);
808 if (count($this->data)==0)
809 exit;
810 $old_id="";
811 foreach ($this->data[0] as $idx=>$op)
812 {
813 // should clean description : remove <b><i> tag and '; char
814 $desc=$op['description'];
815 $desc=noalyss_str_replace("<b>", "", $desc);
816 $desc=noalyss_str_replace("</b>", "", $desc);
817 $desc=noalyss_str_replace("<i>", "", $desc);
818 $desc=noalyss_str_replace("</i>", "", $desc);
819 if ($op['j_id']!="")
820 $old_id=$op['j_id'];
821
822 $export->add($old_id, "text");
823 $export->add($op['jr_pj_number']);
824 $export->add($op['internal']);
825 $export->add($op['j_date']);
826 $export->add($op['poste']);
827 $export->add($op['j_qcode']);
828 $export->add($desc);
829 $export->add($op['deb_montant'], "number");
830 $export->add($op['cred_montant'], "number");
831 $export->write();
832 }
833 }
834}
835
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.
Definition: ac_common.php:682
noalyss_strlentrim($p_string)
Definition: ac_common.php:1549
noalyss_str_replace($search, $replace, $string)
Definition: ac_common.php:1553
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.
Definition: ac_common.php:137
global $g_user
if no group available , then stop
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$op
Definition: ajax_admin.php:38
h( $row[ 'oa_description'])
$idx
$code
$class
Manage the account from the table jrn, jrnx or tmp_pcmn.
manage the list of operation when we need several ledger with a different type or from Misceleaneous ...
get_row($p_limit=-1, $p_offset=-1)
set $this->data with the array of rows
__construct(Database $cn, $pa_ledger, $p_from, $p_to, $p_mode)
get_rowSimple($trunc=0, $p_limit=-1, $p_offset=-1)
Get simplified row from ledger.
export_accounting_html()
display in html the accounting of the list of operations
export_oneline_html()
list operation on one line per operation
export_detail_html()
display in html the detail the list of operation
get_detail(&$p_array, $p_jrn_type, $trunc=0, $a_TVA=null, $a_ParmCode=null)
get_detail gives the detail of row this array must contains at least the field
export_extended_html()
display in html with extended detail the list of operation
export_html()
depending on the mode will call the right function
Display history of operation.
get_tiers($p_jrn_type, $jr_id)
Retrieve the third : supplier for purchase, customer for sale, bank for fin,.
static fetch_all($ret)
wrapper for the function pg_fetch_all
static num_row($ret)
wrapper for the function pg_num_rows
contains the class for connecting to Noalyss
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: fiche.class.php:38
Manage the CSV : manage files and write CSV record.
ORM of the table public.quant_purchase.
ORM of the table public.quant_sold.
const FICHE_TYPE_ACH_SER
Definition: constant.php:255
const ATTR_DEF_NAME
Definition: constant.php:216
const FICHE_TYPE_ACH_MAR
Definition: constant.php:254
const FICHE_TYPE_VENTE
Definition: constant.php:248
const FICHE_TYPE_ADM_TAX
Definition: constant.php:253
const FICHE_TYPE_CLIENT
Definition: constant.php:247
const FICHE_TYPE_ACH_MAT
Definition: constant.php:256
const FICHE_TYPE_FOURNISSEUR
Definition: constant.php:249
$Res
for($e=0; $e< count($afiche); $e++) exit
$SecUser db