易飛8無銷售報價的BOM成本參考

2021-07-23 11:36:19 字數 4616 閱讀 5634

alter procedure [dbo].[sp_bom_expand] (@itemno varchar(80))

as   

begin

--bom展階 

--@itemno:查詢品號

--返回:元件品號v1001,主件品號v1002,階碼v1004,階層次v1005,尾階標誌v1006,展開標誌v1007,組成用量v1011,底數v1012,損耗率%v1013,**%v1014

declare @item_child varchar(80), @item_expand varchar(80), @item_levelno int, @count int

declare @batch_number numeric(18,6)

declare @je numeric(18,6)

declare @je2 numeric(18,6)

declare @ph varchar(80)

declare @sx varchar(2)

declare @rq varchar(8)

create table  #view1 (v1001 varchar(80),vrq varchar(8), v1002 varchar(80), v1004 varchar(80) default '', v1005 int default 0, v1006 char(1) default '0', v1007 char(1) default '0'

, v1011 numeric(18,6) default 0, v1012 numeric(18,6) default 0, v1013 numeric(18,6) default 0,v1014 numeric(18,6) default 0) 

select @item_levelno = 1   --當前階層為1

insert into #view1 (v1001, v1002, v1004, v1005, v1011, v1012, v1013,v1014)

select md003, @itemno, md002, 1, md006 , md007*mc004, md008,0 from bommc, bommd where bommc.mc001 = bommd.md001 and mc001 = @itemno

--找一下輸入引數的品號有沒有相關的bom單身檔,看一下第一層

--select * from #view1

declare bomexpand cursor for select v1001, v1004, v1005, v1011/v1012 from #view1 where v1007 = '0' for update   

--建立第一層的游標,同時這個游標是可以更新的乙個臨時表掃瞄

open bomexpand  /* 開啟游標 */ 

fetch next from bomexpand into @item_child, @item_expand, @item_levelno, @batch_number

while @@fetch_status = 0   /* 用while迴圈控制游標活動*/ 

begin

--select @item_levelno, @item_child, @item_expand

set @sx=(select mb025 from invmb where mb001=@item_child)

if(@sx='p')

begin

set @je=(select top 1 th018 from purth where th004=@item_child order by th014 desc)

set @rq=(select top 1 th014 from purth where th004=@item_child order by th014 desc)

--set @je=(select top 1 la012 from invla where la001=@item_child order by la004 desc)

--set @rq=(select top 1 la004 from invla  where la001=@item_child order by la004 desc)

endelse if(@sx='s')

set @je=(select top 1 ta022 from mocta where ta006=@item_child order by  ta003 desc)

else if(@sx='m' or @sx='y' or @sx='c')

--set @je=0

if(@item_levelno=1)

set @je=(select top 1 lb012+lb013 

from invlb 

where lb012<>0 and lb013 <>0 and lb001=@item_child order by lb002 desc)

else 

set @je=0

update #view1 set v1007 = '1' where current of bomexpand --將第一層的展開標緻為1,更新了游標鎖定的表

set @je2=(select mb057 from invmb where mb001=@item_child)

set @je=isnull(@je,0)

if(@je=0 and @sx='p')

update #view1 set v1014=@je2,vrq='' where current of bomexpand

else

begin

update #view1 set v1014=@je,vrq=@rq where current of bomexpand

--update #view1 set vrq=@rq where current of bomexpand

endselect @count = count(*) from bommc, bommd where bommc.mc001 = bommd.md001 and mc001 = @item_child  --統計一下bommd單身檔裡有多少條

if @count = 0 

update #view1 set v1006 = '1' where current of bomexpand   --如果沒有了,則當前一階即為尾階,更新了游標鎖定的表

else

begin

insert into #view1 (v1001, v1002, v1004, v1005, v1011, v1012, v1013)

select md003, @item_child, @item_expand + '.' + md002, @item_levelno + 1, md006 * @batch_number, md007*mc004, md008 from bommc, bommd where bommc.mc001 = bommd.md001 and mc001 = @item_child

--插入當前掃瞄的行的子項進入到表裡去,同時因為游標有了for update,還會進入迴圈

--set @je=(select top 1 th018 from purth where th004=@item_child order by th014 desc)

--update #view1 set v1014=@je where v1001=@item_child

endfetch next from bomexpand into @item_child, @item_expand, @item_levelno, @batch_number /* 在迴圈體內將讀取其餘行資料 */

endclose bomexpand   /* 關閉游標 */ 

deallocate bomexpand   /* 刪除游標 */ 

--select * from #view1

----union

select space(v1005*1)+'.'+cast(v1005  as varchar)  as 階層,v1002 as 主件品號,v1001 as 元件品號,case when mb025='p' then '採購件'

when mb025='m' then '自製件'

when mb025='s' then '委外加工件'

when mb025='y' then '虛設件'

else '配置件'end as  品號屬性,vrq as '採購日期',

mb002 品名,mb003 規格,mb004 as 單位,v1011 as 組成用量,v1012 as 底數,v1013 as 損耗率,v1011/v1012*(1+v1013) as 總用量,v1014 as 單價, v1011/v1012*(1+v1013)*v1014 as 總價 from #view1 inner join  invmb on v1001=mb001

--union all

--select '',  '', '', '' , '' ,'',  '', '', '' , null ,null,null, sum(v1011/v1012*(1+v1013)*v1014)  from #view1

order by v1004

select @itemno 主件品號, sum(v1011/v1012*(1+v1013)*v1014) as 合計材料進價 from #view1

end

易飛8委外單價抓了上一次報價

erp雖然說是抓最新單價,取價順序也是核價優先,但是資料庫裡有部份單價用的是上一次的 人為原因還是系統原因折騰了半天也不知道,操作人老是說不會去點單價,而系統我再次測試卻又是最新單價,避免再次出現,我對一 商寫了幾句sql語句,將歷史 全部失效為最新 日,這樣在前台再次測試就只有乙個單價了,就算想前...

UTF 8有BOM和無BOM的區別

概念 在ucs 編碼中有乙個叫做 zero width no break space 的字元,它的編碼是feff。而fffe在ucs中是不存在的字元,所以不應該出現在實際傳輸中。ucs規範建議我們在傳輸位元組流前,先傳輸 字元 zero width no break space 如果接收者收到fef...

帶BOM的UTF 8和無BOM 的UTF 8的區別

utf 8 不需要 bom,儘管 unicode 標準允許在 utf 8 中使用 bom。所以不含 bom 的 utf 8 才是標準形式,在 utf 8 檔案中放置 bom 主要是微軟的習慣 順便提一下 把 utf 16 le 稱作 unicode 而又不詳細說明,這也是微軟的習慣 bom byte...