From 93ec9c2e38b1e1d3bf3f5fd011f2277014373e3f Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Thu, 14 Jun 2012 13:35:15 +0000 Subject: [PATCH] Add HtmlInput::select_stock Add function User::can_write_action and User::can_write_repo Insert into the stock with repository Let select the stock in Acc_Ledger_Purchase::confirm --- include/class_acc_ledger_purchase.php | 18 ++++++---- include/class_html_input.php | 30 ++++++++++++++++ include/class_user.php | 52 +++++++++++++++++++++++++-- include/user_common.php | 47 +++++++++++++----------- 4 files changed, 119 insertions(+), 28 deletions(-) diff --git a/include/class_acc_ledger_purchase.php b/include/class_acc_ledger_purchase.php index 8e7652846..3f75da96c 100644 --- a/include/class_acc_ledger_purchase.php +++ b/include/class_acc_ledger_purchase.php @@ -471,8 +471,8 @@ class Acc_Ledger_Purchase extends Acc_Ledger // always save quantity but in withStock we can find // what card need a stock management - - InsertStockGoods($this->db,$j_id,${'e_march'.$i},$nNeg*${'e_quant'.$i},'d') ; + if ( $g_parameter->MY_STOCK='Y') + InsertStockGoods($this->db,$j_id,${'e_march'.$i},$nNeg*${'e_quant'.$i},'d') ; if ( $g_parameter->MY_ANALYTIC != "nu" ) { @@ -1504,8 +1504,10 @@ class Acc_Ledger_Purchase extends Acc_Ledger $r.=HtmlInput::hidden("e_quant".$i,${"e_quant".$i}); } - if ( ! $p_summary ) $r.=$this->extra_info(); - if ( $e_mp!=0 && strlen (trim (${'e_mp_qcode_'.$e_mp})) != 0 ) + if ( ! $p_summary ) + $r.=$this->extra_info(); + + if ( $e_mp!=0 && strlen (trim (${'e_mp_qcode_'.$e_mp})) != 0 ) { $r.=HtmlInput::hidden('e_mp_qcode_'.$e_mp,${'e_mp_qcode_'.$e_mp}); $r.=HtmlInput::hidden('acompte',$acompte); @@ -1518,8 +1520,12 @@ class Acc_Ledger_Purchase extends Acc_Ledger $r.='
'; } // check for upload piece - - + + // Show the available repository + if ( $g_parameter->MY_STOCK=='Y') + { + $r.=HtmlInput::select_stock('repo','W'); + } return $r; } diff --git a/include/class_html_input.php b/include/class_html_input.php index 77bc7e0e7..c22266816 100755 --- a/include/class_html_input.php +++ b/include/class_html_input.php @@ -616,4 +616,34 @@ class HtmlInput $p_url,$p_js,$p_text); return $str; } + /** + *Create an ISelect object containing the available repository for reading + * or writing + * @global $g_user + * @param $p_cn db object + * @param $p_name name of the select + * @param $p_mode is 'R' for reading, 'W' for writinh + * @return ISelect + * @throws Exception if p_mode is wrong + */ + static function select_stock( $p_cn, $p_name,$p_mode) + { + global $g_user; + if ( in_array($p_mode,array('R','W') ) ) + { + throw new Exception (__FILE__.":".__LINE__." $p_mode invalide"); + } + $profile=$g_user->get_profile(); + $sel=new ISelect($p_name); + + $write=($p_mode=='W')?"ur_right='W' and ":""; + + $sel->value=$p_cn->make_array(" + select r_id,r_name from stock_repository + where + $write p_id=$1 + order by 2 + ",array($profile)); + return $sel; + } } \ No newline at end of file diff --git a/include/class_user.php b/include/class_user.php index f0b09d9e4..90c53f5e6 100644 --- a/include/class_user.php +++ b/include/class_user.php @@ -1024,14 +1024,21 @@ class User $this->db->exec_sql("update profile_user set p_id=$1 where user_name=$2", array($p_id, $this->login)); } } - + /** + *return the profile (p_id) + * @return profile.p_id + */ function get_profile() { $profile = $this->db->get_value("select p_id from profile_user where user_name=$1", array($this->login)); return $profile; } - + /** + *Check if the profile of the user can write for this profile + * @param $dtoc action_gestion.ag_id + * @return true if he can write otherwise false + */ function can_write_action($dtoc) { $profile = $this->get_profile(); @@ -1042,6 +1049,11 @@ class User return true; } + /** + *Check if the profile of the user can write for this profile + * @param $dtoc action_gestion.ag_id + * @return true if he can write otherwise false + */ function can_read_action($dtoc) { $profile = $this->get_profile(); @@ -1051,6 +1063,42 @@ class User return false; return true; } + /** + *Check if the profile of the user can write for this repository + * @param $p_repo stock_repository.r_id + * @return true if he can write otherwise false + */ + function can_write_repo($p_repo) + { + $profile=$this->get_profile(); + $r=$this->db->get_value("select count(*) + from user_sec_repository + where + r_id=$1 + and p_id =$2 + and ur_right='W'",array($p_repo,$profile)); + if ( $r==0) + return false; + return true; + } + /** + *Check if the profile of the user can read for this repository + * @param $p_repo stock_repository.r_id + * @return true if he read write otherwise false + */ + function can_read_repo($p_repo) + { + $profile=$this->get_profile(); + $r=$this->db->get_value("select count(*) + from user_sec_repository + where + r_id=$1 + and p_id =$2 + ",array($p_repo,$profile)); + if ( $r==0) + return false; + return true; + } } diff --git a/include/user_common.php b/include/user_common.php index 0d50864ec..cc2f65f3e 100644 --- a/include/user_common.php +++ b/include/user_common.php @@ -44,38 +44,45 @@ require_once("class_acc_operation.php"); * \param $p_j_id the j_id * \param $p_good the goods * \param $p_quant quantity - * \param $p_type c for credit or d for debit + * \param $p_type c for SALE or d for PURCHASE * - * \return none + * \return $res of the insert or false if something gets wrong * \note Link to jrn gives the date */ -function InsertStockGoods($p_cn,$p_j_id,$p_good,$p_quant,$p_type) +function InsertStockGoods($p_cn, $p_j_id, $p_good, $p_quant, $p_type,$p_depot) { global $g_user; + if ( $g_user->can_write_repo($p_depo) == false ) + return false; + // Retrieve the good account for stock - $code=new Fiche($p_cn); + $code = new Fiche($p_cn); $code->get_by_qcode($p_good); - $code_marchandise=$code->strAttribut(ATTR_DEF_STOCK); - $p_good=sql_string($p_good); - $sql="select f_id from vw_poste_qcode where j_qcode=upper('$p_good')"; - $Res=$p_cn->exec_sql($sql); - $r=Database::fetch_array($Res,0); - $f_id=$r['f_id']; - $exercice=$g_user->get_exercice(); - if ( $exercice == 0 ) throw new Exception ('Annee invalide erreur'); + $code_marchandise = $code->strAttribut(ATTR_DEF_STOCK); + if ( $code_marchandise == NOTFOUND ) + return false; + + $exercice = $g_user->get_exercice(); + + if ($exercice == 0) + throw new Exception('Annee invalide erreur'); - - $Res=$p_cn->exec_sql("insert into stock_goods ( + $Res = $p_cn->exec_sql("insert into stock_goods ( j_id, f_id, sg_code, sg_quantity, - sg_type,sg_exercice ) values ( - $p_j_id, - $f_id, - '$code_marchandise', - $p_quant, '$p_type',$exercice) - "); + sg_type,sg_exercice,r_id ) values ($1,$2,$3,$4,$5,$6,$7)", + array( + $p_j_id, + $code->id, + $code_marchandise, + $p_quant, + $p_type, + $exercice, + $p_depot + ) + ); return $Res; }