导入ERP数据生成子订单

1,在奥迪工装订购单表中开启导入Excel功能,把Excel表格中的数据导入后保存,审核后自动生成新的子订单合同

导入ERP数据生成子订单_第1张图片

 2,后台审核时触发生成子订单功能的存储过程

导入ERP数据生成子订单_第2张图片

 3,后台打开存储过程并且修改---》保存(此时的YS字段写死为‘无’,要修改为和订单明细表里的数据颜色一致)

USE [HYData]
GO

/****** Object:  StoredProcedure [dbo].[SP_DDXXB_AODI]    Script Date: 2023-08-18 9:23:30 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER PROC [dbo].[SP_DDXXB_AODI] @DJLSH INT
 AS 
DECLARE @MDJLSH INT,@HJJE DEC(18,2),@HJSL DEC(18,2),@ZDR VARCHAR(20),@ZDRID VARCHAR(20)
DECLARE @JXSDM VARCHAR(60),@XH INT,@MXH INT
SELECT @JXSDM=JXSDM,@ZDR=ZDR,@ZDRID=ZDRID FROM ADGZDGDH WHERE DJLSH=@DJLSH
SELECT @MXH=MAX(XH)+1 FROM ADGZDGDB WHERE DJLSH=@DJLSH
SELECT @MDJLSH=MAX(DJLSH)+1 FROM DDXXBH
-----------------------------------------------------2023/08/18 修改增加字段CYLHTXKH,XKC插入时的默认值
  insert into DDXXBH (DJLSH,DJBTZDH,DJFTZDH,DJSTZDH,JXSDM,KHMC,GSH,GSMC,SHDZ,LXFS,SFZP,FDDBR,NSRSBH,KHYX,KHZH,DH,YB,PP,CZ,WTDLR,BB,ZDRQ,        HTH,                    DJH,YLHTH,ZDRID,ZDR,SHLXR,JEHJ,SLHJ,GL,CYLHTXKH,XKC)
            SELECT @MDJLSH,0,0,0,JXSDM,KHMC,'10','宁波恒远制衣有限公司',SHDZ,LXFS,SFZP,FDDBR,NSRSBH,KHYX,KHZH,DH,YB,PP,CZ,WTDLR,'RMB',GETDATE(),'未生成','XSDDAD'+CAST(@MDJLSH AS varchar(6)) ,'1',@ZDRID,@ZDR,SHR,@HJJE,@HJSL,1,'N',0 FROM GSXXBH
 where jxsdm=@JXSDM;
----------------------------------------------
select TOP 1 * into #t from DDXXBB
delete from #t
SET @XH=1
WHILE(@XH<=@MXH)
-----------------------------------------------------2023/08/18 修改插入临时表时4XL的复制数据
BEGIN
					 INSERT  INTO #t(djlsh,DJBTH,XH,kh,ks,YS,cm,DW,sl,dj,cpfl,cplx,JE)
          SELECT @MDJLSH,DJBTH,ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),WLDM,PZ,'无','XS','件',ISNULL(XS,0),DJ,'奥迪工服','',JE FROM ADGZDGDB WHERE DJLSH=@DJLSH AND XH=@XH
		             INSERT  INTO #t(djlsh,DJBTH,XH,kh,ks,YS,cm,DW,sl,dj,cpfl,cplx,JE)
          SELECT @MDJLSH,DJBTH,ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),WLDM,PZ,'无','S','件',ISNULL(S,0),DJ,'奥迪工服','',JE FROM ADGZDGDB WHERE DJLSH=@DJLSH AND XH=@XH
		             INSERT  INTO #t(djlsh,DJBTH,XH,kh,ks,YS,cm,DW,sl,dj,cpfl,cplx,JE)
          SELECT @MDJLSH,DJBTH,ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),WLDM,PZ,'无','M','件',ISNULL(M,0),DJ,'奥迪工服','',JE FROM ADGZDGDB WHERE DJLSH=@DJLSH AND XH=@XH
		             INSERT  INTO #t(djlsh,DJBTH,XH,kh,ks,YS,cm,DW,sl,dj,cpfl,cplx,JE)
          SELECT @MDJLSH,DJBTH,ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),WLDM,PZ,'无','L','件',ISNULL(L,0),DJ,'奥迪工服','',JE FROM ADGZDGDB WHERE DJLSH=@DJLSH AND XH=@XH
		             INSERT  INTO #t(djlsh,DJBTH,XH,kh,ks,YS,cm,DW,sl,dj,cpfl,cplx,JE)
          SELECT @MDJLSH,DJBTH,ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),WLDM,PZ,'无','XL','件',ISNULL(XL,0),DJ,'奥迪工服','',JE FROM ADGZDGDB WHERE DJLSH=@DJLSH AND XH=@XH
		             INSERT  INTO #t(djlsh,DJBTH,XH,kh,ks,YS,cm,DW,sl,dj,cpfl,cplx,JE)
          SELECT @MDJLSH,DJBTH,ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),WLDM,PZ,'无','2XL','件',ISNULL(XXL,0),DJ,'奥迪工服','',JE FROM ADGZDGDB WHERE DJLSH=@DJLSH AND XH=@XH
		             INSERT  INTO #t(djlsh,DJBTH,XH,kh,ks,YS,cm,DW,sl,dj,cpfl,cplx,JE)
          SELECT @MDJLSH,DJBTH,ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),WLDM,PZ,'无','3XL','件',ISNULL(XXXL,0),DJ,'奥迪工服','',JE FROM ADGZDGDB WHERE DJLSH=@DJLSH AND XH=@XH
		             INSERT  INTO #t(djlsh,DJBTH,XH,kh,ks,YS,cm,DW,sl,dj,cpfl,cplx,JE)
		  SELECT @MDJLSH,DJBTH,ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),WLDM,PZ,'无','4XL','件',ISNULL(XXXXL,0),DJ,'奥迪工服','',JE FROM ADGZDGDB WHERE DJLSH=@DJLSH AND XH=@XH
		             INSERT  INTO #t(djlsh,DJBTH,XH,kh,ks,YS,cm,DW,sl,dj,cpfl,cplx,JE)
          SELECT @MDJLSH,DJBTH,ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),WLDM,PZ,'无','QT','件',ISNULL(QT,0),DJ,'奥迪工服','',JE FROM ADGZDGDB WHERE DJLSH=@DJLSH AND XH=@XH
		  set @xh=@xh+1
END
          INSERT INTO DDXXBB (djlsh,DJBTH,XH,kh,ks,YS,cm,DW,sl,dj,cpfl,cplx,JE)
          SELECT  DJLSH,ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),kh,ks,YS,cm,DW,sl,dj,cpfl,
		  '奥迪工服',JE FROM #T WHERE SL>0

        DROP TABLE #t
      update ADGZDGDH SET DDDJH='XSDDAD'+CAST(@MDJLSH AS varchar(6)) WHERE DJLSH=@DJLSH
GO


4奥迪工装审核后,去查看子订单,发现已经生成

导入ERP数据生成子订单_第3张图片

5,修改正确的预录合同号,和经销商,保存后会自动生成附体内容 

6,修改存储过程,把颜色和订单明细里的款号颜色一一对照(运用replce函数去括号,会另作一篇细讲),顺便把物品编号默认为款号

USE [HYData]
GO

/****** Object:  StoredProcedure [dbo].[SP_DDXXB_AODI]    Script Date: 2023-08-18 9:23:30 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

ALTER PROC [dbo].[SP_DDXXB_AODI] @DJLSH INT
 AS 
DECLARE @MDJLSH INT,@HJJE DEC(18,2),@HJSL DEC(18,2),@ZDR VARCHAR(20),@ZDRID VARCHAR(20)
DECLARE @JXSDM VARCHAR(60),@XH INT,@MXH INT
SELECT @JXSDM=JXSDM,@ZDR=ZDR,@ZDRID=ZDRID FROM ADGZDGDH WHERE DJLSH=@DJLSH
SELECT @MXH=MAX(XH)+1 FROM ADGZDGDB WHERE DJLSH=@DJLSH
SELECT @MDJLSH=MAX(DJLSH)+1 FROM DDXXBH
-----------------------------------------------------2023/08/18 修改增加字段CYLHTXKH,XKC插入时的默认值
  insert into DDXXBH (DJLSH,DJBTZDH,DJFTZDH,DJSTZDH,JXSDM,KHMC,GSH,GSMC,SHDZ,LXFS,SFZP,FDDBR,NSRSBH,KHYX,KHZH,DH,YB,PP,CZ,WTDLR,BB,ZDRQ,        HTH,                    DJH,YLHTH,ZDRID,ZDR,SHLXR,JEHJ,SLHJ,GL,CYLHTXKH,XKC)
            SELECT @MDJLSH,0,0,0,JXSDM,KHMC,'10','宁波恒远制衣有限公司',SHDZ,LXFS,SFZP,FDDBR,NSRSBH,KHYX,KHZH,DH,YB,PP,CZ,WTDLR,'RMB',GETDATE(),'未生成','XSDDAD'+CAST(@MDJLSH AS varchar(6)) ,'1',@ZDRID,@ZDR,SHR,@HJJE,@HJSL,1,'N',0 FROM GSXXBH
 where jxsdm=@JXSDM;
----------------------------------------------
select TOP 1 * into #t from DDXXBB
delete from #t
SET @XH=1
WHILE(@XH<=@MXH)
-----------------------------------------------------2023/08/18 修改插入临时表时4XL的复制数据
BEGIN
					 INSERT  INTO #t(djlsh,DJBTH,XH,kh,ks,WPBH,YS,cm,DW,sl,dj,cpfl,cplx,JE)
          SELECT @MDJLSH,ADGZDGDB.DJBTH,ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),ADGZDGDB.WLDM,ADGZDGDB.PZ,ADGZDGDB.WLDM,YS=replace(SCDDH.YSJ,'()',''),'XS','件',ISNULL(XS,0),ADGZDGDB.DJ,'奥迪工服','',JE FROM ADGZDGDB 
		  LEFT JOIN SCDDH ON SCDDH.KH =ADGZDGDB.WLDM 
		 where  ADGZDGDB.DJLSH=@DJLSH AND XH=@XH
		 
		  



		             INSERT  INTO #t(djlsh,DJBTH,XH,kh,ks,WPBH,YS,cm,DW,sl,dj,cpfl,cplx,JE)
          SELECT @MDJLSH,ADGZDGDB.DJBTH,ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),ADGZDGDB.WLDM,ADGZDGDB.PZ,ADGZDGDB.WLDM,YS=replace(replace(SCDDH.YSJ,'(',''),')',''),'S','件',ISNULL(S,0),ADGZDGDB.DJ,'奥迪工服','',ADGZDGDB.JE FROM ADGZDGDB  LEFT JOIN SCDDH ON SCDDH.KH =ADGZDGDB.WLDM where  ADGZDGDB.DJLSH=@DJLSH AND XH=@XH
		             INSERT  INTO #t(djlsh,DJBTH,XH,kh,ks,WPBH,YS,cm,DW,sl,dj,cpfl,cplx,JE)
          SELECT @MDJLSH,ADGZDGDB.DJBTH,ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),ADGZDGDB.WLDM,ADGZDGDB.PZ,ADGZDGDB.WLDM,YS=replace(replace(SCDDH.YSJ,'(',''),')',''),'M','件',ISNULL(M,0),ADGZDGDB.DJ,'奥迪工服','',ADGZDGDB.JE FROM ADGZDGDB LEFT JOIN SCDDH ON SCDDH.KH =ADGZDGDB.WLDM where  ADGZDGDB.DJLSH=@DJLSH AND XH=@XH
		             INSERT  INTO #t(djlsh,DJBTH,XH,kh,ks,WPBH,YS,cm,DW,sl,dj,cpfl,cplx,JE)
          SELECT @MDJLSH,ADGZDGDB.DJBTH,ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),ADGZDGDB.WLDM,ADGZDGDB.PZ,ADGZDGDB.WLDM,YS=replace(replace(SCDDH.YSJ,'(',''),')',''),'L','件',ISNULL(L,0),ADGZDGDB.DJ,'奥迪工服','',ADGZDGDB.JE FROM ADGZDGDB LEFT JOIN SCDDH ON SCDDH.KH =ADGZDGDB.WLDM where  ADGZDGDB.DJLSH=@DJLSH AND XH=@XH
		             INSERT  INTO #t(djlsh,DJBTH,XH,kh,ks,WPBH,YS,cm,DW,sl,dj,cpfl,cplx,JE)
          SELECT @MDJLSH,ADGZDGDB.DJBTH,ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),ADGZDGDB.WLDM,ADGZDGDB.PZ,ADGZDGDB.WLDM,YS=replace(replace(SCDDH.YSJ,'(',''),')',''),'XL','件',ISNULL(XL,0),ADGZDGDB.DJ,'奥迪工服','',ADGZDGDB.JE FROM ADGZDGDB LEFT JOIN SCDDH ON SCDDH.KH =ADGZDGDB.WLDM where  ADGZDGDB.DJLSH=@DJLSH AND XH=@XH
		             INSERT  INTO #t(djlsh,DJBTH,XH,kh,ks,WPBH,YS,cm,DW,sl,dj,cpfl,cplx,JE)
          SELECT @MDJLSH,ADGZDGDB.DJBTH,ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),ADGZDGDB.WLDM,ADGZDGDB.PZ,ADGZDGDB.WLDM,YS=replace(replace(SCDDH.YSJ,'(',''),')',''),'2XL','件',ISNULL(XXL,0),ADGZDGDB.DJ,'奥迪工服','',ADGZDGDB.JE FROM ADGZDGDB LEFT JOIN SCDDH ON SCDDH.KH =ADGZDGDB.WLDM where  ADGZDGDB.DJLSH=@DJLSH AND XH=@XH
		             INSERT  INTO #t(djlsh,DJBTH,XH,kh,ks,WPBH,YS,cm,DW,sl,dj,cpfl,cplx,JE)
          SELECT @MDJLSH,ADGZDGDB.DJBTH,ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),ADGZDGDB.WLDM,ADGZDGDB.PZ,ADGZDGDB.WLDM,YS=replace(replace(SCDDH.YSJ,'(',''),')',''),'3XL','件',ISNULL(XXXL,0),ADGZDGDB.DJ,'奥迪工服','',ADGZDGDB.JE FROM ADGZDGDB LEFT JOIN SCDDH ON SCDDH.KH =ADGZDGDB.WLDM where  ADGZDGDB.DJLSH=@DJLSH AND XH=@XH
		             INSERT  INTO #t(djlsh,DJBTH,XH,kh,ks,WPBH,YS,cm,DW,sl,dj,cpfl,cplx,JE)
		  SELECT @MDJLSH,ADGZDGDB.DJBTH,ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),ADGZDGDB.WLDM,ADGZDGDB.PZ,ADGZDGDB.WLDM,YS=replace(replace(SCDDH.YSJ,'(',''),')',''),'4XL','件',ISNULL(XXXXL,0),ADGZDGDB.DJ,'奥迪工服','',ADGZDGDB.JE FROM ADGZDGDB LEFT JOIN SCDDH ON SCDDH.KH =ADGZDGDB.WLDM where  ADGZDGDB.DJLSH=@DJLSH AND XH=@XH
		             INSERT  INTO #t(djlsh,DJBTH,XH,kh,ks,WPBH,YS,cm,DW,sl,dj,cpfl,cplx,JE)
          SELECT @MDJLSH,ADGZDGDB.DJBTH,ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),ADGZDGDB.WLDM,ADGZDGDB.PZ,ADGZDGDB.WLDM,YS=replace(replace(SCDDH.YSJ,'(',''),')',''),'QT','件',ISNULL(QT,0),ADGZDGDB.DJ,'奥迪工服','',ADGZDGDB.JE FROM ADGZDGDB LEFT JOIN SCDDH ON SCDDH.KH =ADGZDGDB.WLDM where  ADGZDGDB.DJLSH=@DJLSH AND XH=@XH
		  set @xh=@xh+1
END
          INSERT INTO DDXXBB (djlsh,DJBTH,XH,kh,ks,WPBH,YS,cm,DW,sl,dj,cpfl,cplx,JE)
          SELECT  DJLSH,ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),ROW_NUMBER  () OVER (ORDER BY (SELECT 1)),kh,ks,WPBH,YS,cm,DW,sl,dj,cpfl,
		  '奥迪工服',JE FROM #T WHERE SL>0

        DROP TABLE #t
      update ADGZDGDH SET DDDJH='XSDDAD'+CAST(@MDJLSH AS varchar(6)) WHERE DJLSH=@DJLSH
GO


你可能感兴趣的:(数据库)