diff --git a/html/admin/test.php b/html/admin/test.php
index 9c3ab371f..3fae38ace 100644
--- a/html/admin/test.php
+++ b/html/admin/test.php
@@ -64,8 +64,10 @@ require_once ('class_bud_card.php');
Bud_Card::testme();
-*/
+
require_once('class_bud_hypo.php');
Bud_Hypo::testme();
-
+*/
+require_once ('class_bud_data.php');
+Bud_Data::test_me();
diff --git a/html/bud_ajax.php b/html/bud_ajax.php
new file mode 100644
index 000000000..59e2f65e1
--- /dev/null
+++ b/html/bud_ajax.php
@@ -0,0 +1,63 @@
+delete();
+ header("Content-type: application/json charset=\"ISO8859-1\"",true);
+ echo '{"bd_id":"'.$obj->bd_id.'","form_id":"'.$form_id.'"}';
+
+ }
+
+if ( $action == 'save' ) {
+ if ( $bd_id == 0 ) {
+ $obj=new Bud_Detail($cn);
+ $obj->po_id=$po_id;
+ $obj->bc_id=${"bc_id".$form_id};
+ $obj->pcm_val=${"account_".$form_id."_hidden"};
+ $obj->bh_id=$bh_id;
+ $obj->add();
+ header("Content-type: application/json charset=\"ISO8859-1\"",true);
+ echo '{"bd_id":"'.$obj->bd_id.'","form_id":"'.$form_id.'"}';
+ exit()
+ } else {
+ $obj=new Bud_Detail($cn);
+ $obj->po_id=$po_id;
+ $obj->bc_id=${"bc_id".$form_id};
+ $obj->pcm_val=${"account_".$form_id."_hidden"};
+ $obj->bh_id=$bh_id;
+ $obj->update();
+ }
+
+ }
diff --git a/html/js/bud_script.js b/html/js/bud_script.js
new file mode 100644
index 000000000..4dfa9c522
--- /dev/null
+++ b/html/js/bud_script.js
@@ -0,0 +1,109 @@
+/*
+ * This file is part of PhpCompta.
+ *
+ * PhpCompta is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * PhpCompta is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with PhpCompta; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+/* $Revision$ */
+
+// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
+
+/*! \file
+ * \brief
+ * open a windows for searching an account (poste comptable)
+ */
+
+function bud_search_poste(p_sessid,p_dossier,p_ctl)
+ {
+ var comment="";
+ if ( document.getElementById(p_ctl) ) {
+ comment=document.getElementById(p_ctl).value;
+ }
+
+ var win=window.open('bud_search_poste.php?gDossier='+p_dossier+'&p_ctl='+p_ctl+'&PHPSESSID='+p_sessid+"&comment="+comment+"&search",'Cherche','toolbar=no,width=600,height=600,scrollbars=yes,resizable=yes');
+ }
+function GetIt() {
+ window.close();
+}
+
+function SetItChild(p_ctl,p_value,p_label) {
+ self.opener.SetItParent(p_ctl,p_value,p_label);
+ window.close();
+}
+function SetItParent(p_ctl,p_value,p_label) {
+ $(p_ctl).value=p_value+' '+p_label;
+ $(p_ctl+'_hidden').value=p_value;
+}
+function bud_form_enable(p_ctl) {
+ $("form_"+p_ctl).enable();
+ $('button_save'+p_ctl).show();
+ $('button_change'+p_ctl).hide();
+ $('button_delete'+p_ctl).show();
+}
+function bud_form_save(p_ctl,p_sessid,p_dossier) {
+ query=$("form_"+p_ctl).serialize();
+ query+="&action=save";
+ $("form_"+p_ctl).disable();
+
+ $('button_change'+p_ctl).show();
+ $('button_save'+p_ctl).hide();
+ $('button_delete'+p_ctl).hide();
+ bud_action(query,p_ctl);
+}
+function bud_form_delete(p_ctl,p_sessid,p_dossier) {
+ if ( confirm ("Vous etes sur d'effacer") == false) { return;}
+ query=$("form_"+p_ctl).serialize();
+ query+="&action=delete";
+ var elt=$("form_"+p_ctl).getElements();
+ alert (elt);
+ for (i=0;i < elt.length;i++) {
+ if ( elt[i].name.search(/amount_/)!= -1 ) {
+ elt[i].value="0";
+ }
+ if ( elt[i].name.search(/account_/) != -1 ) { elt[i].value=" ";}
+ }
+ $('button_change'+p_ctl).show();
+ $('button_save'+p_ctl).hide();
+ $('button_delete'+p_ctl).hide();
+ $("form_"+p_ctl).disable();
+ bud_action(query,p_ctl);
+}
+function display_error(request) {
+ alert("L'operation a echoue");
+}
+
+function display_success(request,json) {
+ alert ('ok');
+ var answer=request.responseText.evalJSON(true);
+ var form=$('form_'+answer.form_id);
+ var elt=form.getElements();
+
+ for (i = 0;i < elt.length;i++) {
+ if ( elt[i].name.search(/bd_id/) != -1 ) {elt[i].value=answer.bd_id;}
+ }
+
+
+}
+function bud_action(p_query,p_ctl) {
+ var action=new Ajax.Request (
+ "bud_ajax.php",
+ {
+ method:'post',
+ parameters:p_query,
+ onFailure:display_error,
+ onSuccess:display_success
+ }
+
+ );
+}
\ No newline at end of file
diff --git a/html/test.php b/html/test.php
new file mode 100644
index 000000000..3fae38ace
--- /dev/null
+++ b/html/test.php
@@ -0,0 +1,73 @@
+
+
+';
+
+$hidden=dossier::hidden().widget::hidden('bh_id',$_REQUEST['bh_id']).
+ widget::hidden('po_id',$po_id).widget::hidden('p_action','detail');
+//----------------------------------------------------------------------
+// Show 20 lines by default
+//----------------------------------------------------------------------
+
diff --git a/include/class_acc_ledger.php b/include/class_acc_ledger.php
index e2facba91..55b22eb69 100644
--- a/include/class_acc_ledger.php
+++ b/include/class_acc_ledger.php
@@ -756,6 +756,7 @@ function get_propertie()
$res=pg_fetch_all($r);
if ( empty($res) ) return null;
+ print_r($res[0]);
return $res[0];
}
diff --git a/include/class_anc_account.php b/include/class_anc_account.php
index c99a69f59..44d9e4bbe 100644
--- a/include/class_anc_account.php
+++ b/include/class_anc_account.php
@@ -273,7 +273,7 @@ class Anc_Account
$this->id=(isset ($p_array['po_id']))?$p_array['po_id']:-1;
$this->ga_id=($p_array['ga_id']) == "-1" ?"":$p_array['ga_id'];
}
- static function testme() {
+ static function test_me() {
$cn=DbConnect(dossier::id());
$pa_id=getDBValue($cn,"select max(pa_id) from plan_analytique");
$o=new Poste_Analytique($cn);
diff --git a/include/class_anc_plan.php b/include/class_anc_plan.php
index baf48bbb3..35ff2c3fb 100644
--- a/include/class_anc_plan.php
+++ b/include/class_anc_plan.php
@@ -179,7 +179,7 @@ class Anc_Plan
return ($a==0)?false:true;
}
- static function testme() {
+ static function test_me() {
$cn=DbConnect(dossier::id());
echo "
Plan analytique : test
";
echo "clean";
diff --git a/include/class_bud_card.php b/include/class_bud_card.php
index 17736262e..e91742102 100644
--- a/include/class_bud_card.php
+++ b/include/class_bud_card.php
@@ -184,7 +184,7 @@ class Bud_Card {
return $r;
}
- static function testme() {
+ static function test_me() {
$cn=DbConnect(dossier::id());
$a=new Bud_Card($cn);
diff --git a/include/class_bud_data.php b/include/class_bud_data.php
new file mode 100644
index 000000000..699ebd620
--- /dev/null
+++ b/include/class_bud_data.php
@@ -0,0 +1,248 @@
+cn=$p_cn;
+ $this->bh_id=$p_bh_id;
+ $this->po_id=$p_po_id;
+ /*
+
+ pg_prepare($this->cn,"sql_periode",$sql_periode);
+ */
+ }
+ function load() {
+ $sql=" select bd_id,bc_id,bc_code,bd.bh_id,bd.bh_name,".
+ " tmp_pcmn.pcm_val,pcm_lib,bud_detail_periode.bdp_id ".
+ " from bud_detail join bud_detail_periode using (bd_id)".
+ " join bud_hypothese as bd using (bh_id) ".
+ " join bud_card using (bc_id) ".
+ " join tmp_pcmn using (pcm_val) ".
+ " where bd.bh_id=".$this->bh_id.
+ " and po_id=".$this->po_id;
+
+
+ $res1=ExecSql($this->cn,$sql);
+ $array=pg_fetch_all($res1);
+
+
+ $sql_periode="select coalesce(bdp_amount,0) as bdp_amount,a.p_id as p_id ".
+ " from bud_detail_periode left join parm_periode as a using (p_id) ".
+ " where bdp_id=$1 order by p_start,p_end ";
+
+ print_r($sql_periode);
+
+
+ $ret=array();
+
+
+ if ( ! empty($array)){
+ foreach ($array as $row) {
+ $obj=new Bud_Data($this->cn,$this->bh_id,$this->po_id);
+ $obj->load_from_array($row);
+
+ $res2=ExecSqlParam($this->db,"sql_periode",array($row['bdp_id']));
+ $per=pg_fetch_all($r);
+
+ foreach ($per as $row2) {
+ $p_id=$row['p_id'];
+ $obj->amount[$p_id]=$row['bdp_amount'];
+ }
+ }
+ $ret=clone $obj;
+ }
+ return $ret;
+ }
+
+ function create_empty_row() {
+ $ret=new Bud_Data($this->cn,$this->bh_id,$this->po_id);
+ $ret->bd_id=0;
+ $ret->bdp_id=0;
+ // populate the periode with 0
+ $res_empty=get_array($this->cn,
+ "select 0,p_id from parm_periode order by p_start,p_end");
+ foreach ( $res_empty as $r) {
+ $p_id=$r['p_id'];
+ $ret->amount[$p_id]=0;
+ }
+ return $ret;
+ }
+
+ private function load_from_array($p_array) {
+ foreach (array('bd_id','bh_id','bc_id','pcm_val','bdp_id','pcm_lib','bh_name','bc_code') as $key) {
+ $this->{$key}=$p_array[$key];
+ }
+ }
+ function form() {
+ $r="";
+ $array=$this->load();
+ $a=0;
+ if ( ! empty ($array) ) {
+ foreach ($array as $row) {
+ $a++;
+ $style=($a%2==0)?"even":"odd";
+ $r.=$this->create_row($style);
+ }
+ }
+ for ($i=count($array);$i< MAX_BUD_DETAIL;$i++) {
+ $a++;
+ $style=($a%2==0)?"even":"odd";
+
+ $obj=$this->create_empty_row($style);
+ $r.=$obj->create_row();
+ }
+
+
+ return $r;
+ }
+
+ private function create_row($p_style="odd") {
+ static $p_number=0;
+ $p_number++;
+ $tot=0;
+
+ $wAmount=new widget('text');
+ $wAmount->size=8;
+ $wAmount->extra="disabled";
+
+ $wAccount=new widget('js_bud_search_poste');
+ $wAccount->table=0;
+ $wAccount->disabled=true;
+
+ $wBudCard=new widget('select');
+ $wBudCard->value=$this->load_bud_card();
+ $wBudCard->selected=$this->bc_id;
+ $wBudCard->disabled=true;
+
+ foreach ($this->amount as $p_id=>$amount)
+ $tot+=$amount;
+
+ $r='";
+ $button_change=new widget('button','Change');
+ $button_change->javascript='bud_form_enable('.$p_number.')';
+ $r.=$button_change->IOValue('button_change'.$p_number);
+
+ $button_save=new widget('button','Sauve');
+ $button_save->javascript='bud_form_save('.$p_number.')';
+ $button_save->extra='style="display:none"';
+ $r.=$button_save->IOValue('button_save'.$p_number);
+
+ $button_delete=new widget('button','Efface');
+ $button_delete->javascript='bud_form_delete('.$p_number.')';
+ $button_delete->extra='style="display:none"';
+ $r.=$button_delete->IOValue('button_delete'.$p_number);
+ $r.='';
+ $r.="
";
+ return $r;
+ }
+ private function load_bud_card() {
+ if ( !isset ($this->array_bud_card) )
+ $this->array_bud_card=make_array($this->cn,
+ 'select bc_id,bc_code from bud_card '.
+ 'where bh_id='.$this->bh_id);
+ return $this->array_bud_card;
+ }
+
+ private function header_table() {
+ if ( ! isset ($this->header ) ){
+ $r='';
+ $r.="";
+ $periode=get_array($this->cn,"select to_char(p_start,'MM/YY')as d from parm_periode ");
+ foreach ($periode as $row)
+ $r.='| '.$row['d'].' | ';
+
+ $r.="
";
+ $this->header=$r;
+ }
+ return $this->header;
+ }
+ static function test_me() {
+ echo JS_PROTOTYPE_JS;
+ echo JS_BUD_SCRIPT;
+ $cn=DbConnect(dossier::id());
+ $sql="select bh_id||','||po_id,bh_name||' -- '||po_name ".
+ " from bud_hypothese join poste_analytique using (pa_id)";
+ $w=new widget("select");
+ echo '';
+ if ( isset($_REQUEST['search'])) {
+
+ list($bh_id,$po_id)=split(',',$_REQUEST['bh_po_id']);
+ $obj=new Bud_Data($cn,$bh_id,$po_id);
+ $r=$obj->load();
+ print_r($obj);
+ echo '
';
+ print_r($r);
+ print_r($obj->create_empty_row());
+ echo $obj->form();
+ }
+ }
+}
diff --git a/include/class_bud_detail.php b/include/class_bud_detail.php
index 20a602d84..cd811ba38 100644
--- a/include/class_bud_detail.php
+++ b/include/class_bud_detail.php
@@ -41,16 +41,19 @@ class Bud_Detail {
var $po_id; /*!< PosteAnalytic id */
var $bc_id; /*!< Budget Card id */
var $pcm_val; /*!< from the table tmp_pcmn */
+ var $bh_id;
function __construct( $p_cn,$id = 0 ) {
$this->db=$p_cn; $this->bd_id=$id;
$this->po_id=null;$this->bc_id=null;$this->pcm_val=null;
+ $this->bh_id=null;
}
function add () {
$array=array($this->po_id,
$this->bc_id,
- $this->pcm_val);
- $sql="insert into bud_detail (po_id,bc_id,pcm_val) ".
- " values ($1,$2,$3) returning bd_id ";
+ $this->pcm_val,
+ $this->bh_id);
+ $sql="insert into bud_detail (po_id,bc_id,pcm_val,bh_id) ".
+ " values ($1,$2,$3,$4) returning bd_id ";
$a=ExecSqlParam($this->db,$sql,$array);
$x=pg_fetch_array($a,0);
@@ -98,12 +101,13 @@ class Bud_Detail {
$pa_filter=($pa_id)?" and pa_id = $pa_id ":"";
$sql="select * from bud_detail join bud_detail_periode using(bd_id) ".
" right join parm_periode using (p_id) ".
- " where bh_id= $bh_id $pa_filter "
+ " where bh_id= $bh_id $pa_filter ";
}
- static function testme() {
+ static function test_me() {
$cn=DbConnect(dossier::id());
$a=new Bud_Detail($cn);
$a->po_id=4;
+ $a->bh_id=4;
echo " Ajout d'un bud_detail
";
$a->add();
print_r($a);
diff --git a/include/class_bud_detail_period.php b/include/class_bud_detail_period.php
index 2167e2e8c..82da53f34 100644
--- a/include/class_bud_detail_period.php
+++ b/include/class_bud_detail_period.php
@@ -26,3 +26,8 @@
/*! \brief
*
*/
+class Bud_Detail_Period{
+ function __contruct ($p_cn,$bdp_id) {
+ $sql="delete from budget_detail
+ }
+ }
diff --git a/include/class_bud_hypo.php b/include/class_bud_hypo.php
index 49ce19b9c..637ef886f 100644
--- a/include/class_bud_hypo.php
+++ b/include/class_bud_hypo.php
@@ -165,7 +165,7 @@ class Bud_Hypo {
}
- static function testme() {
+ static function test_me() {
$cn=DbConnect (dossier::id());
ExecSql($cn,"delete from bud_hypothese");
$a=new Bud_Hypo($cn);
diff --git a/include/class_widget.php b/include/class_widget.php
index 13d75171b..467e5c1f5 100644
--- a/include/class_widget.php
+++ b/include/class_widget.php
@@ -115,10 +115,11 @@ class widget {
$this->name=$p_name;
$this->value=($p_value===null)?$this->value:$p_value;
$this->label=($p_label == "")?$this->label:$p_label;
-
+
// Input text type
$disabled = $this->disabled ? "readonly" : "";
if (strtoupper($this->type)=="TEXT") {
+ $extra=(isset($this->extra))?$this->extra:"";
if ( $this->readonly==true ){
$readonly=" readonly ";$style='style="border:solid 1px grey;color:black;background:lightblue;"';
} else {
@@ -127,8 +128,8 @@ class widget {
$this->value=str_replace('"','',$this->value);
$r='name.'" VALUE="'.$this->value.'" '.
- 'SIZE="'.$this->size.'" "'.$this->javascript." ".$disabled." $readonly >";
+ 'NAME="'.$this->name.'" VALUE="'.$this->value.'" '.
+ 'SIZE="'.$this->size.'" "'.$this->javascript." ".$disabled." $readonly $this->extra >";
if ($this->table==1) {
if ( $this->label != "") {
@@ -149,8 +150,9 @@ class widget {
if ( strtoupper($this->type) == "SELECT") {
if ($this->readonly==false )
{
+ $disabled=($this->disabled==true)?"disabled":"";
//echo "Selected ".$this->selected;
- $r="