From 39c8f73c08f78f653fd0cf4356bf92e05aa55b34 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Fri, 18 Jan 2008 20:14:05 +0000 Subject: [PATCH] initial stock when a new stock code is used --- include/class_fiche.php | 39 ++++++++++++++++++++++++++++++++++++++- include/stock_inc.php | 8 +++++++- include/user_common.php | 9 +++++++-- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/include/class_fiche.php b/include/class_fiche.php index 4cf45c5c6..810980945 100644 --- a/include/class_fiche.php +++ b/include/class_fiche.php @@ -462,6 +462,25 @@ class fiche { ExecSql($this->cn,$sql); continue; } + // stock + if ( $id == ATTR_DEF_STOCK ) { + $st=CountSql($this->cn,'select * from stock_goods where '. + " upper(sg_code)=upper('$value')"); + if ( $st == 0 ) { + $user=new User($this->cn); + $exercice=$user->get_exercice(); + if ( $exercice == 0 ) throw Exception ('Annee invalide erreur'); + + $str_stock=sprintf('insert into stock_goods(f_id,sg_initial,sg_code,sg_type,sg_exercice) '. + ' values (%d,upper(\'%s\'),\'c\',\'%s\')', + $fiche_id, + 'initial', + FormatString($value), + $exercice); + + ExecSql($this->cn,$str_stock); + } + } // name if ( $id == ATTR_DEF_NAME ) { @@ -598,7 +617,25 @@ class fiche { } - + if ( $id == ATTR_DEF_STOCK ) { + $st=CountSql($this->cn,'select * from stock_goods where '. + " upper(sg_code)=upper('$value')"); + if ( $st == 0 ) { + $user=new User($this->cn); + $exercice=$user->get_exercice(); + if ( $exercice == 0 ) throw Exception ('Annee invalide erreur'); + + $str_stock=sprintf('insert into stock_goods(f_id,sg_comment,sg_code,sg_type,sg_exercice) '. + ' values (%d,upper(\'%s\'),\'d\',\'%s\')', + $this->id, + 'initial', + FormatString($value), + $exercice); + + ExecSql($this->cn,$str_stock); + } + } + // account if ( $id == ATTR_DEF_ACCOUNT ) { diff --git a/include/stock_inc.php b/include/stock_inc.php index eb7494c49..4421c619c 100644 --- a/include/stock_inc.php +++ b/include/stock_inc.php @@ -36,13 +36,19 @@ function ViewStock($p_cn,$p_year) { // build sql -- get the different merchandise sold or bought // during the p_year -$sql=" select distinct sg_code + /* $sql=" select distinct sg_code from stock_goods left outer join jrnx on (stock_goods.j_id=jrnx.j_id) right outer join parm_periode on (parm_periode.p_id=jrnx.j_tech_per) where p_exercice= '$p_year' and sg_code is not null and sg_code != '' and sg_code!='null'"; + */ +$sql=" select distinct sg_code + from stock_goods +where + sg_code is not null and sg_code != '' and sg_code!='null'"; + // send the sql diff --git a/include/user_common.php b/include/user_common.php index b051c52b4..f82db5902 100644 --- a/include/user_common.php +++ b/include/user_common.php @@ -788,16 +788,21 @@ function InsertStockGoods($p_cn,$p_j_id,$p_good,$p_quant,$p_type) $Res=ExecSql($p_cn,$sql); $r=pg_fetch_array($Res,0); $f_id=$r['f_id']; + $user=new User($p_cn); + $exercice=$user->get_exercice(); + if ( $exercice == 0 ) throw Exception ('Annee invalide erreur'); + + $Res=ExecSql($p_cn,"insert into stock_goods ( j_id, f_id, sg_code, sg_quantity, - sg_type ) values ( + sg_type,sg_exercice ) values ( $p_j_id, $f_id, '$code_marchandise', - $p_quant, '$p_type') + $p_quant, '$p_type',$exercice) "); return $Res; }