金蝶K3 Wise—BOM批量多级展开
生活随笔
收集整理的這篇文章主要介紹了
金蝶K3 Wise—BOM批量多级展开
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
新手——剛開始研究BOM,不對之處還望各位博友不吝賜教
1、創(chuàng)建BOM父項表?? ?——FID,FItemID
create table HWbom ( FId int identity(1,1), FItemID int )2、創(chuàng)建BOM子項表?? ?——FID,FOrgID,FParentID,FLevel,FSN,FItemID,FQty,FBOMInterID,FEntryID
create table HWbomchild (FID int identity(1,1),FOrgID int,FParentID int,FLevel int,FSN nvarchar(200),FItemID int,FQty decimal(28,19),FBOMInterID int,FEntryID int )3、將父項BOM對應(yīng)的物料內(nèi)碼插入父項表(可帶條件)
--t_ICItem——物料表 --t_item——基礎(chǔ)資料主表 --icbom——BOM表 --ICBOMGROUP——BOM組別表--物料表FErpClsID 物料屬性(1-外購,2-自制,3-委外加工,5-虛擬件) --基礎(chǔ)資料主表 fdeleted 是否刪除(0,未刪除) --基礎(chǔ)資料主表 FItemClassID 對應(yīng)編碼: --1-客戶 --2-部門 --3-職員 --4-商品 --5-倉位 --7-單位 --8-供應(yīng)商 --基礎(chǔ)資料主表 FDetail 是否明細(xì)(1,明細(xì))-- delete from HWbom INSERT INTO HWbom ( FItemID ) SELECT t.Fitemid FROMt_ICItem t --71615INNER JOIN t_item t5 ON t5.FItemID = t.FitemidLEFT JOIN icbom t6 ON t6.fitemid= t.FitemidLEFT JOIN ICBOMGROUP t7 ON t7.finterid= t6.fparentid WHEREt.FErpClsID IN ( 1, 2, 3, 5 ) --2代表自制件,3代表委外件,5代表虛擬件AND t5.FItemClassID= 4 AND t5.FDeleted= 0 AND t5.FDetail= 1 --類型是4(商品),未刪除,明細(xì)是1 --and t5.fnumber in('物料編碼1','物料編碼2') --可根據(jù)需要限定BOM范圍ORDER BYt.fnumber4、根據(jù)父項表數(shù)據(jù),將數(shù)據(jù)插入子項表,為后續(xù)卷算做準(zhǔn)備
INSERT INTO HWbomchild ( FOrgID, FParentID, FSN, FItemID, FQty, FBOMInterID, FEntryID, FLevel ) SELECTFId,- 1 AS FParentID,'001',u1.FItemID,1 AS Fqty,t1.FInterID AS FBOMInterID,- 1 AS FEntryID,0 FROMHWbom u1LEFT JOIN ICBOM t1 ON u1.FItemID= t1.FItemID AND t1.FUseStatus= 10725、BOM卷算
DECLARE@LEVEL INT SET @LEVEL = 1WHILEEXISTS ( SELECT 1 FROM HWbomchild WHERE FLevel = @LEVEL - 1 AND FItemID IN ( SELECT Fitemid FROM icbom WHERE FUseStatus = 1072 ) ) AND @LEVEL < 20 BEGININSERT INTO HWbomchild ( FOrgID, FParentID, FSN, FItemID, FQty, FBOMInterID, FEntryID, FLevel ) SELECTu1.FOrgID,u1.FID,u1.FSN+ '.' + RIGHT ( '000' + CONVERT ( nvarchar ( 50 ), t2.Fentryid ), 3 ),t2.Fitemid,u1.FQty* ( t2.FQty/ t1.FQty ) / ( 1-t2.FScrap/ 100 ),t2.FInterID,t2.FEntryID,@LEVEL FROMHWbomchild u1INNER JOIN icbom t1 ON u1.FItemID= t1.FItemIDINNER JOIN ICBOMChild t2 ON t2.FInterID= t1.FInterID WHEREu1.FLevel=@LEVEL - 1 AND t1.FUseStatus= 1072 SET @LEVEL =@LEVEL + 1 END6、最終BOM展開數(shù)據(jù)檢索
SELECTt2.FModel 專機號,t4.FBOMNumber BOM編號,t2.FNumber 產(chǎn)品代碼,t2.FName 產(chǎn)品名稱,t1.FSN 序號,t3.FNumber 材料代碼,t3.FName 材料名稱,t3.FModel 材料規(guī)格,t1.FQty 產(chǎn)品用量,yy.fname 材料屬性,t5.FQty 單位用量,t5.FScrap 損耗率,t6.FName AS 是否跳層,t5.FNote 備注,t5.FPositionNo 位置號 FROMHWbom u1INNER JOIN HWbomchild t1 ON u1.FId= t1.FOrgIDINNER JOIN t_icitem t2 ON t2.FItemID= u1.FItemIDINNER JOIN t_ICItem t3 ON t3.FItemID= t1.FItemIDLEFT JOIN ICBOM t4 ON t4.FInterID= t1.FBOMInterIDLEFT JOIN ICBOMChild t5 ON t5.FInterID= t1.FBOMInterID AND t5.FEntryID= t1.FEntryIDLEFT JOIN t_SubMessage t6 ON t6.FInterID= t4.FBOMSkipINNER JOIN t_SubMessage yy ON yy.FInterID= t3.FErpClsID where t2.FModel='EYY33/04/S.515' AND T4.FUseStatus = 1072 and t4.FBomType <> 3 --FBomType;0-普通,1-配置類,2-生產(chǎn)規(guī)劃類,3-客戶BOM,4-特征類 -- and t4.fitemid=t2.fitemid -- and t4.FBOMNumber = 'BOM019979'order by u1.FId,t1.FSN7、最后清空父項表和子項表數(shù)據(jù)
TRUNCATE TABLE HWbom --清空附表數(shù)據(jù) TRUNCATE TABLE HWbomchild --清空子表數(shù)據(jù)8、如果不再使用,可以將這兩個表刪除
DROP TABLE HWbom --刪除父表 DROP TABLE HWbomchild --刪除子表9、依據(jù)BOM號或規(guī)格型號查詢某bom所有層級物料價格——注意這只能查詢出BOM字表單層級的
在以上1-8以需求選取基礎(chǔ)上創(chuàng)建一個定時任務(wù)每天實時同步BOM,其中的參數(shù)如下,注釋的為依據(jù)BOM查詢,第一條為規(guī)格型號查詢
AND t2.FModel='ATD60L/19.300.E01'
-- and t4.fitemid=t2.fitemid
-- and t4.FBOMNumber = 'BOM019979'
10、若要實現(xiàn)多級展開需要捋順BOM的層級邏輯關(guān)系
BOM主表與子表之間可能只是存儲了一層的關(guān)聯(lián)關(guān)系;通過BOM主子表關(guān)聯(lián)出來這一層后,這一層中所包含的物料很可能是個組件對應(yīng)的是另一個BOM需要對它進(jìn)行再次的展開
通過關(guān)聯(lián)關(guān)系將子表中對應(yīng)的物料id查詢出,可再通過關(guān)聯(lián)關(guān)系查詢出對應(yīng)物料的用料信息,價格信息
因為每個物料對應(yīng)的BOM很可能是不一致的所以多級展開無法使用BOM進(jìn)行查詢,此處我使用的是規(guī)格型號,可自己再往上加條件
with bb as( select distinct cc.FItemID from HWbomchild cc inner join t_ICItem t3 on t3.FItemID=cc.FItemID where cc.FBOMInterID in( selectdistinct t1.FBOMInterIDfrom HWbom u1 inner join HWbomchild t1 on u1.FId=t1.FOrgID inner join t_icitem t2 on t2.FItemID=u1.FItemID inner join t_ICItem t3 on t3.FItemID=t1.FItemID left join ICBOM t4 on t4.FInterID=t1.FBOMInterID left join ICBOMChild t5 on t5.FInterID=t1.FBOMInterID and t5.FEntryID=t1.FEntryID --添加與BOM分組表關(guān)聯(lián) left join t_SubMessage t6 on t6.FInterID=t4.FBOMSkip inner join t_SubMessage yy on yy.FInterID=t3.FErpClsID --left join pp on pp.FNumber=t3.FNumber where T4.FUseStatus = 1072 and t4.FBomType <> 3 --FBomType;0-普通,1-配置類,2-生產(chǎn)規(guī)劃類,3-客戶BOM,4-特征類 AND t2.FModel='ADW77K') ) select aa.FItemID,aa.FModel,aa.FName,aa.FNumber,aa.FDeleted,aa.FErpClsID,FUnitID,FUseState,aa.FFullName from bb left join t_ICItem aa on aa.FItemID = bb.FItemID left join ( select zz.* from( SELECT v1.FNumber AS FSupplyNumber,t1.FModel,v1.FName, u1.FPrice, t1.FNumber AS FItemNumber, u1.FLastModifiedDate, t1.FName AS FItemName, row_number ( ) OVER ( partition BY t1.FNumber,v1.FNumber ORDER BY u1.FLastModifiedDate DESC ) Suquence FROM t_SupplyEntry u1 INNER JOIN t_Supplier v1 ON u1.FSupID=v1.FItemIDINNER JOIN t_Supply u2 ON u1.FSupID = u2.FSupID AND u1.FItemID=u2.FItemID AND u1.FPType=u2.FPTypeINNER JOIN t_ICItem t1 ON u2.FItemID = t1.FItemIDINNER JOIN t_MeasureUnit t2 ON u1.FUnitID = t2.FItemIDINNER JOIN t_Currency t3 ON u1.FCyID = t3.FCurrencyIDINNER JOIN t_Currency u3 ON u3.FCurrencyID = u2.FCurrencyIDLEFT JOIN ICSupOperation t7 on u1.FEntryID=t7.FIDLEFT JOIN t_item t5 ON t1.FParentID=t5.FItemIDLEFT JOIN t_User U ON u1.FLastModifiedBy = U.FUserIDLEFT JOIN t_SubMessage t8 ON t7.FOpID=t8.FInterIDLEFT JOIN t_User uu ON uu.FUserID <> 0 AND u1.FCheckerID = uu.FUserIDWHERE v1.FStatus<>1074 and u1.FPType = '1')zzwhere zz.Suquence=1 )pp on aa.FNumber=pp.FItemNumber?
總結(jié)
以上是生活随笔為你收集整理的金蝶K3 Wise—BOM批量多级展开的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: uploadify php demo,p
- 下一篇: htc816t Android go,移