61 function get_row($p_from_periode,$p_to_periode,$p_previous_exc=0)
65 $per_sql=
sql_filter_per($this->
db,$p_from_periode,$p_to_periode,
'p_id',
'j_tech_per');
73 if ( !empty($this->
jrn) )
81 $jrn=
" j_jrn_def in (";
85 $jrn.=$comma.$this->jrn[
$e];
94 $from_poste=
" $and j_poste::text >= '".$this->from_poste.
"'";
99 $to_poste=
" $and j_poste::text <= '".$this->to_poste.
"'";
102 $filter_sql=
$g_user->get_ledger_sql(
'ALL',3);
104 switch ($p_previous_exc)
108 $sql=
"select j_poste as poste,
110 sum(cred) as sum_cred,
111 sum(deb_op) as sum_deb_ope ,
112 sum(cred_op) as sum_cred_ope
115 case when j_debit='t' then j_montant else 0 end as deb,
116 case when j_debit='f' then j_montant else 0 end as cred,
117 case when j_debit='t' and jr_optype='OPE' then j_montant else 0 end as deb_op,
118 case when j_debit='f' and jr_optype='OPE' then j_montant else 0 end as cred_op
119 from jrnx join tmp_pcmn on (j_poste=pcm_val)
120 left join parm_periode on (j_tech_per = p_id)
121 join jrn_def on (j_jrn_def=jrn_def_id)
122 join jrn on (j_grpt=jr_grpt_id)
124 $jrn $from_poste $to_poste
127 $per_sql ) as m group by 1 order by 1";
138 $per_sql_previous=
sql_filter_per($this->
db,$previous_start->p_id,$previous_end->p_id,
'p_id',
'j_tech_per');
141 ( select j_poste,sum(deb) as sdeb,sum(cred) as scred,
142 sum(deb_op) as sum_deb_ope ,
143 sum(cred_op) as sum_cred_ope
146 case when j_debit='t' then j_montant else 0 end as deb,
147 case when j_debit='f' then j_montant else 0 end as cred ,
148 case when j_debit='t' and jr_optype='OPE' then j_montant else 0 end as deb_op,
149 case when j_debit='f' and jr_optype='OPE' then j_montant else 0 end as cred_op
151 join jrn on (j_grpt=jr_grpt_id)
152 join tmp_pcmn on (j_poste=pcm_val)
153 left join parm_periode on (j_tech_per = p_id)
154 join jrn_def on (j_jrn_def=jrn_def_id)
156 $jrn $from_poste $to_poste
157 $and $filter_sql and $per_sql
158 ) as sub_m group by j_poste order by j_poste ) ,
159 p as ( select j_poste,sum(deb) as sdeb,
163 case when j_debit='t' then j_montant else 0 end as deb,
164 case when j_debit='f' then j_montant else 0 end as cred
165 from jrnx join tmp_pcmn on (j_poste=pcm_val)
166 left join parm_periode on (j_tech_per = p_id)
167 join jrn_def on (j_jrn_def=jrn_def_id)
168 join jrn on (j_grpt=jr_grpt_id)
170 $jrn $from_poste $to_poste
171 $and $filter_sql and $per_sql_previous) as sub_p group by j_poste order by j_poste)
172 select coalesce(m.j_poste,p.j_poste) as poste
173 ,coalesce(m.sdeb,0) as sum_deb
174 , coalesce(m.scred,0) as sum_cred
175 ,coalesce(p.sdeb,0) as sum_deb_previous
176 , coalesce(p.scred,0) as sum_cred_previous
177 ,coalesce(sum_deb_ope,0) as sum_deb_ope
178 ,coalesce(sum_cred_ope,0) as sum_cred_ope
179 from m full join p on (p.j_poste=m.j_poste)
182 }
catch (Exception $exc) {
187 $sql=
"select j_poste as poste,
189 sum(cred) as sum_cred,
190 sum(deb_op) as sum_deb_ope ,
191 sum(cred_op) as sum_cred_ope
194 case when j_debit='t' then j_montant else 0 end as deb,
195 case when j_debit='f' then j_montant else 0 end as cred,
196 case when j_debit='t' and jr_optype='OPE' then j_montant else 0 end as deb_op,
197 case when j_debit='f' and jr_optype='OPE' then j_montant else 0 end as cred_op
198 from jrnx join tmp_pcmn on (j_poste=pcm_val)
199 left join parm_periode on (j_tech_per = p_id)
200 join jrn_def on (j_jrn_def=jrn_def_id)
201 join jrn on (j_grpt=jr_grpt_id)
203 $jrn $from_poste $to_poste
206 $per_sql ) as m group by poste order by poste";
219 $tot_deb_saldo_ope=0.0;
220 $tot_cred_saldo_ope=0.0;
221 $tot_cred_previous= 0.0;
222 $tot_deb_previous= 0.0;
223 $tot_deb_saldo_previous=0.0;
224 $tot_cred_saldo_previous=0.0;
225 $M=$this->
db->size();
233 $a[
'poste']=
$r[
'poste'];
234 $a[
'label']=mb_substr(
$poste->get_lib(),0,40);
235 $a[
'type']=
$poste->get_parameter(
"pcm_type");
236 $a[
'sum_deb']=round(
$r[
'sum_deb'],2);
237 $a[
'sum_cred']=round(
$r[
'sum_cred'],2);
238 $a[
'solde_deb']=round((
$a[
'sum_deb'] >=
$a[
'sum_cred'] )?
$a[
'sum_deb']-
$a[
'sum_cred']:0,2);
239 $a[
'solde_cred']=round((
$a[
'sum_deb'] <=
$a[
'sum_cred'] )?
$a[
'sum_cred']-
$a[
'sum_deb']:0,2);
241 $a[
'sum_deb_ope']=round(
$r[
'sum_deb_ope'],2);
242 $a[
'sum_cred_ope']=round(
$r[
'sum_cred_ope'],2);
243 $a[
'solde_deb_ope']=round((
$a[
'sum_deb_ope'] >=
$a[
'sum_cred_ope'] )?
$a[
'sum_deb_ope']-
$a[
'sum_cred_ope']:0,2);
244 $a[
'solde_cred_ope']=round((
$a[
'sum_deb_ope'] <=
$a[
'sum_cred_ope'] )?
$a[
'sum_cred_ope']-
$a[
'sum_deb_ope']:0,2);
247 if ($p_previous_exc==1)
249 $a[
'sum_deb_previous']=round(
$r[
'sum_deb_previous'],2);
250 $a[
'sum_cred_previous']=round(
$r[
'sum_cred_previous'],2);
251 $a[
'solde_deb_previous']=round((
$a[
'sum_deb_previous'] >=
$a[
'sum_cred_previous'] )?
$a[
'sum_deb_previous']-
$a[
'sum_cred_previous']:0,2);
252 $a[
'solde_cred_previous']=round((
$a[
'sum_deb_previous'] <=
$a[
'sum_cred_previous'] )?
$a[
'sum_cred_previous']-
$a[
'sum_deb_previous']:0,2);
253 $tot_cred_previous = bcadd ($tot_cred_previous,
$a[
'sum_cred_previous']);
254 $tot_deb_previous = bcadd( $tot_deb_previous,
$a[
'sum_deb_previous']);
255 $tot_deb_saldo_previous = bcadd ($tot_deb_saldo_previous ,
$a[
'solde_deb_previous']);
256 $tot_cred_saldo_previous = bcadd ($tot_cred_saldo_previous,
$a[
'solde_cred_previous']);
258 if ($p_previous_exc==0 && $this->unsold==
true &&
$a[
'solde_cred']==0 &&
$a[
'solde_deb']==0)
continue;
259 if ($p_previous_exc==1 && $this->unsold==
true &&
$a[
'solde_cred']==0 &&
$a[
'solde_deb']==0 &&
$a[
'solde_cred_previous']==0 &&
$a[
'solde_deb_previous']==0)
continue;
264 $tot_deb_saldo= bcadd($tot_deb_saldo,
$a[
'solde_deb']);
265 $tot_cred_saldo= bcadd($tot_cred_saldo,
$a[
'solde_cred']);
267 $tot_cred_ope= bcadd ($tot_cred_ope,
$a[
'sum_cred_ope']);
268 $tot_deb_ope= bcadd($tot_deb_ope,
$a[
'sum_deb_ope']);
269 $tot_deb_saldo_ope= bcadd($tot_deb_saldo_ope,
$a[
'solde_deb_ope']);
270 $tot_cred_saldo_ope= bcadd($tot_cred_saldo_ope,
$a[
'solde_cred_ope']);
280 $a[
'label']=sprintf(
_(
"Totaux delta %s %s"),
nbm(abs(
$delta)),$side_delta);
283 $a[
'solde_deb']=$tot_deb_saldo;
284 $a[
'solde_cred']=$tot_cred_saldo;
285 $a[
'sum_deb_ope']=$tot_deb_ope;
286 $a[
'sum_cred_ope']=$tot_cred_ope;
287 $a[
'solde_deb_ope']=$tot_deb_saldo_ope;
288 $a[
'solde_cred_ope']=$tot_cred_saldo_ope;
289 if ($p_previous_exc==1) {
290 $a[
'sum_deb_previous']=$tot_deb_previous;
291 $a[
'sum_cred_previous']=$tot_cred_previous;
292 $a[
'solde_deb_previous']=$tot_deb_saldo_previous;
293 $a[
'solde_cred_previous']=$tot_cred_saldo_previous;
320 $t_a=$this->
db->get_array(
'select jrn_def_id from jrn_def where jrn_def_type=$1',array(
$array[
$e][
'cat']));
321 for (
$f=0;
$f < count($t_a);
$f++) $this->
jrn[]=$t_a[
$f][
'jrn_def_id'];
332 $array[
"1_5"]=[
"deb"=>0,
"cred"=>0];
333 $array[
"6"]=[
"deb"=>0,
"cred"=>0];
334 $array[
"7"]=[
"deb"=>0,
"cred"=>0];
350 if (trim($p_accounting)==
"")
return $p_array;
352 $first_digit=trim($p_accounting);
353 $first_digit_trim=$first_digit[0];
354 if ( $first_digit_trim >0 && $first_digit_trim < 6) {
358 elseif ($first_digit_trim ==
"6") {
362 elseif ($first_digit_trim==
"7") {
378 echo
td(
_(
"Class 1-5"));
386 echo
td(
_(
"Class 6"));
388 echo
td(
nbm(abs($diff6),2),
' class="num"');
389 $side=($diff6 < 0)?
"C":
"D";
394 echo
td(
_(
"Class 7"));
396 echo
td(
nbm(abs($diff7),2),
' class="num"');
397 $side=($diff7 < 0)?
"C":
"D";
402 echo
td(
_(
"Solde 6/7"));
403 $diff=bcadd($diff6,$diff7);
419 $p_pdf->write_cell(30,6,
_(
"Class 1-5"));
421 $p_pdf->write_cell(50,6,
425 $p_pdf->write_cell(10,6,
$side);
428 $p_pdf->write_cell(30,6,
_(
"Class 6"));
430 $p_pdf->write_cell(50,6,
nbm(abs($diff6),2),0,0,
'R');
431 $side=($diff6 < 0)?
"C":
"D";
433 $p_pdf->write_cell(10,6,
$side);
436 $p_pdf->write_cell(30,6,
_(
"Class 7"));
438 $p_pdf->write_cell(50,6,
nbm(abs($diff7),2),0,0,
'R');
439 $side=($diff7 < 0)?
"C":
"D";
441 $p_pdf->write_cell(10,6,
$side);
444 $p_pdf->write_cell(30,6,
_(
"Solde 6/7"));
445 $diff=bcadd($diff6,$diff7);
446 $p_pdf->write_cell(50,6,
nbm(abs(
$diff),2),0,0,
'R');
449 $p_pdf->write_cell(10,6,
$side);
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.
$anc_grandlivre from_poste
summary_add($p_array, $p_accounting, $p_deb, $p_cred)
Add the current amount (d /c) to the right item in the array, in order to compute a summary (1 to 5 ,...