[易飞]ERP的展BOM程序

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/david_520042/article/details/5875499

展BOM程序一直以来都是ERP二次开发人员 非常迫切的任务

易飞7.05的系统,经过在网上一段时间的查找资料,结合现有的报表需求。写了一个存储过程 。

CREATE PROCEDURE [dbo].[SP_BOM_EXPAND] (@ITEMNO VARCHAR(80))
AS  
BEGIN
    --BOM展阶
 --@ITEMNO:查询品号
 --返回:元件品号V1001,主件品号V1002,阶码V1004,阶层次V1005,尾阶标志V1006,展开标志V1007,组成用量V1011,底数V1012,损耗率%V1013
 DECLARE @ITEM_CHILD VARCHAR(80), @ITEM_EXPAND VARCHAR(80), @ITEM_LEVELNO INT, @COUNT INT
 DECLARE @BATCH_NUMBER NUMERIC(18,6)
 CREATE TABLE  #VIEW1 (V1001 VARCHAR(80), 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) 

 SELECT @ITEM_LEVELNO = 1

 INSERT INTO #VIEW1 (V1001, V1002, V1004, V1005, V1011, V1012, V1013)
 SELECT MD003, @ITEMNO, MD002, 1, MD006 , MD007*MC004, MD008 FROM BOMMC, BOMMD WHERE BOMMC.MC001 = BOMMD.MD001 AND MC001 = @ITEMNO

 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
  UPDATE #VIEW1 SET V1007 = '1' WHERE CURRENT OF BOMEXPAND
  SELECT @COUNT = COUNT(*) FROM BOMMC, BOMMD WHERE BOMMC.MC001 = BOMMD.MD001 AND MC001 = @ITEM_CHILD
  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
   END
  FETCH NEXT FROM BOMEXPAND INTO @ITEM_CHILD, @ITEM_EXPAND, @ITEM_LEVELNO, @BATCH_NUMBER /* 在循环体内将读取其余行数据 */
 END
 CLOSE BOMEXPAND   /* 关闭游标 */
 DEALLOCATE BOMEXPAND   /* 删除游标 */
   
  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  品号属性,
         MB002 品名,MB003 规格,MB004 as 单位,V1011 as 组成用量,V1012 as 底数,V1013 as 损耗率,V1011/V1012*(1+V1013) as 累计组成用量  FROM #VIEW1 INNER JOIN  INVMB ON V1001=MB001
 ORDER BY V1004
END
GO

 

效果如下:


系统标准报表

铁观音-厂家直销

展开阅读全文

没有更多推荐了,返回首页