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