Start Stock_Summary

This commit is contained in:
Dany De Bontridder 2012-06-16 23:42:17 +00:00
parent adf8c9fd5d
commit 7c878ea9db
6 changed files with 261 additions and 8 deletions

Binary file not shown.

View file

@ -406,6 +406,53 @@ class Stock extends Stock_Sql
return $sql . $where . $clause;
}
function summary($p_array)
{
global $cn, $g_user;
$tmp_id=$cn->get_next_seq("public.tmp_stockgood_s_id_seq");
$cn->exec_sql("delete from tmp_stockgood where s_date < now() - interval '2 hours' ");
$cn->exec_sql("insert into tmp_stockgood(s_id) values ($1)",array($tmp_id));
// get all readable repository
$a_repository=$g_user->get_available_repository('R');
// All the stock card
$sql_repo_detail="
insert into tmp_stockgood_detail(s_id,sg_code,s_qin,s_qout,r_id)
with fiche_stock as (select distinct ad_value from fiche_detail where ad_id=19 and coalesce(ad_value,'') != '') ,
stock_in as (select coalesce(sum(sg_quantity),0) as qin,r_id,sg_code from stock_goods where sg_type='c'
and (
(j_id is not null and j_id in (select j_id from jrnx where j_date <= '2010-12-31')
or sg_tech_date <= '2010-12-31')
)
group by r_id,sg_code) ,
stock_out as (select coalesce(sum(sg_quantity),0) as qout ,r_id,sg_code from stock_goods
where sg_type='d'
and (
(j_id is not null and j_id in (select j_id from jrnx where j_date <= '2010-12-31')
or sg_tech_date <= '2010-12-31')
)
group by r_id,sg_code)
select distinct
$tmp_id,
coalesce(si.sg_code,so.sg_code),
coalesce(qin,0) as qin,
coalesce(qout,0) as qout,
sg.r_id
from
stock_goods as sg
left join stock_in as si on ( sg.r_id=si.r_id)
full join stock_out as so on (si.sg_code=so.sg_code and sg.r_id=so.r_id)
where
si.sg_code is not null or so.sg_code is not null
and sg.r_id in (select r_id from user_sec_repository where p_id=$1)
";
$cn->exec_sql($sql_repo_detail,array($g_user->get_profile()));
$a_code=$cn->get_array("select distinct sg_code from tmp_stockgood_detail where s_id=$1",array($tmp_id));
require_once 'template/stock_summary.php' ;
}
}
?>

View file

@ -788,7 +788,40 @@ class User
return $isAdmin;
}
/**
*@brief return array of available repository
*
* @param $p_access R for read W for write
* @return an array
*/
function get_available_repository($p_access='R')
{
$profile=$this->get_profile();
$r=array();
if ($p_access=='R')
{
$r=$this->db->get_array("select u.r_id,r_name
from
user_sec_repository as u
join stock_repository as s on(u.r_id=s.r_id)
where
p_id =$1
and ur_right='W'
order by 2
",array($profile));
}
if ($p_access == 'W')
{
$r=$this->db->get_array("select u.r_id,r_name
from
user_sec_repository as u
join stock_repository as s on(u.r_id=s.r_id)
where
p_id =$1 order by 2
",array($profile));
}
return $r;
}
/* !
* \brief return an array with all the users who can access $p_dossier including the global admin. The user
* must be activated
@ -1072,10 +1105,10 @@ class User
{
$profile=$this->get_profile();
$r=$this->db->get_value("select count(*)
from user_sec_repository
where
from user_sec_repository
where
r_id=$1
and p_id =$2
and p_id =$2
and ur_right='W'",array($p_repo,$profile));
if ( $r==0)
return false;
@ -1090,10 +1123,10 @@ class User
{
$profile=$this->get_profile();
$r=$this->db->get_value("select count(*)
from user_sec_repository
where
from user_sec_repository
where
r_id=$1
and p_id =$2
and p_id =$2
",array($p_repo,$profile));
if ( $r==0)
return false;

View file

@ -0,0 +1,36 @@
<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/**
* @file
* @brief show the state of the repository
*
*/
global $cn,$g_parameter,$g_user;
require_once 'class_stock.php';
$stock=new Stock();
$stock->summary($_GET);
?>

View file

@ -0,0 +1,133 @@
<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/**
* @file
* @brief show State of the stock
*
*/
?>
<div class="content">
<table class="result">
<tr>
<th>
Code Stock
</th>
<? for ($i = 0; $i < count($a_repository); $i++):?>
<th>
<?=h( $a_repository[$i]['r_name'])?>
</th>
<? endfor;?>
<th>
Total
</th>
</tr>
<?
for ($x = 0; $x < count($a_code); $x++):
$class=($x%2==0)?' class="odd" ':' class="even" ';
?>
<tr <?=$class?> >
<td>
<?= $a_code[$x]['sg_code']?>
</td>
<?
$n_in=0;$n_out=0;
for ($e = 0; $e < count($a_repository); $e++):
$array = $cn->get_array("select * from tmp_stockgood_detail where r_id=$1 and sg_code=$2", array($a_repository[$e]['r_id'], $a_code[$x]['sg_code']));
?>
<td>
<?
if (count($array)==0):
echo 0;
else:
$n_in+=$array[0]['s_qin'];
$n_out+=$array[0]['s_qout'];
?>
<table>
<tr>
<td>
IN :
</td>
<td class="num">
<?=nbm($array[0]['s_qin'])?>
</td>
</tr>
<tr>
<td>
OUT :
</td>
<td class="num">
<?=nbm($array[0]['s_qout'])?>
</td>
</tr>
<tr>
<td>
DIFF :
</td>
<td class="num">
<?=nbm((bcsub($array[0]['s_qin'],$array[0]['s_qout'])))?>
</td>
</tr>
</table>
<?
endif;
?>
</td>
<?
endfor; // loop e
?>
<td>
<table>
<tr>
<td>
IN :
</td>
<td class="num">
<?=nbm($n_in)?>
</td>
</tr>
<tr>
<td>
OUT :
</td>
<td class="num">
<?=nbm($n_out)?>
</td>
</tr>
<tr>
<td>
DIFF :
</td>
<td class="num">
<?=nbm((bcsub($n_in,$n_out)))?>
</td>
</tr>
</table>
</td>
</tr>
<?
endfor; // loop x
?>
</table>
</div>

View file

@ -320,4 +320,8 @@ select migrate_stock();
drop function migrate_stock();
update attr_def set ad_type='card', ad_extra='[sql] fd_id = 500000 ' where ad_id=19;
update attr_def set ad_type='card', ad_extra='[sql] fd_id = 500000 ' where ad_id=19;
create table tmp_stockgood (s_id bigserial primary key,s_date timestamp default now());
create table tmp_stockgood_detail(d_id bigserial primary key,s_id bigint references tmp_stockgood(s_id) on delete cascade,
sg_code text,s_qin numeric(20,4),s_qout numeric(20,4),r_id bigint);