From c198064d4bf6feb7c033b0f18a1780ff8ce4da82 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Wed, 19 Dec 2007 22:53:07 +0000 Subject: [PATCH] rename class_poste_analytic to Anc_Account --- doc/heading.php | 25 +++ html/search_ca.php | 2 +- include/bud_detail.inc.php | 4 +- include/ca_od.inc.php | 2 +- include/ca_pa.inc.php | 12 +- include/class_anc_account.php | 318 +++++++++++++++++++++++++++++++++ include/class_plananalytic.php | 4 +- 7 files changed, 355 insertions(+), 12 deletions(-) create mode 100644 doc/heading.php create mode 100644 include/class_anc_account.php diff --git a/doc/heading.php b/doc/heading.php new file mode 100644 index 000000000..205f7459b --- /dev/null +++ b/doc/heading.php @@ -0,0 +1,25 @@ +'; @@ -95,7 +95,7 @@ $wHypo=new widget("text","","bh_id",$Hyp->bh_name); $wHypo->readonly=true; echo $wHypo->IOValue(); if ( $po_id !== -1 ) { - $oPo_id=new Poste_analytique($cn,$po_id); + $oPo_id=new Anc_Account($cn,$po_id); $oPo_id->get_by_id(); $wPo_id=new widget("text","","po_id",$oPo_id->name); $wPo_id->readonly=true; diff --git a/include/ca_od.inc.php b/include/ca_od.inc.php index 821c225c0..27a16e874 100644 --- a/include/ca_od.inc.php +++ b/include/ca_od.inc.php @@ -26,7 +26,7 @@ /* \brief Misc Operation for analytic accountancy * */ -require_once("class_poste_analytic.php"); +require_once("class_anc_account.php"); require_once ("class_widget.php"); require_once ("class_anc_operation.php"); require_once ("class_groupop.php"); diff --git a/include/ca_pa.inc.php b/include/ca_pa.inc.php index 39c4446a0..3f6c065cd 100644 --- a/include/ca_pa.inc.php +++ b/include/ca_pa.inc.php @@ -27,7 +27,7 @@ * */ require_once("class_plananalytic.php"); -require_once("class_poste_analytic.php"); +require_once("class_anc_account.php"); $ret=""; //--------------------------------------------------------------------------- // action @@ -125,7 +125,7 @@ if ( isset($_REQUEST['sa'])) // show the form for add a poste if ( $sa=='po_add') { - $po=new Poste_analytique($cn); + $po=new Anc_Account($cn); $po->pa_id=$_REQUEST['pa_id']; $wSa=new widget("hidden","sa","sa","po_write"); $ret.='
'; @@ -140,7 +140,7 @@ if ( isset($_REQUEST['sa'])) if ( $sa=="po_write") { // var_dump($_POST); - $po=new Poste_analytique($cn); + $po=new Anc_Account($cn); $po->fill_from_POST(); $po->add(); $sa="list"; @@ -158,7 +158,7 @@ if ( isset($_REQUEST['sa'])) if ( $sa=="po_detail") { $wHidden=new widget('hidden','','sa','po_update'); - $po=new Poste_analytique($cn,$_GET['po_id']); + $po=new Anc_Account($cn,$_GET['po_id']); $po->get_by_id(); $ret.='
'; $ret.='
'; @@ -178,14 +178,14 @@ if ( isset($_REQUEST['sa'])) } if ( $sa=="po_update") { - $po=new Poste_analytique($cn); + $po=new Anc_Account($cn); $po->fill_from_POST(); $po->update(); $sa="list"; } if ( $sa=="po_delete") { - $po=new Poste_analytique($cn,$_REQUEST['po_id']); + $po=new Anc_Account($cn,$_REQUEST['po_id']); $po->delete(); $sa="list"; } diff --git a/include/class_anc_account.php b/include/class_anc_account.php new file mode 100644 index 000000000..53310317b --- /dev/null +++ b/include/class_anc_account.php @@ -0,0 +1,318 @@ +db=$p_db; + $this->id=$p_id; + $this->ga_id=null; + } + /*! \brief retrieve data from the database and + * fill the object + * \param $p_where the where clause + */ + private function fetch_from_db($p_where) + { + $sql="select po_id, + po_name , + pa_id, + po_amount, + po_description, + ga_id + from poste_analytique + where ". + $p_where; + + $ret=ExecSql($this->db,$sql); + if ( pg_NumRows($ret) == 0 )return null; + $line=pg_fetch_array($ret); + + $this->id=$line['po_id']; + $this->name=$line['po_name']; + $this->pa_id=$line['pa_id']; + $this->amount=$line['po_amount']; + $this->description=$line['po_description']; + $this->ga_id=$line['ga_id']; + + + } + function get_by_id() + { + $this->fetch_from_db("po_id=".$this->id); + } + /*! + * \brief retrieve data thanks the name + * \param $p_name name of the analytic account + * + */ + function get_by_name($p_name) + { + $p_name=FormatString($p_name); + if ( $p_name == null ) + $p_name=$this->name; + + $this->fetch_from_db("po_name='".$p_name."'"); + echo "id = ".$this->id; + } + function add() + { + $this->format_data(); + if ( strlen($this->name) == 0) + return; + if ( $this->ga_id == null || strlen(trim($this->ga_id)) == 0 ) + $ga_id="NULL"; + else + $ga_id="'".$this->ga_id."'"; + $sql="insert into poste_analytique ( + po_name , + pa_id, + po_amount, + po_description, + ga_id + ) values (". + "'".$this->name."',". + $this->pa_id.",". + $this->amount.",". + "'".$this->description."',". + $ga_id.")"; + try { + ExecSql($this->db,$sql); + + } catch (Exception $e) { + echo_debug(__FILE__,__LINE__,$e); + if ( DEBUG ) print_r($e); + echo "

Doublon : l'enregistrement n'est pas sauve

"; + } + + } + function update() + { + $this->format_data(); + if ( strlen($this->name) == 0) + return; + $sql="update poste_analytique ". + " set po_name='".$this->name."',". + " pa_id=".$this->pa_id.",". + " po_amount=".$this->amount.",". + " po_description='".$this->description."',". + " ga_id='".$this->ga_id."'". + " where po_id=".$this->id; + try { + ExecSql($this->db,$sql); + } catch (Exception $e) { + echo_debug(__FILE__,__LINE__,$e); + echo "

Doublon : l'enregistrement n'est pas sauve

"; + } + + } + private function format_data() + { + $this->name=FormatString($this->name); + $this->pa_id=FormatString($this->pa_id); + $this->amount=FormatString($this->amount); + if (strlen($this->amount) == 0 ) + $this->amount=0.0; + + $this->description=FormatString($this->description); + } + function delete() + { + $sql="delete from poste_analytique where po_id=".$this->id; + ExecSql($this->db,$sql); + } + /*! \brief return an array of object Poste_Analytique + * + */ + function get_list() + { + $sql="select po_id, + po_name , + pa_id, + po_amount, + po_description, + ga_id + from poste_analytique ". + " order by po_name"; + + $ex=ExecSql($this->db,$sql); + $ret=pg_fetch_all($ex); + if ( $ret == null ) + return null; + + $array=array(); + foreach ($ret as $line) + { + $objet=new Poste_Analytique($this->db); + + $object->id=$line['po_id']; + $object->name=$line['po_name']; + $object->pa_id=$line['pa_id']; + $object->amount=$line['po_amount']; + $object->description=$line['po_description']; + $object->ga_id=$line['ga_id']; + $array[]=clone $object; + } + + return $array; + } + function display_list() + { + $array=$this->get_list(); + if ( empty($array) ) { echo "Vide"; return;} + foreach ($array as $line) + { + echo $line->id." / ".$line->name." / ".$line->description."/". + $line->amount." / ".$line->pa_id."/".$line->ga_id."
"; + } + } + function debug() + { + echo "id ".$this->id."
"; + echo "name ".$this->name."
"; + echo "pa_id ".$this->pa_id."
"; + echo "amount ".$this->amount."
"; + echo "description ".$this->description."
"; + echo "ga_id ".$this->ga_id."
"; + } + function form() + { + $wId=new widget("hidden","po_id","po_id",$this->id); + $wName=new widget("text","Nom","po_name",$this->name); + $wPa_id=new widget("hidden","pa_id","pa_id",$this->pa_id); + $wAmount=new widget("text","Montant","po_amount",$this->amount); + $wDescription=new widget("text","Description","po_description",$this->description); + $wGa_id=new widget("select","Groupe","ga_id"); + $wGa_id->value=make_array($this->db,"select ga_id,ga_id from groupe_analytique",1); + $wGa_id->selected=$this->ga_id; + $wGa_id->table=1; + $pa=new PlanAnalytic($this->db,$this->pa_id); + $pa->get(); + $wPaName=new widget("text","Plan A.","",$pa->name); + $wPaName->table=1; + $wPaName->readonly=true; + + $wName->table=1; + $wPa_id->table=1; + $wAmount->table=1; + $wDescription->table=1; + + $r=$wId->IOValue(); + $r.=$wPa_id->IOValue(); + + $r.=""; + + $r.=""; + $r.=$wName->IOValue(); + $r.=""; + + $r.=""; + $r.=$wAmount->IOValue(); + $r.=""; + + + $r.=""; + $r.=$wDescription->IOValue(); + $r.=""; + + $r.=""; + $r.=$wPaName->IOValue(); + $r.=""; + + $r.=""; + $r.=$wGa_id->IOValue(); + $r.=""; + + $r.="
"; + return $r; + + } + function fill_from_POST() + { + $this->name=$_POST['po_name']; + $this->description=$_POST['po_description']; + $this->pa_id=$_POST['pa_id']; + $this->amount=$_POST['po_amount']; + $this->id=$_POST['po_id']; + $this->ga_id=($_POST['ga_id'] == "-1" )?"":$_POST['ga_id']; + } + static function testme() { + $cn=DbConnect(dossier::id()); + $pa_id=getDBValue($cn,"select max(pa_id) from plan_analytique"); + $o=new Poste_Analytique($cn); + echo "

Poste_Analytique

"; + echo "

get_list

"; + $ee=$o->get_list(); + print_r($ee); + //var_dump($ee); + + echo "

Add some

"; + $o->pa_id=$pa_id; + $o->name="test1"; + $o->add(); + + + $o->name="test2"; + $o->add(); + + $o->name="test3"; + $o->add(); + + $o->name="test4"; + $o->add(); + + $o->name="test5"; + $o->add(); + + echo "

remove test1

"; + $o->get_by_name("test1"); + $o->delete(); + $o->display_list(); + + $o->get_by_name("test4"); + echo "
".$o->id."
"; + $o->name="Test Four"; + $o->update(); + $o->display_list(); + $o->delete(); + $o->display_list(); + } +} +?> diff --git a/include/class_plananalytic.php b/include/class_plananalytic.php index dabdd6c06..8808b889c 100644 --- a/include/class_plananalytic.php +++ b/include/class_plananalytic.php @@ -29,7 +29,7 @@ require_once("constant.php"); require_once("postgres.php"); require_once("class_widget.php"); -require_once("class_poste_analytic.php"); +require_once("class_anc_account.php"); require_once ('class_dossier.php'); class PlanAnalytic @@ -149,7 +149,7 @@ class PlanAnalytic $all=pg_fetch_all($r); foreach ($all as $line) { - $obj=new Poste_analytique($this->db,$line['po_id']); + $obj=new Anc_Account($this->db,$line['po_id']); $obj->get_by_id(); $ret[]=clone $obj; }