25require_once NOALYSS_INCLUDE.
'/lib/user_common.php';
104 $this->oa_jrnx_id_source=
null;
105 $this->oa_positive=
'Y';
109 $this->currency_rate=1;
119 if ( $this->oa_group == 0)
121 $this->oa_group=$this->
db->get_next_seq(
's_oa_group');
124 if ( $this->j_id == 0 )
129 if ( $this->oa_jrnx_id_source ==
null)
131 $side=$this->
db->get_value(
'select j_debit from jrnx where j_id=$1',
135 $side=$this->
db->get_value(
'select j_debit from jrnx where j_id=$1',
136 array($this->oa_jrnx_id_source));
138 $this->oa_debit=
$side;
143 if ( $this->oa_amount == 0 || $this->po_id==-1)
146 if ( $this->oa_amount< 0)
149 $this->oa_positive=
'N';
150 $this->oa_debit=($this->oa_debit==
't')?
'f':
't';
155 if ( $this->card !=
"") {
157 $fiche->get_by_qcode($this->card);
160 $n_fid=($n_fid!=0)?$n_fid:NULL;
161 $oa_row=(isset($this->oa_row))?$this->oa_row:
null;
162 $sql=
"insert into operation_analytique (
174 ) values ($1,$2,$3,$4,$5,$6,to_date($7,'DD.MM.YYYY'),$8,$9,$10,$11)";
176 $this->
db->exec_sql(
$sql,array(
178 abs($this->oa_amount),
179 $this->oa_description,
185 $this->oa_jrnx_id_source,
196 $sql=
"delete from operation_analytique where oa_id=$1";
198 $this->
db->exec_sql(
$sql,array($this->oa_id));
207 $cond=
"$where (oa_date >= to_date('$p_from','DD.MM.YYYY') or oa_date >= to_date('$p_from','DD.MM.YYYY') )";
211 $cond.=
"$where (oa_date <=to_date('$p_to','DD.MM.YYYY') or oa_date <=to_date('$p_to','DD.MM.YYYY')) ";
215 $cond .= $where.
" j_id is null ";
218 select distinct oa_group,
219 to_char(oa_date,'DD.MM.YYYY') as str_date ,
223 operation_analytique as oa
226 return $this->
db->get_array(
$sql);
232 function get_list($p_from,$p_to,$p_from_poste=
"",$p_to_poste=
"")
238 $cond=
"and (jr_date >= to_date('$p_from','DD.MM.YYYY') or oa_date >= to_date('$p_from','DD.MM.YYYY') )";
240 $cond.=
"and (jr_date <=to_date('$p_to','DD.MM.YYYY') or oa_date <=to_date('$p_to','DD.MM.YYYY')) ";
242 if ($p_from_poste !=
"" )
243 $cond_poste=
" and upper(po_name) >= upper('".$p_from_poste.
"')";
244 if ($p_to_poste !=
"" )
245 $cond_poste.=
" and upper(po_name) <= upper('".$p_to_poste.
"')";
247 if ( isset ( $this->
pa_id) && $this->
pa_id !=
'')
248 $pa_id_cond=
"pa_id=".$this->pa_id.
" and";
251 select B.po_id as po_id,
257 (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,
258 (case when jr_date is not null then to_char(jr_date,'YYYYMMDD') else to_char(oa_date,'YYYYMMDD') end ) as str_order_date,
265 coalesce(jr_comment,b.oa_description) as jr_comment,
266 case when j_poste is null and b.f_id is not null then
267 (select ad_value from fiche_detail where fiche_detail.f_id=b.f_id and ad_id=".ATTR_DEF_ACCOUNT.
")
268 when j_poste is not null then
272 coalesce(jrnx.f_id,b.f_id) as f_id,
273 case when jrnx.f_id is not null then
274 (select ad_value from fiche_Detail where f_id=jrnx.f_id and ad_id=23)
275 when b.f_id is not null then
276 (select ad_value from fiche_Detail where f_id=b.f_id and ad_id=23)
280 from operation_analytique as B join poste_analytique using(po_id)
281 left join jrnx using (j_id)
282 left join jrn on (j_grpt=jr_grpt_id)
283 where $pa_id_cond oa_amount <> 0.0 $cond $cond_poste
284 order by jr_date,oa_group,oa_debit desc,oa_id";
286 $RetSql=$this->
db->exec_sql(
$sql);
302 $p=
new Periode($this->
db);
309 return _(
"Pas d'enregistrement trouvé");
312 $step=$_SESSION[SESSION_KEY.
'g_pagesize'];
313 $page=(isset(
$_GET[
'offset']))?
$_GET[
'page']:1;
330 $ret.=
_(
"Chercher").
" ".HtmlInput::filter_table(
"anc_operation_list_tb",
'0,1,2', 1);
331 $ret.=
"<table id=\"anc_operation_list_tb\"class=\"result\">";
337 foreach ($view as
$row)
339 $class=(
$i%2 == 0)?
'class="even"':
' class="odd"';
342 if ( $oldgroup <>
$row[
'oa_group']) {
343 $oldgroup=
$row[
'oa_group'];
345 $row_id=sprintf(
'id="tr%s"',$oldgroup);
347 $ret.=
"<tr $row_id $class>";
350 $js=
"anc_remove_operation(".$gDossier.
",".$oldgroup.
")";
352 $ret.=
"<td>".Icon_Action::trash(uniqid(),
$js) .
"</td>";
353 $js=
"anc_detail_op({$row['oa_group']},{$gDossier})";
369 $a_plan=$this->
db->get_array(
'select pa_id from plan_analytique order by pa_id');
374 $a_rowcount=$this->
db->get_array(
"select distinct oa_row "
375 .
" from operation_analytique where j_id=$1 order by oa_row", array($p_jid));
377 for (
$i=0;
$i<count($a_rowcount);
$i++)
382 $a_existing=$this->
db->get_array(
'
383 select distinct oa_id,
394 from operation_analytique join poste_analytique using (po_id)
396 j_id=$1 and oa_row = $2
397 order by j_id,oa_row',
398 array($p_jid, $a_rowcount[
$i][
'oa_row']));
405 for ($j=0; $j<count(
$a_plan); $j++)
410 $a_fetch=$this->
db->get_array(
'
411 select distinct oa_id,
422 from operation_analytique join poste_analytique using (po_id)
424 j_id=$1 and oa_row = $2 and pa_id=$3', array($p_jid,
425 $a_rowcount[
$i][
'oa_row'],
429 if (count($a_fetch)==0)
432 $a_fetch[
'pa_id']=
$a_plan[$j][
'pa_id'];
433 $a_fetch[
'po_id']=-1;
434 $a_fetch[
'oa_id']=
'';
438 if (count($a_fetch)==1)
468 $sql=
"select jr_date,j_montant,j_debit from jrnx ".
469 " join jrn on (jr_grpt_id = j_grpt) ".
470 "where j_id=".$this->j_id;
474 $this->oa_amount=
$row[
'j_amount'];
475 $this->oa_date=
$row[
'jr_date'];
476 $this->oa_debit=
$row[
'j_debit'];
477 $this->oa_description=
$row[
'jr_comment'];
484 if (
$row->pa_id == $this->pa_id )
486 $row->po_id=$p_po_id;
495 $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;
499 return $ret[0][
'jr_id'];
510 $sql=
"select oa_id, po_id, oa_amount, oa_debit, j_date from jrnx join operation_analytique using (j_id)
511 join poste_analytique using (po_id)
513 $cond and j_id is not null and pa_id=$p_plan_id";
517 $sql=
"union select oa_id, po_id, oa_amount, oa_debit,oa_date from
519 join poste_analytique using (po_id)
520 where j_id is null and
521 $cond and pa_id=$p_plan_id ";
577 $a_plan=$plan->get_list(
" order by pa_id ");
578 if ( empty (
$a_plan) )
return "";
586 $result .= sprintf(
'<input type="HIDDEN" id="amount_%s" class="%s%s-amount" name="amount_%s" value="%s">',
594 $result.=
'<table id="'.$p_id.$table_id.
'">';
600 $result.=
"<tr>".$plan->header().
"<th>".
_(
"montant").
"</th></tr>";
603 $nb_row=(isset($val[$p_seq]))?count($val[$p_seq]):1;
606 $remain=abs($p_amount);
607 $ctrl_remain=
"remain".$this->in_div.$table_id;
615 $existing=(isset($hplan[$p_seq][
$count]))?$hplan[$p_seq][
$count]:-1;
617 "select po_id as value,".
618 " html_quote(po_name) as label from poste_analytique ".
619 " where pa_id = $1 ".
620 " and ( po_state = 1 or po_id = $2) ".
621 " order by po_name",$p_null,[$r_plan[
'id'],$existing]);
629 if ( isset($hplan) && isset($hplan[$p_seq][
$count]) ){
636 if ( isset($hplan) && isset($hplan[$p_seq][
$count]) ){
644 $result.=
'<td>'.$select->input().
'</td>';
648 $result.=
'<td>'.$select->display().
'</td>';
655 $value->javascript=
'onchange="format_number(this);anc_refresh_remain(\''.$this->in_div.$table_id.
'\',\
''.$p_seq.
'\')
"';
656 $value->name=($readonly)?"ro
"."val[
".$p_seq."][]
":"val[
".$p_seq."][]
";
658 $value->value=(isset($val[$p_seq][$i]))?$val[$p_seq][$i]:abs($p_amount);
659 $value->value=round($value->value,2);
660 $value->style='class="inum
'.$this->in_div.$table_id.'-
value-
'.$p_seq.'"';
661 $value->readOnly=($p_mode==1)?false:true;
662 $remain=bcsub($remain,$value->value);
663 $result.='<td>'.$value->input().'</td>';
670 if ($p_add_button && $p_mode == 1)
672 $style_remain=($remain==0)?'style="color:green
"':' style="color:red
"';
673 $result.=" "._("Reste
")." =
".
674 '<span class="remain
" '.$style_remain.' id="'.$ctrl_remain.'">'.
676 // add a button to add a row
677 $button=new IButton();
678 $button->javascript="add_row(
'".$p_id."$table_id',$p_seq);
";
679 $button->name="js".$p_id.$p_seq;
680 $button->label=_("Nouvelle ligne
");
682 $result.="<br>
".$button->input();
687 $http=new HttpInput();
688 $ledger=$http->post("p_jrn
", "string",0);
690 $ledger=$this->db->get_value('select j_jrn_def from jrnx where j_id=$1',array($this->j_id));
692 $gDossier=Dossier::id();
693 $button_key=new IButton();
694 $button_key->javascript="anc_key_choice(
".$gDossier.",
'".$p_id."$table_id',$p_amount,
'".$ledger."');
";
695 $button_key->name="js".$p_id.$p_seq;
696 $button_key->label=_("Clef
");
697 $result .= $button_key->input();
701 $button_clean=new IButton();
702 $button_clean->javascript=sprintf("anc_key_clean(
'%s',
'%s',
'%s',
'%s',
'%s',
'%s');
",
710 $button_clean->name=uniqid();
711 $button_clean->label=_("Efface détail
");
712 $result.=$button_clean->input();
728 function save_form_plan_vat_nd($p_array,$p_item,$p_j_id,$p_nd):void
731 extract($p_array, EXTR_SKIP);
732 if (! isset ($hplan) ) return;
734 if ( ! isset(${'amount_t'.$p_item}) )
735 throw new Exception ('amount not set');
748 $a_Anc_Operation=array();
750 for ($e=0;$e<count($hplan[$p_item]);$e++)
752 if ( $idx_pa_id == count($pa_id))
757 if ($hplan[$p_item][$e] != -1 && $val[$p_item][$row] != '')
759 $op=new Anc_Operation($this->db);
760 $op->po_id=$hplan[$p_item][$e];
761 $op->oa_group=$this->oa_group;
764 if (${"amount_t
".$p_item} != 0 ) {
765 $ratio=bcdiv($val[$p_item][$row],${"amount_t
".$p_item});
767 $amount= bcmul($p_nd, $ratio);
769 $amount=bcmul($amount,$this->currency_rate);
770 $op->oa_amount=round($amount,2);
771 $op->oa_debit=$this->oa_debit;
772 $op->oa_date=$this->oa_date;
774 $op->oa_description=$this->oa_description;
776 $op->oa_jrnx_id_source=$this->oa_jrnx_id_source;
777 $a_Anc_Operation[]=clone $op;
781 $nb_op=count($a_Anc_Operation);
783 for ($i=0;$i<$nb_op;$i++)
785 $a_Anc_Operation[$i]->add();
877 function save_form_plan($p_array,$p_item,$p_j_id)
879 extract($p_array, EXTR_SKIP);
880 if (! isset ($hplan) ) return;
881 /* variable for in array
882 pa_id array of existing pa_id
883 hplan double array with the pa_id (column)
884 val double array by row with amount
886 p_item is used to identify what op is concerned
892 if ( ! isset ($hplan[$p_item])) return;
894 for ($e=0;$e<count($hplan[$p_item]);$e++)
896 if ( $idx_pa_id == count($pa_id))
901 if ($hplan[$p_item][$e] != -1 && $val[$p_item][$row] != '')
903 $op=new Anc_Operation($this->db);
904 $op->po_id=$hplan[$p_item][$e];
905 $op->oa_group=$this->oa_group;
907 // convert oa_amount to EUR
908 $op->oa_amount=bcdiv($val[$p_item][$row],$this->currency_rate,2);
909 $op->oa_debit=$this->oa_debit;
910 $op->oa_date=$this->oa_date;
912 $op->oa_description=$this->oa_description;
931 function save_update_form($p_array)
933 extract($p_array, EXTR_SKIP);
934 if ( ! isset($opanc)) return;
935 for ($i = 0; $i < count($opanc); $i++)
937 /* clean operation_analytique */
938 $this->db->exec_sql('delete from operation_analytique where j_id=$1', array($opanc[$i]));
940 /* get missing data for adding */
941 $a_missing = $this->db->get_array("select to_char(jr_date,
'DD.MM.YYYY')
942 as mdate,j_montant,j_debit,jr_comment ,j_poste
943 from jrnx join
jrn on (j_grpt=jr_grpt_id) where j_id=$1
", array($opanc[$i]));
944 $missing = $a_missing[0];
946 $this->oa_description = $missing['jr_comment'];
947 $this->j_id = $opanc[$i];
948 $group = $this->db->get_next_seq("s_oa_group
"); /* for analytic */
949 $this->oa_group = $group;
950 $this->oa_date = $missing['mdate'];
951 $this->save_form_plan($p_array, $i, $opanc[$i]);
953 // There is ND VAT amount
954 $a_nd = $this->db->get_array('select j_id from operation_analytique
955 where oa_jrnx_id_source=$1', array($opanc[$i]));
956 if (count($a_nd) > 0)
958 // for each ND VAT amount
959 for ($e=0;$e<count($a_nd);$e++)
961 $this->db->exec_sql('delete from operation_analytique where j_id=$1', array($a_nd[$e]['j_id']));
962 /* get missing data for adding */
963 $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']));
964 $missing_vat = $a_missing_vat[0];
965 $this->oa_debit = 't';
966 $this->oa_description = $missing_vat['jr_comment'];
967 $this->j_id = $opanc[$i];
968 $group = $this->db->get_next_seq("s_oa_group
"); /* for analytic */
969 $this->oa_group = $group;
970 $this->oa_date = $missing_vat['mdate'];
971 $this->oa_jrnx_id_source=$opanc[$i];
972 $p_array['amount_t'.$i]=$missing['j_montant'];
973 $this->save_form_plan_vat_nd($p_array, $i, $a_nd[$e]['j_id'],$missing_vat['j_montant']);
979 /*\brief transform a array of operation into a array usage by
980 *display_form_plan & save_form_plan
981 *\param $p_array array of operation
983 *\return an array complying with \see save_form_plan
985 function to_request ($p_array,$p_line)
988 $result[]=array('op'=>$this->j_id);
991 /* First add the pa_id */
992 for ($i=0;$i < count($p_array);$i++)
994 if ( in_array($p_array[$i]->pa_id,$pa_id)==false)
995 $pa_id[]=$p_array[$i]->pa_id;
997 $result['pa_id']=$pa_id;
1001 for ($i=0;$i < count($p_array);$i++)
1003 $hplan[$p_line][$i]=$p_array[$i]->po_id;
1005 $result['hplan']=$hplan;
1006 /* Add the amount */
1008 $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));
1009 for ($i=0;$i < count($p_array);$i++)
1013 * For the bank, negatif are always on the debit and positif on the credit
1015 if ( $jrn_def != 'FIN')
1017 $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));
1021 $val[$p_line][$p_array[$i]->oa_row]=$p_array[$i]->oa_amount;
1024 $result['val']=$val;
1033 function delete_by_jid($p_jid)
1035 $sql="
delete from operation_analytique where j_id=$1
";
1036 $this->db->exec_sql($sql,array($p_jid));
1048 function display_table($p_mode,$p_amount,$p_id)
1050 static $seq=-1; /* first seq == 0 */
1053 $array=$this->get_by_jid($this->j_id) ;
1054 if ( $array != null )
1056 $request=$this->to_request($array,$seq);
1057 return "<
td>
".$this->display_form_plan($request,1,$p_mode,$seq,$p_amount,$p_id)."</
td>
";
1061 return '<td>'.$this->display_form_plan(null,1,$p_mode,$seq,$p_amount,$p_id)."</TD>
";
1069 /*\brief test the class
1076 $cn=Dossier::connect();
1077 $anco=new Anc_Operation($cn);
1080 $array=$anco->get_by_jid($j_id);
1081 $a=$anco->to_request($array,1);
1083 echo dossier::hidden();
1084 echo HtmlInput::hidden('j_id',$j_id);
1085 echo HtmlInput::hidden('test_select',$_REQUEST['test_select']);
1086 echo $anco->display_table(1,15002,0);
1087 echo '<input type="submit
" name="save
">';
1089 if ( isset($_REQUEST['save']))
1092 var_dump($_REQUEST);
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.
tr($p_string, $p_extra='')
record_log($p_message)
Record an error message into the log file of the server or in the log folder of NOALYSS Record also t...
td($p_string='', $p_extra='')
surround the string with td
return false Description background color
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
h( $row[ 'oa_description'])
_("actif, passif,charge,...")
$class
Display the Plugin and for each profile were it is installed or not.
this class is used to show the form for entering an operation only FOR analytic operation to save it,...
get_jrid()
retrieve the jr_id thanks the oa_group
get_balance($p_from, $p_to, $p_plan_id)
set_currency_rate($currency_rate)
update_from_jrnx($p_po_id)
modify an op from modify_op.php
$oa_positive
signed of the amount
get_by_jid($p_jid)
retrieve an operation thanks a jrnx.j_id
get_list($p_from, $p_to, $p_from_poste="", $p_to_poste="")
get a list of row from a certain periode
get_list_simple($p_from, $p_to)
add($p_seq=0)
add a row to the table operation_analytique
delete()
delete a row from the table operation_analytique
display_form_plan($p_array, $p_null, $p_mode, $p_seq, $p_amount, $p_id='', $p_add_button=true)
display the form for PA
__construct($p_cn, $p_id=0)
constructor
$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 ...
Concerns the Analytic plan (table plan_analytique)
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
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
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
This class handles only the numeric input, the input will call a javascript to change comma to period...
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
static modify($p_id, $p_javascript)
Display the icon to modify a idem.
for($i=0;$i< $count;$i++) $template
catch(\Exception $e) $bar
navigation_bar($p_offset, $p_line, $p_size=0, $p_page=1, $p_javascript="")
Create a navigation_bar (pagesize)