/****** Object:  StoredProcedure [dbo].[pro_bobang_ICItemQiTao]    Script Date: 07/29/2015 16:12:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
alter PROC [dbo].[pro_bobang_ICItemQiTao]
@FBomNumber1 varchar(50), --bom单号
@FBomNumber2 varchar(50) --bom单号
as
begin
set nocount on --1.--业务员查找某个BOM单,包含所有BOM(已使用,未使用,已审核,未审核)
with cte as (
select convert(varchar(100),'') as cen,Finterid,convert(varchar(50),'') as fpbomnumber,Fbomnumber AS FCbomnumber,fitemid,fitemid as fpitemid,0 as fpinterid,convert(decimal(18,4),1) as FBomQty,convert(varchar(500),RIGHT(''+CONVERT(varchar(10),Finterid),6)) as code from ICBOM
where (1=1)
and FBOMNumber >= @FBomNumber1
and FBOMNumber <= case when @FBomNumber2='' then (select MAX(FBOMNumber) from ICBOM) else @FBomNumber2 end
union all
select convert(varchar(100),cen+'------'),a.finterid,convert(varchar(50),c.FCbomnumber) as fpbomnumber,a.fbomnumber as fcbomnumber,a.fitemid,c.fpitemid,a.fpinterid,convert(decimal(18,4),a.FAuxQty) as FBomQty,convert(varchar(500),c.code+RIGHT(''+convert(varchar(10),a.finterid),6)) as code
from (
select t1.finterid as fpinterid,t2.FInterID,t1.FItemID,t2.FBOMNumber,t1.FAuxQty
from ICBOMChild t1 inner join ICBOM t2 on t1.FItemID=t2.FItemID
where t2.FParentID=1038
union all
select t1.finterid as fpinterid,0,t1.fitemid,'',t1.FAuxQty from ICBOMChild t1 where not exists (select * from ICBOM where FItemID=t1.FItemID)) a
inner join cte c on a.fpinterid=c.FInterID
)
select cen,finterid,fpbomnumber,fcbomnumber,fitemid,fpitemid,fpinterid,FBomQty,code into #tmp1 from cte order by code
OPTION (MAXRECURSION 0) --2.--获取成品库存(因为明细材料的需求量,还要减去现有成品库存隐形消耗的材料,才能体现真实需求量)
declare @kc decimal(18,6)
declare @fitemid int
select @kc=isnull(SUM(t1.FQty),0),@fitemid=t1.FItemID from ICInventory t1
inner join (select FItemID from ICBOM where FBOMNumber=@FBomNumber1) t2 on t1.FItemID=t2.FItemID
group by t1.FItemID; --3.--所有正在使用的BOM单(已使用,已审核),为了检索明细物料在哪些bom(成品)中使用,进而计算需求数量
with cte as (
select convert(varchar(100),'') as cen,Finterid,convert(varchar(50),FBOMNumber) as fpbomnumber,Fbomnumber AS FCbomnumber,fitemid,fitemid as fpitemid,0 as fpinterid,convert(decimal(18,4),1) as FBomQty,convert(varchar(500),RIGHT(''+CONVERT(varchar(10),Finterid),6)) as code from ICBOM
where (1=1) and FParentID=1038
union all
select convert(varchar(100),cen+'------'),a.finterid,convert(varchar(50),c.fpbomnumber),a.fbomnumber as fcbomnumber,a.fitemid,c.fpitemid,a.fpinterid,convert(decimal(18,4),a.FAuxQty) as FBomQty,convert(varchar(500),c.code+RIGHT(''+convert(varchar(10),a.finterid),6)) as code
from (
select t1.finterid as fpinterid,t2.FInterID,t1.FItemID,t2.FBOMNumber,t1.FAuxQty
from ICBOMChild t1 inner join ICBOM t2 on t1.FItemID=t2.FItemID
where FParentID=1038
union all
select t1.finterid as fpinterid,0,t1.fitemid,'',t1.FAuxQty from ICBOMChild t1 where not exists (select * from ICBOM where FItemID=t1.FItemID)) a
inner join cte c on a.fpinterid=c.FInterID
)
select fpbomnumber,fitemid,fpitemid,sum(FBomQty) as FBomQty into #tmp2
from cte group by fpbomnumber,FItemID,fpitemid
OPTION (MAXRECURSION 0) --4.--取采购价格管理物料最新日期的价格(已审核,可使用)
SELECT distinct u1.FSupID,u1.FItemID,case when u1.fcyid=1 then u1.FPrice*t3.FExchangeRate/(1+v1.FValueAddRate/100) else u1.FPrice*t3.FExchangeRate end as FPrice,
t3.FName AS FCyName,u1.FQuoteTime,u1.FDisableDate
into #tmp3 FROM t_SupplyEntry u1
INNER JOIN t_ICItem t1 ON u1.FItemID=t1.FItemID
INNER JOIN t_Supply u2 ON u1.FSupID=u2.FSupID AND u1.FItemID=u2.FItemID AND u1.FPType=u2.FPType
INNER JOIN t_Currency t3 ON t3.FCurrencyID=u1.FCyID
INNER JOIN t_Currency u3 ON u3.FCurrencyID=u2.FCurrencyID
INNER JOIN t_Supplier v1 ON u1.FSupID=v1.FItemID
inner join
(
select MAX(fquotetime) as fquotetime,FItemID from t_SupplyEntry where FCheckerID>0 group by FItemID
) bb on bb.FItemID=u1.FItemID and bb.fquotetime=u1.FQuoteTime
WHERE t1.FErpClsID not in (6,8) and u1.FCheckerID>0 and u1.FUsed=1 select w.cen+w2.FNumber as FTree,w2.FName,w2.FModel,w3.FName as FUnitName,w.FBomQty,
--需求量=产品预测量+销售订单量-已发货量-即时库存量-该BOM成品耗费材料库存(仅明细材料)
--w.FKCQty,w.FPRQty,w.FPOQty,w.FPPQty,w.FXSQty1,w.FXSQty2,w.FPPQty+w.FXSQty1-w.FXSQty2-w.FKCQty-(case when w.FItemID=@fitemid then 0 else @kc*w.FBomQty end) as XQSL,(case when w.FItemID=@fitemid then 0 else @kc*w.FBomQty end)
--需求量改为生产需求
--需求量=产品预测量+销售订单量-已发货量-该BOM成品库存及耗费材料库存
w.FKCQty,w.FPRQty,w.FPOQty,w.FStockQty,w.FPPQty,w.FXSQty1,w.FXSQty2,isnull(@kc*w.FBomQty,0) as cbkc,isnull(w.FPPQty,0)+isnull(w.FXSQty1,0)-isnull(w.FXSQty2,0)-isnull(@kc*w.FBomQty,0) as XQSL,w5.FName as FSupName
from
(
select t1.code,t1.cen,t1.FItemID,t1.FBomQty,isnull(t4.FKCQty,0) as FKCQty,isnull(t5.FPRQty1,0)-isnull(t6.FPRQty2,0) as FPRQty,t11.FStockQty,
isnull(t7.FPOQty1,0)-isnull(t7.FPOQty2,0) as FPOQty,isnull(sum(t8.FPPQty1*t3.FBomQty),0)-isnull(sum(t9.FPPQty2*t3.FBomQty),0) as FPPQty,
isnull(sum(t10.FXSQty1*t3.FBomQty),0) as FXSQty1,isnull(sum(t10.FXSQty2*t3.FBomQty),0) as FXSQty2,t2.FErpClsID
from #tmp1 t1
left join t_ICItem t2 on t1.FItemID=t2.FItemID
left join #tmp2 t3 on t1.FItemID=t3.FItemID
left join (select SUM(FQty) as FKCQty,FItemID from ICInventory group by FItemID) t4 on t1.FItemID=t4.FItemID
--采购申请单的数量
left join
(
select SUM(t2.FQty) as FPRQty1,t2.FItemID from PORequest t1
inner join PORequestEntry t2 on t1.FInterID=t2.FInterID
where t1.FStatus>0 and t1.FCancellation=0
group by t2.FItemID
) t5 on t1.FItemID=t5.FItemID
--PR下推采购订单或委外订单
left join
(
--采购申请单下推采购订单
select SUM(t2.FQty) as FPRQty2,t2.FItemID from POOrder t1
inner join POOrderEntry t2 on t1.FInterID=t2.FInterID
inner join t_ICItem t3 on t2.FItemID=t3.FItemID
where t1.FCancellation=0 and t2.FSourceTranType=70 and t3.FErpClsID<>3
group by t2.FItemID
--采购申请单下推委外订单
union all
select SUM(t2.FQty) as FPRQty2,t2.FItemID from ICSubContract t1
inner join ICSubContractEntry t2 on t1.FInterID=t2.FInterID
inner join t_ICItem t3 on t2.FItemID=t3.FItemID
where t1.FCancellation=0 and t2.FClassTypeID_SRC=-70 and t3.FErpClsID=3
group by t2.FItemID
) t6 on t1.FItemID=t6.FItemID
--PO
left join
(
--采购订单的数量、入库数量(外购件下推采购订单)
select SUM(t2.FQty) as FPOQty1,SUM(t2.FStockQty) as FPOQty2,t2.FItemID from POOrder t1
inner join POOrderEntry t2 on t1.FInterID=t2.FInterID
inner join t_ICItem t3 on t2.FItemID=t3.FItemID
where t1.FCancellation=0 and t3.FErpClsID<>3
group by t2.FItemID
--委外订单的数量、入库数量(委外加工件下推委外订单)
union all
select SUM(t2.FQty) as FPOQty1,SUM(t2.FStockQty) as FPOQty2,t2.FItemID from ICSubContract t1
inner join ICSubContractEntry t2 on t1.FInterID=t2.FInterID
inner join t_ICItem t3 on t2.FItemID=t3.FItemID
where t1.FCancellation=0 and t2.FClassTypeID_SRC=-70 and t3.FErpClsID=3
group by t2.FItemID
) t7 on t1.FItemID=t7.FItemID
--产品预测单的数量
left join
(
select sum(t2.FQty) as FPPQty1,t2.FItemID from PPOrder t1
inner join PPOrderEntry t2 on t1.FInterID=t2.FInterID
where t1.FStatus=1 and t1.FCancellation=0 and t2.FNeedDateEnd>GETDATE()
group by t2.FItemID
) t8 on t3.FPItemID=t8.FItemID
--产品预测单下推销售订单的数量
left join
(
select SUM(t2.FQty) as FPPQty2,t2.FItemID from SEOrder t1
inner join SEOrderEntry t2 on t1.FInterID=t2.FInterID
where t1.FCancellation=0 and t2.FSourceTranType=87
group by t2.FItemID
) t9 on t3.FPItemID=t9.FItemID
--销售订单的数量,销售订单下推销售出库的数量
left join
(
select SUM(t2.FQty) as FXSQty1,SUM(t2.FStockQty) as FXSQty2,t2.FItemID from SEOrder t1
inner join SEOrderEntry t2 on t1.FInterID=t2.FInterID
where t1.FCancellation=0
group by t2.FItemID
) t10 on t3.FPItemID=t10.FItemID
--采购入库数量,委外加工入库数量
left join
(
select t1.FItemID,SUM(FQty) as FStockQty from ICStockBillEntry t1 inner join ICStockBill t2 on t1.FInterID=t2.FInterID
where (t2.FTranType=1 or t2.FTranType=5) and t2.FCancellation=0
group by t1.FItemID
) t11 on t1.FItemID=t11.FItemID
group by t1.code,t1.cen,t1.FItemID,t1.FBomQty,t4.FKCQty,t5.FPRQty1,t6.FPRQty2,t7.FPOQty1,t7.FPOQty2,t11.FStockQty,t2.FErpClsID
) w
inner join t_ICItem w2 on w.FItemID=w2.FItemID
inner join t_MeasureUnit w3 on w2.FUnitID=w3.FItemID
left join #tmp3 w4 on w4.FItemID=w.FItemID
left join t_Supplier w5 on w4.FSupID=w5.FItemID
order by w.code,w2.FNumber drop table #tmp1
drop table #tmp2
set nocount off
end
--select * from ICBOM
--select * from ICBOMChild
--exec pro_bobang_ICItemQiTao 'BOM000080','BOM000080'
--exec pro_bobang_ICItemQiTao '*FBomNumber*','#FBomNumber#'

金蝶K3 WISE BOM多级展开_物料齐套表的更多相关文章

  1. 金蝶K3 WISE BOM多级展开_销售成本表

    /****** Object: StoredProcedure [dbo].[pro_bobang_SaleCost] Script Date: 07/29/2015 16:13:43 ******/ ...

  2. 金蝶K3 WISE BOM多级展开_BOM成本表

    /****** Object: StoredProcedure [dbo].[pro_bobang_BOMCost] Script Date: 07/29/2015 16:09:11 ******/ ...

  3. 金蝶K3 wise 插件二次开发与配置

    金蝶K3 wise 插件二次开发与配置 开发环境:K/3 Wise 13.0.K/3 Bos开发平台.Visual Basic 6.0 目录 一.二次开发插件编程二.代码演示三.配置插件四.测试插件五 ...

  4. 金蝶K3 WISE 快速登录

    金蝶K3 WISE 快速登录 "C:\Program Files (x86)\Kingdee\K3ERP\k3main.exe" -LoginUser|账套号|账套密码|用户账号| ...

  5. 关于金蝶k3 wise供应生门户登陆界面屏蔽业务账套多余功能模块设置方法

    关于金蝶k3 wise供应生门户登陆界面屏蔽业务账套多余功能模块设置方法 1. 找到以下路径 ...\Kingdee\K3ERP\KDHR\SITEFILE\WEBUI\ 找到“Login.aspx” ...

  6. 金蝶K3 WISE 13.1版本服务器虚拟机环境部署

    闲来无事,整个13.1版本的金蝶玩玩. 系统环境:WIN2008 R2,x64位 数据库:MSSQL 2008 R2,X64位 记录下操作步骤: 1.准备安装软件,见图: 2.安装资源包,.net3. ...

  7. 金蝶 K3 WISE 服务器必须登陆到桌面以后用户才能正常使用解决!

    我们单位K3的系统,由当地的服务商安装完以后就出现各种蛋疼的问题.做技术支持的小伙他总是会给一个小工具来解决,问他是什么原因要么说我的网络有问题,要么说我们的服务器有问题. K3所有客户端无法登陆一键 ...

  8. XP单机版安装金蝶K3的13.1版本号,金蝶K3Wise安装步骤,安装成功

    在我们安装金蝶K3时往往会出现各种报错.主要是由于我们的Windows Xp操作系统是Ghost版本号.或者是windows XP HOME或者是精简版,因此某些组件在系统里没有.导致我们安装金蝶K3 ...

  9. python办公自动化系列之金蝶K3自动登录(一)

    做办公自动化的小伙伴都知道,驱动SAP GUI我们有SAP原生提供的[脚本录制与回放]以及SAP Scripting API可参考:驱动Office Excel等,我们有微软提供的[录制宏]功能:驱动 ...

随机推荐

  1. 关于dubbo+zookeeper微服务的一些认识记录

    借鉴架构示意图: 实例介绍: 公司某项目架构 服务器A:nginx 服务器BC:tomcat1.tomcat2 服务器D:Dubbo+zookeeper 服务器EF:db1+zookeeper.db2 ...

  2. python发送smtp 邮件 图片

    #-*- coding: utf-8 -*- # python2 import os import time import random import smtplib from time import ...

  3. 10.1 ES6 的新增特性以及简单语法

    ES6 的新增特性以及简单语法  let 和 const 模板字符串 箭头函数 对象单体模式 es6面向对象 模块化  let 和 const 之前一直用 var 来声明变量,ES6 新增 let 和 ...

  4. opencv 图片旋转

    import cv2 as cv import numpy as np # 图片旋转 img = cv.imread('../images/face.jpg', flags=1) # flags=1读 ...

  5. MT【322】绝对值不等式

    已知 $a,b,c\in\mathbb R$,求证:$|a|+|b|+|c|+|a+b+c|\geqslant |a+b|+|b+c|+|c+a|$ 分析:不妨设$c=\max\{a,b,c\},\d ...

  6. 【CF1151F】Sonya and Informatics(动态规划,矩阵快速幂)

    [CF1151F]Sonya and Informatics(动态规划,矩阵快速幂) 题面 CF 题解 考虑一个暴力\(dp\).假设有\(m\)个\(0\),\(n-m\)个\(1\).设\(f[i ...

  7. webpack学习记录-认识loader(二)

    Loader 就像是一个翻译员,能把源文件经过转化后输出新的结果,并且一个文件还可以链式的经过多个翻译员翻译. loader参考文章:https://webpack.docschina.org/loa ...

  8. 洛谷 P4302 【[SCOI2003]字符串折叠】

    又来填一个以前很久很久以前挖的坑 首先如果先抛开折叠的内部情况不谈,我们可以得到这样的一个经典的区间DP的式子 $ f[l][r]=min(f[l][r],f[l][k]+f[k+1][r])(l&l ...

  9. BSGS+exBSGS POJ2417+POJ3243

    a^x=b(mod p)求x,利用分块的思想根号p的复杂度求答案,枚举同余式两端的变量,用hash的方法去找最小的答案(PS:hash看上去很像链式前向星就很有好感).然后如果p不是质数时,就利用同余 ...

  10. 洛谷P1258 小车问题(题解)

    https://www.luogu.org/problemnew/show/P1258(题目传送) 看题的第一眼就把题归为二分题,一直向着二分的方向走,却忽略了数学的推理.推理一番后(看了题解),发现 ...