CREATE OR REPLACE FUNCTION gettwaccbonus
(
P_PK_PSNDOC IN CHAR,
P_YEAR IN CHAR,
P_PERIOD IN CHAR,
P_PK_ORG IN CHAR
)
RETURN NUMBER IS
P_YEARPERIOD CHAR(6) := P_YEAR || P_PERIOD;
result NUMBER(31,0);
BEGIN
result := -1;
select nvl(temp.f_309,0.00) into result
from (select pk_wa_data from wa_data_temp where rownum=1) temprow
left join (select wdtemp.f_309
from wa_data_temp wdtemp
where wdtemp.pk_psndoc = (select pk_psndoc from bd_psndoc where code = P_PK_PSNDOC and nvl(dr,0)=0 and rownum = 1)
and wdtemp.Pk_Org = (select pk_org from org_orgs where code = P_PK_ORG and nvl(dr,0)=0 and rownum = 1)
and wdtemp.cyearperiod = P_YEARPERIOD - 1
and nvl(wdtemp.dr, 0) = 0
and wdtemp.checkflag = 'Y') temp on 1=1;
RETURN result;
END;
(
P_PK_PSNDOC IN CHAR,
P_YEAR IN CHAR,
P_PERIOD IN CHAR,
P_PK_ORG IN CHAR
)
RETURN NUMBER IS
P_YEARPERIOD CHAR(6) := P_YEAR || P_PERIOD;
result NUMBER(31,0);
BEGIN
result := -1;
select nvl(temp.f_309,0.00) into result
from (select pk_wa_data from wa_data_temp where rownum=1) temprow
left join (select wdtemp.f_309
from wa_data_temp wdtemp
where wdtemp.pk_psndoc = (select pk_psndoc from bd_psndoc where code = P_PK_PSNDOC and nvl(dr,0)=0 and rownum = 1)
and wdtemp.Pk_Org = (select pk_org from org_orgs where code = P_PK_ORG and nvl(dr,0)=0 and rownum = 1)
and wdtemp.cyearperiod = P_YEARPERIOD - 1
and nvl(wdtemp.dr, 0) = 0
and wdtemp.checkflag = 'Y') temp on 1=1;
RETURN result;
END;