50 parent::__construct(
$cn, $pa_ledger, $p_from, $p_to, $p_mode);
52 $this->ledger_type=
'ODS';
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');
111 if ($a_ParmCode==
null)
114 $a_ParmCode=$this->
db->get_array(
'select p_code,p_value from parm_code');
135 $nb_tva=count($a_TVA);
136 for (
$i=0;
$i<$nb_tva;
$i++)
140 $a_TVA[
$i][
'tva_id'],
141 $a_TVA[
$i][
'tva_label'],
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
161 group by qp_supplier,qp_vat_code,qp_vat_sided ";
165 sum(coalesce(qs_price,0)) as htva,
166 sum(coalesce(qs_vat)) as vat,
168 sum(0) as nd_tva_recup,
170 qs_vat_code as tva_code,
171 qs_client as fiche_id,
172 qs_vat_sided as tva_sided
177 group by qs_client,qs_vat_code,qs_vat_sided ";
204 $nb_tva=count($a_TVA);
205 for ($j=0; $j<$nb_tva; $j++)
207 if ($xdx==
$p_array[
'TVA'][$j][1][0])
222 $sql=
"select j_id,j_poste,j_montant, j_debit,j_qcode from jrnx where ".
223 " j_grpt=$1 order by 1 desc";
229 if ( $data_jrnx == FALSE ){
232 foreach ($data_jrnx as
$code)
241 $fiche->get_by_qcode(trim(
$code[
'j_qcode']),
false);
242 $fiche_def_id=
$fiche->get_fiche_def_ref_id();
282 if ($p_jrn_type==
'ACH'&&
$code[
'j_debit']==
't')
287 if ($p_jrn_type==
'VEN'&&
$code[
'j_debit']==
'f')
296 foreach ($a_TVA as $line_tva)
298 list($tva_deb, $tva_cred)=explode(
',', $line_tva[
'tva_poste']);
299 if (
$code[
'j_poste']==$tva_deb||
300 $code[
'j_poste']==$tva_cred)
304 if ($p_jrn_type==
'ACH'&&
$code[
'j_debit']==
'f')
308 if ($p_jrn_type==
'VEN'&&
$code[
'j_debit']==
't')
315 $p_array[
'TVA'][$c]=array($idx_tva, array($line_tva[
'tva_id'],
316 $line_tva[
'tva_label'],
$code[
'j_montant']));
326 if (
$p_array[
'jrn_def_type']==
'ACH')
328 $qp_id=$this->get_value(
"select qp_id from quant_purchase where j_id=$1",[
$code[
'j_id']]);
331 $dep_priv=bcadd ($dep_priv,$purchase->qp_dep_priv);
335 bcadd($purchase->qp_nd_tva, $purchase->qp_nd_tva_recup));
336 $p_array[
'tva_np']=bcadd($purchase->qp_vat_sided,
339 if (
$p_array[
'jrn_def_type']==
'VEN')
341 $qs_id=$this->
db->get_value(
"select qs_id from quant_sold where j_id=$1",array(
$code[
'j_id']));
350 $a_tva_amount=array();
352 foreach (
$p_array[
'TVA'] as $linetva)
354 foreach ($a_TVA as $tva)
356 if ($tva[
'tva_id']==$linetva[1][0])
359 $a_tva_amount[
$a]=$linetva[1][2];
363 foreach ($a_TVA as $line_tva)
365 $a=$line_tva[
'tva_id'];
366 if (isset($a_tva_amount[
$a]))
368 $tmp=sprintf(
"% 10.2f", $a_tva_amount[
$a]);
372 $r.=sprintf(
"% 10.2f", 0);
386 switch ($this->m_mode)
419 $jrn=
" jrn_def_id in (".join(
',',$this->ma_ledger).
")";
424 $cond_limite=($p_limit!=-1)?
" limit ".$p_limit.
" offset ".$p_offset:
"";
427 SELECT jrn.jr_id as jr_id ,
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,
436 jrn.jr_grpt_id as grpt_id,
437 jrn.jr_pj_name as pj,
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)
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)
454 j_id in (select j_id from jrnx where j_grpt=jrn2.jr_grpt_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";
510 $cond_limite=($p_limit!=-1)?
" limit ".$p_limit.
" offset ".$p_offset:
"";
512 $ledger_list=join(
",",$this->ma_ledger);
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,
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,
524 jr_rapt as oc, j_tech_per as periode,
528 jrn.currency_rate_ref,
529 operation_currency.oc_amount,
530 operation_currency.oc_vat_amount
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.
")
538 order by j_date::date asc,substring(jr_pj_number,'[0-9]+$')::numeric asc,j_grpt,j_debit desc ".
556 $tot_op=
$line[
'jr_montant'];
563 if (
$fiche->get_by_qcode(
$line[
'j_qcode'],
false)==0)
568 if ($case!=
$line[
'grp'])
572 if (
$line[
'jrn_def_type']==
'FIN')
574 $amount=$this->
db->get_value(
'select qf_amount from quant_fin where jr_id=$1',
575 array(
$line[
'jr_id']));
577 if ($this->
db->count()==0)
578 $tot_op=
$line[
'jr_montant'];
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'],
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']);
601 'int_j_id'=>
$line[
'int_j_id'],
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'],
612 "ledger_type"=>
$line[
'jrn_def_type']
618 'jr_id'=>
$line[
'jr_id'],
619 'int_j_id'=>
$line[
'int_j_id'],
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'],
630 "ledger_type"=>
$line[
'jrn_def_type']);
660 echo
'<TABLE class="result">';
663 if ( empty ($this->data))
return;
664 foreach ($this->data[0] as
$op)
667 if (
$op[
'j_date']!=
'')
672 echo
"<TR class=\"$class\">";
674 echo
"<TD>".$op[
'j_date'].
"</TD>";
675 echo
"<TD >".$op[
'jr_pj_number'].
"</TD>";
678 if (
$op[
'internal']!=
'')
679 echo
"<TD>".HtmlInput::detail_op(
$op[
'jr_id'],
$op[
'internal']).
"</TD>";
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>".
693 echo _(
"solde débiteur:").$this->data[1].
"<br>";
694 echo _(
"solde créditeur:").$this->data[2];
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">';
711 th(_(
"Commentaire")).
713 th(_(
"Total opération")).
718 foreach ($this->data as
$line)
721 $class=(
$i%2==0)?
' class="even" ':
' class="odd" ';
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>";
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"');
742 if (
$line[
'jrn_def_type']==
'FIN')
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)
749 $positive=($positive>0)?1:0;
751 echo
"<TD align=\"right\">";
752 echo ( $positive==0 )?
"<font color=\"red\"> - ".nbm(
$line[
'montant']).
"</font>":
nbm(
$line[
'montant']);
765 echo
"<TD align=\"right\">".nbm(
$line[
'montant']).
"</TD>";
771 echo
'<tr class="highlight">';
772 echo
'<td>'._(
'Totaux').
'</td>';
773 echo
td().td().td().td().td();
808 if (count($this->data)==0)
811 foreach ($this->data[0] as
$idx=>
$op)
th($p_string, $p_extra='', $raw='')
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
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
h( $row[ 'oa_description'])
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...
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_FOURNISSEUR
for($e=0; $e< count($afiche); $e++) exit