[SelectRecords] select w1.tok_cd , w1.row_no , trunc(w1.row_no / 20) as row_page , (trunc(w1.row_no / 20) + 1)||'ページ' as row_B , w1.tok_nm , w1.shime_dd , w1.kbn_no , w1.den_dt , w1.from_to_ymd , w1.den_no , w1.hin_cd , w1.hin_nm , w1.suryo , w1.tanka , w1.kingaku , w1.zei_gaku , w1.zeikomi_gaku , w1.nyukin_gaku , w1.urikake_gaku , w1.biko1 , w1.biko2 , w1.zei_calc_kbn from ( select w.tok_cd , row_number()over(order by w.tok_cd, w.syori_ymd, (case(w.motocyo_kind)when(5)then(4)when(3)then(2)else(w.motocyo_kind)end), w.motocyo_key1, w.motocyo_key2, w.motocyo_kind) as row_no , mt.tok_nm , coalesce('締日:' || mt.shime_dd || '日','未設定') as shime_dd , w.motocyo_kind as kbn_no , case to_char(to_date(w.syori_ymd, 'YYYYMMDD'), 'yyyy/mm/dd') when '0001/01/01' then '' else to_char((to_date(w.syori_ymd, 'YYYYMMDD')), 'yyyy/mm/dd') end as den_dt , case to_char((to_date('&16', 'YYYYMMDD')), 'yyyy/mm/dd') when '0001/01/01' then '未入力' else to_char((to_date('&16', 'YYYYMMDD')), 'yyyy/mm/dd') end || '〜' || case to_char((to_date('&17', 'YYYYMMDD')), 'yyyy/mm/dd') when '0001/01/01' then '未入力' else to_char((to_date('&17', 'YYYYMMDD')), 'yyyy/mm/dd') end as from_to_ymd , w.den_no as den_no , w.hin_cd as hin_cd , w.hin_nm as hin_nm , w.suryo as suryo , w.tanka as tanka , w.zeinuki_gaku as kingaku , w.zei_gaku as zei_gaku , w.zeikomi_gaku as zeikomi_gaku , w.nyukin_gaku as nyukin_gaku , w.seikyu_zan as urikake_gaku , w.biko1 as biko1 , w.biko2 as biko2 , coalesce(mt.zei_calc_kbn,'0') as zei_calc_kbn from w_uri_motocyo w left join m_tokui mt on (mt.tok_cd = w.tok_cd) where 1 = 1 and w.s_id = &32 ) w1 where 1 = 1 --order by w.tok_cd, w.syori_ymd, w.den_no, w.kbn_no, w.sort order by tok_cd, row_no [_SelectRecords] select w.tok_cd , row_number()over(order by w.tok_cd,w.syori_ymd,w.den_no,w.kbn_no) as row_no , trunc((row_number()over(order by w.tok_cd,w.syori_ymd,w.den_no,w.kbn_no)-1)/20) as row_page , (trunc((row_number()over(order by w.tok_cd,w.syori_ymd,w.den_no,w.kbn_no))/20)+1)||'ページ' as row_B , mt.tok_nm , coalesce('締日:' || mt.shime_dd || '日','未設定') as shime_dd , w.kbn_no as kbn_no , w.kbn as kbn , w.sort as sort , case to_char(to_date(w.syori_ymd, 'YYYYMMDD'), 'yyyy/mm/dd') when '0001/01/01' then '' else to_char((to_date(w.syori_ymd, 'YYYYMMDD')), 'yyyy/mm/dd') end as den_dt , case to_char((to_date('&16', 'YYYYMMDD')), 'yyyy/mm/dd') when '0001/01/01' then '未入力' else to_char((to_date('&16', 'YYYYMMDD')), 'yyyy/mm/dd') end || '〜' || case to_char((to_date('&17', 'YYYYMMDD')), 'yyyy/mm/dd') when '0001/01/01' then '未入力' else to_char((to_date('&17', 'YYYYMMDD')), 'yyyy/mm/dd') end as from_to_ymd , w.den_no as den_no , w.cd as hin_cd , w.kbn_nm as hin_nm , w.suryo as suryo , w.tanka as tanka , w.kingaku as kingaku , w.zei_gaku as zei_gaku , w.zeikomi_gaku as zeikomi_gaku , w.nyukin_gaku as nyukin_gaku , w.urikake_gaku as urikake_gaku , w.biko1 as biko1 , w.biko2 as biko2 , coalesce(mt.zei_calc_kbn,'0') as zei_calc_kbn from (select tuk.tok_cd , '0' as kbn_no , '繰越' as kbn , null as sort , tuk.seikyu_ymd as syori_ymd , tuk.seikyu_no as den_no , '' as cd , '【繰越金額】' as kbn_nm , null::numeric as suryo , null::numeric as tanka , null::numeric as kingaku , null::numeric as zei_gaku , null::numeric as zeikomi_gaku , null::numeric as nyukin_gaku , coalesce(tuk.seikyu_zan,0) as urikake_gaku , null as biko1 , null as biko2 from t_urikake tuk left join ( select tu.tok_cd , sum(tu.zeinuki_gaku) as zeinuki_gaku , sum(tu.zeikomi_gaku) as zeikomi_gaku from t_uri tu left join t_urikake tuk on (tu.tok_cd = tuk.tok_cd and tuk.del_flg = '0' and (tuk.tok_cd >= '&20' or ('&20' = '')) and (tuk.tok_cd <= '&21' or ('&21' = '')) --and ((tuk.seikyu_ymd < '&16') or ('&16' = '')) and (tuk.tok_cd,tuk.seikyu_ymd) in (select uk.tok_cd,max(uk.seikyu_ymd) from t_urikake uk where del_flg = '0' and (uk.tok_cd >= '&20' or ('&20' = '')) and (uk.tok_cd <= '&21' or ('&21' = '')) and (uk.seikyu_ymd <'&16') or ('&16' = '') group by uk.tok_cd) ) where tu.del_flg = '0' and coalesce(mitsumori_flg, '0') = '0' and coalesce(jucyu_flg, '0') = '0' and coalesce(seikyu_flg, '0') = '1' and tu.syori_ymd > tuk.seikyu_ymd and tu.syori_ymd < '&16' group by tu.tok_cd order by 1,2 ) w on (w.tok_cd = tuk.tok_cd) where 1=1 and tuk.del_flg = '0' and (tuk.tok_cd >= '&20' or ('&20' = '')) and (tuk.tok_cd <= '&21' or ('&21' = '')) --and ((tuk.seikyu_ymd < '&16') or ('&16' = '')) and (tuk.tok_cd,tuk.seikyu_ymd) in (select uk.tok_cd,max(uk.seikyu_ymd) from t_urikake uk where del_flg = '0' and (uk.tok_cd >= '&20' or ('&20' = '')) and (uk.tok_cd <= '&21' or ('&21' = '')) and (uk.seikyu_ymd <'&16') or ('&16' = '') group by uk.tok_cd) and coalesce(tuk.seikyu_zan,0) != 0 union all( select tuk.tok_cd , '1' as kbn_no , '' as kbn , null as sort , to_char(to_date('&16','yyyymmdd') - CAST('1 day' AS INTERVAL),'yyyymmdd') as syori_ymd , tuk.seikyu_no as den_no , '' as cd , to_char(to_date(tuk.seikyu_ymd,'yyyymmdd') + CAST('1 day' AS INTERVAL),'yyyy年mm月dd日') || '〜' || to_char(to_date('&16','yyyymmdd') - CAST('1 day' AS INTERVAL),'yyyy年mm月dd日') as kbn_nm , null::numeric as suryo , null::numeric as tanka , coalesce(w.zeinuki_gaku,0) as kingaku , coalesce(w.zei_gaku,0) as zei_gaku , coalesce(w.zeikomi_gaku,0) as zeikomi_gaku , coalesce(w2.nyukin_gaku,0) as nyukin_gaku , case (coalesce(mt.zei_calc_kbn,'1')) when '1' then coalesce(tuk.seikyu_zan,0) + coalesce(w.zeinuki_gaku,0) - coalesce(w2.nyukin_gaku,0) else coalesce(tuk.seikyu_zan,0) + coalesce(w.zeikomi_gaku,0) - coalesce(w2.nyukin_gaku,0) end as urikake_gaku , null as biko1 , null as biko2 from t_urikake tuk left join ( select tu.tok_cd , sum(tu.zeinuki_gaku) as zeinuki_gaku , sum(tu.zeikomi_gaku) as zeikomi_gaku , sum(tu.zei_gaku) as zei_gaku from t_uri tu left join t_urikake tuk on (tu.tok_cd = tuk.tok_cd and tuk.del_flg = '0' and (tuk.tok_cd >= '&20' or ('&20' = '')) and (tuk.tok_cd <= '' or ('' = '')) --and ((tuk.seikyu_ymd < '&16') or ('&16' = '')) and (tuk.tok_cd,tuk.seikyu_ymd) in (select uk.tok_cd,max(uk.seikyu_ymd) from t_urikake uk where del_flg = '0' and (uk.tok_cd >= '&20' or ('&20' = '')) and (uk.tok_cd <= '&21' or ('&21' = '')) and (uk.seikyu_ymd <'&16') or ('&16' = '') group by uk.tok_cd) ) where tu.del_flg = '0' and coalesce(mitsumori_flg, '0') = '0' and coalesce(jucyu_flg, '0') = '0' --and coalesce(seikyu_flg, '0') = '1' and tu.syori_ymd > tuk.seikyu_ymd and tu.syori_ymd < '&16' group by tu.tok_cd order by tu.tok_cd ) w on (w.tok_cd = tuk.tok_cd) left join ( select tn.tok_cd , sum(tn.total_gaku) as nyukin_gaku from t_nyukin tn left join t_urikake tuk on (tn.tok_cd = tuk.tok_cd and tuk.del_flg = '0' and (tuk.tok_cd >= '&20' or ('&20' = '')) and (tuk.tok_cd <= '' or ('' = '')) and (tuk.tok_cd,tuk.seikyu_ymd) in (select uk.tok_cd,max(uk.seikyu_ymd) from t_urikake uk where del_flg = '0' and (uk.tok_cd >= '&20' or ('&20' = '')) and (uk.tok_cd <= '&21' or ('&21' = '')) and (uk.seikyu_ymd <'&16') or ('&16' = '') group by uk.tok_cd) ) where tn.del_flg = '0' and tn.nyukin_ymd > tuk.seikyu_ymd and tn.nyukin_ymd < '&16' group by tn.tok_cd order by tn.tok_cd ) w2 on (w2.tok_cd = tuk.tok_cd) left join m_tokui mt on (mt.tok_cd = tuk.tok_cd) where 1=1 and tuk.del_flg = '0' and (coalesce(w.zeinuki_gaku,0) != 0 or coalesce(w2.nyukin_gaku,0) != 0) and (tuk.tok_cd >= '&20' or ('&20' = '')) and (tuk.tok_cd <= '&21' or ('&21' = '')) --and ((tuk.seikyu_ymd < '&16') or ('&16' = '')) and (tuk.tok_cd,tuk.seikyu_ymd) in (select uk.tok_cd,max(uk.seikyu_ymd) from t_urikake uk where del_flg = '0' and (uk.tok_cd >= '&20' or ('&20' = '')) and (uk.tok_cd <= '&21' or ('&21' = '')) and (uk.seikyu_ymd <'&16') or ('&16' = '') group by uk.tok_cd) order by tok_cd,kbn_no ) union all( --標準の表示 ( select tok_cd , '2' as kbn_no , '売上' as kbn , lpad ((row_number()over(order by tum.den_no,tum.row_no)::text),3,'0') as sort --, null as syori_ymd , tu.syori_ymd --, null::numeric as den_no , tu.den_no , tum.hin_cd as cd , tum.hin_nm --#18334 2021.08.08 MOD STT -- , tum.suryo -- , tum.tanka -- , tum.kingaku as kingaku , (case when(h90a.koumoku1 = tum.hin_cd)then(null)else(tum.suryo)end) as suryo , (case when(h90a.koumoku1 = tum.hin_cd)then(null)else(tum.tanka)end) as tanka , (case when(h90a.koumoku1 = tum.hin_cd)then(null)else(tum.kingaku)end) as kingaku --#18334 2021.08.08 MOD END , null::numeric as zei_gaku , null::numeric as zeikomi_gaku , null::numeric as nyukin_gaku , null::numeric as urikake_gaku , tum.meisai_biko as biko1 , tum.meisai_biko2 as biko2 from t_uri_m tum left join t_uri tu on (tu.den_no = tum.den_no) left join m_hanyo han on (han.mst_kbn = '99' and han.han_cd = 'seisan-grp') --#18334 2021.08.08 MOD STT left join m_hanyo h90a on (h90a.mst_kbn = '90' and h90a.han_cd = 'hin-title') --#18334 2021.08.08 MOD END where 1=1 and tu.del_flg = '0' and coalesce(tu.jucyu_flg,'0') = '0' and coalesce(tu.mitsumori_flg,'0') = '0' --and coalesce(tu.seikyu_flg,'0') = '1' and (tu.tok_cd >= '&20' or ('&20' = '')) and (tu.tok_cd <= '&21' or ('&21' = '')) and (tu.syori_ymd >= '&16' or ('&16' = '')) and (tu.syori_ymd <= '&17' or ('&17' = '')) and coalesce(han.han_name,'0') = '0' order by tum.den_no ,tum.row_no ) --生産グループ切替(アドニス) union all ( select tu.tok_cd , '2' as kbn_no , '売上' as kbn , lpad ((row_number()over(order by tu.group_no,tum.row_no)::text),3,'0') as sort , tu.syori_ymd , tu.group_no as den_no , tum.hin_cd as cd , tum.hin_nm , sum(tum.suryo) as suryo , tum.tanka as tanka , sum(tum.kingaku) as kingaku , null::numeric as zei_gaku , null::numeric as zeikomi_gaku , null::numeric as nyukin_gaku , null::numeric as urikake_gaku , tum.meisai_biko as biko1 , tum.meisai_biko2 as biko2 from t_uri_m tum left join t_uri tu on (tu.den_no = tum.den_no) left join m_hanyo han on (han.mst_kbn = '99' and han.han_cd = 'seisan-grp') where 1=1 and tu.del_flg = '0' and coalesce(tu.jucyu_flg,'0') = '0' and coalesce(tu.mitsumori_flg,'0') = '0' --and coalesce(tu.seikyu_flg,'0') = '1' and (tu.tok_cd >= '&20' or ('&20' = '')) and (tu.tok_cd <= '&21' or ('&21' = '')) and (tu.syori_ymd >= '&16' or ('&16' = '')) and (tu.syori_ymd <= '&17' or ('&17' = '')) and han.han_name = '1' group by tu.group_no,tu.tok_cd,tu.syori_ymd,tum.row_no,tum.hin_cd,tum.hin_nm,tum.tanka,tum.meisai_biko,tum.meisai_biko2 order by tu.group_no ,tum.row_no ) union all select tu.tok_cd , '3' as kbn_no , '売上' as kbn , null as sort , tu.syori_ymd , tu.den_no , '' as cd , '【伝票金額】' , null::numeric as suryo , null::numeric as tanka , tu.zeinuki_gaku as kingaku , tu.zei_gaku as zei_gaku , tu.zeikomi_gaku as zeikomi_gaku , null::numeric as nyukin_gaku , tu.zei_gaku as urikake_gaku , trim(both chr(10) from substring(biko1,-1,(position(chr(10) in (replace(biko1,'','')))))) as biko1 , trim(both chr(10) from substring(biko2,-1,(position(chr(10) in (replace(biko2,'','')))))) as biko2 from t_uri tu left join m_hanyo han on (han.mst_kbn = '99' and han.han_cd = 'seisan-grp') where 1=1 and tu.del_flg = '0' and coalesce(tu.jucyu_flg,'0') = '0' and coalesce(tu.mitsumori_flg,'0') = '0' --and coalesce(tu.seikyu_flg,'0') = '1' and (tu.tok_cd >= '&20' or ('&20' = '')) and (tu.tok_cd <= '&21' or ('&21' = '')) and (tu.syori_ymd >= '&16' or ('&16' = '')) and (tu.syori_ymd <= '&17' or ('&17' = '')) and coalesce(han.han_name,'0') = '0' --生産グループ切替(アドニス) union all select tu.tok_cd , '3' as kbn_no , '売上' as kbn , null as sort , tu.syori_ymd , tu.group_no as den_no , '' as cd , '【伝票金額】' , null::numeric as suryo , null::numeric as tanka , sum(tu.zeinuki_gaku) as kingaku , sum(tu.zei_gaku) as zei_gaku , sum(tu.zeikomi_gaku) as zeikomi_gaku , null::numeric as nyukin_gaku , sum(tu.zei_gaku) as urikake_gaku --to_do , null as biko1 , null as biko2 --to_do end from t_uri tu left join m_hanyo han on (han.mst_kbn = '99' and han.han_cd = 'seisan-grp') where 1=1 and tu.del_flg = '0' and coalesce(tu.jucyu_flg,'0') = '0' and coalesce(tu.mitsumori_flg,'0') = '0' --and coalesce(tu.seikyu_flg,'0') = '1' and (tu.tok_cd >= '&20' or ('&20' = '')) and (tu.tok_cd <= '&21' or ('&21' = '')) and (tu.syori_ymd >= '&16' or ('&16' = '')) and (tu.syori_ymd <= '&17' or ('&17' = '')) and han.han_name = '1' group by tu.group_no,tu.tok_cd,tu.syori_ymd order by den_no ,kbn_no ) union all select tok_cd , '4' as kbn_no , '入金' as kbn , lpad(cast(tm.row_no as varchar),3,'0') as sort , tn.nyukin_ymd , tn.nyukin_no , tm.nyukin_kbn as cd ,'【' || coalesce(han.han_name,'') ||'】' as kbn_name , null::numeric as suryo , null::numeric as tanka , null::numeric as kingaku , null::numeric as zei_gaku , null::numeric as zeikomi_gaku , tm.nyukin_gaku as nyukin_gaku , null as urikake_gaku , tm.biko as biko1 , case(tm.nyukin_kbn) when '4' then tm.tegata_no else '' end as biko2 from t_nyukin tn left join t_nyukin_m tm on (tn.nyukin_no = tm.nyukin_no) left join m_hanyo han on (han.han_cd = tm.nyukin_kbn and mst_kbn = '13') left join m_hanyo flg1 on (flg1.mst_kbn = '99' and flg1.han_cd = 'nyukin-m') where 1=1 and tn.del_flg = '0' and flg1.han_name = '1' and (tn.tok_cd >= '&20' or ('&20' = '')) and (tn.tok_cd <= '&21' or ('&21' = '')) and (tn.nyukin_ymd >= '&16' or ('&16' = '')) and (tn.nyukin_ymd <= '&17' or ('&17' = '')) union all select tok_cd , '5' as kbn_no , '入金' as kbn , null as sort , tn.nyukin_ymd , tn.nyukin_no , '' as cd --,'【' || han.han_name ||'】' as kbn_name ,'【伝票金額】' as kbn_name , null::numeric as suryo , null::numeric as tanka , null::numeric as kingaku , null::numeric as zei_gaku , null::numeric as zeikomi_gaku , tn.total_gaku as nyukin_gaku , null as urikake_gaku , tn.biko as biko1 , case(tn.nyukin_kbn) when '4' then tn.tegata_no else '' end as biko2 from t_nyukin tn left join m_hanyo han on (han.han_cd = nyukin_kbn and mst_kbn = '19') where 1=1 and tn.del_flg = '0' and (tn.tok_cd >= '&20' or ('&20' = '')) and (tn.tok_cd <= '&21' or ('&21' = '')) and (tn.nyukin_ymd >= '&16' or ('&16' = '')) and (tn.nyukin_ymd <= '&17' or ('&17' = '')) union all select tok_cd , '6' as kbn_no , '締処理' as kbn , null as sort , tuk.seikyu_ymd , tuk.seikyu_no , '' as cd , '【締請求】' as kbn_nm , null::numeric as suryo , null::numeric as tanka , coalesce(zeinuki_gaku,0) as kingaku , coalesce(zei_gaku,0) as zei_gaku , coalesce(zeikomi_gaku,0) as zeikomi_gaku , tuk.nyukin_gaku as nyukin_gaku , seikyu_zan urikake_gaku , null as biko1 , null as biko2 --, '請求時税額:\' || (to_char(coalesce(zei_gaku,0), 'FM999,999,999')) as biko1 --, '請求時税抜金額:\' || (to_char(coalesce(zeinuki_gaku,0), 'FM999,999,999')) as biko2 from t_urikake tuk where 1=1 and tuk.del_flg = '0' and ( coalesce(tuk.zeinuki_gaku,0) != 0 or coalesce(tuk.zei_gaku,0) != 0 or coalesce(tuk.zeikomi_gaku,0) != 0 or coalesce(tuk.nyukin_gaku,0) != 0 ) and (tuk.tok_cd >= '&20' or ('&20' = '')) and (tuk.tok_cd <= '&21' or ('&21' = '')) and (tuk.seikyu_ymd >= '&16' or ('&16' = '')) and (tuk.seikyu_ymd <= '&17' or ('&17' = '')) --and coalesce(zeinuki_gaku,0) != 0 and coalesce(zei_gaku,0) != 0 and coalesce(zeikomi_gaku,0) != 0 and tuk.nyukin_gaku != 0 and seikyu_zan != 0 ) w left join m_tokui mt on (mt.tok_cd = w.tok_cd) where 1=1 and (mt.shime_dd = fnc_to_number('&31') or ('&31' = '')) order by w.tok_cd,w.syori_ymd,w.den_no,w.kbn_no,w.sort [SelectRecords_Jisya] select w.* ,(case coalesce(j_tel,'') when '' then '' else 'TEL:' || j_tel end) as j_tel_s ,(case coalesce(j_fax,'') when '' then '' else 'FAX:' || j_fax end) as j_fax_s ,(case coalesce(j_url,'') when '' then '' else 'URL:' || j_url end) as j_url_s ,(case coalesce(j_mail,'') when '' then '' else 'EMAIL:' || j_mail end) as j_mail_s from( select j3.han_name as tait--得意先元帳 ,j.mst_kbn ,j.han_cd ,j.han_name as j_nm ,j.koumoku1 as j_post_s ,j.koumoku2 || j.koumoku3 as j_address -- ,j.koumoku3 as j_address2 -- ,j.koumoku4 ,j.koumoku5 as j_tel ,j.koumoku6 as j_fax ,j.koumoku7 as j_url ,j.koumoku8 as j_mail -- ,j.koumoku9 -- ,j.koumoku10 ,j.sort_key ,j2.mst_kbn ,j2.han_cd ,j2.han_name ,j2.koumoku1 as koumoku1 ,j2.koumoku2 as koumoku2 ,j2.koumoku3 as koumoku3 ,j2.koumoku4 as koumoku4 ,j2.koumoku5 as koumoku5 ,j2.koumoku6 as koumoku6 ,j2.koumoku7 as koumoku7 ,j2.koumoku8 as koumoku8 ,j2.koumoku9 as koumoku9 ,j2.koumoku10 as koumoku10 , '毎度お引き立てくださいましてありがとうございます。' as mongon1 , '下記の通りご請求させて頂きます。' as mongon2 , '尚、締切日以降の入金は含まれておりませんのでご了承ください。' as mongon3 , '※お振込手数料はお客様にてご負担願います。' as mongon4 , '' as mongon5 , case when coalesce(ar1.han_name,'') = '1' then coalesce(ar1.han_name,'') else '0' end as midasi_kbn , coalesce('&15','') || coalesce('&16','') , case when coalesce(m2.koumoku1,'') = 'M' then coalesce(m2.koumoku1,'') else '' end as midasi_FLG from m_hanyo j left join m_hanyo m2 on (m2.mst_kbn = '90' and m2.han_cd = 'hin-title') --見出し行対応(数量・単価・金額の非表示) left join m_hanyo j2 on (j2.mst_kbn = '90' and j2.han_cd = 'jisya2') left join m_hanyo j3 on (j3.mst_kbn = '59' and j3.han_cd = '1')--得意先元帳 left join m_hanyo ar1 on (ar1.mst_kbn='99' and ar1.han_cd='uri-jknrno') where 1=1 and j.mst_kbn = '90' and j.han_cd = 'jisya' )w [InsertWork] select fnc_update_motocyo_uri_range(&1, '&2', '&3', '&4', '&5', '&6', '&7', '&8', '&9', 'BASR0210')