diff --git a/include/class_bud_synthese_hypo.php b/include/class_bud_synthese_hypo.php index 4e82b7738..48df0ee04 100644 --- a/include/class_bud_synthese_hypo.php +++ b/include/class_bud_synthese_hypo.php @@ -101,8 +101,8 @@ Array $sql_poste="select distinct pcm_val from bud_detail where bh_id=".$this->bh_id; $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,". + $local_con=DbConnect(dossier::id()); + $sql_prepare=pg_prepare($local_con,"get_group","select sum(bdp_amount) as amount,ga_id,". "bc_price_unit". " from ". " bud_detail join bud_detail_periode using (bd_id) ". @@ -144,8 +144,58 @@ Array $line['acc_amount']=$acc_account->get_solde($per_acc); $array[$pcm_val]=$line; } - pg_close($cn); + /*!\bug it is a bug ? When I close a connection created and used + * locally, it closed also the main connection so I reopened it + */ + pg_close($local_con); + $this->cn=DbConnect(dossier::id()); + return $array; + } + /*!\brief compute the summary + * \param $p_array is an array generated by load() + * \return array +Array +( + [65] => Array + ( + [GROUPE1] => 0 + [total] => 74 + [GROUPE3] => 74 + ) + [60] => Array + ( + [GROUPE1] => 83.7 + [total] => 161.7 + [GROUPE3] => 78 + ) + +) + */ + function summary($p_array) { + + if ( empty ($p_array)) return ; + // Now we put 0 if there is nothing for a group + $aGroup=get_array($this->cn,"select distinct ga_id from bud_detail join poste_analytique ". + " using (po_id) where bh_id=".$this->bh_id." order by ga_id "); + + + $array=array(); + foreach ($p_array as $key=>$row) { + $pcm_val=substr($key,0,2); + $sub=array(); + foreach ($aGroup as $rGroup ) { + $group_id=$rGroup['ga_id']; + $sub[$group_id]=(isset($sub[$group_id]))?$sub[$group_id]:0; + $sub[$group_id]=+$row[$group_id]; + $sub['total']=(isset($sub['total']))?$sub['total']:0; + $sub['total']+=$row[$group_id]; + } + if (isset( $array[$pcm_val])) + $array[$pcm_val]+=$sub; + else + $array[$pcm_val]=$sub; + } return $array; } static function test_me() { @@ -158,7 +208,10 @@ Array print_r($_GET); if ( isset ($_GET['recherche'])) { $obj->from_array($_GET); - print_r( $obj->load()); + $res=$obj->load(); + print_r($res); + $summary=$obj->summary($res); + print_r($summary); } } }