金蝶ERP实现产品入库及委外加工冲减生产现场虚仓毛坯数(修正委外出库的入库及销售出库的入库冲减两次毛坯的问题)
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
 

ALTER    trigger icstockbill_jade01 on icstockbill
for insert,update,delete
as
declare @frob int,@finterid int,@ftrantype int,@fstatus int
select  @frob = frob,@finterid = finterid,@ftrantype = ftrantype,@fstatus = fstatus 
from inserted
--from icstockbill where finterid = 26864

declare @fstatus1 smallint,@fstatus2 smallint,@fbillno varchar(40)
select @fbillno = fbillno,@fstatus1 = fstatus from inserted
--from icstockbill where finterid = 26864
select @fstatus2 = fstatus from deleted
--select @fstatus2 = 0
 
--更新蓝字,未审核状态的 '销售出库单','领料单','委外出库单','其他出库单'的单价和金额
--更新步骤:供应商供货信息,以前月份的期末单价,以前月份的发出单价
--供应商供货信息只取RMB的平均单价
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.fprice,0),famount = isnull(b.fprice,0) * fqty,fauxprice = isnull(b.fprice,0)
     from icstockbillentry a ,(select fitemid,convert(decimal(18,2),avg(fprice)) as fprice from t_supplyentry where fcyid = 1 group by fitemid) 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),avg(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
     group by fstockid,fitemid,fyear * 100 + fperiod) 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 and x.finterid = @finterid

 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),avg(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
     group by fstockid,fitemid,fyear * 100 + fperiod) 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 and x.finterid = @finterid
    end

if @ftrantype  = 2 and ((isnull(@fstatus1,0) = 1 and isnull(@fstatus2,0) = 0) or (isnull(@fstatus1,0) = 0 and isnull(@fstatus2,0) = 1))
    begin
 declare @finterid_zp int
 declare @fitemid_mp int,@fstockid_mp as int,@fqty_mp decimal(18,2)
 --虚仓入库单最大内码
 select @finterid_zp = isnull(max(finterid),0) + 1 from zpstockbill
 --产品入库单第一行产品对应的毛坯
 select @fitemid_mp = c.fitemid from icstockbillentry a,t_icitem b,t_icitem c
 where a.fitemid = b.fitemid and finterid = @finterid
 and c.fnumber = case left(b.fnumber,3) when '11.' then '15.001' when '12.' then '15.001' when '13.' then '15.002' when '14.' then '15.003' when '20.' then '15.002' end
 and fentryid = 1
 if isnull(@fitemid_mp,0) = 0 goto ext
 --产品入库单第一行产品对应的毛坯虚仓
 select @fstockid_mp = c.fitemid from icstockbillentry a,t_icitem b,t_stock c
 where a.fitemid = b.fitemid and finterid = @finterid
 and c.fnumber = case left(b.fnumber,3) when '11.' then '22' when '12.' then '22' when '13.' then '23' when '14.' then '22' when '20.' then '23' end
 and fentryid = 1
 --仓库入库单总数量
 select @fqty_mp = sum(fqty) from icstockbillentry where finterid = @finterid
 
 --审核过程
        if isnull(@fstatus1,0) = 1 and isnull(@fstatus2,0) = 0 
     begin
  --新增单据头
  insert into zpstockbill(fbrno,finterid,ftrantype,frob,fdate,fbillno,fcheckerid,ffmanagerid,fsmanagerid,fbillerid,fdeptid,fstatus,fcheckdate,fbilltypeid)
  select fbrno,@finterid_zp as finterid,26 as ftrantype,frob,fdate,fbillno,fcheckerid,ffmanagerid,fsmanagerid,fbillerid,fdeptid,fstatus,fcheckdate,12551 as fbilltypeid
  from icstockbill where finterid = @finterid
  --新增单据体
  insert into zpstockbillentry(fbrno,finterid,fentryid,fitemid,fqty,funitid,fauxqty,fdcstockid)
  select 0 as fbrno,@finterid_zp as finterid,1 as fentryid,
  @fitemid_mp as fitemid,
  @fqty_mp as fqty,@fqty_mp as fauxqty,
  (select funitid from t_icitem where fitemid = @fitemid_mp) as funitid,
  @fstockid_mp as fdcstockid
  --审核减少库存数量
  select @fqty_mp = - @fqty_mp
     end
 --反审核过程
        if isnull(@fstatus1,0) = 0 and isnull(@fstatus2,0) = 1
     begin
  update zpstockbill set fstatus = 0,fcheckerid = 0 where fbillno = @fbillno
  delete zpstockbill where fbillno = @fbillno
     end
 --更新库存
 if exists (select * from poinventory where fitemid = @fitemid_mp and fstockid = @fstockid_mp)
  update poinventory set fqty = fqty + @fqty_mp where fitemid = @fitemid_mp and fstockid = @fstockid_mp
 else
  insert into poinventory(fbrno,fitemid,fstockid,fqty,fstocktypeid)
  select 0,@fitemid_mp,@fstockid_mp,@fqty_mp,(select ftypeid from t_stock where fitemid = @fstockid_mp)
update icmaxnum set fmaxnum  = (select max(finterid) from zpstockbill) where ftablename = 'zpstockbill' 
    end

ext:
/*
alter table icstockbill disable trigger icstockbill_jade01
alter table icstockbill enable trigger icstockbill_jade01
*/
 
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
 

附件:http://down.51cto.com/data/2347817

本文转自redking51CTO博客,原文链接:http://blog.51cto.com/redking/23235,如需转载请自行联系原作者

金蝶ERP实现产品入库及委外加工冲减生产现场虚仓毛坯数(终结版)相关推荐

  1. 金蝶ERP实现产品入库及委外加工冲减生产现场虚仓毛坯数(修正虚仓不能保存)...

    金蝶ERP实现产品入库冲减生产现场虚仓毛坯数,销售成品代码前一位数对应毛坯件的唯一代码,一一对应,其中增加委外加工时的半成品冲减功能.在此语句具体操作中出现虚仓入库单不能保存,提示不能删除己审核的单据 ...

  2. 金蝶ERP实现产品入库及委外加工冲减生产现场虚仓毛坯数

    金蝶ERP实现产品入库冲减生产现场虚仓毛坯数,销售成品代码前一位数对应毛坯件的唯一代码,一一对应,其中增加委外加工时的半成品冲减功能.具体语句如下: if exists(select 1 from s ...

  3. 金蝶ERP实现产品入库冲减生产现场虚仓毛坯数

    金蝶ERP实现产品入库冲减生产现场虚仓毛坯数,销售成品代码前一位数对应毛坯件的唯一代码,一一对应,具体语句如下: if exists(select 1 from sysobjects where na ...

  4. 学习金蝶ERP 之 K3 介绍

    第1章 金蝶ERP K3 介绍 学习重点: l         金蝶ERP K/3系统数据流程图 l         金蝶ERP K/3 应用流程 1.1 金蝶ERP K/3 系统介绍 金的ERP K ...

  5. 金蝶ERP K3 介绍

    学习重点: l 金蝶ERP K/3系统数据流程图 l 金蝶ERP K/3 应用流程 1.1 金蝶ERP K/3 系统介绍 金的ERP K/3共有56个子系统,在这里主要讲述了销售管理系统.生产数据系统 ...

  6. 委外订单_ERP软件教程:金蝶ERP的委外加工业务流程(一)

    ERP软件教程:金蝶ERP的委外加工业务流程 关注我,我将定期分享更多的ERP解决方案 转发关注并私信我,了解更多的解决方案及操作方法哦 欢迎大家随时咨询关于金蝶ERP的任何问题! 一.应用软件版本: ...

  7. 用友和金蝶ERP产品私有云部署方案

    用友和金蝶ERP产品私有云部署方案 [摘要] 用友 金蝶 私有云 部署 架构图 用友和金蝶ERP产品私有云部署方案 一. 前言 此文档用于用友.金蝶ERP服务端在云环境下部署说明.用友产品包括U8+. ...

  8. 金蝶K3如何根据生产领料情况控制产品入库

    需求: 1.如何控制没有领料不允许做产品入库单? 2.如何控制领料领多少,入库就入库多少? 3.系统能不能控制必须领足够入库的材料才可以入库? 4.想实现材料没有生产领料完不允许产品入库? 5.做产品 ...

  9. el-date-picker设置默认日期_ERP入门教程:快速掌握金蝶ERP的基础-物料批次管理的应用及设置...

    ERP入门教程:快速掌握金蝶ERP的基础-物料的批次管理的应用及设置 关注我,我将定期分享更多的ERP解决方案 转发关注并私信我,了解更多的解决方案及操作方法哦 一.应用软件版本:金蝶KIS旗舰版6. ...

最新文章

  1. iOS - 图文混排技术方案分享
  2. 从换脸到换姿势,AI 在图像处理的道路上越走越魔幻
  3. 线程里面添加参数,并解决多个参数问题[原创]
  4. 安卓手机的加密设备和加密外置SD卡
  5. 无法在 Web 服务器上启动调试。调试失败,因为没有启用集成 Windows 身份验证。请...
  6. CSS中越界问题经典解决方案
  7. sr锁存器 数电_C06. SR锁存器的认识
  8. 机器学习笔记——决策树之分类树
  9. Ubuntu系统下环境变量那些事儿
  10. python代码运行顺序_python 代码运行顺序问题?
  11. 1056 组合数的和 (15 分)—PAT (Basic Level) Practice (中文)
  12. windows字体:中文名,英文名
  13. Junit4测试报错:java.lang.NoClassDefFoundError: org/junit/runner/manipulation/Filter
  14. 如何制作龙芯系统安装U盘
  15. 那一年岳云鹏14岁,郭德纲26岁
  16. 中科大自主招生2018年笔试数学之四
  17. 用scratch2.0编写乒乓球游戏
  18. 强智教务php,强智科技教务处模拟登录
  19. 心电电路算法滤波_心电仪滤波
  20. 解决yay官方源下载慢问题

热门文章

  1. HEC-RAS建模与案例应用
  2. 一文带你认识进行用户细分的原则
  3. 深度:一套系统从无到有的设计
  4. java二次开发流程,源码修改流程(Hadoop)
  5. 人人商城添加虚拟商品支持线下核销的方法
  6. C++ Primer 09 顺序容器
  7. 【BZOJ】4044: [Cerc2014] Virus synthesis-回文自动机
  8. Windows问题解决方法
  9. Tachyon与Ignite系统对比
  10. 在ubuntu 16.04上安装基本的拼音输入法