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

简介: /****** Object: StoredProcedure [dbo].[pro_bobang_BOMCost] Script Date: 07/29/2015 16:09:11 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIE...
/****** Object:  StoredProcedure [dbo].[pro_bobang_BOMCost]    Script Date: 07/29/2015 16:09:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
drop proc pro_bobang_BOMCost
GO
create PROC [dbo].[pro_bobang_BOMCost]
@FBomNumber1 varchar(50),  --bom单号
@FBomNumber2 varchar(50)   --bom单号
as
begin
SET ANSI_WARNINGS OFF
set nocount on


--1.--业务员查找某个BOM单,包含所有BOM(已使用,未使用,已审核,未审核)
  with cte as (
  select convert(varchar(100),'') as cen,Finterid,FBOMNumber as fppbomnumber,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('000000'+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,c.fppbomnumber,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('000000'+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  cen,finterid,fppbomnumber,fpbomnumber,fcbomnumber,fitemid,fpitemid,fpinterid,FBomQty,code into #tmp1 from cte order by code
  OPTION (MAXRECURSION 0)

--2.--取采购价格管理物料最新日期的价格(已审核,可使用)
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 #tmp2 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

--3.--列出BOM明细成本,取采购价格的最新价格
select t1.cen+t1.code as FTree,t1.cen,t1.code,t1.fppbomnumber,t1.fpbomnumber,t1.fcbomnumber,t1.FItemID,t1.FBomQty,
t2.FSupID,t2.FPrice as FAuxPrice,t1.FBomQty*t2.FPrice as FAmount,case when FCbomnumber<>'' then t1.FBomQty*t2.FPrice end as FJGAmount 
into #tmp3 from #tmp1 t1
left join #tmp2 t2 on t1.FItemID=t2.FItemID
left join t_ICItem t3 on t1.FItemID=t3.FItemID
order by t1.code,t3.FNumber


--4.--循环计算中间件成本
---这部分部署会出错,先注释,部署成功,再解除注释更新存储过程
declare @cb decimal(18,4),@fbom varchar(50),@fppbom varchar(50)
declare auth_cur cursor for
select fppbomnumber,fcbomnumber from #tmp3 where FAuxPrice is null and fcbomnumber<>'' and cen<>''  order by cen desc
open auth_cur
fetch next from auth_cur into @fppbom,@fbom
while(@@fetch_status=0)
begin
  set @cb=0
  select @cb=isnull(SUM(FAmount),0) from #tmp3 where fpbomnumber=@fbom and fppbomnumber=@fppbom
  UPDATE #tmp3 set FAmount=isnull(FAmount,0)+@cb,FAuxPrice=isnull(FAuxPrice,0)+@cb/FBomQty where FCbomnumber=@fbom and fppbomnumber=@fppbom
  fetch next from auth_cur into @fppbom,@fbom
end
close auth_cur
deallocate auth_cur
----这部分部署会出错,先注释,部署成功,再解除注释更新存储过程


--5.--循环计算成品件成本
---这部分部署会出错,先注释,部署成功,再解除注释更新存储过程
declare @cb1 decimal(18,4),@fbom1 varchar(50),@fppbom1 varchar(50)
declare auth_cur cursor for
select fppbomnumber,fcbomnumber from #tmp3 where fcbomnumber<>'' and cen=''  order by cen desc
open auth_cur
fetch next from auth_cur into @fppbom1,@fbom1
while(@@fetch_status=0)
begin
  set @cb1=0
  select @cb1=isnull(SUM(FAmount),0) from #tmp3 where fpbomnumber=@fbom1 and fppbomnumber=@fppbom1
  UPDATE #tmp3 set FAmount=isnull(FAmount,0)+@cb1,FAuxPrice=isnull(FAmount,0)+@cb1/FBomQty where FCbomnumber=@fbom1 and fppbomnumber=@fppbom1
  fetch next from auth_cur into @fppbom1,@fbom1
end
close auth_cur
deallocate auth_cur
----这部分部署会出错,先注释,部署成功,再解除注释更新存储过程

select t1.FTree,case when t1.fpbomnumber='' then t1.FCbomnumber end as fpbomnumber,t2.FNumber,t2.FName,t2.FModel,t3.FName as FUnitName,t1.FBomQty,t1.FAuxPrice,t1.FAmount,t1.FJGAmount,t4.FName as FSupName from #tmp3 t1
inner join t_ICItem t2 on t2.FItemID=t1.FItemID
inner join t_MeasureUnit t3 on t2.FUnitID=t3.FItemID
left join t_Supplier t4 on t1.FSupID=t4.FItemID
order by t1.code


drop table #tmp1
drop table #tmp2
drop table #tmp3
set nocount off

end 

--exec pro_bobang_BOMCost 'BOM000032','BOM000032'
--exec pro_bobang_BOMCost '*FBomNumber*','#FBomNumber#'

 

网名:浩秦; 邮箱:root#landv.pw; 只要我能控制一個國家的貨幣發行,我不在乎誰制定法律。金錢一旦作響,壞話隨之戛然而止。
目录
相关文章
SAP扩充物料的销售视图
比如我们现在有一个物料,这个物料只具备基本视图,我们如何为这个物料补充销售视图呢?先看看这个物料,使用事务码MM03我们无法使用MM02去扩充视图,我们需要使用MM50为它扩充销售视图。维护执行之后,进入类似于MM01的画面,如下图看,我们可以开始扩充这个物料的销售视图了。
4153 0
|
3月前
|
存储 开发框架 前端开发
EAV模型(实体-属性-值)的设计和低代码的处理方案(2)--数据的查询处理
EAV模型(实体-属性-值)的设计和低代码的处理方案(2)--数据的查询处理
|
JavaScript 算法 Linux
硬件工程师物料清单BOM对比工具
硬件工程师物料清单BOM对比工具
290 1
硬件工程师物料清单BOM对比工具
|
资源调度 监控 供应链
ERP、APS、MES 三者之间的关系
ERP、APS、MES三者之间的关系是相互补充的。ERP系统是企业内部管理的总体解决方案,负责统一管理各种资源和流程。APS系统是ERP系统的补充,负责优化企业的生产计划和调度。MES系统则是在生产过程中对实时数据进行监督、跟踪和控制的系统。三者共同协作,帮助企业提高生产效率、提升质量、降低成本,并实现企业的数字化转型。
516 0
ERP、APS、MES 三者之间的关系
|
6月前
|
小程序 开发者
社区每周丨交易组件新增扩展组件介绍文档及开发成员管理能力优化
社区每周丨交易组件新增扩展组件介绍文档及开发成员管理能力优化
65 11
|
监控 架构师 安全
「应用组合管理」应用程序投资组合管理的权威指南
「应用组合管理」应用程序投资组合管理的权威指南
|
大数据 开发者
电商项目之层级调用原则讲解|学习笔记
快速学习电商项目之层级调用原则讲解
电商项目之层级调用原则讲解|学习笔记
SAP 物料主数据分类视图维护了批次分类特性值以后,不允许去批次主数据里覆盖了?
SAP 物料主数据分类视图维护了批次分类特性值以后,不允许去批次主数据里覆盖了?
SAP 物料主数据分类视图维护了批次分类特性值以后,不允许去批次主数据里覆盖了?
SAP MM 影响Vendor主数据维护界面的字段选择的四大因素?
SAP MM 影响Vendor主数据维护界面的字段选择的四大因素?
SAP MM 影响Vendor主数据维护界面的字段选择的四大因素?
|
JavaScript Go
金蝶K3 WISE BOM多级展开_物料齐套表
/****** 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].
1542 0