diff --git a/html/test.php b/html/test.php index 0f1e2b7b3..c53d842f0 100644 --- a/html/test.php +++ b/html/test.php @@ -76,8 +76,12 @@ Bud_Detail_Periode::test_me(); require_once ('class_bud_data.php'); Bud_Data::test_me(); -*/ + require_once ('class_bud_synthese_hypo.php'); Bud_Synthese_Hypo::test_me(); + +*/ +require_once ('class_bud_synthese_anc.php'); +Bud_Synthese_Anc::test_me(); diff --git a/include/class_anc_account.php b/include/class_anc_account.php index a1194a26d..cb605ef86 100644 --- a/include/class_anc_account.php +++ b/include/class_anc_account.php @@ -123,6 +123,12 @@ class Anc_Account } } + static function make_array_name($cn,$pa_id) { + $a=make_array($cn,"select po_name,po_name from poste_analytique ". + " where ". + " pa_id =".$pa_id." order by po_name "); + return $a; + } function update() { $this->format_data(); diff --git a/include/class_bud_synthese_acc.php b/include/class_bud_synthese_acc.php index de0621bbe..4b3e6d569 100644 --- a/include/class_bud_synthese_acc.php +++ b/include/class_bud_synthese_acc.php @@ -31,12 +31,6 @@ require_once ('class_bud_synthese.php'); class Bud_Synthese_Acc extents Bud_Synthese { - static function make_array($p_cn) { - $a=make_array($p_cn,'select bh_id, bh_name from bud_hypothese ' - ' where pa_id is not null order by bh_name'); - ret $a; - } - function form() { $obj=new Bud_Hypo($this->cn); $obj->bh_id=$this->bh_id; @@ -56,15 +50,7 @@ class Bud_Synthese_Acc extents Bud_Synthese { } function load() { - $per=sql_filter_per($this->cn,$this->from,$this->to,'p_id','p_id'); - $sql="select sum(bdp_amount),ga_id,pcm_val,pcm_lib ". - " from bud_detail_periode join bud_detail using (bd_id) " - " join bud_hypothese using (bh_id) ". - " join tmp_pcmn using (pcm_val) ". - " join plan_analytique using (pa_id) ". - " join groupe_analytique using(pa_id) ". - " where bh_id= ".$this->bh_id.' and '.$per. - " group by ga_id,pcm_lib,pcm_val "; + } function test_me() { diff --git a/include/class_bud_synthese_anc.php b/include/class_bud_synthese_anc.php new file mode 100644 index 000000000..b3e79ada8 --- /dev/null +++ b/include/class_bud_synthese_anc.php @@ -0,0 +1,211 @@ +$r=(isset($p_array[$r]))?$p_array[$r]:""; + } + // swap po_from and po_to if po_from is > to + if ( $this->from > $this->po_to ){ + $swap=$this->po_to; + $this->po_to=$this->from; + $this->from=$swap; + } + } + + function select_hypo() { + $hypo=make_array($this->cn,'select bh_id, bh_name from bud_hypothese '. + ' where pa_id is not null order by bh_name'); + $wSelect = new widget('select'); + $wSelect->name='bh_id'; + $wSelect->value=$hypo; + + $r="Hypothèse :".$wSelect->IOValue(); + $r.=dossier::hidden(); + return $r; + } + function form() { + /* 2nd Step + */ + if ( $this->bh_id == 0 ) + throw new Exception ("bh_id n'est pas sélectionné"); + $hypo=new Bud_Hypo($this->cn); + $hypo->bh_id=$this->bh_id; + $hypo->load(); + $po_value=Anc_Account::make_array_name($this->cn,$hypo->pa_id); + $wPo_from=new widget("select"); + $wPo_from->name="po_from"; + $wPo_from->value=$po_value; + + $wPo_to=new widget("select"); + $wPo_to->name="po_to"; + $wPo_to->value=$po_value; + + $per=make_array($this->cn,"select p_id,to_char(p_start,'MM.YYYY') ". + " from parm_periode order by p_start,p_end"); + + $wFrom=new widget('select'); + $wFrom->name='from'; + $wFrom->value=$per; + + $wto=new widget('select'); + $wto->name='to'; + $wto->value=$per; + $r=""; + $r.="Periode de ".$wFrom->IOValue()." à ".$wto->IOValue(); + $r.="Poste analytique de ".$wPo_from->IOValue()." à ".$wPo_to->IOValue(); + $r.=dossier::hidden(); + return $r; + } + /*!\brief return all the data (raw format) in a array +\return Array structure ( + [0] => Array + ( + [bc_id] => 4 + [pcm_val] => 6040002 + [amount] => Array + ( + [79] => 1.0000 + [91] => 0.0000 + [90] => 12.0000 + [81] => 3.0000 + [89] => 11.0000 + [80] => 2.0000 + [88] => 10.0000 + [87] => 9.0000 + [86] => 0.0000 + [85] => 0.0000 + [84] => 0.0000 + [83] => 0.0000 + [82] => 0.0000 + ) + + ) + + [1] => Array + ( + [bc_id] => 7 + [pcm_val] => 6510 + [amount] => Array + ( + [79] => 2.0000 + [91] => 0.0000 + [90] => 0.0000 + [81] => 4.0000 + [89] => 0.0000 + [80] => 43.0000 + [88] => 0.0000 + [87] => 0.0000 + [86] => 7.0000 + [85] => 7.0000 + [84] => 6.0000 + [83] => 0.0000 + [82] => 5.0000 + ) + + ) + +) */ + function load() { + $per=sql_filter_per($this->cn,$this->from,$this->to,'p_id','p_id'); + + // get all the bud_card.bc_id + $sql="select distinct bc_id from bud_card join bud_detail using (bc_id) ". + "join poste_analytique using(po_id) where po_name >= $1 and ". + "po_name <=$2 and bud_card.bh_id=$3"; + $res=ExecSqlParam($this->cn,$sql,array($this->po_from,$this->po_to,$this->bh_id)); + $aBudCard=pg_fetch_all($res); + $array=array(); + $cn=DbConnect(dossier::id()); + pg_prepare($cn,"sql_detail","select distinct pcm_val from bud_detail ". + " where bc_id=$1"); + pg_prepare($cn,"sql_detail_periode","select sum(bdp_amount) as amount,". + "p_id from bud_card join bud_detail using (bc_id)". + " join bud_detail_periode using (bd_id) ". + " join parm_periode using (p_id) ". + " where bc_id=$1 and $per and pcm_val=$2 group by p_id,p_start order by p_start"); + + // foreach card get the detail per pcm_val and periode + foreach ($aBudCard as $rBudCard) { + $line=array(); + $line['bc_id']=$rBudCard['bc_id']; + $res=pg_execute("sql_detail",array($line['bc_id'])); + $row=pg_fetch_all($res); + foreach ($row as $col) { + $pcm_val=$col['pcm_val']; + $line['pcm_val']=$pcm_val; + $periode=array(); + $res2=pg_execute("sql_detail_periode",array($rBudCard['bc_id'],$pcm_val)); + $col_per=pg_fetch_all($res2); + + foreach ($col_per as $cPer) { + $p_id=$cPer['p_id']; + $periode[$p_id]=$cPer['amount']; + } + $line['amount']=$periode; + } + $array[]=$line; + } + pg_close($cn); + return $array; + } + static function test_me() { + + $cn=DbConnect(dossier::id()); + $obj=new Bud_Synthese_Anc($cn); + echo '
'; + echo $obj->select_hypo(); + echo widget::submit_button('recherche','recherche'); + echo '
'; + if ( isset($_GET['recherche'])) { + $obj->from_array($_GET); + echo '
'; + echo $obj->form(); + echo widget::hidden('bh_id',$obj->bh_id); + echo widget::submit_button('recherche2','recherche'); + echo '
'; + } + if ( isset($_GET['recherche2'])){ + print_r($_GET); + $obj->from_array($_GET); + + echo 'ICI'; + print_r($obj->load()); + } + } + + + +} diff --git a/include/class_bud_synthese_hypo.php b/include/class_bud_synthese_hypo.php index 5e82246fc..3cff44974 100644 --- a/include/class_bud_synthese_hypo.php +++ b/include/class_bud_synthese_hypo.php @@ -88,13 +88,16 @@ class Bud_Synthese_Hypo extends Bud_Synthese { $aPoste=get_array($this->cn,$sql_poste); $cn=DbConnect(dossier::id()); - $sql_prepare=pg_prepare($cn,"get_group","select sum(bdp_amount) as amount,ga_id from ". + $sql_prepare=pg_prepare($cn,"get_group","select sum(bdp_amount) as amount,ga_id,". + "bc_price_unit". + " from ". " bud_detail join bud_detail_periode using (bd_id) ". + " join bud_card using (bc_id) ". " join poste_analytique using (po_id) ". " where $per ". " and pcm_val=$1 and ". - " bh_id=$2 ". - " group by ga_id ". + " bud_detail.bh_id=$2 ". + " group by ga_id,bc_price_unit ". " order by ga_id "); $array=array(); // Now we put 0 if there is nothing for a group @@ -116,7 +119,7 @@ class Bud_Synthese_Hypo extends Bud_Synthese { } foreach ($row as $col ) { $groupe=$col['ga_id']; - $line[$groupe]=$col['amount']; + $line[$groupe]=$col['amount']*$col['bc_price_unit']; } $array[$pcm_val]=$line; } @@ -134,8 +137,6 @@ class Bud_Synthese_Hypo extends Bud_Synthese { print_r($_GET); if ( isset ($_GET['recherche'])) { $obj->from_array($_GET); - $obj->from=79; - $obj->to=90; print_r( $obj->load()); } } diff --git a/include/class_bud_synthese_simple.php b/include/class_bud_synthese_simple.php deleted file mode 100644 index acb881c90..000000000 --- a/include/class_bud_synthese_simple.php +++ /dev/null @@ -1,75 +0,0 @@ -$l=isset($p_array[$l])?$p_array[$l]:''; - } - } - - function form() { - $r=""; - $obj=new Bud_Hypo($this->cn); - $obj->bh_id=$this->bh_id; - if ( $obj->has_plan () == 1 ) { - /* show the analytic account of this plan */ - $po=new widget('select'); - $po->name='from_po'; - $value=make_array($this->cn,'select po_id,po_name from poste_analytique '. - ' where pa_id = '.$this->bh_id.' order by po_name'); - $po->value=$value; - $po_to=new widget('select'); - $po_to->name='to'; - $po_to->value=$value; - $r.='Plage de poste analytique '.$po->IOValue().' à '.$po_to->IOValue(); - } - $per=make_array($this->cn,"select p_id,to_char(p_start,'MM.YYYY') ". - " from periode order by p_start,p_end"); - - $wFrom=new widget('select'); - $wFrom->name='from'; - $wFrom->value=$per; - - $wto=new widget('select'); - $wto->name='to'; - $wto->value=$per; - $r.="Periode de ".$wFrom->IOValue()." à ".$wto->IOValue(); - } - - function load_all() { - - - } - static function test_me() { - - } -}