25 require_once NOALYSS_INCLUDE.
'/lib/class_ibutton.php';
26 require_once NOALYSS_INCLUDE.
'/lib/class_ihidden.php';
27 require_once NOALYSS_INCLUDE.
'/lib/class_iselect.php';
28 require_once NOALYSS_INCLUDE.
'/lib/class_itext.php';
29 require_once NOALYSS_INCLUDE.
'/class/class_anc_plan.php';
30 require_once NOALYSS_INCLUDE.
'/lib/user_common.php';
70 $this->oa_jrnx_id_source=null;
71 $this->oa_positive=
'Y';
80 function add($p_seq=0)
83 if ( $this->oa_group == 0)
85 $this->oa_group=$this->
db->get_next_seq(
's_oa_group');
88 if ( $this->j_id == 0 )
93 if ( $this->oa_jrnx_id_source == null)
95 $side=$this->
db->get_value(
'select j_debit from jrnx where j_id=$1',
99 $side=$this->
db->get_value(
'select j_debit from jrnx where j_id=$1',
100 array($this->oa_jrnx_id_source));
102 $this->oa_debit=
$side;
107 if ( $this->oa_amount == 0 || $this->po_id==-1)
110 if ( $this->oa_amount< 0)
113 $this->oa_positive=
'N';
114 $this->oa_debit=($this->oa_debit==
't')?
'f':
't';
117 $oa_row=(isset($this->oa_row))?$this->oa_row:null;
118 $sql=
"insert into operation_analytique (
129 ) values ($1,$2,$3,$4,$5,$6,to_date($7,'DD.MM.YYYY'),$8,$9,$10)";
131 $this->
db->exec_sql(
$sql,array(
133 abs($this->oa_amount),
134 $this->oa_description,
140 $this->oa_jrnx_id_source,
150 $sql=
"delete from operation_analytique where oa_id=$1";
152 $this->
db->exec_sql(
$sql,array($this->oa_id));
157 function get_list($p_from,$p_to,$p_from_poste=
"",$p_to_poste=
"")
163 $cond=
"and (jr_date >= to_date('$p_from','DD.MM.YYYY') or oa_date >= to_date('$p_from','DD.MM.YYYY') )";
165 $cond.=
"and (jr_date <=to_date('$p_to','DD.MM.YYYY') or oa_date <=to_date('$p_to','DD.MM.YYYY')) ";
167 if ($p_from_poste !=
"" )
168 $cond_poste=
" and upper(po_name) >= upper('".$p_from_poste.
"')";
169 if ($p_to_poste !=
"" )
170 $cond_poste.=
" and upper(po_name) <= upper('".$p_to_poste.
"')";
172 if ( isset ( $this->pa_id) && $this->pa_id !=
'')
173 $pa_id_cond=
"pa_id=".$this->pa_id.
" and";
181 (case when jr_date is not null then to_char(jr_date,'DD.MM.YYYY') else to_char(oa_date,'DD.MM.YYYY') end ) as oa_date,
190 ( select ad_value from fiche_Detail where f_id=jrnx.f_id and ad_id=23) as qcode,
192 from operation_analytique as B join poste_analytique using(po_id)
193 left join jrnx using (j_id)
194 left join jrn on (j_grpt=jr_grpt_id)
195 where $pa_id_cond oa_amount <> 0.0 $cond $cond_poste
196 order by jr_date,oa_group,oa_debit desc,oa_id";
198 $RetSql=$this->
db->exec_sql(
$sql);
220 return "Pas d'enregistrement trouvé";
223 $step=$_SESSION[
'g_pagesize'];
242 foreach ($view as
$row)
244 $group=$row[
'oa_group'];
245 if ( $group !=$oldgroup )
251 $efface->javascript=
"anc_remove_operation(".$gDossier.
",".$oldgroup.
")";
252 $efface->name=
"Efface";
253 $efface->label=
"Efface";
254 $ret.=
"<td>".$efface->input().
"</td>";
256 $this->oa_group=$oldgroup;
263 $detail->javascript=
"viewOperation($jr_id,$gDossier)";
266 $ret.=
"<td>".$detail->input().
"</td>";
271 $ret.=
'<table id="'.$row[
'oa_group'].
'" class="result">';
273 $ret.=
"<tr class=\"highlight\">".
281 "Groupe id : ".$row[
'oa_group'].
290 $cred= ( $row[
'oa_debit'] ==
'f')?
"CREDIT":
"DEBIT";
291 $ret.=
"<tr class=\"$class\">";
296 $ret.=
td(
h($row[
'po_description']));
298 $ret.=
'<td class="num">'.
nbm($row[
'oa_amount']).
309 $efface->javascript=
"anc_remove_operation(".
"$gDossier,".$oldgroup.
")";
310 $efface->name=
"Efface";
311 $efface->label=
"Efface";
312 $ret.=
"<td>".$efface->input().
"</td>";
314 $this->oa_group=$oldgroup;
319 $detail->javascript=
"modifyOperation($jr_id,'".$gDossier.
"')";
322 $ret.=
"<td>".$detail->input().
"</td>";
335 $a_plan=$this->
db->get_array(
'select pa_id from plan_analytique order by pa_id');
340 $a_rowcount=$this->
db->get_array(
"select distinct oa_row "
341 .
" from operation_analytique where j_id=$1 order by oa_row", array($p_jid));
343 for ($i=0; $i<count($a_rowcount); $i++)
348 $a_existing=$this->
db->get_array(
'
349 select distinct oa_id,
360 from operation_analytique join poste_analytique using (po_id)
362 j_id=$1 and oa_row = $2
363 order by j_id,oa_row',
364 array($p_jid, $a_rowcount[$i][
'oa_row']));
367 $template=$a_existing[0];
371 for ($j=0; $j<count($a_plan); $j++)
376 $a_fetch=$this->
db->get_array(
'
377 select distinct oa_id,
388 from operation_analytique join poste_analytique using (po_id)
390 j_id=$1 and oa_row = $2 and pa_id=$3', array($p_jid,
391 $a_rowcount[$i][
'oa_row'],
395 if (count($a_fetch)==0)
398 $a_fetch[
'pa_id']=$a_plan[$j][
'pa_id'];
399 $a_fetch[
'po_id']=-1;
400 $a_fetch[
'oa_id']=
'';
404 if (count($a_fetch)==1)
414 foreach ($row as $attr=>
$value)
416 $a->$attr=$row[$attr];
434 $sql=
"select jr_date,j_montant,j_debit from jrnx ".
435 " join jrn on (jr_grpt_id = j_grpt) ".
436 "where j_id=".$this->j_id;
440 $this->oa_amount=
$row[
'j_amount'];
441 $this->oa_date=
$row[
'jr_date'];
442 $this->oa_debit=
$row[
'j_debit'];
443 $this->oa_description=
$row[
'jr_comment'];
450 if ( $row->pa_id == $this->pa_id )
452 $row->po_id=$p_po_id;
461 $sql=
"select distinct jr_id from jrn join jrnx on (j_grpt=jr_grpt_id) join operation_analytique using (j_id) where j_id is not null and oa_group=".$this->oa_group;
465 return $ret[0][
'jr_id'];
476 $sql=
"select oa_id, po_id, oa_amount, oa_debit, j_date from jrnx join operation_analytique using (j_id)
477 join poste_analytique using (po_id)
479 $cond and j_id is not null and pa_id=$p_plan_id";
483 $sql=
"union select oa_id, po_id, oa_amount, oa_debit,oa_date from
485 join poste_analytique using (po_id)
486 where j_id is null and
487 $cond and pa_id=$p_plan_id ";
542 $a_plan=$plan->get_list(
" order by pa_id ");
543 if ( empty ($a_plan) )
return "";
547 $readonly=($p_mode==1)?
false:
true;
551 $result.=
'<table id="'.$p_id.$table_id.
'">';
554 $result.=
"<tr>".$plan->header().
"<th>montant</th></tr>";
560 $remain=abs($p_amount);
561 $ctrl_remain=
"remain".$this->in_div.$table_id;
567 foreach ($a_plan as $r_plan)
571 "select po_id as value,".
572 " html_quote(po_name) as label from poste_analytique ".
573 " where pa_id = ".$r_plan[
'id'].
574 " order by po_name",$p_null);
582 if ( isset($hplan) && isset($hplan[$p_seq][
$count]) ){
589 if ( isset($hplan) && isset($hplan[$p_seq][
$count]) ){
596 $result.=
'<td>'.$select->input().
'</td>';
598 $result.=
'<td>'.$select->display().
'</td>';
604 $value->javascript=
'onchange="format_number(this);anc_refresh_remain(\''.$this->in_div.$table_id.
'\',\
''.$p_seq.
'\')
"';
605 $value->name="val[
".$p_seq."][]
";
607 $value->value=(isset($val[$p_seq][$i]))?$val[$p_seq][$i]:abs($p_amount);
608 $value->value=round($value->value,2);
609 $value->readOnly=($p_mode==1)?false:true;
610 $remain=bcsub($remain,$value->value);
611 $result.='<td>'.$value->input().'</td>';
618 if ($p_add_button && $p_mode == 1)
620 $style_remain=($remain==0)?'style="color:green
"':' style="color:red
"';
621 $result.=" "._("Reste
")." =
".
622 '<span class="remain
" '.$style_remain.' id="'.$ctrl_remain.'">'.
624 // add a button to add a row
625 $button=new IButton();
626 $button->javascript="add_row(
'".$p_id."$table_id',$p_seq);
";
627 $button->name="js
".$p_id.$p_seq;
628 $button->label=_("Nouvelle ligne
");
630 $result.="<br>
".$button->input();
635 $ledger=HtmlInput::default_value_post("p_jrn
", 0);
637 $ledger=$this->db->get_value('select j_jrn_def from jrnx where j_id=$1',array($this->j_id));
639 $gDossier=Dossier::id();
640 $button_key=new IButton();
641 $button_key->javascript="anc_key_choice(
".$gDossier.",
'".$p_id."$table_id',$p_amount,
'".$ledger."');
";
642 $button_key->name="js
".$p_id.$p_seq;
643 $button_key->label=_("Clef
");
644 $result .= $button_key->input();
660 function save_form_plan_vat_nd($p_array,$p_item,$p_j_id,$p_nd)
663 extract($p_array, EXTR_SKIP);
664 if (! isset ($hplan) ) return;
666 if ( ! isset(${'amount_t'.$p_item}) )
667 throw new Exception ('amount not set');
670 /* variable for in array
671 pa_id array of existing pa_id
672 hplan double array with the pa_id (column)
673 val double array by row with amount
675 p_item is used to identify what op is concerned
677 /* echo "j_id =
$j_id p_item = $p_item hplan=
".var_export($hplan[$p_item],true)." val =
".var_export($val[$p_item],true).'<br>'; */
679 // for ($i=0;$i<count($val[$p_item]);$i++) {
682 $a_Anc_Operation=array();
684 for ($e=0;$e<count($hplan[$p_item]);$e++)
686 if ( $idx_pa_id == count($pa_id))
691 if ($hplan[$p_item][$e] != -1 && $val[$p_item][$row] != '')
693 $op=new Anc_Operation($this->db);
694 $op->po_id=$hplan[$p_item][$e];
695 $op->oa_group=$this->oa_group;
697 $ratio=bcdiv($val[$p_item][$row],${"amount_t
".$p_item});
698 $amount= bcmul($p_nd, $ratio);
699 $op->oa_amount=round($amount,2);
700 $op->oa_debit=$this->oa_debit;
701 $op->oa_date=$this->oa_date;
703 $op->oa_description=$this->oa_description;
705 $op->oa_jrnx_id_source=$this->oa_jrnx_id_source;
706 $a_Anc_Operation[]=clone $op;
710 $nb_op=count($a_Anc_Operation);
712 for ($i=0;$i<$nb_op;$i++)
714 $tot=bcadd($tot,$a_Anc_Operation[$i]->oa_amount);
716 if ( $tot != $p_nd && count($a_Anc_Operation) > 0 )
718 $diff= bcsub($tot, $p_nd);
719 $a_Anc_Operation[0]->oa_amount=bcsub($a_Anc_Operation[0]->oa_amount,$diff);
721 for ($i=0;$i<$nb_op;$i++)
723 $a_Anc_Operation[$i]->add();
747 function save_form_plan($p_array,$p_item,$p_j_id)
749 extract($p_array, EXTR_SKIP);
750 if (! isset ($hplan) ) return;
751 /* variable for in array
752 pa_id array of existing pa_id
753 hplan double array with the pa_id (column)
754 val double array by row with amount
756 p_item is used to identify what op is concerned
762 if ( ! isset ($hplan[$p_item])) return;
764 for ($e=0;$e<count($hplan[$p_item]);$e++)
766 if ( $idx_pa_id == count($pa_id))
771 if ($hplan[$p_item][$e] != -1 && $val[$p_item][$row] != '')
773 $op=new Anc_Operation($this->db);
774 $op->po_id=$hplan[$p_item][$e];
775 $op->oa_group=$this->oa_group;
777 $op->oa_amount=$val[$p_item][$row];
778 $op->oa_debit=$this->oa_debit;
779 $op->oa_date=$this->oa_date;
781 $op->oa_description=$this->oa_description;
800 function save_update_form($p_array)
802 extract($p_array, EXTR_SKIP);
803 if ( ! isset($opanc)) return;
804 for ($i = 0; $i < count($opanc); $i++)
806 /* clean operation_analytique */
807 $this->db->exec_sql('delete from operation_analytique where j_id=$1', array($opanc[$i]));
809 /* get missing data for adding */
810 $a_missing = $this->db->get_array("select to_char(jr_date,
'DD.MM.YYYY')
811 as mdate,j_montant,j_debit,jr_comment ,j_poste
812 from jrnx join
jrn on (j_grpt=jr_grpt_id) where j_id=$1", array($opanc[$i]));
813 $missing = $a_missing[0];
815 $this->oa_description = $missing['jr_comment'];
816 $this->j_id = $opanc[$i];
817 $group = $this->
db->get_next_seq("s_oa_group");
818 $this->oa_group = $group;
819 $this->oa_date = $missing['mdate'];
823 $a_nd = $this->
db->get_array('select j_id
from operation_analytique
824 where oa_jrnx_id_source=$1', array($opanc[$i]));
825 if (count($a_nd) > 0)
828 for (
$e=0;
$e<count($a_nd);
$e++)
830 $this->
db->exec_sql(
'delete from operation_analytique where j_id=$1', array($a_nd[
$e][
'j_id']));
832 $a_missing_vat = $this->
db->get_array(
"select to_char(jr_date,'DD.MM.YYYY') as mdate,j_montant,j_debit,jr_comment from jrnx join jrn on (j_grpt=jr_grpt_id) where j_id=$1", array($a_nd[$e][
'j_id']));
833 $missing_vat = $a_missing_vat[0];
834 $this->oa_debit =
't';
835 $this->oa_description = $missing_vat[
'jr_comment'];
836 $this->j_id = $opanc[$i];
837 $group = $this->
db->get_next_seq(
"s_oa_group");
838 $this->oa_group = $group;
839 $this->oa_date = $missing_vat[
'mdate'];
840 $this->oa_jrnx_id_source=$opanc[$i];
841 $p_array[
'amount_t'.$i]=$missing[
'j_montant'];
857 $result[]=array(
'op'=>$this->j_id);
861 for ($i=0;$i < count(
$p_array);$i++)
870 for ($i=0;$i < count(
$p_array);$i++)
872 $hplan[$p_line][$i]=
$p_array[$i]->po_id;
877 $jrn_def=$this->
db->get_value(
'select jrn_def_type from jrnx join jrn_def on (j_jrn_def=jrn_def_id) where j_id=$1',array($this->j_id));
878 for ($i=0;$i < count(
$p_array);$i++)
884 if ( $jrn_def !=
'FIN')
886 $val[$p_line][
$p_array[$i]->oa_row]=($p_array[$i]->oa_positive==
'Y')?$p_array[$i]->oa_amount:($p_array[$i]->oa_amount*(-1));
890 $val[$p_line][
$p_array[$i]->oa_row]=$p_array[$i]->oa_amount;
904 $sql=
"delete from operation_analytique where j_id=$1";
905 $this->
db->exec_sql(
$sql,array($p_jid));
926 return "<td>".$this->display_form_plan($request,1,$p_mode,
$seq,$p_amount,
$p_id).
"</td>";
930 return '<td>'.$this->display_form_plan(null,1,$p_mode,
$seq,$p_amount,
$p_id).
"</TD>";
952 echo dossier::hidden();
955 echo $anco->display_table(1,15002,0);
956 echo
'<input type="submit" name="save">';
get_list($p_from, $p_to, $p_from_poste="", $p_to_poste="")
get a list of row from a certain periode
static fetch_all($ret)
wrapper for the function pg_fetch_all
get_jrid()
retrieve the jr_id thanks the oa_group
this class is used to show the form for entering an operation only FOR analytic operation to save it...
td($p_string='', $p_extra='')
surround the string with td
get_balance($p_from, $p_to, $p_plan_id)
save_form_plan($p_array, $p_item, $p_j_id)
it called for each item, the data are taken from $p_array data and set before in this.
static num_row($ret)
wrapper for the function pg_NumRows
update_from_jrnx($p_po_id)
modify an op from modify_op.php
__construct($p_cn, $p_id=0)
constructor
nbm($p_number, $p_dec=2)
format the number with a sep.
Concerns the Analytic plan (table plan_analytique)
add($p_seq=0)
add a row to the table operation_analytique
display_table($p_mode, $p_amount, $p_id)
Display a table with analytic accounting in detail of operation.
static fetch_array($ret, $p_indice=0)
wrapper for the function pg_fetch_array
$oa_positive
signed of the amount
navigation_bar($p_offset, $p_line, $p_size=0, $p_page=1, $p_javascript="")
Create a navigation_bar (pagesize)
For the periode tables parm_periode and jrn_periode.
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.
save_form_plan_vat_nd($p_array, $p_item, $p_j_id, $p_nd)
Save the ND VAT with prorata.
function anc_key_choice(p_dossier, p_table, p_amount, p_ledger)
choose the distribution key in ajax, a window let you choose what key you want to use ...
if(!isset($_REQUEST['p_jrn'])) else $Ledger id
delete_by_jid($p_jid)
delete from operation_analytique
h($p_string)
to protect again bad characters which can lead to a cross scripting attack the string to be diplayed ...
display_form_plan($p_array, $p_null, $p_mode, $p_seq, $p_amount, $p_id='', $p_add_button=true)
display the form for PA
tr($p_string, $p_extra='')
to_request($p_array, $p_line)
function add_row(p_table, p_seq)
add a row for the CA
$oa_jrnx_id_source
In the case, the amount comes from a ND VAT, the variable contents the jrnx.j_id of the source which ...
get_by_jid($p_jid)
retrieve an operation thanks a jrnx.j_id
This class handles only the numeric input, the input will call a javascript to change comma to period...