Files
U8-Import/NX.ERP.U8/MES/MesLogic.cs

996 lines
56 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
2021-06-11 12:48:07 +08:00
using Dapper;
namespace NX.ERP.U8.MES
{
public class MesLogic
{
2021-06-16 10:05:13 +08:00
/// <summary>
///
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
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)
{
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<string, int>();
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 ";
}
}