From b9a9f6e7efd80210628a58758313d23d7f6b8f92 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Fri, 2 Jul 2010 06:53:06 +0000 Subject: [PATCH] Progress on ca ============== Must be tested : insert for ACH VEN ODS --- html/ajax_ledger.php | 2 +- html/js/anc_script.js | 7 +- html/test.php | 5 + include/class_acc_ledger.php | 53 +++++--- include/class_acc_ledger_purchase.php | 21 +++- include/class_acc_ledger_sold.php | 27 ++++- include/class_anc_operation.php | 168 +++++++++++++------------- include/class_anc_plan.php | 16 +++ release-note | 6 + 9 files changed, 194 insertions(+), 111 deletions(-) diff --git a/html/ajax_ledger.php b/html/ajax_ledger.php index e82a4a8c9..ccfcf37e0 100644 --- a/html/ajax_ledger.php +++ b/html/ajax_ledger.php @@ -322,7 +322,7 @@ case 'rmf': $op->oa_date=$row_ca['j_date']; $op->oa_group=$group; $op->oa_description=$_REQUEST['lib']; - $op->save_form_plan($_REQUEST,$count); + $op->save_form_plan($_REQUEST,$count,$row_ca['j_id']); $count++; } //if myereg }//foreach diff --git a/html/js/anc_script.js b/html/js/anc_script.js index e4687f34d..eb2ec293c 100644 --- a/html/js/anc_script.js +++ b/html/js/anc_script.js @@ -25,9 +25,8 @@ /*!\brief add a row for the CA * \param p_table_id * \param p_amount amount to reach - * \param p_count count of col. */ -function add_row(p_table,p_seq,p_count) { +function add_row(p_table,p_seq) { var mytable=g(p_table).tBodies[0]; if ( ! mytable ) {return;} @@ -44,13 +43,13 @@ function add_row(p_table,p_seq,p_count) { for ( var i=0;i< rowToCopy.cells.length;i++) { var cell=row.insertCell(i); var txt=rowToCopy.cells[i].innerHTML; - txt=txt.replace(/row_1/g,"row_"+new_value); +// txt=txt.replace(/row_1/g,"row_"+new_value); cell.innerHTML=txt; } // create the amount cell - row.cells[i-1].innerHTML=''; +// row.cells[i-1].innerHTML=''; } /*! diff --git a/html/test.php b/html/test.php index 72ed229d0..1a9e7d1eb 100644 --- a/html/test.php +++ b/html/test.php @@ -47,6 +47,7 @@ if ( ! isset($_REQUEST['gDossier'])) { $array=array( array(1,'Plan Analytic'), array(2,'Poste Analytic'), + array(3,'Opération Analytic'), array(11,'Periode'), array(12,'verif.inc.php'), array(13,'Rapport(class_acc_report'), @@ -100,6 +101,10 @@ case 2: require_once("class_anc_account.php"); Anc_Account::test_me(); break; +case 3: + require_once ('class_anc_operation.php'); + Anc_Operation::test_me(); + break; case 11: require_once ('class_periode.php'); Periode::test_me(); diff --git a/include/class_acc_ledger.php b/include/class_acc_ledger.php index 16100a8fa..34e98a744 100644 --- a/include/class_acc_ledger.php +++ b/include/class_acc_ledger.php @@ -993,13 +993,18 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj } /*! - * \brief show the result of the array + * \brief show the result of the array to confirm + * before inserting * \param $p_array array from the form * \return string */ function show_summary($p_array) { + /** + *@todo add a call to verify ??? + */ $this->id=$p_array['p_jrn']; if ( empty($p_array)) return 'Aucun résultat'; + $anc=null; extract($p_array); $lPeriode=new Periode($this->db); if ($this->check_periode() == true) { @@ -1007,6 +1012,8 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj } else { $lPeriode->find_periode($date); } + $owner=new own($this->db); + $ret=""; $ret.=""; $ret.=""; @@ -1022,8 +1029,18 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj $ret.=_("Poste")." "; $ret.=""; $ret.=""; + /* if we use the AC */ + if ($owner->MY_ANALYTIC!='nu') { + $anc=new Anc_Plan($this->db); + $a_anc=$anc->get_list(); + $x=count($a_anc); + /* set the width of the col */ + $ret.=''; + + /* add hidden variables pa[] to hold the value of pa_id */ + $ret.=Anc_Plan::hidden($a_anc); + } $ret.=""; - $own=new own($this->db); $ret.=HtmlInput::hidden('date',$date); $ret.=HtmlInput::hidden('desc',$desc); @@ -1072,14 +1089,18 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj $ret.=""; // CA - if ( $own->MY_ANALYTIC!='nu') // use of AA + if ( $owner->MY_ANALYTIC!='nu') // use of AA { if ( myereg("^[6,7]+",$strPoste)) { // show form $op=new Anc_Operation($this->db); - $null=($own->MY_ANALYTIC=='op')?1:0; + $null=($owner->MY_ANALYTIC=='op')?1:0; + $p_array['pa_id']=$a_anc; + /* op is the operation it contains either a sequence or a jrnx.j_id */ + $ret.=HtmlInput::hidden('op[]=',$i); + $ret.=''; $count++; } @@ -1186,8 +1207,8 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj /* suggest PJ ? */ $default_pj=''; - $own=new Own($this->db); - if ( $own->MY_PJ_SUGGEST=='Y') { + $owner=new Own($this->db); + if ( $owner->MY_PJ_SUGGEST=='Y') { $default_pj=$this->guess_pj(); } $wPJ->value=(isset($e_pj))?$e_pj:$default_pj; @@ -1460,7 +1481,7 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj $internal=$this->compute_internal_code($seq); $group=$this->db->get_next_seq("s_oa_group"); - $own=new own($this->db); + $owner=new own($this->db); $tot_amount=0; $tot_deb=0; $tot_cred=0; @@ -1512,7 +1533,7 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj $tot_amount+=round($acc_op->amount,2); $tot_deb+=($acc_op->type=='d')?$acc_op->amount:0; $tot_cred+=($acc_op->type=='c')?$acc_op->amount:0; - if ( $own->MY_ANALYTIC != "nu" ) + if ( $owner->MY_ANALYTIC != "nu" ) { if ( myereg("^[6,7]+",$poste)) { @@ -1523,7 +1544,7 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj $op->oa_date=$date; $op->oa_debit=($acc_op->type=='d' )?'t':'f'; $op->oa_description=$desc; - $op->save_form_plan($p_array,$count); + $op->save_form_plan($p_array,$count,$j_id); $count++; } } @@ -1711,9 +1732,9 @@ jr_comment||' ('||jr_internal||')'||case when jr_pj_number is not null and jr_pj * \return true if we are using the strict_mode */ function check_strict() { - $own=new Own($this->db); - if ( $own->MY_STRICT=='Y') return true; - if ( $own->MY_STRICT=='N') return false; + $owner=new Own($this->db); + if ( $owner->MY_STRICT=='Y') return true; + if ( $owner->MY_STRICT=='N') return false; exit("Valeur invalid ".__FILE__.':'.__LINE__); } /*! @@ -1722,9 +1743,9 @@ function check_strict() { * \return true if we are using the double encoding (date+periode) */ function check_periode() { - $own=new Own($this->db); - if ( $own->MY_CHECK_PERIODE=='Y') return true; - if ( $own->MY_CHECK_PERIODE=='N') return false; + $owner=new Own($this->db); + if ( $owner->MY_CHECK_PERIODE=='Y') return true; + if ( $owner->MY_CHECK_PERIODE=='N') return false; exit("Valeur invalid ".__FILE__.':'.__LINE__); } diff --git a/include/class_acc_ledger_purchase.php b/include/class_acc_ledger_purchase.php index 9a643dab5..5c405a737 100644 --- a/include/class_acc_ledger_purchase.php +++ b/include/class_acc_ledger_purchase.php @@ -416,7 +416,7 @@ class Acc_Ledger_Purchase extends Acc_Ledger { $op->oa_date=$e_date; $op->oa_debit=($amount < 0 )?'t':'f'; $op->oa_description=FormatString($e_comm); - $op->save_form_plan($_POST,$i); + $op->save_form_plan($_POST,$i,$j_id); } // insert into quant_purchase //----- @@ -1051,7 +1051,7 @@ array function confirm($p_array) { extract ($p_array); $this->verify($p_array) ; - + $anc=null; // to show a select list for the analytic // if analytic is op (optionnel) there is a blank line $owner = new Own($this->db); @@ -1106,7 +1106,19 @@ array $r.=""; $r.='"; } - $r.=($owner->MY_ANALYTIC!='nu')?'':''; + + /* if we use the AC */ + if ($owner->MY_ANALYTIC!='nu') { + $anc=new Anc_Plan($this->db); + $a_anc=$anc->get_list(); + $x=count($a_anc); + /* set the width of the col */ + $r.=''; + + /* add hidden variables pa[] to hold the value of pa_id */ + $r.=Anc_Plan::hidden($a_anc); + } + $r.=''; $tot_amount=0.0; $tot_tva=0.0; @@ -1182,6 +1194,9 @@ array $null=($owner->MY_ANALYTIC=='op')?1:0; $r.=''; } diff --git a/include/class_acc_ledger_sold.php b/include/class_acc_ledger_sold.php index ffe0f2389..97bff60b6 100644 --- a/include/class_acc_ledger_sold.php +++ b/include/class_acc_ledger_sold.php @@ -57,8 +57,12 @@ class Acc_Ledger_Sold extends Acc_Ledger { public function verify($p_array) { extract ($p_array); /* check for a double reload */ - if ( isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1',array($mt)) != 0 ) + /** + *@todo REMOVE DEBUG FALSE + */ + if ( false && isset($mt) && $this->db->count_sql('select jr_mt from jrn where jr_mt=$1',array($mt)) != 0 ) throw new Exception (_('Double Encodage'),5); + /* check if we can write into this ledger */ $user=new User($this->db); if ( $user->check_jrn($p_jrn) != 'W' ) @@ -205,7 +209,6 @@ class Acc_Ledger_Sold extends Acc_Ledger { *\note throw an Exception */ public function insert($p_array) { - extract ($p_array); $this->verify($p_array) ; @@ -308,6 +311,7 @@ class Acc_Ledger_Sold extends Acc_Ledger { if ( $owner->MY_ANALYTIC != "nu" ) { + var_dump("save anal"); // for each item, insert into operation_analytique */ $op=new Anc_Operation($this->db); $op->oa_group=$group; @@ -315,7 +319,7 @@ class Acc_Ledger_Sold extends Acc_Ledger { $op->oa_date=$e_date; $op->oa_debit=($amount < 0 )?'t':'f'; $op->oa_description=FormatString($e_comm); - $op->save_form_plan($_POST,$i); + $op->save_form_plan($_POST,$i,$j_id); } if ( $owner->MY_TVA_USE=='Y') { /* save into quant_sold */ @@ -531,7 +535,7 @@ class Acc_Ledger_Sold extends Acc_Ledger { function confirm($p_array) { extract ($p_array); $this->verify($p_array) ; - + $anc=null; // to show a select list for the analytic & VAT USE // if analytic is op (optionnel) there is a blank line $owner = new Own($this->db); @@ -584,7 +588,17 @@ class Acc_Ledger_Sold extends Acc_Ledger { $r.=''; $r.=''; } - $r.=($owner->MY_ANALYTIC!='nu')?'':''; + /* if we use the AC */ + if ($owner->MY_ANALYTIC!='nu') { + $anc=new Anc_Plan($this->db); + $a_anc=$anc->get_list(); + $x=count($a_anc); + /* set the width of the col */ + $r.=''; + + /* add hidden variables pa[] to hold the value of pa_id */ + $r.=Anc_Plan::hidden($a_anc); + } $r.=''; $tot_amount=0.0; $tot_tva=0.0; @@ -654,6 +668,9 @@ class Acc_Ledger_Sold extends Acc_Ledger { $null=($owner->MY_ANALYTIC=='op')?1:0; $r.=''; } diff --git a/include/class_anc_operation.php b/include/class_anc_operation.php index f708f2115..7084a8e1e 100644 --- a/include/class_anc_operation.php +++ b/include/class_anc_operation.php @@ -289,7 +289,7 @@ class Anc_Operation oa_row from operation_analytique where - j_id=$p_jid order by j_id,oa_row"; + j_id=$p_jid order by j_id,pa_id,oa_row"; $ret=$this->db->exec_sql($sql); $res=Database::fetch_all($ret); if ( $res== false) return null; @@ -395,48 +395,45 @@ function get_balance($p_from,$p_to,$p_plan_id) $result.='
"._('Date')." : $date
"._("Montant")." "._("Débit")."'._('Compt. Analytique').'
'; - $ret.=$op->display_form_plan(null,$null,1,$count,round(${'amount'.$i},2)); + $ret.=$op->display_form_plan($p_array,$null,1,$count,round(${'amount'.$i},2)); $ret.='"._('quantité')." '._('Total')."'._('Compt. Analytique').''._('Compt. Analytique').'
'; $p_mode=1; + $p_array['pa_id']=$a_anc; + /* op is the operation it contains either a sequence or a jrnx.j_id */ + $r.=HtmlInput::hidden('op[]=',$i); $r.=$anc_op->display_form_plan($p_array,$null,$p_mode,$i,$amount); $r.=' '._('Montant TVA').''._('Montant HTVA').''._('Compt. Analytique').''._('Compt. Analytique').'
'; $p_mode=1; + $p_array['pa_id']=$a_anc; + /* op is the operation it contains either a sequence or a jrnx.j_id */ + $r.=HtmlInput::hidden('op[]=',$i); $r.=$anc_op->display_form_plan($p_array,$null,$p_mode,$i,$amount); $r.='
'; $result.="".$plan->header().""; + /* compute the number of rows */ + $nb_row=count($p_array['pa_id'])/count($a_plan); - - $nb_row=(!isset(${'nb_'.$table_id}))?1:${'nb_'.$table_id}; - $result.=$hidden->input('nb_'.$table_id,$nb_row); - - for ( $i=1; $i <= $nb_row;$i++) { + for ( $i=0; $i < $nb_row;$i++) { $result.=''; $count=0; foreach ($a_plan as $r_plan) { - $count++; $array=$this->db->make_array( - "select pa_id||'_'||po_id as value,". + "select po_id as value,". " html_quote(po_name) as label from poste_analytique ". " where pa_id = ".$r_plan['id']. " order by po_name",$p_null); - $select =new ISelect("ta_".$p_seq."o".$count."row_".$i,$array); + $select =new ISelect("hplan[".$p_seq."][]",$array); $select->table=0; - // view only or editable + // view only or editables if ( $p_mode==1 ) { // editable $select->readonly=false; - $select->selected=(isset(${"ta_".$p_seq."o".$count."row_".$i}))?${"ta_".$p_seq."o".$count."row_".$i}:0; + if ( isset($hplan) ) + $select->selected=$hplan[$p_seq][$count]; } else { // view only $select->readonly=true; - $select->selected=(isset(${"ta_".$p_seq."o".$count."row_".$i}))?${"ta_".$p_seq."o".$count."row_".$i}:0; } if ($p_mode==1) - $result.=''; - else $result.=''; + else + $result.=''; + $count++; } $value=new INum(); - $value->name="val".$p_seq."l$i"; + $value->name="val[".$p_seq."][]"; $value->size=6; - $value->value=(isset(${"val".$p_seq."l$i"}))?round(${"val".$p_seq."l$i"},2):$p_amount; - // $value->value=($p_doc=="form")?$p_amount:round(${"val".$p_seq."l$i"},2); + // $value->value=(isset(${"val".$p_seq."l$i"}))?round(${"val".$p_seq."l$i"},2):$p_amount; $value->readonly=($p_mode==1)?false:true; $result.=''; @@ -447,7 +444,7 @@ function get_balance($p_from,$p_to,$p_plan_id) $result.="
montant
'.$select->input().''.$select->input().''.$select->display().''.$value->input().'
"; // add a button to add a row $button=new IButton(); - $button->javascript="add_row('".$p_id."$table_id',$p_seq,$count);"; + $button->javascript="add_row('".$p_id."$table_id',$p_seq);"; $button->name="js".$p_id.$p_seq; $button->label="Nouvelle ligne"; if ( $p_mode == 1 ) @@ -475,41 +472,48 @@ function get_balance($p_from,$p_to,$p_plan_id) * -oa_description * */ - function save_form_plan($p_array,$p_item) { + function save_form_plan($p_array,$p_item,$j_id) { extract($p_array); - if ( !isset (${"nb_t".$p_item}) ) { - // echo __FILE__.':'.__LINE."nb_t".$p_item." n'est pas defini !!!"; - return; + /* variable for in array + pa_id array of existing pa_id + hplan double array with the pa_id (column) + val double array by row with amount + op contains sequence + p_item is used to identify what op is concerned + */ + /* for each row */ + for ($i=0;$i= (count($pa_id)-1)) { + $idx_pa_id=0; + } + echo "p_item[$p_item] e[$e]"; + echo $hplan[$p_item][$e]; + if ($hplan[$p_item][$e] != -1 && $val[$p_item][$i] != '') + { + echo "insert"; + $op=new Anc_Operation($this->db); + $op->po_id=$hplan[$p_item][$e]; + $op->pa_id=$pa_id[$idx_pa_id]; + $op->oa_group=$this->oa_group; + $op->j_id=$j_id; + $op->oa_amount=$val[$p_item][$i]; + $op->oa_debit=$this->oa_debit; + $op->oa_date=$this->oa_date; + + $op->oa_description=$this->oa_description; + $op->oa_row=$i; + $op->add(); + } + $idx_pa_id++; + } } - $max=${"nb_t".$p_item}; - // get all the PA - $plan=new Anc_Plan($this->db); - $cplan=$plan->count(); - // foreach row - for ($i=1;$i<=$max;$i++) { - - // foreach col PA - for ($e=1;$e<=$cplan+1;$e++) - { - if ( isset(${"ta_".$p_item."o".$e."row_".$i}) && ${"ta_".$p_item."o".$e."row_".$i}!=-1) - { - $op=new Anc_Operation($this->db); - $val=${"ta_".$p_item."o".$e."row_".$i}; - list($op->pa_id,$op->po_id)=sscanf($val,"%d_%d"); - $op->oa_group=$this->oa_group; - $op->j_id=$this->j_id; - $op->oa_amount=${"val".$p_item."l".$i}; - $op->oa_debit=$this->oa_debit; - $op->oa_date=$this->oa_date; - - $op->oa_description=$this->oa_description; - $op->oa_row=$i; - $op->add(); - } - } - } - } + + /*\brief transform a array of operation into a array usage by *display_form_plan & save_form_plan *\param $p_array array of operation @@ -517,35 +521,30 @@ function get_balance($p_from,$p_to,$p_plan_id) *\return an array complying with \see save_form_plan */ function to_request ($p_array,$p_line){ - if ( count($p_array) == 0 ) { - return null; - } + var_dump($p_array); $result=array(); - $table="nb_t".$p_line; + $result[]=array('op'=>$this->j_id); + $pa_id=array(); - $col=1; - $line=1; - $first=true; - $last_pa_id=0; - foreach ( $p_array as $row) { - $val="val".$p_line."l".$row->oa_row; - $result[$val]=$row->oa_amount; - if ( $first ) { - $first_pa_id=$row->pa_id; - $first=false; - } - - if ( $first_pa_id != $row->pa_id ) - $col++; - else { - $col=1; - $line++; - } - $po="ta_".$p_line."o".$col."row_".$row->oa_row; - $result[$po]=$row->pa_id."_".$row->po_id; - // $last_pa_id=$row->pa_id; + /* First add the pa_id */ + for ($i=0;$i < count($p_array);$i++){ + if ( in_array($p_array[$i]->pa_id,$pa_id)==false) + $pa_id[]=$p_array[$i]->pa_id; } - $result[$table]=$line-1; + $result['pa_id']=$pa_id; + + /* add the hplan */ + $seq=0; + for ($i=0;$i < count($p_array);$i++){ + $hplan[$p_line][$i]=$p_array[$i]->po_id; + } + $result['hplan']=$hplan; + /* Add the amount */ + $idx_pa=0; + for ($i=0;$i < count($p_array);$i++){ + $val[$p_line][$p_array[$i]->oa_row]=$p_array[$i]->oa_amount; + } + $result['val']=$val; return $result; } /*! @@ -561,14 +560,13 @@ function get_balance($p_from,$p_to,$p_plan_id) /*\brief Display a table with analytic accounting in * detail of operation *@note $this->j_id must be set - *\param $p_own object own *\param $p_mode 0 = readonly or 1=writable *\param $p_amount amount *\param $p_id unique id *@see display_form_plan *\return string to display */ - function display_table($p_own,$p_mode,$p_amount,$p_id) { + function display_table($p_mode,$p_amount,$p_id) { static $seq=0; $seq++; @@ -582,17 +580,23 @@ function get_balance($p_from,$p_to,$p_plan_id) return ""; } - +/////////////////////////////////////////////////////////////////////////// +// TEST +/////////////////////////////////////////////////////////////////////////// /*\brief test the class *\param *\param *\return */ function test_me() { - $array=$this->get_by_jid(442); - - $a=$this->to_request($array,1); + $cn=new Database(dossier::id()); + $anco=new Anc_Operation($cn); + $anco->j_id=141; + $array=$anco->get_by_jid(141); + $a=$anco->to_request($array,1); + echo $anco->display_table(1,15002,0); + var_dump($a); } diff --git a/include/class_anc_plan.php b/include/class_anc_plan.php index 288db1049..c0be0c9cd 100644 --- a/include/class_anc_plan.php +++ b/include/class_anc_plan.php @@ -180,6 +180,22 @@ class Anc_Plan return ($a==0)?false:true; + } + /** + *@brief return an HTML string containing hidden input type to + * hold the differant PA_ID + *@param $p_array contains a array, it is the result of the fct + * Anc_Plan::get_list + *@return html string + *@see Anc_Plan::get_list + */ + static function hidden($p_array) { + var_dump($p_array); + $r=''; + for ($i_anc=0;$i_anc Plan Analytique) \ No newline at end of file