[changeStock]
select fnc_update_basv0610(':hin_cd', ':loc_no', ':chg_stock', ':chg_loc_no', ':login_id')

[load_grdList]
select
  m.hin_cd
, m.hin_nm
, m.hin_rnm
, m.tanka
, m.stanka
, st.loc_no
, st.now_stock
, st.now_ztanka
, round(st.now_stock * st.now_ztanka, 2) as goukei_kingaku
, h1.han_name as hin_sts_nm
, h2.han_name as cat_nm
, h3.han_name as loc_nm
from m_hin m
left join (
	select
	  sm.hin_cd
	, sm.tanka as now_ztanka
	, COALESCE(sh.loc_no,'') as loc_no
	, sum(COALESCE(sm.suryo * (case when(mh.iri_su > 1)then(mh.iri_su)else(1)end),0) - COALESCE(sm.syuko_su,0)) as now_stock
	from t_sir sh
	inner join t_sir_m sm on (sm.den_no = sh.den_no)
	left join m_hin mh on (mh.hin_cd = sm.hin_cd)
	where sh.hacyu_flg = 0
	and (COALESCE(sm.suryo * (case when(mh.iri_su > 1)then(mh.iri_su)else(1)end),0) - COALESCE(sm.syuko_su,0)) > 0
	group by 
	  sm.hin_cd
	, sm.tanka
	, COALESCE(sh.loc_no,'')
) st on (st.hin_cd = m.hin_cd)
left join m_hanyo h1 on (h1.mst_kbn = '04' and h1.han_cd = m.hin_sts)
left join m_hanyo h2 on (h2.mst_kbn = '05' and h2.han_cd = m.cat_cd)
left join m_hanyo h3 on (h3.mst_kbn = '17' and h3.han_cd = st.loc_no)
WHERE 1 = 1
AND ((m.jan_cd LIKE '%:jan_cd') or (':jan_cd' = ''))
AND ((m.hin_cd LIKE '%:hin_cd') or (':hin_cd' = ''))
AND ((m.hin_nm LIKE '%:hin_nm%') or (':hin_nm' = ''))
AND ((m.brand_cd = ':brand_cd') or (':brand_cd' = ''))
AND ((h2.han_cd is not null and h2.koumoku1 = ':dcat_cd') or (':dcat_cd' = ''))
AND ((m.cat_cd = ':cat_cd') or (':cat_cd' = ''))
AND ((m.price_kbn = ':price_kbn') or (':price_kbn' = ''))
AND ((m.hin_sts = ':hin_sts') or (':hin_sts' = ''))
AND ((':st_cond' != '1') or (st.now_stock > 0))
and m.del_flg = 0
order by brand_cd, hin_cd



