|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622 。
您需要 登录 才可以下载或查看,没有帐号?注册
x
各位朋友,在下近日紧急开发应收帐款帐龄分析7时段报表,在开发过程中遇到困难,所取出的SQL不能把发票历史的核销也反映出来。
比如发票 SF_000123(为1月15日收款)的发票金额为200
但是在1月20号核销了100,那么20好的帐龄就为100,而16号的帐龄为200。我开发的报表只能计算该发表到当前的帐龄,而不能追溯到1月16号时候的帐龄。不知道哪位朋友能解决!
在本论坛也看到了有这样的贴子,并且获得了一个PCK文件,但不知道怎么使用,如果有哪位朋友写过这个报表,麻烦发给我借鉴看一下,谢谢了,下面是我写的SQL,不能核销!QQ:312076667
select tt.ACCOUNT_NUMBER 编号,
tt.party_name 单位名称,
tt.total_money as 合计金额,
&P_DATE 日期,
sum(nvl(decode(tt.classical,1,tt.monthmoney),0)) as "一个月",
sum(nvl(decode(tt.classical,2,tt.monthmoney),0)) as "二个月",
sum(nvl(decode(tt.classical,3,tt.monthmoney),0)) as "三个月",
sum(nvl(decode(tt.classical,4,tt.monthmoney),0)) as "四个月",
sum(nvl(decode(tt.classical,5,tt.monthmoney),0)) as "五个月",
sum(nvl(decode(tt.classical,6,tt.monthmoney),0)) as "六个月",
sum(nvl(decode(tt.classical,7,tt.monthmoney),0)) as "半年以上"
from (select zz.ACCOUNT_NUMBER,
zz.party_name,
max(zz.ar_total) as total_money,
sum(zz.ACCTD_AMOUNT_DUE_REMAINING) as monthmoney,
zz.classical
from (select CUST_ACCT.ACCOUNT_NUMBER,
PARTY.party_name,
PS.ACCTD_AMOUNT_DUE_REMAINING,
sum (PS.ACCTD_AMOUNT_DUE_REMAINING) over(partition by CUST_ACCT.ACCOUNT_NUMBER) ar_total,
case when DECODE(PS.AMOUNT_DUE_REMAINING,0,TO_NUMBER(NULL),TRUNC( to_date(&P_DATE,'yyyy-mm-dd')) - PS.DUE_DATE) <= 0 then 1
when DECODE(PS.AMOUNT_DUE_REMAINING,0,TO_NUMBER(NULL),TRUNC( to_date(&P_DATE,'yyyy-mm-dd')) - PS.DUE_DATE) >0 and DECODE(PS.AMOUNT_DUE_REMAINING,0,TO_NUMBER(NULL),TRUNC( to_date(&P_DATE,'yyyy-mm-dd')) - PS.DUE_DATE) <=30 then 2
when DECODE(PS.AMOUNT_DUE_REMAINING,0,TO_NUMBER(NULL),TRUNC( to_date(&P_DATE,'yyyy-mm-dd')) - PS.DUE_DATE) >30 and DECODE(PS.AMOUNT_DUE_REMAINING,0,TO_NUMBER(NULL),TRUNC( to_date(&P_DATE,'yyyy-mm-dd')) - PS.DUE_DATE) <=60 then 3
when DECODE(PS.AMOUNT_DUE_REMAINING,0,TO_NUMBER(NULL),TRUNC( to_date(&P_DATE,'yyyy-mm-dd')) - PS.DUE_DATE) >60 and DECODE(PS.AMOUNT_DUE_REMAINING,0,TO_NUMBER(NULL),TRUNC( to_date(&P_DATE,'yyyy-mm-dd')) - PS.DUE_DATE) <=90 then 4
when DECODE(PS.AMOUNT_DUE_REMAINING,0,TO_NUMBER(NULL),TRUNC( to_date(&P_DATE,'yyyy-mm-dd')) - PS.DUE_DATE) >90 and DECODE(PS.AMOUNT_DUE_REMAINING,0,TO_NUMBER(NULL),TRUNC( to_date(&P_DATE,'yyyy-mm-dd')) - PS.DUE_DATE) <=120 then 5
when DECODE(PS.AMOUNT_DUE_REMAINING,0,TO_NUMBER(NULL),TRUNC( to_date(&P_DATE,'yyyy-mm-dd')) - PS.DUE_DATE) >120 and DECODE(PS.AMOUNT_DUE_REMAINING,0,TO_NUMBER(NULL),TRUNC( to_date(&P_DATE,'yyyy-mm-dd')) - PS.DUE_DATE) <=150 then 6
when DECODE(PS.AMOUNT_DUE_REMAINING,0,TO_NUMBER(NULL),TRUNC( to_date(&P_DATE,'yyyy-mm-dd')) - PS.DUE_DATE) >0 and DECODE(PS.AMOUNT_DUE_REMAINING,0,TO_NUMBER(NULL),TRUNC( to_date(&P_DATE,'yyyy-mm-dd')) - PS.DUE_DATE) <=30 then 7
end as classical
from ar_payment_schedules_all ps,
hz_parties party,
hz_cust_accounts cust_acct
where PS.CUSTOMER_ID = CUST_ACCT.CUST_ACCOUNT_ID(+)
and CUST_ACCT.PARTY_ID = PARTY.PARTY_ID(+)
)zz
group by zz.ACCOUNT_NUMBER,zz.party_name,zz.classical
)tt
group by tt.ACCOUNT_NUMBER,tt.party_name,tt.total_money; |
|