';
+$action= ( isset ($_GET['action']))? $_GET['action']:"";
include_once("stock_inc.php");
+// Adjust the stock
+if ( isset ($_POST['sub_change'])) {
+ $change=$_POST['stock_change'];
+ $sg_code=$_POST['sg_code'];
+ $sg_date=$_POST['sg_date'];
+ if ( isDate($sg_date) == null
+ or isNumber($change) == 0 ) {
+ $msg="Stock données non conformes";
+ echo "";
+ echo_error($msg);
+ } else {
+ // if neg the stock decrease => credit
+ $type=( $change < 0 )?'c':'d';
+ if ( $change != 0)
+ $Res=ExecSql($cn,"insert into stock_goods
+ ( j_id,
+ f_id,
+ sg_code,
+ sg_quantity,
+ sg_type,
+ sg_date,
+ sg_tech_user)
+ values (
+ null,
+ 0,
+ '$sg_code',
+ abs($change),
+ '$type',
+ to_date('$sg_date','DD.MM.YYYY'),
+ '$g_user');
+ ");
+ // to update the view
+ $action="detail";
+ }
+}
+
+// View the summary
// if year is not set then use the year of the user's periode
-if ( ! isset ($_GET['p_year']) ) {
+if ( ! isset ($_GET['year']) ) {
// get defaut periode
$a=GetUserPeriode($cn,$g_user);
// get exercice of periode
- $p_year=GetExercice($cn,$a);
+ $year=GetExercice($cn,$a);
} else
{
- $p_year=$_GET['p_year'];
+ $year=$_GET['year'];
}
+// View details
+if ( $action == 'detail' ) {
+
+ $sg_code=(isset ($_GET['sg_code'] ))?$_GET['sg_code']:$_POST['sg_code'];
+ $year=(isset($_GET['year']))?$_GET['year']:$_POST['year'];
+ $a=ViewDetailStock($cn,$sg_code,$year);
+ $b=ChangeStock($sg_code,$year);
+ echo '
' ;
+ echo $a;
+ echo 'Entrer la valeur qui doit augmenter ou diminuer le stock';
+ echo '';
+ echo '
';
+ exit();
+}
+
// Show the possible years
$sql="select distinct (p_exercice) as exercice from parm_periode ";
$Res=ExecSql($cn,$sql);
@@ -94,12 +150,10 @@ for ( $i = 0; $i < pg_NumRows($Res);$i++) {
// Show the current stock
echo '
';
echo $r;
-echo '
';
-
+html_page_stop();
?>
\ No newline at end of file
diff --git a/include/jrn.php b/include/jrn.php
index 68ca0c0ff..1d817ffd3 100644
--- a/include/jrn.php
+++ b/include/jrn.php
@@ -1,5 +1,4 @@
-
/*
* This file is part of PhpCompta.
*
diff --git a/include/postgres.php b/include/postgres.php
index 9d2e5a0d7..dbeeb51a9 100644
--- a/include/postgres.php
+++ b/include/postgres.php
@@ -147,8 +147,13 @@ function DbConnect($p_db="account_repository") {
*/
function ExecSql($p_connection, $p_string) {
echo_debug("SQL = $p_string");
+
$ret=pg_exec($p_connection,$p_string);
- if ( $ret == false ) { echo_error ("SQL ERROR ::: $p_string");}
+ if ( $ret == false ) {
+ echo_error ("SQL ERROR ::: $p_string");
+ exit(" Operation cancelled due to error : $p_string");
+ }
+
return $ret;
}
/*
diff --git a/include/stock_inc.php b/include/stock_inc.php
index 4e5562052..dc179975e 100644
--- a/include/stock_inc.php
+++ b/include/stock_inc.php
@@ -32,25 +32,45 @@
*/
function ViewStock($p_cn,$p_year) {
// build sql
-$sql=" select C.sg_code,sum(deb) as deb_sum,sum(cred) as cred_sum
- from jrnx
- join stock_goods using (j_id)
- join
+$sql=" select e.sg_code,sum(deb_sum) as deb_sum,sum(cred_sum) as cred_sum
+from ( select C.sg_code,sum(deb) as deb_sum,sum(cred) as cred_sum
+ from stock_goods
+ join jrnx using (j_id)
+ join
( select sg_code,j_id,
case when sg_type='d' then sg_quantity else 0 end as deb,
case when sg_type='c' then sg_quantity else 0 end as cred
from stock_goods
where sg_code is not null
and sg_code != 'null'
- ) as C on (jrnx.j_id=C.j_id)
+ ) as C on (C.j_id=jrnx.j_id)
where
- to_char(j_date,'YYYY') = '$p_year'
-group by c.sg_code";
+ ( to_char(j_date,'YYYY') = '$p_year'
+ or to_char(sg_date,'YYYY') = '$p_year'
+ )
+group by c.sg_code
+union
+select D.sg_code,sum(deb) as deb_sum,sum(cred) as cred_sum
+ from stock_goods
+ left outer join
+ ( select sg_code,j_id,
+ case when sg_type='d' then sg_quantity else 0 end as deb,
+ case when sg_type='c' then sg_quantity else 0 end as cred
+ from stock_goods
+ where f_id=0
+ ) as D using (sg_code)
+ where
+ to_char(sg_date,'YYYY') = '2003'
+
+group by d.sg_code ) as E
+group by e.sg_code
+";
// send the sql
$Res=ExecSql($p_cn,$sql);
+
if ( ( $M = pg_NumRows($Res)) == 0 ) return null;
// store it in a HTLM table
$result="
";
@@ -98,22 +118,6 @@ group by c.sg_code";
$result.="
";
return $result;
-}
-/* function ViewDetailStock ($p_cn,$p_f_id,$p_year)
- ************************************************************
- * Purpose : return all the stock movement
- *
- * parm :
- * - p_cn database connection
- * - p_f_id f_id concerned card
- * - year
- * gen :
- * - none
- * return: table with the html code (string)
- */
-function ViewDetailStock($p_cn,$p_f_id,$p_year) {
-
-
}
/* function getFicheNameCode ($p_cn,$p_sg_code)
************************************************************
@@ -136,7 +140,7 @@ $sql="select f_id,av_text
where
ad_id=".ATTR_DEF_NAME."
and sg_code='$p_sg_code'
- and sg_code != null ";
+ ";
// Execute
$Res=ExecSql($p_cn,$sql);
if ( ( $M=pg_NumRows($Res)) == 0 ) return null;
@@ -152,4 +156,141 @@ $sql="select f_id,av_text
return $result;
-}
\ No newline at end of file
+}
+/* function ViewDetailStock($cn,$sg_code,$year)
+ **************************************************
+ * Purpose :
+ *
+ * parm :
+ * - cn database connection
+ * - sg_code
+ * - year
+ * gen :
+ * -
+ * return: HTML code
+ */
+function ViewDetailStock($p_cn,$p_sg_code,$p_year) {
+$sql="select sg_code,
+ j_montant,
+ j_date,
+ sg_quantity,
+ sg_type,
+ jr_comment,
+ jr_internal,
+ jr_id,
+ case when sg_date is not null then sg_date else j_date end as stock_date
+ from stock_goods
+ left outer join jrnx using (j_id)
+ left outer join jrn on jr_grpt_id=j_grpt
+ where
+ sg_code='$p_sg_code' and (
+ to_char(sg_date,'YYYY') = '$p_year'
+ or to_char(j_date,'YYYY') = '$p_year'
+ )
+ order by stock_date
+ " ;
+// $r.=sprintf('',
+// $row['jr_id'],$l_sessid,$row['jr_internal']);
+ // name
+
+
+ $r="";
+ $a_name=getFicheNameCode($p_cn,$p_sg_code);
+ $name="";
+ if ( $a_name != null ) {
+ foreach ($a_name as $key=>$element) {
+ $name.=$element['av_text'].",";
+ }
+ }// if ( $a_name
+ // Add java script for detail
+ $r.=JS_VIEW_JRN_DETAIL;
+
+ $r.='
'.$p_sg_code." Noms : ".$name.'
';
+
+ $Res=ExecSql($p_cn,$sql);
+ if ( ($M=pg_NumRows($Res)) == 0 ) return "no rows";
+ $r.="