金蝶K3實現自動核算(物料單價)

2021-09-04 13:32:00 字數 2625 閱讀 7458

原金蝶k3的存貨核算都是手動核算,比較麻煩!hoho!現編寫sql語句搞定自動核算!(想盡辦法偷懶,hoho!)

if exists (select * from sysobjects where name = 'icstockbill_jade01') drop trigger icstockbill_jade01go

create trigger icstockbill_jade01 on icstockbill

for insert,updateas

declare @frob int,@finterid int,@ftrantype int,@fstatus int

select  @frob = frob,@finterid = finterid,@ftrantype = ftrantype,@fstatus = fstatus from inserted

--更新藍字,未審核狀態的 '銷售出庫單','領料單','委外出庫單','其他出庫單'的單價和金額

--更新步驟:物料的採購單價,以前月份的期末單價,以前月份的發出單價

if @frob = 1 and @fstatus = 0 and (@ftrantype = 21 or @ftrantype = 24 or @ftrantype = 28 or @ftrantype = 29)

begin       

--更新採購單價

update a set fprice = isnull(b.forderprice,0),famount = isnull(b.forderprice,0) * fqty,fauxprice = isnull(b.forderprice,0)

from icstockbillentry a ,t_icitem b where a.fitemid = b.fitemid and a.finterid = @finterid

if @ftrantype = 24

--更新以前月的平均單價

update x set fprice = y.fprice,famount = y.fprice * fqty,fauxprice = y.fprice

from icstockbillentry x,

(select fstockid,fitemid,fyear * 100 + fperiod as fperiods,

convert(decimal(18,2),case when fendqty = 0 then case when fsend <> 0 then fcredit/fsend end else fendbal / fendqty end) as fprice

from icinvbal

where fsend <> 0 or fendqty <> 0) y,

(select fstockid,fitemid,max(fyear * 100 + fperiod) as fperiods from icinvbal

where fsend <> 0 or fendqty <> 0 

group by fstockid,fitemid) z

where y.fstockid = z.fstockid and y.fitemid = z.fitemid and y.fperiods = z.fperiods

and x.fscstockid = y.fstockid and x.fitemid = y.fitemid

else

--更新以前月的平均單價

update x set fprice = y.fprice,famount = y.fprice * fqty,fauxprice = y.fprice

from icstockbillentry x,

(select fstockid,fitemid,fyear * 100 + fperiod as fperiods,

convert(decimal(18,2),case when fendqty = 0 then case when fsend <> 0 then fcredit/fsend end else fendbal / fendqty end) as fprice

from icinvbal

where fsend <> 0 or fendqty <> 0) y,

(select fstockid,fitemid,max(fyear * 100 + fperiod) as fperiods from icinvbal

where fsend <> 0 or fendqty <> 0 

group by fstockid,fitemid) z

where y.fstockid = z.fstockid and y.fitemid = z.fitemid and y.fperiods = z.fperiods

and x.fdcstockid = y.fstockid and x.fitemid = y.fitemid

end /*

alter table icstockbill disable trigger icstockbill_jade01

alter table icstockbill enable trigger icstockbill_jade01

*/****************************************====

金蝶k3實現自動核算(**商管理單價)

金蝶k3單據編碼規則 金蝶k3物料編碼規則

金蝶 k3物料編碼規則 金蝶物料編碼規則包括 一 類 有 變 數 短 長 跳。一 求唯一 通常情況下,只要物料的物理或化學性質有變化,只要物料必須要在倉庫 中儲存,就必須為其指定乙個編碼,即通常所說的一物一碼。比如某零件 要經過沖壓成型 鑽孔 噴漆三道工序才能完成。如果該物料的三道工序 都在同一車間...

金蝶K3批量禁用物料的語句

批量禁用物料 update t set t.fdeleted 1 from t icitemcore t 將物料標示為禁用 inner join portal dbo ttgi28e t111 on t111.f3j00xc t.fnumber 關聯物料編碼清單 update t set t.fde...

金蝶K3批量禁用物料的語句

批量禁用物料 update t set t.fdeleted 1 from t icitemcore t 將物料標示為禁用 inner join portal dbo ttgi28e t111 on t111.f3j00xc t.fnumber 關聯物料編碼清單 update t set t.fde...