小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

單據(jù)上加自定義字段,在后臺(tái)用sql觸發(fā)器

 庋藏天下 2013-05-13

單據(jù)上加自定義字段,在后臺(tái)用sql觸發(fā)器

CREATE trigger icstockbill_check --實(shí)現(xiàn)對(duì)物料單據(jù)管控

on Icstockbill

for insert

as

Declare @Ftrantype int --單據(jù)類別定義/生產(chǎn)領(lǐng)料單24/調(diào)拔單41/銷售出庫單21

Select @Ftrantype=Ftrantype from inserted

--控制領(lǐng)料單的領(lǐng)料日期不能小于生產(chǎn)任務(wù)單的計(jì)劃開工日期 倒扣物料只能車間倉庫發(fā)料

if (@Ftrantype=24)

begin

declare @icmo varchar(20)

declare @message varchar(200)

declare @message0 varchar(200)

declare @message00 varchar(200)

declare @message000 varchar(200)

declare @message24000 varchar(200)

declare @finterid240 int

declare @fsumcount int

set @message='錯(cuò)誤!領(lǐng)料日期不能小于生產(chǎn)任務(wù)單計(jì)劃開工日期,請(qǐng)與生管人員聯(lián)系!錯(cuò)誤單號(hào):'

set @message00='已完工生產(chǎn)任務(wù)單不能跨月領(lǐng)料.請(qǐng)檢查領(lǐng)料日期!'

set @message24000='一張生產(chǎn)領(lǐng)料單只能領(lǐng)同一類別的物料.請(qǐng)檢查領(lǐng)料單!'

set @fsumcount=0

--控制領(lǐng)料單的日期不能小于生產(chǎn)任務(wù)單計(jì)劃開工日期

if exists( select t3.fbillno from inserted as t1

inner join icstockbillentry as t2 on t2.finterid=t1.finterid

inner join icmo as t3 on t3.finterid=t2.fsourceinterid

where t2.fsourceinterid>0 and t1.fdate begin

select top 1 @icmo=t3.fbillno from inserted as t1

inner join icstockbillentry as t2 on t2.finterid=t1.finterid

inner join icmo as t3 on t3.finterid=t2.fsourceinterid

where t2.fsourceinterid>0 and t1.fdate set @message=@message+@icmo

RAISERROR(@message,18,18)

ROLLBACK

end

--完工生產(chǎn)任務(wù)單不能跨月領(lǐng)料

if exists(

select t3.fbillno,t1.fdate,max(t4.fdate) from inserted as t1

inner join icstockbillentry as t2 on t2.finterid=t1.finterid

inner join icmo as t3 on t3.finterid=t2.fsourceinterid and t3.fqty=t3.fstockqty

inner join icstockbill as t4 on t4.ftrantype=2

inner join icstockbillentry as t5 on t5.finterid=t4.finterid and t5.fsourceinterid=t2.fsourceinterid

group by t3.fbillno,t1.fdate

having Cast(year(t1.fdate) as int(10))*100+Cast(month(t1.fdate) as int(5))

>Cast(year(max(t4.fdate)) as int(10))*100+Cast(month(max(t4.fdate)) as int(5))

)

begin

RAISERROR(@message00,18,18)

ROLLBACK

end

--限制一張領(lǐng)料單只能領(lǐng)同一類型的物料

select @fsumcount=count(distinct(left(t4.fnumber,1))) from inserted as t1

inner join icstockbillentry as t2 on t2.finterid=t1.finterid

inner join icmo as t3 on t3.finterid=t2.fsourceinterid and t3.fworkshop=84

inner join t_icitem as t4 on t4.fitemid=t2.fitemid

where t1.fbillno>'wout.07.013400'

if (@fsumcount>1 )

begin

RAISERROR(@message24000,18,18)

ROLLBACK

end

--更新領(lǐng)料單上的銷售訂單號(hào)

select @finterid240=finterid from inserted

update t2 set t2.fentryselfb0445=t4.fbillno from icstockbill as t1

inner join icstockbillentry as t2 on t1.ftrantype=24 and t1.finterid=t2.finterid

inner join icmo as t3 on t3.finterid=t2.ficmointerid

left join seorder as t4 on t4.finterid=t3.forderinterid

where isnull(t4.fbillno,'no')<>'no' and t2.finterid=@finterid240

return

end

if (@Ftrantype=28)

begin

--更新委外加工出庫單銷售訂單號(hào)

update t2 set t2.FEntrySelfB0842=t4.fbillno from inserted as t1

inner join icstockbillentry as t2 on t2.finterid=t1.finterid

inner join icmo as t3 on t3.finterid=t2.fsourceinterid

inner join seorder as t4 on t4.finterid=t3.forderinterid

return

end

if (@Ftrantype=2)

begin

declare @message4 varchar(200)

declare @message41 varchar(200)

declare @icmo4 varchar(20)

declare @finterid20 int

set @message4='產(chǎn)品入庫日期不能小于生產(chǎn)任務(wù)單計(jì)劃開工日期,錯(cuò)誤單號(hào):'

--產(chǎn)品入庫單入庫日期不能小于生產(chǎn)任務(wù)單計(jì)劃開工日期

if exists( select t3.fbillno from inserted as t1

inner join icstockbillentry as t2 on t2.finterid=t1.finterid

inner join icmo as t3 on t3.finterid=t2.fsourceinterid

where t2.fsourceinterid>0 and t1.fdate begin

select top 1 @icmo4=t3.fbillno from inserted as t1

inner join icstockbillentry as t2 on t2.finterid=t1.finterid

inner join icmo as t3 on t3.finterid=t2.fsourceinterid

where t2.fsourceinterid>0 and t1.fdate set @message4=@message4+@icmo4

RAISERROR(@message4,18,18)

ROLLBACK

end ;

--更新產(chǎn)品入庫單上的銷售訂單號(hào)

select @finterid20=finterid from inserted

update t2 set t2.fentryselfa0236=t4.fbillno from icstockbill as t1

inner join icstockbillentry as t2 on t1.ftrantype=2 and t1.finterid=t2.finterid

inner join icmo as t3 on t3.finterid=t2.ficmointerid

left join seorder as t4 on t4.finterid=t3.forderinterid

where isnull(t4.fbillno,'no')<>'no' and t2.finterid=@finterid20

return

end

 

--更新委外加工入單銷售訂單號(hào)

if (@Ftrantype=5)

begin

update t2 set t2.fentryselfa0548=t4.fbillno from inserted as t1

inner join icstockbillentry as t2 on t2.finterid=t1.finterid

inner join icmo as t3 on t3.finterid=t2.fsourceinterid

inner join seorder as t4 on t4.finterid=t3.forderinterid

return

end

--控制出全部出貨的銷售訂單所對(duì)應(yīng)的采購訂單不能退料(紅字外購入庫單)

/*if (@Ftrantype=1)

begin

declare @message500 varchar(200)

set @message500='已全部出貨的銷售訂單所對(duì)應(yīng)的采購訂單不能退料!請(qǐng)檢查您所退料的采購訂單號(hào)碼是否正確!'

if exists

(select t1.fbillno from inserted as t1

inner join icstockbillentry as t2 on t2.finterid=t1.finterid

inner join seorder as t3 on t3.fbillno=t2.fentryselfa0152

where t2.fqty )

begin

RAISERROR(@message500,18,18)

ROLLBACK

end

return

end */

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多