壹佰网|ERP100 - 企业信息化知识门户

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5460|回复: 0

自己写的一段有关应付帐龄分析的SQL,请参考

[复制链接]
发表于 2006/6/7 15:14:32 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622  。

您需要 登录 才可以下载或查看,没有帐号?注册

x
select aps.org_id,pv.vendor_name vendor_name,pv.segment1 vendor_number,gcc.segment3 code_number,ffvt.Description code_desc,
ppa.name project_name,aia.invoice_num invoice_number,Sum(aps.amount_remaining) sum_ap,          --
sum(decode(ap_pre_analysis.account(aia.terms_date),'1',aps.amount_remaining,0)) half_year,    --
sum(decode(ap_pre_analysis.account(aia.terms_date),'2',aps.amount_remaining,0)) one_year,     --
sum(decode(ap_pre_analysis.account(aia.terms_date),'3',aps.amount_remaining,0)) two_year,     --
sum(decode(ap_pre_analysis.account(aia.terms_date),'4',aps.amount_remaining,0)) three_year,   --
sum(decode(ap_pre_analysis.account(aia.terms_date),'5',aps.amount_remaining,0)) three_year_up --
from ap_payment_schedules_all aps,ap_invoices_all aia,po_vendors pv,pa_projects_all ppa,
     po_vendor_sites_all ps,gl_code_combinations gcc,fnd_flex_values ffv,fnd_flex_values_tl ffvt
where aps.invoice_id = aia.invoice_id
and aia.vendor_id = pv.vendor_id(+)
and ppa.project_id(+) = aia.project_id
and (aia.payment_status_flag = 'N' or aia.payment_status_flag = 'P')
And pv.vendor_id = ps.vendor_id And ps.prepay_code_combination_id = gcc.code_combination_id
And gcc.segment3 = ffv.flex_value And ffv.flex_value_id(+) = ffvt.flex_value_id
And ffvt.Language = 'ZHS'
group by pv.vendor_name,gcc.segment3,ffvt.description,aps.org_id,pv.segment1,ppa.name,aia.invoice_num
Having Sum(aps.amount_remaining)<>0


create or replace package body ap_pre_analysis is

  -- Private type declarations
  function account(term_date date) return varchar2 is
    term_y number;
    term_m number;
    sys_y number;
    sys_m number;
    a_num number;
    f varchar2(10);
  begin
    select to_number(to_char(term_date,'yyyy')) into term_y from dual;
    select to_number(to_char(term_date,'mm')) into term_m from dual;
    select to_number(to_char(sysdate,'yyyy')) into sys_y from dual;
    select to_number(to_char(sysdate,'mm')) into sys_m from dual;
   
    if term_y = sys_y then
       if sys_m-term_m <= 6 then f := 1;
       else f := 2;
       end if;
    else
       if sys_y - term_y = 1 then
          if sys_m+(12-term_m) < 6 then f := 1;
          else
             if sys_m< term_m then f := 2;
             else f := 3;
             end if;
          end if;
       else
          if sys_y - term_y = 2 then
             if sys_m < term_m then f := 3;
             else f := 4;
             end if;
          else
             if sys_y - term_y = 3 then
                if sys_m < term_m then f := 4;
                else f:= 5;
                end if;
             else
                f := 5;
             end if;
          end if;
       end if;
    end if;
   
    return(f);
  End account;
end ap_pre_analysis;
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|手机版|壹佰网 ERP100 ( 京ICP备19053597号-2 )

Copyright © 2005-2012 北京海之大网络技术有限责任公司 服务器托管由互联互通
手机:13911575376
网站技术点击发送消息给对方83569622   广告&合作 点击发送消息给对方27675401   点击发送消息给对方634043306   咨询及人才点击发送消息给对方138011526

GMT+8, 2025/11/29 16:45 , Processed in 0.012799 second(s), 16 queries , File On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表