应付的帐龄分析SQL


select hao.name 公司名称,
       
       pha.segment1 订单编号,
       
       to_char(pla.line_num) 订单行编号,
       
       pv.vendor_name 供应商名,
       
       pvs.vendor_site_code 供应商地点,
       
       nvl(msib.segment1, 
null) 物料编码, 
       
       pla.item_description 物料名称,
       
       hao1.name 发运组织,
       
       rec.currency_code 订单币种,
       
       decode(rec.transaction_type,
              
              
'RETURN TO VENDOR',
              
              
-rec.quantity,
              
              rec.quantity) 数量,
       
       pla.unit_price 单价,
       
       decode(rrs.entered_cr, 
null-rrs.entered_dr, rrs.entered_cr) 金额,
       
       rec.currency_conversion_rate 接收汇率,
       
       decode(rrs.accounted_cr, 
null-rrs.accounted_dr, rrs.accounted_cr) 本位币金额,
       
       plla.accrue_on_receipt_flag 接收应计标志,
       
       gcc.segment3 科目,
       
       to_char(rec.transaction_date, 
'YYYY-MM-DD') 总帐日期,
       
       
'采购接收' 来源,
       
       rsh.receipt_num 接收编号,
       
       rec.currency_conversion_date 接收日期,
       
       pl2.displayed_field 接收类型,
       
       pda.recovery_rate 退税率,
       
       apca.name 税码

  
from po_headers_all pha,
       
       po_lines_all pla,
       
       po_line_locations_all plla,
       
       po_distributions_all pda,
       
       po_vendors pv,
       
       po_vendor_sites_all pvs,
       
       hr_all_organization_units hao,
       
       hr_all_organization_units hao1,
       
       gl_code_combinations gcc,
       
       rcv_transactions rec,
       
       rcv_shipment_headers rsh,
       
       ap_tax_codes_all apca,
       
       rcv_receiving_sub_ledger rrs,
       
       po_lookup_codes pl2,
       
       mtl_system_items_b msib

 
where pha.org_id = hao.organization_id
      
   
and msib.organization_id = 103
      
   
and pha.vendor_id = pv.vendor_id
      
   
and pha.vendor_site_id = pvs.vendor_site_id
      
   
and plla.ship_to_organization_id = hao1.organization_id
      
   
and pha.po_header_id = pla.po_header_id
      
   
and plla.po_line_id = pla.po_line_id
      
   
and user_entered_flag = 'Y'
      
   
and rec.po_line_id = pla.po_line_id
      
   
and rec.po_header_id = pha.po_header_id
      
   
and rec.po_line_location_id = plla.line_location_id
      
   
and pda.line_location_id = plla.line_location_id
      
   
and pda.accrual_account_id = gcc.code_combination_id
      
   
and rec.shipment_header_id = rsh.shipment_header_id
      
   
and plla.tax_code_id = apca.tax_id(+)
      
   
and pda.po_distribution_id = rrs.reference3
      
   
and rec.transaction_id = rrs.rcv_transaction_id
      
   
and gcc.code_combination_id = rrs.code_combination_id
      
   
and rrs.set_of_books_id = fnd_profile.value('GL_SET_OF_BKS_ID')
      
   
and rec.transaction_type in ('RECEIVE''RETURN TO VENDOR''CORRECT')
      
   
and pl2.lookup_code = rec.transaction_type
      
   
and pl2.lookup_type = 'RCV TRANSACTION TYPE'
      
   
and pla.item_id = msib.inventory_item_id 

union all

select hao.name 公司名称,
       
       pha.segment1 订单编号,
       
       to_char(pla.line_num) 订单行编号,
       
       pv.vendor_name 供应商名,
       
       pvs.vendor_site_code 供应商地点,
       
       nvl(msib.segment1, 
null) 物料编码,
       
       pla.item_description 物料名称,
       
       hao1.name 发运组织,
       
       decode(rt.currency_code, 
null, pha.currency_code, rt.currency_code) 订单币种,
       
       
-aida.quantity_invoiced 数量,
       
       aida.unit_price 单价,
       
       nvl(aala.entered_cr, 
0- nvl(aala.entered_dr, 0) 金额,
       
       rt.currency_conversion_rate 接收汇率,
       
       nvl(aala.accounted_cr, 
0- nvl(aala.accounted_dr, 0) 本位币金额,
       
       plla.accrue_on_receipt_flag 接收应计标志,
       
       gcc.segment3 科目,
       
       to_char(aida.accounting_date, 
'YYYY-MM-DD') 总帐日期,
       
       
'发票匹配' 来源,
       
       rsh.receipt_num 接收编号,
       
       rt.currency_conversion_date 接收日期,
       
       pl1.displayed_field 接收类型,
       
       pda.recovery_rate 退税率,
       
       apca.name 税码

  
from ap_invoices_all aia,
       
       ap_invoice_distributions_all aida,
       
       ap_ae_lines_all aala,
       
       hr_all_organization_units hao,
       
       gl_code_combinations gcc,
       
       po_vendors pv,
       
       po_vendor_sites_all pvs,
       
       po_distributions_all pda,
       
       po_line_locations_all plla,
       
       hr_all_organization_units hao1,
       
       po_lines_all pla,
       
       po_headers_all pha,
       
       rcv_shipment_headers rsh,
       
       rcv_transactions rt,
       
       ap_tax_codes_all apca,
       
       po_lookup_codes pl1,
       
       mtl_system_items_b msib 
       
 
where aia.invoice_id = aida.invoice_id
      
   
and msib.organization_id = 103 
      
   
and aida.org_id = hao.organization_id
      
   
and aala.source_table = 'AP_INVOICE_DISTRIBUTIONS'
      
   
and aida.invoice_distribution_id = aala.source_id
      
   
and aala.code_combination_id = gcc.code_combination_id
      
   
and aida.po_distribution_id = pda.po_distribution_id
      
   
and pda.line_location_id = plla.line_location_id
      
   
and plla.ship_to_organization_id = hao1.organization_id
      
   
and plla.po_line_id = pla.po_line_id
      
   
and pla.po_header_id = pha.po_header_id
      
   
and aia.vendor_id = pv.vendor_id
      
   
and aia.vendor_site_id = pvs.vendor_site_id
      
   
and aida.po_distribution_id is not null
      
   
and aala.ae_line_type_code = 'AP ACCRUAL'
      
   
and aida.rcv_transaction_id = rt.transaction_id(+)
      
   
and rt.shipment_header_id = rsh.shipment_header_id(+)
      
   
and plla.tax_code_id = apca.tax_id(+)
      
   
and (rt.transaction_type in ('RECEIVE''RETURN TO VENDOR'or
       
       rt.transaction_type 
is null)
      
   
and pl1.lookup_code(+= rt.transaction_type
      
   
and pl1.lookup_type(+= 'RCV TRANSACTION TYPE'
      
   
and pla.item_id = msib.inventory_item_id 

union all

select hao.name 公司名称,
       
       aia.invoice_num 订单编号,
       
       to_char(aida.distribution_line_number) 订单行编号,
       
       pv.vendor_name 供应商名,
       
       pvs.vendor_site_code 供应商地点,
       
       
null 物料编码,
       
       
null 物料名称,
       
       
null 发运组织,
       
       aia.invoice_currency_code 订单币种,
       
       
null 数量,
       
       
null 单价,
       
       aia.invoice_amount 
* (-1) 金额,
       
       aida.exchange_rate 接收汇率,
       
       nvl(aida.base_amount 
* (-1), aida.amount * (-1)) 本位币金额,
       
       
null 接收应计标志,
       
       gcc.segment3 科目,
       
       to_char(aida.accounting_date, 
'YYYY-MM-DD') 总帐日期,
       
       
'发票无匹配' 来源,
       
       
null 接收编号,
       
       
null 接收日期,
       
       
null 接收类型,
       
       
null 退税率,
       
       
null 税码

  
from ap_invoice_distributions_all aida,
       
       ap_invoices_all aia,
       
       hr_all_organization_units hao,
       
       gl_code_combinations gcc,
       
       po_vendors pv,
       
       po_vendor_sites_all pvs

 
where gcc.code_combination_id = aida.dist_code_combination_id
      
   
and aia.invoice_id = aida.invoice_id
      
   
and pv.vendor_id = aia.vendor_id
      
   
and aida.org_id = hao.organization_id
      
   
and pv.vendor_id = pvs.vendor_id
      
   
and aia.vendor_site_id = pvs.vendor_site_id
      
   
and gcc.segment3 like '2121020000'
      
   
and aida.po_distribution_id is null
      
   
and aida.reversal_flag is null


转载于:https://www.cnblogs.com/benio/archive/2010/12/31/1923294.html

乐播投屏是一款简单好用、功能强大的专业投屏软件,支持手机投屏电视、手机投电脑、电脑投电视等多种投屏方式。 多端兼容与跨网投屏:支持手机、平板、电脑等多种设备之间的自由组合投屏,且无需连接 WiFi,通过跨屏技术打破网络限制,扫一扫即可投屏。 广泛的应用支持:支持 10000+APP 投屏,包括综合视频、网盘与浏览器、美韩剧、斗鱼、虎牙等直播平台,还能将央视、湖南卫视等各大卫视的直播内容一键投屏。 高清流畅投屏体验:腾讯独家智能音画调校技术,支持 4K 高清画质、240Hz 超高帧率,低延迟不卡顿,能为用户提供更高清、流畅的视觉享受。 会议办公功能强大:拥有全球唯一的 “超级投屏空间”,扫码即投,无需安装。支持多人共享投屏、远程协作批注,PPT、Excel、视频等文件都能流畅展示,还具备企业级安全加密,保障会议资料不泄露。 多人互动功能:支持多人投屏,邀请好友加入投屏互动,远程也可加入。同时具备一屏多显、语音互动功能,支持多人连麦,实时语音交流。 文件支持全面:支持 PPT、PDF、Word、Excel 等办公文件,以及视频、图片等多种类型文件的投屏,还支持网盘直投,无需下载和转格式。 特色功能丰富:投屏时可同步录制投屏画面,部分版本还支持通过触控屏或电视端外接鼠标反控电脑,以及在投屏过程中用画笔实时标注等功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值