Stock included, can be improved

This commit is contained in:
sparkyx 2004-04-03 05:15:36 +00:00
parent 6c2615eed4
commit dc941e276c
6 changed files with 237 additions and 35 deletions

View file

@ -64,20 +64,76 @@ $left_menu=ShowMenuAdvanced();
echo '<div class="lmenu">';
echo $left_menu;
echo '</DIV>';
$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 "<script> alert('$msg');</script>";
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 '<div class="u_redcontent">' ;
echo $a;
echo 'Entrer la valeur qui doit augmenter ou diminuer le stock';
echo '<form action="stock.php" method="POST">';
echo $b;
echo '<input type="submit" name="sub_change" value="Ok">';
echo '</form>';
echo '</div>';
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 '<div class="u_redcontent">';
echo $r;
echo '<FORM action="stock.php" method="post">';
$a=ViewStock($cn,$p_year);
$a=ViewStock($cn,$year);
if ( $a != null ) {
echo '<input type="submit" name="view" value="ok">';
echo $a;
}
echo '</div>';
html_page_stop();
?>

View file

@ -1,5 +1,4 @@
<?
/*
* This file is part of PhpCompta.
*

View file

@ -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;
}
/*

View file

@ -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="<table>";
@ -98,22 +118,6 @@ group by c.sg_code";
$result.="</table>";
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;
}
}
/* 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('<input TYPE="button" onClick="modifyOperation(\'%s\',\'%s\')" value="%s">',
// $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.='<H2 class="info">'.$p_sg_code." Noms : ".$name.'</H2>';
$Res=ExecSql($p_cn,$sql);
if ( ($M=pg_NumRows($Res)) == 0 ) return "no rows";
$r.="<table>";
$r.="<TR>";
$r.="<th>Date </th>";
$r.="<th>Entrée / Sortie </th>";
$r.="<th></th>";
$r.="<th>Description</th>";
$r.="<th>Montant</th>";
$r.="<th>Quantité</th>";
$r.="<th>Prix/Cout Unitaire</th>";
$r.="</TR>";
// compute sessid
$l_sessid=(isset($_POST['PHPSESSID']))?$_POST['PHPSESSID']:$_GET['PHPSESSID'];
for ( $i=0; $i < $M;$i++) {
$l=pg_fetch_array($Res,$i);
$r.="<tR>";
// date
$r.="<TD>";
$r.=$l['j_date'];
$r.="</TD>";
//type (deb = out cred=in)
$r.="<TD>";
$r.=($l['sg_type']=='c')?'OUT':'IN';
$r.="</TD>";
// jr_internal
$r.="<TD>";
$r.="</TD>";
// comment
$r.="<TD>";
$r.=$l['jr_comment'];
$r.="</TD>";
//amount
$r.="<TD>";
$r.=$l['j_montant'];
$r.="</TD>";
//quantity
$r.="<TD>";
$r.=$l['sg_quantity'];
$r.="</TD>";
// Unit Price
$r.="<TD>";
$up=$l['j_montant']/$l['sg_quantity'];
$r.=$up;
$r.="</TD>";
$r.="</TR>";
}// for ($i
$r.="</table>";
return $r;
}
/* function ChangeStock($cn,$sg_code,$sg_date)
**************************************************
* Purpose :
*
* parm :
* -
* gen :
* -
* return:
*/
function ChangeStock($p_sg_code,$p_year){
$sg_date=date("d.m.Y");
$r='
<input type="text" name="stock_change" value="0">
<input type="hidden" name="sg_code" value="'.$p_sg_code.'">
<input type="text" name="sg_date" value="'.$sg_date.'">
<input type="hidden" name="year" value="'.$p_year.'">
<br>
';
return $r;
}

View file

@ -155,6 +155,7 @@ function InsertJrnx($p_cn,$p_type,$p_user,$p_jrn,$p_poste,$p_date,$p_amount,$p_g
$p_date,round($p_amount,2),$p_poste,$p_grpt,$p_jrn,$debit,$p_user,$p_periode);
echo_debug("InsertJrnx $sql");
$Res=ExecSql($p_cn,$sql);
if ( $Res==false) return $Res;
return GetSequence($p_cn,'s_jrn_op');
}
@ -189,6 +190,7 @@ function InsertJrn($p_cn,$p_date,$p_echeance,$p_jrn,$p_comment,$p_amount,$p_grpt
$p_jrn, round($p_amount,2),$p_comment,$p_date,$p_echeance,$p_grpt,$p_periode);
echo_debug("InsertJrn $sql");
$Res=ExecSql($p_cn,$sql);
if ( $Res == false) return false;
return GetSequence($p_cn,'s_jrn');
}
/* function ListJrn($p_cn,$p_jrn,$p_wherel)
@ -395,6 +397,7 @@ function InsertStockGoods($p_cn,$p_j_id,$p_good,$p_quant,$p_type)
'$l_code',
$p_quant, '$p_type')
");
return $Res;
}
/* function withStock($p_cn,$p_f_id)
**************************************************

View file

@ -219,7 +219,7 @@ div.u_redcontent{
top:100px;
left:150px;
width:700px;
font-size:9pt;
font-size:9px;
}
span.odd {