48 parent::__construct(
$cn, $pa_ledger, $p_from, $p_to, $p_mode);
50 $this->ledger_type=
'ODS';
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');
109 if ($a_ParmCode==
null)
112 $a_ParmCode=$this->
db->get_array(
'select p_code,p_value from parm_code');
133 $nb_tva=count($a_TVA);
134 for (
$i=0;
$i<$nb_tva;
$i++)
138 $a_TVA[
$i][
'tva_id'],
139 $a_TVA[
$i][
'tva_label'],
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
159 group by qp_supplier,qp_vat_code,qp_vat_sided ";
163 sum(coalesce(qs_price,0)) as htva,
164 sum(coalesce(qs_vat)) as vat,
166 sum(0) as nd_tva_recup,
168 qs_vat_code as tva_code,
169 qs_client as fiche_id,
170 qs_vat_sided as tva_sided
175 group by qs_client,qs_vat_code,qs_vat_sided ";
202 $nb_tva=count($a_TVA);
203 for ($j=0; $j<$nb_tva; $j++)
205 if ($xdx==
$p_array[
'TVA'][$j][1][0])
220 $sql=
"select j_id,j_poste,j_montant, j_debit,j_qcode from jrnx where ".
221 " j_grpt=$1 order by 1 desc";
227 if ( $data_jrnx == FALSE ){
230 foreach ($data_jrnx as
$code)
239 $fiche->get_by_qcode(trim(
$code[
'j_qcode']),
false);
280 if ($p_jrn_type==
'ACH'&&
$code[
'j_debit']==
't')
285 if ($p_jrn_type==
'VEN'&&
$code[
'j_debit']==
'f')
294 foreach ($a_TVA as $line_tva)
296 list($tva_deb, $tva_cred)=explode(
',', $line_tva[
'tva_poste']);
297 if (
$code[
'j_poste']==$tva_deb||
298 $code[
'j_poste']==$tva_cred)
302 if ($p_jrn_type==
'ACH'&&
$code[
'j_debit']==
'f')
306 if ($p_jrn_type==
'VEN'&&
$code[
'j_debit']==
't')
313 $p_array[
'TVA'][
$c]=array($idx_tva, array($line_tva[
'tva_id'],
314 $line_tva[
'tva_label'],
$code[
'j_montant']));
324 if (
$p_array[
'jrn_def_type']==
'ACH')
326 $qp_id=$this->get_value(
"select qp_id from quant_purchase where j_id=$1",[
$code[
'j_id']]);
329 $dep_priv=bcadd ($dep_priv,$purchase->qp_dep_priv);
333 bcadd($purchase->qp_nd_tva, $purchase->qp_nd_tva_recup));
334 $p_array[
'tva_np']=bcadd($purchase->qp_vat_sided,
337 if (
$p_array[
'jrn_def_type']==
'VEN')
339 $qs_id=$this->
db->get_value(
"select qs_id from quant_sold where j_id=$1",array(
$code[
'j_id']));
348 $a_tva_amount=array();
350 foreach (
$p_array[
'TVA'] as $linetva)
352 foreach ($a_TVA as $tva)
354 if ($tva[
'tva_id']==$linetva[1][0])
357 $a_tva_amount[
$a]=$linetva[1][2];
361 foreach ($a_TVA as $line_tva)
363 $a=$line_tva[
'tva_id'];
364 if (isset($a_tva_amount[
$a]))
366 $tmp=sprintf(
"% 10.2f", $a_tva_amount[
$a]);
370 $r.=sprintf(
"% 10.2f", 0);
384 switch ($this->m_mode)
417 $jrn=
" jrn_def_id in (".join(
',',$this->ma_ledger).
")";
422 $cond_limite=($p_limit!=-1)?
" limit ".$p_limit.
" offset ".$p_offset:
"";
425 SELECT jrn.jr_id as jr_id ,
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,
435 jrn.jr_grpt_id as grpt_id,
436 jrn.jr_pj_name as pj,
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)
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)
453 j_id in (select j_id from jrnx where j_grpt=jrn2.jr_grpt_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";
509 $cond_limite=($p_limit!=-1)?
" limit ".$p_limit.
" offset ".$p_offset:
"";
511 $ledger_list=join(
",",$this->ma_ledger);
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,
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,
523 jr_rapt as oc, j_tech_per as periode,
527 jrn.currency_rate_ref,
528 operation_currency.oc_amount,
529 operation_currency.oc_vat_amount
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.
")
537 order by j_date::date asc,substring(jr_pj_number,'[0-9]+$')::numeric asc,j_grpt,j_debit desc ".
555 $tot_op=
$line[
'jr_montant'];
562 if (
$fiche->get_by_qcode(
$line[
'j_qcode'],
false)==0)
567 if ($case!=
$line[
'grp'])
571 if (
$line[
'jrn_def_type']==
'FIN')
573 $amount=$this->
db->get_value(
'select qf_amount from quant_fin where jr_id=$1',
574 array(
$line[
'jr_id']));
576 if ($this->
db->count()==0)
577 $tot_op=
$line[
'jr_montant'];
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'],
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']);
600 'int_j_id'=>
$line[
'int_j_id'],
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'],
611 "ledger_type"=>
$line[
'jrn_def_type']
617 'jr_id'=>
$line[
'jr_id'],
618 'int_j_id'=>
$line[
'int_j_id'],
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'],
629 "ledger_type"=>
$line[
'jrn_def_type']);
659 echo
'<TABLE class="result">';
662 if ( empty ($this->data))
return;
663 foreach ($this->data[0] as
$op)
666 if (
$op[
'j_date']!=
'')
671 echo
"<TR class=\"$class\">";
673 echo
"<TD>".$op[
'j_date'].
"</TD>";
674 echo
"<TD >".$op[
'jr_pj_number'].
"</TD>";
677 if (
$op[
'internal']!=
'')
678 echo
"<TD>".HtmlInput::detail_op(
$op[
'jr_id'],
$op[
'internal']).
"</TD>";
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>".
692 echo
_(
"solde débiteur:").$this->data[1].
"<br>";
693 echo
_(
"solde créditeur:").$this->data[2];
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">';
710 th(
_(
"Commentaire")).
712 th(
_(
"Total opération")).
717 foreach ($this->data as
$line)
720 $class=(
$i%2==0)?
' class="even" ':
' class="odd" ';
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>";
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"');
741 if (
$line[
'jrn_def_type']==
'FIN')
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)
748 $positive=($positive>0)?1:0;
750 echo
"<TD align=\"right\">";
751 echo ( $positive==0 )?
"<font color=\"red\"> - ".nbm(
$line[
'montant']).
"</font>":
nbm(
$line[
'montant']);
764 echo
"<TD align=\"right\">".nbm(
$line[
'montant']).
"</TD>";
770 echo
'<tr class="highlight">';
771 echo
'<td>'._(
'Totaux').
'</td>';
772 echo
td().td().td().td().td();
807 if (count($this->data)==0)
810 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'])
_("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.
const FICHE_TYPE_FOURNISSEUR
for($e=0; $e< count($afiche); $e++) exit