diff --git a/contrib/document_test/all_tags.odt b/contrib/document_test/all_tags.odt
new file mode 100644
index 000000000..6e92ecdc5
Binary files /dev/null and b/contrib/document_test/all_tags.odt differ
diff --git a/include/class_stock.php b/include/class_stock.php
index 364bcb3b6..259d5f150 100644
--- a/include/class_stock.php
+++ b/include/class_stock.php
@@ -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' ;
+ }
}
?>
diff --git a/include/class_user.php b/include/class_user.php
index 90c53f5e6..936c6c7b1 100644
--- a/include/class_user.php
+++ b/include/class_user.php
@@ -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;
diff --git a/include/stock_state.inc.php b/include/stock_state.inc.php
new file mode 100644
index 000000000..973bd854e
--- /dev/null
+++ b/include/stock_state.inc.php
@@ -0,0 +1,36 @@
+summary($_GET);
+
+?>
diff --git a/include/template/stock_summary.php b/include/template/stock_summary.php
new file mode 100644
index 000000000..28e31e641
--- /dev/null
+++ b/include/template/stock_summary.php
@@ -0,0 +1,133 @@
+
+
+
+
+ |
+ Code Stock
+ |
+ for ($i = 0; $i < count($a_repository); $i++):?>
+
+ =h( $a_repository[$i]['r_name'])?>
+ |
+ endfor;?>
+
+ Total
+ |
+
+
+ for ($x = 0; $x < count($a_code); $x++):
+ $class=($x%2==0)?' class="odd" ':' class="even" ';
+ ?>
+
+ >
+ |
+ = $a_code[$x]['sg_code']?>
+ |
+
+ $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']));
+ ?>
+
+
+ if (count($array)==0):
+ echo 0;
+ else:
+ $n_in+=$array[0]['s_qin'];
+ $n_out+=$array[0]['s_qout'];
+ ?>
+
+
+ |
+ IN :
+ |
+
+ =nbm($array[0]['s_qin'])?>
+ |
+
+
+ |
+ OUT :
+ |
+
+ =nbm($array[0]['s_qout'])?>
+ |
+
+
+ |
+ DIFF :
+ |
+
+ =nbm((bcsub($array[0]['s_qin'],$array[0]['s_qout'])))?>
+ |
+
+
+
+ endif;
+ ?>
+ |
+
+ endfor; // loop e
+ ?>
+
+
+
+ |
+ IN :
+ |
+
+ =nbm($n_in)?>
+ |
+
+
+ |
+ OUT :
+ |
+
+ =nbm($n_out)?>
+ |
+
+
+ |
+ DIFF :
+ |
+
+ =nbm((bcsub($n_in,$n_out)))?>
+ |
+
+
+ |
+
+
+ endfor; // loop x
+ ?>
+
+
\ No newline at end of file
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index e85346db2..a591fd92f 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -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;
\ No newline at end of file
+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);
\ No newline at end of file