[getSeikyuYmd]
select fnc_get_seikyu_ymd(':taisyo_ym', :shime_dd) as seikyu_ymd

[load_grdList]
select distinct t.seikyu_ymd, fnc_get_shime_dd(t.seikyu_ymd) as shime_dd
from t_urikake t
left join m_tokui mt on (mt.tok_cd = t.tok_cd)
where 1 = 1
and ((':eig_cd' = '') or (mt.eig_cd = ':eig_cd'))
order by seikyu_ymd desc

[load_grdList2]
select
	  t.tok_cd
	, t.seikyu_ymd
	, t.zen_seikyu_ymd
	, t.zen_seikyu_zan
	, t.nyukin_gaku
	, t.kurikoshi_gaku
	, t.zeinuki_gaku
	, t.zei_gaku
	, t.zeikomi_gaku
	, t.seikyu_zan
	, t.den_cnt
	, t.nyukin_yotei_ymd
	, m1.tok_nm
	, (case when(t.print_time is not null)then(to_char(t.print_time,'yyyymmdd'))else(null)end) as print_ymd
	, 1 as checkbox
	, m1.tori_cond
from t_urikake t
left join m_tokui m1 on (m1.tok_cd = t.tok_cd)
where 1 = 1
and t.seikyu_ymd = ':seikyu_ymd'
and ((':chk_zero' = '1') or (t.seikyu_zan != 0))
and ((':tok_cd' = '') or (t.tok_cd = ':tok_cd'))
and ((':eig_cd' = '') or (m1.eig_cd = ':eig_cd'))
and ((':tok_cd_fr' = '') or (t.tok_cd >= ':tok_cd_fr'))
and ((':tok_cd_to' = '') or (t.tok_cd <= ':tok_cd_to'))

union all
select
	  m1.tok_cd
	, null --seikyu_ymd
	, m1.seikyu_ymd --zen_seikyu_ymd
	, t2.seikyu_zan --zen_seikyu_zan
	, null --nyukin_gaku
	, null --kurikoshi_gaku
	, null --zeinuki_gaku
	, null --zei_gaku
	, null --zeikomi_gaku
	, null --seikyu_zan
	, null --den_cnt
	, t2.nyukin_yotei_ymd
	, m1.tok_nm
	, null --print_ymd
	, 1 as checkbox
	, m1.tori_cond
from m_tokui m1
left join t_urikake t1 on (t1.tok_cd = m1.tok_cd and t1.seikyu_ymd = ':seikyu_ymd')
left join t_urikake t2 on (t2.tok_cd = m1.tok_cd and t2.seikyu_ymd = m1.seikyu_ymd)
where 1 = 1
--and ((':chk_zero' = '1') or (1 = 0))
and t1.seikyu_ymd is null
and m1.tori_kbn = '1'
and m1.shime_dd = fnc_get_shime_dd(':seikyu_ymd')
--#17989 2021.02.16 MOD STT
and ((COALESCE(m1.sei_cd,'') = '') or (m1.sei_cd = m1.tok_cd))
--#17989 2021.02.16 MOD END
and ((':tok_cd' = '') or (m1.tok_cd = ':tok_cd'))
and ((':eig_cd' = '') or (m1.eig_cd = ':eig_cd'))
and ((':tok_cd_fr' = '') or (m1.tok_cd >= ':tok_cd_fr'))
and ((':tok_cd_to' = '') or (m1.tok_cd <= ':tok_cd_to'))

union all
select
	  m1.tok_cd
	, null --seikyu_ymd
	, m1.seikyu_ymd --zen_seikyu_ymd
	, t2.seikyu_zan --zen_seikyu_zan
	, null --nyukin_gaku
	, null --kurikoshi_gaku
	, null --zeinuki_gaku
	, null --zei_gaku
	, null --zeikomi_gaku
	, null --seikyu_zan
	, null --den_cnt
	, t2.nyukin_yotei_ymd
	, m1.tok_nm
	, null --print_ymd
	, 1 as checkbox
	, m1.tori_cond
from m_tokui m1
left join t_urikake t1 on (t1.tok_cd = m1.tok_cd and t1.seikyu_ymd = ':seikyu_ymd')
left join t_urikake t2 on (t2.tok_cd = m1.tok_cd and t2.seikyu_ymd = m1.seikyu_ymd)
where 1 = 1
--and ((':chk_zero' = '1') or (1 = 0))
and t1.seikyu_ymd is null
and m1.tori_kbn = '1'
and m1.shime_dd2 = fnc_get_shime_dd(':seikyu_ymd')
--#17989 2021.02.16 MOD STT
and ((COALESCE(m1.sei_cd,'') = '') or (m1.sei_cd = m1.tok_cd))
--#17989 2021.02.16 MOD END
and ((':tok_cd' = '') or (m1.tok_cd = ':tok_cd'))
and ((':eig_cd' = '') or (m1.eig_cd = ':eig_cd'))
and ((':tok_cd_fr' = '') or (m1.tok_cd >= ':tok_cd_fr'))
and ((':tok_cd_to' = '') or (m1.tok_cd <= ':tok_cd_to'))

union all
select
	  m1.tok_cd
	, null --seikyu_ymd
	, m1.seikyu_ymd --zen_seikyu_ymd
	, t2.seikyu_zan --zen_seikyu_zan
	, null --nyukin_gaku
	, null --kurikoshi_gaku
	, null --zeinuki_gaku
	, null --zei_gaku
	, null --zeikomi_gaku
	, null --seikyu_zan
	, null --den_cnt
	, t2.nyukin_yotei_ymd
	, m1.tok_nm
	, null --print_ymd
	, 1 as checkbox
	, m1.tori_cond
from m_tokui m1
left join t_urikake t1 on (t1.tok_cd = m1.tok_cd and t1.seikyu_ymd = ':seikyu_ymd')
left join t_urikake t2 on (t2.tok_cd = m1.tok_cd and t2.seikyu_ymd = m1.seikyu_ymd)
where 1 = 1
--and ((':chk_zero' = '1') or (1 = 0))
and t1.seikyu_ymd is null
and m1.tori_kbn = '1'
and m1.shime_dd3 = fnc_get_shime_dd(':seikyu_ymd')
--#17989 2021.02.16 MOD STT
and ((COALESCE(m1.sei_cd,'') = '') or (m1.sei_cd = m1.tok_cd))
--#17989 2021.02.16 MOD END
and ((':tok_cd' = '') or (m1.tok_cd = ':tok_cd'))
and ((':eig_cd' = '') or (m1.eig_cd = ':eig_cd'))
and ((':tok_cd_fr' = '') or (m1.tok_cd >= ':tok_cd_fr'))
and ((':tok_cd_to' = '') or (m1.tok_cd <= ':tok_cd_to'))

order by tok_cd

[doUpdate]
select fnc_update_basv0700(:s_id, ':taisyo_ym', :shime_dd, ':login_id')

[cancelSeikyu]
select fnc_cancel_urikake(':tok_cd', ':seikyu_ymd', ':login_id')

[deleteSeikyuWork]
DELETE FROM w_basv0710
WHERE 1=1 
AND s_id = :s_id

[insertSeikyuWork]
INSERT INTO w_basv0710(
	 s_id
	,tok_cd
	,zen_seikyu_ymd
	,seikyu_ymd
	,seikyu_no
	,del_flg
	,cre_id
	,cre_time
	,upd_id
	,upd_time
)
SELECT
	 :s_id
	,w.tok_cd
	,(select max(t.seikyu_ymd) from t_urikake t where t.tok_cd = w.tok_cd and t.seikyu_ymd < w.seikyu_ymd) --zen_seikyu_ymd
	,w.seikyu_ymd
	,null --seikyu_no
	,0
	,':login_id'
	,now()
	,':login_id'
	,now()
FROM (
SELECT
	 cast(':tok_cd' as varchar) as tok_cd
	,fnc_get_seikyu_ymd(':taisyo_ym', :shime_dd) as seikyu_ymd
) w


[delete_wk]
delete from w_basr0030
where 1=1
and s_id = :s_id

[insert_wk]
insert into w_basr0030(s_id, seikyu_ymd, tok_cd, del_flg, cre_id, cre_time, upd_id, upd_time)
values(:s_id, ':seikyu_ymd', ':tok_cd', 0, ':login_id', now(), ':login_id', now())

[updatePrint]
update t_urikake set print_time = now()
where (tok_cd, seikyu_ymd) in (select tok_cd, seikyu_ymd from w_basr0030 where s_id = :s_id)




