日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

金蝶K3 SQL报表系列-BOM成本明细表

發(fā)布時(shí)間:2024/8/1 数据库 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 金蝶K3 SQL报表系列-BOM成本明细表 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1、創(chuàng)建供應(yīng)商維護(hù)價(jià)格視圖z_view_SupplyRatePrice,代碼如下:

?

  • create view [dbo].[z_view_SupplyRatePrice]

  • as

  • select

  • u1.*,

  • t1.FValueAddRate,

  • t2.FCoefficient,

  • t3.FExchangeRate

  • from t_supplyentry u1

  • inner join t_supplier t1 on u1.fsupid=t1.fitemid

  • inner join t_MeasureUnit t2 on t2.FItemID=u1.Funitid

  • inner join t_currency t3 on t3.Fcurrencyid=u1.FCyID

  • 2、創(chuàng)建實(shí)際入庫(kù)價(jià)格視圖z_view_OrderPrice,代碼如下:

    ?

    ?

  • create view

  • [dbo].[z_view_OrderPrice]

  • as

  • select

  • t1.finterid,

  • t1.fdate,

  • case when Forderinterid>0 then 1 else 0 end as Forderinterid,

  • t2.Fitemid,

  • case t1.ftrantype when 1 then t2.Fprice when 5 then FProcessprice end as Fprice

  • from

  • ICStockBill t1

  • inner join ICStockBillEntry t2 on t1.finterid=t2.finterid

  • inner join t_MeasureUnit t3 on t3.Fitemid=t2.Funitid

  • where t1.ftrantype in (1,5) and t1.FROB=1

  • 3、創(chuàng)建存儲(chǔ)過(guò)程zp_z_ProduceCostNow,代碼如下:

    ?

  • create procedure [dbo].[zp_z_ProduceCostNow]

  • @starFnumber nvarchar(50),

  • @endFNumber nvarchar(50)

  • as

  • set nocount on

  • /*

  • declare @Fitemid int

  • set @Fitemid=(select top 1 Fitemid from t_icitem where Fnumber=@Fnumber)

  • */

  • ?
  • ?
  • create table #z_ProductCost

  • (

  • Finterid int not null IDENTITY (1, 1) primary key,

  • FItemid int,

  • FSupplyAmount decimal(18,6) default 0,

  • FStockAmount decimal(18,6) default 0,

  • FError int default 0

  • )

  • ?
  • create table #z_ProductCostEntry

  • (

  • id int not null identity(1,1) primary key,

  • Finterid int not null,

  • FEntry nvarchar(50) not null,

  • Fitemid int,

  • Fqty decimal(18,6),

  • Flevel int,

  • FerpClsID int,

  • FMaterType int,

  • FError int default 0,

  • FSupplyPrice decimal(18,6) default 0,

  • FSupplyAmount decimal(18,6) default 0,

  • FSupplyPriceType int,

  • FStockPrice decimal(18,6) default 0,

  • FStockAmount decimal(18,6) default 0,

  • FMinStockPrice decimal(18,6) default 0,

  • FStockPriceType int

  • )

  • ?
  • ?
  • ?
  • insert into #z_ProductCost

  • (FItemid)

  • select fitemid

  • from t_icitem where fnumber>=@starFnumber and fnumber<=@endFNumber and FerpClsid in (2,3)

  • ?
  • ?
  • ?
  • create table #Product(

  • FParentID int,

  • sn nvarchar(50),

  • Fitemid int,

  • FQty decimal(18,6),

  • FErpClsID int

  • )

  • ?
  • create table #ProductEntry(

  • FParentID int,

  • sn nvarchar(50),

  • fitemid int,

  • fqty decimal(18,6),

  • FMaterType int,

  • FErpClsID int,

  • FError int default 0

  • )

  • ?
  • ?
  • update #z_ProductCost

  • set FError=1

  • where not exists (select finterid from icbom where #z_ProductCost.Fitemid=icbom.fitemid and icbom.FUsestatus=1072)

  • ?
  • ?
  • insert into #Product

  • (FParentID,sn,Fitemid,Fqty,FerpClsID)

  • select

  • FInterid,'001',Fitemid,1,2

  • from #z_ProductCost

  • ?
  • declare @Level int

  • set @Level=1

  • ?
  • while @level<20 and exists(select * from #Product)

  • ?
  • begin

  • ?
  • insert into #ProductEntry

  • (FParentID,

  • sn,

  • Fitemid,

  • Fqty,

  • FMaterType,

  • FerpClsID)

  • select

  • u1.FParentID,

  • u1.sn+'.'+right('000'+cast(t2.fentryid as nvarchar),3),

  • t2.fitemid,

  • u1.fqty*(t2.fqty/t1.fqty)*(1+FScrap/100),

  • t2.FMaterielType,

  • t3.FerpClsID

  • from #Product u1

  • inner join icbom t1 on t1.fitemid=u1.fitemid and t1.FUsestatus=1072

  • inner join icbomchild t2 on t1.finterid=t2.finterid

  • inner join t_icitem t3 on t2.fitemid=t3.fitemid

  • ?
  • ?
  • update

  • #ProductEntry

  • set FError=1

  • where not exists(select * from icbom u1 where u1.fitemid=#ProductEntry.fitemid and u1.FUsestatus=1072)

  • and FerpClsid in (2,3) and FMaterType=371

  • ?
  • ?
  • insert into #z_ProductCostEntry

  • (Finterid,

  • FEntry,

  • Fitemid,

  • Fqty,

  • FMaterType,

  • Flevel,

  • FerpClsID,

  • FError)

  • select

  • FParentID,sn,fitemid,fqty,FMaterType,@level,ferpclsid,Ferror

  • from #ProductEntry

  • ?
  • ?
  • delete #Product

  • ?
  • insert into #Product

  • (FParentID,sn,Fitemid,Fqty,FerpClsID)

  • select

  • FParentID,sn,Fitemid,Fqty,FerpClsID

  • from #ProductEntry where FerpClsid in (2,3,5) and Ferror=0 and FMaterType=371

  • ?
  • delete #ProductEntry

  • ?
  • set @level=@level+1

  • end

  • ?
  • drop table #Product

  • drop table #ProductEntry

  • ?
  • update

  • #z_ProductCostEntry

  • set FError=0

  • from #z_ProductCostEntry,#z_ProductCostEntry t2 ,#z_ProductCost t3

  • where

  • #z_ProductCostEntry.fmatertype=371 and t2.fmatertype=372

  • and #z_ProductCostEntry.finterid=t2.finterid

  • and #z_ProductCostEntry.fitemid=t2.fitemid and #z_ProductCostEntry.fqty=t2.fqty

  • ?
  • ?
  • update

  • #z_ProductCost

  • set FError=1

  • where exists(select id from #z_ProductCostEntry t1 where #z_ProductCost.finterid=t1.finterid and t1.Ferror=1 and FmaterType=371)

  • ?
  • ?
  • ?
  • update #z_ProductCostEntry

  • set FSupplyPrice=

  • (select top 1 fprice*FExchangeRate/(1+FValueAddRate/100)/FCoefficient from z_view_SupplyRatePrice t9 where t9.fitemid=t2.fitemid and fdisabledate>getdate() and fquotetime<getdate() order by Fquotetime desc),

  • FSupplyPriceType=1

  • from #z_ProductCost t1,#z_ProductCostEntry t2

  • where t1.finterid=t2.finterid and t2.FSupplyPrice=0 and FMaterType=371

  • and exists(select top 1 fprice from z_view_SupplyRatePrice t10 where t10.fitemid=t2.fitemid and fdisabledate>getdate() and fquotetime<getdate())

  • ?
  • update #z_ProductCostEntry

  • set FSupplyPrice=

  • (select top 1 Fprice from z_view_OrderPrice t9 where t9.fitemid=t2.fitemid order by Fdate desc),

  • FSupplyPriceType=2

  • from #z_ProductCost t1,#z_ProductCostEntry t2

  • where t1.finterid=t2.finterid and t2.FSupplyprice=0 and FMaterType=371

  • and exists(select top 1 Fprice from z_view_OrderPrice t10 where t10.fitemid=t2.fitemid)

  • ?
  • ?
  • update #z_ProductCostEntry

  • set FStockPrice=

  • (select top 1 Fprice from z_view_OrderPrice t9 where t9.fitemid=t2.fitemid order by Forderinterid desc ,Fdate desc),

  • FStockPriceType=2

  • from #z_ProductCost t1,#z_ProductCostEntry t2

  • where t1.finterid=t2.finterid and t2.FStockPrice=0 and FMaterType=371

  • and exists(select top 1 Fprice from z_view_OrderPrice t10 where t10.fitemid=t2.fitemid)

  • ?
  • ?
  • update #z_ProductCostEntry

  • set FStockPrice=

  • (select top 1 fprice*FExchangeRate/(1+FValueAddRate/100)/FCoefficient from z_view_SupplyRatePrice t9 where t9.fitemid=t2.fitemid and fdisabledate>getdate() and fquotetime<getdate() order by Fquotetime desc),

  • FStockPriceType=1

  • from #z_ProductCost t1,#z_ProductCostEntry t2

  • where t1.finterid=t2.finterid and t2.FStockPrice=0 and FMaterType=371

  • and exists(select top 1 fprice from z_view_SupplyRatePrice t10 where t10.fitemid=t2.fitemid and fdisabledate>getdate() and fquotetime<getdate())

  • ?
  • ?
  • ?
  • ?
  • update #z_ProductCostEntry

  • set FSupplyAmount=fqty*FSupplyPrice,

  • FStockAmount=Fqty*FStockPrice

  • from #z_ProductCost t1,#z_ProductCostEntry t2

  • where t1.finterid=t2.finterid

  • ?
  • ?
  • update #z_ProductCost

  • set FSupplyAmount=(select top 1 FSupplyAmount from (

  • select

  • finterid,

  • sum(FSupplyAmount) as FSupplyAmount,

  • sum(FStockAmount) as FStockAmount,

  • min(FSupplyPrice) as FMinSupplyPrice,

  • min (FStockPrice) as FminStockPrice

  • from #z_productCostEntry

  • where FMaterType=371 --and FerpClsid in (1,3)

  • group by finterid

  • ?
  • ) t1 where t1.Finterid=#z_ProductCost.Finterid),

  • FStockAmount=(select top 1 FStockAmount from (

  • ?
  • select

  • finterid,

  • sum(FSupplyAmount) as FSupplyAmount,

  • sum(FStockAmount) as FStockAmount,

  • min(FSupplyPrice) as FMinSupplyPrice,

  • min (FStockPrice) as FminStockPrice

  • from #z_productCostEntry

  • where FMaterType=371 --and FerpClsid in (1,3)

  • group by finterid

  • ?
  • ) t1 where t1.Finterid=#z_ProductCost.Finterid)

  • ?
  • ?
  • ?
  • update t1

  • set t1.FError=t1.FError+2

  • from #z_ProductCost t1 ,#z_productCostEntry t2

  • where t1.finterid=t2.finterid and t2.FMinStockPrice=0

  • ?
  • ?
  • ?
  • ?
  • select

  • t3.fnumber as 產(chǎn)品代碼,

  • t3.fname as 產(chǎn)品名稱(chēng),

  • t3.fmodel as 產(chǎn)品規(guī)格,

  • u1.fentry 行號(hào),

  • t1.fnumber 材料代碼,

  • t1.Fname 材料名稱(chēng),

  • t1.Fmodel 材料規(guī)格,

  • u1.fqty 用量,

  • t4.Fname as 材料類(lèi)型,

  • case u1.fmatertype when 371 then '正常' when 372 then '聯(lián)產(chǎn)品' when 376 then '返回件' end as 領(lǐng)料類(lèi)型,

  • case u1.fError when 0 then '正常' when 1 then'沒(méi)有BOM' end as 錯(cuò)誤狀態(tài),

  • u1.FSupplyPrice 供應(yīng)商維護(hù)單價(jià),

  • u1.FSupplyAmount 供應(yīng)商維護(hù)金額,

  • case u1.FSupplyPriceType when 1 then '供應(yīng)商維護(hù)單價(jià)' when 2 then '最新入庫(kù)價(jià)' when 3 then '計(jì)劃單價(jià)' when 4 then '其它' else '無(wú)單價(jià)' end as 供應(yīng)商維護(hù)價(jià)格來(lái)源,

  • u1.FStockPrice 最新入庫(kù)單價(jià),

  • u1.FStockAmount 最新入庫(kù)價(jià)金額,

  • case u1.FstockPriceType when 1 then '供應(yīng)商維護(hù)單價(jià)' when 2 then '最新入庫(kù)價(jià)' when 3 then '計(jì)劃單價(jià)' when 4 then '其它' else '無(wú)單價(jià)' end as 入庫(kù)價(jià)價(jià)格來(lái)源

  • into #result

  • from #z_ProductCostEntry u1

  • inner join t_icitem t1 on t1.fitemid=u1.fitemid

  • inner join #z_ProductCost t2 on t2.finterid=u1.finterid

  • inner join t_icitem t3 on t2.fitemid=t3.fitemid

  • inner join t_submessage t4 on t4.Finterid=u1.Ferpclsid

  • ?
  • insert into #result

  • select

  • t1.Fnumber,

  • t1.Fname,

  • t1.FModel,

  • '合計(jì):',

  • t1.Fnumber,

  • '',

  • '',

  • 0,

  • '',

  • '',

  • '',

  • 0,

  • u1.fsupplyamount,

  • '',

  • 0,

  • u1.fstockamount,

  • ''

  • from #z_ProductCost u1

  • inner join t_icitem t1 on u1.fitemid=t1.fitemid

  • ?
  • select * from #result order by 產(chǎn)品代碼,行號(hào)

  • ?
  • drop table #z_productCost

  • drop table #z_productCostEntry


  • 4、K3查詢(xún)分析工具調(diào)用存儲(chǔ)過(guò)程,代碼如下:

    ?

    ?

    exec zp_z_ProduceCostNow '*ItemNo*','#ItemNo#'

    總結(jié)

    以上是生活随笔為你收集整理的金蝶K3 SQL报表系列-BOM成本明细表的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。