create or replace function FUNSSBB00104(
p_payday out char, ---精算支払日
p_payrefday out char, ---支払基準日
p_sitetype in char, ---支払サイト区分
p_clicd in char, ---取引先コード
p_lastadjday in char ---最終精算日
) return number is
---Copyright: Copyright (c) 2007
---Company: FounderInter
---興行精算支払日and 支払基準日取得
v_cotype char(2); ---法人区分
v_count number;
begin
select CO_TYP into v_cotype ---法人区分
from CO_JURI_M ---法人管轄M
where JURI_CD= ---管轄コード
(select JURI_CD
from CLIENT_M ---取引先M
where CLI_CD=p_clicd); ---取引先コード
--- 15日 月末締/月末 15日払
if p_sitetype='01' then
if to_number(to_char(EXTRACT(day from to_date(p_lastadjday,'YYYY-MM-DD')))) <= 15 then
p_payrefday := to_char((LAST_DAY(p_lastadjday)),'YYYYMMDD');
else
p_payrefday := to_char((add_months((to_date(p_lastadjday,'YYYY-MM-DD')),1)),'YYYYMM') || '15';
end if;
end if;
----0日締/翌月0日払
if p_sitetype='02' then
if to_number(to_char(EXTRACT(day from to_date(p_lastadjday,'YYYY-MM-DD')))) <= 10 then
p_payrefday := to_char(to_date(p_lastadjday),'yyyymm') || '20';
end if;
if to_number(to_char(EXTRACT(day from to_date(p_lastadjday,'YYYY-MM-DD')))) >=11 and to_number(to_char(EXTRACT(day from to_date(p_lastadjday,'YYYY-MM-DD')))) <21 then
p_payrefday := to_char((LAST_DAY(p_lastadjday)),'YYYYMMDD');
end if;
if to_number(to_char(EXTRACT(day from to_date(p_lastadjday,'YYYY-MM-DD')))) >=21 then
p_payrefday := to_char((add_months((to_date(p_lastadjday,'YYYY-MM-DD')),1)),'YYYYMM') || '10';
end if;
end if;
---月末締/翌月末払
if p_sitetype='03' then
p_payrefday := to_char(last_day(add_months((to_date(p_lastadjday,'YYYY-MM-DD')),1) ),'YYYYMMDD');
end if;
---月末締/翌々月10日払
if p_sitetype='04' then
p_payrefday := to_char((add_months((to_date(p_lastadjday,'YYYY-MM-DD')),2)),'YYYYMM') || '10';
end if;
---月末締/翌々月末払
if p_sitetype='05' then
p_payrefday := to_char(last_day(add_months((to_date(p_lastadjday,'YYYY-MM-DD')),2) ),'YYYYMMDD');
end if;
---月末締/翌月10日払
if p_sitetype='06' then
p_payrefday := to_char((add_months((to_date(p_lastadjday,'YYYY-MM-DD')),1)),'YYYYMM') || '10';
end if;
select count(*) into v_count---興行精算支払日
from PAY_DA_M ---支払日M
where
CO_TYP=v_cotype ---法人区分
and PAY_REF_DA=p_payrefday---支払基準日
and DELETE_FLG='0'; ---削除フラグ
if v_count >0 then
select NVL(EVADJ_PAY_DA,'') into p_payday---興行精算支払日
from PAY_DA_M ---支払日M
where
CO_TYP=v_cotype ---法人区分
and PAY_REF_DA=p_payrefday; ---支払基準日
else
p_payday :=p_payrefday;
end if;
return 0;
exception
when others then
return 1;
end FUNSSBB00104;