diff --git a/NX.ERP.Model/NX.ERP.Model.csproj b/NX.ERP.Model/NX.ERP.Model.csproj index 787a7cc..9ca16cb 100644 --- a/NX.ERP.Model/NX.ERP.Model.csproj +++ b/NX.ERP.Model/NX.ERP.Model.csproj @@ -89,6 +89,7 @@ + diff --git a/NX.ERP.Model/Response/Store/MaterialAppVouchAndPostName.cs b/NX.ERP.Model/Response/Store/MaterialAppVouchAndPostName.cs new file mode 100644 index 0000000..08edbe1 --- /dev/null +++ b/NX.ERP.Model/Response/Store/MaterialAppVouchAndPostName.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NX.ERP.Model.Response.Store +{ + public class MaterialAppVouchAndPostName + { + + /// + /// 领料单号 + /// + public string AppVouchOrderNo { get; set; } + + /// + /// 物料编码 + /// + public string MaterialCode { get; set; } + + /// + /// 物料名称 + /// + public string MaterialName { get; set; } + + /// + /// 物料规格 + /// + public string MaterialSpec { get; set; } + + /// + /// 单位 + /// + public string Unit { get; set; } + + public decimal Qty { get; set; } + /// + /// 需求日期 + /// + public string DemandDate { get; set; } + + /// + /// 仓库名称 + /// + public string WarehouseName { get; set; } + + /// + /// 生产单号 + /// + public string ProductOrderNo { get; set; } + + /// + /// 生产单行号 + /// + public string ProductOrderLineNo { get; set; } + + /// + /// 产品编码 + /// + public string ProductCode { get; set; } + + /// + /// 产品名称 + /// + public string ProductName { get; set; } + + /// + /// 产品规格 + /// + public string ProductSpec { get; set; } + /// + /// 库位 + /// + public string Position { get; set; } + } +} diff --git a/NX.ERP.U8/MES/MesLogic.cs b/NX.ERP.U8/MES/MesLogic.cs index 21937c3..5e3d9b8 100644 --- a/NX.ERP.U8/MES/MesLogic.cs +++ b/NX.ERP.U8/MES/MesLogic.cs @@ -8,70 +8,988 @@ namespace NX.ERP.U8.MES { public class MesLogic { - /// - /// - /// - /// - /// - public bool ReportSnList(Model.Request.ProductOrderReportSn info) - { - #region 校验数据 - var momOrder = new Mom.MomOrderDAL().GetModel(info.ProductOrder); - if (momOrder == null || string.IsNullOrEmpty(momOrder.ProductOrderNo)) - { - throw new Exception($"非法的生产单号[{info.ProductOrder}]"); - } - foreach (var detail in info.OrderDetails) - { - //校验明细行合法性 - var momOrderDetail = momOrder.ProductDtlLst.FirstOrDefault(m => { return m.ProductOrderDtlId == detail.SourceDetailId; }); - if (momOrderDetail == null || momOrderDetail.ProductOrderDtlId <= 0) - { - throw new Exception($"非法的生产明细[{detail.SourceDetailId}]"); - } - //校验SN合法性 - var lstExcept = detail.SnList.Except(momOrderDetail.SN).ToList(); - if (lstExcept.Count > 0) - { - throw new Exception($"包含非法的序列号[{string.Join(",", lstExcept.ToArray())}]"); - } - } - #endregion + /// + /// + /// + /// + /// + public bool ReportSnList(Model.Request.ProductOrderReportSn info) + { + #region 校验数据 + var momOrder = new Mom.MomOrderDAL().GetModel(info.ProductOrder); + if (momOrder == null || string.IsNullOrEmpty(momOrder.ProductOrderNo)) + { + throw new Exception($"非法的生产单号[{info.ProductOrder}]"); + } + using (var conn = U8LoginContext.Instance.Connection) + { - #region 写入DB - var instertSql = "INSERT INTO [dbo].[MES_PRODUCT_SN_LIST] ([PRODUCT_ORDER_NO], [ORDER_LINE_ID], [SN]) VALUES (@PRODUCT_ORDER_NO, @ORDER_LINE_ID, @SN);"; - using (var conn = U8LoginContext.Instance.Connection) - { - conn.Open(); - conn.ChangeDatabase(System.Configuration.ConfigurationManager.AppSettings["ApiDbName"]); - var tran = conn.BeginTransaction(); - try - { - conn.Execute($"DELETE FROM MES_PRODUCT_SN_LIST WHERE PRODUCT_ORDER_NO = '{info.ProductOrder}'", null, tran); - foreach (var detail in info.OrderDetails) - { - var newList = detail.SnList.Select(sn => new - { - PRODUCT_ORDER_NO = info.ProductOrder, - ORDER_LINE_ID = detail.SourceDetailId, - SN = sn, - }); - conn.Execute(instertSql, newList, tran); - } - tran.Commit(); - return true; - } - catch (Exception ex) - { - tran.Rollback(); - throw new Exception("保存失败"); - } - finally - { - conn.Close(); - } - } - #endregion 写入DB - } + foreach (var detail in info.OrderDetails) + { + //校验明细行合法性 + var momOrderDetail = momOrder.ProductDtlLst.FirstOrDefault(m => { return m.ProductOrderDtlId == detail.SourceDetailId; }); + if (momOrderDetail == null || momOrderDetail.ProductOrderDtlId <= 0) + { + throw new Exception($"非法的生产明细[{detail.SourceDetailId}]"); + } + //校验SN合法性 + var lstExcept = detail.SnList.Except(momOrderDetail.SN).ToList(); + if (lstExcept.Count > 0) + { + throw new Exception($"包含非法的序列号[{string.Join(",", lstExcept.ToArray())}]"); + } + + var dicSnCount = new Dictionary(); + var rd = conn.ExecuteReader(querySnSql, new { SN = string.Join(",", detail.SnList.ToArray()) }); + while (rd.Read()) + { + var sn = rd["cinvsn"]?.ToString(); + var compareCount = -1;//仅用于未赋值的标记,实际数据不存在-1 + if (dicSnCount.ContainsKey(sn)) + { + compareCount = dicSnCount[sn]; + } + if (rd["InOutType"]?.ToString() == "出") + { + if (compareCount == -1) + { + dicSnCount.Add(sn, int.Parse(rd["COUNT"].ToString())); + } + else if (int.Parse(rd["COUNT"].ToString()) <= compareCount) + { + throw new Exception($"序列号[{rd["cinvsn"]?.ToString()}]校验失败,无法继续入库"); + } + } + else if (rd["InOutType"]?.ToString() == "入") + { + if (compareCount == -1) + { + dicSnCount.Add(sn, int.Parse(rd["COUNT"].ToString())); + } + else if (int.Parse(rd["COUNT"].ToString()) > compareCount) + { + throw new Exception($"序列号[{rd["cinvsn"]?.ToString()}]校验失败,无法继续入库"); + } + } + } + conn.Close(); + } + #endregion + + #region 写入DB + var instertSql = "INSERT INTO [dbo].[MES_PRODUCT_SN_LIST] ([PRODUCT_ORDER_NO], [ORDER_LINE_ID], [SN]) VALUES (@PRODUCT_ORDER_NO, @ORDER_LINE_ID, @SN);"; + + + conn.Open(); + conn.ChangeDatabase(System.Configuration.ConfigurationManager.AppSettings["ApiDbName"]); + var tran = conn.BeginTransaction(); + try + { + conn.Execute($"DELETE FROM MES_PRODUCT_SN_LIST WHERE PRODUCT_ORDER_NO = '{info.ProductOrder}'", null, tran); + foreach (var detail in info.OrderDetails) + { + var newList = detail.SnList.Select(sn => new + { + PRODUCT_ORDER_NO = info.ProductOrder, + ORDER_LINE_ID = detail.SourceDetailId, + SN = sn, + }); + conn.Execute(instertSql, newList, tran); + } + tran.Commit(); + return true; + } + catch (Exception ex) + { + tran.Rollback(); + throw new Exception("保存失败"); + } + finally + { + conn.Close(); + } + } + #endregion 写入DB + } + + const string querySnSql = @" +declare @chrSQl as nvarchar(4000) ,@tmptableName nvarchar(100), + @sWhere nvarchar(4000)='' +declare @sTmpWhere as nvarchar(4000) +set @sWhere=rtrim(ltrim(@sWhere)) +select @tmptableName='SP_ST_SNLSZ20210615' + +if @sWhere<>'' set @sWhere=' and '+@sWhere + +if exists (select name from tempdb..sysobjects where name=@tmptablename and xtype=N'u') + exec ('drop table tempdb..'+@tmptableName) + + +set @chrSQL = N'CREATE TABLE tempdb..'+@tmptableName +N' ( + [ID] [int] NULL , + [cVouchType] [nvarchar] (20) NULL , + [VouchType] [nvarchar] (150) NULL , + [cInvCode] [nvarchar] (60) NULL , + [cInvName] [nvarchar] (60) NOT NULL , + [cInvAddCode] [nvarchar] (30) NULL , + [cInvStd] [nvarchar] (60) NULL , + [ccomunitcode] [nvarchar] (35) NULL , + [cinvm_unit] [nvarchar] (20) NOT NULL , + [cFree1] [nvarchar] (20) NULL , + [cFree2] [nvarchar] (20) NULL , + [cFree3] [nvarchar] (20) NULL , + [cFree4] [nvarchar] (20) NULL , + [cFree5] [nvarchar] (20) NULL , + [cFree6] [nvarchar] (20) NULL , + [cFree7] [nvarchar] (20) NULL , + [cFree8] [nvarchar] (20) NULL , + [cFree9] [nvarchar] (20) NULL , + [cFree10] [nvarchar] (20) NULL , + [cInvDefine1] [nvarchar] (20) NULL , + [cInvDefine2] [nvarchar] (20) NULL , + [cInvDefine3] [nvarchar] (20) NULL , + [cInvDefine4] [nvarchar] (60) NULL , + [cInvDefine5] [nvarchar] (60) NULL , + [cInvDefine6] [nvarchar] (60) NULL , + [cInvDefine7] [nvarchar] (120) NULL , + [cInvDefine8] [nvarchar] (120) NULL , + [cInvDefine9] [nvarchar] (120) NULL , + [cInvDefine10] [nvarchar] (120) NULL , + [cInvDefine11] [int] NULL , + [cInvDefine12] [int] NULL , + [cInvDefine13] [float] NULL , + [cInvDefine14] [float] NULL , + [cInvDefine15] [datetime] NULL , + [cInvDefine16] [datetime] NULL , + [iId] [int] NULL , + [cinvccode] [nvarchar] (12) NULL , + [cinvcname] [nvarchar] (100) NULL , + [cBatch] [nvarchar] (60) NULL , + [dmdate] [datetime] NULL , + [imassunit] [smallint] NULL , + [cmassunit] [nvarchar] (150) NULL , + [imassdate] [int] NULL , + [dvdate] [datetime] NULL , + [cincode] [nvarchar] (30) NULL , + [cVenCode] [nvarchar] (30) NULL , + [cVenAbbName] [nvarchar] (60) NULL , + [cWhCode] [nvarchar] (10) NULL , + [cWhName] [nvarchar] (20) NULL , + [cposition] [nvarchar] (30) NULL , + [cposname] [nvarchar] (30) NULL , + [cinvsn] [nvarchar] (150) NULL , + [cSNDefine1] [nvarchar] (200) NULL , + [cSNDefine2] [nvarchar] (200) NULL , + [cSNDefine3] [nvarchar] (200) NULL , + [cSNDefine4] [nvarchar] (200) NULL , + [cSNDefine5] [nvarchar] (200) NULL , + [cSNDefine6] [nvarchar] (200) NULL , + [cSNDefine7] [nvarchar] (200) NULL , + [cSNDefine8] [nvarchar] (200) NULL , + [cSNDefine9] [nvarchar] (200) NULL , + [cSNDefine10] [nvarchar] (200) NULL , + [cSNMemo] [nvarchar] (200) NULL , + [InOutTypeCode] [nvarchar] (20) NULL , + [InOutType] [nvarchar] (150) NULL , + [ccode] [nvarchar] (30) NULL , + [ddate] [datetime] NULL , + [cstate] [nvarchar] (150) NULL , + [cbustype] [nvarchar] (12) NULL , + [cbustypename] [nvarchar] (150) NULL , + [cdepcode] [nvarchar] (12) NULL , + [cdepname] [nvarchar] (20) NULL , + [cpersoncode] [nvarchar] (20) NULL , + [cpersonname] [nvarchar] (40) NULL , + [chvencode] [nvarchar] (20) NULL , + [chvenabbname] [nvarchar] (60) NULL , + [ccuscode] [nvarchar] (20) NULL , + [ccusabbname] [nvarchar] (60) NULL , + [crdcode] [nvarchar] (5) NULL , + [crdname] [nvarchar] (20) NULL , + [cmaker] [nvarchar] (60) NULL , + [chandler] [nvarchar] (60) NULL +)' +--exec (@chrSQL) + + +set @chrSQL =N' select r.id,convert (nvarchar(10), Null ) as cVouchType +,convert (nvarchar(255), Null ) as VouchType +,SN.cInvCode,I.cInvName,I.cInvAddCode,I.cInvStd,i.ccomunitcode,computationunit.ccomunitname as cinvm_unit +,SN.cFree1,SN.cFree2,SN.cFree3,SN.cFree4,SN.cFree5,SN.cFree6,SN.cFree7,SN.cFree8,SN.cFree9,SN.cFree10 +,I.cInvDefine1,I.cInvDefine2,I.cInvDefine3,I.cInvDefine4,I.cInvDefine5,I.cInvDefine6,I.cInvDefine7,I.cInvDefine8 +,I.cInvDefine9,I.cInvDefine10,I.cInvDefine11,I.cInvDefine12,I.cInvDefine13,I.cInvDefine14,I.cInvDefine15 +,I.cInvDefine16,I.iId,IC.cinvccode,IC.cinvcname,SN.cBatch,SN.dmdate,SN.imassunit,enum2.enumname as cmassunit +,sn.imassdate,SN.dvdate,SN.cincode,SN.cVenCode,vendor.cVenAbbName,SN.cWhCode,W.cWhName,SN.cposition,p.cposname +,SN.cinvsn,SN.cSNDefine1,SN.cSNDefine2,SN.cSNDefine3,SN.cSNDefine4,SN.cSNDefine5,SN.cSNDefine6,SN.cSNDefine7 +,SN.cSNDefine8,SN.cSNDefine9,SN.cSNDefine10,SN.cSNMemo,convert (nvarchar(20), Null ) as InOutTypeCode +,convert (nvarchar(150), Null ) as InOutType +,r.ccode,r.ddate +, +convert (nvarchar(150), Null ) as cstate +,r.cbustype,enum1.enumname as cbustypename,r.cdepcode,d.cdepname,r.cpersoncode,person.cpersonname +,r.cvencode as chvencode,v.cvenabbname as chvenabbname,r.ccuscode,customer.ccusabbname +,r.crdcode,rd_style.crdname,r.cmaker,r.chandler +into tempdb..'+@tmptableName +N' +from ST_SNDetail_QC SN +inner join Inventory I on SN.cInvCode = I.cInvCode +inner join computationunit on I.ccomunitcode = computationunit.ccomunitcode +inner join inventoryclass IC on I.cinvccode=IC.cinvccode +left join rdrecords34 rs on SN.iVouchsid=rs.autoid +left join rdrecord34 r on rs.id=r.id and r.cvouchtype=N''34'' +left join v_aa_enum enum2 on enum2.enumtype=N''ST.MassUnit'' and enum2.enumcode=sn.imassunit +left join position p on SN.cposition=p.cposcode +left join vendor on SN.cvencode=vendor.cvencode +inner join warehouse w on SN.cwhcode=w.cwhcode +left join department d on d.cdepcode=r.cdepcode +left join person on person.cpersoncode=r.cpersoncode +left join vendor v on v.cvencode=r.cvencode +left join customer on r.ccuscode = customer.ccuscode +left join rd_style on r.crdcode = rd_style.crdcode +left join v_aa_enum enum1 on enum1.enumtype=N''ST.BusType'' and enum1.enumcode=r.cbustype +left join v_aa_enum enum3 on enum3.enumtype=N''ST.VouchType'' and enum3.enumcode=N''34'' +where 1=0 ' + +exec (@chrSQL) +--期初结存 +set @chrSQL =N'insert into tempdb..'+@tmptableName +N' select r.id,r.cVouchType +,enum3.enumname as VouchType +,SN.cInvCode,I.cInvName,I.cInvAddCode,I.cInvStd,i.ccomunitcode,computationunit.ccomunitname as cinvm_unit +,SN.cFree1,SN.cFree2,SN.cFree3,SN.cFree4,SN.cFree5,SN.cFree6,SN.cFree7,SN.cFree8,SN.cFree9,SN.cFree10 +,I.cInvDefine1,I.cInvDefine2,I.cInvDefine3,I.cInvDefine4,I.cInvDefine5,I.cInvDefine6,I.cInvDefine7,I.cInvDefine8 +,I.cInvDefine9,I.cInvDefine10,I.cInvDefine11,I.cInvDefine12,I.cInvDefine13,I.cInvDefine14,I.cInvDefine15 +,I.cInvDefine16,I.iId,IC.cinvccode,IC.cinvcname,SN.cBatch,SN.dmdate,SN.imassunit,enum2.enumname as cmassunit +,sn.imassdate,SN.dvdate,SN.cincode,SN.cVenCode,vendor.cVenAbbName,SN.cWhCode,W.cWhName,SN.cposition,p.cposname +,SN.cinvsn,SN.cSNDefine1,SN.cSNDefine2,SN.cSNDefine3,SN.cSNDefine4,SN.cSNDefine5,SN.cSNDefine6,SN.cSNDefine7 +,SN.cSNDefine8,SN.cSNDefine9,SN.cSNDefine10,SN.cSNMemo,N''1'' as InOutTypeCode +,(select top 1 EnumName from v_aa_enum where enumcode=N''1'' and enumtype=N''ST.InOutFlag'') as InOutType +,r.ccode,r.ddate +,(select top 1 EnumName from v_aa_enum where enumcode= +(case when isnull(r.chandler,'''')='''' then N''4'' else N''1'' end) and enumtype=N''ST.VouchState'') as cstate +,r.cbustype,enum1.enumname as cbustypename,r.cdepcode,d.cdepname,r.cpersoncode,person.cpersonname +,r.cvencode as chvencode,v.cvenabbname as chvenabbname,r.ccuscode,customer.ccusabbname +,r.crdcode,rd_style.crdname,r.cmaker,r.chandler +from ST_SNDetail_QC SN +inner join Inventory I on SN.cInvCode = I.cInvCode +inner join computationunit on I.ccomunitcode = computationunit.ccomunitcode +inner join inventoryclass IC on I.cinvccode=IC.cinvccode +left join rdrecords34 rs on SN.iVouchsid=rs.autoid +left join rdrecord34 r on rs.id=r.id and r.cvouchtype=N''34'' +left join v_aa_enum enum2 on enum2.enumtype=N''ST.MassUnit'' and enum2.enumcode=sn.imassunit +left join position p on SN.cposition=p.cposcode +left join vendor on SN.cvencode=vendor.cvencode +inner join warehouse w on SN.cwhcode=w.cwhcode +left join department d on d.cdepcode=r.cdepcode +left join person on person.cpersoncode=r.cpersoncode +left join vendor v on v.cvencode=r.cvencode +left join customer on r.ccuscode = customer.ccuscode +left join rd_style on r.crdcode = rd_style.crdcode +left join v_aa_enum enum1 on enum1.enumtype=N''ST.BusType'' and enum1.enumcode=r.cbustype +left join v_aa_enum enum3 on enum3.enumtype=N''ST.VouchType'' and enum3.enumcode=N''34'' +where 1=1 ' +exec (@chrSQL+@sWhere) + + + +--期初不合格品 +set @chrSQL =N'insert into tempdb..'+@tmptableName +N' select r.id,r.cVouchType +,enum3.enumname as VouchType +,SN.cInvCode,I.cInvName,I.cInvAddCode,I.cInvStd,i.ccomunitcode,computationunit.ccomunitname as cinvm_unit +,SN.cFree1,SN.cFree2,SN.cFree3,SN.cFree4,SN.cFree5,SN.cFree6,SN.cFree7,SN.cFree8,SN.cFree9,SN.cFree10 +,I.cInvDefine1,I.cInvDefine2,I.cInvDefine3,I.cInvDefine4,I.cInvDefine5,I.cInvDefine6,I.cInvDefine7,I.cInvDefine8 +,I.cInvDefine9,I.cInvDefine10,I.cInvDefine11,I.cInvDefine12,I.cInvDefine13,I.cInvDefine14,I.cInvDefine15 +,I.cInvDefine16,I.iId,IC.cinvccode,IC.cinvcname,SN.cBatch,SN.dmdate,SN.imassunit,enum2.enumname as cmassunit +,sn.imassdate,SN.dvdate,SN.cincode,SN.cVenCode,vendor.cVenAbbName,SN.cWhCode,W.cWhName,SN.cposition,p.cposname +,SN.cinvsn,SN.cSNDefine1,SN.cSNDefine2,SN.cSNDefine3,SN.cSNDefine4,SN.cSNDefine5,SN.cSNDefine6,SN.cSNDefine7 +,SN.cSNDefine8,SN.cSNDefine9,SN.cSNDefine10,SN.cSNMemo,N''1'' as InOutTypeCode +,(select top 1 EnumName from v_aa_enum where enumcode=N''1'' and enumtype=N''ST.InOutFlag'') as InOutType +,r.cspcode as ccode,r.ddate +,(select top 1 EnumName from v_aa_enum where enumcode= +(case when isnull(r.cverifyperson,'''')='''' then N''4'' else N''1'' end) and enumtype=N''ST.VouchState'') as cstate +,null as cbustype,null as cbustypename,r.cdepcode,d.cdepname,r.cpersoncode,person.cpersonname +,r.cvencode as chvencode,v.cvenabbname as chvenabbname,r.ccuscode,customer.ccusabbname +,r.cirdcode as crdcode,rd_style.crdname,r.cmaker,r.cverifyperson as chandler +from ST_SNDetail_QCUnQ SN +inner join Inventory I on SN.cInvCode = I.cInvCode +inner join computationunit on I.ccomunitcode = computationunit.ccomunitcode +inner join inventoryclass IC on I.cinvccode=IC.cinvccode +left join scrapvouchs rs on SN.iVouchsid=rs.autoid +left join scrapvouch r on rs.id=r.id and r.cvouchtype=N''55'' +left join v_aa_enum enum2 on enum2.enumtype=N''ST.MassUnit'' and enum2.enumcode=sn.imassunit +left join position p on SN.cposition=p.cposcode +left join vendor on SN.cvencode=vendor.cvencode +inner join warehouse w on SN.cwhcode=w.cwhcode +left join department d on d.cdepcode=r.cdepcode +left join person on person.cpersoncode=r.cpersoncode +left join vendor v on v.cvencode=r.cvencode +left join customer on r.ccuscode = customer.ccuscode +left join rd_style on r.cirdcode = rd_style.crdcode +left join v_aa_enum enum3 on enum3.enumtype=N''ST.VouchType'' and enum3.enumcode=N''55'' +where 1=1 ' +exec (@chrSQL+@sWhere) + +--期初合格品序列号 +set @chrSQL =N'insert into tempdb..'+@tmptableName +N' select rs.autoid as id,N''91'' as cVouchType +,(select top 1 EnumName from v_aa_enum where enumcode=N''91'' and enumtype=N''ST.VouchType'') as VouchType +,SN.cInvCode,I.cInvName,I.cInvAddCode,I.cInvStd,i.ccomunitcode,computationunit.ccomunitname as cinvm_unit +,SN.cFree1,SN.cFree2,SN.cFree3,SN.cFree4,SN.cFree5,SN.cFree6,SN.cFree7,SN.cFree8,SN.cFree9,SN.cFree10 +,I.cInvDefine1,I.cInvDefine2,I.cInvDefine3,I.cInvDefine4,I.cInvDefine5,I.cInvDefine6,I.cInvDefine7,I.cInvDefine8 +,I.cInvDefine9,I.cInvDefine10,I.cInvDefine11,I.cInvDefine12,I.cInvDefine13,I.cInvDefine14,I.cInvDefine15 +,I.cInvDefine16,I.iId,IC.cinvccode,IC.cinvcname,SN.cBatch,SN.dmdate,SN.imassunit,enum2.enumname as cmassunit +,sn.imassdate,SN.dvdate,SN.cincode,SN.cVenCode,vendor.cVenAbbName,SN.cWhCode,W.cWhName,SN.cposition,p.cposname +,SN.cinvsn,SN.cSNDefine1,SN.cSNDefine2,SN.cSNDefine3,SN.cSNDefine4,SN.cSNDefine5,SN.cSNDefine6,SN.cSNDefine7 +,SN.cSNDefine8,SN.cSNDefine9,SN.cSNDefine10,SN.cSNMemo,N''1'' as InOutTypeCode +,(select top 1 EnumName from v_aa_enum where enumcode=N''1'' and enumtype=N''ST.InOutFlag'') as InOutType +,null as ccode,rs.ddate +,(select top 1 EnumName from v_aa_enum where enumcode= +(case when isnull(rs.chandler,'''')='''' then N''4'' else N''1'' end) and enumtype=N''ST.VouchState'') as cstate +,null as cbustype,null as cbustypename,null as cdepcode,null as cdepname,null as cpersoncode,null as cpersonname +,rs.cbvencode as chvencode,v.cvenabbname as chvenabbname,null as ccuscode,null as ccusabbname +,null as crdcode,null as crdname,rs.cmaker,rs.chandler +from ST_SNDetail_QCQu SN +inner join Inventory I on SN.cInvCode = I.cInvCode +inner join computationunit on I.ccomunitcode = computationunit.ccomunitcode +inner join inventoryclass IC on I.cinvccode=IC.cinvccode +left join St_QCQualifiedSNdetail rs on SN.iVouchsid=rs.autoid and rs.cvouchtype=N''SN88'' +left join v_aa_enum enum2 on enum2.enumtype=N''ST.MassUnit'' and enum2.enumcode=sn.imassunit +left join position p on SN.cposition=p.cposcode +left join vendor on SN.cvencode=vendor.cvencode +inner join warehouse w on SN.cwhcode=w.cwhcode +left join vendor v on v.cvencode=rs.cbvencode +where 1=1 ' +exec (@chrSQL+@sWhere) + +--期初不合格品序列号 +set @chrSQL =N'insert into tempdb..'+@tmptableName +N' select rs.autoid as id,N''92'' as cVouchType +,(select top 1 EnumName from v_aa_enum where enumcode=N''92'' and enumtype=N''ST.VouchType'') as VouchType +,SN.cInvCode,I.cInvName,I.cInvAddCode,I.cInvStd,i.ccomunitcode,computationunit.ccomunitname as cinvm_unit +,SN.cFree1,SN.cFree2,SN.cFree3,SN.cFree4,SN.cFree5,SN.cFree6,SN.cFree7,SN.cFree8,SN.cFree9,SN.cFree10 +,I.cInvDefine1,I.cInvDefine2,I.cInvDefine3,I.cInvDefine4,I.cInvDefine5,I.cInvDefine6,I.cInvDefine7,I.cInvDefine8 +,I.cInvDefine9,I.cInvDefine10,I.cInvDefine11,I.cInvDefine12,I.cInvDefine13,I.cInvDefine14,I.cInvDefine15 +,I.cInvDefine16,I.iId,IC.cinvccode,IC.cinvcname,SN.cBatch,SN.dmdate,SN.imassunit,enum2.enumname as cmassunit +,sn.imassdate,SN.dvdate,SN.cincode,SN.cVenCode,vendor.cVenAbbName,SN.cWhCode,W.cWhName,SN.cposition,p.cposname +,SN.cinvsn,SN.cSNDefine1,SN.cSNDefine2,SN.cSNDefine3,SN.cSNDefine4,SN.cSNDefine5,SN.cSNDefine6,SN.cSNDefine7 +,SN.cSNDefine8,SN.cSNDefine9,SN.cSNDefine10,SN.cSNMemo,N''1'' as InOutTypeCode +,(select top 1 EnumName from v_aa_enum where enumcode=N''1'' and enumtype=N''ST.InOutFlag'') as InOutType +,null as ccode,rs.ddate +,(select top 1 EnumName from v_aa_enum where enumcode= +(case when isnull(rs.chandler,'''')='''' then N''4'' else N''1'' end) and enumtype=N''ST.VouchState'') as cstate +,null as cbustype,null as cbustypename,null as cdepcode,null as cdepname,null as cpersoncode,null as cpersonname +,rs.cbvencode as chvencode,v.cvenabbname as chvenabbname,null as ccuscode,null as ccusabbname +,null as crdcode,null as crdname,rs.cmaker,rs.chandler +from ST_SNDetail_QCScrap SN +inner join Inventory I on SN.cInvCode = I.cInvCode +inner join computationunit on I.ccomunitcode = computationunit.ccomunitcode +inner join inventoryclass IC on I.cinvccode=IC.cinvccode +left join St_QCQualifiedSNdetail rs on SN.iVouchsid=rs.autoid and rs.cvouchtype=N''SN89'' +left join v_aa_enum enum2 on enum2.enumtype=N''ST.MassUnit'' and enum2.enumcode=sn.imassunit +left join position p on SN.cposition=p.cposcode +left join vendor on SN.cvencode=vendor.cvencode +inner join warehouse w on SN.cwhcode=w.cwhcode +left join vendor v on v.cvencode=rs.cbvencode +where 1=1 ' +exec (@chrSQL+@sWhere) + +--采购入库单 +set @chrSQL =N'insert into tempdb..'+@tmptableName +N' select r.id,r.cVouchType +,enum3.enumname as VouchType +,SN.cInvCode,I.cInvName,I.cInvAddCode,I.cInvStd,i.ccomunitcode,computationunit.ccomunitname as cinvm_unit +,SN.cFree1,SN.cFree2,SN.cFree3,SN.cFree4,SN.cFree5,SN.cFree6,SN.cFree7,SN.cFree8,SN.cFree9,SN.cFree10 +,I.cInvDefine1,I.cInvDefine2,I.cInvDefine3,I.cInvDefine4,I.cInvDefine5,I.cInvDefine6,I.cInvDefine7,I.cInvDefine8 +,I.cInvDefine9,I.cInvDefine10,I.cInvDefine11,I.cInvDefine12,I.cInvDefine13,I.cInvDefine14,I.cInvDefine15 +,I.cInvDefine16,I.iId,IC.cinvccode,IC.cinvcname,SN.cBatch,SN.dmdate,SN.imassunit,enum2.enumname as cmassunit +,sn.imassdate,SN.dvdate,SN.cincode,SN.cVenCode,vendor.cVenAbbName,SN.cWhCode,W.cWhName,SN.cposition,p.cposname +,SN.cinvsn,SN.cSNDefine1,SN.cSNDefine2,SN.cSNDefine3,SN.cSNDefine4,SN.cSNDefine5,SN.cSNDefine6,SN.cSNDefine7 +,SN.cSNDefine8,SN.cSNDefine9,SN.cSNDefine10,SN.cSNMemo +,case when isnull(rs.iquantity,0)<0 then N''0'' else N''1'' end as InOutTypeCode +,case when isnull(rs.iquantity,0)<0 then +(select top 1 EnumName from v_aa_enum where enumcode=N''0'' and enumtype=N''ST.InOutFlag'') +else +(select top 1 EnumName from v_aa_enum where enumcode=N''1'' and enumtype=N''ST.InOutFlag'') +end as InOutType +,r.ccode,r.ddate +,(select top 1 EnumName from v_aa_enum where enumcode= +(case when isnull(r.chandler,'''')='''' then N''4'' else N''1'' end) and enumtype=N''ST.VouchState'') as cstate +,r.cbustype,enum1.enumname as cbustypename,r.cdepcode,d.cdepname,r.cpersoncode,person.cpersonname +,r.cvencode as chvencode,v.cvenabbname as chvenabbname,r.ccuscode,customer.ccusabbname +,r.crdcode,rd_style.crdname,r.cmaker,r.chandler +from ST_SNDetail_PUIN SN +inner join Inventory I on SN.cInvCode = I.cInvCode +inner join computationunit on I.ccomunitcode = computationunit.ccomunitcode +inner join inventoryclass IC on I.cinvccode=IC.cinvccode +left join rdrecords01 rs on SN.iVouchsid=rs.autoid +left join rdrecord01 r on rs.id=r.id and r.cvouchtype=N''01'' +left join v_aa_enum enum2 on enum2.enumtype=N''ST.MassUnit'' and enum2.enumcode=sn.imassunit +left join position p on SN.cposition=p.cposcode +left join vendor on SN.cvencode=vendor.cvencode +inner join warehouse w on SN.cwhcode=w.cwhcode +left join department d on d.cdepcode=r.cdepcode +left join person on person.cpersoncode=r.cpersoncode +left join vendor v on v.cvencode=r.cvencode +left join customer on r.ccuscode = customer.ccuscode +left join rd_style on r.crdcode = rd_style.crdcode +left join v_aa_enum enum1 on enum1.enumtype=N''ST.BusType'' and enum1.enumcode=r.cbustype +left join v_aa_enum enum3 on enum3.enumtype=N''ST.VouchType'' and enum3.enumcode=N''01'' +where 1=1 ' +exec (@chrSQL+@sWhere) + +--产成品入库单 +set @chrSQL =N'insert into tempdb..'+@tmptableName +N' select r.id,r.cVouchType +,enum3.enumname as VouchType +,SN.cInvCode,I.cInvName,I.cInvAddCode,I.cInvStd,i.ccomunitcode,computationunit.ccomunitname as cinvm_unit +,SN.cFree1,SN.cFree2,SN.cFree3,SN.cFree4,SN.cFree5,SN.cFree6,SN.cFree7,SN.cFree8,SN.cFree9,SN.cFree10 +,I.cInvDefine1,I.cInvDefine2,I.cInvDefine3,I.cInvDefine4,I.cInvDefine5,I.cInvDefine6,I.cInvDefine7,I.cInvDefine8 +,I.cInvDefine9,I.cInvDefine10,I.cInvDefine11,I.cInvDefine12,I.cInvDefine13,I.cInvDefine14,I.cInvDefine15 +,I.cInvDefine16,I.iId,IC.cinvccode,IC.cinvcname,SN.cBatch,SN.dmdate,SN.imassunit,enum2.enumname as cmassunit +,sn.imassdate,SN.dvdate,SN.cincode,SN.cVenCode,vendor.cVenAbbName,SN.cWhCode,W.cWhName,SN.cposition,p.cposname +,SN.cinvsn,SN.cSNDefine1,SN.cSNDefine2,SN.cSNDefine3,SN.cSNDefine4,SN.cSNDefine5,SN.cSNDefine6,SN.cSNDefine7 +,SN.cSNDefine8,SN.cSNDefine9,SN.cSNDefine10,SN.cSNMemo +,case when isnull(rs.iquantity,0)<0 then N''0'' else N''1'' end as InOutTypeCode +,case when isnull(rs.iquantity,0)<0 then +(select top 1 EnumName from v_aa_enum where enumcode=N''0'' and enumtype=N''ST.InOutFlag'') +else +(select top 1 EnumName from v_aa_enum where enumcode=N''1'' and enumtype=N''ST.InOutFlag'') +end as InOutType +,r.ccode,r.ddate +,(select top 1 EnumName from v_aa_enum where enumcode= +(case when isnull(r.chandler,'''')='''' then N''4'' else N''1'' end) and enumtype=N''ST.VouchState'') as cstate +,r.cbustype,enum1.enumname as cbustypename,r.cdepcode,d.cdepname,r.cpersoncode,person.cpersonname +,r.cvencode as chvencode,v.cvenabbname as chvenabbname,r.ccuscode,customer.ccusabbname +,r.crdcode,rd_style.crdname,r.cmaker,r.chandler +from ST_SNDetail_PROIN SN +inner join Inventory I on SN.cInvCode = I.cInvCode +inner join computationunit on I.ccomunitcode = computationunit.ccomunitcode +inner join inventoryclass IC on I.cinvccode=IC.cinvccode +left join rdrecords10 rs on SN.iVouchsid=rs.autoid +left join rdrecord10 r on rs.id=r.id and r.cvouchtype=N''10'' +left join v_aa_enum enum2 on enum2.enumtype=N''ST.MassUnit'' and enum2.enumcode=sn.imassunit +left join position p on SN.cposition=p.cposcode +left join vendor on SN.cvencode=vendor.cvencode +inner join warehouse w on SN.cwhcode=w.cwhcode +left join department d on d.cdepcode=r.cdepcode +left join person on person.cpersoncode=r.cpersoncode +left join vendor v on v.cvencode=r.cvencode +left join customer on r.ccuscode = customer.ccuscode +left join rd_style on r.crdcode = rd_style.crdcode +left join v_aa_enum enum1 on enum1.enumtype=N''ST.BusType'' and enum1.enumcode=r.cbustype +left join v_aa_enum enum3 on enum3.enumtype=N''ST.VouchType'' and enum3.enumcode=N''10'' +where 1=1 ' +exec (@chrSQL+@sWhere) + +--其他入库单 +set @chrSQL =N'insert into tempdb..'+@tmptableName +N' select r.id,r.cVouchType +,enum3.enumname as VouchType +,SN.cInvCode,I.cInvName,I.cInvAddCode,I.cInvStd,i.ccomunitcode,computationunit.ccomunitname as cinvm_unit +,SN.cFree1,SN.cFree2,SN.cFree3,SN.cFree4,SN.cFree5,SN.cFree6,SN.cFree7,SN.cFree8,SN.cFree9,SN.cFree10 +,I.cInvDefine1,I.cInvDefine2,I.cInvDefine3,I.cInvDefine4,I.cInvDefine5,I.cInvDefine6,I.cInvDefine7,I.cInvDefine8 +,I.cInvDefine9,I.cInvDefine10,I.cInvDefine11,I.cInvDefine12,I.cInvDefine13,I.cInvDefine14,I.cInvDefine15 +,I.cInvDefine16,I.iId,IC.cinvccode,IC.cinvcname,SN.cBatch,SN.dmdate,SN.imassunit,enum2.enumname as cmassunit +,sn.imassdate,SN.dvdate,SN.cincode,SN.cVenCode,vendor.cVenAbbName,SN.cWhCode,W.cWhName,SN.cposition,p.cposname +,SN.cinvsn,SN.cSNDefine1,SN.cSNDefine2,SN.cSNDefine3,SN.cSNDefine4,SN.cSNDefine5,SN.cSNDefine6,SN.cSNDefine7 +,SN.cSNDefine8,SN.cSNDefine9,SN.cSNDefine10,SN.cSNMemo +,case when isnull(rs.iquantity,0)<0 then N''0'' else N''1'' end as InOutTypeCode +,case when isnull(rs.iquantity,0)<0 then +(select top 1 EnumName from v_aa_enum where enumcode=N''0'' and enumtype=N''ST.InOutFlag'') +else +(select top 1 EnumName from v_aa_enum where enumcode=N''1'' and enumtype=N''ST.InOutFlag'') +end as InOutType +,r.ccode,r.ddate +,(select top 1 EnumName from v_aa_enum where enumcode= +(case when isnull(r.chandler,'''')='''' then N''4'' else N''1'' end) and enumtype=N''ST.VouchState'') as cstate +,r.cbustype,enum1.enumname as cbustypename,r.cdepcode,d.cdepname,r.cpersoncode,person.cpersonname +,r.cvencode as chvencode,v.cvenabbname as chvenabbname,r.ccuscode,customer.ccusabbname +,r.crdcode,rd_style.crdname,r.cmaker,r.chandler +from ST_SNDetail_OtherIN SN +inner join Inventory I on SN.cInvCode = I.cInvCode +inner join computationunit on I.ccomunitcode = computationunit.ccomunitcode +inner join inventoryclass IC on I.cinvccode=IC.cinvccode +left join rdrecords08 rs on SN.iVouchsid=rs.autoid +left join rdrecord08 r on rs.id=r.id and r.cvouchtype=N''08'' +left join v_aa_enum enum2 on enum2.enumtype=N''ST.MassUnit'' and enum2.enumcode=sn.imassunit +left join position p on SN.cposition=p.cposcode +left join vendor on SN.cvencode=vendor.cvencode +inner join warehouse w on SN.cwhcode=w.cwhcode +left join department d on d.cdepcode=r.cdepcode +left join person on person.cpersoncode=r.cpersoncode +left join vendor v on v.cvencode=r.cvencode +left join customer on r.ccuscode = customer.ccuscode +left join rd_style on r.crdcode = rd_style.crdcode +left join v_aa_enum enum1 on enum1.enumtype=N''ST.BusType'' and enum1.enumcode=r.cbustype +left join v_aa_enum enum3 on enum3.enumtype=N''ST.VouchType'' and enum3.enumcode=N''08'' +where 1=1 ' +exec (@chrSQL+@sWhere) + +--销售出库单 +set @chrSQL =N'insert into tempdb..'+@tmptableName +N' select r.id,r.cVouchType +,enum3.enumname as VouchType +,SN.cInvCode,I.cInvName,I.cInvAddCode,I.cInvStd,i.ccomunitcode,computationunit.ccomunitname as cinvm_unit +,SN.cFree1,SN.cFree2,SN.cFree3,SN.cFree4,SN.cFree5,SN.cFree6,SN.cFree7,SN.cFree8,SN.cFree9,SN.cFree10 +,I.cInvDefine1,I.cInvDefine2,I.cInvDefine3,I.cInvDefine4,I.cInvDefine5,I.cInvDefine6,I.cInvDefine7,I.cInvDefine8 +,I.cInvDefine9,I.cInvDefine10,I.cInvDefine11,I.cInvDefine12,I.cInvDefine13,I.cInvDefine14,I.cInvDefine15 +,I.cInvDefine16,I.iId,IC.cinvccode,IC.cinvcname,SN.cBatch,SN.dmdate,SN.imassunit,enum2.enumname as cmassunit +,sn.imassdate,SN.dvdate,SN.cincode,SN.cVenCode,vendor.cVenAbbName,SN.cWhCode,W.cWhName,SN.cposition,p.cposname +,SN.cinvsn,SN.cSNDefine1,SN.cSNDefine2,SN.cSNDefine3,SN.cSNDefine4,SN.cSNDefine5,SN.cSNDefine6,SN.cSNDefine7 +,SN.cSNDefine8,SN.cSNDefine9,SN.cSNDefine10,SN.cSNMemo +,case when isnull(rs.iquantity,0)>=0 then N''0'' else N''1'' end as InOutTypeCode +,case when isnull(rs.iquantity,0)>=0 then +(select top 1 EnumName from v_aa_enum where enumcode=N''0'' and enumtype=N''ST.InOutFlag'') +else +(select top 1 EnumName from v_aa_enum where enumcode=N''1'' and enumtype=N''ST.InOutFlag'') +end as InOutType +,r.ccode,r.ddate +,(select top 1 EnumName from v_aa_enum where enumcode= +(case when isnull(r.chandler,'''')='''' then N''4'' else N''1'' end) and enumtype=N''ST.VouchState'') as cstate +,r.cbustype,enum1.enumname as cbustypename,r.cdepcode,d.cdepname,r.cpersoncode,person.cpersonname +,r.cvencode as chvencode,v.cvenabbname as chvenabbname,r.ccuscode,customer.ccusabbname +,r.crdcode,rd_style.crdname,r.cmaker,r.chandler +from ST_SNDetail_SaleOut SN +inner join Inventory I on SN.cInvCode = I.cInvCode +inner join computationunit on I.ccomunitcode = computationunit.ccomunitcode +inner join inventoryclass IC on I.cinvccode=IC.cinvccode +left join rdrecords32 rs on SN.iVouchsid=rs.autoid +left join rdrecord32 r on rs.id=r.id and r.cvouchtype=N''32'' +left join v_aa_enum enum2 on enum2.enumtype=N''ST.MassUnit'' and enum2.enumcode=sn.imassunit +left join position p on SN.cposition=p.cposcode +left join vendor on SN.cvencode=vendor.cvencode +inner join warehouse w on SN.cwhcode=w.cwhcode +left join department d on d.cdepcode=r.cdepcode +left join person on person.cpersoncode=r.cpersoncode +left join vendor v on v.cvencode=r.cvencode +left join customer on r.ccuscode = customer.ccuscode +left join rd_style on r.crdcode = rd_style.crdcode +left join v_aa_enum enum1 on enum1.enumtype=N''ST.BusType'' and enum1.enumcode=r.cbustype +left join v_aa_enum enum3 on enum3.enumtype=N''ST.VouchType'' and enum3.enumcode=N''32'' +where 1=1 ' +exec (@chrSQL+@sWhere) + +--材料出库单 +set @chrSQL =N'insert into tempdb..'+@tmptableName +N' select r.id,r.cVouchType +,enum3.enumname as VouchType +,SN.cInvCode,I.cInvName,I.cInvAddCode,I.cInvStd,i.ccomunitcode,computationunit.ccomunitname as cinvm_unit +,SN.cFree1,SN.cFree2,SN.cFree3,SN.cFree4,SN.cFree5,SN.cFree6,SN.cFree7,SN.cFree8,SN.cFree9,SN.cFree10 +,I.cInvDefine1,I.cInvDefine2,I.cInvDefine3,I.cInvDefine4,I.cInvDefine5,I.cInvDefine6,I.cInvDefine7,I.cInvDefine8 +,I.cInvDefine9,I.cInvDefine10,I.cInvDefine11,I.cInvDefine12,I.cInvDefine13,I.cInvDefine14,I.cInvDefine15 +,I.cInvDefine16,I.iId,IC.cinvccode,IC.cinvcname,SN.cBatch,SN.dmdate,SN.imassunit,enum2.enumname as cmassunit +,sn.imassdate,SN.dvdate,SN.cincode,SN.cVenCode,vendor.cVenAbbName,SN.cWhCode,W.cWhName,SN.cposition,p.cposname +,SN.cinvsn,SN.cSNDefine1,SN.cSNDefine2,SN.cSNDefine3,SN.cSNDefine4,SN.cSNDefine5,SN.cSNDefine6,SN.cSNDefine7 +,SN.cSNDefine8,SN.cSNDefine9,SN.cSNDefine10,SN.cSNMemo +,case when isnull(rs.iquantity,0)>=0 then N''0'' else N''1'' end as InOutTypeCode +,case when isnull(rs.iquantity,0)>=0 then +(select top 1 EnumName from v_aa_enum where enumcode=N''0'' and enumtype=N''ST.InOutFlag'') +else +(select top 1 EnumName from v_aa_enum where enumcode=N''1'' and enumtype=N''ST.InOutFlag'') +end as InOutType +,r.ccode,r.ddate +,(select top 1 EnumName from v_aa_enum where enumcode= +(case when isnull(r.chandler,'''')='''' then N''4'' else N''1'' end) and enumtype=N''ST.VouchState'') as cstate +,r.cbustype,enum1.enumname as cbustypename,r.cdepcode,d.cdepname,r.cpersoncode,person.cpersonname +,r.cvencode as chvencode,v.cvenabbname as chvenabbname,r.ccuscode,customer.ccusabbname +,r.crdcode,rd_style.crdname,r.cmaker,r.chandler +from ST_SNDetail_MaOut SN +inner join Inventory I on SN.cInvCode = I.cInvCode +inner join computationunit on I.ccomunitcode = computationunit.ccomunitcode +inner join inventoryclass IC on I.cinvccode=IC.cinvccode +left join rdrecords11 rs on SN.iVouchsid=rs.autoid +left join rdrecord11 r on rs.id=r.id and r.cvouchtype=N''11'' +left join v_aa_enum enum2 on enum2.enumtype=N''ST.MassUnit'' and enum2.enumcode=sn.imassunit +left join position p on SN.cposition=p.cposcode +left join vendor on SN.cvencode=vendor.cvencode +inner join warehouse w on SN.cwhcode=w.cwhcode +left join department d on d.cdepcode=r.cdepcode +left join person on person.cpersoncode=r.cpersoncode +left join vendor v on v.cvencode=r.cvencode +left join customer on r.ccuscode = customer.ccuscode +left join rd_style on r.crdcode = rd_style.crdcode +left join v_aa_enum enum1 on enum1.enumtype=N''ST.BusType'' and enum1.enumcode=r.cbustype +left join v_aa_enum enum3 on enum3.enumtype=N''ST.VouchType'' and enum3.enumcode=N''11'' +where 1=1 ' +exec (@chrSQL+@sWhere) + +--其他出库单 +set @chrSQL =N'insert into tempdb..'+@tmptableName +N' select r.id,r.cVouchType +,enum3.enumname as VouchType +,SN.cInvCode,I.cInvName,I.cInvAddCode,I.cInvStd,i.ccomunitcode,computationunit.ccomunitname as cinvm_unit +,SN.cFree1,SN.cFree2,SN.cFree3,SN.cFree4,SN.cFree5,SN.cFree6,SN.cFree7,SN.cFree8,SN.cFree9,SN.cFree10 +,I.cInvDefine1,I.cInvDefine2,I.cInvDefine3,I.cInvDefine4,I.cInvDefine5,I.cInvDefine6,I.cInvDefine7,I.cInvDefine8 +,I.cInvDefine9,I.cInvDefine10,I.cInvDefine11,I.cInvDefine12,I.cInvDefine13,I.cInvDefine14,I.cInvDefine15 +,I.cInvDefine16,I.iId,IC.cinvccode,IC.cinvcname,SN.cBatch,SN.dmdate,SN.imassunit,enum2.enumname as cmassunit +,sn.imassdate,SN.dvdate,SN.cincode,SN.cVenCode,vendor.cVenAbbName,SN.cWhCode,W.cWhName,SN.cposition,p.cposname +,SN.cinvsn,SN.cSNDefine1,SN.cSNDefine2,SN.cSNDefine3,SN.cSNDefine4,SN.cSNDefine5,SN.cSNDefine6,SN.cSNDefine7 +,SN.cSNDefine8,SN.cSNDefine9,SN.cSNDefine10,SN.cSNMemo +,case when isnull(rs.iquantity,0)>=0 then N''0'' else N'''' end as InOutTypeCode +,case when isnull(rs.iquantity,0)>=0 then +(select top 1 EnumName from v_aa_enum where enumcode=N''0'' and enumtype=''ST.InOutFlag'') +else +(select top 1 EnumName from v_aa_enum where enumcode=N''1'' and enumtype=''ST.InOutFlag'') +end as InOutType +,r.ccode,r.ddate +,(select top 1 EnumName from v_aa_enum where enumcode= +(case when isnull(r.chandler,'''')='''' then N''4'' else N''1'' end) and enumtype=N''ST.VouchState'') as cstate +,r.cbustype,enum1.enumname as cbustypename,r.cdepcode,d.cdepname,r.cpersoncode,person.cpersonname +,r.cvencode as chvencode,v.cvenabbname as chvenabbname,r.ccuscode,customer.ccusabbname +,r.crdcode,rd_style.crdname,r.cmaker,r.chandler +from ST_SNDetail_OtherOut SN +inner join Inventory I on SN.cInvCode = I.cInvCode +inner join computationunit on I.ccomunitcode = computationunit.ccomunitcode +inner join inventoryclass IC on I.cinvccode=IC.cinvccode +left join rdrecords09 rs on SN.iVouchsid=rs.autoid +left join rdrecord09 r on rs.id=r.id and r.cvouchtype=N''09'' +left join v_aa_enum enum2 on enum2.enumtype=N''ST.MassUnit'' and enum2.enumcode=sn.imassunit +left join position p on SN.cposition=p.cposcode +left join vendor on SN.cvencode=vendor.cvencode +inner join warehouse w on SN.cwhcode=w.cwhcode +left join department d on d.cdepcode=r.cdepcode +left join person on person.cpersoncode=r.cpersoncode +left join vendor v on v.cvencode=r.cvencode +left join customer on r.ccuscode = customer.ccuscode +left join rd_style on r.crdcode = rd_style.crdcode +left join v_aa_enum enum1 on enum1.enumtype=N''ST.BusType'' and enum1.enumcode=r.cbustype +left join v_aa_enum enum3 on enum3.enumtype=N''ST.VouchType'' and enum3.enumcode=N''09'' +where 1=1 ' +exec (@chrSQL+@sWhere) + +--调拨单 +--调拨转入 +set @chrSQL =N'insert into tempdb..'+@tmptableName +N' select r.id,N''12'' as cVouchType +,(select top 1 EnumName from v_aa_enum where enumcode=N''12'' and enumtype=N''ST.VouchType'') as VouchType +,SN.cInvCode,I.cInvName,I.cInvAddCode,I.cInvStd,i.ccomunitcode,computationunit.ccomunitname as cinvm_unit +,SN.cFree1,SN.cFree2,SN.cFree3,SN.cFree4,SN.cFree5,SN.cFree6,SN.cFree7,SN.cFree8,SN.cFree9,SN.cFree10 +,I.cInvDefine1,I.cInvDefine2,I.cInvDefine3,I.cInvDefine4,I.cInvDefine5,I.cInvDefine6,I.cInvDefine7,I.cInvDefine8 +,I.cInvDefine9,I.cInvDefine10,I.cInvDefine11,I.cInvDefine12,I.cInvDefine13,I.cInvDefine14,I.cInvDefine15 +,I.cInvDefine16,I.iId,IC.cinvccode,IC.cinvcname,SN.cBatch,SN.dmdate,SN.imassunit,enum2.enumname as cmassunit +,sn.imassdate,SN.dvdate,SN.cincode,SN.cVenCode,vendor.cVenAbbName,SN.cinWhCode as cwhcode,W.cWhName,SN.cinposition as cposition,p.cposname +,SN.cinvsn,SN.cSNDefine1,SN.cSNDefine2,SN.cSNDefine3,SN.cSNDefine4,SN.cSNDefine5,SN.cSNDefine6,SN.cSNDefine7 +,SN.cSNDefine8,SN.cSNDefine9,SN.cSNDefine10,SN.cSNMemo +,N''1'' as InOutTypeCode +,(select top 1 EnumName from v_aa_enum where enumcode=N''1'' and enumtype=N''ST.InOutFlag'') as InOutType +,r.ctvcode as ccode,r.dtvdate as ddate +,(select top 1 EnumName from v_aa_enum where enumcode= +(case when isnull(r.cverifyperson,'''')='''' then N''4'' else N''1'' end) and enumtype=N''ST.VouchState'') as cstate +,null as cbustype,null as cbustypename,r.cidepcode,d.cdepname +,r.cpersoncode,person.cpersonname +,null as chvencode,null as chvenabbname,null as ccuscode,null as ccusabbname +,r.cirdcode as crdcode,rd_style.crdname,r.cmaker,r.cverifyperson as chandler +from ST_SNDetail_Tran SN +inner join Inventory I on SN.cInvCode = I.cInvCode +inner join computationunit on I.ccomunitcode = computationunit.ccomunitcode +inner join inventoryclass IC on I.cinvccode=IC.cinvccode +left join transvouchs rs on SN.iVouchsid=rs.autoid +left join transvouch r on rs.id=r.id +left join v_aa_enum enum2 on enum2.enumtype=N''ST.MassUnit'' and enum2.enumcode=sn.imassunit +left join position p on SN.cinposition=p.cposcode +left join vendor on SN.cvencode=vendor.cvencode +inner join warehouse w on SN.cinwhcode=w.cwhcode +left join department d on d.cdepcode=r.cidepcode +left join person on person.cpersoncode=r.cpersoncode +left join rd_style on r.cirdcode = rd_style.crdcode +where isnull(r.cverifyperson,'''')=''''' + +set @sTmpWhere = REPLACE(@sWhere,'SN.cposition','SN.cinposition') +set @sTmpWhere = REPLACE(@sWhere,'SN.cWhCode','SN.cinWhCode') + +exec (@chrSQL+@sTmpWhere) + +--调拨转出 +set @chrSQL =N'insert into tempdb..'+@tmptableName +N' select r.id,N''12'' as cVouchType +,(select top 1 EnumName from v_aa_enum where enumcode=N''12'' and enumtype=N''ST.VouchType'') as VouchType +,SN.cInvCode,I.cInvName,I.cInvAddCode,I.cInvStd,i.ccomunitcode,computationunit.ccomunitname as cinvm_unit +,SN.cFree1,SN.cFree2,SN.cFree3,SN.cFree4,SN.cFree5,SN.cFree6,SN.cFree7,SN.cFree8,SN.cFree9,SN.cFree10 +,I.cInvDefine1,I.cInvDefine2,I.cInvDefine3,I.cInvDefine4,I.cInvDefine5,I.cInvDefine6,I.cInvDefine7,I.cInvDefine8 +,I.cInvDefine9,I.cInvDefine10,I.cInvDefine11,I.cInvDefine12,I.cInvDefine13,I.cInvDefine14,I.cInvDefine15 +,I.cInvDefine16,I.iId,IC.cinvccode,IC.cinvcname,SN.cBatch,SN.dmdate,SN.imassunit,enum2.enumname as cmassunit +,sn.imassdate,SN.dvdate,SN.cincode,SN.cVenCode,vendor.cVenAbbName,SN.coutWhCode as cwhcode,W.cWhName,SN.coutposition as cposition,p.cposname +,SN.cinvsn,SN.cSNDefine1,SN.cSNDefine2,SN.cSNDefine3,SN.cSNDefine4,SN.cSNDefine5,SN.cSNDefine6,SN.cSNDefine7 +,SN.cSNDefine8,SN.cSNDefine9,SN.cSNDefine10,SN.cSNMemo +,N''0'' as InOutTypeCode +,(select top 1 EnumName from v_aa_enum where enumcode=N''0'' and enumtype=N''ST.InOutFlag'') as InOutType +,r.ctvcode as ccode,r.dtvdate as ddate +,(select top 1 EnumName from v_aa_enum where enumcode= +(case when isnull(r.cverifyperson,'''')='''' then N''4'' else N''1'' end) and enumtype=N''ST.VouchState'') as cstate +,null as cbustype,null as cbustypename,r.codepcode as cdepcode,d.cdepname +,r.cpersoncode,person.cpersonname +,null as chvencode,null as chvenabbname,null as ccuscode,null as ccusabbname +,r.cordcode as crdcode,rd_style.crdname,r.cmaker,r.cverifyperson as chandler +from ST_SNDetail_Tran SN +inner join Inventory I on SN.cInvCode = I.cInvCode +inner join computationunit on I.ccomunitcode = computationunit.ccomunitcode +inner join inventoryclass IC on I.cinvccode=IC.cinvccode +left join transvouchs rs on SN.iVouchsid=rs.autoid +left join transvouch r on rs.id=r.id +left join v_aa_enum enum2 on enum2.enumtype=N''ST.MassUnit'' and enum2.enumcode=sn.imassunit +left join position p on SN.coutposition=p.cposcode +left join vendor on SN.cvencode=vendor.cvencode +inner join warehouse w on SN.coutwhcode=w.cwhcode +left join department d on d.cdepcode=r.codepcode +left join person on person.cpersoncode=r.cpersoncode +left join rd_style on r.cordcode = rd_style.crdcode +where isnull(r.cverifyperson,'''')=''''' + +set @sTmpWhere = REPLACE(@sWhere,'SN.cposition','SN.coutposition') +set @sTmpWhere = REPLACE(@sWhere,'SN.cWhCode','SN.coutWhCode') + +exec (@chrSQL+@sTmpWhere) + +--不合格品记录单 +set @chrSQL =N'insert into tempdb..'+@tmptableName +N' select r.id,r.cVouchType +,enum3.enumname as VouchType +,SN.cInvCode,I.cInvName,I.cInvAddCode,I.cInvStd,i.ccomunitcode,computationunit.ccomunitname as cinvm_unit +,SN.cFree1,SN.cFree2,SN.cFree3,SN.cFree4,SN.cFree5,SN.cFree6,SN.cFree7,SN.cFree8,SN.cFree9,SN.cFree10 +,I.cInvDefine1,I.cInvDefine2,I.cInvDefine3,I.cInvDefine4,I.cInvDefine5,I.cInvDefine6,I.cInvDefine7,I.cInvDefine8 +,I.cInvDefine9,I.cInvDefine10,I.cInvDefine11,I.cInvDefine12,I.cInvDefine13,I.cInvDefine14,I.cInvDefine15 +,I.cInvDefine16,I.iId,IC.cinvccode,IC.cinvcname,SN.cBatch,SN.dmdate,SN.imassunit,enum2.enumname as cmassunit +,sn.imassdate,SN.dvdate,SN.cincode,SN.cVenCode,vendor.cVenAbbName,SN.cWhCode,W.cWhName,SN.cposition,p.cposname +,SN.cinvsn,SN.cSNDefine1,SN.cSNDefine2,SN.cSNDefine3,SN.cSNDefine4,SN.cSNDefine5,SN.cSNDefine6,SN.cSNDefine7 +,SN.cSNDefine8,SN.cSNDefine9,SN.cSNDefine10,SN.cSNMemo,N''1'' as InOutTypeCode +,(select top 1 EnumName from v_aa_enum where enumcode=N''1'' and enumtype=N''ST.InOutFlag'') as InOutType +,r.cspcode as ccode,r.ddate +,(select top 1 EnumName from v_aa_enum where enumcode= +(case when isnull(r.cverifyperson,'''')='''' then N''4'' else N''1'' end) and enumtype=N''ST.VouchState'') as cstate +,null as cbustype,null as cbustypename,r.cdepcode,d.cdepname,r.cpersoncode,person.cpersonname +,r.cvencode as chvencode,v.cvenabbname as chvenabbname,r.ccuscode,customer.ccusabbname +,r.cirdcode as crdcode,rd_style.crdname,r.cmaker,r.cverifyperson as chandler +from ST_SNDetail_QARecord SN +inner join Inventory I on SN.cInvCode = I.cInvCode +inner join computationunit on I.ccomunitcode = computationunit.ccomunitcode +inner join inventoryclass IC on I.cinvccode=IC.cinvccode +left join scrapvouchs rs on SN.iVouchsid=rs.autoid +left join scrapvouch r on rs.id=r.id and r.cvouchtype=N''45'' +left join v_aa_enum enum2 on enum2.enumtype=N''ST.MassUnit'' and enum2.enumcode=sn.imassunit +left join position p on SN.cposition=p.cposcode +left join vendor on SN.cvencode=vendor.cvencode +inner join warehouse w on SN.cwhcode=w.cwhcode +left join department d on d.cdepcode=r.cdepcode +left join person on person.cpersoncode=r.cpersoncode +left join vendor v on v.cvencode=r.cvencode +left join customer on r.ccuscode = customer.ccuscode +left join rd_style on r.cirdcode = rd_style.crdcode +left join v_aa_enum enum3 on enum3.enumtype=N''ST.VouchType'' and enum3.enumcode=N''45'' +where 1=1 ' +exec (@chrSQL+@sWhere) + +--不合格品处理单 +set @chrSQL =N'insert into tempdb..'+@tmptableName +N' select r.id,r.cVouchType +,enum3.enumname as VouchType +,SN.cInvCode,I.cInvName,I.cInvAddCode,I.cInvStd,i.ccomunitcode,computationunit.ccomunitname as cinvm_unit +,SN.cFree1,SN.cFree2,SN.cFree3,SN.cFree4,SN.cFree5,SN.cFree6,SN.cFree7,SN.cFree8,SN.cFree9,SN.cFree10 +,I.cInvDefine1,I.cInvDefine2,I.cInvDefine3,I.cInvDefine4,I.cInvDefine5,I.cInvDefine6,I.cInvDefine7,I.cInvDefine8 +,I.cInvDefine9,I.cInvDefine10,I.cInvDefine11,I.cInvDefine12,I.cInvDefine13,I.cInvDefine14,I.cInvDefine15 +,I.cInvDefine16,I.iId,IC.cinvccode,IC.cinvcname,SN.cBatch,SN.dmdate,SN.imassunit,enum2.enumname as cmassunit +,sn.imassdate,SN.dvdate,SN.cincode,SN.cVenCode,vendor.cVenAbbName,SN.cWhCode,W.cWhName,SN.cposition,p.cposname +,SN.cinvsn,SN.cSNDefine1,SN.cSNDefine2,SN.cSNDefine3,SN.cSNDefine4,SN.cSNDefine5,SN.cSNDefine6,SN.cSNDefine7 +,SN.cSNDefine8,SN.cSNDefine9,SN.cSNDefine10,SN.cSNMemo,N''0'' as InOutTypeCode +,(select top 1 EnumName from v_aa_enum where enumcode=N''0'' and enumtype=N''ST.InOutFlag'') as InOutType +,r.cspcode as ccode,r.ddate +,(select top 1 EnumName from v_aa_enum where enumcode= +(case when isnull(r.cverifyperson,'''')='''' then N''4'' else N''1'' end) and enumtype=N''ST.VouchState'') as cstate +,null as cbustype,null as cbustypename,r.cdepcode,d.cdepname,r.cpersoncode,person.cpersonname +,r.cvencode as chvencode,v.cvenabbname as chvenabbname,r.ccuscode,customer.ccusabbname +,r.cirdcode as crdcode,rd_style.crdname,r.cmaker,r.cverifyperson as chandler +from ST_SNDetail_QA SN +inner join Inventory I on SN.cInvCode = I.cInvCode +inner join computationunit on I.ccomunitcode = computationunit.ccomunitcode +inner join inventoryclass IC on I.cinvccode=IC.cinvccode +left join scrapvouchs rs on SN.iVouchsid=rs.autoid +left join scrapvouch r on rs.id=r.id and r.cvouchtype=N''46'' +left join v_aa_enum enum2 on enum2.enumtype=N''ST.MassUnit'' and enum2.enumcode=sn.imassunit +left join position p on SN.cposition=p.cposcode +left join vendor on SN.cvencode=vendor.cvencode +inner join warehouse w on SN.cwhcode=w.cwhcode +left join department d on d.cdepcode=r.cdepcode +left join person on person.cpersoncode=r.cpersoncode +left join vendor v on v.cvencode=r.cvencode +left join customer on r.ccuscode = customer.ccuscode +left join rd_style on r.cirdcode = rd_style.crdcode +left join v_aa_enum enum3 on enum3.enumtype=N''ST.VouchType'' and enum3.enumcode=N''46'' +where 1=1 ' +exec (@chrSQL+@sWhere) + +--货位调整单 +--货位调整前 +set @chrSQL =N'insert into tempdb..'+@tmptableName +N' select r.id,N''19'' as cVouchType +,(select top 1 EnumName from v_aa_enum where enumcode=N''19'' and enumtype=N''ST.VouchType'') as VouchType +,SN.cInvCode,I.cInvName,I.cInvAddCode,I.cInvStd,i.ccomunitcode,computationunit.ccomunitname as cinvm_unit +,SN.cFree1,SN.cFree2,SN.cFree3,SN.cFree4,SN.cFree5,SN.cFree6,SN.cFree7,SN.cFree8,SN.cFree9,SN.cFree10 +,I.cInvDefine1,I.cInvDefine2,I.cInvDefine3,I.cInvDefine4,I.cInvDefine5,I.cInvDefine6,I.cInvDefine7,I.cInvDefine8 +,I.cInvDefine9,I.cInvDefine10,I.cInvDefine11,I.cInvDefine12,I.cInvDefine13,I.cInvDefine14,I.cInvDefine15 +,I.cInvDefine16,I.iId,IC.cinvccode,IC.cinvcname,SN.cBatch,SN.dmdate,SN.imassunit,enum2.enumname as cmassunit +,sn.imassdate,SN.dvdate,SN.cincode,SN.cVenCode,vendor.cVenAbbName,SN.cWhCode,W.cWhName,SN.coutposition as cposition,p.cposname +,SN.cinvsn,SN.cSNDefine1,SN.cSNDefine2,SN.cSNDefine3,SN.cSNDefine4,SN.cSNDefine5,SN.cSNDefine6,SN.cSNDefine7 +,SN.cSNDefine8,SN.cSNDefine9,SN.cSNDefine10,SN.cSNMemo +,N''0'' as InOutTypeCode +,(select top 1 EnumName from v_aa_enum where enumcode=N''0'' and enumtype=N''ST.InOutFlag'') as InOutType +,r.cvouchcode as ccode,r.ddate +,(select top 1 EnumName from v_aa_enum where enumcode=N''4'' and enumtype=N''ST.VouchState'') as cstate,null as cbustype,null as cbustypename,r.cdepcode,d.cdepname +,r.cpersoncode,person.cpersonname +,null as chvencode,null as chvenabbname,null as ccuscode,null as ccusabbname +,null as crdcode,null as crdname,r.cmaker,null as chandler +from ST_SNDetail_InvPosAjust SN +inner join Inventory I on SN.cInvCode = I.cInvCode +inner join computationunit on I.ccomunitcode = computationunit.ccomunitcode +inner join inventoryclass IC on I.cinvccode=IC.cinvccode +left join AdjustPVouchs rs on SN.iVouchsid=rs.autoid +left join AdjustPVouch r on rs.id=r.id +left join v_aa_enum enum2 on enum2.enumtype=N''ST.MassUnit'' and enum2.enumcode=sn.imassunit +left join position p on SN.coutposition=p.cposcode +left join vendor on SN.cvencode=vendor.cvencode +inner join warehouse w on SN.cwhcode=w.cwhcode +left join department d on d.cdepcode=r.cdepcode +left join person on person.cpersoncode=r.cpersoncode +where 1=1 ' +set @sTmpWhere = REPLACE(@sWhere,'SN.cposition','SN.coutposition') +exec (@chrSQL+@sTmpWhere) + +--货位调整后 +set @chrSQL =N'insert into tempdb..'+@tmptableName +N' select r.id,N''19'' as cVouchType +,(select top 1 EnumName from v_aa_enum where enumcode=N''19'' and enumtype=N''ST.VouchType'') as VouchType +,SN.cInvCode,I.cInvName,I.cInvAddCode,I.cInvStd,i.ccomunitcode,computationunit.ccomunitname as cinvm_unit +,SN.cFree1,SN.cFree2,SN.cFree3,SN.cFree4,SN.cFree5,SN.cFree6,SN.cFree7,SN.cFree8,SN.cFree9,SN.cFree10 +,I.cInvDefine1,I.cInvDefine2,I.cInvDefine3,I.cInvDefine4,I.cInvDefine5,I.cInvDefine6,I.cInvDefine7,I.cInvDefine8 +,I.cInvDefine9,I.cInvDefine10,I.cInvDefine11,I.cInvDefine12,I.cInvDefine13,I.cInvDefine14,I.cInvDefine15 +,I.cInvDefine16,I.iId,IC.cinvccode,IC.cinvcname,SN.cBatch,SN.dmdate,SN.imassunit,enum2.enumname as cmassunit +,sn.imassdate,SN.dvdate,SN.cincode,SN.cVenCode,vendor.cVenAbbName,SN.cWhCode,W.cWhName,SN.cinposition as cposition,p.cposname +,SN.cinvsn,SN.cSNDefine1,SN.cSNDefine2,SN.cSNDefine3,SN.cSNDefine4,SN.cSNDefine5,SN.cSNDefine6,SN.cSNDefine7 +,SN.cSNDefine8,SN.cSNDefine9,SN.cSNDefine10,SN.cSNMemo +,N''1'' as InOutTypeCode +,(select top 1 EnumName from v_aa_enum where enumcode=N''1'' and enumtype=N''ST.InOutFlag'') as InOutType +,r.cvouchcode as ccode,r.ddate +,(select top 1 EnumName from v_aa_enum where enumcode=N''4'' and enumtype=N''ST.VouchState'') as cstate +,null as cbustype,null as cbustypename,r.cdepcode,d.cdepname +,r.cpersoncode,person.cpersonname +,null as chvencode,null as chvenabbname,null as ccuscode,null as ccusabbname +,null as crdcode,null as crdname,r.cmaker,null as chandler +from ST_SNDetail_InvPosAjust SN +inner join Inventory I on SN.cInvCode = I.cInvCode +inner join computationunit on I.ccomunitcode = computationunit.ccomunitcode +inner join inventoryclass IC on I.cinvccode=IC.cinvccode +left join AdjustPVouchs rs on SN.iVouchsid=rs.autoid +left join AdjustPVouch r on rs.id=r.id +left join v_aa_enum enum2 on enum2.enumtype=N''ST.MassUnit'' and enum2.enumcode=sn.imassunit +left join position p on SN.cinposition=p.cposcode +left join vendor on SN.cvencode=vendor.cvencode +inner join warehouse w on SN.cwhcode=w.cwhcode +left join department d on d.cdepcode=r.cdepcode +left join person on person.cpersoncode=r.cpersoncode +where 1=1 ' +set @sTmpWhere = REPLACE(@sWhere,'SN.cposition','SN.cinposition') +exec (@chrSQL+@sTmpWhere) + +--序列号调整 +set @chrSQL =N'insert into tempdb..'+@tmptableName +N' select r.id,N''SN10'' as cVouchType +,(select top 1 EnumName from v_aa_enum where enumcode=N''SN10'' and enumtype=N''ST.VouchType'') as VouchType +,SN.cInvCode,I.cInvName,I.cInvAddCode,I.cInvStd,i.ccomunitcode,computationunit.ccomunitname as cinvm_unit +,SN.cFree1,SN.cFree2,SN.cFree3,SN.cFree4,SN.cFree5,SN.cFree6,SN.cFree7,SN.cFree8,SN.cFree9,SN.cFree10 +,I.cInvDefine1,I.cInvDefine2,I.cInvDefine3,I.cInvDefine4,I.cInvDefine5,I.cInvDefine6,I.cInvDefine7,I.cInvDefine8 +,I.cInvDefine9,I.cInvDefine10,I.cInvDefine11,I.cInvDefine12,I.cInvDefine13,I.cInvDefine14,I.cInvDefine15 +,I.cInvDefine16,I.iId,IC.cinvccode,IC.cinvcname,SN.cBatch,SN.dmdate,SN.imassunit,enum2.enumname as cmassunit +,sn.imassdate,SN.dvdate,SN.cincode,SN.cVenCode,vendor.cVenAbbName,SN.cWhCode,W.cWhName,SN.cposition as cposition,p.cposname +,SN.cinvsn,SN.cSNDefine1,SN.cSNDefine2,SN.cSNDefine3,SN.cSNDefine4,SN.cSNDefine5,SN.cSNDefine6,SN.cSNDefine7 +,SN.cSNDefine8,SN.cSNDefine9,SN.cSNDefine10,SN.cSNMemo +,case when bpresn =1 then + case when ipostinvsnstate =''2'' or ipostinvsnstate=''6'' then N''1'' + when ipostinvsnstate=''10'' then '''' else ''0'' end + else + case when ipreinvsnstate =''2'' or ipreinvsnstate=''6'' then N''1'' + when ipreinvsnstate=''10'' then '''' else ''0'' end + end +as InOutTypeCode +,(select top 1 EnumName from v_aa_enum where enumcode=(case when bpresn =1 then + case when ipostinvsnstate =''2'' or ipostinvsnstate=''6'' then N''1'' + when isnpoststate=''10'' then '''' else ''0'' end + else + case when ipreinvsnstate =''2'' or ipreinvsnstate=''6'' then N''1'' + when ipreinvsnstate=''10'' then '''' else ''0'' end + end ) and enumtype=N''ST.InOutFlag'') as InOutType +,r.ccode as ccode,r.ddate +,(select top 1 EnumName from v_aa_enum where enumcode=N''4'' and enumtype=N''ST.VouchState'') as cstate +,null as cbustype,null as cbustypename,r.cdepcode,d.cdepname +,r.cpersoncode,person.cpersonname +,null as chvencode,null as chvenabbname,null as ccuscode,null as ccusabbname +,null as crdcode,null as crdname,r.cmaker,null as chandler +from v_ST_SNDetail_SNAdjVouch SN +inner join Inventory I on SN.cInvCode = I.cInvCode +inner join computationunit on I.ccomunitcode = computationunit.ccomunitcode +inner join inventoryclass IC on I.cinvccode=IC.cinvccode +left join ST_SNAdjustVouchs rs on SN.iVouchsid=rs.autoid +left join ST_SNAdjustVouch r on rs.id=r.id +left join v_aa_enum enum2 on enum2.enumtype=N''ST.MassUnit'' and enum2.enumcode=sn.imassunit +left join position p on SN.cposition=p.cposcode +left join vendor on SN.cvencode=vendor.cvencode +inner join warehouse w on SN.cwhcode=w.cwhcode +left join department d on d.cdepcode=r.cdepcode +left join person on person.cpersoncode=r.cpersoncode +where 1=1 ' +--set @sTmpWhere = REPLACE(@sWhere,'SN.cposition','SN.cinposition') +exec (@chrSQL+@sTmpWhere) + +--销售发货单 +set @chrSQL =N'insert into tempdb..'+@tmptableName +N' select r.dlid,r.cVouchType +,enum3.enumname as VouchType +,SN.cInvCode,I.cInvName,I.cInvAddCode,I.cInvStd,i.ccomunitcode,computationunit.ccomunitname as cinvm_unit +,SN.cFree1,SN.cFree2,SN.cFree3,SN.cFree4,SN.cFree5,SN.cFree6,SN.cFree7,SN.cFree8,SN.cFree9,SN.cFree10 +,I.cInvDefine1,I.cInvDefine2,I.cInvDefine3,I.cInvDefine4,I.cInvDefine5,I.cInvDefine6,I.cInvDefine7,I.cInvDefine8 +,I.cInvDefine9,I.cInvDefine10,I.cInvDefine11,I.cInvDefine12,I.cInvDefine13,I.cInvDefine14,I.cInvDefine15 +,I.cInvDefine16,I.iId,IC.cinvccode,IC.cinvcname,SN.cBatch,SN.dmdate,SN.imassunit,enum2.enumname as cmassunit +,sn.imassdate,SN.dvdate,SN.cincode,SN.cVenCode,vendor.cVenAbbName,SN.cWhCode,W.cWhName,SN.cposition,p.cposname +,SN.cinvsn,SN.cSNDefine1,SN.cSNDefine2,SN.cSNDefine3,SN.cSNDefine4,SN.cSNDefine5,SN.cSNDefine6,SN.cSNDefine7 +,SN.cSNDefine8,SN.cSNDefine9,SN.cSNDefine10,SN.cSNMemo +,NULL as InOutTypeCode +,NULL AS InOutType +,r.cdlcode,r.ddate +,(select top 1 EnumName from v_aa_enum where enumcode= +(case when isnull(r.cverifier,'''')='''' then N''4'' else N''1'' end) and enumtype=N''ST.VouchState'') as cstate +,r.cbustype,enum1.enumname as cbustypename,r.cdepcode,d.cdepname,r.cpersoncode,person.cpersonname +,Null as chvencode,Null as chvenabbname,r.ccuscode,customer.ccusabbname +, r.crdcode,rd_style.crdname,r.cmaker,r.cverifier +from SA_SNDetail_Disp SN +inner join Inventory I on SN.cInvCode = I.cInvCode +inner join computationunit on I.ccomunitcode = computationunit.ccomunitcode +inner join inventoryclass IC on I.cinvccode=IC.cinvccode +left join dispatchlists rs on SN.idlsid=rs.idlsid +left join dispatchlist r on rs.dlid=r.dlid +left join v_aa_enum enum2 on enum2.enumtype=N''ST.MassUnit'' and enum2.enumcode=sn.imassunit +left join position p on SN.cposition=p.cposcode +left join vendor on SN.cvencode=vendor.cvencode +inner join warehouse w on SN.cwhcode=w.cwhcode +left join department d on d.cdepcode=r.cdepcode +left join person on person.cpersoncode=r.cpersoncode + +left join customer on r.ccuscode = customer.ccuscode +left join rd_style on r.crdcode = rd_style.crdcode +left join v_aa_enum enum1 on enum1.enumtype=N''ST.BusType'' and enum1.enumcode=r.cbustype +left join v_aa_enum enum3 on enum3.enumtype=N''ST.VouchType'' and enum3.enumcode=isnull(r.cvouchtype,N''05'') +where 1=1 ' +exec (@chrSQL+@sWhere) +--升产订单 +set @chrSQL =N'insert into tempdb..'+@tmptableName +N' select r.moid,''MO'' +,enum3.enumname as VouchType +,SN.cInvCode,I.cInvName,I.cInvAddCode,I.cInvStd,i.ccomunitcode,computationunit.ccomunitname as cinvm_unit +,SN.cFree1,SN.cFree2,SN.cFree3,SN.cFree4,SN.cFree5,SN.cFree6,SN.cFree7,SN.cFree8,SN.cFree9,SN.cFree10 +,I.cInvDefine1,I.cInvDefine2,I.cInvDefine3,I.cInvDefine4,I.cInvDefine5,I.cInvDefine6,I.cInvDefine7,I.cInvDefine8 +,I.cInvDefine9,I.cInvDefine10,I.cInvDefine11,I.cInvDefine12,I.cInvDefine13,I.cInvDefine14,I.cInvDefine15 +,I.cInvDefine16,I.iId,IC.cinvccode,IC.cinvcname,SN.cBatch,SN.dmdate,SN.imassunit,enum2.enumname as cmassunit +,sn.imassdate,SN.dvdate,SN.cincode,SN.cVenCode,Null as cVenAbbName,Null as cWhCode,NUll as cWhName,SN.cposition,Null as cposname +,SN.cinvsn,SN.cSNDefine1,SN.cSNDefine2,SN.cSNDefine3,SN.cSNDefine4,SN.cSNDefine5,SN.cSNDefine6,SN.cSNDefine7 +,SN.cSNDefine8,SN.cSNDefine9,SN.cSNDefine10,SN.cSNMemo +,NULL as InOutTypeCode +,NULL AS InOutType +,r.mocode,r.CreateDate +,NUll as cstate +,Null as cbustype,Null cbustypename,dp.cdepcode,dp.cdepname,Null as cpersoncode,Null as cpersonname +,Null as chvencode,Null as chvenabbname,Null ccuscode,Null ccusabbname +, Null crdcode,Null as crdname,us.cUser_Name as cmaker,Null as cverifier +from mom_sndetail SN +inner join Inventory I on SN.cInvCode = I.cInvCode +inner join computationunit on I.ccomunitcode = computationunit.ccomunitcode +inner join inventoryclass IC on I.cinvccode=IC.cinvccode +left join mom_orderdetail rs on SN.ivouchsid=rs.modid +left join mom_order r on rs.moid=r.moid +left join ufsystem..ua_user us on us.cUser_Id =r.CreateUser +left join department dp on rs.MDeptCode=dp.cdepcode +left join v_aa_enum enum3 on enum3.enumtype=N''ST.Sotype'' and enum3.enumcode=''7'' +left join v_aa_enum enum2 on enum2.enumtype=N''ST.MassUnit'' and enum2.enumcode=sn.imassunit +where 1=1 ' +exec (@chrSQL+@sWhere) +--isnpoststate ,bpresn + +select InOutType,tb.cinvsn SN,COUNT(0) [COUNT] From tempdb..SP_ST_SNLSZ20210615 tb WHERE tb.cinvsn in (@SN) AND InOutType IS NOT NULL GROUP BY InOutType,tb.cinvsn "; } } diff --git a/NX.ERP.U8/Pmc/FinanceQuery.cs b/NX.ERP.U8/Pmc/FinanceQuery.cs index f099f5a..88d67f4 100644 --- a/NX.ERP.U8/Pmc/FinanceQuery.cs +++ b/NX.ERP.U8/Pmc/FinanceQuery.cs @@ -22,8 +22,8 @@ namespace NX.ERP.U8.Finance public IEnumerable InventorySNDetail(NX.ERP.Model.Request.SnOrderRequest info1) { string sql = $@" - select a.cInvCode,e.cInvName,b.cCode as Cprk, b.dDate as rkrq,c.cWhName, - b.cMPoCode,d.cDepName,a.cInvSN,k.iUnitCost, + select a.cInvCode,e.cInvName,b.cCode as Cprk, b.dDate as rkrq,c.cWhName, + b.cMPoCode,d.cDepName,a.cInvSN,a.csnmemo,k.iUnitCost, g.cCode as Clck,g.dDate as ckrq,h.cCusAbbName,f.cInvSN as ckcInvSN from ST_SNDetail_PROIN a WITH(NOLOCK) left join rdrecord10 b WITH(NOLOCK) on a.iVouchID=b.id diff --git a/NX.ERP.U8/Pmc/PmcQuery.cs b/NX.ERP.U8/Pmc/PmcQuery.cs index 5c3b83c..fd549bc 100644 --- a/NX.ERP.U8/Pmc/PmcQuery.cs +++ b/NX.ERP.U8/Pmc/PmcQuery.cs @@ -168,7 +168,7 @@ SELECT m..mocode,CONVERT(varchar(100), mor.StartDate, 23) as StartDate ,md.Rem mom_moallocate ma WITH (NOLOCK) ON md.MoDId = ma.MoDId left JOIN mom_motype motype WITH (NOLOCK) ON motype.MoTypeId = md.MoTypeId - INNER JOIN + left JOIN (SELECT ma.invcode, SUM(isnull(ma.qty, 0) - isnull(issqty, 0)) wqty FROM mom_moallocate ma WITH (NOLOCK) INNER JOIN mom_orderdetail md WITH (NOLOCK) ON ma.MoDId = md.MoDId @@ -199,12 +199,14 @@ SELECT m..mocode,CONVERT(varchar(100), mor.StartDate, 23) as StartDate ,md.Rem WHERE md.Status = 3 GROUP BY ma.InvCode) shwl ON ma.InvCode = shwl.InvCode LEFT JOIN - - (SELECT mom.MoCode, ma.invcode,round(SUM(isnull(ma.qty, 0))/md.Qty,3) dtty + (select a.MoCode ,a.InvCode ,a.MoDId ,(a.dtty/b.Qty) as dtty from ( + SELECT mom.MoCode, ma.invcode,round(SUM(isnull(ma.qty, 0)),3) dtty, md.MoDId FROM mom_moallocate ma WITH (NOLOCK) INNER JOIN mom_orderdetail md WITH (NOLOCK) ON ma.MoDId = md.MoDId left join - mom_order mom WITH (NOLOCK) on md.MoId=mom.MoId - GROUP BY ma.InvCode,mom.MoCode,md.Qty ) dtyl ON ma.InvCode = dtyl.InvCode and dtyl.MoCode=m.MoCode LEFT JOIN + mom_order mom WITH (NOLOCK) on md.MoId=mom.MoId + + GROUP BY ma.InvCode,mom.MoCode, md.MoDId ) a left join mom_orderdetail b WITH (NOLOCK) ON a.MoDId = b.MoDId ) dtyl ON ma.InvCode = dtyl.InvCode and dtyl.MoCode=m.MoCode and md.MoDId= dtyl.MoDId + LEFT JOIN (SELECT ma.invcode, SUM( isnull(issqty, 0)) issqty FROM mom_moallocate ma WITH (NOLOCK) INNER JOIN @@ -288,7 +290,7 @@ SELECT m..mocode,CONVERT(varchar(100), mor.StartDate, 23) as StartDate,md.Rema mom_moallocate ma WITH (NOLOCK) ON md.MoDId = ma.MoDId left JOIN mom_motype motype WITH (NOLOCK) ON motype.MoTypeId = md.MoTypeId - INNER JOIN + left JOIN (SELECT ma.invcode, SUM(isnull(ma.qty, 0) - isnull(issqty, 0)) wqty FROM mom_moallocate ma WITH (NOLOCK) INNER JOIN mom_orderdetail md WITH (NOLOCK) ON ma.MoDId = md.MoDId @@ -321,11 +323,14 @@ SELECT m..mocode,CONVERT(varchar(100), mor.StartDate, 23) as StartDate,md.Rema GROUP BY ma.InvCode) shwl ON ma.InvCode = shwl.InvCode LEFT JOIN - (SELECT mom.MoCode, ma.invcode,round(SUM(isnull(ma.qty, 0))/md.Qty,3) dtty + (select a.MoCode ,a.InvCode ,a.MoDId ,(a.dtty/b.Qty) as dtty from ( + SELECT mom.MoCode, ma.invcode,round(SUM(isnull(ma.qty, 0)),3) dtty, md.MoDId FROM mom_moallocate ma WITH (NOLOCK) INNER JOIN mom_orderdetail md WITH (NOLOCK) ON ma.MoDId = md.MoDId left join - mom_order mom WITH (NOLOCK) on md.MoId=mom.MoId - GROUP BY ma.InvCode,mom.MoCode,md.Qty ) dtyl ON ma.InvCode = dtyl.InvCode and dtyl.MoCode=m.MoCode LEFT JOIN + mom_order mom WITH (NOLOCK) on md.MoId=mom.MoId + + GROUP BY ma.InvCode,mom.MoCode, md.MoDId ) a left join mom_orderdetail b WITH (NOLOCK) ON a.MoDId = b.MoDId ) dtyl ON ma.InvCode = dtyl.InvCode and dtyl.MoCode=m.MoCode and md.MoDId= dtyl.MoDId + LEFT JOIN (SELECT ma.invcode, SUM( isnull(issqty, 0)) issqty FROM mom_moallocate ma WITH (NOLOCK) INNER JOIN diff --git a/NX.ERP.U8/Pmc/PurchaseQuery.cs b/NX.ERP.U8/Pmc/PurchaseQuery.cs index 8b3d188..dca6c95 100644 --- a/NX.ERP.U8/Pmc/PurchaseQuery.cs +++ b/NX.ERP.U8/Pmc/PurchaseQuery.cs @@ -211,7 +211,7 @@ namespace NX.ERP.U8.Purchase public IEnumerable Purchasesum(NX.ERP.Model.Request.PurchasesumRequest info) { string sql = $@" - DECLARE @RdRecord table( + DECLARE @RdRecord table( cPsn_Num nvarchar(30), cpersonname nvarchar(30), puappnumall int, @@ -259,7 +259,7 @@ namespace NX.ERP.U8.Purchase (SELECT iAppIds, sum(iquantity) AS qty FROM PO_Podetails WITH (nolock) GROUP BY iAppIds) rds ON isnull(ommds.autoid,'') = isnull(rds.iAppIds,'') - WHERE ISNULL(OMM.cCloser, N'') = N'' AND ISNULL(ommds.cbCloser, N'') = N'' AND ISNULL(ommds.cbCloser, N'') = N'' AND ISNULL(rds.qty, 0)=0 and ommds.iReceivedQTY=0 and + WHERE ISNULL(OMM.cCloser, N'') = N'' AND ISNULL(ommds.cbCloser, N'') = N'' AND ISNULL(omm.cverifier, N'') <> N'' AND ISNULL(rds.qty, 0)=0 and ommds.iReceivedQTY=0 and ommds.fquantity - ISNULL(rds.qty, 0) > 0) OM GROUP BY cInvCode ) as tbl1 @@ -273,11 +273,15 @@ namespace NX.ERP.U8.Purchase as tbl on tbl1.cinvcode=tbl.cInvCode ) q group by cPsn_Num - update a set a.puappnumall=b.puappnumall From @RdRecord a left join @RdRecord2 b on a.cpersonname =b.cpersonname + update a set a.cpersonname=b.receive From @RdRecord2 a left join CGBB2021_0001_E001 b WITH (NOLOCK) on a.cpersonname =b.quit + where b.quit is not null - update a set a.puappnumall= a.puappnumall +b.puappnumall From @RdRecord a left join ( + update a set a.puappnumall=isnull(b.puappnumall,0) From @RdRecord a left join + (select cpersonname,sum(puappnumall) as puappnumall from @RdRecord2 group by cpersonname ) b on a.cpersonname =b.cpersonname + + update a set a.puappnumall= isnull(a.puappnumall,0) +isnull(b.puappnumall,0) From @RdRecord a left join ( select '其他' as cpersonname ,sum(puappnumall) as puappnumall from @RdRecord2 where cpersonname not in (select cpersonname From @RdRecord) )b on a.cpersonname =b.cpersonname - where a.cpersonname='其他' + where a.cpersonname='其他' insert into @RdRecord3 select cPsn_Num,sum(RQTY3) as puappnumall from ( @@ -291,7 +295,7 @@ namespace NX.ERP.U8.Purchase (SELECT iAppIds, sum(iquantity) AS qty FROM PO_Podetails WITH (nolock) GROUP BY iAppIds) rds ON isnull(ommds.autoid,'') = isnull(rds.iAppIds,'') - WHERE ISNULL(OMM.cCloser, N'') = N'' AND ISNULL(ommds.cbCloser, N'') = N'' AND ISNULL(ommds.cbCloser, N'') = N'' AND ISNULL(rds.qty, 0)=0 and ommds.iReceivedQTY=0 and DATEDIFF(day,ddate ,GETDATE()) >=3 and + WHERE ISNULL(OMM.cCloser, N'') = N'' AND ISNULL(ommds.cbCloser, N'') = N'' AND ISNULL(omm.cverifier, N'') <> N'' AND ISNULL(rds.qty, 0)=0 and ommds.iReceivedQTY=0 and DATEDIFF(day,ddate ,GETDATE()) >=3 and ommds.fquantity - ISNULL(rds.qty, 0) > 0) OM GROUP BY cInvCode ) as tbl1 @@ -305,9 +309,13 @@ namespace NX.ERP.U8.Purchase as tbl on tbl1.cinvcode=tbl.cInvCode ) q group by cPsn_Num - update a set a.puappnum03=b.puappnumall From @RdRecord a left join @RdRecord3 b on a.cpersonname =b.cpersonname + update a set a.cpersonname=b.receive From @RdRecord3 a left join CGBB2021_0001_E001 b WITH (NOLOCK) on a.cpersonname =b.quit + where b.quit is not null - update a set a.puappnum03= a.puappnum03 +b.puappnumall From @RdRecord a left join ( + update a set a.puappnum03=isnull(b.puappnumall,0) From @RdRecord a left join + (select cpersonname,sum(puappnumall) as puappnumall from @RdRecord3 group by cpersonname) b on a.cpersonname =b.cpersonname + + update a set a.puappnum03= isnull(a.puappnum03,0) +isnull(b.puappnumall,0) From @RdRecord a left join ( select '其他' as cpersonname ,sum(puappnumall) as puappnumall from @RdRecord3 where cpersonname not in (select cpersonname From @RdRecord) )b on a.cpersonname =b.cpersonname where a.cpersonname='其他' @@ -342,10 +350,14 @@ namespace NX.ERP.U8.Purchase as tbl on tbl1.cinvcode=tbl.cInvCode ) q group by cPsn_Num + update a set a.cpersonname=b.receive From @RdRecord4 a left join CGBB2021_0001_E001 b WITH (NOLOCK) on a.cpersonname =b.quit + where b.quit is not null - update a set a.mommouth02=b.puappnumall From @RdRecord a left join @RdRecord4 b on a.cpersonname =b.cpersonname + update a set a.mommouth02=isnull(b.puappnumall,0) From @RdRecord a left join + (select cpersonname,sum(puappnumall) as puappnumall from @RdRecord4 group by cpersonname + ) b on a.cpersonname =b.cpersonname - update a set a.mommouth02= a.mommouth02 +b.mommouth02 From @RdRecord a left join ( + update a set a.mommouth02= isnull(a.mommouth02,0) +isnull(b.mommouth02,0) From @RdRecord a left join ( select '其他' as cpersonname ,sum(puappnumall) as mommouth02 from @RdRecord4 where cpersonname not in (select cpersonname From @RdRecord) )b on a.cpersonname =b.cpersonname where a.cpersonname='其他' @@ -379,21 +391,27 @@ namespace NX.ERP.U8.Purchase as tbl on tbl1.cinvcode=tbl.cInvCode ) q group by cPsn_Num - + update a set a.cpersonname=b.receive From @RdRecord5 a left join CGBB2021_0001_E001 b WITH (NOLOCK) on a.cpersonname =b.quit + where b.quit is not null - update a set a.mommouth04=b.puappnumall From @RdRecord a left join @RdRecord5 b on a.cpersonname =b.cpersonname + update a set a.mommouth04=isnull(b.puappnumall,0) From @RdRecord a left join ( + select cpersonname,sum(puappnumall) as puappnumall from @RdRecord5 group by cpersonname) b on a.cpersonname =b.cpersonname - update a set a.mommouth04= a.mommouth04 +b.mommouth04 From @RdRecord a left join ( + update a set a.mommouth04= isnull(a.mommouth04,0) +isnull(b.mommouth04,0) From @RdRecord a left join ( select '其他' as cpersonname ,sum(puappnumall) as mommouth04 from @RdRecord5 where cpersonname not in (select cpersonname From @RdRecord) )b on a.cpersonname =b.cpersonname where a.cpersonname='其他' + + delete from @RdRecord where cpersonname in (select quit from CGBB2021_0001_E001) + select *from @RdRecord + "; @@ -407,8 +425,24 @@ namespace NX.ERP.U8.Purchase public IEnumerable Purchasesumpuapp(NX.ERP.Model.Request.PurchasesumRequest info) { string sql = $@" - select *from ( - SELECT omm.ccode, CONVERT(varchar(100), omm.ddate, 23) as dDatel, omm.ddate ,ommds.cInvCode,ommds.cinvname, ommds.cinvstd,ommds.fquantity - ISNULL(rds.qty, 0) as RQTY,isnull(f.cMaker,'其他') as cMaker + IF EXISTS (SELECT NAME FROM tempdb..SYSOBJECTS WHERE NAME ='tablepuapp20210625' AND Xtype='U') DROP Table tempdb..tablepuapp20210625 + create table tempdb..tablepuapp20210625 ( + ccode nvarchar(200), + dDatel nvarchar(200), + ddate datetime, + cInvCode nvarchar(200), + cinvname nvarchar(500), + cinvstd nvarchar(500), + RQTY decimal(28, 6), + cMaker nvarchar(200) + ) +CREATE INDEX IX_test ON tempdb..tablepuapp20210625 (cinvcode) + + + insert into tempdb..tablepuapp20210625 + + select *from ( + SELECT omm.ccode, CONVERT(varchar(100), omm.ddate, 23) as dDatel, omm.ddate ,ommds.cInvCode,ommds.cinvname, ommds.cinvstd,ommds.fquantity - ISNULL(rds.qty, 0) as RQTY,isnull(isnull(k.receive ,f.cMaker),'其他') as cMaker FROM pu_AppHead omm WITH (nolock) INNER JOIN pu_appbody ommds WITH (nolock) ON omm.id = ommds.id LEFT JOIN (SELECT iAppIds, sum(iquantity) AS qty @@ -417,8 +451,15 @@ namespace NX.ERP.U8.Purchase left join (select cInvCode,cMaker from ( select cInvCode,ROW_NUMBER() over( partition by b.cInvCode order by a.poid desc) as rownumber ,a.cMaker from PO_Pomain a WITH (nolock), PO_Podetails b WITH (nolock) where a.poid=b.poid) as c where c.rownumber=1) f on ommds.cInvCode =f.cInvCode - WHERE ISNULL(OMM.cCloser, N'') = N'' AND ISNULL(ommds.cbCloser, N'') = N'' AND ISNULL(ommds.cbCloser, N'') = N'' AND ISNULL(rds.qty, 0)=0 and ommds.iReceivedQTY=0 AND - ommds.fquantity - ISNULL(rds.qty, 0) > 0 ) puu + left join CGBB2021_0001_E001 k WITH (NOLOCK) on f.cMaker =k.quit + WHERE ISNULL(OMM.cCloser, N'') = N'' AND ISNULL(ommds.cbCloser, N'') = N'' AND ISNULL(omm.cverifier, N'') <> N'' AND ISNULL(rds.qty, 0)=0 and ommds.iReceivedQTY=0 AND + ommds.fquantity - ISNULL(rds.qty, 0) > 0 ) puapp + + update tempdb..tablepuapp20210625 set cmaker='其他' where cMaker not in ( select cPsn_Name from hr_v_HR31_show WITH (NOLOCK) where cDepCode ='52' and rEmployState ='在职') + and cMaker not in (select quit from CGBB2021_0001_E001 WITH (NOLOCK)) + + + select *From tempdb..tablepuapp20210625 puu "; List where = new List(); @@ -453,8 +494,9 @@ namespace NX.ERP.U8.Purchase public IEnumerable Purchasesummom(NX.ERP.Model.Request.PurchasesumRequest info) { string sql = $@" - DECLARE @RdRecord table( - CINVCODE nvarchar(200), + IF EXISTS (SELECT NAME FROM tempdb..SYSOBJECTS WHERE NAME ='tablemom20210625' AND Xtype='U') DROP Table tempdb..tablemom20210625 + create table tempdb..tablemom20210625 ( + CINVCODE nvarchar(200), RQTY int, iqty int, iQuantity int, @@ -462,10 +504,12 @@ namespace NX.ERP.U8.Purchase cpersonname nvarchar(200), cInvName nvarchar(200), cInvStd nvarchar(500) - ) - insert into @RdRecord + ) + + + insert into tempdb..tablemom20210625 select *from ( - select a.*,isnull(f.cMaker,'其他') as cpersonname ,inv.cInvName,inv.cInvStd from ( + select a.*,isnull(isnull(k.receive ,f.cMaker),'其他') as cpersonname ,inv.cInvName,inv.cInvStd from ( select a.InvCode as CINVCODE ,1 as RQTY , iqty,cur.iQuantity, (cur.iQuantity-iqty) as bull From ( SELECT ma.invcode, SUM(isnull(ma.qty, 0) - isnull(issqty, 0)) iqty FROM mom_moallocate ma WITH (NOLOCK) INNER JOIN @@ -480,12 +524,14 @@ namespace NX.ERP.U8.Purchase ) a left join (select cInvCode,cMaker from ( select cInvCode,ROW_NUMBER() over( partition by b.cInvCode order by a.poid desc) as rownumber ,a.cMaker from PO_Pomain a WITH (NOLOCK), PO_Podetails b WITH (NOLOCK) where a.poid=b.poid) as c where c.rownumber=1) f on a.CINVCODE=f.cInvCode + left join CGBB2021_0001_E001 k WITH (NOLOCK) on f.cMaker =k.quit left join Inventory inv WITH (NOLOCK) on a.CINVCODE=inv.cInvCode )pumo - update @RdRecord set cpersonname ='其他' where cpersonname not in ( select cPsn_Name from hr_v_HR31_show where cDepCode ='52' and rEmployState ='在职') + update tempdb..tablemom20210625 set cpersonname ='其他' where cpersonname not in ( select cPsn_Name from hr_v_HR31_show WITH (NOLOCK) where cDepCode ='52' and rEmployState ='在职') + and cpersonname not in (select quit from CGBB2021_0001_E001 WITH (NOLOCK)) - select *From @RdRecord + select *From tempdb..tablemom20210625 "; List where = new List(); diff --git a/NX.ERP.U8/Pmc/WarehouseQuery.cs b/NX.ERP.U8/Pmc/WarehouseQuery.cs index b70a559..0d834a6 100644 --- a/NX.ERP.U8/Pmc/WarehouseQuery.cs +++ b/NX.ERP.U8/Pmc/WarehouseQuery.cs @@ -51,7 +51,7 @@ select a.id AS ArrivalId,a.cCode as ArrivalCode,a.cpersoncode,a.cpersonname,A.c , PO_Podetails C WITH (NOLOCK) Where ( (1>0) AND (1>0) ) AND ( 1>0 ) and (isnull(cbustype,'')<>'委外加工') -- and ( isnull (b.cInvCode,'')=isnull(Pos.cInvCode,'')) - And (1=1) and isnull(b.cbcloser,N'')=N'' And isnull(a.cverifier,'')<>'' and a.id=b.id and b.cinvcode=inventory.cinvcode1 and B.iPOsID = C.ID + And (1=1) and isnull(b.cbcloser,N'')=N'' and a.id=b.id and b.cinvcode=inventory.cinvcode1 and B.iPOsID = C.ID And a.iBillType =N'0' and isnull(b.bGsp,N'')=N'0' and (isnull(b.iQuantity,0)-isnull(b.fRefuseQuantity,0)>isnull(b.fValidInQuan,0) or (b.igrouptype=2 and isnull(b.inum,0)-isnull(b.frefusenum,0)>isnull(b.fvalidinnum,0))) and isnull(a.bStorageArrivalOrder,1)=1 and 1=1 diff --git a/NX.ERP.U8/Store/MaterialAppDAL.cs b/NX.ERP.U8/Store/MaterialAppDAL.cs index d6fe8f8..b80b5ee 100644 --- a/NX.ERP.U8/Store/MaterialAppDAL.cs +++ b/NX.ERP.U8/Store/MaterialAppDAL.cs @@ -45,7 +45,7 @@ namespace NX.ERP.U8.Store headXml.setAttribute("cDepCode", param.DepCode); headXml.setAttribute("cMaker", param.Maker); headXml.setAttribute("cPersonCode", param.PersonCode); - Model.MOM.MomOrder Order = null; + Model.MOM.MomOrder Order = null; if (param.source == "生产订单") { Order = new Mom.MomOrderDAL().GetModel(param.SourceCode); @@ -251,5 +251,113 @@ FROM MaterialAppVouch a } + + + + /// + /// 根据领料单号查询 带库位 + /// + /// + /// + public IEnumerable GetModelAndPost(string OrderCode, string invCode) + { + if (!string.IsNullOrEmpty(OrderCode) && !string.IsNullOrEmpty(invCode)) + { + return this.GetListAndPost(" MA.cCode=@OrderCode AND MAS.cInvCode = @invCode ", new { OrderCode, invCode }); + } + else + if (!string.IsNullOrEmpty(OrderCode)) + { + + return this.GetListAndPost(" MA.cCode=@OrderCode", new { OrderCode }); + + } + else if (!string.IsNullOrEmpty(invCode)) + { + return this.GetListAndPost(" MAS.cInvCode = @invCode ", new { invCode }); + } + else + { + return this.GetListAndPost(); + } + } + + /// + /// 查询领料信息 带库位 + /// + /// + /// + /// + public IEnumerable GetListAndPost(string strWhere = null, object Params = null) + { + var strSQL = @"SELECT + MA.cCode AS AppVouchOrderNo,--领料申请单号 + MAS.cInvCode MaterialCode,--物料编码 + INV.cInvName MaterialName,--物料名称 + INV.cInvStd MaterialSpec,--物料规格 + UNT.cComUnitName Unit,--单位 + MAS.iQuantity Qty,--数量 + CONVERT(varchar(100), MA.dDate, 23) DemandDate,--需求日期 + wh.cWhName WarehouseName,--仓库名称 + MAS.cpesocode ProductOrderNo,--生产单号 + MAS.ipesoseq ProductOrderLineNo,--生产单行号 + MAS.invcode ProductCode,--产品编码, + PDT.cInvName ProductName,--产品名称 + PDT.cInvStd ProductSpec,--产品规格 + POST.cPosName [Position]--库位 + +FROM + MaterialAppVouch MA + LEFT JOIN MaterialAppVouchs MAS ON MA.ID = MAS.ID + LEFT JOIN Inventory INV ON MAS.cInvCode = INV.cInvCode + LEFT JOIN Warehouse wh ON WH.cwhcode = MAS.cwhcode + LEFT JOIN ComputationUnit UNT ON INV.ccomunitcode = UNT.ccomunitcode + LEFT JOIN Inventory PDT ON MAS.invcode = PDT.cInvCode + LEFT JOIN ( + SELECT + cinvcode, + STUFF( + ( + SELECT + ',' + cPosName + FROM + ( + SELECT + b.cPosName, + a.cInvCode, + a.iQuantity + FROM + InvPositionSum a WITH ( NOLOCK ), + POSITION b WITH ( NOLOCK ) + WHERE + a.iQuantity <> 0 + AND a.cPosCode= b.cPosCode + ) a + WHERE + b.cinvcode = a.cinvcode + ORDER BY + a.iQuantity DESC FOR XML PATH ( '' ) + ), + 1, + 1, + '' + ) cPosName + FROM + InvPositionSum b + GROUP BY + cinvcode + ) AS post ON INV.cinvcode = post.cinvcode + WHERE MAS.iQuantity > ISNULL(MAS.foutquantity,0) +"; + if (!string.IsNullOrEmpty(strWhere)) + { + strSQL += $" AND {strWhere} "; + } + using (var conn = U8LoginContext.Instance.Connection) + { + var list = conn.Query(strSQL, Params); + return list; + } + } } } diff --git a/NX.ERP.WebAPi/Controllers/Store/MaterialAppController.cs b/NX.ERP.WebAPi/Controllers/Store/MaterialAppController.cs index ba73b84..81e48ed 100644 --- a/NX.ERP.WebAPi/Controllers/Store/MaterialAppController.cs +++ b/NX.ERP.WebAPi/Controllers/Store/MaterialAppController.cs @@ -34,7 +34,7 @@ namespace NX.ERP.WebAPi.Controllers.Store - [Obsolete] + [Route("api/MaterialApp/Model")] [HttpGet] @@ -45,6 +45,15 @@ namespace NX.ERP.WebAPi.Controllers.Store } + [Route("api/MaterialApp/ListAndPost")] + [HttpPost] + public IEnumerable GetModelAndPost(Model.Response.Store.MaterialAppVouchAndPostName req) + { + var dal = new NX.ERP.U8.Store.MaterialAppDAL(); + return dal.GetModelAndPost(req.AppVouchOrderNo, req.MaterialCode); + } + + [Obsolete] [Route("api/MaterialApp/ListByMoCode")] [HttpGet] diff --git a/NX.ERP.WebAPi/Web.config b/NX.ERP.WebAPi/Web.config index 04952c3..cede30a 100644 --- a/NX.ERP.WebAPi/Web.config +++ b/NX.ERP.WebAPi/Web.config @@ -6,9 +6,9 @@ - - - + + + diff --git a/NX.ERP.Webapp/package-lock.json b/NX.ERP.Webapp/package-lock.json index 41308c8..dfb0736 100644 --- a/NX.ERP.Webapp/package-lock.json +++ b/NX.ERP.Webapp/package-lock.json @@ -11710,9 +11710,9 @@ } }, "vue-loader-v16": { - "version": "npm:vue-loader@16.2.0", - "resolved": "https://registry.nlark.com/vue-loader/download/vue-loader-16.2.0.tgz", - "integrity": "sha1-BGpTMI3Ufljv4g3ewe3sAnzjtG4=", + "version": "npm:vue-loader@16.4.0", + "resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-16.4.0.tgz", + "integrity": "sha512-oySoEgEedGw0jz2czEOdb6sycQ2PPyzUmF8Yclj1NTpoTVHGCYCQaGf+jsvxhdDVfhOnDLjkRzT2fLpGOrVPjg==", "dev": true, "optional": true, "requires": { @@ -11723,8 +11723,8 @@ "dependencies": { "ansi-styles": { "version": "4.3.0", - "resolved": "https://registry.nlark.com/ansi-styles/download/ansi-styles-4.3.0.tgz?cache=0&sync_timestamp=1618995625950&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fansi-styles%2Fdownload%2Fansi-styles-4.3.0.tgz", - "integrity": "sha1-7dgDYornHATIWuegkG7a00tkiTc=", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", "dev": true, "optional": true, "requires": { @@ -11732,9 +11732,9 @@ } }, "chalk": { - "version": "4.1.1", - "resolved": "https://registry.nlark.com/chalk/download/chalk-4.1.1.tgz?cache=0&sync_timestamp=1618995297666&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fchalk%2Fdownload%2Fchalk-4.1.1.tgz", - "integrity": "sha1-yAs/qyi/Y3HmhjMl7uZ+YYt35q0=", + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", "dev": true, "optional": true, "requires": { @@ -11744,8 +11744,8 @@ }, "color-convert": { "version": "2.0.1", - "resolved": "https://registry.npm.taobao.org/color-convert/download/color-convert-2.0.1.tgz", - "integrity": "sha1-ctOmjVmMm9s68q0ehPIdiWq9TeM=", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", "dev": true, "optional": true, "requires": { @@ -11754,22 +11754,22 @@ }, "color-name": { "version": "1.1.4", - "resolved": "https://registry.npm.taobao.org/color-name/download/color-name-1.1.4.tgz", - "integrity": "sha1-wqCah6y95pVD3m9j+jmVyCbFNqI=", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true, "optional": true }, "has-flag": { "version": "4.0.0", - "resolved": "https://registry.nlark.com/has-flag/download/has-flag-4.0.0.tgz?cache=0&sync_timestamp=1618847009337&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fhas-flag%2Fdownload%2Fhas-flag-4.0.0.tgz", - "integrity": "sha1-lEdx/ZyByBJlxNaUGGDaBrtZR5s=", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", "dev": true, "optional": true }, "loader-utils": { "version": "2.0.0", - "resolved": "https://registry.npm.taobao.org/loader-utils/download/loader-utils-2.0.0.tgz", - "integrity": "sha1-5MrOW4FtQloWa18JfhDNErNgZLA=", + "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.0.tgz", + "integrity": "sha512-rP4F0h2RaWSvPEkD7BLDFQnvSf+nK+wr3ESUjNTyAGobqrijmW92zc+SO6d4p4B1wh7+B/Jg1mkQe5NYUEHtHQ==", "dev": true, "optional": true, "requires": { @@ -11780,8 +11780,8 @@ }, "supports-color": { "version": "7.2.0", - "resolved": "https://registry.npm.taobao.org/supports-color/download/supports-color-7.2.0.tgz?cache=0&sync_timestamp=1618560998281&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fsupports-color%2Fdownload%2Fsupports-color-7.2.0.tgz", - "integrity": "sha1-G33NyzK4E4gBs+R4umpRyqiWSNo=", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", "dev": true, "optional": true, "requires": { diff --git a/NX.ERP.Webapp/src/App.vue b/NX.ERP.Webapp/src/App.vue index c513de7..1f991a6 100644 --- a/NX.ERP.Webapp/src/App.vue +++ b/NX.ERP.Webapp/src/App.vue @@ -26,7 +26,7 @@ 到货单 异常单据查询 - + 领料单查询 diff --git a/NX.ERP.Webapp/src/api/materialAppVouch.js b/NX.ERP.Webapp/src/api/materialAppVouch.js new file mode 100644 index 0000000..208582c --- /dev/null +++ b/NX.ERP.Webapp/src/api/materialAppVouch.js @@ -0,0 +1,6 @@ +import axios from 'axios' + +//查询领料列表带库位 +export const getListAndPost = (info) => { + return axios.post('/api/MaterialApp/ListAndPost', info) +} \ No newline at end of file diff --git a/NX.ERP.Webapp/src/route/index.js b/NX.ERP.Webapp/src/route/index.js index 86e652f..4971ddf 100644 --- a/NX.ERP.Webapp/src/route/index.js +++ b/NX.ERP.Webapp/src/route/index.js @@ -10,6 +10,7 @@ import inventorypoc from '@/views/inventory-poc.vue' import Purchasesum from '@/views/Purchasesum.vue' import inventoryrrival from '@/bill/inventory-arrival.vue' import inventoryerror from '@/bill/inventory-error.vue' +import inventoryMaterialAppVouch from '@/views/inventory-materialAppVouch.vue' export default [ { @@ -29,4 +30,5 @@ export default [ { path: '/Purchasesum', component: Purchasesum }, { path: '/inventoryrrival', component: inventoryrrival }, { path: '/inventoryerror', component: inventoryerror }, + { path: '/inventoryMaterialAppVouch', component: inventoryMaterialAppVouch }, ] diff --git a/NX.ERP.Webapp/src/views/inventory-SNDetail.vue b/NX.ERP.Webapp/src/views/inventory-SNDetail.vue index ebc2ee9..9b258a2 100644 --- a/NX.ERP.Webapp/src/views/inventory-SNDetail.vue +++ b/NX.ERP.Webapp/src/views/inventory-SNDetail.vue @@ -170,6 +170,11 @@ export default { align: "center", key: "iUnitCost", }, + { + title: "备注", + align: "center", + key: "csnmemo", + }, { title: "出库库单号", align: "center", diff --git a/NX.ERP.Webapp/src/views/inventory-materialAppVouch.vue b/NX.ERP.Webapp/src/views/inventory-materialAppVouch.vue new file mode 100644 index 0000000..5cf0757 --- /dev/null +++ b/NX.ERP.Webapp/src/views/inventory-materialAppVouch.vue @@ -0,0 +1,485 @@ + + + + + + + diff --git a/NX.ERP.Webapp/src/views/inventory-mom.vue b/NX.ERP.Webapp/src/views/inventory-mom.vue index 9888e57..653398e 100644 --- a/NX.ERP.Webapp/src/views/inventory-mom.vue +++ b/NX.ERP.Webapp/src/views/inventory-mom.vue @@ -50,6 +50,18 @@ +
+ + + + + + + + + + +
+ - - + + + + + + + + diff --git a/U8Test/Store/APVouchTest.cs b/U8Test/Store/APVouchTest.cs new file mode 100644 index 0000000..52d483e --- /dev/null +++ b/U8Test/Store/APVouchTest.cs @@ -0,0 +1,22 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using NX.ERP.U8.Store; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NX.ERP.U8.Store.Tests +{ + [TestClass()] + public class APVouchTest + { + [TestMethod()] + public void GetListAndPostNameTest() + { + var ap = new NX.ERP.U8.Store.MaterialAppDAL(); + ap.GetListAndPost(); + //Assert.Fail(); + } + } +} \ No newline at end of file diff --git a/U8Test/U8Test.csproj b/U8Test/U8Test.csproj index 350fc6b..f667165 100644 --- a/U8Test/U8Test.csproj +++ b/U8Test/U8Test.csproj @@ -57,8 +57,10 @@ + +