From 0c7bf1482622ed11662ae1db32694ef9bd788743 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Tue, 16 Oct 2007 22:04:33 +0000 Subject: [PATCH] Multiple selection for reconciliation, acc_ledger can now add a reconciliation --- html/admin/sql/patch/upgrade32.sql | 2 +- html/annulation.php | 12 +- html/jrn_search.php | 2 +- html/js/jrn_concerned.js | 30 +++- html/modify_op.php | 2 +- include/class_acc_ledger.php | 40 +++++- include/class_acc_reconciliation.php | 196 +++++++++++++++++++++++++++ include/class_widget.php | 8 +- include/quick_writing.inc.php | 5 + include/user_common.php | 9 +- include/user_form_fin.php | 2 +- scripts/cleanup.sh | 2 +- 12 files changed, 283 insertions(+), 27 deletions(-) create mode 100644 include/class_acc_reconciliation.php diff --git a/html/admin/sql/patch/upgrade32.sql b/html/admin/sql/patch/upgrade32.sql index 55d77a27c..fa6b3c44b 100644 --- a/html/admin/sql/patch/upgrade32.sql +++ b/html/admin/sql/patch/upgrade32.sql @@ -4,7 +4,7 @@ delete from jrnx where j_grpt not in (select jr_grpt_id from jrn); alter table op_predef add od_direct bool; update op_predef set od_direct=false; alter table op_predef alter od_direct set not null; -alter table op_predef_detail add od_qc bool; +alter table op_predef_detail add opd_qc bool; update version set val=33; commit; diff --git a/html/annulation.php b/html/annulation.php index 0a01de03e..57d631ec8 100644 --- a/html/annulation.php +++ b/html/annulation.php @@ -40,7 +40,7 @@ $User=new cl_user($cn); $User->Check(); html_page_start($User->theme,"onLoad='window.focus();'"); - +echo JS_VIEW_JRN_MODIFY; if ( isset( $_GET['p_jrn'] )) { $p_jrn=$_GET['p_jrn']; } @@ -397,10 +397,18 @@ for ( $i = 0; $i < $max_cred;$i++) { $a=GetConcerned($cn,$e_jr_id); if ( $a != null ) { + foreach ($a as $key => $element) { echo "operation concernée
"; - echo " ".GetInternal($cn,$element)."
"; + // echo " + // ".GetInternal($cn,$element)."
"; + $w=new widget("button"); + $w->label=GetInternal($cn,$element); + $w->javascript="modifyOperation('".$element."','".$_REQUEST['PHPSESSID']."',".dossier::id(). + ','.$_REQUEST['p_jrn'].",'S')"; + echo $w->IOValue().'
'; }//for }// if ( $a != null ) { diff --git a/html/jrn_search.php b/html/jrn_search.php index 9b87c53a5..61c3269bc 100644 --- a/html/jrn_search.php +++ b/html/jrn_search.php @@ -166,7 +166,7 @@ if ( isset ($_GET["search"]) ) { $page=(isset($_GET['page']))?$_GET['page']:0; $sql_limit=" LIMIT $limit "; $sql_offset=" OFFSET $offset "; - $bar=jrn_navigation_bar($offset,$MaxLine,$limit,$page); + $bar=jrn_navigation_bar($offset,$MaxLine,$limit,$page,'onClick="return go_next_concerned();"'); } $sql.=$sql_limit.$sql_offset; diff --git a/html/js/jrn_concerned.js b/html/js/jrn_concerned.js index 270e61879..cb565f15a 100644 --- a/html/js/jrn_concerned.js +++ b/html/js/jrn_concerned.js @@ -40,14 +40,18 @@ function SearchJrn(p_sessid,p_dossier,p_ctl,p_montant,p_paid) /* Get the amount */ var ctl_montant_name="e_other"+num+"_amount"; - for ( i=0; i < document.forms[0].length; i++) - { - var e=document.forms[0].elements[i]; - if ( e.name == ctl_montant_name ) { - p_montant=e.value; - break; + + if ( document.forms[0]) { + + for ( i=0; i < document.forms[0].length; i++) + { + var e=document.forms[0].elements[i]; + if ( e.name == ctl_montant_name ) { + p_montant=e.value; + break; } - } + } + } } @@ -73,13 +77,25 @@ function updateJrn(p_ctl) { } } } + window.close(); } function GetIt(p_ctl,p_value) { self.opener.SetIt(p_value,p_ctl); window.close(); } +function go_next_concerned() { + var form=document.forms[1]; + for (var e=0;eid=$p_id; $this->db=$p_cn; @@ -756,6 +761,9 @@ class Acc_Ledger { $ret.=$hidden->IOValue('jrn_type',$this->get_type()); $ret.=$hidden->IOValue('p_jrn',$this->id); $ret.=$hidden->IOValue('nb_item',$this->nb); + if ( $this->with_concerned==true) { + $ret.=$hidden->IOValue('jrn_concerned',$jrn_concerned); + } $ret.=dossier::hidden(); $count=0; for ($i=0;$i<$this->nb;$i++) { @@ -822,7 +830,7 @@ class Acc_Ledger { { if ( $p_readonly == 1 ) return $this->show_summary($p_array); - + if ( $p_array != null ) extract($p_array); @@ -913,6 +921,13 @@ class Acc_Ledger { // If readonly == 1 then show CA } $ret.=''; + if ( isset ($this->with_concerned) && $this->with_concerned==true) { + $oRapt=new Acc_Reconciliation($this->db); + $w=$oRapt->widget(); + $w->name='jrn_concerned'; + $w->value=(isset($jrn_concerned))?$jrn_concerned:""; + $ret.=$w->IOValue(); + } return $ret; } /*! @@ -1059,7 +1074,8 @@ class Acc_Ledger { $acc_end->desc=$desc; $acc_end->grpt=$seq; $acc_end->jrn=$this->id; - if ( $acc_end->insert_jrn() == false ) + $jr_id= $acc_end->insert_jrn(); + if ($jr_id == false ) throw new Exception('Balance incorrecte'); ExecSql($this->db,"update jrn set jr_internal='".$internal."' where ". @@ -1073,7 +1089,15 @@ class Acc_Ledger { $opd->get_post(); $opd->save(); } + + if ( isset($this->with_concerned) && $this->with_concerned==true) { + $orap=new acc_reconciliation($this->db); + $orap->jr_id=$jr_id; + $orap->insert($jrn_concerned); } + + } + catch (AcException $a) { throw $a; } @@ -1113,6 +1137,7 @@ class Acc_Ledger { */ static function test_me() { + echo Acc_Reconciliation::$javascript; html_page_start(); $cn=DbConnect(dossier::id()); $_SESSION['g_user']='phpcompta'; @@ -1120,6 +1145,7 @@ class Acc_Ledger { $id=(isset ($_REQUEST['p_jrn']))?$_REQUEST['p_jrn']:-1; $a=new Acc_Ledger($cn,$id); + $a->with_concerned=true; // Vide echo '
'; echo $a->select_ledger()->IOValue(); diff --git a/include/class_acc_reconciliation.php b/include/class_acc_reconciliation.php new file mode 100644 index 000000000..1bb9baea8 --- /dev/null +++ b/include/class_acc_reconciliation.php @@ -0,0 +1,196 @@ +db=$cn; + $this->jr_id=0; + } + + function set_jr_id($jr_id) { + $this->jr_id=$jr_id; + } + /*! \brief return a widget of type js_concerned + */ + function widget() { + $wConcerned=new widget("js_concerned"); + $wConcerned->extra=0; // with 0 javascript search from e_amount... field (see javascript) + + return $wConcerned; + + } + /*! + *\brief Insert into jrn_rapt the concerned operations + * + * \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned or a string + * like "jr_id2,jr_id3,jr_id4..." + * + * \return none + * + */ + function insert($jr_id2) { + if ( trim($jr_id2) == "" ) + return; + if ( strpos($jr_id2,',') !== 0 ) + { + $aRapt=split(',',$jr_id2); + foreach ($aRapt as $rRapt) { + if ( isNumber($rRapt) == 1 ) + { + $this->insert_rapt($rRapt); + } + } + } else + if ( isNumber($jr_id2) == 1 ) + { + $this->insert_rapt($jr_id2); + } + } + + /*! + *\brief Insert into jrn_rapt the concerned operations + * should not be called directly, use insert instead + * + * \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned + * + * \return none + * + */ + function insert_rapt($jr_id2) { + if ( isNumber($this->jr_id) == 0 || isNumber($jr_id2) == 0 ) + { + return false; + } + if ( $this->jr_id==$jr_id2) + return true; + + // verify if exists + if ( CountSql($this->db, + "select jra_id from jrn_rapt where jra_concerned=".$this->jr_id. + " and jr_id=$jr_id2 + union + select jra_id from jrn_rapt where jra_id=".$this->jr_id. + " and jra_concerned=$jr_id2 ") + ==0) + { + // Ok we can insert + $Res=ExecSql($this->db,"insert into jrn_rapt(jr_id,jra_concerned) values ". + "(".$this->jr_id.",$jr_id2)"); + } + return true; + } + /*! + *\brief Insert into jrn_rapt the concerned operations + * + * \param $this->jr_id (jrn.jr_id) => jrn_rapt.jr_id + * \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned + * + * \return none + */ + function remove($jr_id2) { + if ( isNumber($this->jr_id) == 0 or + isNumber($jr_id2) == 0 ) + { + return; + } + // verify if exists + if ( CountSql($this->db,"select jra_id from jrn_rapt where ". + " jra_concerned=".$this->jr_id." and jr_id=$jr_id2 + union + select jra_id from jrn_rapt where jra_concerned=$jr_id2 ". + " and jr_id=".$this->jr_id) !=0) + { + // Ok we can delete + $Res=ExecSql($this->db,"delete from jrn_rapt where ". + "(jra_concerned=$jr_id2 and jr_id=".$this->jr_id.") or + (jra_concerned=".$this->jr_id." and jr_id=$jr_id2) "); + } + } + + /*! + *\brief Return an array of the concerned operation + * + * + *\param database connection + * \return array if something is found or null + */ + function get ( ) { + $sql=" select jr_id as cn from jrn_rapt where jra_concerned=".$this->jr_id. + " union ". + " select jra_concerned as cn from jrn_rapt where jr_id=".$this->jr_id; + $Res=ExecSql($this->db,$sql); + + // If nothing is found return null + $n=pg_NumRows($Res); + + if ($n ==0 ) return null; + + // put everything in an array + for ($i=0;$i<$n;$i++) { + $l=pg_fetch_array($Res,$i); + $r[$i]=$l['cn']; + } + return $r; + } + /*!\brief return the javascript function (static method) + * + static function javascript() { + return JS_CONCERNED_OP; + } + */ + static function test_me() { + $cn=DbConnect(dossier::id()); + $rap=new Acc_Reconciliation($cn); + $rap->set_jr_id(38); + $a=$rap->get(); + print_r($a); + $rap->remove(4); + $rap->insert("4,5,6"); + $a=$rap->get(); + print_r($a); + echo Acc_Reconciliation::$javascript; + $w=$rap->widget(); + $w->name="jr_concerned"; + + $w->extra2=""; + echo $w->IOValue(); + } + +} diff --git a/include/class_widget.php b/include/class_widget.php index f3eb4120e..ce4d40757 100644 --- a/include/class_widget.php +++ b/include/class_widget.php @@ -119,9 +119,13 @@ class widget { // Input text type $disabled = $this->disabled ? "readonly" : ""; if (strtoupper($this->type)=="TEXT") { - $readonly=($this->readonly==false)?" readonly ":""; + if ( $this->readonly==true ){ + $readonly=" readonly ";$style="border:solid 1px grey;color:black;background:lightblue;"; + } else { + $readonly=" ";$style="border:solid 1px blue;"; + } $this->value=str_replace('"','',$this->value); - $r='javascript." ".$disabled." $readonly >"; diff --git a/include/quick_writing.inc.php b/include/quick_writing.inc.php index 3e4a48a1e..711589768 100644 --- a/include/quick_writing.inc.php +++ b/include/quick_writing.inc.php @@ -28,6 +28,7 @@ * */ require_once ('class_acc_ledger.php'); +require_once ('class_acc_reconciliation.php'); $cn=DbConnect(dossier::id()); $id=(isset ($_REQUEST['p_jrn']))?$_REQUEST['p_jrn']:-1; @@ -35,6 +36,7 @@ $id=(isset ($_REQUEST['p_jrn']))?$_REQUEST['p_jrn']:-1; function show_direct_form($cn,$ledger,$p_array) { $id=(isset ($_REQUEST['p_jrn']))?$_REQUEST['p_jrn']:-1; echo JS_COMPUTE_DIRECT; + echo Acc_Reconciliation::$javascript; // Show the predef operation // Don't forget the p_jrn @@ -73,6 +75,7 @@ function show_direct_form($cn,$ledger,$p_array) { } $ledger=new Acc_Ledger($cn,$id); +$ledger->with_concerned=true; // no ledger selected, propose one if ($id == -1 ) { @@ -131,6 +134,8 @@ if ( isset($_POST['save_it' ])) { try { $ledger->save($array); + echo '

Opération enregistrée

'; + // echo $ledger->show_form($array,true); } catch (AcException $e) { echo '"; show_direct_form($cn,$ledger,$_POST); diff --git a/include/user_common.php b/include/user_common.php index f8cba9a1d..6b23cdd75 100644 --- a/include/user_common.php +++ b/include/user_common.php @@ -1032,6 +1032,7 @@ function isValid ($p_cn,$p_grpt_id) { * \param $p_line total of returned row * \param $p_size current g_pagesize user's preference * \param $p_page number of the page where the user is + * \param $p_javascript javascript code to add * \note example : \verbatim $step=$_SESSION['g_pagesize']; @@ -1043,7 +1044,7 @@ function isValid ($p_cn,$p_grpt_id) { \endverbatim * \return string with the nav. bar */ -function jrn_navigation_bar($p_offset,$p_line,$p_size=0,$p_page=1) +function jrn_navigation_bar($p_offset,$p_line,$p_size=0,$p_page=1,$p_javascript="") { echo_debug('user_common',__LINE__,"function jrn_navigation_bar($p_offset,$p_line,$p_size=0,$p_page=1)"); // if the pagesize is unlimited return "" @@ -1080,7 +1081,7 @@ function jrn_navigation_bar($p_offset,$p_line,$p_size=0,$p_page=1) $step=$p_size; $offset=($e-1)*$step; - $r=''; + $r=''; //$r.="Précédent"; $r.=''; $r.="  "; @@ -1103,7 +1104,7 @@ function jrn_navigation_bar($p_offset,$p_line,$p_size=0,$p_page=1) $go=$_SERVER['PHP_SELF']."?".$url."&offset=$offset&step=$step&page=$e&size=$step"; - $r.=sprintf('%d ',$go,$e); + $r.=sprintf('%d ',$go,$p_javascript,$e); } else { $r.=" [ $e ] "; } //else @@ -1116,7 +1117,7 @@ function jrn_navigation_bar($p_offset,$p_line,$p_size=0,$p_page=1) $step=$p_size; $offset=($e-1)*$step; - $r.=' '; + $r.=' '; //$r.="Suivant"; $r.=''; $r.=""; diff --git a/include/user_form_fin.php b/include/user_form_fin.php index 42d0e3fd6..2012ae9d3 100644 --- a/include/user_form_fin.php +++ b/include/user_form_fin.php @@ -415,7 +415,7 @@ function RecordFin($p_cn,$p_array,$p_user,$p_jrn) { $jr_id=InsertJrn($p_cn,$e_date,'',$p_jrn,FormatString(${"e_other$i"."_comment"}), $seq,$periode); -print_r('e_concerned'.$i.${"e_concerned".$i}); + if ( trim(${"e_concerned".$i}) != "" ) { if ( strpos(${"e_concerned".$i},',') !== 0 ) { diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh index 81b413e72..3cc3a8224 100755 --- a/scripts/cleanup.sh +++ b/scripts/cleanup.sh @@ -1,6 +1,6 @@ #!/bin/bash # clean all phpcompta related DB. -DOMAIN="beta3_" +DOMAIN="" export PGPASSWORD="dany" export PGUSER="phpcompta" export PGHOST=localhost