fun-oracle

 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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值