From 79ecf702c2b5c2675bc242c5ddbdf6e9d29d7b48 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Thu, 28 Jun 2012 22:54:49 +0000 Subject: [PATCH] =?UTF-8?q?Correction=20stock=20:=20calcul=20r=C3=A9sum?= =?UTF-8?q?=C3=A9=20table=20+=20liste?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/class_stock.php | 91 +++++++++++++++--------- include/template/stock_histo.php | 4 ++ include/template/stock_summary_list.php | 12 ++-- include/template/stock_summary_table.php | 4 +- 4 files changed, 71 insertions(+), 40 deletions(-) diff --git a/include/class_stock.php b/include/class_stock.php index 32dda988d..12ecae825 100644 --- a/include/class_stock.php +++ b/include/class_stock.php @@ -192,7 +192,8 @@ class Stock extends Stock_Sql { $clause.=$and . " to_date('" . sql_string($p_array['wdate_end']) . "','DD.MM.YYYY')>=coalesce(sg_date,jr_date) "; } - if (isset($p_array['wamount_start']) && $p_array['wamount_start'] != '' && isNumber($p_array['wamount_start']) == 1) + if (isset($p_array['wamount_start']) && $p_array['wamount_start'] != '' && isNumber($p_array['wamount_start']) == 1 + && $p_array['wamount_start'] != 0 ) { $clause.=$and . " j_montant >= " . sql_string($p_array['wamount_start']); } @@ -214,7 +215,7 @@ class Stock extends Stock_Sql } if (isset($p_array['wcode_stock']) && $p_array['wcode_stock'] != "") { - $clause.=$and . " upper(sg_code) = upper('" . sql_string($p_array['wcode_stock']) . "')"; + $clause.=$and . " upper(sg_code) = upper('" . sql_string(trim($p_array['wcode_stock'])) . "')"; } if (isset($p_array['wrepo']) && $p_array['wrepo'] != -1) { @@ -224,6 +225,7 @@ class Stock extends Stock_Sql { $clause.=$and . " sg.sg_type = '" . sql_string($p_array['wdirection']) . "'"; } + return $sql . $clause; } @@ -264,39 +266,7 @@ class Stock extends Stock_Sql // 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 <= to_date($2,'DD.MM.YYYY')) - or sg_tech_date <= to_date($2,'DD.MM.YYYY')) - ) - 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 <= to_date($2,'DD.MM.YYYY')) - or sg_tech_date <= to_date($2,'DD.MM.YYYY')) - ) - 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 profile_sec_repository where p_id=$1) - - "; $end_date = $cn->get_value("select to_char(max(p_end),'DD.MM.YYYY') from parm_periode"); if (isset($p_array['state_exercice'])) { @@ -305,8 +275,61 @@ class Stock extends Stock_Sql $end_date = $p_array['state_exercice']; } } + // From ACH : IN + $sql_repo_detail = " + insert into tmp_stockgood_detail(s_id,sg_code,s_qin,r_id,f_id) + select $tmp_id,trim(sg_code), coalesce(sum(sg_quantity),0) as qin,r_id,f_id + 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 <= to_date($2,'DD.MM.YYYY')) + and r_id in (select r_id from profile_sec_repository where p_id=$1) + group by r_id,trim(sg_code),f_id + "; + + // From VEN : out + $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), $end_date)); + $sql_repo_detail = " + insert into tmp_stockgood_detail(s_id,sg_code,s_qout,r_id,f_id) + select $tmp_id,trim(sg_code) , coalesce(sum(sg_quantity),0) as qout,r_id,f_id + from stock_goods as sg + where + sg_type='c' + and sg.j_id is not null + and sg.j_id in (select j_id from jrnx where j_date <= to_date($2,'DD.MM.YYYY')) + and sg.r_id in (select r_id from profile_sec_repository where p_id=$1) + group by r_id,trim(sg_code),f_id + "; $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), $end_date)); + // From INV IN + $sql_repo_detail = " + insert into tmp_stockgood_detail(s_id,sg_code,s_qin,r_id,f_id) + select $tmp_id,trim(sg_code) , coalesce(sum(sg_quantity),0) as qin,r_id,f_id + from stock_goods as sg + where + sg_type='d' + and j_id is null + and sg_tech_date <= to_date($2,'DD.MM.YYYY') + and sg.r_id in (select r_id from profile_sec_repository where p_id=$1) + group by r_id,trim(sg_code),f_id + "; + + // From INV: OUT + $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), $end_date)); + $sql_repo_detail = " + insert into tmp_stockgood_detail(s_id,sg_code,s_qout,r_id,f_id) + select $tmp_id,trim(sg_code), coalesce(sum(sg_quantity),0) as qout,r_id,f_id + from stock_goods + where + sg_type='c' + and j_id is null + and r_id in (select r_id from profile_sec_repository where p_id=$1) + and sg_tech_date <= to_date($2,'DD.MM.YYYY') + group by r_id,trim(sg_code),f_id + "; + $cn->exec_sql($sql_repo_detail, array($g_user->get_profile(), $end_date)); return $tmp_id; } diff --git a/include/template/stock_histo.php b/include/template/stock_histo.php index a36785b3d..bc8a6bae4 100644 --- a/include/template/stock_histo.php +++ b/include/template/stock_histo.php @@ -59,10 +59,14 @@ + + + + diff --git a/include/template/stock_summary_list.php b/include/template/stock_summary_list.php index 0bbfd2e7f..e4e111dbe 100644 --- a/include/template/stock_summary_list.php +++ b/include/template/stock_summary_list.php @@ -64,12 +64,14 @@ $a_repo=$cn->get_array("select distinct t.r_id,r_name,r_adress,r_city,r_country, from vw_fiche_attr where f_id in ( - select distinct f_id from fiche_detail + select distinct f_id + from tmp_stockgood_detail where - ad_id=19 and - ad_value=$1) + r_id=$1 + and s_id=$2 + and sg_code=$3) order by vw_name,quick_code - ",array($a_stock[$s]['sg_code'])); + ",array($a_repo[$r]['r_id'],$tmp_id,$a_stock[$s]['sg_code'])); ?> @@ -82,7 +84,7 @@ $a_repo=$cn->get_array("select distinct t.r_id,r_name,r_adress,r_city,r_country, echo $sep.HtmlInput::card_detail($a_card[$c]['quick_code'], $a_card[$c]['vw_name'], ' class="line" '); $sep=" ,"; endfor; - if ( count($a_card)== 0 ) echo ' Erreur Code non utilisé '; + if ( count($a_card)== 0 ) echo 'Changement manuel'; ?> diff --git a/include/template/stock_summary_table.php b/include/template/stock_summary_table.php index 9085cc2d3..449a62896 100644 --- a/include/template/stock_summary_table.php +++ b/include/template/stock_summary_table.php @@ -54,7 +54,9 @@ $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 and s_id=$3" + $array = $cn->get_array("select coalesce(sum(s_qin)) as s_qin,coalesce(sum(s_qout)) as s_qout + from tmp_stockgood_detail + where r_id=$1 and sg_code=$2 and s_id=$3" , array($a_repository[$e]['r_id'], $a_code[$x]['sg_code'],$tmp_id)); ?>