using ICSSoft.Common;
using ICSSoft.Entity;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NFine.Code;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
using System.Xml.Linq;
namespace ICSSoft.DataProject
{
///
/// 使用中
/// 提交业务处理
///
public class ICSSubmitService
{
private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static string connString = System.Configuration.ConfigurationManager.AppSettings["ConnStr"];
private static string enableCode = "";
private static string excessQtySql = "";
#region 源头单据信息
///
/// 源头单据信息
///
///
///
public static DataTable TransInformationGet(WMSSourceDocumentModel JsonData)
{
var language = LanguageHelper.GetName("WMSAPIInfo");
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
string sql = string.Empty;
string arrivalCtrlSql = string.Empty;
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
try
{
if (string.IsNullOrEmpty(JsonData.TransCode))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
}
else if (string.IsNullOrEmpty(JsonData.TransType))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
}
else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
}
else if (string.IsNullOrEmpty(JsonData.WorkPoint))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
}
string TransType = JsonData.TransType;
//string enableCode = "";
//string excessQtySql = "";
#region SLQ
string sqlCheck = @"
--判断源头单据是否存在
IF NOT EXISTS(SELECT a.ID FROM {1} WHERE {6})
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo035") + @"',16,1);
RETURN
END
";
//销售发货绑定快递单号不验证单据是否完成
//if (TransType != TransTypeEnum.SalesBindCourierDoc.GetDescription())
//{
// sqlCheck += @"--判断源头单据是否已完成
// IF NOT EXISTS(SELECT a.ID FROM {1} WHERE {7})
// BEGIN
// RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo535"), JsonData.TransCode) + @"',16,1);
// RETURN
// END
// ";
//}
//查询是否需要去除单据中已发完明细
string excludeSql = @"DECLARE @ExcludeEnable BIT
SET @ExcludeEnable=(SELECT Enable FROM ICSConfiguration WHERE Code='excludeInvDelivered' and workpoint='{0}')";
excludeSql = string.Format(excludeSql, JsonData.WorkPoint);
if (TransType == TransTypeEnum.ASN.GetDescription() || TransType == TransTypeEnum.OASN.GetDescription())
{
sql = @"SELECT a.ID,
{0}
convert(varchar(100),'') AS LocationCode,
convert(varchar(100),'') AS LotNo,
convert(varchar(10),'') AS ToWarehouseCode,
0 AS LocationQty,
0 AS isMatched,
a.InvCode,
inv.InvName,
inv.InvStd,
inv.EATTRIBUTE4 AS module,
a.Quantity,
inv.InvUnit,
a.Amount,
--a.WHCode,
inv.AmountUnit,
--wh.WarehouseName AS WHName,
ISNULL(ext.ProjectCode, '') AS ProjectCode,
a.ExtensionID,
--CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
ISNULL(ext.Version, '') AS Version,
ISNULL(ext.Brand, '') AS Brand,
ISNULL(ext.cFree1, '') AS cFree1,
ISNULL(ext.cFree2, '') AS cFree2,
ISNULL(ext.cFree3, '') AS cFree3,
ISNULL(ext.cFree4, '') AS cFree4,
ISNULL(ext.cFree5, '') AS cFree5,
ISNULL(ext.cFree6, '') AS cFree6,
ISNULL(ext.cFree7, '') AS cFree7,
ISNULL(ext.cFree8, '') AS cFree8,
ISNULL(ext.cFree9, '') AS cFree9,
ISNULL(ext.cFree10, '') AS cFree10,
a.MUSER AS [User],
a.MTIME AS [MTime]
{4}
FROM {1}
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
--LEFT JOIN ICSWarehouse wh ON a.WHCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
--LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WHCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE {2}
Order By asn.Sequence ASC";
if (JsonData.IsInspect == 1)
{
//海格采购、委外检验需判断送货单是否到货
//整单检验时,需判断是否存在已经入库条码
if (TransType == TransTypeEnum.ASN.GetDescription())
{
sqlCheck += string.Format(@"
IF NOT EXISTS (SELECT 1 FROM ICSASN a
INNER JOIN ICSDeliveryNotice b ON b.ASNCode=a.ASNCode AND b.WorkPoint=a.WorkPoint AND b.DNType='1'
WHERE a.ASNCode='{0}' AND a.WorkPoint='{1}')
BEGIN
RAISERROR('送货单{0}未到货!',16,1)
RETURN
END
", JsonData.TransCode, JsonData.WorkPoint);
if (JsonData.IsEntire == 1)
{
sqlCheck += sqlCheck += string.Format(@"
IF EXISTS(
SELECT 1
FROM ICSWareHouseLotInfo a
INNER JOIN ICSASNDetail b ON b.LotNo=a.LotNo AND b.WorkPoint=a.WorkPoint
WHERE b.ASNCode='{0}' AND b.WorkPoint='{1}'
)
BEGIN
RAISERROR('送货单{0}存在已经入库的条码,无法整单检验,请选择单条码检验',16,1)
END
", JsonData.TransCode, JsonData.WorkPoint);
}
}
else if (TransType == TransTypeEnum.OASN.GetDescription())
{
sqlCheck += string.Format(@"
IF NOT EXISTS (SELECT 1 FROM ICSOASN a
INNER JOIN ICSODeliveryNotice b ON b.OASNCode=a.OASNCode AND b.WorkPoint=a.WorkPoint AND b.ODNType='1'
WHERE a.OASNCode='{0}' AND a.WorkPoint='{1}')
BEGIN
RAISERROR('委外送货单{0}未到货!',16,1)
RETURN
END
", JsonData.TransCode, JsonData.WorkPoint);
if (JsonData.IsEntire == 1)
{
sqlCheck += sqlCheck += string.Format(@"
IF EXISTS(
SELECT 1
FROM ICSWareHouseLotInfo a
INNER JOIN ICSOASNDetail b ON b.LotNo=a.LotNo AND b.WorkPoint=a.WorkPoint
WHERE b.OASNCode='{0}' AND b.WorkPoint='{1}'
)
BEGIN
RAISERROR('委外送货单{0}存在已经入库的条码,无法整单检验,请选择单条码检验',16,1)
END
", JsonData.TransCode, JsonData.WorkPoint);
}
}
}
}
else if (TransType == TransTypeEnum.RTTwoStepTransferDocIn.GetDescription())
{
sql = @"SELECT a.ID,
{0}
convert(varchar(100),'') AS LocationCode,
convert(varchar(100),'') AS LotNo,
convert(varchar(10),'') AS ToWarehouseCode,
0 AS LocationQty,
0 AS isMatched,
a.InvCode,
inv.InvName,
inv.InvStd,
inv.EATTRIBUTE4 AS module,
a.Quantity,
inv.InvUnit,
a.Amount,
a.ToWarehouseCode AS WHCode,
inv.AmountUnit,
wh.WarehouseName AS WHName,
(select a.F_EnabledMark from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_id='4f733e37-445b-4534-8ec0-9f88d0842381') AS TransEnable,
ISNULL(ext.ProjectCode, '') AS ProjectCode,
a.ExtensionID,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
ISNULL(ext.Version, '') AS Version,
ISNULL(ext.Brand, '') AS Brand,
ISNULL(ext.cFree1, '') AS cFree1,
ISNULL(ext.cFree2, '') AS cFree2,
ISNULL(ext.cFree3, '') AS cFree3,
ISNULL(ext.cFree4, '') AS cFree4,
ISNULL(ext.cFree5, '') AS cFree5,
ISNULL(ext.cFree6, '') AS cFree6,
ISNULL(ext.cFree7, '') AS cFree7,
ISNULL(ext.cFree8, '') AS cFree8,
ISNULL(ext.cFree9, '') AS cFree9,
ISNULL(ext.cFree10, '') AS cFree10,
a.MUSER AS [User],
a.MTIME AS [MTime]
FROM {1}
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSWarehouse wh ON a.ToWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE {2} ";
}
else if (TransType == TransTypeEnum.JHMOIssueDoc.GetDescription())
{
sql = @"SELECT DISTINCT TOP 1 a.ID,
{0}
convert(varchar(100),'') AS LocationCode,
convert(varchar(100),'') AS LotNo,
convert(varchar(10),'') AS ToWarehouseCode,
0 AS LocationQty,
0 AS isMatched,
a.InvCode,
inv.InvName,
inv.InvStd,
inv.EATTRIBUTE4 AS module,
'9999' AS Quantity,
inv.InvUnit,
a.Amount,
a.WHCode,
inv.AmountUnit,
wh.WarehouseName AS WHName,
(select a.F_EnabledMark from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_id='4f733e37-445b-4534-8ec0-9f88d0842381') AS TransEnable,
ISNULL(ext.ProjectCode, '') AS ProjectCode,
a.ExtensionID,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
ISNULL(ext.Version, '') AS Version,
ISNULL(ext.Brand, '') AS Brand,
ISNULL(ext.cFree1, '') AS cFree1,
ISNULL(ext.cFree2, '') AS cFree2,
ISNULL(ext.cFree3, '') AS cFree3,
ISNULL(ext.cFree4, '') AS cFree4,
ISNULL(ext.cFree5, '') AS cFree5,
ISNULL(ext.cFree6, '') AS cFree6,
ISNULL(ext.cFree7, '') AS cFree7,
ISNULL(ext.cFree8, '') AS cFree8,
ISNULL(ext.cFree9, '') AS cFree9,
ISNULL(ext.cFree10, '') AS cFree10,
ISNULL(inv.EATTRIBUTE1, '') AS EATTRIBUTE1,
a.MUSER AS [User],
a.MTIME AS [MTime]
{4}
FROM {1}
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSWarehouse wh ON a.WHCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WHCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE {2} {5} ";
}
else
{
sql = @"SELECT DISTINCT a.ID,
{0}
convert(varchar(100),'') AS LocationCode,
convert(varchar(100),'') AS LotNo,
convert(varchar(10),'') AS ToWarehouseCode,
0 AS LocationQty,
0 AS isMatched,
a.InvCode,
inv.InvName,
inv.InvStd,
inv.EATTRIBUTE4 AS module,
a.Quantity,
inv.InvUnit,
a.Amount,
a.WHCode,
inv.AmountUnit,
wh.WarehouseName AS WHName,
(select a.F_EnabledMark from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_id='4f733e37-445b-4534-8ec0-9f88d0842381') AS TransEnable,
ISNULL(ext.ProjectCode, '') AS ProjectCode,
a.ExtensionID,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
ISNULL(ext.Version, '') AS Version,
ISNULL(ext.Brand, '') AS Brand,
ISNULL(ext.cFree1, '') AS cFree1,
ISNULL(ext.cFree2, '') AS cFree2,
ISNULL(ext.cFree3, '') AS cFree3,
ISNULL(ext.cFree4, '') AS cFree4,
ISNULL(ext.cFree5, '') AS cFree5,
ISNULL(ext.cFree6, '') AS cFree6,
ISNULL(ext.cFree7, '') AS cFree7,
ISNULL(ext.cFree8, '') AS cFree8,
ISNULL(ext.cFree9, '') AS cFree9,
ISNULL(ext.cFree10, '') AS cFree10,
ISNULL(inv.EATTRIBUTE1, '') AS EATTRIBUTE1,
a.MUSER AS [User],
a.MTIME AS [MTime]
{4}
FROM {1}
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSWarehouse wh ON a.WHCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WHCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE {2} {5} ";
}
string Picksql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
c.Code,
c.InvCode,
c.InvName,
c.InvStd,
c.InvUnit,
FLOOR(c.iQuantity) AS iQuantity,
d.WarehouseCode,
d.LocationCode,
d.LotNO,
FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
CONVERT(varchar(100),d.MTIME, 23) MTIME,
FLOOR(f.QTYTotal) QTYTotal INTO #temp
FROM
({0}) c
LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND ((LEN(ISNULL(c.WHCode,''))<=0) OR (LEN(ISNULL(c.WHCode,''))>0) AND c.WhCode=d.WarehouseCode) AND d.WorkPoint='{1}' AND d.Quantity>0
left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{1}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
DECLARE @ItemCode VARCHAR(50),
@QTY DECIMAL(18,3),
@ItemCodeCurrent VARCHAR(50),
@QTYCurrent DECIMAL(18,3),
@iQuantityCurrent DECIMAL(18,3),
@CanDelete BIT,
@Row INT,
@rowCurrent INT
SET @Row = @@rowcount
SET @rowCurrent=1
SET @CanDelete=0
SET @ItemCode=''
WHILE @rowCurrent<=@Row
BEGIN
SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
PRINT(@rowCurrent)
IF @ItemCode<>@ItemCodeCurrent
BEGIN
SET @ItemCode=@ItemCodeCurrent
SET @QTY=0
SET @CanDelete=0
END
IF @CanDelete=1
BEGIN
DELETE FROM #temp WHERE rowNo=@rowCurrent
SET @rowCurrent += 1
CONTINUE
END
SET @QTY += @QTYCurrent
IF @QTY>=@iQuantityCurrent
BEGIN
SET @CanDelete=1
END
SET @rowCurrent += 1
END
SELECT * FROM #temp
DROP TABLE #temp
";
#endregion
bool isDeliveryNotice = false; //送货、到货、含委外
string columns = string.Empty; //查询源头单据表的特殊列名
string tableName = string.Empty; //查询源头单据表名
string where = string.Empty; //查询源头单据的过滤条件
string singleWhere = string.Empty; //判断源头单据是否存在的过滤条件
string completeWhere = string.Empty; //判断单据是否已完成的过滤条件
string invWhere = ""; //查询特殊物料要求的过滤条件
bool isMerge = false; //合并发料
string columnsMerge = string.Empty; //合并发料查询源头单据表的特殊列名
string tableNameMerge = string.Empty; //合并发料查询源头单据表名
string sqls = string.Empty;
string sqlCheckSign = "";
string isRTOut = "0";
string isPN = "0";
string whcode = "";
string EATTRIBUTE = "";
DataTable flag = null;
#region 检料表信息
//enableCode = "";
//excessQtySql = "";
if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
{
enableCode = "Over001";
excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
#region 工单备料sql
sqls = @" SELECT
c.MOCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
b.InvUnit,
a.ExtensionID
FROM
ICSMOPick a
inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.JHMOIssueDoc.GetDescription())
{
enableCode = "Over001";
excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
#region 工单备料sql
sqls = @" SELECT
c.MOCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
b.InvUnit,
a.ExtensionID
FROM
ICSMOPick a
inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.MOApply.GetDescription())
{
enableCode = "Over002";
excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
#region 工单领料SQL
sqls = @" select
a.ApplyCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
FROM
ICSMOApply a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.MOIssue.GetDescription())
{
enableCode = "Over003";
excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
#region 工单材料出库SQL
sqls = @" select
a.IssueCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
FROM
ICSMOIssue a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription() || TransType == TransTypeEnum.RTOutsourcingIssueDoc.GetDescription())
{
enableCode = "Over004";
excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
#region 委外备料SQL
sqls = @" select
c.OOCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
FROM
ICSOOPick a
left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.OOApply.GetDescription())
{
enableCode = "Over005";
excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
#region 委外领料SQL
sqls = @" select
a.ApplyCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
FROM
ICSOApply a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.OOIssue.GetDescription())
{
//enableCode = "Over006";
excessQtySql = "";
#region 委外材料出库SQL
sqls = @" select
a.IssueCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
FROM
ICSOIssue a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
{
enableCode = "";
excessQtySql = "";
#region 销售发货SQL
sqls = @" select
a.SDNCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
FROM
ICSSDN a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
{
enableCode = "";
excessQtySql = "";
#region 其它出库SQL
sqls = @" select
a.OutCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
FROM
ICSOtherOut a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
{
enableCode = "";
excessQtySql = "";
#region 借用SQL
sqls = @"select
a.BrrowCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
FROM
ICSBrrow a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
{
enableCode = "";
excessQtySql = "";
#region 物料调拨
sqls = @" select
a.TransferNO as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.FromWarehouseCode as WhCode,
a.ExtensionID
FROM
ICSTransfer a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
{
enableCode = "";
excessQtySql = "";
#region 两步调出
sqls = @"select
a.OutCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WHCode ,
a.ExtensionID
from ICSOtherOut a
INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID";
#endregion
}
#endregion
#region 出库
#region 采购退货
if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
{
isDeliveryNotice = true;
columns = @"a.DNCode AS TransCode,
a.DNDetailID AS DetailID,
a.DNType AS Type,
a.Sequence AS TransSequence,
ISNULL(a.RCVQuantity,0) AS IssueQuantity,
a.Quantity,
a.Amount,
a.MUSER AS [User],
a.MTIME AS [MTime],";
tableName = @"ICSDeliveryNotice a ";
where = @" a.DNCode='{0}' AND a.WorkPoint='{1}' AND a.DNType='2' AND a.Status<>'3'";
singleWhere = @" a.DNCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.DNCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.RCVQuantity,0)";
}
#region 采购退货(采购订单)
else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegativePo.GetDescription())
{
isDeliveryNotice = true;
columns = @"a.DNCode AS TransCode,
a.DNDetailID AS DetailID,
a.DNType AS Type,
a.Sequence AS TransSequence,
isnull(a.Quantity,0) - isnull(a.RCVQuantity,0) AS IssueQuantity,
a.Quantity,
a.Amount,
a.MUSER AS [User],
a.MTIME AS [MTime],";
tableName = @"ICSDeliveryNotice a ";
where = @" a.DNCode='{0}' AND a.WorkPoint='{1}' AND a.DNType='1' AND a.Status<>'3'";
singleWhere = @" a.DNCode='{0}' AND a.WorkPoint='{1}'";
}
#endregion
#endregion
#region 工单关联
else if (TransType == TransTypeEnum.ICSMOReceive.GetDescription())
{
isDeliveryNotice = true;
columns = @"a.MOCode AS TransCode,
a.Sequence AS TransSequence,";
tableName = @"ICSMO a ";
where = @" a.MOCode='{0}' AND a.WorkPoint='{1}' and a.ERPStatus<>'3'";
singleWhere = @" a.MOCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.MOCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.RCVQuantity,0)";
}
#endregion
#region 委外发料(合并发料)
else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription() || TransType == TransTypeEnum.RTOutsourcingIssueDoc.GetDescription())
{
if (JsonData.IsRTOut == "1")
{
isRTOut = "1";
}
else
{
isRTOut = "0";
}
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode004' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+b.OOCode AS TransCode,
a.PickID AS DetailID,
a.SupplyType AS Type,
b.Sequence+'~'+a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSOOPick a
INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"b.OOCode AS TransCode,
a.PickID AS DetailID,
a.SupplyType AS Type,
b.Sequence+'~'+a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableName = @"ICSOOPick a
INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint ";
where = @" b.OOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.Status<>'3' and isnull(a.EATTRIBUTE1,'')<>'1' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
singleWhere = @" b.OOCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.OOCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.IssueQuantity,0)";
}
#endregion
#region 委外退货
else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
{
isDeliveryNotice = true;
columns = @"a.ODNCode AS TransCode,
a.ODNDetailID AS DetailID,
a.ODNType AS Type,
a.Sequence AS TransSequence,
ISNULL(a.RCVQuantity,0) AS IssueQuantity,
a.Quantity,
a.Amount,
a.MUSER AS [User],
a.MTIME AS [MTime],";
tableName = @"ICSODeliveryNotice a ";
where = @" a.ODNCode='{0}' AND a.WorkPoint='{1}' AND a.ODNType='2' AND a.Status<>'3'";
singleWhere = @" a.ODNCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.ODNCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.RCVQuantity,0)";
}
#endregion
#region 委外退货(委外采购订单)
else if (TransType == TransTypeEnum.OutsourcingReturnBackPo.GetDescription())
{
isDeliveryNotice = true;
columns = @"a.ODNCode AS TransCode,
a.ODNDetailID AS DetailID,
a.ODNType AS Type,
a.Sequence AS TransSequence,
a.Quantity - ISNULL(a.RCVQuantity,0) AS IssueQuantity,
a.Quantity,
a.Amount,
a.MUSER AS [User],
a.MTIME AS [MTime],";
tableName = @"ICSODeliveryNotice a ";
where = @" a.ODNCode='{0}' AND a.WorkPoint='{1}' AND a.ODNType='1' AND a.Status<>'3'";
singleWhere = @" a.ODNCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.ODNCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.RCVQuantity,0)";
}
#endregion
#region 生产发料(合并发料)
else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode001' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+b.MOCode AS TransCode,
a.PickID AS DetailID,
a.SupplyType AS Type,
b.Sequence+'~'+a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"b.MOCode AS TransCode,
a.PickID AS DetailID,
a.SupplyType AS Type,
b.Sequence+'~'+a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,
ISNULL(a.EATTRIBUTE3, isnull(A.Quantity,0)) as DHexcessQty,";
tableName = @"ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint ";
where = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1'
AND ((@ExcludeEnable=1 AND dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{2}', 2, 2,'')-ISNULL(a.IssueQuantity,0)>0) OR (@ExcludeEnable=0 OR @ExcludeEnable IS NULL)) ";
invWhere = DBHelper.SearchConditonGet("Trans_btnInvOut", JsonData.User, cmd);
//海格仓库领料
if (JsonData.DepType != null && JsonData.DepType == "W") { invWhere += @" and (isnull(inv.EATTRIBUTE12,'') ='False') "; }//and isnull(inv.EATTRIBUTE11,'') ='0'
//海格生产领料
else if (JsonData.DepType != null && JsonData.DepType == "P") { invWhere += @" and ( isnull(inv.EATTRIBUTE12,'') ='True') "; }//and (isnull(inv.EATTRIBUTE11,'') ='0'
singleWhere = @" b.MOCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.IssueQuantity,0)";
#region 锐腾杂发控制线边仓发料
DataTable rtdt = null;
string rtsql = @"select a.F_ItemCode,a.F_Define1 from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_id='d51a7d1a-cc8a-4b8e-b306-d4ef3a108549' and a.F_EnabledMark='1' AND a.F_ItemCode='{0}'";
rtsql = string.Format(rtsql, JsonData.User);
rtdt = DBHelper.SQlReturnData(rtsql, cmd);
if (rtdt != null && rtdt.Rows.Count > 0)
{
for (int i = 0; i < rtdt.Rows.Count; i++)
{
whcode = rtdt.Rows[i]["F_Define1"].ToString();
}
}
if (whcode != "")
{
where = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1' and a.WHCode in ({2})";
}
#endregion
}
#endregion
#region 生产发料(合并发料)金豪表外领料
else if (TransType == TransTypeEnum.JHMOIssueDoc.GetDescription())
{
//金豪表外领料 无子件领料
string ssql = @"select a.id from ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
where b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1' ";
ssql = string.Format(ssql, JsonData.TransCode, JsonData.WorkPoint);
DataTable dtt = DBHelper.SQlReturnData(ssql, cmd);
if (dtt.Rows.Count == 0 || dtt == null)
{
sqlCheck = @"
--判断源头单据是否存在
IF NOT EXISTS(SELECT a.ID FROM {1} WHERE {2})
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo035") + @"',16,1);
RETURN
END
";
sql = @"SELECT DISTINCT a.ID,
{0}
convert(varchar(100),'') AS LocationCode,
convert(varchar(100),'') AS LotNo,
convert(varchar(10),'') AS ToWarehouseCode,
0 AS LocationQty,
0 AS isMatched,
a.InvCode,
inv.InvName,
inv.InvStd,
inv.EATTRIBUTE4 AS module,
'9999' AS Quantity,
'9999' AS ExcessQty,
0 AS IssueQuantity,
inv.InvUnit,
inv.AmountUnit,
(select a.F_EnabledMark from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_id='4f733e37-445b-4534-8ec0-9f88d0842381') AS TransEnable,
ISNULL(ext.ProjectCode, '') AS ProjectCode,
a.ExtensionID,
ISNULL(ext.BatchCode, '') AS BatchCode,
ISNULL(ext.Version, '') AS Version,
ISNULL(ext.Brand, '') AS Brand,
ISNULL(ext.cFree1, '') AS cFree1,
ISNULL(ext.cFree2, '') AS cFree2,
ISNULL(ext.cFree3, '') AS cFree3,
ISNULL(ext.cFree4, '') AS cFree4,
ISNULL(ext.cFree5, '') AS cFree5,
ISNULL(ext.cFree6, '') AS cFree6,
ISNULL(ext.cFree7, '') AS cFree7,
ISNULL(ext.cFree8, '') AS cFree8,
ISNULL(ext.cFree9, '') AS cFree9,
ISNULL(ext.cFree10, '') AS cFree10,
ISNULL(inv.EATTRIBUTE1, '') AS EATTRIBUTE1,
a.MUSER AS [User],
a.MTIME AS [MTime]
FROM {1}
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE {2}";
columns = @"a.MOCode AS TransCode,a.Sequence AS TransSequence,
";
tableName = @"ICSMO a";
where = @" a.mocode='{0}' AND a.WorkPoint='{1}' ";
}
else
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode001' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+b.MOCode AS TransCode,
a.PickID AS DetailID,
a.SupplyType AS Type,
b.Sequence+'~'+a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"b.MOCode AS TransCode,
a.PickID AS DetailID,
a.SupplyType AS Type,
b.Sequence+'~'+a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,
ISNULL(a.EATTRIBUTE3, isnull(A.Quantity,0)) as DHexcessQty,";
tableName = @"ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint ";
where = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.Quantity>0 and a.EATTRIBUTE1<>'1' ";
invWhere = DBHelper.SearchConditonGet("Trans_btnInvOut", JsonData.User, cmd);
//海格仓库领料
if (JsonData.DepType != null && JsonData.DepType == "W") { invWhere += @" and (isnull(inv.EATTRIBUTE11,'') ='0' and isnull(inv.EATTRIBUTE12,'') ='False') "; }
//海格生产领料
else if (JsonData.DepType != null && JsonData.DepType == "P") { invWhere += @" and ( isnull(inv.EATTRIBUTE12,'') ='True') and (isnull(inv.EATTRIBUTE11,'') ='0' and (isnull(inv.EATTRIBUTE11,'') ='0' "; }
singleWhere = @" b.MOCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.IssueQuantity,0)";
#region 锐腾杂发控制线边仓发料
DataTable rtdt = null;
string rtsql = @"select a.F_ItemCode,a.F_Define1 from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_id='d51a7d1a-cc8a-4b8e-b306-d4ef3a108549' and a.F_EnabledMark='1' AND a.F_ItemCode='{0}'";
rtsql = string.Format(rtsql, JsonData.User);
rtdt = DBHelper.SQlReturnData(rtsql, cmd);
if (rtdt != null && rtdt.Rows.Count > 0)
{
for (int i = 0; i < rtdt.Rows.Count; i++)
{
whcode = rtdt.Rows[i]["F_Define1"].ToString();
}
}
if (whcode != "")
{
where = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1' and a.WHCode in ({2})";
}
#endregion
}
}
#endregion
#region 生产发料——自动出库
else if (TransType == TransTypeEnum.MOIssueAutoDoc.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode001' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+b.MOCode AS TransCode,
a.PickID AS DetailID,
a.SupplyType AS Type,
b.Sequence+'~'+a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"b.MOCode AS TransCode,
a.PickID AS DetailID,
a.SupplyType AS Type,
b.Sequence+'~'+a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,
ISNULL(a.EATTRIBUTE3, isnull(A.Quantity,0)) as DHexcessQty,";
tableName = @"ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint ";
where = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1'
AND ((@ExcludeEnable=1 AND dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{2}', 2, 2,'')-ISNULL(a.IssueQuantity,0)>0) OR (@ExcludeEnable=0 OR @ExcludeEnable IS NULL)) ";
invWhere = DBHelper.SearchConditonGet("Trans_btnInvOutAuto", JsonData.User, cmd);
singleWhere = @" b.MOCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.IssueQuantity,0)";
}
#endregion
#region 销售出库(合并发料)
else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode007' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.SDNCode AS TransCode,
a.SDNDetailID AS DetailID,
a.SOCode,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.SDNQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSSDN a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.SDNCode AS TransCode,
a.SDNDetailID AS DetailID,
a.SOCode,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.SDNQuantity,0) AS IssueQuantity,";
tableName = @"ICSSDN a ";
where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3'
AND a.Quantity-ISNULL(a.SDNQuantity,0)>0";
singleWhere = @" a.SDNCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.SDNQuantity,0)";
}
#endregion
#region 销售发货单-快递单
else if (TransType == TransTypeEnum.SalesBindCourierDoc.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode007' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.SSDCode AS TransCode,
a.SSDDetailID AS DetailID,
a.SDNCode,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.SSDQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSSSD a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.SSDCode AS TransCode,
a.SSDDetailID AS DetailID,
a.SDNCode,
a.Type,
a.Sequence AS TransSequence,
a.EATTRIBUTE3 AS CourierCode,
ISNULL(a.SSDQuantity,0) AS IssueQuantity,";
tableName = @"ICSSSD a ";
where = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3'";
singleWhere = @" a.SSDCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.SSDQuantity,0)";
}
#endregion
#region 销售出库-出库单(合并发料)
else if (TransType == TransTypeEnum.SalesShipmentOutDoc.GetDescription() || TransType == TransTypeEnum.JHSalesShipmentOutDoc.GetDescription())
{
if (DBHelper.IsPNU9())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode013' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.SSDCode AS TransCode,
a.SSDDetailID AS DetailID,
isnull(a.EATTRIBUTE3,'') AS FDQuantity,
a.SDNCode,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.SSDQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSSSD a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.SSDCode AS TransCode,
a.SSDDetailID AS DetailID,
isnull(a.EATTRIBUTE3,'') AS FDQuantity,
a.SDNCode,
a.Type,
a.CusName,
a.Sequence AS TransSequence,
ISNULL(a.SSDQuantity,0) AS IssueQuantity,";
tableName = @"ICSSSD a
";
where = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' AND a.Quantity-ISNULL(a.SSDQuantity,0)>0";
singleWhere = @" a.SSDCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.SSDQuantity,0)";
}
else
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode013' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.SSDCode AS TransCode,
a.SSDDetailID AS DetailID,
'' AS FDQuantity,
a.SDNCode,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.SSDQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSSSD a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.SSDCode AS TransCode,
a.SSDDetailID AS DetailID,
'' AS FDQuantity,
a.SDNCode,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.SSDQuantity,0) AS IssueQuantity,";
tableName = @"ICSSSD a ";
where = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' AND a.Quantity-ISNULL(a.SSDQuantity,0)>0";
singleWhere = @" a.SSDCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.SSDQuantity,0)";
}
}
#endregion
#region 盘点
else if (TransType == TransTypeEnum.Check.GetDescription())
{
#region SLQ
sql = @"SELECT a.ID,
{0}
a.Quantity,
a.SelectLevel AS LocationCode,
a.Amount,
a.MUSER AS [User],
a.MTIME AS [MTime]
FROM {1}
WHERE {2} ";
#endregion
columns = @"a.CheckCode AS TransCode,
a.ID,
'' AS Type,";
tableName = @"ICSCheck a ";
where = @" a.CheckCode='{0}' AND a.WorkPoint='{1}' ";
singleWhere = @" a.CheckCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.CheckCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>0";
}
#endregion
#region 一步调拨(合并发料)
else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
{
if (JsonData.IsPN == "1")
{
isPN = "1";
}
else
{
isPN = "0";
}
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode009' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
string Wsql = @"select ColumnCode from ICSColumnEnable where TableCode='ICSTransfer' and Enable='1' and WorkPoint='{0}'";
DataTable chekdt = DBHelper.SQlReturnData(Wsql, cmd);
if (chekdt.Rows.Count > 0)
{
EATTRIBUTE = "a." + chekdt.Rows[0]["ColumnCode"].ToString();
}
if (!EATTRIBUTE.Equals(""))
{
columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
'" + EATTRIBUTE + @" as NewWorkPoint,'
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
}
else
{
columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
}
tableNameMerge = @"ICSTransfer a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
#region SLQ
sql = @"SELECT a.ID,
{0}
convert(varchar(100),'') AS LocationCode,
convert(varchar(100),'') AS LotNo,
isnull(a.EATTRIBUTE3,'') AS ToWorkPoint,
0 AS LocationQty,
0 AS isMatched,
a.InvCode,
inv.InvName,
inv.InvStd,
a.Quantity,
inv.InvUnit,
a.Amount,
a.FromWarehouseCode AS WHCode,
inv.AmountUnit,
wh.WarehouseName AS WHName,
a.ExtensionID,
ext.ProjectCode,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MTIME AS [MTime]
FROM {1}
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE {2} ";
#endregion
if (!EATTRIBUTE.Equals(""))
{
columns = @"a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
ISNULL(tlo.F_Define1,'') AS MLocationCode,
ISNULL(tlo.F_Define2,'') AS MWareHouseCode,
'' AS Type,
a.Sequence AS TransSequence,
'" + EATTRIBUTE + @" as NewWorkPoint,'
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
}
else
{
columns = @"a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
ISNULL(tlo.F_Define1,'') AS MLocationCode,
ISNULL(tlo.F_Define2,'') AS MWareHouseCode,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
}
tableName = @"ICSTransfer a
LEFT JOIN (select a.F_Define1,a.F_Define2 from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_EnCode='TransLocation') tlo ON a.ToWarehouseCode=tlo.F_Define2";
if (isPN == "1")
{
where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' AND a.Status<>'3' and a.type='3' AND a.Quantity>ISNULL(a.TransferQuantity,0)";
}
else
{
where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' AND a.Status<>'3' AND a.Quantity>ISNULL(a.TransferQuantity,0)";
}
singleWhere = @" a.TransferNO='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.TransferQuantity,0)";
}
#endregion
#region VMI调拨(合并发料)
else if (TransType == TransTypeEnum.VMITransferDocIn.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode009' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
string Wsql = @"select ColumnCode from ICSColumnEnable where TableCode='ICSTransfer' and Enable='1' and WorkPoint='{0}'";
DataTable chekdt = DBHelper.SQlReturnData(Wsql, cmd);
if (chekdt.Rows.Count > 0)
{
EATTRIBUTE = "a." + chekdt.Rows[0]["ColumnCode"].ToString();
}
if (!EATTRIBUTE.Equals(""))
{
columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
'" + EATTRIBUTE + @" as NewWorkPoint,'
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
}
else
{
columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
}
tableNameMerge = @"ICSTransfer a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
#region SQL
sql = @"SELECT a.ID,
{0}
convert(varchar(100),'') AS LocationCode,
convert(varchar(100),'') AS LotNo,
isnull(a.EATTRIBUTE3,'') AS ToWorkPoint,
0 AS LocationQty,
0 AS isMatched,
a.InvCode,
inv.InvName,
inv.InvStd,
a.Quantity,
inv.InvUnit,
a.Amount,
a.FromWarehouseCode AS WHCode,
inv.AmountUnit,
wh.WarehouseName AS WHName,
a.ExtensionID,
ext.ProjectCode,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MTIME AS [MTime]
FROM {1}
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
LEFT JOIN ICSWarehouse towh ON a.ToWarehouseCode=towh.WarehouseCode AND a.WorkPoint=towh.WorkPoint
LEFT JOIN ICSLocation lo ON lo.WHID=towh.ID AND lo.WorkPoint=towh.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE {2} ";
#endregion
if (!EATTRIBUTE.Equals(""))
{
columns = @"a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
ISNULL(tlo.F_Define1,'') AS MLocationCode,
ISNULL(tlo.F_Define2,'') AS MWareHouseCode,
'' AS Type,
a.Sequence AS TransSequence,
'" + EATTRIBUTE + @" as NewWorkPoint,'
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
lo.LocationCode AS ToLocationCode,
a.ToWarehouseCode,";
}
else
{
columns = @"a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
ISNULL(tlo.F_Define1,'') AS MLocationCode,
ISNULL(tlo.F_Define2,'') AS MWareHouseCode,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
lo.LocationCode AS ToLocationCode,
a.ToWarehouseCode,";
}
tableName = @"ICSTransfer a
LEFT JOIN (select a.F_Define1,a.F_Define2 from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_EnCode='TransLocation') tlo ON a.ToWarehouseCode=tlo.F_Define2";
where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' AND a.Status<>'3' AND a.Quantity>ISNULL(a.TransferQuantity,0)";
singleWhere = @" a.TransferNO='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.TransferQuantity,0)";
}
#endregion
#region 物料调拨-自动
else if (TransType == TransTypeEnum.OneStepTransferDocAuto.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode009' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
string Wsql = @"select ColumnCode from ICSColumnEnable where TableCode='ICSTransfer' and Enable='1' and WorkPoint='{0}'";
DataTable chekdt = DBHelper.SQlReturnData(Wsql, cmd);
if (chekdt.Rows.Count > 0)
{
EATTRIBUTE = "a." + chekdt.Rows[0]["ColumnCode"].ToString();
}
if (!EATTRIBUTE.Equals(""))
{
columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
'" + EATTRIBUTE + @" as NewWorkPoint,'
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
}
else
{
columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
}
tableNameMerge = @"ICSTransfer a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
#region SLQ
sql = @"SELECT a.ID,
{0}
convert(varchar(100),'') AS LocationCode,
convert(varchar(100),'') AS LotNo,
0 AS LocationQty,
0 AS isMatched,
a.InvCode,
inv.InvName,
inv.InvStd,
a.Quantity,
inv.InvUnit,
a.Amount,
a.FromWarehouseCode AS WHCode,
inv.AmountUnit,
wh.WarehouseName AS WHName,
a.ExtensionID,
ext.ProjectCode,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MTIME AS [MTime]
FROM {1}
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE {2} {5} ";
#endregion
if (!EATTRIBUTE.Equals(""))
{
columns = @"a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
'" + EATTRIBUTE + @" as NewWorkPoint,'
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
}
else
{
columns = @"a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
}
tableName = @"ICSTransfer a ";
where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' AND a.Status<>'3' ";
invWhere = DBHelper.SearchConditonGet("Trans_btnInvTransAuto", JsonData.User, cmd);
singleWhere = @" a.TransferNO='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.TransferQuantity,0)";
}
#endregion
#region 调拨申请单(领料)
else if (TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription())
{
if (JsonData.IsPN == "1")
{
isPN = "1";
}
else
{
isPN = "0";
}
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,isnull(a.EATTRIBUTE29,'') AS OutWorkPoint,isnull(a.EATTRIBUTE30,'') AS InWorkPoint,
a.Sequence AS TransSequence,
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
tableNameMerge = @"ICSTransferApplication a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
#region SLQ
sql = @"SELECT DISTINCT a.ID,
{0}
convert(varchar(100),'') AS LocationCode,
convert(varchar(100),'') AS LotNo,
0 AS LocationQty,
0 AS isMatched,
a.InvCode,
inv.InvName,
inv.InvStd,
a.Quantity,
inv.InvUnit,
a.Amount,
a.FromWarehouseCode AS WHCode,
inv.AmountUnit,
wh.WarehouseName AS WHName,
(select a.F_EnabledMark from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_id='4f733e37-445b-4534-8ec0-9f88d0842381') AS TransEnable,
a.ExtensionID,
ext.ProjectCode,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MTIME AS [MTime]
FROM {1}
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE {2} order by a.InvCode asc";
#endregion
columns = @"a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
a.FromWarehouseCode,
'' AS Type,isnull(a.EATTRIBUTE29,'') AS OutWorkPoint,isnull(a.EATTRIBUTE30,'') AS InWorkPoint,
ISNULL(tlo.F_Define1,'') AS MLocationCode,
ISNULL(tlo.F_Define2,'') AS MWareHouseCode,
a.Sequence AS TransSequence,
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
tableName = @"ICSTransferApplication a
LEFT JOIN (select a.F_Define1,a.F_Define2 from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_EnCode='TransLocation') tlo ON a.ToWarehouseCode=tlo.F_Define2";
if (isPN == "1")
{
where = @" a.TransferNO='{0}' AND a.Status='2' AND a.Status<>'3' AND a.Quantity>ISNULL(a.TransferQuantity,0)";
}
else
{
where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='2' AND a.Status<>'3' AND a.Quantity>ISNULL(a.TransferQuantity,0)";
}
singleWhere = @" a.TransferNO='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.TransferQuantity,0)";
}
#endregion
#region 调拨(合并发料)
else if (TransType == TransTypeEnum.StepTransferDocIn.GetDescription())
{
}
#endregion
#region 两步调出(合并发料)
else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode010' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
a.OutDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.OutQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSOtherOut a
INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.OutCode AS TransCode,
a.OutDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.OutQuantity,0) AS IssueQuantity,";
tableName = @"ICSOtherOut a
INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-a.OutQuantity>0";
singleWhere = @" a.OutCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.OutQuantity,0)";
}
#endregion
#region 晶华两步调出(合并发料)
else if (TransType == TransTypeEnum.JHTwoStepTransferDocOut.GetDescription())
{
sql = @"SELECT DISTINCT a.ID,
{0}
convert(varchar(100),'') AS LocationCode,
convert(varchar(100),'') AS LotNo,
convert(varchar(10),'') AS ToWarehouseCode,
0 AS LocationQty,
0 AS isMatched,
a.InvCode,
inv.InvName,
inv.InvStd,
inv.EATTRIBUTE4 AS module,
a.Quantity,
inv.InvUnit,
a.Amount,
a.FromWarehouseCode AS WHCode,
inv.AmountUnit,
wh.WarehouseName AS WHName,
(select a.F_EnabledMark from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_id='4f733e37-445b-4534-8ec0-9f88d0842381') AS TransEnable,
ISNULL(ext.ProjectCode, '') AS ProjectCode,
a.ExtensionID,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
ISNULL(ext.Version, '') AS Version,
ISNULL(ext.Brand, '') AS Brand,
ISNULL(ext.cFree1, '') AS cFree1,
ISNULL(ext.cFree2, '') AS cFree2,
ISNULL(ext.cFree3, '') AS cFree3,
ISNULL(ext.cFree4, '') AS cFree4,
ISNULL(ext.cFree5, '') AS cFree5,
ISNULL(ext.cFree6, '') AS cFree6,
ISNULL(ext.cFree7, '') AS cFree7,
ISNULL(ext.cFree8, '') AS cFree8,
ISNULL(ext.cFree9, '') AS cFree9,
ISNULL(ext.cFree10, '') AS cFree10,
ISNULL(inv.EATTRIBUTE1, '') AS EATTRIBUTE1,
a.MUSER AS [User],
a.MTIME AS [MTime]
{4}
FROM {1}
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE {2} {5} ";
//sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode010' and enable = '1'";
//flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
//isMerge = true;
//columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
// a.OutDetailID AS DetailID,
// '' AS Type,
// a.Sequence AS TransSequence,
// ISNULL(a.OutQuantity,0) AS IssueQuantity,";
//tableNameMerge = @"ICSTransfer a
// INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
// INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.TransferQuantity,0) AS IssueQuantity,";
tableName = @"ICSTransfer a";
where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-isnull(a.EATTRIBUTE1,0)>0";
singleWhere = @" a.TransferNO='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Quantity>isnull(a.EATTRIBUTE1,0)";
}
#endregion
#region 其他出库(合并发料)
else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode008' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
a.OutDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.OutQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSOtherOut a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.OutCode AS TransCode,
a.OutDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.OutQuantity,0) AS IssueQuantity,";
tableName = @"ICSOtherOut a ";
where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.OutQuantity, 0)>0";
invWhere = DBHelper.SearchConditonGet("Trans_btnOtherOut", JsonData.User, cmd);
singleWhere = @" a.OutCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.OutQuantity,0)";
#region 锐腾杂发控制线边仓发料
DataTable rtdt = null;
string rtsql = @"select a.F_ItemCode,a.F_Define1 from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_id='d51a7d1a-cc8a-4b8e-b306-d4ef3a108549' and a.F_EnabledMark='1' AND a.F_ItemCode='{0}'";
rtsql = string.Format(rtsql, JsonData.User);
rtdt = DBHelper.SQlReturnData(rtsql, cmd);
if (rtdt != null && rtdt.Rows.Count > 0)
{
for (int i = 0; i < rtdt.Rows.Count; i++)
{
whcode = rtdt.Rows[i]["F_Define1"].ToString();
}
}
if (whcode != "")
{
where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.OutQuantity, 0)>0 and a.WHCode in ({2})";
}
#endregion
}
#endregion
#region 其他出库-自动出库
else if (TransType == TransTypeEnum.OtherOutAutoDoc.GetDescription())
{
sqlCheck += @"IF EXISTS (SELECT 1
FROM ICSOtherOut a
INNER JOIN ICSInventory inv ON inv.InvCode=a.InvCode AND inv.WorkPoint=a.WorkPoint
WHERE {2} " + DBHelper.SearchConditonGet("Trans_btnOtherOut", JsonData.User, cmd) + @")
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo530") + @"',16,1);
RETURN
END
";
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode008' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = false;
columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
a.OutDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.OutQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSOtherOut a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.OutCode AS TransCode,
a.OutDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.OutQuantity,0) AS IssueQuantity,";
tableName = @"ICSOtherOut a ";
where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.OutQuantity, 0)>0 ";
invWhere = DBHelper.SearchConditonGet("Trans_btnOtherOutAuto", JsonData.User, cmd);
singleWhere = @" a.OutCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.OutQuantity,0)";
}
#endregion
#region 红字其他入库
else if (TransType == TransTypeEnum.OtherInRedDoc.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode008' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.InCode AS TransCode,
a.InDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.InQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSOtherIn a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.InCode AS TransCode,
a.InDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.InQuantity,0) AS IssueQuantity,";
tableName = @"ICSOtherIn a ";
where = @" a.InCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-a.InQuantity>0 AND a.Type='2'";
singleWhere = @" a.InCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.InCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.InQuantity,0)";
}
#endregion
#region 领料申请单发料(合并发料)
else if (TransType == TransTypeEnum.MOApply.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode002' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
a.ApplyDetailID AS DetailID,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,
ISNULL(a.EATTRIBUTE3,'') AS Memo,";
tableNameMerge = @"ICSMOApply a
INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.ApplyCode AS TransCode,
a.ApplyDetailID AS DetailID,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,
ISNULL(a.EATTRIBUTE3,'') AS Memo,
";
tableName = @"ICSMOApply a ";
where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
singleWhere = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.IssueQuantity,0)";
// 东辉增加备用字段
//受益部门(EATTRIBUTE)、单据类型EATTRIBUTE2、
//RD编号EATTRIBUTE5、项目编号EATTRIBUTE8、实际领用部门DepName、备注EATTRIBUTE11
if (DBHelper.IsU9())
{
columns += @"isnull(a.EATTRIBUTE15,'') as EATTRIBUTE1,
isnull(a.EATTRIBUTE17,'') as EATTRIBUTE2,
isnull(a.EATTRIBUTE5,'') as EATTRIBUTE5,
isnull(a.EATTRIBUTE8,'') as EATTRIBUTE8,
isnull(its.F_itemName,'') as DepName,
isnull(a.EATTRIBUTE11,'') as EATTRIBUTE11,
isnull(lotinfo.qty,0) as invLotQty,
";
tableName = @"ICSMOApply a
LEFT join Sys_SRM_Items it on it.F_EnCode = 'LYDep'
LEFT join Sys_SRM_ItemsDetail its on it.F_id = its.f_itemid and its.F_itemcode = a.DepCode
left join (select invcode,sum(Quantity) as qty from icswarehouselotinfo group by invcode) lotinfo on a.invcode = lotinfo.invcode
";
where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
sqlCheck += @"
DECLARE @status VARCHAR(20)
select top 1 @status = status from ICSMOApply where ApplyCode='" + JsonData.TransCode + @"'
IF(@status!=2)
BEGIN
RAISERROR('单据不是审核状态无法发料',16,1);
RETURN
END
";
}
}
#endregion
#region 补料申请单发料(合并发料)
else if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode012' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
a.ApplyDetailID AS DetailID,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSMOReplenishment a
INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.ReplenishmentCode AS TransCode,
a.ReplenishmentDetailID AS DetailID,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableName = @"ICSMOReplenishment a ";
where = @" a.ReplenishmentCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
singleWhere = @" a.ReplenishmentCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.ReplenishmentCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.IssueQuantity,0)";
}
#endregion
#region 委外领料申请单发料(合并发料)
else if (TransType == TransTypeEnum.OOApply.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode005' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
a.ApplyDetailID AS DetailID,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSOApply a
INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.ApplyCode AS TransCode,
a.ApplyDetailID AS DetailID,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableName = @"ICSOApply a ";
where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
singleWhere = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.IssueQuantity,0)";
}
#endregion
#region 开立材料出库(合并发料)
else if (TransType == TransTypeEnum.MOIssue.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode003' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
a.IssueDetailID AS DetailID,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSMOIssue a
INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.IssueCode AS TransCode,
a.IssueDetailID AS DetailID,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableName = @"ICSMOIssue a ";
where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
singleWhere = @" a.IssueCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.IssueQuantity,0)";
#region 锐腾杂发控制线边仓发料
DataTable rtdt = null;
string rtsql = @"select a.F_ItemCode,a.F_Define1 from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_id='d51a7d1a-cc8a-4b8e-b306-d4ef3a108549' and a.F_EnabledMark='1' AND a.F_ItemCode='{0}'";
rtsql = string.Format(rtsql, JsonData.User);
rtdt = DBHelper.SQlReturnData(rtsql, cmd);
if (rtdt != null && rtdt.Rows.Count > 0)
{
for (int i = 0; i < rtdt.Rows.Count; i++)
{
whcode = rtdt.Rows[i]["F_Define1"].ToString();
}
}
if (whcode != "")
{
where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0 and a.WHCode in ({2})";
}
#endregion
}
#endregion
#region 开立委外材料出库(合并发料)
else if (TransType == TransTypeEnum.OOIssue.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode006' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
a.IssueDetailID AS DetailID,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSOIssue a
INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.IssueCode AS TransCode,
a.IssueDetailID AS DetailID,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableName = @"ICSOIssue a ";
where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
singleWhere = @" a.IssueCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.IssueQuantity,0)";
}
#endregion
#region 开立红字入库单
else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
{
columns = @"a.RCVCode AS TransCode,
a.RCVDetailID AS DetailID,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.RCVQuantity, 0) AS IssueQuantity,";
tableName = @"ICSPurchaseReceive a ";
where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3' AND a.Quantity>ISNULL(a.RCVQuantity,0)";
singleWhere = @" a.RCVCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.RCVQuantity,0)";
}
#endregion
#region 开立委外红字入库单
else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
{
columns = @"a.RCVCode AS TransCode,
a.RCVDetailID AS DetailID,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.RCVQuantity,0) AS IssueQuantity,";
tableName = @"ICSOutsourcingReceive a ";
where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3'";
singleWhere = @" a.RCVCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.RCVQuantity,0)";
}
#endregion
#region 借用(合并发料)
else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode011' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.BrrowCode AS TransCode,
a.BrrowDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.BrrowQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSBrrow a
INNER JOIN ICSMOPickMerge mer ON a.BrrowDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.BrrowCode AS TransCode,
a.BrrowDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.BrrowQuantity,0) AS IssueQuantity,";
tableName = @"ICSBrrow a ";
where = @" a.BrrowCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.BrrowQuantity,0)>0";
singleWhere = @" a.BrrowCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.BrrowCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.BrrowQuantity,0)";
}
#endregion
#region 送货单
else if (TransType == TransTypeEnum.ASN.GetDescription())
{
isDeliveryNotice = true;
columns = @"asn.ASNCode AS TransCode,
asn.ID AS DetailID,
asn.LotNo,
'' AS Type,
asn.Sequence AS TransSequence,
ISNULL(asn.DNQuantity,0) AS IssueQuantity,
asn.Quantity,
asn.Quantity*(a.Amount/a.Quantity) AS Amount,
asn.MUSER AS [User],
asn.MTIME AS [MTime],
--东辉新增
case when its.F_Define1 is not null then '1' else '0' end as needScan,
--海格自定义档案 急料期限
case when DATEDIFF(hour, getDate(), isnull(potemp.PlanArriveDate,'2000-01-01 00:00:00'))<=(isnull(itts.F_Define1,0)*24) then 1 else 0 end as isUrgency,invinfo.InvIQC,
case when invinfo.INVIQC =1 then isnull(ins.enable,0) else '1' end as inspection,isnull(ins.QualifiedQuantity,0) as PassQuantity,
POQuantity , YDNQuantity , (POQuantity-YDNQuantity) as NDNQuantity,";
tableName = @"ICSInventoryLot a
INNER JOIN ICSASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint
LEFT join Sys_SRM_Items it on it.F_EnCode = 'Arrive_inv'
LEFT join Sys_SRM_ItemsDetail its on it.F_id = its.f_itemid and SUBSTRING(a.InvCode, 1, 1) = its.F_Define1
LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1
LEFT join Sys_SRM_Items itt on itt.F_EnCode = 'Urgent001'
LEFT join Sys_SRM_ItemsDetail itts on itt.F_id = itts.f_itemid -- itts.F_Define1
INNER JOIN ICSInventoryLotDetail lotdetail ON a.LotNo=lotdetail.LotNo AND a.WorkPoint=lotdetail.WorkPoint
INNER JOIN ICSInventory invinfo on invinfo.invcode = a.invcode AND a.WorkPoint=invinfo.WorkPoint
LEFT join
(select c.Quantity as POQuantity ,SUM(a.DNQuantity) as YDNQuantity,c.pocode ,c.sequence,c.PlanArriveDate
from ICSASNDetail a
inner join ICSInventoryLotdetail b on a.lotno =b.lotno
inner join ICSPurchaseOrder c on b.transcode = c.pocode and b.transSequence = c.sequence
GROUP BY c.pocode ,c.sequence,c.Quantity,c.PlanArriveDate) potemp on lotdetail.transcode = potemp.pocode and lotdetail.transSequence = potemp.sequence
";
where = @" asn.ASNCode='{0}' AND a.WorkPoint='{1}' ";
singleWhere = @" asn.ASNCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" asn.ASNCode='{0}' AND a.WorkPoint='{1}' AND asn.Quantity>ISNULL(asn.DNQuantity,0)";
}
#endregion
#region 委外送货单
else if (TransType == TransTypeEnum.OASN.GetDescription())
{
isDeliveryNotice = true;
columns = @"asn.OASNCode AS TransCode,
asn.ID AS DetailID,
asn.LotNo,
'' AS Type,
asn.Sequence AS TransSequence,
ISNULL(asn.ODNQuantity,0) AS IssueQuantity,
asn.Quantity,
asn.Quantity*(a.Amount/a.Quantity) AS Amount,
asn.MUSER AS [User],
asn.MTIME AS [MTime],isnull(ins.QualifiedQuantity,0) as PassQuantity,";
tableName = @"ICSInventoryLot a
INNER JOIN ICSOASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint
LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1";
where = @" asn.OASNCode='{0}' AND a.WorkPoint='{1}' ";
singleWhere = @" asn.OASNCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" asn.OASNCode='{0}' AND a.WorkPoint='{1}' AND asn.Quantity>ISNULL(asn.ODNQuantity,0)";
}
#endregion
#endregion
#region 入库
#region 采购入库
else if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
{
}
#endregion
#region 采购入库-入库单
else if (TransType == TransTypeEnum.PurchaseReceiveRevDoc.GetDescription())
{
}
#endregion
#region 审核的到货单
else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
{
}
#endregion
#region 采购拒收
else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
{
}
#endregion
#region 审核的委外到货单
else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
{
}
#endregion
#region 委外拒收
else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
{
}
#endregion
#region 委外入库
else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
{
}
#endregion
#region 生产退料
else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
|| TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
|| TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
{
#region SLQ
sql = @"SELECT a.ID,
{0}
FROM {1}
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE {2} ";
#endregion
columns = @"a.ApplyNegCode AS TransCode,lot.LotNo,
a.Sequence AS TransSequence";
tableName = @"ICSMOApplyNegDetail a
INNER JOIN ICSMOApplyNeg d ON a.ApplyNegCode=d.ApplyNegCode AND a.WorkPoint=d.WorkPoint
INNER JOIN ICSInventoryLotDetail cc on a.ApplyNegCode=cc.TransCode AND a.Sequence=cc.TransSequence and a.Workpoint=cc.Workpoint
INNER JOIN ICSInventoryLot lot on cc.lotno=lot.lotno and cc.workpoint=lot.workpoint";
where = @" a.ApplyNegCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>a.IssueNegQuantity AND d.Status<>'3'";
singleWhere = @" a.ApplyNegCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.ApplyNegCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.IssueNegQuantity,0)";
}
#endregion
#region 委外退料
else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
{
#region SLQ
sql = @"SELECT a.ID,
{0}
FROM {1}
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE {2} ";
#endregion
columns = @"a.OApplyNegCode AS TransCode,
a.Sequence AS TransSequence";
tableName = @"ICSOApplyNegDetail a
INNER JOIN ICSOApplyNeg d ON a.OApplyNegCode=d.OApplyNegCode AND a.WorkPoint=d.WorkPoint";
where = @" a.OApplyNegCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>a.IssueNegQuantity AND d.Status<>'3'";
singleWhere = @" a.OApplyNegCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.OApplyNegCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.IssueNegQuantity,0)";
}
#endregion
#region 生产入库
else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
{
}
#endregion
#region 开立的生产入库单
else if (TransType == TransTypeEnum.ManufactureMESReceive.GetDescription())
{
columns = @"a.RCVCode AS TransCode,
a.RCVDetailID AS DetailID,
a.Type AS Type,
a.Sequence AS TransSequence,
a.SourceCode,
a.SourceSequence,
ISNULL(a.RCVQuantity,0) AS IssueQuantity,";
tableName = @"ICSManufactureReceive a ";
where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status='1' AND a.Quantity>ISNULL(a.RCVQuantity, 0)";
singleWhere = @" a.RCVCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.RCVQuantity,0)";
}
#endregion
#region 返工工单
else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
{
}
#endregion
#region 销售退货
else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
{
}
#endregion
#region 销售出库-红字出库单原条码
else if (TransType == TransTypeEnum.SalesShipmentOutRedYuanDoc.GetDescription())
{
columns = @"a.SSDCode AS TransCode,
a.SSDDetailID AS DetailID,
a.SDNCode,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.SSDQuantity,0) AS IssueQuantity,";
tableName = @"ICSSSD a ";
where = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status='1' AND a.Quantity-ISNULL(a.SSDQuantity,0)>0";
singleWhere = @" a.SSDCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.SSDQuantity,0)";
}
#endregion
#region 两步调入
else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
{
columns = @"a.InCode AS TransCode,
a.InDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.InQuantity,0) AS IssueQuantity,";
tableName = @"ICSOtherIn a
INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
where = @" a.InCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
singleWhere = @" a.InCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.InCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.InQuantity,0)";
}
#endregion
#region 晶华两步调入
else if (TransType == TransTypeEnum.JHTwoStepTransferDocIn.GetDescription())
{
sql = @"SELECT DISTINCT a.ID,
{0}
convert(varchar(100),'') AS LocationCode,
convert(varchar(100),'') AS LotNo,
convert(varchar(10),'') AS ToWarehouseCode,
0 AS LocationQty,
0 AS isMatched,
a.InvCode,
inv.InvName,
inv.InvStd,
inv.EATTRIBUTE4 AS module,
a.Quantity,
inv.InvUnit,
a.Amount,
a.ToWarehouseCode AS WHCode,
inv.AmountUnit,
wh.WarehouseName AS WHName,
(select a.F_EnabledMark from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_id='4f733e37-445b-4534-8ec0-9f88d0842381') AS TransEnable,
ISNULL(ext.ProjectCode, '') AS ProjectCode,
a.ExtensionID,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
ISNULL(ext.Version, '') AS Version,
ISNULL(ext.Brand, '') AS Brand,
ISNULL(ext.cFree1, '') AS cFree1,
ISNULL(ext.cFree2, '') AS cFree2,
ISNULL(ext.cFree3, '') AS cFree3,
ISNULL(ext.cFree4, '') AS cFree4,
ISNULL(ext.cFree5, '') AS cFree5,
ISNULL(ext.cFree6, '') AS cFree6,
ISNULL(ext.cFree7, '') AS cFree7,
ISNULL(ext.cFree8, '') AS cFree8,
ISNULL(ext.cFree9, '') AS cFree9,
ISNULL(ext.cFree10, '') AS cFree10,
ISNULL(inv.EATTRIBUTE1, '') AS EATTRIBUTE1,
a.MUSER AS [User],
a.MTIME AS [MTime]
{4}
FROM {1}
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE {2} {5} ";
columns = @"a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.TransferQuantity,0) AS IssueQuantity,";
tableName = @"ICSTransfer a
";
where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
singleWhere = @" a.TransferNO='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.TransferQuantity,0)";
}
#endregion
#region 锐腾两步调入
else if (TransType == TransTypeEnum.RTTwoStepTransferDocIn.GetDescription())
{
columns = @"a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
a.TransferQuantity AS IssueQuantity,";
tableName = @"ICSTransfer a ";
where = @" a.TransferNo='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
singleWhere = @" a.TransferNo='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.TransferNo='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.TransferQuantity,0)";
}
#endregion
#region 销售退货-原条码
else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
{
columns = @"a.SDNCode AS TransCode,
a.SOCode ,
a.SDNDetailID AS DetailID,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.SDNQuantity,0) AS IssueQuantity,";
tableName = @"ICSSDN a ";
where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3'";
singleWhere = @" a.SDNCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.SDNQuantity,0)";
}
#endregion
#region 其他入库
else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
{
}
#endregion
#region 拆卸单
else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
{
columns = @"a.DABDOCCode AS TransCode,
a.DABDOCDetailID AS DetailID,
a.DABDOCType AS Type,
a.Sequence AS TransSequence,
ISNULL(a.DABDOCQuantity,0) AS IssueQuantity,";
tableName = @"ICSDisassemblyDoc a";
where = @" a.DABDOCCode='{0}' AND a.WorkPoint='{1}' AND a.DABDOCType='2' AND a.Status<>'3' ";
singleWhere = @" a.DABDOCCode='{0}' AND a.WorkPoint='{1}'";
completeWhere = @" a.DABDOCCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.DABDOCQuantity,0)";
}
#endregion
#region 归还
else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
{
columns = @"a.ReturnCode AS TransCode,
a.ReturnDetailID AS DetailID,
a.Sequence AS TransSequence,
ISNULL(a.ReturnQuantity,0) AS IssueQuantity,";
tableName = @"ICSReturn a ";
where = @" a.ReturnCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity>ISNULL(a.ReturnQuantity, 0)";
singleWhere = @" a.ReturnCode='{0}' AND a.Status<>'3' AND a.WorkPoint='{1}'";
completeWhere = @" a.ReturnCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity>ISNULL(a.ReturnQuantity,0)";
}
#endregion
#endregion
if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName) || string.IsNullOrWhiteSpace(where))
throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
#region 判断是否启用匹配库位
if ((flag != null && flag.Rows.Count > 0) || isRTOut == "1")
//if (true)
{
sql = @"select * into #maintemp from (" + sql + @")a
select * into #resulttemp from #maintemp
truncate table #resulttemp
select a.lotno,a.locationcode,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime,a.warehousecode,isnull(ext.ProjectCode,'')as ProjectCode, isnull(ext.Version,'')as Version,
isnull(ext.Brand,'')as Brand,
isnull(ext.cFree1,'')as cFree1,
isnull(ext.cFree2,'') cFree2,
isnull(ext.cFree3,'') cFree3,
isnull(ext.cFree4,'') cFree4,
isnull(ext.cFree5,'') cFree5,
isnull(ext.cFree6,'') cFree6,
isnull(ext.cFree7,'') cFree7,
isnull(ext.cFree8,'') cFree8,
isnull(ext.cFree9,'') cFree9,
isnull(ext.cFree10,'') cFree10,ISNULL(ext.BatchCode, '') BatchCode into #barcodetemp
from ICSWareHouseLotInfo a INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
LEFT JOIN
(select invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE from #maintemp
group by invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE) b on a.invcode = b.invcode
where (a.warehousecode = b.whcode or ISNULL(b.whcode,'')='') and a.Quantity-a.lockQuantity>0 and
((LEN(ISNULL(b.ProjectCode,''))<=0)or((LEN(ISNULL(b.ProjectCode,''))>0) and ext.ProjectCode = b.ProjectCode))
and ((LEN(ISNULL(b.Version,''))<=0)or((LEN(ISNULL(b.Version,''))>0) and ext.Version =b.Version)) and
((LEN(ISNULL(b.Brand,''))<=0)or ((LEN(ISNULL(b.Brand,''))>0) and ext.Brand =b.Brand)) and
((LEN(ISNULL(b.BatchCode,''))<=0)or((LEN(ISNULL(b.BatchCode,''))>0) and ext.BatchCode =b.BatchCode)) and
((LEN(ISNULL(b.cFree1,''))<=0)or((LEN(ISNULL(b.cFree1,''))>0) and ext.cFree1 =b.cFree1)) and
((LEN(ISNULL(b.cFree2,''))<=0)or((LEN(ISNULL(b.cFree2,''))>0) and ext.cFree2 =b.cFree2)) and
((LEN(ISNULL(b.cFree3,''))<=0)or((LEN(ISNULL(b.cFree3,''))>0) and ext.cFree3 =b.cFree3)) and
((LEN(ISNULL(b.cFree4,''))<=0)or((LEN(ISNULL(b.cFree4,''))>0) and ext.cFree4 =b.cFree4)) and
((LEN(ISNULL(b.cFree5,''))<=0)or((LEN(ISNULL(b.cFree5,''))>0) and ext.cFree5 =b.cFree5)) and
((LEN(ISNULL(b.cFree6,''))<=0)or((LEN(ISNULL(b.cFree6,''))>0) and ext.cFree6 =b.cFree6)) and
((LEN(ISNULL(b.cFree7,''))<=0)or((LEN(ISNULL(b.cFree7,''))>0) and ext.cFree7 =b.cFree7)) and
((LEN(ISNULL(b.cFree8,''))<=0)or((LEN(ISNULL(b.cFree8,''))>0) and ext.cFree8 =b.cFree8)) and
((LEN(ISNULL(b.cFree9,''))<=0)or((LEN(ISNULL(b.cFree9,''))>0) and ext.cFree9 =b.cFree9)) and
((LEN(ISNULL(b.cFree10,''))<=0)or((LEN(ISNULL(b.cFree10,''))>0) and ext.cFree10 =b.cFree10)) order by a.mtime
BEGIN
DECLARE @transSequence VARCHAR(50);--当前循环的行号
DECLARE @qty decimal(18, 4);--条码表数量
DECLARE @needqty decimal(18, 4);--本行所需数量
DECLARE @lotno VARCHAR(50);--本行所需数量
DECLARE @locationcode VARCHAR(50);--本行所在库位
DECLARE @WHCode VARCHAR(50);--本行所在仓库
DECLARE @invcode VARCHAR(50);--本行条码
DECLARE @mtime DATE;
DECLARE @issueQuantity decimal(18, 4);
DECLARE tempCursor CURSOR FOR (select transSequence from #maintemp); --创建游标tempCursor,并定义游标所指向的集合
OPEN tempCursor; --打开游标
FETCH NEXT FROM tempCursor INTO @transSequence; --游标读取下一个数据
WHILE @@fetch_status=0
BEGIN
select @needqty=Quantity,@issueQuantity=issueQuantity from #maintemp where transSequence = @transSequence
PRINT @transSequence
WHILE @needqty>0
BEGIN
select top 1 @qty = isnull(a.quantity,0), @locationcode = isnull(a.locationcode,''),@lotno = isnull(a.lotno,''),@WHCode = isnull(a.warehousecode,''),@mtime=a.mtime,@invcode = b.invcode from #barcodetemp a
right JOIN(select invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE from #maintemp where transSequence=@transSequence)b on a.invcode = b.invcode
and ((isnull(b.ProjectCode,'')<>'' and b.ProjectCode = a.ProjectCode) or isnull(b.ProjectCode,'') ='') and
((isnull(b.Version,'')<>'' and b.Version = a.Version) or isnull(b.Version,'') ='') and
((isnull(b.Brand,'')<>'' and b.Brand = a.Brand )or isnull(b.Brand,'') ='') and
((isnull(b.cFree1,'')<>'' and b.cFree1 =a.cFree1) or isnull(b.cFree1,'') ='') and
((isnull(b.cFree2,'')<>'' and b.cFree2 =a.cFree2 )or isnull(b.cFree2,'') ='') and
((isnull(b.cFree3,'')<>'' and b.cFree3 =a.cFree3 )or isnull(b.cFree3,'') ='') and
((isnull(b.cFree4,'')<>'' and b.cFree4 =a.cFree4 )or isnull(b.cFree4,'') ='') and
((isnull(b.cFree5,'')<>'' and b.cFree5 =a.cFree5) or isnull(b.cFree5,'') ='') and
((isnull(b.cFree6,'')<>'' and b.cFree6 =a.cFree6 )or isnull(b.cFree6,'') ='') and
((isnull(b.cFree7,'')<>'' and b.cFree7 =a.cFree7) or isnull(b.cFree7,'') ='') and
((isnull(b.cFree8,'')<>'' and b.cFree8 =a.cFree8) or isnull(b.cFree8,'') ='') and
((isnull(b.cFree9,'')<>'' and b.cFree9 =a.cFree9) or isnull(b.cFree9,'') ='') and
((isnull(b.cFree10,'')<>'' and b.cFree10 =a.cFree10) or isnull(b.cFree10,'') ='') and
((isnull(b.BatchCode,'')<>'' and b.BatchCode =a.BatchCode) or isnull(b.BatchCode,'') ='')ORDER BY a.mtime,a.locationcode
IF(@needqty-@issueQuantity-@qty>=0 and ISNULL(@lotno, '')<>'')
BEGIN
insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotNo,
WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
ISNULL(Amount, 0),[User],@mtime,InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),@qty,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
delete from #barcodetemp where lotno = @lotno
SET @needqty=@needqty-@qty
END
ELSE if(@needqty-@issueQuantity-@qty<0 and ISNULL(@lotno, '')<>''and @needqty-@issueQuantity>0)
BEGIN
insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotno,
WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
ISNULL(Amount, 0),[User],@mtime,InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),case WHEN ISNULL(@qty, 0)=0 THEN 0 else @needqty-@issueQuantity end ,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
update #barcodetemp set quantity = @qty-@needqty+-@issueQuantity where lotno = @lotno
SET @needqty=@needqty-@issueQuantity-@qty
END
ELSE
BEGIN
insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotno,
WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
ISNULL(Amount, 0),[User],@mtime,InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),0 ,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
SET @needqty=0
END
END
FETCH NEXT FROM tempCursor INTO @transSequence;
END
CLOSE tempCursor
DEALLOCATE tempCursor
END
select id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,sum(LocationQty)as LocationQty,isMatched,AmountUnit,LotNo,
WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #resulttemp GROUP BY id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,isMatched,AmountUnit,LotNo,
WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ORDER BY locationcode ASC ,InvCode ASC
DROP table #maintemp
DROP table #resulttemp
DROP table #barcodetemp";
}
#endregion
if (isDeliveryNotice)//送货、到货、含委外
{
#region SLQ
sql = sqlCheck + @"SELECT a.ID,
{0}
a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,
'' AS WHCode,
inv.AmountUnit,
'' AS WHName,
a.ExtensionID,
ext.ProjectCode,
CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10
FROM {1}
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE {2} ";
#endregion
}
//else if (isMerge )//合并发料
else if (isMerge && (JsonData.DepType != "P"))//合并发料
{
#region SLQ
string sqlMerge = "SELECT ID FROM ICSMOPickMerge WHERE MergeID='" + JsonData.TransCode + "' AND WorkPoint='" + JsonData.WorkPoint + "'";
DataTable sign = DBHelper.SQlReturnData(sqlMerge, cmd);
if (sign != null && sign.Rows.Count > 0)
{
string whereMerge = string.Format("mer.MergeID='{0}' AND mer.WorkPoint='{1}'", JsonData.TransCode, JsonData.WorkPoint);
sql = string.Format(sql, columnsMerge, tableNameMerge, whereMerge, JsonData.TransCode, excessQtySql, invWhere, singleWhere, completeWhere);
}
else
{
sql = @" BEGIN
IF EXISTS(SELECT a.ID FROM {1} INNER JOIN ICSMOPickMerge c ON a.ID=c.SourceID AND a.WorkPoint=c.WorkPoint WHERE {2})
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo194") + @"',16,1);
RETURN
END
" + sqlCheck + sql + @"
END";
}
#endregion
}
else
{
sql = sqlCheck + sql;
}
where = string.Format(where, JsonData.TransCode, JsonData.WorkPoint, whcode);
singleWhere = string.Format(singleWhere, JsonData.TransCode, JsonData.WorkPoint);
completeWhere = string.Format(completeWhere, JsonData.TransCode, JsonData.WorkPoint);
sql = excludeSql + sql;
sql = string.Format(sql, columns, tableName, where, JsonData.TransCode, excessQtySql, invWhere, singleWhere, completeWhere, JsonData.CJName);
sqls = string.Format(sqls, JsonData.TransCode, JsonData.WorkPoint);
Picksql = string.Format(Picksql, sqls, JsonData.WorkPoint);
//DataTable table2 = DBHelper.SQlReturnData(Picksql, cmd);
//return table2;
log.Debug("源头单据sql:" + sql);
DataTable table = DBHelper.SQlReturnData(sql, cmd);
return table;
}
catch (Exception ex)
{
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
#endregion
#region 源头单据信息
///
/// 源头单据信息
///
///
///
public static DataTable NewTransInformationGet(WMSSourceDocumentModel JsonData)
{
var language = LanguageHelper.GetName("WMSAPIInfo");
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
string sql = string.Empty;
string arrivalCtrlSql = string.Empty;
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
try
{
if (string.IsNullOrEmpty(JsonData.TransType))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
}
else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
}
else if (string.IsNullOrEmpty(JsonData.WorkPoint))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
}
string TransType = JsonData.TransType;
string enableCode = "";
string excessQtySql = "";
#region SLQ
string sqlCheck = @"IF NOT EXISTS(SELECT a.ID FROM {1} WHERE {2})
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo035") + @"',16,1);
RETURN
END
";
//查询是否需要去除单据中已发完明细
string excludeSql = @"DECLARE @ExcludeEnable BIT
SET @ExcludeEnable=(SELECT Enable FROM ICSConfiguration WHERE Code='excludeInvDelivered')";
if (TransType == TransTypeEnum.ASN.GetDescription() || TransType == TransTypeEnum.OASN.GetDescription())
{
sql = @"SELECT a.ID,
{0}
convert(varchar(100),'') AS LocationCode,
convert(varchar(100),'') AS LotNo,
convert(varchar(10),'') AS ToWarehouseCode,
0 AS LocationQty,
0 AS isMatched,
a.InvCode,
inv.InvName,
inv.InvStd,
a.Quantity,
inv.InvUnit,
a.Amount,
--a.WHCode,
inv.AmountUnit,
--wh.WarehouseName AS WHName,
ISNULL(ext.ProjectCode, '') AS ProjectCode,
a.ExtensionID,
--CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
ISNULL(ext.Version, '') AS Version,
ISNULL(ext.Brand, '') AS Brand,
ISNULL(ext.cFree1, '') AS cFree1,
ISNULL(ext.cFree2, '') AS cFree2,
ISNULL(ext.cFree3, '') AS cFree3,
ISNULL(ext.cFree4, '') AS cFree4,
ISNULL(ext.cFree5, '') AS cFree5,
ISNULL(ext.cFree6, '') AS cFree6,
ISNULL(ext.cFree7, '') AS cFree7,
ISNULL(ext.cFree8, '') AS cFree8,
ISNULL(ext.cFree9, '') AS cFree9,
ISNULL(ext.cFree10, '') AS cFree10,
a.MUSER AS [User],
a.MTIME AS [MTime]
{4}
FROM {1}
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
--LEFT JOIN ICSWarehouse wh ON a.WHCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
--LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WHCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE {2}
Order By asn.Sequence ASC";
}
else if (TransType == TransTypeEnum.RTTwoStepTransferDocIn.GetDescription())
{
sql = @"SELECT a.ID,
{0}
convert(varchar(100),'') AS LocationCode,
convert(varchar(100),'') AS LotNo,
convert(varchar(10),'') AS ToWarehouseCode,
0 AS LocationQty,
0 AS isMatched,
a.InvCode,
inv.InvName,
inv.InvStd,
a.Quantity,
inv.InvUnit,
a.Amount,
a.ToWarehouseCode AS WHCode,
inv.AmountUnit,
wh.WarehouseName AS WHName,
(select a.F_EnabledMark from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_id='4f733e37-445b-4534-8ec0-9f88d0842381') AS TransEnable,
ISNULL(ext.ProjectCode, '') AS ProjectCode,
a.ExtensionID,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
ISNULL(ext.Version, '') AS Version,
ISNULL(ext.Brand, '') AS Brand,
ISNULL(ext.cFree1, '') AS cFree1,
ISNULL(ext.cFree2, '') AS cFree2,
ISNULL(ext.cFree3, '') AS cFree3,
ISNULL(ext.cFree4, '') AS cFree4,
ISNULL(ext.cFree5, '') AS cFree5,
ISNULL(ext.cFree6, '') AS cFree6,
ISNULL(ext.cFree7, '') AS cFree7,
ISNULL(ext.cFree8, '') AS cFree8,
ISNULL(ext.cFree9, '') AS cFree9,
ISNULL(ext.cFree10, '') AS cFree10,
a.MUSER AS [User],
a.MTIME AS [MTime]
FROM {1}
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSWarehouse wh ON a.ToWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE {2} ";
}
else
{
// sql = @"SELECT a.ID,
// {0}
//aply.sumQty,aply.sumIsQty,
// convert(varchar(100),'') AS LocationCode,
// convert(varchar(100),'') AS LotNo,
// convert(varchar(10),'') AS ToWarehouseCode,
// 0 AS LocationQty,
// 0 AS isMatched,
// a.InvCode,
// inv.InvName,
// inv.InvStd,
// a.Quantity,
// inv.InvUnit,
// a.Amount,
// a.WHCode,
// inv.AmountUnit,
// wh.WarehouseName AS WHName,
// (select a.F_EnabledMark from Sys_SRM_ItemsDetail a
// inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
// where b.F_id='4f733e37-445b-4534-8ec0-9f88d0842381') AS TransEnable,
// ISNULL(ext.ProjectCode, '') AS ProjectCode,
// a.ExtensionID,
// CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
// ISNULL(ext.Version, '') AS Version,
// ISNULL(ext.Brand, '') AS Brand,
// ISNULL(ext.cFree1, '') AS cFree1,
// ISNULL(ext.cFree2, '') AS cFree2,
// ISNULL(ext.cFree3, '') AS cFree3,
// ISNULL(ext.cFree4, '') AS cFree4,
// ISNULL(ext.cFree5, '') AS cFree5,
// ISNULL(ext.cFree6, '') AS cFree6,
// ISNULL(ext.cFree7, '') AS cFree7,
// ISNULL(ext.cFree8, '') AS cFree8,
// ISNULL(ext.cFree9, '') AS cFree9,
// ISNULL(ext.cFree10, '') AS cFree10,
// ISNULL(inv.EATTRIBUTE1, '') AS EATTRIBUTE1,
// a.MUSER AS [User],
// a.MTIME AS [MTime]
// {4}
// FROM {1}
// INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
// INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
// LEFT JOIN ICSWarehouse wh ON a.WHCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
// LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WHCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
// WHERE {2} {5} {6}";
sql = @"SELECT DISTINCT isnull(a.EATTRIBUTE8,'') AS ProjectName,isnull(a.EATTRIBUTE3,'') AS VenCode,
{0}
FROM {1}
WHERE {2} ";
}
string Picksql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
c.Code,
c.InvCode,
c.InvName,
c.InvStd,
c.InvUnit,
FLOOR(c.iQuantity) AS iQuantity,
d.WarehouseCode,
d.LocationCode,
d.LotNO,
FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
CONVERT(varchar(100),d.MTIME, 23) MTIME,
FLOOR(f.QTYTotal) QTYTotal INTO #temp
FROM
({0}) c
LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND ((LEN(ISNULL(c.WHCode,''))<=0) OR (LEN(ISNULL(c.WHCode,''))>0) AND c.WhCode=d.WarehouseCode) AND d.WorkPoint='{1}' AND d.Quantity>0
left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{1}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
DECLARE @ItemCode VARCHAR(50),
@QTY DECIMAL(18,3),
@ItemCodeCurrent VARCHAR(50),
@QTYCurrent DECIMAL(18,3),
@iQuantityCurrent DECIMAL(18,3),
@CanDelete BIT,
@Row INT,
@rowCurrent INT
SET @Row = @@rowcount
SET @rowCurrent=1
SET @CanDelete=0
SET @ItemCode=''
WHILE @rowCurrent<=@Row
BEGIN
SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
PRINT(@rowCurrent)
IF @ItemCode<>@ItemCodeCurrent
BEGIN
SET @ItemCode=@ItemCodeCurrent
SET @QTY=0
SET @CanDelete=0
END
IF @CanDelete=1
BEGIN
DELETE FROM #temp WHERE rowNo=@rowCurrent
SET @rowCurrent += 1
CONTINUE
END
SET @QTY += @QTYCurrent
IF @QTY>=@iQuantityCurrent
BEGIN
SET @CanDelete=1
END
SET @rowCurrent += 1
END
SELECT * FROM #temp
DROP TABLE #temp
";
#endregion
bool isDeliveryNotice = false; //送货、到货、含委外
string columns = string.Empty; //查询源头单据表的特殊列名
string tableName = string.Empty; //查询源头单据表名
string where = string.Empty; //查询源头单据的过滤条件
string order = string.Empty; //查询源头单据的过滤条件
string invWhere = ""; //查询特殊物料要求的过滤条件
bool isMerge = false; //合并发料
string columnsMerge = string.Empty; //合并发料查询源头单据表的特殊列名
string tableNameMerge = string.Empty; //合并发料查询源头单据表名
string sqls = string.Empty;
string sqlCheckSign = "";
string isRTOut = "0";
string isPN = "0";
string whcode = "";
string EATTRIBUTE = "";
DataTable flag = null;
#region 检料表信息
//enableCode = "";
//excessQtySql = "";
if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
{
enableCode = "Over001";
excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
#region 工单备料sql
sqls = @" SELECT
c.MOCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
b.InvUnit,
a.ExtensionID
FROM
ICSMOPick a
inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.MOApply.GetDescription())
{
enableCode = "Over002";
excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
#region 工单领料SQL
sqls = @" select
a.ApplyCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
FROM
ICSMOApply a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.MOIssue.GetDescription())
{
enableCode = "Over003";
excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
#region 工单材料出库SQL
sqls = @" select
a.IssueCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
FROM
ICSMOIssue a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription() || TransType == TransTypeEnum.RTOutsourcingIssueDoc.GetDescription())
{
enableCode = "Over004";
excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
#region 委外备料SQL
sqls = @" select
c.OOCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
FROM
ICSOOPick a
left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.OOApply.GetDescription())
{
enableCode = "Over005";
excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
#region 委外领料SQL
sqls = @" select
a.ApplyCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
FROM
ICSOApply a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.OOIssue.GetDescription())
{
//enableCode = "Over006";
excessQtySql = "";
#region 委外材料出库SQL
sqls = @" select
a.IssueCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
FROM
ICSOIssue a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
{
enableCode = "";
excessQtySql = "";
#region 销售发货SQL
sqls = @" select
a.SDNCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
FROM
ICSSDN a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
{
enableCode = "";
excessQtySql = "";
#region 其它出库SQL
sqls = @" select
a.OutCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
FROM
ICSOtherOut a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
{
enableCode = "";
excessQtySql = "";
#region 借用SQL
sqls = @"select
a.BrrowCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
FROM
ICSBrrow a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
{
enableCode = "";
excessQtySql = "";
#region 物料调拨
sqls = @" select
a.TransferNO as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.FromWarehouseCode as WhCode,
a.ExtensionID
FROM
ICSTransfer a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID";
#endregion
}
if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
{
enableCode = "";
excessQtySql = "";
#region 两步调出
sqls = @"select
a.OutCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WHCode ,
a.ExtensionID
from ICSOtherOut a
INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID";
#endregion
}
#endregion
#region 出库
#region 采购退货
if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
{
isDeliveryNotice = true;
columns = @"a.DNCode AS TransCode,
a.DNDetailID AS DetailID,
a.DNType AS Type,
a.Sequence AS TransSequence,
ISNULL(a.RCVQuantity,0) AS IssueQuantity,
a.Quantity,
a.Amount,
'' AS CusName,
a.MUSER AS [User],
a.MTIME AS [MTime],";
tableName = @"ICSDeliveryNotice a
LEFT JOIN (SELECT SUM(Quantity) AS sumQty,SUM(RCVQuantity) AS sumIsQty,WorkPoint,DNCode from ICSDeliveryNotice GROUP BY WorkPoint,DNCode) aply ON aply.WorkPoint=b.WorkPoint AND aply.DNCode=b.DNCode";
where = @" a.DNCode='{0}' AND a.WorkPoint='{1}' AND a.DNType='2' AND a.Status<>'3'";
}
#region 采购退货(采购订单)
else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegativePo.GetDescription())
{
isDeliveryNotice = true;
columns = @"a.DNCode AS TransCode,
a.DNDetailID AS DetailID,
a.DNType AS Type,
a.Sequence AS TransSequence,
a.Quantity - a.RCVQuantity AS IssueQuantity,
a.Quantity,
a.Amount,
'' AS CusName,
a.MUSER AS [User],
a.MTIME AS [MTime],";
tableName = @"ICSDeliveryNotice a ";
where = @" a.DNCode='{0}' AND a.WorkPoint='{1}' AND a.DNType='1' AND a.Status<>'3'";
}
#endregion
#endregion
//#region 工单关联
//else if (TransType == TransTypeEnum.ICSMOReceive.GetDescription())
//{
// isDeliveryNotice = true;
// columns = @"a.MOCode AS TransCode,
// a.Sequence AS TransSequence,";
// tableName = @"ICSMO a ";
// where = @" a.MOCode='{0}' AND a.WorkPoint='{1}' and a.ERPStatus<>'3'";
//}
//#endregion
#region 委外发料(合并发料)
else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription() || TransType == TransTypeEnum.RTOutsourcingIssueDoc.GetDescription())
{
if (JsonData.IsRTOut == "1")
{
isRTOut = "1";
}
else
{
isRTOut = "0";
}
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode004' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+b.OOCode AS TransCode,
a.PickID AS DetailID,
a.SupplyType AS Type,
b.Sequence+'~'+a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSOOPick a
INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"b.OOCode AS TransCode";
tableName = @"ICSOOPick a
INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
LEFT JOIN (SELECT SUM(a.Quantity) AS sumQty,SUM(a.IssueQuantity) AS sumIsQty,a.WorkPoint,b.OOCode from ICSOOPick a
INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint GROUP BY a.WorkPoint,b.OOCode) aply ON aply.WorkPoint=b.WorkPoint AND aply.OOCode=b.OOCode";
//where = @" b.OOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.Status<>'3' and isnull(a.EATTRIBUTE1,'')<>'1' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
if (JsonData.TransCode == "")
{
where = @" a.WorkPoint='{1}' AND a.SupplyType='3' AND b.Status<>'3' and isnull(a.EATTRIBUTE1,'')<>'1' ";
}
else
{
where = @" b.OOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.Status<>'3' and isnull(a.EATTRIBUTE1,'')<>'1' ";
}
if (JsonData.TransSelect == "当天单据")
{
where += @" and a.mtime >= CAST(GETDATE() AS DATE)
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
}
else if (JsonData.TransSelect == "7天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -7, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
}
else if (JsonData.TransSelect == "30天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -30, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
}
else if (JsonData.TransSelect == "已完成")
{
where += @" AND a.Quantity-ISNULL(a.IssueQuantity,0)=0";
}
else if (JsonData.TransSelect == "未完成")
{
where += @" AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
}
order = @"order by b.OOCode asc";
}
#endregion
#region 委外退货
else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
{
isDeliveryNotice = true;
columns = @"a.ODNCode AS TransCode,";
tableName = @"ICSODeliveryNotice a
LEFT JOIN (SELECT SUM(Quantity) AS sumQty,SUM(RCVQuantity) AS sumIsQty,WorkPoint,ODNCode from ICSODeliveryNotice GROUP BY WorkPoint,ODNCode) aply ON aply.WorkPoint=a.WorkPoint AND aply.ODNCode=a.ODNCode";
//where = @" a.ODNCode='{0}' AND a.WorkPoint='{1}' AND a.ODNType='2' AND a.Status<>'3'";
if (JsonData.TransCode == "")
{
where = @" a.WorkPoint='{1}' AND a.ODNType='2' AND a.Status<>'3'";
}
else
{
where = @"a.ODNCode='{0}' AND a.WorkPoint='{1}' AND a.ODNType='2' AND a.Status<>'3'";
}
if (JsonData.TransSelect == "当天单据")
{
where += @" and a.mtime >= CAST(GETDATE() AS DATE)
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
else if (JsonData.TransSelect == "7天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -7, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
else if (JsonData.TransSelect == "30天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -30, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
else if (JsonData.TransSelect == "已完成")
{
where += @" AND a.Quantity-ISNULL(a.RCVQuantity,0)=0";
}
else if (JsonData.TransSelect == "未完成")
{
where += @" AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
order = @"order by a.ODNCode asc";
}
#endregion
#region 委外退货(委外采购订单)
else if (TransType == TransTypeEnum.OutsourcingReturnBackPo.GetDescription())
{
isDeliveryNotice = true;
columns = @"a.ODNCode AS TransCode,
a.ODNDetailID AS DetailID,
a.ODNType AS Type,
a.Sequence AS TransSequence,
a.Quantity - ISNULL(a.RCVQuantity,0) AS IssueQuantity,
a.Quantity,
a.Amount,
'' AS CusName,
a.MUSER AS [User],
a.MTIME AS [MTime],";
tableName = @"ICSODeliveryNotice a ";
where = @" a.ODNCode='{0}' AND a.WorkPoint='{1}' AND a.ODNType='1' AND a.Status<>'3'";
}
#endregion
#region 生产发料(合并发料)
else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription() || TransType == TransTypeEnum.JHMOIssueDoc.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode001' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+b.MOCode AS TransCode,
a.PickID AS DetailID,
a.SupplyType AS Type,
'' AS CusName,
b.Sequence+'~'+a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"b.MOCode AS TransCode,
a.PickID AS DetailID,
a.SupplyType AS Type,
'' AS CusName,
b.Sequence+'~'+a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,
ISNULL(a.EATTRIBUTE3, isnull(A.Quantity,0)) as DHexcessQty,";
tableName = @"ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint ";
where = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1'
AND ((@ExcludeEnable=1 AND dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{2}', 2, 2,'')-ISNULL(a.IssueQuantity,0)>0) OR (@ExcludeEnable=0 OR @ExcludeEnable IS NULL)) ";
invWhere = DBHelper.SearchConditonGet("Trans_btnInvOut", JsonData.User, cmd);
#region 锐腾杂发控制线边仓发料
DataTable rtdt = null;
string rtsql = @"select a.F_ItemCode,a.F_Define1 from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_id='d51a7d1a-cc8a-4b8e-b306-d4ef3a108549' and a.F_EnabledMark='1' AND a.F_ItemCode='{0}'";
rtsql = string.Format(rtsql, JsonData.User);
rtdt = DBHelper.SQlReturnData(rtsql, cmd);
if (rtdt != null && rtdt.Rows.Count > 0)
{
for (int i = 0; i < rtdt.Rows.Count; i++)
{
whcode = rtdt.Rows[i]["F_Define1"].ToString();
}
}
if (whcode != "")
{
where = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1' and a.WHCode in ({2})";
}
#endregion
}
#endregion
#region 生产发料——自动出库
else if (TransType == TransTypeEnum.MOIssueAutoDoc.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode001' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+b.MOCode AS TransCode,
a.PickID AS DetailID,
a.SupplyType AS Type,
'' AS CusName,
b.Sequence+'~'+a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"b.MOCode AS TransCode,
a.PickID AS DetailID,
a.SupplyType AS Type,
'' AS CusName,
b.Sequence+'~'+a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,
ISNULL(a.EATTRIBUTE3, isnull(A.Quantity,0)) as DHexcessQty,";
tableName = @"ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint ";
where = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1'
AND ((@ExcludeEnable=1 AND dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{2}', 2, 2,'')-ISNULL(a.IssueQuantity,0)>0) OR (@ExcludeEnable=0 OR @ExcludeEnable IS NULL)) ";
invWhere = DBHelper.SearchConditonGet("Trans_btnInvOutAuto", JsonData.User, cmd);
}
#endregion
#region 销售出库(合并发料)
else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode007' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.SDNCode AS TransCode,
a.SDNDetailID AS DetailID,
a.SOCode,
a.Type,
'' AS CusName,
a.Sequence AS TransSequence,
ISNULL(a.SDNQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSSDN a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.SDNCode AS TransCode,
a.SDNDetailID AS DetailID,
a.SOCode,
a.Type,
'' AS CusName,
a.Sequence AS TransSequence,
ISNULL(a.SDNQuantity,0) AS IssueQuantity,";
tableName = @"ICSSDN a ";
where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3'
AND a.Quantity-ISNULL(a.SDNQuantity,0)>0";
}
#endregion
#region 销售发货单-快递单
else if (TransType == TransTypeEnum.SalesBindCourierDoc.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode007' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.SDNCode AS TransCode,
a.SDNDetailID AS DetailID,
a.SOCode,
a.Type,
'' AS CusName,
a.Sequence AS TransSequence,
ISNULL(a.SDNQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSSDN a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.SDNCode AS TransCode,
a.SDNDetailID AS DetailID,
a.SOCode,
a.Type,
'' AS CusName,
a.Sequence AS TransSequence,
a.EATTRIBUTE3 AS CourierCode,
ISNULL(a.SDNQuantity,0) AS IssueQuantity,";
tableName = @"ICSSDN a ";
where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3'";
}
#endregion
#region 销售出库-出库单(合并发料)
else if (TransType == TransTypeEnum.SalesShipmentOutDoc.GetDescription() || TransType == TransTypeEnum.JHSalesShipmentOutDoc.GetDescription())
{
if (DBHelper.IsPNU9())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode013' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.SSDCode AS TransCode,
a.SSDDetailID AS DetailID,
isnull(a.EATTRIBUTE3,'') AS FDQuantity,
a.SDNCode,
a.Type,a.CusName,
a.Sequence AS TransSequence,
ISNULL(a.SSDQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSSSD a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.SSDCode AS TransCode";
tableName = @"ICSSSD a
--INNER JOIN ICSSO b on a.SDNCode=b.SOcode and a.SDNSequence=b.Sequence and a.WorkPoint=b.WorkPoint
LEFT JOIN (SELECT SUM(Quantity) AS sumQty,SUM(SSDQuantity) AS sumIsQty,WorkPoint,SSDCode from ICSSSD GROUP BY WorkPoint,SSDCode) aply ON aply.WorkPoint=a.WorkPoint AND aply.SSDCode=a.SSDCode";
//where = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' AND a.Quantity-a.SSDQuantity>0";
if (JsonData.TransCode == "")
{
where = @" a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' ";
}
else
{
where = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' ";
}
if (JsonData.TransSelect == "当天单据")
{
where += @" and a.mtime >= CAST(GETDATE() AS DATE)
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.SSDQuantity,0)>0";
}
else if (JsonData.TransSelect == "7天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -7, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.SSDQuantity,0)>0";
}
else if (JsonData.TransSelect == "30天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -30, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.SSDQuantity,0)>0";
}
else if (JsonData.TransSelect == "已完成")
{
where += @" AND a.Quantity-ISNULL(a.SSDQuantity,0)=0";
}
else if (JsonData.TransSelect == "未完成")
{
where += @" AND a.Quantity-ISNULL(a.SSDQuantity,0)>0";
}
order = @"order by a.SSDCode asc";
}
else
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode013' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.SSDCode AS TransCode,
a.SSDDetailID AS DetailID,
'' AS FDQuantity,
a.SDNCode,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.SSDQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSSSD a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.SSDCode AS TransCode,
a.SSDDetailID AS DetailID,
'' AS FDQuantity,
a.SDNCode,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.SSDQuantity,0) AS IssueQuantity,";
tableName = @"ICSSSD a ";
where = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' AND a.Quantity-a.SSDQuantity>0";
}
}
#endregion
#region 盘点
else if (TransType == TransTypeEnum.Check.GetDescription())
{
#region SLQ
sql = @"SELECT a.ID,
{0}
a.Quantity,
a.SelectLevel AS LocationCode,
a.Amount,
a.MUSER AS [User],
a.MTIME AS [MTime]
FROM {1}
WHERE {2} ";
#endregion
columns = @"a.CheckCode AS TransCode,
a.ID,
'' AS Type,";
tableName = @"ICSCheck a ";
where = @" a.CheckCode='{0}' AND a.WorkPoint='{1}' ";
}
#endregion
#region 一步调拨(合并发料)
else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
{
if (JsonData.IsPN == "1")
{
isPN = "1";
}
else
{
isPN = "0";
}
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode009' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
string Wsql = @"select ColumnCode from ICSColumnEnable where TableCode='ICSTransfer' and Enable='1' and WorkPoint='{0}'";
DataTable chekdt = DBHelper.SQlReturnData(Wsql, cmd);
if (chekdt.Rows.Count > 0)
{
EATTRIBUTE = "a." + chekdt.Rows[0]["ColumnCode"].ToString();
}
if (!EATTRIBUTE.Equals(""))
{
columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
'' AS CusName,
'" + EATTRIBUTE + @" as NewWorkPoint,'
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
}
else
{
columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,
'' AS CusName,
a.Sequence AS TransSequence,
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
}
tableNameMerge = @"ICSTransfer a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
#region SLQ
sql = @"SELECT a.ID,
aply.sumQty,aply.sumIsQty,
{0}
convert(varchar(100),'') AS LocationCode,
convert(varchar(100),'') AS LotNo,
isnull(a.EATTRIBUTE3,'') AS ToWorkPoint,
0 AS LocationQty,
0 AS isMatched,
a.InvCode,
inv.InvName,
inv.InvStd,
a.Quantity,
inv.InvUnit,
a.Amount,
'' AS CusName,
a.FromWarehouseCode AS WHCode,
inv.AmountUnit,
wh.WarehouseName AS WHName,
a.ExtensionID,
ext.ProjectCode,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MTIME AS [MTime]
FROM {1}
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE {2} ";
#endregion
if (!EATTRIBUTE.Equals(""))
{
columns = @"a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
'" + EATTRIBUTE + @" as NewWorkPoint,'
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
}
else
{
columns = @"a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
}
tableName = @"ICSTransfer a
LEFT JOIN (SELECT SUM(Quantity) AS sumQty,SUM(TransferQuantity) AS sumIsQty,WorkPoint,TransferNO from ICSTransfer GROUP BY WorkPoint,TransferNO) aply ON aply.WorkPoint=a.WorkPoint AND aply.TransferNO=a.TransferNO";
if (JsonData.TransCode == "")
{
where = @" a.WorkPoint='{1}' AND a.Status<>'3'";
}
else
{
if (isPN == "1")
{
where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' AND a.Status<>'3' and a.type='3'";
}
else
{
where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' AND a.Status<>'3'";
}
}
if (JsonData.TransSelect == "当天单据")
{
where += @" and a.mtime >= CAST(GETDATE() AS DATE)
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.TransferQuantity,0)>0";
}
else if (JsonData.TransSelect == "7天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -7, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.TransferQuantity,0)>0";
}
else if (JsonData.TransSelect == "30天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -30, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.TransferQuantity,0)>0";
}
else if (JsonData.TransSelect == "已完成")
{
where += @" AND a.Quantity-ISNULL(a.TransferQuantity,0)=0";
}
else if (JsonData.TransSelect == "未完成")
{
where += @" AND a.Quantity-ISNULL(a.TransferQuantity,0)>0";
}
order = @"order by a.TransferNO asc";
}
#endregion
#region 物料调拨-自动
else if (TransType == TransTypeEnum.OneStepTransferDocAuto.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode009' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
string Wsql = @"select ColumnCode from ICSColumnEnable where TableCode='ICSTransfer' and Enable='1' and WorkPoint='{0}'";
DataTable chekdt = DBHelper.SQlReturnData(Wsql, cmd);
if (chekdt.Rows.Count > 0)
{
EATTRIBUTE = "a." + chekdt.Rows[0]["ColumnCode"].ToString();
}
if (!EATTRIBUTE.Equals(""))
{
columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
'" + EATTRIBUTE + @" as NewWorkPoint,'
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
}
else
{
columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
}
tableNameMerge = @"ICSTransfer a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
#region SLQ
sql = @"SELECT a.ID,
{0}
convert(varchar(100),'') AS LocationCode,
convert(varchar(100),'') AS LotNo,
0 AS LocationQty,
0 AS isMatched,
a.InvCode,
inv.InvName,
inv.InvStd,
a.Quantity,
inv.InvUnit,
a.Amount,
a.FromWarehouseCode AS WHCode,
inv.AmountUnit,
wh.WarehouseName AS WHName,
a.ExtensionID,
ext.ProjectCode,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MTIME AS [MTime]
FROM {1}
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
WHERE {2} {5} ";
#endregion
if (!EATTRIBUTE.Equals(""))
{
columns = @"a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
'" + EATTRIBUTE + @" as NewWorkPoint,'
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
}
else
{
columns = @"a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
}
tableName = @"ICSTransfer a ";
where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' AND a.Status<>'3' ";
invWhere = DBHelper.SearchConditonGet("Trans_btnInvTransAuto", JsonData.User, cmd);
}
#endregion
#region 调拨申请单(领料)
else if (TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription())
{
if (JsonData.IsPN == "1")
{
isPN = "1";
}
else
{
isPN = "0";
}
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,isnull(a.EATTRIBUTE29,'') AS OutWorkPoint,isnull(a.EATTRIBUTE30,'') AS InWorkPoint,
a.Sequence AS TransSequence,
'' AS CusName,
ISNULL(a.TransferQuantity,0) AS IssueQuantity,
a.ToWarehouseCode,";
tableNameMerge = @"ICSTransferApplication a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
#region SLQ
sql = @"SELECT DISTINCT
{0}
FROM {1}
WHERE {2} ";
#endregion
columns = @"a.TransferNO AS TransCode";
tableName = @"ICSTransferApplication a
LEFT JOIN (SELECT SUM(Quantity) AS sumQty,SUM(TransferQuantity) AS sumIsQty,WorkPoint,TransferNO from ICSTransferApplication GROUP BY WorkPoint,TransferNO) aply ON aply.WorkPoint=a.WorkPoint AND aply.TransferNO=a.TransferNO";
if (isPN == "1")
{
if (JsonData.TransCode == "")
{
where = @" a.WorkPoint='{1}' AND a.Status<>'3' ";
}
else
{
where = @" a.TransferNO='{0}' AND a.Status='2' AND a.Status<>'3'";
}
if (JsonData.TransSelect == "当天单据")
{
where += @" and a.mtime >= CAST(GETDATE() AS DATE)
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.TransferQuantity,0)>0";
}
else if (JsonData.TransSelect == "7天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -7, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.TransferQuantity,0)>0";
}
else if (JsonData.TransSelect == "30天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -30, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.TransferQuantity,0)>0";
}
else if (JsonData.TransSelect == "已完成")
{
where += @" AND a.Quantity-ISNULL(a.TransferQuantity,0)=0";
}
else if (JsonData.TransSelect == "未完成")
{
where += @" AND a.Quantity-ISNULL(a.TransferQuantity,0)>0";
}
order = @"order by a.TransferNO asc";
}
else
{
if (JsonData.TransCode == "")
{
where = @" a.WorkPoint='{1}' AND a.Status<>'3' ";
}
else
{
where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='2' AND a.Status<>'3'";
}
if (JsonData.TransSelect == "当天单据")
{
where += @" and a.mtime >= CAST(GETDATE() AS DATE)
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.TransferQuantity,0)>0";
}
else if (JsonData.TransSelect == "7天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -7, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.TransferQuantity,0)>0";
}
else if (JsonData.TransSelect == "30天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -30, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.TransferQuantity,0)>0";
}
else if (JsonData.TransSelect == "已完成")
{
where += @" AND a.Quantity-ISNULL(a.TransferQuantity,0)=0";
}
else if (JsonData.TransSelect == "未完成")
{
where += @" AND a.Quantity-ISNULL(a.TransferQuantity,0)>0";
}
order = @"order by a.TransferNO asc";
}
}
#endregion
#region 调拨(合并发料)
else if (TransType == TransTypeEnum.StepTransferDocIn.GetDescription())
{
}
#endregion
#region 两步调出(合并发料)
else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode010' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
a.OutDetailID AS DetailID,
'' AS Type,
'' AS CusName,
a.Sequence AS TransSequence,
ISNULL(a.OutQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSOtherOut a
INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.OutCode AS TransCode,
a.OutDetailID AS DetailID,
'' AS Type,
'' AS CusName,
a.Sequence AS TransSequence,
ISNULL(a.OutQuantity,0) AS IssueQuantity,";
tableName = @"ICSOtherOut a
INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-a.OutQuantity>0";
}
#endregion
#region 其他出库(合并发料)
else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode008' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
a.OutDetailID AS DetailID,
'' AS Type,
'' AS CusName,
a.Sequence AS TransSequence,
ISNULL(a.OutQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSOtherOut a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.OutCode AS TransCode";
tableName = @"ICSOtherOut a
LEFT JOIN (SELECT SUM(Quantity) AS sumQty,SUM(OutQuantity) AS sumIsQty,WorkPoint,OutCode from ICSOtherOut GROUP BY WorkPoint,OutCode) aply ON aply.WorkPoint=a.WorkPoint AND aply.OutCode=a.OutCode";
// where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.OutQuantity, 0)>0";
if (JsonData.TransCode == "")
{
where = @" a.WorkPoint='{1}' AND a.Status<>'3'";
}
else
{
where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' ";
}
if (JsonData.TransSelect == "当天单据")
{
where += @" and a.mtime >= CAST(GETDATE() AS DATE)
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.OutQuantity,0)>0";
}
else if (JsonData.TransSelect == "7天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -7, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.OutQuantity,0)>0";
}
else if (JsonData.TransSelect == "30天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -30, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.OutQuantity,0)>0";
}
else if (JsonData.TransSelect == "已完成")
{
where += @" AND a.Quantity-ISNULL(a.OutQuantity,0)=0";
}
else if (JsonData.TransSelect == "未完成")
{
where += @" AND a.Quantity-ISNULL(a.OutQuantity,0)>0";
}
order = @"order by a.OutCode asc";
invWhere = DBHelper.SearchConditonGet("Trans_btnOtherOut", JsonData.User, cmd);
#region 锐腾杂发控制线边仓发料
DataTable rtdt = null;
string rtsql = @"select a.F_ItemCode,a.F_Define1 from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_id='d51a7d1a-cc8a-4b8e-b306-d4ef3a108549' and a.F_EnabledMark='1' AND a.F_ItemCode='{0}'";
rtsql = string.Format(rtsql, JsonData.User);
rtdt = DBHelper.SQlReturnData(rtsql, cmd);
if (rtdt != null && rtdt.Rows.Count > 0)
{
for (int i = 0; i < rtdt.Rows.Count; i++)
{
whcode = rtdt.Rows[i]["F_Define1"].ToString();
}
}
if (whcode != "")
{
where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.OutQuantity, 0)>0 and a.WHCode in ({2})";
}
#endregion
}
#endregion
#region 其他出库-自动出库
else if (TransType == TransTypeEnum.OtherOutAutoDoc.GetDescription())
{
sqlCheck += @"IF EXISTS (SELECT 1
FROM ICSOtherOut a
INNER JOIN ICSInventory inv ON inv.InvCode=a.InvCode AND inv.WorkPoint=a.WorkPoint
WHERE {2} " + DBHelper.SearchConditonGet("Trans_btnOtherOut", JsonData.User, cmd) + @")
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo530") + @"',16,1);
RETURN
END
";
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode008' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = false;
columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
a.OutDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.OutQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSOtherOut a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.OutCode AS TransCode,
a.OutDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.OutQuantity,0) AS IssueQuantity,";
tableName = @"ICSOtherOut a ";
where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.OutQuantity, 0)>0 ";
invWhere = DBHelper.SearchConditonGet("Trans_btnOtherOutAuto", JsonData.User, cmd);
}
#endregion
#region 红字其他入库
else if (TransType == TransTypeEnum.OtherInRedDoc.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode008' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.InCode AS TransCode,
a.InDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.InQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSOtherIn a
INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.InCode AS TransCode,
a.InDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.InQuantity,0) AS IssueQuantity,";
tableName = @"ICSOtherIn a ";
where = @" a.InCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-a.InQuantity>0 AND a.Type='2'";
}
#endregion
#region 领料申请单发料(合并发料)
else if (TransType == TransTypeEnum.MOApply.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode002' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
a.ApplyDetailID AS DetailID,
a.Type,
'' AS CusName,
a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSMOApply a
INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.ApplyCode AS TransCode
";
tableName = @"ICSMOApply a
LEFT JOIN (SELECT SUM(Quantity) AS sumQty,SUM(IssueQuantity) AS sumIsQty,WorkPoint,ApplyCode from ICSMOApply GROUP BY WorkPoint,ApplyCode) aply ON aply.WorkPoint=a.WorkPoint AND aply.ApplyCode=a.ApplyCode";
if (JsonData.TransCode == "")
{
where = @" a.WorkPoint='{1}' AND a.Status<>'3' ";
}
else
{
where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' ";
}
if (JsonData.TransSelect == "当天单据")
{
where += @" and a.mtime >= CAST(GETDATE() AS DATE)
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
}
else if (JsonData.TransSelect == "7天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -7, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
}
else if (JsonData.TransSelect == "30天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -30, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
}
else if (JsonData.TransSelect == "已完成")
{
where += @" AND a.Quantity-ISNULL(a.IssueQuantity,0)=0";
}
else if (JsonData.TransSelect == "未完成")
{
where += @" AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
}
order = @"order by a.ApplyCode asc";
// 东辉增加备用字段
//受益部门(EATTRIBUTE)、单据类型EATTRIBUTE2、
//RD编号EATTRIBUTE5、项目编号EATTRIBUTE8、实际领用部门DepName、备注EATTRIBUTE11
if (DBHelper.IsU9())
{
columns += @"isnull(a.EATTRIBUTE15,'') as EATTRIBUTE1,
isnull(a.EATTRIBUTE17,'') as EATTRIBUTE2,
isnull(a.EATTRIBUTE5,'') as EATTRIBUTE5,
isnull(a.EATTRIBUTE8,'') as EATTRIBUTE8,
isnull(its.F_itemName,'') as DepName,
isnull(a.EATTRIBUTE11,'') as EATTRIBUTE11,
isnull(lotinfo.qty,0) as invLotQty,
";
tableName = @"ICSMOApply a
LEFT join Sys_SRM_Items it on it.F_EnCode = 'LYDep'
LEFT join Sys_SRM_ItemsDetail its on it.F_id = its.f_itemid and its.F_itemcode = a.DepCode
left join (select invcode,sum(Quantity) as qty from icswarehouselotinfo group by invcode) lotinfo on a.invcode = lotinfo.invcode
";
where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
sqlCheck += @"
DECLARE @status VARCHAR(20)
select top 1 @status = status from ICSMOApply where ApplyCode='" + JsonData.TransCode + @"'
IF(@status!=2)
BEGIN
RAISERROR('单据不是审核状态无法发料',16,1);
RETURN
END
";
}
}
#endregion
#region 补料申请单发料(合并发料)
else if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode012' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
a.ApplyDetailID AS DetailID,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSMOReplenishment a
INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.ReplenishmentCode AS TransCode,
a.ReplenishmentDetailID AS DetailID,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableName = @"ICSMOReplenishment a ";
where = @" a.ReplenishmentCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
}
#endregion
#region 委外领料申请单发料(合并发料)
else if (TransType == TransTypeEnum.OOApply.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode005' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
a.ApplyDetailID AS DetailID,
a.Type,
'' AS CusName,
a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSOApply a
INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.ApplyCode AS TransCode,
a.ApplyDetailID AS DetailID,
a.Type,
'' AS CusName,
a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableName = @"ICSOApply a ";
where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
}
#endregion
#region 开立材料出库(合并发料)
else if (TransType == TransTypeEnum.MOIssue.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode003' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
a.IssueDetailID AS DetailID,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSMOIssue a
INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.IssueCode AS TransCode,
a.IssueDetailID AS DetailID,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableName = @"ICSMOIssue a ";
where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
#region 锐腾杂发控制线边仓发料
DataTable rtdt = null;
string rtsql = @"select a.F_ItemCode,a.F_Define1 from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_id='d51a7d1a-cc8a-4b8e-b306-d4ef3a108549' and a.F_EnabledMark='1' AND a.F_ItemCode='{0}'";
rtsql = string.Format(rtsql, JsonData.User);
rtdt = DBHelper.SQlReturnData(rtsql, cmd);
if (rtdt != null && rtdt.Rows.Count > 0)
{
for (int i = 0; i < rtdt.Rows.Count; i++)
{
whcode = rtdt.Rows[i]["F_Define1"].ToString();
}
}
if (whcode != "")
{
where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0 and a.WHCode in ({2})";
}
#endregion
}
#endregion
#region 开立委外材料出库(合并发料)
else if (TransType == TransTypeEnum.OOIssue.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode006' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
a.IssueDetailID AS DetailID,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSOIssue a
INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.IssueCode AS TransCode,
a.IssueDetailID AS DetailID,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
tableName = @"ICSOIssue a ";
where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
}
#endregion
#region 开立红字入库单
else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
{
columns = @"a.RCVCode AS TransCode";
tableName = @"ICSPurchaseReceive a
LEFT JOIN (SELECT SUM(Quantity) AS sumQty,SUM(RCVQuantity) AS sumIsQty,WorkPoint,RCVCode from ICSPurchaseReceive GROUP BY WorkPoint,RCVCode) aply ON aply.WorkPoint=a.WorkPoint AND aply.RCVCode=a.RCVCode";
//where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3'";
if (JsonData.TransCode == "")
{
where = @" a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3'";
}
else
{
where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3' ";
}
if (JsonData.TransSelect == "当天单据")
{
where += @" and a.mtime >= CAST(GETDATE() AS DATE)
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
else if (JsonData.TransSelect == "7天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -7, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
else if (JsonData.TransSelect == "30天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -30, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
else if (JsonData.TransSelect == "已完成")
{
where += @" AND a.Quantity-ISNULL(a.RCVQuantity,0)=0";
}
else if (JsonData.TransSelect == "未完成")
{
where += @" AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
order = @"order by a.RCVCode asc";
}
#endregion
#region 开立委外红字入库单
else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
{
columns = @"a.RCVCode AS TransCode";
tableName = @"ICSOutsourcingReceive a
LEFT JOIN (SELECT SUM(Quantity) AS sumQty,SUM(RCVQuantity) AS sumIsQty,WorkPoint,RCVCode from ICSOutsourcingReceive GROUP BY WorkPoint,RCVCode) aply ON aply.WorkPoint=a.WorkPoint AND aply.RCVCode=a.RCVCode";
//where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3'";
if (JsonData.TransCode == "")
{
where = @" a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3'";
}
else
{
where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3' ";
}
if (JsonData.TransSelect == "当天单据")
{
where += @" and a.mtime >= CAST(GETDATE() AS DATE)
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
else if (JsonData.TransSelect == "7天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -7, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
else if (JsonData.TransSelect == "30天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -30, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
else if (JsonData.TransSelect == "已完成")
{
where += @" AND a.Quantity-ISNULL(a.RCVQuantity,0)=0";
}
else if (JsonData.TransSelect == "未完成")
{
where += @" AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
order = @"order by a.RCVCode asc";
}
#endregion
#region 借用(合并发料)
else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
{
sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode011' and enable = '1'";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
isMerge = true;
columnsMerge = @"mer.MergeID+'~'+a.BrrowCode AS TransCode,
a.BrrowDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.BrrowQuantity,0) AS IssueQuantity,";
tableNameMerge = @"ICSBrrow a
INNER JOIN ICSMOPickMerge mer ON a.BrrowDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
columns = @"a.BrrowCode AS TransCode,
a.BrrowDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.BrrowQuantity,0) AS IssueQuantity,";
tableName = @"ICSBrrow a ";
where = @" a.BrrowCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.BrrowQuantity,0)>0";
}
#endregion
#region 送货单
else if (TransType == TransTypeEnum.ASN.GetDescription())
{
isDeliveryNotice = true;
columns = @"asn.ASNCode AS TransCode,
asn.ID AS DetailID,
asn.LotNo,
'' AS Type,
asn.Sequence AS TransSequence,
ISNULL(asn.DNQuantity,0) AS IssueQuantity,
asn.Quantity,
asn.Quantity*(a.Amount/a.Quantity) AS Amount,
asn.MUSER AS [User],
asn.MTIME AS [MTime],
--东辉新增
case when its.F_Define1 is not null then '1' else '0' end as needScan,
--海格自定义档案 急料期限
case when DATEDIFF(hour, getDate(), isnull(potemp.PlanArriveDate,'2000-01-01 00:00:00'))<=(isnull(itts.F_Define1,0)*24) then 1 else 0 end as isUrgency,invinfo.InvIQC,
case when invinfo.INVIQC =1 then isnull(ins.enable,0) else '1' end as inspection,
POQuantity , YDNQuantity , (POQuantity-YDNQuantity) as NDNQuantity,";
tableName = @"ICSInventoryLot a
INNER JOIN ICSASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint
LEFT join Sys_SRM_Items it on it.F_EnCode = 'Arrive_inv'
LEFT join Sys_SRM_ItemsDetail its on it.F_id = its.f_itemid and SUBSTRING(a.InvCode, 1, 1) = its.F_Define1
LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1
LEFT join Sys_SRM_Items itt on itt.F_EnCode = 'Urgent001'
LEFT join Sys_SRM_ItemsDetail itts on itt.F_id = itts.f_itemid -- itts.F_Define1
INNER JOIN ICSInventoryLotDetail lotdetail ON a.LotNo=lotdetail.LotNo AND a.WorkPoint=lotdetail.WorkPoint
INNER JOIN ICSInventory invinfo on invinfo.invcode = a.invcode AND a.WorkPoint=invinfo.WorkPoint
LEFT join
(select c.Quantity as POQuantity ,SUM(a.DNQuantity) as YDNQuantity,c.pocode ,c.sequence,c.PlanArriveDate
from ICSASNDetail a
inner join ICSInventoryLotdetail b on a.lotno =b.lotno
inner join ICSPurchaseOrder c on b.transcode = c.pocode and b.transSequence = c.sequence
GROUP BY c.pocode ,c.sequence,c.Quantity,c.PlanArriveDate) potemp on lotdetail.transcode = potemp.pocode and lotdetail.transSequence = potemp.sequence
";
where = @" asn.ASNCode='{0}' AND a.WorkPoint='{1}' ";
}
#endregion
#region 委外送货单
else if (TransType == TransTypeEnum.OASN.GetDescription())
{
isDeliveryNotice = true;
columns = @"asn.OASNCode AS TransCode,
asn.ID AS DetailID,
asn.LotNo,
'' AS Type,
asn.Sequence AS TransSequence,
ISNULL(asn.ODNQuantity,0) AS IssueQuantity,
asn.Quantity,
asn.Quantity*(a.Amount/a.Quantity) AS Amount,
asn.MUSER AS [User],
asn.MTIME AS [MTime],";
tableName = @"ICSInventoryLot a
INNER JOIN ICSOASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint ";
where = @" asn.OASNCode='{0}' AND a.WorkPoint='{1}' ";
}
#endregion
#endregion
#region 入库
#region 采购入库
else if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
{
}
#endregion
#region 采购入库-入库单
else if (TransType == TransTypeEnum.PurchaseReceiveRevDoc.GetDescription())
{
columns = @"a.RCVCode AS TransCode";
tableName = @"ICSPurchaseReceive a
LEFT JOIN (SELECT SUM(Quantity) AS sumQty,SUM(RCVQuantity) AS sumIsQty,WorkPoint,RCVCode from ICSPurchaseReceive GROUP BY WorkPoint,RCVCode) aply ON aply.WorkPoint=a.WorkPoint AND aply.RCVCode=a.RCVCode";
//where = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' AND a.Quantity-a.SSDQuantity>0";
if (JsonData.TransCode == "")
{
where = @" a.WorkPoint='{1}' AND a.Status<>'3'";
}
else
{
where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' ";
}
if (JsonData.TransSelect == "当天单据")
{
where += @" and a.mtime >= CAST(GETDATE() AS DATE)
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
else if (JsonData.TransSelect == "7天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -7, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
else if (JsonData.TransSelect == "30天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -30, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
else if (JsonData.TransSelect == "已完成")
{
where += @" AND a.Quantity-ISNULL(a.RCVQuantity,0)=0";
}
else if (JsonData.TransSelect == "未完成")
{
where += @" AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
order = @"order by a.RCVCode asc";
}
#endregion
#region 委外入库-入库单
else if (TransType == TransTypeEnum.OutsourcingReceiveRevDoc.GetDescription())
{
columns = @"a.RCVCode AS TransCode";
tableName = @"ICSOutsourcingReceive a
LEFT JOIN (SELECT SUM(Quantity) AS sumQty,SUM(RCVQuantity) AS sumIsQty,WorkPoint,RCVCode from ICSOutsourcingReceive GROUP BY WorkPoint,RCVCode) aply ON aply.WorkPoint=a.WorkPoint AND aply.RCVCode=a.RCVCode";
//where = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' AND a.Quantity-a.SSDQuantity>0";
if (JsonData.TransCode == "")
{
where = @" a.WorkPoint='{1}' AND a.Status<>'3'";
}
else
{
where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' ";
}
if (JsonData.TransSelect == "当天单据")
{
where += @" and a.mtime >= CAST(GETDATE() AS DATE)
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
else if (JsonData.TransSelect == "7天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -7, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
else if (JsonData.TransSelect == "30天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -30, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
else if (JsonData.TransSelect == "已完成")
{
where += @" AND a.Quantity-ISNULL(a.RCVQuantity,0)=0";
}
else if (JsonData.TransSelect == "未完成")
{
where += @" AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
order = @"order by a.RCVCode asc";
}
#endregion
#region 审核的到货单
else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
{
}
#endregion
#region 采购拒收
else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
{
}
#endregion
#region 审核的委外到货单
else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
{
}
#endregion
#region 委外拒收
else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
{
}
#endregion
#region 委外入库
else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
{
}
#endregion
#region 生产退料
else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
|| TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
|| TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
{
#region SLQ
sql = @"SELECT DISTINCT
{0}
FROM {1}
WHERE {2} ";
#endregion
columns = @"a.ApplyNegCode AS TransCode";
tableName = @"ICSMOApplyNegDetail a
INNER JOIN ICSMOApplyNeg d ON a.ApplyNegCode=d.ApplyNegCode AND a.WorkPoint=d.WorkPoint
LEFT JOIN (SELECT SUM(Quantity) AS sumQty,SUM(IssueNegQuantity) AS sumIsQty,WorkPoint,ApplyNegCode from ICSMOApplyNegDetail GROUP BY WorkPoint,ApplyNegCode) aply ON aply.WorkPoint=a.WorkPoint AND aply.ApplyNegCode=a.ApplyNegCode";
//where = @" a.OApplyNegCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>a.IssueNegQuantity AND d.Status<>'3'";
if (JsonData.TransCode == "")
{
where = @" a.WorkPoint='{1}' AND d.Status<>'3'";
}
else
{
where = @" a.ApplyNegCode='{0}' AND a.WorkPoint='{1}' AND d.Status<>'3' ";
}
if (JsonData.TransSelect == "当天单据")
{
where += @" and a.mtime >= CAST(GETDATE() AS DATE)
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.IssueNegQuantity,0)>0";
}
else if (JsonData.TransSelect == "7天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -7, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.IssueNegQuantity,0)>0";
}
else if (JsonData.TransSelect == "30天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -30, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.IssueNegQuantity,0)>0";
}
else if (JsonData.TransSelect == "已完成")
{
where += @" AND a.Quantity-ISNULL(a.IssueNegQuantity,0)=0";
}
else if (JsonData.TransSelect == "未完成")
{
where += @" AND a.Quantity-ISNULL(a.IssueNegQuantity,0)>0";
}
order = @"order by a.ApplyNegCode asc";
}
#endregion
#region 委外退料
else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
{
#region SLQ
sql = @"SELECT DISTINCT
{0}
FROM {1}
WHERE {2} ";
#endregion
//columns = @"a.OApplyNegCode AS TransCode,
// a.Sequence AS TransSequence";
columns = @"a.OApplyNegCode AS TransCode";
tableName = @"ICSOApplyNegDetail a
INNER JOIN ICSOApplyNeg d ON a.OApplyNegCode=d.OApplyNegCode AND a.WorkPoint=d.WorkPoint
LEFT JOIN (SELECT SUM(Quantity) AS sumQty,SUM(IssueNegQuantity) AS sumIsQty,WorkPoint,OApplyNegCode from ICSOApplyNegDetail GROUP BY WorkPoint,OApplyNegCode) aply ON aply.WorkPoint=a.WorkPoint AND aply.OApplyNegCode=a.OApplyNegCode";
//where = @" a.OApplyNegCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>a.IssueNegQuantity AND d.Status<>'3'";
if (JsonData.TransCode == "")
{
where = @" a.WorkPoint='{1}' AND d.Status<>'3'";
}
else
{
where = @" a.OApplyNegCode='{0}' AND a.WorkPoint='{1}' AND d.Status<>'3' ";
}
if (JsonData.TransSelect == "当天单据")
{
where += @" and a.mtime >= CAST(GETDATE() AS DATE)
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.IssueNegQuantity,0)>0";
}
else if (JsonData.TransSelect == "7天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -7, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.IssueNegQuantity,0)>0";
}
else if (JsonData.TransSelect == "30天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -30, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.IssueNegQuantity,0)>0";
}
else if (JsonData.TransSelect == "已完成")
{
where += @" AND a.Quantity-ISNULL(a.IssueNegQuantity,0)=0";
}
else if (JsonData.TransSelect == "未完成")
{
where += @" AND a.Quantity-ISNULL(a.IssueNegQuantity,0)>0";
}
order = @"order by a.OApplyNegCode asc";
}
#endregion
#region 生产入库
else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
{
columns = @"a.MOCode AS TransCode";
tableName = @"ICSMO a
LEFT JOIN (SELECT SUM(Quantity) AS sumQty,SUM(RCVQuantity) AS sumIsQty,WorkPoint,MOCode from ICSMO GROUP BY WorkPoint,MOCode) aply ON aply.WorkPoint=a.WorkPoint AND aply.MOCode=a.MOCode";
//where = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' AND a.Quantity-a.SSDQuantity>0";
if (JsonData.TransCode == "")
{
where = @" a.WorkPoint='{1}' AND a.MOStatus<>'3'";
}
else
{
where = @" a.MOCode='{0}' AND a.WorkPoint='{1}' AND a.MOStatus<>'3' ";
}
if (JsonData.TransSelect == "当天单据")
{
where += @" and a.mtime >= CAST(GETDATE() AS DATE)
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
else if (JsonData.TransSelect == "7天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -7, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
else if (JsonData.TransSelect == "30天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -30, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
else if (JsonData.TransSelect == "已完成")
{
where += @" AND a.Quantity-ISNULL(a.RCVQuantity,0)=0";
}
else if (JsonData.TransSelect == "未完成")
{
where += @" AND a.Quantity-ISNULL(a.RCVQuantity,0)>0";
}
if (JsonData.WHCode != "")
{
where += @" and a.whcode='{3}'";
}
order = @"order by a.MOCode asc";
}
#endregion
#region 开立的生产入库单
else if (TransType == TransTypeEnum.ManufactureMESReceive.GetDescription())
{
columns = @"a.RCVCode AS TransCode,
a.RCVDetailID AS DetailID,
a.Type AS Type,
a.Sequence AS TransSequence,
a.SourceCode,
a.SourceSequence,
ISNULL(a.RCVQuantity,0) AS IssueQuantity,";
tableName = @"ICSManufactureReceive a ";
where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status='1' AND a.Quantity>ISNULL(a.RCVQuantity, 0)";
}
#endregion
#region 返工工单
else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
{
}
#endregion
#region 销售退货
else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
{
}
#endregion
#region 销售出库-红字出库单
else if (TransType == TransTypeEnum.SalesShipmentOutRedDoc.GetDescription())
{
//columns = @"a.SSDCode AS TransCode,
// a.SSDDetailID AS DetailID,
// a.SDNCode,
// a.Type,
// a.Sequence AS TransSequence,
// ISNULL(a.SSDQuantity,0) AS IssueQuantity,";
//tableName = @"ICSSSD a ";
//where = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status='1' AND a.Quantity-ISNULL(a.SSDQuantity,0)>0";
columns = @"a.SSDCode AS TransCode";
tableName = @"ICSSSD a
--INNER JOIN ICSSO b on a.SDNCode=b.SOcode and a.SDNSequence=b.Sequence and a.WorkPoint=b.WorkPoint
LEFT JOIN (SELECT SUM(Quantity) AS sumQty,SUM(SSDQuantity) AS sumIsQty,WorkPoint,SSDCode from ICSSSD GROUP BY WorkPoint,SSDCode) aply ON aply.WorkPoint=a.WorkPoint AND aply.SSDCode=a.SSDCode";
//where = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' AND a.Quantity-a.SSDQuantity>0";
if (JsonData.TransCode == "")
{
where = @" a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3' ";
}
else
{
where = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3' ";
}
if (JsonData.TransSelect == "当天单据")
{
where += @" and a.mtime >= CAST(GETDATE() AS DATE)
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.SSDQuantity,0)>0";
}
else if (JsonData.TransSelect == "7天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -7, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.SSDQuantity,0)>0";
}
else if (JsonData.TransSelect == "30天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -30, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.SSDQuantity,0)>0";
}
else if (JsonData.TransSelect == "已完成")
{
where += @" AND a.Quantity-ISNULL(a.SSDQuantity,0)=0";
}
else if (JsonData.TransSelect == "未完成")
{
where += @" AND a.Quantity-ISNULL(a.SSDQuantity,0)>0";
}
order = @"order by a.SSDCode asc";
}
#endregion
#region 销售出库-红字出库单原条码
else if (TransType == TransTypeEnum.SalesShipmentOutRedYuanDoc.GetDescription())
{
columns = @"a.SSDCode AS TransCode";
tableName = @"ICSSSD a ";
where = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status='1' AND a.Quantity-ISNULL(a.SSDQuantity,0)>0";
}
#endregion
#region 两步调入
else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
{
columns = @"a.InCode AS TransCode,
a.InDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.InQuantity,0) AS IssueQuantity,";
tableName = @"ICSOtherIn a
INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
where = @" a.InCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
}
#endregion
#region 锐腾两步调入
else if (TransType == TransTypeEnum.RTTwoStepTransferDocIn.GetDescription())
{
columns = @"a.TransferNO AS TransCode,
a.TransferDetailID AS DetailID,
'' AS Type,
a.Sequence AS TransSequence,
a.TransferQuantity AS IssueQuantity,";
tableName = @"ICSTransfer a ";
where = @" a.TransferNo='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
}
#endregion
#region 销售退货-原条码
else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
{
columns = @"a.SDNCode AS TransCode,
a.SOCode ,
a.SDNDetailID AS DetailID,
a.Type,
a.Sequence AS TransSequence,
ISNULL(a.SDNQuantity,0) AS IssueQuantity,";
tableName = @"ICSSDN a ";
where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3'";
}
#endregion
#region 其他入库
else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
{
columns = @"a.InCode AS TransCode";
tableName = @"ICSOtherIn a
LEFT JOIN (SELECT SUM(Quantity) AS sumQty,SUM(InQuantity) AS sumIsQty,WorkPoint,InCode from ICSOtherIn GROUP BY WorkPoint,InCode) aply ON aply.WorkPoint=a.WorkPoint AND aply.InCode=a.InCode";
//where = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' AND a.Quantity-a.SSDQuantity>0";
if (JsonData.TransCode == "")
{
where = @" a.WorkPoint='{1}' AND a.Status<>'3'";
}
else
{
where = @" a.InCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' ";
}
if (JsonData.TransSelect == "当天单据")
{
where += @" and a.mtime >= CAST(GETDATE() AS DATE)
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.InQuantity,0)>0";
}
else if (JsonData.TransSelect == "7天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -7, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.InQuantity,0)>0";
}
else if (JsonData.TransSelect == "30天内单据")
{
where += @" and a.mtime >= DATEADD(DAY, -30, CAST(GETDATE() AS DATE))
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) AND a.Quantity-ISNULL(a.InQuantity,0)>0";
}
else if (JsonData.TransSelect == "已完成")
{
where += @" AND a.Quantity-ISNULL(a.InQuantity,0)=0";
}
else if (JsonData.TransSelect == "未完成")
{
where += @" AND a.Quantity-ISNULL(a.InQuantity,0)>0";
}
order = @"order by a.InCode asc";
}
#endregion
#region 拆卸单
else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
{
columns = @"a.DABDOCCode AS TransCode,
a.DABDOCDetailID AS DetailID,
a.DABDOCType AS Type,
a.Sequence AS TransSequence,
ISNULL(a.DABDOCQuantity,0) AS IssueQuantity,";
tableName = @"ICSDisassemblyDoc a";
where = @" a.DABDOCCode='{0}' AND a.WorkPoint='{1}' AND a.DABDOCType='2' AND a.Status<>'3' ";
}
#endregion
#region 归还
else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
{
}
#endregion
#endregion
if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName) || string.IsNullOrWhiteSpace(where))
throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
#region 判断是否启用匹配库位
if ((flag != null && flag.Rows.Count > 0) || isRTOut == "1")
//if (true)
{
sql = @"select * into #maintemp from (" + sql + @")a
select * into #resulttemp from #maintemp
truncate table #resulttemp
select a.lotno,a.locationcode,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime,a.warehousecode,isnull(ext.ProjectCode,'')as ProjectCode, isnull(ext.Version,'')as Version,
isnull(ext.Brand,'')as Brand,
isnull(ext.cFree1,'')as cFree1,
isnull(ext.cFree2,'') cFree2,
isnull(ext.cFree3,'') cFree3,
isnull(ext.cFree4,'') cFree4,
isnull(ext.cFree5,'') cFree5,
isnull(ext.cFree6,'') cFree6,
isnull(ext.cFree7,'') cFree7,
isnull(ext.cFree8,'') cFree8,
isnull(ext.cFree9,'') cFree9,
isnull(ext.cFree10,'') cFree10,ISNULL(ext.BatchCode, '') BatchCode into #barcodetemp
from ICSWareHouseLotInfo a INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
LEFT JOIN
(select invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE from #maintemp
group by invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE) b on a.invcode = b.invcode
where (a.warehousecode = b.whcode or ISNULL(b.whcode,'')='') and a.Quantity-a.lockQuantity>0 and
((LEN(ISNULL(b.ProjectCode,''))<=0)or((LEN(ISNULL(b.ProjectCode,''))>0) and ext.ProjectCode = b.ProjectCode))
and ((LEN(ISNULL(b.Version,''))<=0)or((LEN(ISNULL(b.Version,''))>0) and ext.Version =b.Version)) and
((LEN(ISNULL(b.Brand,''))<=0)or ((LEN(ISNULL(b.Brand,''))>0) and ext.Brand =b.Brand)) and
((LEN(ISNULL(b.BatchCode,''))<=0)or((LEN(ISNULL(b.BatchCode,''))>0) and ext.BatchCode =b.BatchCode)) and
((LEN(ISNULL(b.cFree1,''))<=0)or((LEN(ISNULL(b.cFree1,''))>0) and ext.cFree1 =b.cFree1)) and
((LEN(ISNULL(b.cFree2,''))<=0)or((LEN(ISNULL(b.cFree2,''))>0) and ext.cFree2 =b.cFree2)) and
((LEN(ISNULL(b.cFree3,''))<=0)or((LEN(ISNULL(b.cFree3,''))>0) and ext.cFree3 =b.cFree3)) and
((LEN(ISNULL(b.cFree4,''))<=0)or((LEN(ISNULL(b.cFree4,''))>0) and ext.cFree4 =b.cFree4)) and
((LEN(ISNULL(b.cFree5,''))<=0)or((LEN(ISNULL(b.cFree5,''))>0) and ext.cFree5 =b.cFree5)) and
((LEN(ISNULL(b.cFree6,''))<=0)or((LEN(ISNULL(b.cFree6,''))>0) and ext.cFree6 =b.cFree6)) and
((LEN(ISNULL(b.cFree7,''))<=0)or((LEN(ISNULL(b.cFree7,''))>0) and ext.cFree7 =b.cFree7)) and
((LEN(ISNULL(b.cFree8,''))<=0)or((LEN(ISNULL(b.cFree8,''))>0) and ext.cFree8 =b.cFree8)) and
((LEN(ISNULL(b.cFree9,''))<=0)or((LEN(ISNULL(b.cFree9,''))>0) and ext.cFree9 =b.cFree9)) and
((LEN(ISNULL(b.cFree10,''))<=0)or((LEN(ISNULL(b.cFree10,''))>0) and ext.cFree10 =b.cFree10)) order by a.mtime
BEGIN
DECLARE @transSequence VARCHAR(50);--当前循环的行号
DECLARE @qty decimal(18, 4);--条码表数量
DECLARE @needqty decimal(18, 4);--本行所需数量
DECLARE @lotno VARCHAR(50);--本行所需数量
DECLARE @locationcode VARCHAR(50);--本行所在库位
DECLARE @WHCode VARCHAR(50);--本行所在仓库
DECLARE @invcode VARCHAR(50);--本行条码
DECLARE @mtime DATE;
DECLARE @issueQuantity decimal(18, 4);
DECLARE tempCursor CURSOR FOR (select transSequence from #maintemp); --创建游标tempCursor,并定义游标所指向的集合
OPEN tempCursor; --打开游标
FETCH NEXT FROM tempCursor INTO @transSequence; --游标读取下一个数据
WHILE @@fetch_status=0
BEGIN
select @needqty=Quantity,@issueQuantity=issueQuantity from #maintemp where transSequence = @transSequence
PRINT @transSequence
WHILE @needqty>0
BEGIN
select top 1 @qty = isnull(a.quantity,0), @locationcode = isnull(a.locationcode,''),@lotno = isnull(a.lotno,''),@WHCode = isnull(a.warehousecode,''),@mtime=a.mtime,@invcode = b.invcode from #barcodetemp a
right JOIN(select invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE from #maintemp where transSequence=@transSequence)b on a.invcode = b.invcode
and ((isnull(b.ProjectCode,'')<>'' and b.ProjectCode = a.ProjectCode) or isnull(b.ProjectCode,'') ='') and
((isnull(b.Version,'')<>'' and b.Version = a.Version) or isnull(b.Version,'') ='') and
((isnull(b.Brand,'')<>'' and b.Brand = a.Brand )or isnull(b.Brand,'') ='') and
((isnull(b.cFree1,'')<>'' and b.cFree1 =a.cFree1) or isnull(b.cFree1,'') ='') and
((isnull(b.cFree2,'')<>'' and b.cFree2 =a.cFree2 )or isnull(b.cFree2,'') ='') and
((isnull(b.cFree3,'')<>'' and b.cFree3 =a.cFree3 )or isnull(b.cFree3,'') ='') and
((isnull(b.cFree4,'')<>'' and b.cFree4 =a.cFree4 )or isnull(b.cFree4,'') ='') and
((isnull(b.cFree5,'')<>'' and b.cFree5 =a.cFree5) or isnull(b.cFree5,'') ='') and
((isnull(b.cFree6,'')<>'' and b.cFree6 =a.cFree6 )or isnull(b.cFree6,'') ='') and
((isnull(b.cFree7,'')<>'' and b.cFree7 =a.cFree7) or isnull(b.cFree7,'') ='') and
((isnull(b.cFree8,'')<>'' and b.cFree8 =a.cFree8) or isnull(b.cFree8,'') ='') and
((isnull(b.cFree9,'')<>'' and b.cFree9 =a.cFree9) or isnull(b.cFree9,'') ='') and
((isnull(b.cFree10,'')<>'' and b.cFree10 =a.cFree10) or isnull(b.cFree10,'') ='') and
((isnull(b.BatchCode,'')<>'' and b.BatchCode =a.BatchCode) or isnull(b.BatchCode,'') ='')ORDER BY a.mtime,a.locationcode
IF(@needqty-@issueQuantity-@qty>=0 and ISNULL(@lotno, '')<>'')
BEGIN
insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotNo,
WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
ISNULL(Amount, 0),[User],@mtime,InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),@qty,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
delete from #barcodetemp where lotno = @lotno
SET @needqty=@needqty-@qty
END
ELSE if(@needqty-@issueQuantity-@qty<0 and ISNULL(@lotno, '')<>''and @needqty-@issueQuantity>0)
BEGIN
insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotno,
WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
ISNULL(Amount, 0),[User],@mtime,InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),case WHEN ISNULL(@qty, 0)=0 THEN 0 else @needqty-@issueQuantity end ,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
update #barcodetemp set quantity = @qty-@needqty+-@issueQuantity where lotno = @lotno
SET @needqty=@needqty-@issueQuantity-@qty
END
ELSE
BEGIN
insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotno,
WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
ISNULL(Amount, 0),[User],@mtime,InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),0 ,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
SET @needqty=0
END
END
FETCH NEXT FROM tempCursor INTO @transSequence;
END
CLOSE tempCursor
DEALLOCATE tempCursor
END
select id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,sum(LocationQty)as LocationQty,isMatched,AmountUnit,LotNo,
WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #resulttemp GROUP BY id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,isMatched,AmountUnit,LotNo,
WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ORDER BY locationcode ASC ,InvCode ASC
DROP table #maintemp
DROP table #resulttemp
DROP table #barcodetemp";
}
#endregion
if (isDeliveryNotice)//送货、到货、含委外
{
#region SLQ
sql = sqlCheck + @"SELECT a.ID,
{0}
a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,
'' AS WHCode,
inv.AmountUnit,
'' AS WHName,
a.ExtensionID,
ext.ProjectCode,
CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10
FROM {1}
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE {2} ";
#endregion
}
//else if (isMerge)//合并发料
//{
// #region SLQ
// string sqlMerge = "SELECT ID FROM ICSMOPickMerge WHERE MergeID='" + JsonData.TransCode + "' AND WorkPoint='" + JsonData.WorkPoint + "'";
// DataTable sign = DBHelper.SQlReturnData(sqlMerge, cmd);
// if (sign != null && sign.Rows.Count > 0)
// {
// string whereMerge = string.Format("mer.MergeID='{0}' AND mer.WorkPoint='{1}'", JsonData.TransCode, JsonData.WorkPoint);
// sql = string.Format(sql, columnsMerge, tableNameMerge, whereMerge, JsonData.TransCode, excessQtySql, invWhere);
// }
// else
// {
// sql = @" BEGIN
// IF EXISTS(SELECT a.ID FROM {1} INNER JOIN ICSMOPickMerge c ON a.ID=c.SourceID AND a.WorkPoint=c.WorkPoint WHERE {2})
// BEGIN
// RAISERROR('" + language.GetNameByCode("WMSAPIInfo194") + @"',16,1);
// RETURN
// END
// " + sqlCheck + sql + @"
// END";
// }
// #endregion
//}
else
{
sql = sqlCheck + sql;
}
where = string.Format(where, JsonData.TransCode, JsonData.WorkPoint, whcode, JsonData.WHCode);
sql = excludeSql + sql;
sql = string.Format(sql, columns, tableName, where, JsonData.TransCode, excessQtySql, invWhere, order);
sqls = string.Format(sqls, JsonData.TransCode, JsonData.WorkPoint);
Picksql = string.Format(Picksql, sqls, JsonData.WorkPoint);
//DataTable table2 = DBHelper.SQlReturnData(Picksql, cmd);
//return table2;
log.Debug("单据查询sql:" + sql);
DataTable table = DBHelper.SQlReturnData(sql, cmd);
return table;
}
catch (Exception ex)
{
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
#endregion
#region 源头单据信息
///
/// 获取工单生成的子线条码信息
///
///
///
public static DataTable MOWireInformationGet(WMSSourceDocumentModel JsonData)
{
var language = LanguageHelper.GetName("WMSAPIInfo");
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
string sql = string.Empty;
string arrivalCtrlSql = string.Empty;
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
try
{
if (string.IsNullOrEmpty(JsonData.TransCode))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
}
else if (string.IsNullOrEmpty(JsonData.TransType))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
}
else if (string.IsNullOrEmpty(JsonData.WorkPoint))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
}
string TransType = JsonData.TransType;
string excessQtySql = "";
#region SLQ
string sqlCheck = @"";
//查询是否需要去除单据中已发完明细
string excludeSql = @"";
#endregion
string columns = string.Empty; //查询源头单据表的特殊列名
string tableName = string.Empty; //查询源头单据表名
string where = string.Empty; //查询源头单据的过滤条件
string sqls = string.Empty;
string whcode = "";
#region 出库
columns = @"a.MOCode AS TransCode,
a.ID AS DetailID,
a.LotNo,
'' AS Type,
a.Sequence AS TransSequence,
ISNULL(a.Quantity,0) AS IssueQuantity,
a.Quantity,
a.Quantity*(a.Amount/a.Quantity) AS Amount,
a.MUSER AS [User],
a.MTIME AS [MTime],";
tableName = @"ICSMOSubInventoryLot a
";
where = @" a.MOCode='{0}' AND a.WorkPoint='{1}' ";
#endregion
#region SLQ
sql = sqlCheck + @"SELECT a.ID,
{0}
a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,
'' AS WHCode,
inv.AmountUnit,
'' AS WHName,
a.ExtensionID,
ext.ProjectCode,
CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10
FROM {1}
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE {2} ";
#endregion
where = string.Format(where, JsonData.TransCode, JsonData.WorkPoint, whcode);
sql = excludeSql + sql;
sql = string.Format(sql, columns, tableName, where, JsonData.TransCode, excessQtySql);
log.Debug("工单子线条码sql:" + sql);
DataTable table = DBHelper.SQlReturnData(sql, cmd);
return table;
}
catch (Exception ex)
{
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
#endregion
#region 源头单据检料表信息
///
/// 源头单据信息
///
///
///
public static DataTable TransPickGet(WMSSourceDocumentModel JsonData)
{
var language = LanguageHelper.GetName("WMSAPIInfo");
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
try
{
if (string.IsNullOrEmpty(JsonData.TransCode))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
}
else if (string.IsNullOrEmpty(JsonData.TransType))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
}
else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
}
else if (string.IsNullOrEmpty(JsonData.WorkPoint))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
}
string TransType = JsonData.TransType;
#region 原拣料SLQ
// string Picksql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
// c.Code,
// c.InvCode,
// c.InvName,
// c.InvStd,
//c.InvUnit,
// FLOOR(c.iQuantity) AS iQuantity,
// d.WarehouseCode,
// d.LocationCode,
// d.LotNO,
// FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
// CONVERT(varchar(100),d.MTIME, 23) MTIME,
// FLOOR(f.QTYTotal) QTYTotal INTO #temp
// FROM
// ({0}) c
// LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND ((LEN(ISNULL(c.WHCode,''))<=0) OR (LEN(ISNULL(c.WHCode,''))>0) AND c.WhCode=d.WarehouseCode) AND d.WorkPoint='{1}' AND d.Quantity>0
// left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
// LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{1}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
//DECLARE @ItemCode VARCHAR(50),
// @QTY DECIMAL(18,3),
// @ItemCodeCurrent VARCHAR(50),
// @QTYCurrent DECIMAL(18,3),
// @iQuantityCurrent DECIMAL(18,3),
// @CanDelete BIT,
// @Row INT,
// @rowCurrent INT
//SET @Row = @@rowcount
//SET @rowCurrent=1
//SET @CanDelete=0
//SET @ItemCode=''
//WHILE @rowCurrent<=@Row
// BEGIN
// SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
//PRINT(@rowCurrent)
// IF @ItemCode<>@ItemCodeCurrent
// BEGIN
// SET @ItemCode=@ItemCodeCurrent
// SET @QTY=0
// SET @CanDelete=0
// END
// IF @CanDelete=1
// BEGIN
// DELETE FROM #temp WHERE rowNo=@rowCurrent
// SET @rowCurrent += 1
// CONTINUE
// END
// SET @QTY += @QTYCurrent
// IF @QTY>=@iQuantityCurrent
// BEGIN
// SET @CanDelete=1
// END
// SET @rowCurrent += 1
// END
//SELECT * FROM #temp
//DROP TABLE #temp
//";
#endregion
#region SLQ
string Picksql = @" EXEC ICSPicking '{0}', '{1}','{2}', '{3}'";
#endregion
string sqls = string.Empty;
string type = string.Empty;
bool isMerge = true;
#region 检料表信息
if (TransType == TransTypeEnum.MOIssueDoc.GetDescription() || TransType == TransTypeEnum.JHMOIssueDoc.GetDescription())
{
#region 工单备料sql
type = "1";
#endregion
}
if (TransType == TransTypeEnum.MOIssueAutoDoc.GetDescription())
{
#region 工单备料(自动出库)sql
type = "1";
#endregion
}
if (TransType == TransTypeEnum.MOApply.GetDescription())
{
#region 工单领料SQL
type = "2";
#endregion
}
if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
{
#region 工单补料SQL
type = "12";
#endregion
}
if (TransType == TransTypeEnum.MOIssue.GetDescription())
{
#region 工单材料出库SQL
type = "3";
#endregion
}
if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
{
#region 委外备料SQL
type = "4";
#endregion
}
if (TransType == TransTypeEnum.OOApply.GetDescription())
{
#region 委外领料SQL
type = "5";
#endregion
}
if (TransType == TransTypeEnum.OOIssue.GetDescription())
{
#region 委外材料出库SQL
type = "6";
#endregion
}
if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
{
#region 销售发货SQL
type = "7";
#endregion
}
if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
{
#region 其他出库SQL
type = "8";
#endregion
}
if (TransType == TransTypeEnum.OtherOutAutoDoc.GetDescription())
{
#region 其他出库(自动出库)SQL
type = "8";
#endregion
}
if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
{
#region 借用SQL
type = "9";
#endregion
}
if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
{
#region 物料调拨
type = "10";
#endregion
}
if (TransType == TransTypeEnum.OneStepTransferDocAuto.GetDescription())
{
#region 物料调拨
type = "10";
#endregion
}
if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
{
#region 两步调出
type = "11";
#endregion
}
if (TransType == TransTypeEnum.SalesShipmentOutDoc.GetDescription() || TransType == TransTypeEnum.JHSalesShipmentOutDoc.GetDescription())
{
#region 销售出库单
type = "16";
#endregion
}
if (TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription())
{
#region 调拨申请单
type = "17";
#endregion
}
if (isMerge)
{
string sqlMerge = "SELECT ID FROM ICSMOPickMerge WHERE MergeID='" + JsonData.TransCode + "' AND WorkPoint='" + JsonData.WorkPoint + "'";
DataTable sign = DBHelper.SQlReturnData(sqlMerge, cmd);
if (sign != null && sign.Rows.Count > 0)
{
isMerge = true;
}
else
{
isMerge = false;
}
}
#endregion
JsonData.TransCode = "'" + JsonData.TransCode + "'";
JsonData.TransCode = JsonData.TransCode.TrimEnd(',').Replace("'", "''");
Picksql = string.Format(Picksql, JsonData.TransCode, type, isMerge, JsonData.WorkPoint);
DataTable table = DBHelper.SQlReturnData(Picksql, cmd);
return table;
}
catch (Exception ex)
{
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
#endregion
#region 源头单据检料表信息
///
/// 源头单据信息
///
///
///
public static DataTable TransPickGetByItem(WMSSourceDocumentModel JsonData)
{
var language = LanguageHelper.GetName("WMSAPIInfo");
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
try
{
if (string.IsNullOrEmpty(JsonData.TransCode))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
}
else if (string.IsNullOrEmpty(JsonData.TransType))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
}
else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
}
else if (string.IsNullOrEmpty(JsonData.WorkPoint))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
}
string TransType = JsonData.TransType;
#region 原拣料SLQ
// string Picksql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
// c.Code,
// c.InvCode,
// c.InvName,
// c.InvStd,
//c.InvUnit,
// FLOOR(c.iQuantity) AS iQuantity,
// d.WarehouseCode,
// d.LocationCode,
// d.LotNO,
// FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
// CONVERT(varchar(100),d.MTIME, 23) MTIME,
// FLOOR(f.QTYTotal) QTYTotal INTO #temp
// FROM
// ({0}) c
// LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND ((LEN(ISNULL(c.WHCode,''))<=0) OR (LEN(ISNULL(c.WHCode,''))>0) AND c.WhCode=d.WarehouseCode) AND d.WorkPoint='{1}' AND d.Quantity>0
// left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
// LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{1}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
//DECLARE @ItemCode VARCHAR(50),
// @QTY DECIMAL(18,3),
// @ItemCodeCurrent VARCHAR(50),
// @QTYCurrent DECIMAL(18,3),
// @iQuantityCurrent DECIMAL(18,3),
// @CanDelete BIT,
// @Row INT,
// @rowCurrent INT
//SET @Row = @@rowcount
//SET @rowCurrent=1
//SET @CanDelete=0
//SET @ItemCode=''
//WHILE @rowCurrent<=@Row
// BEGIN
// SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
//PRINT(@rowCurrent)
// IF @ItemCode<>@ItemCodeCurrent
// BEGIN
// SET @ItemCode=@ItemCodeCurrent
// SET @QTY=0
// SET @CanDelete=0
// END
// IF @CanDelete=1
// BEGIN
// DELETE FROM #temp WHERE rowNo=@rowCurrent
// SET @rowCurrent += 1
// CONTINUE
// END
// SET @QTY += @QTYCurrent
// IF @QTY>=@iQuantityCurrent
// BEGIN
// SET @CanDelete=1
// END
// SET @rowCurrent += 1
// END
//SELECT * FROM #temp
//DROP TABLE #temp
//";
#endregion
#region SLQ
string Picksql = @" EXEC ICSPickingByItem '{0}', '{5}','{1}','{4}','{2}', '{3}'";
#endregion
string sqls = string.Empty;
string type = string.Empty;
bool isMerge = true;
#region 检料表信息
if (TransType == TransTypeEnum.MOIssueDoc.GetDescription() || TransType == TransTypeEnum.JHMOIssueDoc.GetDescription())
{
#region 工单备料sql
type = "1";
#endregion
}
if (TransType == TransTypeEnum.MOIssueAutoDoc.GetDescription())
{
#region 工单备料(自动出库)sql
type = "1";
#endregion
}
if (TransType == TransTypeEnum.MOApply.GetDescription())
{
#region 工单领料SQL
type = "2";
#endregion
}
if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
{
#region 工单补料SQL
type = "12";
#endregion
}
if (TransType == TransTypeEnum.MOIssue.GetDescription())
{
#region 工单材料出库SQL
type = "3";
#endregion
}
if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
{
#region 委外备料SQL
type = "4";
#endregion
}
if (TransType == TransTypeEnum.OOApply.GetDescription())
{
#region 委外领料SQL
type = "5";
#endregion
}
if (TransType == TransTypeEnum.OOIssue.GetDescription())
{
#region 委外材料出库SQL
type = "6";
#endregion
}
if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
{
#region 销售发货SQL
type = "7";
#endregion
}
if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
{
#region 其他出库SQL
type = "8";
#endregion
}
if (TransType == TransTypeEnum.OtherOutAutoDoc.GetDescription())
{
#region 其他出库(自动出库)SQL
type = "8";
#endregion
}
if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
{
#region 借用SQL
type = "9";
#endregion
}
if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
{
#region 物料调拨
type = "10";
#endregion
}
if (TransType == TransTypeEnum.OneStepTransferDocAuto.GetDescription())
{
#region 物料调拨
type = "10";
#endregion
}
if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
{
#region 两步调出
type = "11";
#endregion
}
if (TransType == TransTypeEnum.SalesShipmentOutDoc.GetDescription() || TransType == TransTypeEnum.JHSalesShipmentOutDoc.GetDescription())
{
#region 销售出库单
type = "16";
#endregion
}
if (TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription())
{
#region 调拨申请单
type = "17";
#endregion
}
if (isMerge)
{
string sqlMerge = "SELECT ID FROM ICSMOPickMerge WHERE MergeID='" + JsonData.TransCode + "' AND WorkPoint='" + JsonData.WorkPoint + "'";
DataTable sign = DBHelper.SQlReturnData(sqlMerge, cmd);
if (sign != null && sign.Rows.Count > 0)
{
isMerge = true;
}
else
{
isMerge = false;
}
}
#endregion
JsonData.TransCode = "'" + JsonData.TransCode + "'";
JsonData.TransCode = JsonData.TransCode.TrimEnd(',').Replace("'", "''");
Picksql = string.Format(Picksql, JsonData.TransCode, type, isMerge, JsonData.WorkPoint, JsonData.InvCode, JsonData.TransSequence);
DataTable table = DBHelper.SQlReturnData(Picksql, cmd);
return table;
}
catch (Exception ex)
{
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
#endregion
#region 根据组件捡料
///
/// 根据组件捡料
///
///
///
public static DataTable TransPickGetByZJCode(WMSSourceDocumentModel JsonData)
{
var language = LanguageHelper.GetName("WMSAPIInfo");
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
try
{
if (string.IsNullOrEmpty(JsonData.TransCode))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
}
else if (string.IsNullOrEmpty(JsonData.TransType))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
}
else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
}
else if (string.IsNullOrEmpty(JsonData.WorkPoint))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
}
string TransType = JsonData.TransType;
#region SLQ
string Picksql = @" EXEC ICSPickingDYS '{0}', '{1}','{2}','{3}','{4}'";
#endregion
string sqls = string.Empty;
string type = string.Empty;
bool isMerge = true;
#region 检料表信息
if (TransType == TransTypeEnum.MOIssueDoc.GetDescription() || TransType == TransTypeEnum.JHMOIssueDoc.GetDescription())
{
#region 工单备料sql
type = "1";
#endregion
}
if (TransType == TransTypeEnum.MOIssueAutoDoc.GetDescription())
{
#region 工单备料(自动出库)sql
type = "1";
#endregion
}
if (TransType == TransTypeEnum.MOApply.GetDescription())
{
#region 工单领料SQL
type = "2";
#endregion
}
if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
{
#region 工单补料SQL
type = "12";
#endregion
}
if (TransType == TransTypeEnum.MOIssue.GetDescription())
{
#region 工单材料出库SQL
type = "3";
#endregion
}
if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
{
#region 委外备料SQL
type = "4";
#endregion
}
if (TransType == TransTypeEnum.OOApply.GetDescription())
{
#region 委外领料SQL
type = "5";
#endregion
}
if (TransType == TransTypeEnum.OOIssue.GetDescription())
{
#region 委外材料出库SQL
type = "6";
#endregion
}
if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
{
#region 销售发货SQL
type = "7";
#endregion
}
if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
{
#region 其他出库SQL
type = "8";
#endregion
}
if (TransType == TransTypeEnum.OtherOutAutoDoc.GetDescription())
{
#region 其他出库(自动出库)SQL
type = "8";
#endregion
}
if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
{
#region 借用SQL
type = "9";
#endregion
}
if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
{
#region 物料调拨
type = "10";
#endregion
}
if (TransType == TransTypeEnum.OneStepTransferDocAuto.GetDescription())
{
#region 物料调拨
type = "10";
#endregion
}
if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
{
#region 两步调出
type = "11";
#endregion
}
if (TransType == TransTypeEnum.SalesShipmentOutDoc.GetDescription() || TransType == TransTypeEnum.JHSalesShipmentOutDoc.GetDescription())
{
#region 销售出库单
type = "16";
#endregion
}
if (TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription())
{
#region 调拨申请单
type = "17";
#endregion
}
if (isMerge)
{
string sqlMerge = "SELECT ID FROM ICSMOPickMerge WHERE MergeID='" + JsonData.TransCode + "' AND WorkPoint='" + JsonData.WorkPoint + "'";
DataTable sign = DBHelper.SQlReturnData(sqlMerge, cmd);
if (sign != null && sign.Rows.Count > 0)
{
isMerge = true;
}
else
{
isMerge = false;
}
}
#endregion
JsonData.TransCode = "'" + JsonData.TransCode + "'";
JsonData.TransCode = JsonData.TransCode.TrimEnd(',').Replace("'", "''");
Picksql = string.Format(Picksql, JsonData.TransCode, type, JsonData.InvCode, isMerge, JsonData.WorkPoint);
DataTable table = DBHelper.SQlReturnData(Picksql, cmd);
return table;
}
catch (Exception ex)
{
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
#endregion
///
/// 所有未完成单据号
///
///
///
public static DataTable TransCodeGet(WMSSourceDocumentModel JsonData)
{
var language = LanguageHelper.GetName("WMSAPIInfo");
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
try
{
if (string.IsNullOrEmpty(JsonData.TransType))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
}
else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
}
else if (string.IsNullOrEmpty(JsonData.WorkPoint))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
}
string TransType = JsonData.TransType;
#region SLQ
//string sqlCheck = @"IF NOT EXISTS(SELECT a.ID FROM {1} WHERE {2})
// BEGIN
// RAISERROR('" + language.GetNameByCode("WMSAPIInfo035") + @"',16,1);
// RETURN
// END
// ";
string sql = @"SELECT
{0}
FROM {1}
WHERE {2}
order by {3}";
#endregion
bool isDeliveryNotice = false; //送货、到货、含委外
bool MOApplyWithBin = false; //生产领料-库位
bool OtherOutDocWithBin = false; //杂发-库位
string columns = string.Empty; //查询源头单据表的特殊列名
string tableName = string.Empty; //查询源头单据表名
string where = string.Empty; //查询源头单据的过滤条件
string orderby = string.Empty; //查询源头单据的排序方式
bool isMerge = false; //合并发料
string columnsMerge = string.Empty; //合并发料查询源头单据表的特殊列名
string tableNameMerge = string.Empty; //合并发料查询源头单据表名
#region 出库
#region 采购退货
if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
{
columns = @" DISTINCT a.DNCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @"ICSDeliveryNotice a ";
where = @" a.WorkPoint='{1}' AND a.DNType='2' AND a.Status='2' AND (a.Quantity-ISNULL(a.RCVQuantity,0))>0";
orderby = @" CAST(a.MTIME AS DATE) DESC,a.DNCode DESC";
}
else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegativePo.GetDescription())
{
columns = @" DISTINCT a.DNCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @"ICSDeliveryNotice a ";
where = @" a.WorkPoint='{1}' AND a.DNType='2' AND a.Status='1' AND ISNULL(a.RCVQuantity,0)>0";
orderby = @" CAST(a.MTIME AS DATE) DESC,a.DNCode DESC";
}
#endregion
#region 委外退货
if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
{
columns = @" DISTINCT a.ODNCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @"ICSODeliveryNotice a ";
where = @" a.WorkPoint='{1}' AND a.ODNType='2' AND a.Status='2' AND (a.Quantity-ISNULL(a.RCVQuantity,0))>0";
orderby = @" CAST(a.MTIME AS DATE) DESC,a.ODNCode DESC";
}
#endregion
#region 其他出库
else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
{
columns = @" DISTINCT a.OutCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @"ICSOtherOut a ";
where = @" a.Status='1' AND a.WorkPoint='{1}' and a.Quantity>ISNULL(a.OutQuantity, 0)";
orderby = @" CAST(a.MTIME AS DATE) DESC,a.OutCode DESC";
}
#endregion
#region 借用
else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
{
columns = @" DISTINCT a.BrrowCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @"ICSBrrow a ";
where = @" a.Status='2' AND a.WorkPoint='{1}' and a.Quantity>ISNULL(a.BrrowQuantity, 0)";
orderby = @" CAST(a.MTIME AS DATE) DESC,a.BrrowCode DESC";
}
#endregion
#region 其他出库-自动出库
else if (TransType == TransTypeEnum.OtherOutAutoDoc.GetDescription())
{
columns = @" DISTINCT a.OutCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @"ICSOtherOut a
INNER JOIN ICSInventory inv ON inv.InvCode=a.InvCode AND inv.WorkPoint=a.WorkPoint ";
where = @" a.Status='1' AND a.WorkPoint='{1}' and a.Quantity>ISNULL(a.OutQuantity, 0)";
where += DBHelper.SearchConditonGet("Trans_btnOtherOutAuto", JsonData.User, cmd);
orderby = @" CAST(a.MTIME AS DATE) DESC,a.OutCode DESC";
}
#endregion
#region 红字其他入库
else if (TransType == TransTypeEnum.OtherInRedDoc.GetDescription())
{
columns = @" DISTINCT a.InCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @"ICSOtherIn a ";
where = @" a.Status='1' AND a.WorkPoint='{1}' and a.Quantity>ISNULL(a.InQuantity,0) and a.EATTRIBUTE2='2'";
orderby = @" CAST(a.MTIME AS DATE) DESC,a.InCode DESC";
}
#endregion
#region 红字委外入库单
else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
{
columns = @" DISTINCT a.RCVCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @"ICSOutsourcingReceive a ";
where = @" a.Status='1' AND a.WorkPoint='{1}' and a.Quantity>ISNULL(a.RCVQuantity,0) ";
orderby = @" CAST(a.MTIME AS DATE) DESC,a.RCVCode DESC";
}
#endregion
#region 一步调拨(合并发料)
else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
{
sql = @"SELECT TransCode
FROM (
SELECT
a.TransferNO AS TransCode,
a.MTIME,
ROW_NUMBER() OVER (PARTITION BY a.TransferNO ORDER BY a.MTIME DESC) as rn
FROM ICSTransfer a
WHERE {2}
) AS temp
WHERE rn = 1
ORDER BY MTIME DESC,TransCode DESC";
//columns = @" DISTINCT a.TransferNO AS TransCode,a.MTIME";
//tableName = @"ICSTransfer a ";
where = @" a.WorkPoint='{1}' AND a.Status='1' AND a.Quantity>ISNULL(a.TransferQuantity,0) AND Type='1'";
//orderby = @" a.MTIME DESC";
}
#endregion
#region 自动调拨
else if (TransType == TransTypeEnum.OneStepTransferDocAuto.GetDescription())
{
columns = @" DISTINCT a.TransferNO AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @"ICSTransfer a
INNER JOIN ICSInventory inv ON inv.InvCode=a.InvCode AND inv.WorkPoint=a.WorkPoint ";
where = @" a.WorkPoint='{1}' AND a.Status='1' AND a.Quantity>ISNULL(a.TransferQuantity,0) AND Type='1' ";
where += DBHelper.SearchConditonGet("Trans_btnInvTransAuto", JsonData.User, cmd);
orderby = @" CAST(a.MTIME AS DATE) DESC,a.TransferNO DESC";
}
#endregion
#region 调拨申请单(合并发料)
else if (TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription())
{
columns = @" DISTINCT a.TransferNO AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @"ICSTransferApplication a ";
where = @" a.WorkPoint='{1}' AND a.Status='2' AND a.Quantity>ISNULL(a.TransferQuantity,0) AND Type='1'";
orderby = @" CAST(a.MTIME AS DATE) DESC,a.TransferNO DESC";
}
#endregion
#region 委外退料
else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
{
columns = @" DISTINCT a.OApplyNegCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @"ICSOApplyNegDetail a
INNER JOIN ICSOApplyNeg d ON a.OApplyNegCode=d.OApplyNegCode AND a.WorkPoint=d.WorkPoint";
where = @" a.WorkPoint='{1}' AND d.Status='1' AND a.Quantity>ISNULL(a.IssueNegQuantity,0) AND d.Type='1'";
orderby = @" CAST(a.MTIME AS DATE) DESC,a.OApplyNegCode DESC";
}
#endregion
#region 生产发料(合并发料)
else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
{
columns = @" DISTINCT b.MOCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @" ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint ";
where = @" a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and ISNULL(a.EATTRIBUTE1, '')<>'1' and a.Quantity-ISNULL(a.IssueQuantity,0)>0 --dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{2}', 2, 2,'')-ISNULL(a.IssueQuantity,0)>0";
orderby = @" CAST(a.MTIME AS DATE) DESC,b.MOCode DESC";
}
#endregion
#region 生产发料(合并发料)
else if (TransType == TransTypeEnum.JHMOIssueDoc.GetDescription())
{
columns = @" DISTINCT b.MOCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @" ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint ";
where = @" a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and ISNULL(a.EATTRIBUTE1, '')<>'1' and a.Quantity-ISNULL(a.IssueQuantity,0)>0 --dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{2}', 2, 2,'')-ISNULL(a.IssueQuantity,0)>0";
orderby = @" b.MOCode DESC";
}
#endregion
#region 生产发料——自动出库
else if (TransType == TransTypeEnum.MOIssueAutoDoc.GetDescription())
{
columns = @" DISTINCT b.MOCode AS TransCode,CAST(b.MTIME AS DATE) AS MTIME";
tableName = @" ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSInventory inv ON inv.InvCode=a.InvCode AND inv.WorkPoint=a.WorkPoint ";
where = @" a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and ISNULL(a.EATTRIBUTE1, '')<>'1' and a.Quantity-ISNULL(a.IssueQuantity,0)>0 --dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{2}', 2, 2,'')-ISNULL(a.IssueQuantity,0)>0";
where += DBHelper.SearchConditonGet("Trans_btnInvOutAuto", JsonData.User, cmd);
orderby = @" CAST(b.MTIME AS DATE) AS MTIME,b.MOCode DESC";
}
#endregion
#region 开立材料出库(合并发料)
else if (TransType == TransTypeEnum.MOIssue.GetDescription())
{
columns = @" DISTINCT a.IssueCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @" ICSMOIssue a ";
where = @" a.WorkPoint='{1}' AND a.Status<>'3' and a.Quantity-ISNULL(a.IssueQuantity, 0)>0";
orderby = @" CAST(a.MTIME AS DATE) DESC,a.IssueCode DESC";
}
#endregion
#region 生产发料-领料申请单
else if (TransType == TransTypeEnum.MOApply.GetDescription())
{
columns = @" DISTINCT a.ApplyCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @" ICSMOApply a";
where = @" a.Status='2' AND a.WorkPoint='{1}' and a.Quantity-ISNULL(a.IssueQuantity, 0)>0";
orderby = @" CAST(a.MTIME AS DATE) DESC,a.ApplyCode DESC";
}
#endregion
#region 开立委外材料出库(合并发料)
else if (TransType == TransTypeEnum.OOIssue.GetDescription())
{
columns = @" DISTINCT a.IssueCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @" ICSOIssue a ";
where = @" a.WorkPoint='{1}' AND a.Status<>'3' and a.Quantity-ISNULL(a.IssueQuantity, 0)>0";
orderby = @" CAST(a.MTIME AS DATE) DESC,a.IssueCode DESC";
}
#endregion
#region 委外领料申请单发料(合并发料)
else if (TransType == TransTypeEnum.OOApply.GetDescription())
{
columns = @" DISTINCT a.ApplyCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @" ICSOApply a ";
where = @" a.WorkPoint='{1}' AND a.Status<>'3' and a.Quantity-ISNULL(a.IssueQuantity, 0)>0";
orderby = @" CAST(a.MTIME AS DATE) DESC,a.ApplyCode DESC";
}
#endregion
#region 委外发料(合并发料)
else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription() || TransType == TransTypeEnum.RTOutsourcingIssueDoc.GetDescription())
{
columns = @" DISTINCT b.OOCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @" ICSOOPick a
INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint ";
where = @" a.WorkPoint='{1}' AND a.SupplyType='3' AND b.Status<>'3' and ISNULL(a.EATTRIBUTE1, '')<>'1' and a.Quantity-ISNULL(a.IssueQuantity, 0)>0";
orderby = @" CAST(a.MTIME AS DATE) DESC,b.OOCode DESC";
}
#endregion
#region 销售出库(合并发料)
else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
{
columns = @" DISTINCT a.SDNCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @"ICSSDN a ";
where = @" a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' and a.Quantity-ISNULL(a.SDNQuantity,0)>0";
orderby = @" CAST(a.MTIME AS DATE) DESC,a.SDNCode DESC";
}
#endregion
#region 销售出库(合并发料)
else if (TransType == TransTypeEnum.SalesBindCourierDoc.GetDescription())
{
columns = @" DISTINCT a.SDNCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @"ICSSDN a ";
where = @" a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' and a.Quantity-ISNULL(a.SDNQuantity,0)>0";
orderby = @" CAST(a.MTIME AS DATE) DESC,a.SDNCode DESC";
}
#endregion
#region 销售出库-出库单(合并发料)
else if (TransType == TransTypeEnum.SalesShipmentOutDoc.GetDescription() || TransType == TransTypeEnum.JHSalesShipmentOutDoc.GetDescription())
{
columns = @" DISTINCT a.SSDCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @"ICSSSD a ";
where = @" a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' and a.Quantity-ISNULL(a.SSDQuantity,0)>0";
orderby = @" CAST(a.MTIME AS DATE) DESC,a.SSDCode DESC";
}
#endregion
#region 盘点
else if (TransType == TransTypeEnum.Check.GetDescription())
{
columns = @" DISTINCT a.CheckCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @"ICSCheck a ";
where = @" a.WorkPoint='{1}' ";
orderby = @" CAST(a.MTIME AS DATE) DESC,a.CheckCode DESC";
}
#endregion
#endregion
#region 入库
#region 生产退料
else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
{
columns = @" DISTINCT a.ApplyNegcode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @"ICSMOApplyNegDetail b
inner join ICSMOApplyNeg a on a.ApplyNegcode=b.ApplyNegcode and a.workpoint=b.workpoint";
where = @" a.WorkPoint='{1}' AND a.Type='3' AND a.Status='2' AND b.Quantity>ISNULL(b.IssueNegQuantity, 0)";
orderby = @" CAST(a.MTIME AS DATE) DESC,a.ApplyNegcode DESC";
}
#endregion
#region 归还
else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
{
columns = @" DISTINCT a.ReturnCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @"ICSReturn a ";
where = @" a.WorkPoint='{1}' AND a.Quantity>ISNULL(a.ReturnQuantity, 0)";
orderby = @" CAST(a.MTIME AS DATE) DESC,a.ReturnCode DESC";
}
#endregion
#region 产成品入库-产成品入库单-mes
else if (TransType == TransTypeEnum.ManufactureMESReceive.GetDescription())
{
columns = @" DISTINCT a.RCVCode AS TransCode,CAST(a.MTIME AS DATE) AS MTIME";
tableName = @"ICSManufactureReceive a ";
where = @" a.WorkPoint='{1}' AND a.Type='1' AND a.Status='1' AND a.Quantity>ISNULL(a.RCVQuantity, 0)";
orderby = @" CAST(a.MTIME AS DATE) DESC,a.RCVCode DESC";
}
#endregion
#endregion
else
{
//throw new Exception();
}
where = string.Format(where, JsonData.TransCode, JsonData.WorkPoint, enableCode);
sql = string.Format(sql, columns, tableName, where, orderby);
log.Debug("源头单据sql : " + sql);
DataTable table = DBHelper.SQlReturnData(sql, cmd);
return table;
}
catch (Exception ex)
{
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
///
/// 所有未完成单据号
///
///
///
public static DataTable MoLotInfoGet(WMSSourceDocumentModel JsonData)
{
var language = LanguageHelper.GetName("WMSAPIInfo");
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
try
{
if (string.IsNullOrEmpty(JsonData.TransType))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
}
else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
}
else if (string.IsNullOrEmpty(JsonData.WorkPoint))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
}
string TransType = JsonData.TransType;
#region SLQ
//string sqlCheck = @"IF NOT EXISTS(SELECT a.ID FROM {1} WHERE {2})
// BEGIN
// RAISERROR('" + language.GetNameByCode("WMSAPIInfo035") + @"',16,1);
// RETURN
// END
// ";
string sql = @"--条码 子线数量
select {0},a.MTime from {1}
where {2}
SELECT
{0},a.MTime
FROM {1}
WHERE
order by {3}";
#endregion
string columns = string.Empty; //查询源头单据表的特殊列名
string tableName = string.Empty; //查询源头单据表名
string where = string.Empty; //查询源头单据的过滤条件
string orderby = string.Empty; //查询源头单据的排序方式
if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
{
columns = @" a.lotno, a.Quantity*ISNULL(d.EATTRIBUTE6, 1) Quantity ";
tableName = @"ICSInventoryLot a
inner join ICSInventoryLotDetail b
on a.lotno = b.lotno and a.WorkPoint = b.WorkPoint
inner join ICSMO c
on c.MOCode = b.TransCode and c.Sequence = b.TransSequence and c.WorkPoint = b.WorkPoint
inner join ICSInventory d on a.invcode = d.invcode and a.WorkPoint = d.WorkPoint";
where = @" c.MOCode = '{0}' and a.EATTRIBUTE1 is null and a.WorkPoint='{1}'";
orderby = @" a.MTIME DESC";
}
else
{
//throw new Exception();
}
where = string.Format(where, JsonData.TransCode, JsonData.WorkPoint, enableCode);
sql = string.Format(sql, columns, tableName, where, orderby);
log.Debug("海格工单条码查询sql : " + sql);
DataTable table = DBHelper.SQlReturnData(sql, cmd);
return table;
}
catch (Exception ex)
{
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
///
///
///
///
///
public static DataTable SRMItemsGet(WMSSourceDocumentModel JsonData)
{
var language = LanguageHelper.GetName("WMSAPIInfo");
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
try
{
if (string.IsNullOrEmpty(JsonData.TransType))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
}
string TransType = JsonData.TransType;
#region SLQ
string sql = @"SELECT
{0}
FROM {1}
WHERE {2}
";
#endregion
string columns = string.Empty; //查询源头单据表的特殊列名
string tableName = string.Empty; //查询源头单据表名
string where = string.Empty; //查询源头单据的过滤条件
#region 出库
columns = @" DISTINCT its.F_define1 AS TransCode";
tableName = @" Sys_SRM_Items it
inner join Sys_SRM_ItemsDetail its on it.F_id = its.f_itemid ";
where = @" it.F_ENCODE='{0}' ";
where = string.Format(where, JsonData.TransType);
sql = string.Format(sql, columns, tableName, where, JsonData.TransCode);
log.Debug("获取自定义档案: " + sql);
DataTable table = DBHelper.SQlReturnData(sql, cmd);
return table;
#endregion
}
catch (Exception ex)
{
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
#region 条码信息
///
/// 条码信息
///
///
///
public static Result BarCodeInformationGet(BarCodeModel JsonData)
{
var language = LanguageHelper.GetName("WMSAPIInfo");
DataTable table = new DataTable();
DataTable ZLtable = new DataTable();
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
try
{
string ScanType = DBHelper.ScanTypeCheck(JsonData.Code, JsonData.WorkPoint, cmd);
if (string.IsNullOrEmpty(JsonData.Code) && JsonData.IsLotNoCapper != "1")
{
throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!!"
}
else if (string.IsNullOrEmpty(JsonData.TransType))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
}
else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
}
else if (string.IsNullOrEmpty(JsonData.WorkPoint))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
}
string TransType = JsonData.TransType;
string sql = "";
string PNTranfersql = "";
string LotTypesql = "";
string Losql = "";
string WLosql = "";
string Lotsplitsql = "";
string Printsql = "";
string LotJLSql = "";
string sqlNew = "";
string LotType = "";
string QuantityWhere = " AND a.Quantity>0";
bool iszl = false;
string zlqty = "0";
string DBValue = EnumHelper.GetDBValue(typeof(TransTypeEnum), TransType);
bool needIns = ICSControlModeService.GetOrderIns(DBValue.Length > 0 ? DBValue : TransType);
log.Debug(EnumHelper.GetDBValue(typeof(TransTypeEnum), TransType) + TransType + needIns);
log.Debug(((TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.PurchaseReceiveDRCoffeeDoc.GetDescription() || TransType == TransTypeEnum.DeliveryNotice.GetDescription()
|| TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription() || TransType == TransTypeEnum.ODeliveryNotice.GetDescription()
|| TransType == TransTypeEnum.MOStockINByProduct.GetDescription() || TransType == TransTypeEnum.MOStockINByProductNoTrans.GetDescription()
|| TransType == TransTypeEnum.OOStockINByProduct.GetDescription() || TransType == TransTypeEnum.OtherInDoc.GetDescription()
|| TransType == TransTypeEnum.PurchaseReceiveRevDoc.GetDescription() || TransType == TransTypeEnum.OutsourcingReceiveRevDoc.GetDescription()) && needIns));
#region SLQ
if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
{
if (JsonData.IsLotNoCapper == "1")
{
if (JsonData.Code == "")
{
Losql = @"
DECLARE @b VARCHAR(MAX)
set @b =
'
SELECT a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,
inv.InvIQC,
inv.LotEnable,CONVERT(varchar(16), lot.ProductDate, 120) AS ProductDate,
a.WarehouseCode,a.LocationCode,b.LocationName,a.Quantity as Qty,SUM(s.sumQty) sumQty,
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MUSERName AS UserName,
CONVERT(varchar(16), a.MTIME, 120) AS [MTime]
FROM ICSWareHouseLotInfo a
LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint and lot.type=''3''
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode,LocationCode,workpoint from ICSWareHouseLotInfo where quantity>0 group by WarehouseCode,INVCode,LocationCode,workpoint)s ON a.workpoint=s.workpoint and a.InvCode=s.InvCode
LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE a.Quantity>0 and a.WorkPoint=''{3}'' and a.InvCode=s.INVCode and a.mtime >= CAST(GETDATE() AS DATE)
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE))
group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME
'
exec(@b)
";
}
else
{
Losql = @"
DECLARE @b VARCHAR(MAX)
set @b =
'
SELECT a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,
inv.InvIQC,
inv.LotEnable,CONVERT(varchar(16), lot.ProductDate, 120) AS ProductDate,
a.WarehouseCode,a.LocationCode,b.LocationName,a.Quantity as Qty,SUM(s.sumQty) sumQty,
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MUSERName AS UserName,
CONVERT(varchar(16), a.MTIME, 120) AS [MTime]
FROM ICSWareHouseLotInfo a
LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint and lot.type=''3''
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode,LocationCode,workpoint from ICSWareHouseLotInfo where quantity>0 group by WarehouseCode,INVCode,LocationCode,workpoint)s ON a.workpoint=s.workpoint and a.InvCode=s.InvCode
LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE a.Quantity>0 and a.WorkPoint=''{3}'' and a.InvCode=s.INVCode and a.mtime >= CAST(GETDATE() AS DATE)
AND a.mtime < DATEADD(DAY, 1, CAST(GETDATE() AS DATE)) and a.invcode=''{2}''
group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME
'
exec(@b)
";
}
}
else
{
//库存查询排除仓库
string whsql = @"SELECT b.F_ItemCode FROM Sys_SRM_Items a
INNER JOIN Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
where a.F_EnCode='OutWHCode' AND b.F_EnabledMark='1' ";
whsql = string.Format(whsql);
DataTable dtt = DBHelper.SQlReturnData(whsql, cmd);
//库存查询界面批次是否扫描
if (null == JsonData.BatchCode || JsonData.BatchCode == "")
{
if (dtt.Rows.Count > 0 && dtt != null)
{
Losql = @" DECLARE @wheresql VARCHAR(MAX)
DECLARE @groupsql VARCHAR(MAX)
DECLARE @aa VARCHAR(MAX)
DECLARE @bb VARCHAR(MAX)
DECLARE @cc VARCHAR(MAX)
DECLARE @dd VARCHAR(MAX)
DECLARE @ee VARCHAR(MAX)
DECLARE @b VARCHAR(MAX)
select @dd=id from ICSInventory where InvStd LIKE '%{2}%'
IF @dd IS not NULL
BEGIN
set @wheresql='and inv.InvStd LIKE ''%{2}%'' '
set @groupsql='group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.WarehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
select @ee=id from ICSInventoryLot where lotno = '{2}'
IF @ee IS not NULL AND '" + JsonData.lotnoSingle + @"' <> 'true'
BEGIN
set @wheresql='and a.InvCode=(SELECT InvCode FROM ICSInventoryLot WHERE LotNo=''{2}'')'
set @groupsql='group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.WarehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
ELSE IF @ee IS not NULL AND '" + JsonData.lotnoSingle + @"' = 'true'
BEGIN
set @wheresql='and a.LotNo=''{2}'''
set @groupsql='group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
select @aa=id from ICSWareHouseLotInfo where LotNo='{2}'
IF @aa IS NOT NULL AND '" + JsonData.lotnoSingle + @"' <> 'true'
BEGIN
set @wheresql='and a.lotno=''{2}'' and s.invcode IN(SELECT invcode FROM ICSWareHouseLotInfo where LotNo=''{2}'') and a.invcode=s.invcode '
set @groupsql=' group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
ELSE IF @aa IS not NULL AND '" + JsonData.lotnoSingle + @"' = 'true'
BEGIN
set @wheresql='and a.LotNo=''{2}'''
set @groupsql='group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
ELSE IF @ee IS not NULL AND @aa IS NULL AND '" + JsonData.lotnoSingle + @"' = 'true'
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo171"), JsonData.Code) + @"',16,1)
RETURN
END
select @bb=id from ICSLocation where LocationCode='{2}'
IF @bb IS not NULL
BEGIN
set @wheresql='and a.locationcode=s.locationcode and a.LocationCode=''{2}'' '
set @groupsql = 'group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
select @cc=id from ICSInventory where invcode='{2}'
IF @cc IS not NULL
BEGIN
set @wheresql='and inv.invcode=''{2}'' '
set @groupsql='group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.WarehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
IF @aa IS NULL and @bb IS NULL and @cc IS NULL and @dd IS NULL and @ee IS NULL
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo478") + @"',16,1)
END
ELSE
BEGIN
set @b =
'SELECT a.WareHouseCode, a.WorkPoint
INTO #BarCodeTemp
FROM ICSWareHouse a
LEFT JOIN (
SELECT b.F_ItemCode
FROM Sys_SRM_Items a
INNER JOIN Sys_SRM_ItemsDetail b ON a.F_Id = b.F_ItemId
WHERE a.F_EnCode = ''OutWHCode'' AND b.F_EnabledMark = ''1''
) AS temp ON a.WareHouseCode = temp.F_ItemCode
WHERE temp.F_ItemCode IS NULL
IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a LEFT JOIN ICSWareHouseLotInfo b ON a.LotNo = b.LotNo WHERE a.LotNo = ''{2}'' AND b.LotNo IS NULL)
BEGIN
SELECT a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,
inv.InvIQC,
inv.LotEnable,CONVERT(varchar(16), lot.ProductDate, 120) AS ProductDate,
a.WarehouseCode,a.LocationCode,b.LocationName,a.Quantity as Qty,SUM(s.sumQty) sumQty,
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MUSERName AS UserName,
CONVERT(varchar(16), a.MTIME, 120) AS [MTime]
FROM ICSWareHouseLotInfo a
LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
inner join #BarCodeTemp wh on a.WareHouseCode=wh.WareHouseCode and a.WorkPoint=wh.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode,LocationCode,workpoint from ICSWareHouseLotInfo
where quantity>0 group by WarehouseCode,INVCode,LocationCode,workpoint)s ON a.workpoint=s.workpoint and a.InvCode=s.InvCode and s.WarehouseCode=wh.WareHouseCode
LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE a.Quantity>0 and a.WorkPoint=''{3}'' '+ @wheresql + @groupsql +' order by a.InvCode,ext.BatchCode
END
ELSE
BEGIN
SELECT a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,
inv.InvIQC,
inv.LotEnable,CONVERT(varchar(16), lot.ProductDate, 120) AS ProductDate,
a.WarehouseCode,a.LocationCode,b.LocationName,a.Quantity as Qty,SUM(s.sumQty) sumQty,
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MUSERName AS UserName,
CONVERT(varchar(16), a.MTIME, 120) AS [MTime]
FROM ICSWareHouseLotInfo a
LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
inner join #BarCodeTemp wh on a.WareHouseCode=wh.WareHouseCode and a.WorkPoint=wh.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode,LocationCode,workpoint from ICSWareHouseLotInfo
where quantity>0 group by WarehouseCode,INVCode,LocationCode,workpoint)s ON a.workpoint=s.workpoint and a.InvCode=s.InvCode and s.WarehouseCode=wh.WareHouseCode
LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE a.Quantity>0 and a.WorkPoint=''{3}'' ' + @wheresql + @groupsql +' order by a.InvCode,ext.BatchCode
END
DROP TABLE #BarCodeTemp
'
END
PRINT @b
exec(@b)
";
}
else
{
Losql = @" DECLARE @wheresql VARCHAR(MAX)
DECLARE @groupsql VARCHAR(MAX)
DECLARE @aa VARCHAR(MAX)
DECLARE @bb VARCHAR(MAX)
DECLARE @cc VARCHAR(MAX)
DECLARE @dd VARCHAR(MAX)
DECLARE @ee VARCHAR(MAX)
DECLARE @b VARCHAR(MAX)
select @dd=id from ICSInventory where InvStd LIKE '%{2}%'
IF @dd IS not NULL
BEGIN
set @wheresql='and inv.InvStd LIKE ''%{2}%'' '
set @groupsql='group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.WarehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
select @ee=id from ICSInventoryLot where lotno = '{2}'
IF @ee IS not NULL AND '" + JsonData.lotnoSingle + @"' <> 'true'
BEGIN
set @wheresql='and a.InvCode=(SELECT InvCode FROM ICSInventoryLot WHERE LotNo=''{2}'')'
set @groupsql='group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.WarehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
ELSE IF @ee IS not NULL AND '" + JsonData.lotnoSingle + @"' = 'true'
BEGIN
set @wheresql='and a.LotNo=''{2}'''
set @groupsql='group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
select @aa=id from ICSWareHouseLotInfo where LotNo='{2}'
IF @aa IS NOT NULL AND '" + JsonData.lotnoSingle + @"' <> 'true'
BEGIN
set @wheresql='and a.lotno=''{2}'' and s.invcode IN(SELECT invcode FROM ICSWareHouseLotInfo where LotNo=''{2}'') and a.invcode=s.invcode '
set @groupsql=' group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
ELSE IF @aa IS not NULL AND '" + JsonData.lotnoSingle + @"' = 'true'
BEGIN
set @wheresql='and a.LotNo=''{2}'''
set @groupsql='group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
ELSE IF @ee IS not NULL AND @aa IS NULL AND '" + JsonData.lotnoSingle + @"' = 'true'
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo171"), JsonData.Code) + @"',16,1)
RETURN
END
select @bb=id from ICSLocation where LocationCode='{2}'
IF @bb IS not NULL
BEGIN
set @wheresql='and a.locationcode=s.locationcode and a.LocationCode=''{2}'' '
set @groupsql = 'group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
select @cc=id from ICSInventory where invcode='{2}'
IF @cc IS not NULL
BEGIN
set @wheresql='and inv.invcode=''{2}'' '
set @groupsql='group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.WarehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
IF @aa IS NULL and @bb IS NULL and @cc IS NULL and @dd IS NULL and @ee IS NULL
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo478") + @"',16,1)
END
ELSE
BEGIN
set @b =
'IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a LEFT JOIN ICSWareHouseLotInfo b ON a.LotNo = b.LotNo WHERE a.LotNo = ''{2}'' AND b.LotNo IS NULL)
BEGIN
SELECT a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,
inv.InvIQC,
inv.LotEnable,CONVERT(varchar(16), lot.ProductDate, 120) AS ProductDate,
a.WarehouseCode,a.LocationCode,b.LocationName,a.Quantity as Qty,SUM(s.sumQty) sumQty,
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MUSERName AS UserName,
CONVERT(varchar(16), a.MTIME, 120) AS [MTime]
FROM ICSWareHouseLotInfo a
LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode,LocationCode,workpoint from ICSWareHouseLotInfo where quantity>0 group by WarehouseCode,INVCode,LocationCode,workpoint)s ON a.workpoint=s.workpoint and a.InvCode=s.InvCode
LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE a.Quantity>0 and a.WorkPoint=''{3}'' '+ @wheresql + @groupsql +' order by a.InvCode,ext.BatchCode
END
ELSE
BEGIN
SELECT a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,
inv.InvIQC,
inv.LotEnable,CONVERT(varchar(16), lot.ProductDate, 120) AS ProductDate,
a.WarehouseCode,a.LocationCode,b.LocationName,a.Quantity as Qty,SUM(s.sumQty) sumQty,
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MUSERName AS UserName,
CONVERT(varchar(16), a.MTIME, 120) AS [MTime]
FROM ICSWareHouseLotInfo a
LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode,LocationCode,workpoint from ICSWareHouseLotInfo where quantity>0 group by WarehouseCode,INVCode,LocationCode,workpoint)s ON a.workpoint=s.workpoint and a.InvCode=s.InvCode
LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE a.Quantity>0 and a.WorkPoint=''{3}'' ' + @wheresql + @groupsql +' order by a.InvCode,ext.BatchCode
END
'
END
PRINT @b
exec(@b)
";
}
}
else
{
if (dtt.Rows.Count > 0 && dtt != null)
{
Losql = @" DECLARE @wheresql VARCHAR(MAX)
DECLARE @groupsql VARCHAR(MAX)
DECLARE @aa VARCHAR(MAX)
DECLARE @bb VARCHAR(MAX)
DECLARE @cc VARCHAR(MAX)
DECLARE @dd VARCHAR(MAX)
DECLARE @ee VARCHAR(MAX)
DECLARE @b VARCHAR(MAX)
--select @ee=lotinfo.id from ICSWareHouseLotInfo lotinfo
--INNER JOIN ICSInventoryLot lot ON lotinfo.lotno=lot.lotno and lotinfo.workpoint=lot.workpoint
--INNER JOIN ICSExtension exx ON lot.ExtensionID=exx.id and lot.workpoint=exx.workpoint
--where exx.BatchCode = '{2}'
--IF @ee IS not NULL
select @ee=id from ICSInventoryLot where lotno = '{2}'
IF @ee IS not NULL AND '" + JsonData.lotnoSingle + @"' <> 'true'
BEGIN
set @wheresql='and a.InvCode=(SELECT InvCode FROM ICSInventoryLot WHERE LotNo=''{2}'')'
set @groupsql='group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.WarehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
ELSE IF @ee IS not NULL AND '" + JsonData.lotnoSingle + @"' = 'true'
BEGIN
set @wheresql='and a.LotNo=''{2}'''
set @groupsql='group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
select @dd=a.id from ICSInventory a INNER JOIN ICSInventoryLot b ON a.invcode=b.invcode and a.workpoint=b.workpoint
INNER JOIN ICSExtension c ON b.ExtensionID=c.id and b.workpoint=c.workpoint where a.InvStd LIKE '%{2}%' AND c.BatchCode='{4}'
IF @dd IS not NULL
BEGIN
set @wheresql='and inv.InvStd LIKE ''%{2}%'' and ext.BatchCode= ''{4}'' '
set @groupsql='group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.WarehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
select @aa=a.id from ICSWareHouseLotInfo a INNER JOIN ICSInventoryLot b ON a.lotno=b.lotno and a.workpoint=b.workpoint
INNER JOIN ICSExtension c ON b.ExtensionID=c.id and b.workpoint=c.workpoint where a.LotNo='{2}' AND c.BatchCode='{4}'
IF @aa IS NOT NULL AND '" + JsonData.lotnoSingle + @"' <> 'true'
BEGIN
set @wheresql='and a.lotno=''{2}'' and ext.BatchCode= ''{4}'' and s.invcode IN(SELECT invcode FROM ICSWareHouseLotInfo where LotNo=''{2}'') and a.invcode=s.invcode '
set @groupsql=' group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
ELSE IF @aa IS not NULL AND '" + JsonData.lotnoSingle + @"' = 'true'
BEGIN
set @wheresql='and a.LotNo=''{2}'''
set @groupsql='group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
ELSE IF @ee IS not NULL AND @aa IS NULL AND '" + JsonData.lotnoSingle + @"' = 'true'
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo171"), JsonData.Code) + @"',16,1)
END
select @bb=a.id from ICSLocation a inner join ICSWareHouseLotInfo aa on a.locationcode=aa.locationcode
INNER JOIN ICSInventoryLot b ON aa.lotno=b.lotno and aa.workpoint=b.workpoint
INNER JOIN ICSExtension c ON b.ExtensionID=c.id and b.workpoint=c.workpoint where a.LocationCode='{2}' AND c.BatchCode='{4}'
IF @bb IS not NULL
BEGIN
set @wheresql='and a.locationcode=s.locationcode and a.LocationCode=''{2}'' and ext.BatchCode= ''{4}'' '
set @groupsql = 'group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
select @cc=a.id from ICSInventory a INNER JOIN ICSInventoryLot b ON a.invcode=b.invcode and a.workpoint=b.workpoint
INNER JOIN ICSExtension c ON b.ExtensionID=c.id and b.workpoint=c.workpoint where a.invcode='{2}' AND c.BatchCode='{4}'
IF @cc IS not NULL
BEGIN
set @wheresql='and inv.invcode=''{2}'' and ext.BatchCode= ''{4}'' '
set @groupsql='group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.WarehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
IF @aa IS NULL and @bb IS NULL and @cc IS NULL and @dd IS NULL and @ee IS NULL
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo478") + @"',16,1)
END
ELSE
BEGIN
set @b =
'SELECT a.WareHouseCode, a.WorkPoint
INTO #BarCodeTemp
FROM ICSWareHouse a
LEFT JOIN (
SELECT b.F_ItemCode
FROM Sys_SRM_Items a
INNER JOIN Sys_SRM_ItemsDetail b ON a.F_Id = b.F_ItemId
WHERE a.F_EnCode = ''OutWHCode'' AND b.F_EnabledMark = ''1''
) AS temp ON a.WareHouseCode = temp.F_ItemCode
WHERE temp.F_ItemCode IS NULL
IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a LEFT JOIN ICSWareHouseLotInfo b ON a.LotNo = b.LotNo WHERE a.LotNo = ''{2}'' AND b.LotNo IS NULL)
BEGIN
SELECT a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,
inv.InvIQC,
inv.LotEnable,CONVERT(varchar(16), lot.ProductDate, 120) AS ProductDate,
a.WarehouseCode,a.LocationCode,b.LocationName,a.Quantity as Qty,SUM(s.sumQty) sumQty,
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MUSERName AS UserName,
CONVERT(varchar(16), a.MTIME, 120) AS [MTime]
FROM ICSWareHouseLotInfo a
LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
inner join #BarCodeTemp wh on a.WareHouseCode=wh.WareHouseCode and a.WorkPoint=wh.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode,LocationCode,workpoint from ICSWareHouseLotInfo
where quantity>0 group by WarehouseCode,INVCode,LocationCode,workpoint)s ON a.workpoint=s.workpoint and a.InvCode=s.InvCode and s.WarehouseCode=wh.WareHouseCode
LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE a.Quantity>0 and ext.BatchCode= ''{4}'' and a.WorkPoint=''{3}'' '+ @wheresql + @groupsql +' order by a.InvCode,ext.BatchCode
END
ELSE
BEGIN
SELECT a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,
inv.InvIQC,
inv.LotEnable,CONVERT(varchar(16), lot.ProductDate, 120) AS ProductDate,
a.WarehouseCode,a.LocationCode,b.LocationName,a.Quantity as Qty,SUM(s.sumQty) sumQty,
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MUSERName AS UserName,
CONVERT(varchar(16), a.MTIME, 120) AS [MTime]
FROM ICSWareHouseLotInfo a
LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
inner join #BarCodeTemp wh on a.WareHouseCode=wh.WareHouseCode and a.WorkPoint=wh.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode,LocationCode,workpoint from ICSWareHouseLotInfo
where quantity>0 group by WarehouseCode,INVCode,LocationCode,workpoint)s ON a.workpoint=s.workpoint and a.InvCode=s.InvCode and s.WarehouseCode=wh.WareHouseCode
LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE a.Quantity>0 and a.WorkPoint=''{3}'' ' + @wheresql + @groupsql +' order by a.InvCode,ext.BatchCode
END
DROP TABLE #BarCodeTemp
'
END
exec(@b)
";
}
else
{
Losql = @" DECLARE @wheresql VARCHAR(MAX)
DECLARE @groupsql VARCHAR(MAX)
DECLARE @aa VARCHAR(MAX)
DECLARE @bb VARCHAR(MAX)
DECLARE @cc VARCHAR(MAX)
DECLARE @dd VARCHAR(MAX)
DECLARE @ee VARCHAR(MAX)
DECLARE @b VARCHAR(MAX)
--select @ee=lotinfo.id from ICSWareHouseLotInfo lotinfo
--INNER JOIN ICSInventoryLot lot ON lotinfo.lotno=lot.lotno and lotinfo.workpoint=lot.workpoint
--INNER JOIN ICSExtension exx ON lot.ExtensionID=exx.id and lot.workpoint=exx.workpoint
--where exx.BatchCode = '{2}'
--IF @ee IS not NULL
select @ee=id from ICSInventoryLot where lotno = '{2}'
IF @ee IS not NULL AND '" + JsonData.lotnoSingle + @"' <> 'true'
BEGIN
set @wheresql='and a.InvCode=(SELECT InvCode FROM ICSInventoryLot WHERE LotNo=''{2}'')'
set @groupsql='group by lot.EATTRIBUTE2,b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.WarehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
ELSE IF @ee IS not NULL AND '" + JsonData.lotnoSingle + @"' = 'true'
BEGIN
set @wheresql='and a.LotNo=''{2}'''
set @groupsql='group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
select @dd=a.id from ICSInventory a INNER JOIN ICSInventoryLot b ON a.invcode=b.invcode and a.workpoint=b.workpoint
INNER JOIN ICSExtension c ON b.ExtensionID=c.id and b.workpoint=c.workpoint where a.InvStd LIKE '%{2}%' AND c.BatchCode='{4}'
IF @dd IS not NULL
BEGIN
set @wheresql='and inv.InvStd LIKE ''%{2}%'' and ext.BatchCode= ''{4}'' '
set @groupsql='group by lot.EATTRIBUTE2,b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.WarehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
select @aa=a.id from ICSWareHouseLotInfo a INNER JOIN ICSInventoryLot b ON a.lotno=b.lotno and a.workpoint=b.workpoint
INNER JOIN ICSExtension c ON b.ExtensionID=c.id and b.workpoint=c.workpoint where a.LotNo='{2}' AND c.BatchCode='{4}'
IF @aa IS NOT NULL AND '" + JsonData.lotnoSingle + @"' <> 'true'
BEGIN
set @wheresql='and a.lotno=''{2}'' and ext.BatchCode= ''{4}'' and s.invcode IN(SELECT invcode FROM ICSWareHouseLotInfo where LotNo=''{2}'') and a.invcode=s.invcode '
set @groupsql=' group by lot.EATTRIBUTE2,b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
ELSE IF @aa IS not NULL AND '" + JsonData.lotnoSingle + @"' = 'true'
BEGIN
set @wheresql='and a.LotNo=''{2}'''
set @groupsql='group by b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
ELSE IF @ee IS not NULL AND @aa IS NULL AND '" + JsonData.lotnoSingle + @"' = 'true'
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo171"), JsonData.Code) + @"',16,1)
RETURN
END
select @bb=a.id from ICSLocation a inner join ICSWareHouseLotInfo aa on a.locationcode=aa.locationcode
INNER JOIN ICSInventoryLot b ON aa.lotno=b.lotno and aa.workpoint=b.workpoint
INNER JOIN ICSExtension c ON b.ExtensionID=c.id and b.workpoint=c.workpoint where a.LocationCode='{2}' AND c.BatchCode='{4}'
IF @bb IS not NULL
BEGIN
set @wheresql='and a.locationcode=s.locationcode and a.LocationCode=''{2}'' and ext.BatchCode= ''{4}'' '
set @groupsql = 'group by lot.EATTRIBUTE2,b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
select @cc=a.id from ICSInventory a INNER JOIN ICSInventoryLot b ON a.invcode=b.invcode and a.workpoint=b.workpoint
INNER JOIN ICSExtension c ON b.ExtensionID=c.id and b.workpoint=c.workpoint where a.invcode='{2}' AND c.BatchCode='{4}'
IF @cc IS not NULL
BEGIN
set @wheresql='and inv.invcode=''{2}'' and a.invcode=s.invcode and ext.BatchCode= ''{4}'' '
set @groupsql='group by lot.EATTRIBUTE2,b.LocationName,lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,inv.LotEnable,a.WarehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MUSERName,a.MTIME'
END
IF @aa IS NULL and @bb IS NULL and @cc IS NULL and @dd IS NULL and @ee IS NULL
BEGIN
RAISERROR('查询的编码不存在!',16,1)
END
ELSE
BEGIN
set @b =
'IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a LEFT JOIN ICSWareHouseLotInfo b ON a.LotNo = b.LotNo WHERE a.LotNo = ''{2}'' AND b.LotNo IS NULL)
BEGIN
SELECT a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,
inv.InvIQC,
inv.LotEnable,CONVERT(varchar(16), lot.ProductDate, 120) AS ProductDate,ISNULL(lot.EATTRIBUTE2,'') AS Memo,
a.WarehouseCode,a.LocationCode,b.LocationName,a.Quantity as Qty,SUM(s.sumQty) sumQty,
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MUSERName AS UserName,
CONVERT(varchar(16), a.MTIME, 120) AS [MTime]
FROM ICSWareHouseLotInfo a
LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode,LocationCode,workpoint from ICSWareHouseLotInfo where quantity>0 group by WarehouseCode,INVCode,LocationCode,workpoint)s ON a.workpoint=s.workpoint and a.InvCode=s.InvCode
LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE a.Quantity>0 and ext.BatchCode= ''{4}'' and a.WorkPoint=''{3}'' '+ @wheresql + @groupsql +' order by a.InvCode,ext.BatchCode
END
ELSE
BEGIN
SELECT a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,
inv.InvIQC,
inv.LotEnable,CONVERT(varchar(16), lot.ProductDate, 120) AS ProductDate,ISNULL(lot.EATTRIBUTE2,'') AS Memo,
a.WarehouseCode,a.LocationCode,b.LocationName,a.Quantity as Qty,SUM(s.sumQty) sumQty,
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MUSERName AS UserName,
CONVERT(varchar(16), a.MTIME, 120) AS [MTime]
FROM ICSWareHouseLotInfo a
LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode,LocationCode,workpoint from ICSWareHouseLotInfo where quantity>0 group by WarehouseCode,INVCode,LocationCode,workpoint)s ON a.workpoint=s.workpoint and a.InvCode=s.InvCode
LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE a.Quantity>0 and a.WorkPoint=''{3}'' ' + @wheresql + @groupsql +' order by a.InvCode,ext.BatchCode
END
'
END
exec(@b)
";
}
}
}
}
else if (TransType == TransTypeEnum.WLotNoSearch.GetDescription())
{
//(SELECT ID FROM icsCoordinateLandMark where state != '0' and locationid =
//(select id from ICSLocation where locationcode = '{2}'))
WLosql = @"
SELECT lot.ID,con.ContainerCode,con.ContainerName,lot.LotNo,lot.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,
inv.InvIQC,
a.WarehouseCode,a.LocationCode,b.LandMark,inv.LotEnable,CONVERT(varchar(16), lot.ProductDate, 120) AS ProductDate,lot.Quantity as Qty,
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
lot.MUSER AS [User],
lot.MUSERName AS UserName,
CONVERT(varchar(16), lot.MTIME, 120) AS [MTime]
FROM ICSInventoryLot lot
LEFT JOIN ICSWareHouseLotInfo a ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint --and lot.type=''3''
--LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
--LEFT JOIN icsCoordinateLandMark lm ON lm.locationid = b.ID
LEFT JOIN (select top 1 a.ToLocationcode as Locationcode,lm.LandMark from ICSSmartDeviceLog a
inner join icsCoordinateLandMark lm ON lm.locationid = a.TOlocationid
where a.lotno = '{2}' and a.TransType like '%入库%' order by a.mtime desc) b on 1=1
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
--INNER JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode,LocationCode,workpoint from ICSWareHouseLotInfo where quantity>0 group by WarehouseCode,INVCode,LocationCode,workpoint)s ON lot.workpoint=s.workpoint and lot.InvCode=s.InvCode
LEFT JOIN ICSContainerLot conlot ON lot.LotNo=conlot.LotNo AND lot.WorkPoint=conlot.WorkPoint
LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
LEFT JOIN ICSInventory inv ON lot.InvCode=inv.InvCode AND lot.WorkPoint=inv.WorkPoint
WHERE lot.lotno = '{2}' and lot.workpoint= '{3}'
";
}
else if (TransType == TransTypeEnum.CodeSplitSearch.GetDescription())
{
Lotsplitsql = @"select
isnull(case
WHEN a.Type = 22 THEN d.EATTRIBUTE8
WHEN a.Type = 23 THEN e.EATTRIBUTE8
WHEN a.Type = 2 THEN a.EATTRIBUTE8
WHEN a.Type = 3 THEN f.EATTRIBUTE8
WHEN a.Type = 5 THEN qt.EATTRIBUTE8
WHEN a.Type = 12 THEN a.EATTRIBUTE8
WHEN a.Type = 0 THEN a.EATTRIBUTE8
WHEN a.Type = 24 THEN a.EATTRIBUTE8
WHEN a.Type = 201 THEN a.EATTRIBUTE8
WHEN a.Type = 203 THEN a.EATTRIBUTE8
ELSE NULL
END ,'')as xm,
isnull(case
WHEN a.Type = 22 THEN d.EATTRIBUTE3
WHEN a.Type = 23 THEN e.EATTRIBUTE3
WHEN a.Type = 2 THEN a.EATTRIBUTE3
WHEN a.Type = 5 THEN qt.EATTRIBUTE3
WHEN a.Type = 12 THEN a.EATTRIBUTE3
WHEN a.Type = 0 THEN a.EATTRIBUTE3
WHEN a.Type = 24 THEN a.EATTRIBUTE3
WHEN a.Type = 201 THEN a.EATTRIBUTE8
WHEN a.Type = 203 THEN a.EATTRIBUTE8
ELSE NULL
END ,'')as gys,
isnull(case
WHEN a.Type = 23 THEN e.EATTRIBUTE7
WHEN a.Type = 3 THEN f.EATTRIBUTE7
ELSE NULL
END ,'')as jyy,
isnull(case
WHEN a.Type = 22 THEN d.EATTRIBUTE6
WHEN a.Type = 23 THEN e.EATTRIBUTE6
WHEN a.Type = 3 THEN f.EATTRIBUTE6
WHEN a.Type = 5 THEN qt.EATTRIBUTE6
WHEN a.Type = 2 THEN a.EATTRIBUTE6
WHEN a.Type = 12 THEN a.EATTRIBUTE6
WHEN a.Type = 0 THEN a.EATTRIBUTE6
WHEN a.Type = 24 THEN a.EATTRIBUTE6
WHEN a.Type = 101 THEN a.EATTRIBUTE6
ELSE NULL
END ,'')as ywy,
isnull(h.BatchCode,'') as pc,
-- Ʒ
isnull(e.RCVCode ,'')as ddh,
isnull(e.EATTRIBUTE4 ,'')as dz,
--ԭ
isnull(d.EATTRIBUTE9 ,'')as cslh,
-- Ʒ
isnull(a.EATTRIBUTE10 ,'')as mbbl,
isnull(a.EATTRIBUTE7,'') as xqfl,
--
isnull(b.InvName,'') as pm,
isnull(a.WorkPoint ,'')as zd,
isnull(a.InvCode ,'')as ph,
isnull(b.InvStd ,'')as ggxh,
isnull(b.EATTRIBUTE9 ,'')as khlh,
isnull(b.InvUnit ,'')as dw,
a1.Quantity as sl,
FORMAT(a.MTIME, 'yyyy-MM-dd')as rq,
a1.LotNo as OLDLotNo,
a2.EATTRIBUTE1 as YTLotNo
FROM
ICSWareHouseLotInfo a1
LEFT JOIN ICSInventoryLot a
ON
a.LotNo =
CASE
WHEN LEN(a1.LotNo) > 25 THEN a1.LotNo
ELSE
CASE
WHEN CHARINDEX('-', a1.LotNo) > 0 THEN LEFT(a1.LotNo, CHARINDEX('-', a1.LotNo) - 1)
ELSE a1.LotNo
END
END
AND a.WorkPoint = a1.WorkPoint
LEFT JOIN ICSInventoryLot a2 on a1.LotNo=a2.LotNo and a1.WorkPoint=a2.WorkPoint
INNER JOIN ICSInventory b ON b.InvCode = a1.InvCode AND b.WorkPoint = a1.WorkPoint
LEFT JOIN ICSInventoryLotDetail c ON a.LotNO = c.LotNO AND a.WorkPoint = c.WorkPoint
LEFT JOIN ICSPurchaseReceive d ON d.RCVCode = c.TransCode AND d.Sequence = c.TransSequence AND d.WorkPoint = c.WorkPoint AND a.Type = 22
LEFT JOIN ICSOutsourcingReceive e ON e.RCVCode = c.TransCode AND e.Sequence = c.TransSequence AND e.WorkPoint = c.WorkPoint AND a.Type = 23
LEFT join ICSMO f on f.MOCode=c.TransCode and f.Sequence=c.TransSequence and f.WorkPoint=c.WorkPoint and a.Type =3
LEFT join ICSOtherIn qt on qt.InCode=c.TransCode and qt.Sequence=c.TransSequence and qt.WorkPoint=c.WorkPoint and a.Type =5
LEFT join ICSExtension h on h.ID=a2.ExtensionID and h.WorkPoint=a2.WorkPoint --and a.Type <> 22 and a.Type <> 23 and a.Type <> 3
where a1.lotno like '{2}%' and a1.workpoint='{3}' ";
}
else if (TransType == TransTypeEnum.CodePrint.GetDescription())
{
Printsql = @"select ISNULL(C.LotNo,'') AS LOTNO,ISNULL(B.InvCode,'') AS InvCode,ISNULL(d.InvName,'') AS INVNAME,ISNULL(d.InvStd,'') AS INVSTD,ISNULL(C.Quantity,0) AS LotQty,c.LocationCode,
ISNULL(c.MTIME,'') AS MTIME,ISNULL(b.EATTRIBUTE4,'') AS VenCode,ISNULL(h.VenName,'') AS cVenName,ISNULL(d.InvUnit,'') AS InvUnit,ISNULL(b.EATTRIBUTE3,'') AS POCode,ISNULL(g.ProjectCode,'') AS EATTRIBUTE4,ISNULL(d.InvUnit,'') AS InvUnit,ISNULL(g.BatchCode,'') AS BatchCode,CONVERT(VARCHAR(10), B.ProductDate, 120) as ProductDate,CONVERT(VARCHAR(10), B.ExpirationDate, 120) as ExpirationDate,d.EATTRIBUTE5 from ICSInventoryLot B
left join ICSWareHouseLotInfo C ON B.LotNO=C.LotNO and B.WorkPoint=c.WorkPoint
left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
left join ICSInventoryLotDetail e on b.lotNo=e.LotNo and b.WorkPoint=e.WorkPoint
LEFT JOIN ICSPurchaseOrder f ON f.POCode=e.TransCode AND f.Sequence=e.TransSequence AND f.WorkPoint=e.WorkPoint
left join ICSVendor h on f.VenCode=h.VenCode and e.WorkPoint=h.WorkPoint
left join ICSExtension g on b.ExtensionID=g.ID and b.WorkPoint=g.WorkPoint
where B.LotNo='{2}' AND B.workpoint='{3}' AND C.Quantity>0
UNION ALL
select ISNULL(C.LotNo,'') AS LOTNO,ISNULL(B.InvCode,'') AS InvCode,ISNULL(d.InvName,'') AS INVNAME,ISNULL(d.InvStd,'') AS INVSTD,ISNULL(C.Quantity,0) AS LotQty,c.LocationCode,
ISNULL(c.MTIME,'') AS MTIME,'' AS VenCode,'' AS cVenName,d.InvUnit,'' AS POCode,'' AS EATTRIBUTE4,d.InvUnit,g.BatchCode,CONVERT(VARCHAR(10), B.ProductDate, 120) as ProductDate,CONVERT(VARCHAR(10), B.ExpirationDate, 120) as ExpirationDate,d.EATTRIBUTE5 from ICSInventoryLot B
left join ICSWareHouseLotInfo C ON B.LotNO=C.LotNO and B.WorkPoint=c.WorkPoint
left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
left join ICSInventoryLotDetail e on b.lotNo=e.LotNo and b.WorkPoint=e.WorkPoint
left join ICSExtension g on b.ExtensionID=g.ID and b.WorkPoint=g.WorkPoint
where B.LotNo='{2}' AND B.workpoint='{3}' AND C.Quantity>0
UNION ALL
select ISNULL(C.LotNo,'') AS LOTNO,ISNULL(B.InvCode,'') AS InvCode,ISNULL(d.InvName,'') AS INVNAME,ISNULL(d.InvStd,'') AS INVSTD,ISNULL(C.Quantity,0) AS LotQty,c.LocationCode,
ISNULL(c.MTIME,'') AS MTIME,ISNULL(f.VenCode,'') AS VenCode,ISNULL(h.VenName,'') AS cVenName,ISNULL(d.InvUnit,'') AS InvUnit,ISNULL(f.POCode,'') AS POCode,ISNULL(f.EATTRIBUTE4,'') AS EATTRIBUTE4,ISNULL(d.InvUnit,'') AS InvUnit,ISNULL(g.BatchCode,'') AS BatchCode,CONVERT(VARCHAR(10), B.ProductDate, 120) as ProductDate,CONVERT(VARCHAR(10), B.ExpirationDate, 120) as ExpirationDate,d.EATTRIBUTE5 from ICSInventoryLot B
inner join ICSWareHouseLotInfo C ON B.LotNO=C.LotNO and B.WorkPoint=c.WorkPoint
inner join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
inner join ICSInventoryLotDetail e on b.lotNo=e.LotNo and b.WorkPoint=e.WorkPoint
inner JOIN ICSPurchaseOrder f ON f.POCode=e.TransCode AND f.Sequence=e.TransSequence AND f.WorkPoint=e.WorkPoint
inner join ICSVendor h on f.VenCode=h.VenCode and e.WorkPoint=h.WorkPoint
inner join ICSExtension g on b.ExtensionID=g.ID and b.WorkPoint=g.WorkPoint
where B.InvCode='{2}' AND B.workpoint='{3}' AND C.Quantity>0
UNION ALL
select ISNULL(C.LotNo,'') AS LOTNO,ISNULL(B.InvCode,'') AS InvCode,ISNULL(d.InvName,'') AS INVNAME,ISNULL(d.InvStd,'') AS INVSTD,ISNULL(C.Quantity,0) AS LotQty,c.LocationCode,
ISNULL(c.MTIME,'') AS MTIME,'' AS VenCode,'' AS cVenName,d.InvUnit,'' AS POCode,'' AS EATTRIBUTE4,d.InvUnit,g.BatchCode,CONVERT(VARCHAR(10), B.ProductDate, 120) as ProductDate,CONVERT(VARCHAR(10), B.ExpirationDate, 120) as ExpirationDate,d.EATTRIBUTE5 from ICSInventoryLot B
inner join ICSWareHouseLotInfo C ON B.LotNO=C.LotNO and B.WorkPoint=c.WorkPoint
inner join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
inner join ICSInventoryLotDetail e on b.lotNo=e.LotNo and b.WorkPoint=e.WorkPoint
inner join ICSExtension g on b.ExtensionID=g.ID and b.WorkPoint=g.WorkPoint
where B.InvCode='{2}' AND B.workpoint='{3}' AND C.Quantity>0
";
}
else if (TransType == TransTypeEnum.LotJL.GetDescription())
{
LotJLSql = @"select
a.LotNo,
a.TransCode,
a.TransSequence,
a.MTime,
bb.Name AS TransType,
a.InvCode,
o.BatchCode,
c.InvName,
c.InvStd,
a.Quantity,
d.WarehouseName AS FromWarehouseName,
f.LocationName AS FromLocationName,
d1.WarehouseName AS ToWarehouseName,
f1.LocationName AS ToLocationName,
a.MUSERName
from ICSWareHouseLotInfoLog a
inner join ICSInventoryLot b on b.LotNo=a.LotNo --and b.WorkPoint=a.WorkPoint
inner join ICSInventory c on c.InvCode=a.InvCode and c.WorkPoint=a.WorkPoint
left join ICSWarehouse d on d.WarehouseCode=a.FromWarehouseCode and a.WorkPoint=d.WorkPoint
left join ICSLocation f on f.LocationCode=a.FromLocationCode and a.WorkPoint=f.WorkPoint
left join ICSWarehouse d1 on d1.WarehouseCode=a.ToWarehouseCode and d1.WorkPoint=a.WorkPoint
left join ICSLocation f1 on f1.LocationCode=a.ToLocationCode and f1.WorkPoint=a.WorkPoint
left join ICSExtension o on o.ID=b.ExtensionID and o.WorkPoint=b.WorkPoint
left join ICSType BB with (nolock) on a.BusinessCode=bb.Code and bb.TableCode='ICSWareHouseLotInfoLog' and bb.ColumnCode='businesscode'
where a.lotno='{2}' and bb.Name<>'拆分前'
";
}
else
{
//派纳调拨,不用站点条件
if (DBHelper.IsPNU9() && TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
{
if (ScanType == "LOTNO")
{
sql = @"SELECT a.ID,
con.ContainerCode,
con.ContainerName,
a.LotNo,
a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,
inv.InvIQC,
inv.LotEnable,
{0}
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.Version,
--ext.BatchCode,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MTIME AS [MTime],
'" + ScanType + @"' AS ScanType
FROM {1}
LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE a.LotNo='{2}' ";
}
else
{
sql = @"SELECT a.ID,
con.ContainerCode,
con.ContainerName,
a.LotNo,
a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,
inv.InvIQC,
inv.LotEnable,
{0}
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.Version,
--ext.BatchCode,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MTIME AS [MTime],
'" + ScanType + @"' AS ScanType
FROM {1}
LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
LEFT JOIN ICSBomALL bom ON bom.ID=conlot.ContainerID
LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE bom.TContainerCode='{2}' ";
}
}
else
{
if (ScanType == "LOTNO")
{
#region 验证是否到货
if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.PurchaseReceiveDRCoffeeDoc.GetDescription() || TransType == TransTypeEnum.PurchaseReceiveDRCoffeeDoc.GetDescription())
{
string arrivalCtrlSql = string.Format(@"IF NOT EXISTS(SELECT
1
FROM ICSInventoryLot lot
INNER JOIN ICSASNDetail asde ON asde.LotNo=lot.LotNo AND asde.WorkPoint=lot.WorkPoint
INNER JOIN ICSDeliveryNotice dn ON dn.ASNCode=asde.ASNCode AND dn.WorkPoint=asde.WorkPoint
WHERE lot.LotNo='{0}' AND lot.WorkPoint='{1}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo532"), "{0}") + @"',16,1);
RETURN
END", JsonData.Code, JsonData.WorkPoint);
DBHelper.ExecuteNonQuery(arrivalCtrlSql, cmd);
}
if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
{
string arrivalCtrlSql = string.Format(@"IF NOT EXISTS(SELECT
1
FROM ICSInventoryLot lot
INNER JOIN ICSOASNDetail asde ON asde.LotNo=lot.LotNo AND asde.WorkPoint=lot.WorkPoint
INNER JOIN ICSODeliveryNotice dn ON dn.OASNCode=asde.OASNCode AND dn.WorkPoint=asde.WorkPoint
WHERE lot.LotNo='{0}' AND lot.WorkPoint='{1}'
--铭锋特殊 委外订单和到货单源头均为委外订单
union
select 1 FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSODeliveryNotice d ON b.TransCode=d.ODNCode AND b.TransSequence=d.Sequence AND b.WorkPoint=d.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
)
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo532"), "{0}") + @"',16,1);
RETURN
END", JsonData.Code, JsonData.WorkPoint);
DBHelper.ExecuteNonQuery(arrivalCtrlSql, cmd);
}
#endregion
//验证条码是否存在
string verifyLotExistSql = "";
if (DBHelper.IsPNU9() && TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
{
verifyLotExistSql = string.Format(@"IF NOT EXISTS(SELECT 1 FROM ICSInventoryLot WHERE LotNo='{0}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{0}") + @"',16,1);
RETURN
END", JsonData.Code, JsonData.WorkPoint);
}
else
{
verifyLotExistSql = string.Format(@"IF NOT EXISTS(SELECT 1 FROM ICSInventoryLot WHERE LotNo='{0}' AND WorkPoint='{1}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{0}") + @"',16,1);
RETURN
END", JsonData.Code, JsonData.WorkPoint);
}
DBHelper.ExecuteNonQuery(verifyLotExistSql, cmd);
sql = @"SELECT a.ID,
isnull(con.ContainerCode,'') AS ContainerCode,
isnull(con.ContainerName,'') AS ContainerName,
a.LotNo,
a.InvCode,
ISNULL(inv.EATTRIBUTE10,'') AS KInvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,
inv.InvIQC,
inv.LotEnable,
{0}
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.Version,
--ext.BatchCode,
isnull((select a.F_EnabledMark from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_id='500fb2a3-c597-4371-ab18-b280b55d571e'),'') AS LotSplitEnable,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MTIME AS [MTime],
'" + ScanType + @"' AS ScanType
FROM {1}
LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' ";
}
else
{
#region 验证是否到货
if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.PurchaseReceiveDRCoffeeDoc.GetDescription())
{
string arrivalCtrlSql = string.Format(@"WITH ICSBomALL AS
(
SELECT
ContainerCode AS TContainerCode,
ContainerCode AS PContainerCode,
ContainerCode AS ContainerCode,
ID,
ContainerID,
WorkPoint,
0 AS [Level],
CAST(1 AS nvarchar(MAX)) AS SortSeq,
CAST('00001' AS nvarchar(MAX)) AS Sort
FROM ICSContainer
WHERE ContainerCode='{0}' AND WorkPoint='{1}'
UNION ALL
SELECT
b.TContainerCode,
b.ContainerCode AS PContainerCode,
a.ContainerCode,
a.ID,
a.ContainerID,
a.WorkPoint,
b.[Level]+1 AS [Level],
CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
FROM
ICSContainer a
INNER JOIN ICSBomALL b ON a.ContainerID=b.ID AND a.WorkPoint=b.WorkPoint
)
SELECT *
INTO #TempICSBomALL
FROM ICSBomALL;
IF NOT EXISTS(SELECT
1
FROM #TempICSBomALL con
INNER JOIN ICSContainerLot conlot ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSInventoryLot lot ON lot.LotNo=conlot.LotNo AND lot.WorkPoint=conlot.WorkPoint
INNER JOIN ICSASNDetail asde ON asde.LotNo=lot.LotNo AND asde.WorkPoint=lot.WorkPoint
INNER JOIN ICSDeliveryNotice dn ON dn.ASNCode=asde.ASNCode AND dn.WorkPoint=asde.WorkPoint
WHERE con.TContainerCode='{0}' AND con.WorkPoint='{1}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo532"), "{0}") + @"',16,1);
RETURN
END
DROP TABLE #TempICSBomALL", JsonData.Code, JsonData.WorkPoint);
DBHelper.ExecuteNonQuery(arrivalCtrlSql, cmd);
}
if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
{
string arrivalCtrlSql = string.Format(@"WITH ICSBomALL AS
(
SELECT
ContainerCode AS TContainerCode,
ContainerCode AS PContainerCode,
ContainerCode AS ContainerCode,
ID,
ContainerID,
WorkPoint,
0 AS [Level],
CAST(1 AS nvarchar(MAX)) AS SortSeq,
CAST('00001' AS nvarchar(MAX)) AS Sort
FROM ICSContainer
WHERE ContainerCode='{0}' AND WorkPoint='{1}'
UNION ALL
SELECT
b.TContainerCode,
b.ContainerCode AS PContainerCode,
a.ContainerCode,
a.ID,
a.ContainerID,
a.WorkPoint,
b.[Level]+1 AS [Level],
CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
FROM
ICSContainer a
INNER JOIN ICSBomALL b ON a.ContainerID=b.ID AND a.WorkPoint=b.WorkPoint
)
SELECT *
INTO #TempICSBomALL
FROM ICSBomALL;
IF NOT EXISTS(SELECT
1
FROM #TempICSBomALL con
INNER JOIN ICSContainerLot conlot ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSInventoryLot lot ON lot.LotNo=conlot.LotNo AND lot.WorkPoint=conlot.WorkPoint
INNER JOIN ICSOASNDetail asde ON asde.LotNo=lot.LotNo AND asde.WorkPoint=lot.WorkPoint
INNER JOIN ICSODeliveryNotice dn ON dn.OASNCode=asde.OASNCode AND dn.WorkPoint=asde.WorkPoint
WHERE con.TContainerCode='{0}' AND con.WorkPoint='{1}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo532"), "{0}") + @"',16,1);
RETURN
END
DROP TABLE #TempICSBomALL", JsonData.Code, JsonData.WorkPoint);
DBHelper.ExecuteNonQuery(arrivalCtrlSql, cmd);
}
#endregion
//验证箱号中的条码是否存在
string verifyLotExistSql = string.Format(@"WITH ICSBomALL AS
(
SELECT
ContainerCode AS TContainerCode,
ContainerCode AS PContainerCode,
ContainerCode AS ContainerCode,
ID,
ContainerID,
WorkPoint,
0 AS [Level],
CAST(1 AS nvarchar(MAX)) AS SortSeq,
CAST('00001' AS nvarchar(MAX)) AS Sort
FROM ICSContainer
WHERE ContainerCode='{0}' AND WorkPoint='{1}'
UNION ALL
SELECT
b.TContainerCode,
b.ContainerCode AS PContainerCode,
a.ContainerCode,
a.ID,
a.ContainerID,
a.WorkPoint,
b.[Level]+1 AS [Level],
CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
FROM
ICSContainer a
INNER JOIN ICSBomALL b ON a.ContainerID=b.ID AND a.WorkPoint=b.WorkPoint
)
SELECT *
INTO #TempICSBomALL
FROM ICSBomALL;
IF NOT EXISTS(SELECT 1 FROM #TempICSBomALL a
INNER JOIN ICSContainerLot b ON b.ContainerID=a.ID AND b.WorkPoint=a.WorkPoint
INNER JOIN ICSInventoryLot c ON c.LotNo=b.LotNo AND c.WorkPoint=b.WorkPoint
WHERE a.TContainerCode='{0}' AND a.WorkPoint='{1}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{0}") + @"',16,1);
RETURN
END
DROP TABLE #TempICSBomALL", JsonData.Code, JsonData.WorkPoint);
DBHelper.ExecuteNonQuery(verifyLotExistSql, cmd);
sql = @"SELECT a.ID,
bom.PContainerCode AS ContainerCode,
con.ContainerName,
a.LotNo,
a.InvCode,
inv.InvName,
inv.InvStd,
inv.LotEnable,
inv.InvUnit,
inv.InvIQC,
{0}
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.Version,
--ext.BatchCode,
isnull((select a.F_EnabledMark from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_id='500fb2a3-c597-4371-ab18-b280b55d571e'),'') AS LotSplitEnable,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MTIME AS [MTime],
'" + ScanType + @"' AS ScanType
FROM {1}
LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
LEFT JOIN #TempICSBomALL bom ON bom.ID=conlot.ContainerID
LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE bom.TContainerCode='{2}' AND a.WorkPoint='{3}' {6}";
}
}
}
#endregion
bool isOut = false; //出库标记
string columns = string.Empty; //查询源头单据表的特殊列名
string columnsLOCODE = string.Empty;
string columnsLONAME = string.Empty;
string columnsWHCODE = string.Empty;
string columnsWHNAME = string.Empty;
string tableName = string.Empty; //查询源头单据表名
string where = string.Empty; //排序
if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription() //采购退货
|| TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription() //委外发料
|| TransType == TransTypeEnum.RTOutsourcingIssueDoc.GetDescription() //委外发料
|| TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription() //委外退货
|| TransType == TransTypeEnum.MOIssueDoc.GetDescription() //生产发料
|| TransType == TransTypeEnum.JHMOIssueDoc.GetDescription() //金豪表外领料
|| TransType == TransTypeEnum.MOIssueAutoDoc.GetDescription() //生产发料——自动出库
|| TransType == TransTypeEnum.SalesShipmentDoc.GetDescription() //销售出库
|| TransType == TransTypeEnum.SalesShipmentOutDoc.GetDescription() //销售出库
|| TransType == TransTypeEnum.JHSalesShipmentOutDoc.GetDescription()
|| TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription() //一步调拨
|| TransType == TransTypeEnum.StepTransferDocIn.GetDescription() //调拨
|| TransType == TransTypeEnum.StepNoTransferDocIn.GetDescription() //无源头调拨
|| TransType == TransTypeEnum.JHStepNoTransferDocIn.GetDescription() //无源头调拨
|| TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription() //调拨申请单
|| TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription() //两步调出
|| TransType == TransTypeEnum.JHTwoStepTransferDocOut.GetDescription() //两步调出
|| TransType == TransTypeEnum.OtherOutDoc.GetDescription() //其他出库
|| TransType == TransTypeEnum.OtherInRedDoc.GetDescription() //红字其他入库
|| TransType == TransTypeEnum.Check.GetDescription() //盘点
|| TransType == TransTypeEnum.MOApply.GetDescription() //领料申请单
|| TransType == TransTypeEnum.MOReplenishment.GetDescription() //领料申请单
|| TransType == TransTypeEnum.OOApply.GetDescription() //委外领料申请单
|| TransType == TransTypeEnum.MOIssue.GetDescription() //开立材料出库单
|| TransType == TransTypeEnum.OOIssue.GetDescription() //开立委外材料出库单
|| TransType == TransTypeEnum.PurchaseReceive.GetDescription() //开立红字入库单
|| TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription()//开立委外红字入库单
|| TransType == TransTypeEnum.BrrowDoc.GetDescription() //借用
|| TransType == TransTypeEnum.TransferLibrary.GetDescription() //移库
|| TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription() //移库
|| TransType == TransTypeEnum.PurchaseReceiveDoctNegativePo.GetDescription() //采购退货-采购订单
|| TransType == TransTypeEnum.OutsourcingReturnBackPo.GetDescription() //委外退货-委外采购订单
|| TransType == TransTypeEnum.GiftOutDoc.GetDescription() //赠品出库
//|| TransType == TransTypeEnum.DisassemblyDoc.GetDescription() //拆卸单(散件生成条码入库)
)
{
isOut = true;
}
//库位查询
if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
{
// Losql = @"" + Losql + "group by a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.LotEnable,s.WarehouseCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,s.sumQty,inv.AmountUnit,ext.ID,ext.ProjectCode,ext.Version,ext.Brand, " +
// "ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MTIME";
// columns = @"s.WarehouseCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,sum(a.Quantity) as Qty,s.sumQty,";
// tableName = @"ICSWareHouseLotInfo a
//LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
//INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
//INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
//LEFT JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode from ICSWareHouseLotInfo group by WarehouseCode,INVCode)s
//ON a.INVCode=s.INVCode ";
}
//库位查询
else if (TransType == TransTypeEnum.CodePrint.GetDescription())
{
}
else
{
//两步调入条码
if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
{
if (string.IsNullOrEmpty(JsonData.TransCode))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
}
if (ScanType == "LOTNO")
{
sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSOtherIn Otin
INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND Otin.InCode = '" + JsonData.TransCode + @"')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo036") + @"',16,1);
RETURN
END
" + sql + "AND Otin.InCode = '" + JsonData.TransCode + @"'
GROUP BY inv.EATTRIBUTE10,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,a.WarehouseCode,
wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
columns = @"SUM(log.Quantity) AS Quantity,
SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
a.WarehouseCode AS WHCode,
wh.WarehouseName AS WHName,
a.LocationCode,
loc.LocationName,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,";
tableName = @"ICSOtherIn Otin
INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
}
else
{
sql = @"WITH ICSBomALL AS
(
SELECT
ContainerCode AS TContainerCode,
ContainerCode AS PContainerCode,
ContainerCode AS ContainerCode,
ID,
ContainerID,
0 AS [Level],
CAST(1 AS nvarchar(MAX)) AS SortSeq,
CAST('00001' AS nvarchar(MAX)) AS Sort
FROM ICSContainer
WHERE ContainerCode='{2}'
UNION ALL
SELECT
b.TContainerCode,
b.ContainerCode AS PContainerCode,
a.ContainerCode,
a.ID,
a.ContainerID,
b.[Level]+1 AS [Level],
CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
FROM
ICSContainer a
INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
)
" + sql + "AND Otin.InCode = '" + JsonData.TransCode + @"'
GROUP BY inv.EATTRIBUTE10,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,a.WarehouseCode,
wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
columns = @"SUM(log.Quantity) AS Quantity,
SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
a.WarehouseCode AS WHCode,
wh.WarehouseName AS WHName,
a.LocationCode,
loc.LocationName,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,";
tableName = @"ICSOtherIn Otin
INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
}
}
else if (TransType == TransTypeEnum.JHTwoStepTransferDocIn.GetDescription())
{
if (string.IsNullOrEmpty(JsonData.TransCode))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
}
if (ScanType == "LOTNO")
{
sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSTransfer tra
INNER JOIN ICSWareHouseLotInfoLog log ON tra.TransferNo=log.TransCode AND tra.Sequence=log.TransSequence AND tra.ID=log.TransID AND tra.WorkPoint=log.WorkPoint
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND log.BusinessCode='22-1')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo036") + @"',16,1);
RETURN
END
" + sql + @"
GROUP BY inv.EATTRIBUTE10,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,a.WarehouseCode,
wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
columns = @"SUM(log.Quantity) AS Quantity,
SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
a.WarehouseCode AS WHCode,
wh.WarehouseName AS WHName,
a.LocationCode,
loc.LocationName,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,";
tableName = @"ICSTransfer tra
INNER JOIN ICSWareHouseLotInfoLog log ON tra.TransferNo=log.TransCode AND tra.Sequence=log.TransSequence AND tra.ID=log.TransID AND tra.WorkPoint=log.WorkPoint
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
}
else
{
sql = @"WITH ICSBomALL AS
(
SELECT
ContainerCode AS TContainerCode,
ContainerCode AS PContainerCode,
ContainerCode AS ContainerCode,
ID,
ContainerID,
0 AS [Level],
CAST(1 AS nvarchar(MAX)) AS SortSeq,
CAST('00001' AS nvarchar(MAX)) AS Sort
FROM ICSContainer
WHERE ContainerCode='{2}'
UNION ALL
SELECT
b.TContainerCode,
b.ContainerCode AS PContainerCode,
a.ContainerCode,
a.ID,
a.ContainerID,
b.[Level]+1 AS [Level],
CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
FROM
ICSContainer a
INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
)
" + sql + "AND tra.TransferNo = '" + JsonData.TransCode + @"'
GROUP BY inv.EATTRIBUTE10,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,a.WarehouseCode,
wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
columns = @"SUM(log.Quantity) AS Quantity,
SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
a.WarehouseCode AS WHCode,
wh.WarehouseName AS WHName,
a.LocationCode,
loc.LocationName,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,";
tableName = @"ICSTransfer tra
INNER JOIN ICSWareHouseLotInfoLog log ON tra.TransferNo=log.TransCode AND tra.Sequence=log.TransSequence AND tra.ID=log.TransID AND tra.WorkPoint=log.WorkPoint
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
}
}
//销售退货-原条码(可支持一个条码多次发货,汇总数量,目前加了限制:785-793行)
else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
{
if (string.IsNullOrEmpty(JsonData.TransCode))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
}
if (ScanType == "LOTNO")
{
sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSSDN sdn
INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND sdn.Type='1')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo037") + @"',16,1);
RETURN
END
IF EXISTS(SELECT log.LotNo FROM ICSSDN sdn
INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND sdn.Type='1' AND log.BusinessCode='19'
GROUP BY log.LotNo HAVING COUNT(log.LotNo)>=2)
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo191"), "{2}") + @"',16,1);
RETURN
END
" + sql + @"AND sdn.Type='1'
GROUP BY inv.EATTRIBUTE10,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,a.WarehouseCode,
wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
columns = @"SUM(log.Quantity) AS Quantity,
SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
a.WarehouseCode AS WHCode,
wh.WarehouseName AS WHName,
a.LocationCode,
loc.LocationName,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,";
tableName = @"ICSSDN sdn
INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
}
else
{
sql = @"WITH ICSBomALL AS
(
SELECT
ContainerCode AS TContainerCode,
ContainerCode AS PContainerCode,
ContainerCode AS ContainerCode,
ID,
ContainerID,
0 AS [Level],
CAST(1 AS nvarchar(MAX)) AS SortSeq,
CAST('00001' AS nvarchar(MAX)) AS Sort
FROM ICSContainer
WHERE ContainerCode='{2}'
UNION ALL
SELECT
b.TContainerCode,
b.ContainerCode AS PContainerCode,
a.ContainerCode,
a.ID,
a.ContainerID,
b.[Level]+1 AS [Level],
CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
FROM
ICSContainer a
INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
)
" + sql + @"AND sdn.Type='1'
GROUP BY inv.EATTRIBUTE10,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,a.WarehouseCode,
wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
columns = @"SUM(log.Quantity) AS Quantity,
SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
a.WarehouseCode AS WHCode,
wh.WarehouseName AS WHName,
a.LocationCode,
loc.LocationName,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,";
tableName = @"ICSSDN sdn
INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
}
}
//销售出库红字出库单-原条码(可支持一个条码多次发货,汇总数量,目前加了限制:785-793行)
else if (TransType == TransTypeEnum.SalesShipmentOutRedYuanDoc.GetDescription())
{
if (string.IsNullOrEmpty(JsonData.TransCode))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
}
if (ScanType == "LOTNO")
{
sql = @"IF NOT EXISTS(SELECT log.ID FROM ICSWareHouseLotInfoLog log
WHERE log.LotNo='{2}' AND log.WorkPoint='{3}' AND log.BusinessCode IN ('19','55') AND log.EATTRIBUTE1<>'1')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo037") + @"',16,1);
RETURN
END
IF EXISTS(SELECT log.LotNo FROM ICSWareHouseLotInfoLog log
WHERE log.LotNo='{2}' AND log.WorkPoint='{3}' AND log.BusinessCode IN ('19','55') AND log.EATTRIBUTE1<>'1'
GROUP BY log.LotNo HAVING COUNT(log.LotNo)>=2)
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo191"), "{2}") + @"',16,1);
RETURN
END
" + sql + @" AND log.BusinessCode IN ('19','55') AND log.EATTRIBUTE1<>'1'
GROUP BY inv.EATTRIBUTE10,inv.LotEnable,log.ID,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,a.WarehouseCode,
wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
columns = @"SUM(log.Quantity) AS Quantity,
SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
a.WarehouseCode AS WHCode,
wh.WarehouseName AS WHName,
a.LocationCode,
loc.LocationName,
log.ID AS LogID,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,";
tableName = @" ICSWareHouseLotInfoLog log
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
}
else
{
sql = @"WITH ICSBomALL AS
(
SELECT
ContainerCode AS TContainerCode,
ContainerCode AS PContainerCode,
ContainerCode AS ContainerCode,
ID,
ContainerID,
0 AS [Level],
CAST(1 AS nvarchar(MAX)) AS SortSeq,
CAST('00001' AS nvarchar(MAX)) AS Sort
FROM ICSContainer
WHERE ContainerCode='{2}'
UNION ALL
SELECT
b.TContainerCode,
b.ContainerCode AS PContainerCode,
a.ContainerCode,
a.ID,
a.ContainerID,
b.[Level]+1 AS [Level],
CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
FROM
ICSContainer a
INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
)
" + sql + @"AND log.BusinessCode IN ('19','55') AND log.EATTRIBUTE1<>'1'
GROUP BY inv.EATTRIBUTE10,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,a.WarehouseCode,
wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
columns = @"SUM(log.Quantity) AS Quantity,
SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
a.WarehouseCode AS WHCode,
wh.WarehouseName AS WHName,
a.LocationCode,
loc.LocationName,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,";
tableName = @" ICSWareHouseLotInfoLog log
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
}
}
//生产(委外)退料-原条码+新条码
//先校验日志里面是否有原条码(同一种类型的条码只能发一次料才能原条码退,不然更新源头单据数量有问题,根据LogID判断是否原条码退回),如果没有查询新条码
else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
|| TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
|| TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
{
string type = "13";
string msglanguage = "WMSAPIInfo185";
if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
{
type = "14";
msglanguage = "WMSAPIInfo186";
}
else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
{
type = "15";
msglanguage = "WMSAPIInfo187";
}
else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
{
type = "5";
msglanguage = "WMSAPIInfo188";
}
else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
{
type = "6";
msglanguage = "WMSAPIInfo189";
}
else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
{
type = "7";
msglanguage = "WMSAPIInfo190";
}
#region 新条码
if (ScanType == "LOTNO")
{
sqlNew = @"IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
RETURN
END
IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
RETURN
END
" + sql;
//东辉生产退料不需要检验 先注释
// IF EXISTS(SELECT a.ID FROM ICSInventoryLot a
// INNER JOIN ICSInventory b ON a.InvCode = b.InvCode AND a.WorkPoint = b.WorkPoint
// LEFT JOIN ICSInspection ins ON a.LotNo = ins.LotNo AND a.WorkPoint = ins.WorkPoint
// WHERE a.LotNo = '{2}' AND a.WorkPoint = '{3}' AND(b.InvIQC = '1'AND ins.LotNo IS NULL))
// BEGIN
// RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"', 16, 1);
// RETURN
//END
if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
|| TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
|| TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
{
columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
a.Quantity*(a.Amount/a.Quantity) AS Amount,
(select negg.WHCode from ICSMOApplyNegDetail neg
INNER JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
inner join ICSInventoryLotDetail lotdetail on neg.ApplyNegCode=lotdetail.TransCode
and neg.Sequence=lotdetail.TransSequence
where lotdetail.LotNo=a.LotNo and lotdetail.WorkPoint=a.WorkPoint) AS WHCode,
'' AS WHName,
'' AS LocationCode,
'' AS LocationName,
'' AS LogID,
ext.BatchCode AS BatchCode,";
}
if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
{
columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
a.Quantity*(a.Amount/a.Quantity) AS Amount,
(select negg.WHCode from ICSOApplyNegDetail neg
INNER JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
inner join ICSInventoryLotDetail lotdetail on neg.OApplyNegCode=lotdetail.TransCode
and neg.Sequence=lotdetail.TransSequence
where lotdetail.LotNo=a.LotNo and lotdetail.WorkPoint=a.WorkPoint) AS WHCode,
'' AS WHName,
'' AS LocationCode,
'' AS LocationName,
'' AS LogID,
ext.BatchCode AS BatchCode,";
}
tableName = @"ICSInventoryLot a
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1 ";
}
else
{
sqlNew = @"WITH ICSBomALL AS
(
SELECT
ContainerCode AS TContainerCode,
ContainerCode AS PContainerCode,
ContainerCode AS ContainerCode,
ID,
ContainerID,
0 AS [Level],
CAST(1 AS nvarchar(MAX)) AS SortSeq,
CAST('00001' AS nvarchar(MAX)) AS Sort
FROM ICSContainer
WHERE ContainerCode='{2}'
UNION ALL
SELECT
b.TContainerCode,
b.ContainerCode AS PContainerCode,
a.ContainerCode,
a.ID,
a.ContainerID,
b.[Level]+1 AS [Level],
CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
FROM
ICSContainer a
INNER JOIN ICSBomALL b ON a.ContainerID=b.ID
)
" + sql;
columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
a.Quantity*(a.Amount/a.Quantity) AS Amount,
'' AS WHCode,
'' AS WHName,
'' AS LocationCode,
'' AS LocationName,
ext.BatchCode AS BatchCode,";
tableName = @"ICSInventoryLot a
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1";
}
sqlNew = string.Format(sqlNew, columns, tableName, JsonData.Code, JsonData.WorkPoint, zlqty);
#endregion
#region 原条码
if (ScanType == "LOTNO")
{
sql = sql + @" AND log.BusinessCode IN('" + type + @"') GROUP BY inv.EATTRIBUTE10,inv.LotEnable,log.ID,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,a.WarehouseCode,
wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN(invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')= '1') OR ISNULL(invBat.BatchEnable, '0')= '1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME
";
sql = @"IF EXISTS(" + sql + @")
BEGIN
" + sql + @"
END
ELSE
BEGIN
" + sqlNew + @"
END";
sql = @"IF EXISTS(SELECT log.LotNo FROM ICSWareHouseLotInfoLog log
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND log.BusinessCode='" + type + @"'
GROUP BY log.LotNo HAVING COUNT(log.LotNo)>=2)
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode(msglanguage), "{2}") + @"',16,1);
RETURN
END
" + sql;
columns = @"SUM(log.Quantity) AS Quantity,
SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
a.WarehouseCode AS WHCode,
wh.WarehouseName AS WHName,
a.LocationCode,
loc.LocationName,
log.ID AS LogID,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,";
tableName = @"ICSWareHouseLotInfoLog log
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
}
else
{
sql = sql + @" AND log.BusinessCode IN('" + type + @"') GROUP BY inv.EATTRIBUTE10,inv.LotEnable,log.ID,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,a.WarehouseCode,
wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN(invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')= '1') OR ISNULL(invBat.BatchEnable, '0')= '1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME
";
sql = @"IF EXISTS(" + sql + @")
BEGIN
" + sql + @"
END
ELSE
BEGIN
" + sqlNew + @"
END";
sql = @"WITH ICSBomALL AS
(
SELECT
ContainerCode AS TContainerCode,
ContainerCode AS PContainerCode,
ContainerCode AS ContainerCode,
ID,
ContainerID,
0 AS [Level],
CAST(1 AS nvarchar(MAX)) AS SortSeq,
CAST('00001' AS nvarchar(MAX)) AS Sort
FROM ICSContainer
WHERE ContainerCode='{2}'
UNION ALL
SELECT
b.TContainerCode,
b.ContainerCode AS PContainerCode,
a.ContainerCode,
a.ID,
a.ContainerID,
b.[Level]+1 AS [Level],
CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
FROM
ICSContainer a
INNER JOIN ICSBomALL b ON a.ContainerID=b.ID
)
" + sql;
columns = @"SUM(log.Quantity) AS Quantity,
SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
a.WarehouseCode AS WHCode,
wh.WarehouseName AS WHName,
a.LocationCode,
loc.LocationName,
log.ID AS LogID,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,";
tableName = @"ICSWareHouseLotInfoLog log
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
}
#endregion
}
else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
{
#region 新条码
if (ScanType == "LOTNO")
{
sqlNew = @"IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
RETURN
END
IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
RETURN
END
" + sql;
columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
a.Quantity*(a.Amount/a.Quantity) AS Amount,
'' AS WHCode,
'' AS WHName,
'' AS LocationCode,
'' AS LocationName,
ext.BatchCode AS BatchCode,";
tableName = @"ICSInventoryLot a
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1 ";
}
else
{
sqlNew = @"WITH ICSBomALL AS
(
SELECT
ContainerCode AS TContainerCode,
ContainerCode AS PContainerCode,
ContainerCode AS ContainerCode,
ID,
ContainerID,
0 AS [Level],
CAST(1 AS nvarchar(MAX)) AS SortSeq,
CAST('00001' AS nvarchar(MAX)) AS Sort
FROM ICSContainer
WHERE ContainerCode='{2}'
UNION ALL
SELECT
b.TContainerCode,
b.ContainerCode AS PContainerCode,
a.ContainerCode,
a.ID,
a.ContainerID,
b.[Level]+1 AS [Level],
CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
FROM
ICSContainer a
INNER JOIN ICSBomALL b ON a.ContainerID=b.ID
)
" + sql;
columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
a.Quantity*(a.Amount/a.Quantity) AS Amount,
'' AS WHCode,
'' AS WHName,
'' AS LocationCode,
'' AS LocationName,
ext.BatchCode AS BatchCode,";
tableName = @"ICSInventoryLot a
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1";
}
sqlNew = string.Format(sqlNew, columns, tableName, JsonData.Code, JsonData.WorkPoint, zlqty);
#endregion
#region 原条码
if (ScanType == "LOTNO")
{
sql = sql + @" AND log.BusinessCode IN('27') GROUP BY inv.EATTRIBUTE10,inv.LotEnable,log.ID,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,a.WarehouseCode,
wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN(invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')= '1') OR ISNULL(invBat.BatchEnable, '0')= '1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME
";
sql = @"IF EXISTS(" + sql + @")
BEGIN
" + sql + @"
END
ELSE
BEGIN
" + sqlNew + @"
END";
columns = @"SUM(log.Quantity) AS Quantity,
SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
a.WarehouseCode AS WHCode,
wh.WarehouseName AS WHName,
a.LocationCode,
loc.LocationName,
log.ID AS LogID,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,";
tableName = @"ICSWareHouseLotInfoLog log
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
}
else
{
sql = sql + @" AND log.BusinessCode IN('27') GROUP BY inv.EATTRIBUTE10,inv.LotEnable,log.ID,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.InvIQC,a.WarehouseCode,
wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN(invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')= '1') OR ISNULL(invBat.BatchEnable, '0')= '1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME
";
sql = @"IF EXISTS(" + sql + @")
BEGIN
" + sql + @"
END
ELSE
BEGIN
" + sqlNew + @"
END";
sql = @"WITH ICSBomALL AS
(
SELECT
ContainerCode AS TContainerCode,
ContainerCode AS PContainerCode,
ContainerCode AS ContainerCode,
ID,
ContainerID,
0 AS [Level],
CAST(1 AS nvarchar(MAX)) AS SortSeq,
CAST('00001' AS nvarchar(MAX)) AS Sort
FROM ICSContainer
WHERE ContainerCode='{2}'
UNION ALL
SELECT
b.TContainerCode,
b.ContainerCode AS PContainerCode,
a.ContainerCode,
a.ID,
a.ContainerID,
b.[Level]+1 AS [Level],
CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
FROM
ICSContainer a
INNER JOIN ICSBomALL b ON a.ContainerID=b.ID
)
" + sql;
columns = @"SUM(log.Quantity) AS Quantity,
SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
a.WarehouseCode AS WHCode,
wh.WarehouseName AS WHName,
a.LocationCode,
loc.LocationName,
log.ID AS LogID,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,";
tableName = @"ICSWareHouseLotInfoLog log
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
}
#endregion
}
//分批
else if (TransType == TransTypeEnum.LOTSplit.GetDescription() || TransType == TransTypeEnum.LOTMerge.GetDescription())
{
sql = @"IF NOT EXISTS(SELECT 1 FROM ICSInventoryLot WHERE LotNo='{2}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
RETURN
END
IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0)
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo479")) + @"',16,1);
RETURN
END
--冻结条码不可分批合批(待增加提示11.13)
IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Freeze!=0)
BEGIN
--RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
RAISERROR('条码已冻结,不能操作!',16,1);
RETURN
END
" + sql;
columns = @"a.Quantity,
a.Quantity*(lot.Amount/lot.Quantity) AS Amount,
a.WarehouseCode AS WHCode,
wh.WarehouseName AS WHName,isnull(lot.EATTRIBUTE4,'') as EATTRIBUTE4,
a.LocationCode,
loc.LocationName,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
ISNULL(split.SplitLotNo, a.LotNo+'-1') AS SplitLotNo,";
tableName = @"ICSWareHouseLotInfo a
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
LEFT JOIN (SELECT EATTRIBUTE1 AS LotNo,WorkPoint,EATTRIBUTE1+'-'+CAST((MAX(CAST(reverse(substring(reverse(LotNo),1,charindex('-',reverse(LotNo)) - 1)) AS INT))+1) AS VARCHAR) AS SplitLotNo FROM ICSInventoryLot GROUP BY EATTRIBUTE1,WorkPoint) split ON a.LotNo=split.LotNo --AND a.WorkPoint=split.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
}
//出库条码
else if (isOut)
{
if (TransType == TransTypeEnum.MOIssueDoc.GetDescription() || TransType == TransTypeEnum.MOApply.GetDescription()
|| TransType == TransTypeEnum.MOIssue.GetDescription() || TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription()
|| TransType == TransTypeEnum.OOApply.GetDescription() || TransType == TransTypeEnum.OOIssue.GetDescription()
|| TransType == TransTypeEnum.SalesShipmentDoc.GetDescription() || TransType == TransTypeEnum.OtherOutDoc.GetDescription()
|| TransType == TransTypeEnum.BrrowDoc.GetDescription() || TransType == TransTypeEnum.StepTransferDocIn.GetDescription()
|| TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription() || TransType == TransTypeEnum.MOReplenishment.GetDescription()
|| TransType == TransTypeEnum.OtherInRedDoc.GetDescription() || TransType == TransTypeEnum.MOIssueAutoDoc.GetDescription()
|| TransType == TransTypeEnum.SalesShipmentOutDoc.GetDescription() || TransType == TransTypeEnum.JHSalesShipmentOutDoc.GetDescription() || TransType == TransTypeEnum.JHTwoStepTransferDocOut.GetDescription())
{
if (JsonData.IsPick != "1")
{
ZLtable = ICSControlModeService.GetZL();
if (ZLtable == null)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo471"));
}
for (int i = 0; i < ZLtable.Rows.Count; i++)
{
string zlName = ZLtable.Rows[i]["Name"].ToString();
string zlTransCode = ZLtable.Rows[i]["BusinessCode"].ToString();
string Enable = ZLtable.Rows[i]["Enable"].ToString();
if (JsonData.TransType.Equals(zlName))
{
if (Enable.Equals("True"))
{
if (JsonData.TransCode.Contains("~"))
{
JsonData.TransCode = JsonData.TransCode.Substring(0, JsonData.TransCode.IndexOf('~'));
}
string zlsql = @"IF NOT EXISTS(select a.Quantity from ICSWareHouseLotInfoLog a
left join ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint and a.InvCode=b.InvCode
--left join ICSType c on a.BusinessCode=c.Code and c.tablecode='ICSWareHouseLotInfoLog' and c.ColumnCode='BusinessCode'
where b.LotNo='{0}' and b.WorkPoint='{1}' and a.TransType='15' and (a.TransCode='{3}' or a.MergeID='{3}') and isnull(a.EATTRIBUTE2,'')<>'1')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo469") + @"',16,1);
RETURN
END
select sum(a.Quantity) AS Quantity from ICSWareHouseLotInfoLog a
left join ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint and a.InvCode=b.InvCode
--left join ICSType c on a.BusinessCode=c.Code and c.tablecode='ICSWareHouseLotInfoLog' and c.ColumnCode='BusinessCode'
where b.LotNo='{0}' and b.WorkPoint='{1}' and a.TransType='15' and (a.TransCode='{3}' or a.MergeID='{3}') and isnull(a.EATTRIBUTE2,'')<>'1'";
zlsql = string.Format(zlsql, JsonData.Code, JsonData.WorkPoint, JsonData.TransType, JsonData.TransCode);
DataTable zlltable = DBHelper.SQlReturnData(zlsql, cmd);
if (zlltable != null || zlltable.Rows.Count > 0)
{
zlqty = zlltable.Rows[0]["Quantity"].ToString();
iszl = true;
}
}
}
}
}
}
if (ScanType == "LOTNO")
{
//东辉盘点 判断是否存在于子表
if (TransType == TransTypeEnum.Check.GetDescription())
{
sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' )
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo171"), "{2}") + @"', 16, 1);
RETURN
END
IF NOT EXISTS(SELECT a.ID FROM ICSCheckDetail a inner join ICSCheck b on a.CheckID = b.id WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND b.CheckCode = '{5}')
BEGIN
RAISERROR('盘点单无此条码数据!',16,1);
RETURN
END
" + sql;
}
else if (TransType == TransTypeEnum.JHStepNoTransferDocIn.GetDescription())
{
sql = @"IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.warehousecode in (SELECT DISTINCT
b.F_ItemCode
FROM Sys_SRM_Items a
LEFT JOIN Sys_SRM_ItemsDetail b ON a.F_Id = b.F_ItemId
WHERE a.F_EnCode = 'JinHuaLiKu') )
BEGIN
RAISERROR('该条码所在仓库为立库,该功能不能调拨立库库存的条码!', 16, 1);
RETURN
END
IF NOT EXISTS(SELECT 1 FROM ICSInventoryLot WHERE LotNo = '{2}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"', 16, 1);
RETURN
END
IF NOT EXISTS(SELECT 1 FROM ICSWareHouseLotInfo WHERE LotNo = '{2}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo171"), "{2}") + @"', 16, 1);
RETURN
END
IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0)
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo479"), "{2}") + @"',16,1);
RETURN
END
IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0 AND a.Freeze='1')
BEGIN
RAISERROR('条码状态:冻结,无法出库,请确认!',16,1);
RETURN
END
" + sql;
}
else //原逻辑
{
if (DBHelper.IsPNU9() && TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
{
sql = @"IF NOT EXISTS(SELECT 1 FROM ICSInventoryLot WHERE LotNo = '{2}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"', 16, 1);
RETURN
END
IF NOT EXISTS(SELECT 1 FROM ICSWareHouseLotInfo WHERE LotNo = '{2}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo171"), "{2}") + @"', 16, 1);
RETURN
END
IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.Quantity>0)
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo479")) + @"',16,1);
RETURN
END
IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.Quantity>0 AND a.Freeze='1')
BEGIN
RAISERROR('条码状态:冻结,无法出库,请确认!',16,1);
RETURN
END
" + sql;
}
else
{
sql = @"IF NOT EXISTS(SELECT 1 FROM ICSInventoryLot WHERE LotNo = '{2}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"', 16, 1);
RETURN
END
IF NOT EXISTS(SELECT 1 FROM ICSWareHouseLotInfo WHERE LotNo = '{2}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo171"), "{2}") + @"', 16, 1);
RETURN
END
IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0)
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo479"), "{2}") + @"',16,1);
RETURN
END
IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0 AND a.Freeze='1')
BEGIN
RAISERROR('条码状态:冻结,无法出库,请确认!',16,1);
RETURN
END
" + sql;
}
//log.Debug(sql);
}
if (iszl)
{
columns = @"{0} as Quantity,
{0}*(lot.Amount/lot.Quantity) AS Amount,
a.id AS LogID,
a.FromWarehouseCode AS WHCode,
wh.WarehouseName AS WHName,
inv.LotEnable,
a.FromLocationCode,
loc.LocationName,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,";
columns = string.Format(columns, zlqty);
tableName = @"ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint and a.transtype='15'
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
INNER JOIN ICSLocation loc ON a.FromLocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
}
else
{
if (DBHelper.IsPNU9() && TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
{
#region 派纳一步调拨sql单独
PNTranfersql = @"IF NOT EXISTS(SELECT 1 FROM ICSInventoryLot WHERE LotNo = '{2}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"', 16, 1);
RETURN
ENDIF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.Quantity>0)
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo479")) + @"',16,1);
RETURN
END
IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.Quantity>0 AND a.Freeze='1')
BEGIN
RAISERROR('条码状态:冻结,无法出库,请确认!',16,1);
RETURN
END
IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a
INNER JOIN ICSInventoryLotDetail b ON a.lotno=b.LotNo
INNER JOIN ICSTransfer c ON b.TransCode=c.TransferNO and b.TransSequence=c.Sequence
where c.TransferNO='{5}' GROUP BY a.LotNo
HAVING COUNT(b.LotNo)>0
)
BEGIN
IF NOT EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a
INNER JOIN ICSInventoryLotDetail b ON a.lotno=b.LotNo
INNER JOIN ICSTransfer c ON b.TransCode=c.TransferNO and b.TransSequence=c.Sequence
where a.LotNo='{2}')
BEGIN
RAISERROR('请扫描该调拨单生成的条码!',16,1);
RETURN
END
ELSE
BEGIN
SELECT a.ID,
con.ContainerCode,
con.ContainerName,
a.LotNo,
a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,
inv.InvIQC,
inv.LotEnable,
(a.Quantity-a.lockQuantity) AS Quantity,
(a.Quantity-a.lockQuantity)*(lot.Amount/lot.Quantity) AS Amount,
'' AS LogID,
a.WarehouseCode AS WHCode,
wh.WarehouseName AS WHName,
inv.LotEnable,
a.LocationCode,
loc.LocationName,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.Version,
--ext.BatchCode,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MTIME AS [MTime],
'LOTNO' AS ScanType
FROM ICSWareHouseLotInfo a
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo --AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSInventoryLotDetail b ON a.lotno=b.LotNo
INNER JOIN ICSTransfer c ON b.TransCode=c.TransferNO and b.TransSequence=c.Sequence
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID --AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode --AND a.WorkPoint=wh.WorkPoint
INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode --AND a.WorkPoint=loc.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode --AND a.WorkPoint=invBat.WorkPoint
LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE a.LotNo='{2}'
END
END
ELSE
BEGIN
SELECT DISTINCT a.ID,
con.ContainerCode,
con.ContainerName,
a.LotNo,
a.InvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,
inv.InvIQC,
inv.LotEnable,
(a.Quantity-a.lockQuantity) AS Quantity,
(a.Quantity-a.lockQuantity)*(lot.Amount/lot.Quantity) AS Amount,
'0' AS SUMLotCount,
'0' AS ISSUMLotCount,
'' AS LogID,
a.WarehouseCode AS WHCode,
wh.WarehouseName AS WHName,
inv.LotEnable,
a.LocationCode,
loc.LocationName,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.Version,
--ext.BatchCode,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MTIME AS [MTime],
'LOTNO' AS ScanType
FROM ICSWareHouseLotInfo a
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo --AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID --AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode --AND a.WorkPoint=wh.WorkPoint
INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode --AND a.WorkPoint=loc.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode --AND a.WorkPoint=invBat.WorkPoint
LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE a.LotNo='{2}'
END";
#endregion
}
columns = @"(a.Quantity-a.lockQuantity) AS Quantity,
(a.Quantity-a.lockQuantity)*(lot.Amount/lot.Quantity) AS Amount,
'' AS LogID,
a.WarehouseCode AS WHCode,
wh.WarehouseName AS WHName,
inv.LotEnable,
a.LocationCode,
loc.LocationName,
'0' AS SUMLotCount,
'0' AS ISSUMLotCount,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,";
//if (DBHelper.IsPNU9() && TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
//{
// tableName = @"ICSWareHouseLotInfo a
//INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo --AND a.WorkPoint=lot.WorkPoint
//INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID --AND lot.WorkPoint=ext.WorkPoint
//INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode --AND a.WorkPoint=wh.WorkPoint
//INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode --AND a.WorkPoint=loc.WorkPoint
//LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode --AND a.WorkPoint=invBat.WorkPoint";
//}
//else
//{
tableName = @"ICSWareHouseLotInfo a
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
//}
}
}
else
{
sql = @"
WITH ICSBomALL AS
(
SELECT
ContainerCode AS TContainerCode,
ContainerCode AS PContainerCode,
ContainerCode AS ContainerCode,
ID,
ContainerID,
0 AS [Level],
CAST(1 AS nvarchar(MAX)) AS SortSeq,
CAST('00001' AS nvarchar(MAX)) AS Sort
FROM ICSContainer
WHERE ContainerCode='{2}'
UNION ALL
SELECT
b.TContainerCode,
b.ContainerCode AS PContainerCode,
a.ContainerCode,
a.ID,
a.ContainerID,
b.[Level]+1 AS [Level],
CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
FROM
ICSContainer a
INNER JOIN ICSBomALL b ON a.ContainerID=b.ID
)
SELECT *
INTO #TempICSBomALL
FROM ICSBomALL;
-- IF EXISTS(SELECT 1 FROM ICSInventoryLot a
-- INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
-- LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
-- LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1
-- LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
-- LEFT JOIN #TempICSBomALL bom ON bom.ID=conlot.ContainerID
-- LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
-- INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
-- WHERE bom.TContainerCode='{2}' AND a.WorkPoint='{3}' AND inv.InvIQC='1' AND ins.LotNo IS NULL)
-- BEGIN
-- RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"',16,1);
-- RETURN;
-- END
" + sql + @"
DROP TABLE #TempICSBomALL";
columns = @"(a.Quantity-a.lockQuantity) AS Quantity,
(a.Quantity-a.lockQuantity)*(lot.Amount/lot.Quantity) AS Amount,
a.WarehouseCode AS WHCode,
wh.WarehouseName AS WHName,
inv.LotEnable,
a.LocationCode,
loc.LocationName,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,";
tableName = @"ICSWareHouseLotInfo a
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
";
}
}
//入库条码
else
{
if (ScanType == "LOTNO")
{
if ((TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.PurchaseReceiveDRCoffeeDoc.GetDescription() || TransType == TransTypeEnum.DeliveryNotice.GetDescription()
|| TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription() || TransType == TransTypeEnum.ODeliveryNotice.GetDescription()
//|| TransType == TransTypeEnum.MOStockINByProduct.GetDescription()
|| TransType == TransTypeEnum.MOStockINByProductNoTrans.GetDescription()
|| TransType == TransTypeEnum.OOStockINByProduct.GetDescription() || TransType == TransTypeEnum.OtherInDoc.GetDescription()
|| TransType == TransTypeEnum.PurchaseReceiveRevDoc.GetDescription() || TransType == TransTypeEnum.OutsourcingReceiveRevDoc.GetDescription()) && needIns)
{
sql = @"
IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo = '{2}' AND a.WorkPoint = '{3}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"', 16, 1);
RETURN
END
IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
RETURN
END
IF EXISTS(SELECT a.ID FROM ICSInventoryLot a
INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint
WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND (b.InvIQC='1' AND ins.LotNo IS NULL))
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"',16,1);
RETURN
END
IF EXISTS(SELECT a.ID FROM ICSInventoryLot a
INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint
WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND b.InvIQC='1' AND ins.enable = 1 AND ISNULL(ins.QualifiedQuantity, 0)+ISNULL(ins.WaiveQuantity, 0)<=0)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo533") + @"',16,1);
RETURN
END
" + sql;
}
else if ((TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription() || TransType == TransTypeEnum.ManufactureReceiveDRCoffeeDoc.GetDescription()
|| TransType == TransTypeEnum.ManufactureReceive.GetDescription() || TransType == TransTypeEnum.JHManufactureReceiveDoc.GetDescription()
|| TransType == TransTypeEnum.ManufactureReceiveDRCoffeeDoc.GetDescription()
|| TransType == TransTypeEnum.ManufactureMESReceive.GetDescription()) && needIns)
{
sql = @"
IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo = '{2}' AND a.WorkPoint = '{3}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"', 16, 1);
RETURN
END
IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
RETURN
END
IF EXISTS(SELECT a.ID FROM ICSInventoryLot a
INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint
WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND (b.InvFQC='1' AND ins.LotNo IS NULL))
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"',16,1);
RETURN
END
IF EXISTS(SELECT a.ID FROM ICSInventoryLot a
INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint
WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND b.InvIQC='1' AND ins.enable = 1 AND ISNULL(ins.QualifiedQuantity, 0)+ISNULL(ins.WaiveQuantity, 0)<=0)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo533") + @"',16,1);
RETURN
END
" + sql;
}
else
{
sql = @"
IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo = '{2}' AND a.WorkPoint = '{3}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"', 16, 1);
RETURN
END
IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
RETURN
END
" + sql;
}
ControlMode mode = ICSControlModeService.GetSuLocation();
//获取条码类型
LotTypesql = @"IF NOT EXISTS(SELECT Type FROM ICSInventoryLot WHERE LotNo='{0}' AND WorkPoint='{1}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo461") + @"',16,1);
RETURN
END
SELECT Type FROM ICSInventoryLot WHERE LotNo='{0}' AND WorkPoint='{1}'";
LotTypesql = string.Format(LotTypesql, JsonData.Code, JsonData.WorkPoint);
DataTable dt = DBHelper.SQlReturnData(LotTypesql, cmd);
if (dt != null && dt.Rows.Count > 0)
{
LotType = dt.Rows[0]["Type"].ToString();
}
if (mode != null)
{
if (mode.itemCode.Equals("LocationRemind01"))//固定库位:物料和库位绑定,显示库位名称列表
{
columnsLONAME = @"
(SELECT locat.LocationName from ICSWareHouseLotInfo loinfo
LEFT JOIN ICSLocation locat on locat.LocationCode=loinfo.LocationCode and loinfo.WorkPoint=locat.WorkPoint
where loinfo.lotno=a.lotno and loinfo.invcode=a.invcode and a.WorkPoint=loinfo.WorkPoint) AS LocationName,";
columnsLOCODE = @"
(SELECT locat.LocationCode from ICSWareHouseLotInfo loinfo
LEFT JOIN ICSLocation locat on locat.LocationCode=loinfo.LocationCode and loinfo.WorkPoint=locat.WorkPoint
where loinfo.lotno=a.lotno and loinfo.invcode=a.invcode and a.WorkPoint=loinfo.WorkPoint) AS LocationCode,";
}
else if (mode.itemCode.Equals("LocationRemind02"))//在库库位:物料有库存的对应库位,显示库位名称列表
{
columnsLONAME = @"
STUFF(
(SELECT DISTINCT ',' + LocationName
from ICSLocation wh
LEFT JOIN ICSWareHouseLotInfo lotinfo on wh.LocationCode=lotinfo.LocationCode and wh.WorkPoint=lotinfo.WorkPoint
WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and lotinfo.Quantity>0
FOR xml path('')
),1,1,''
) AS LocationName,";
columnsLOCODE = @"
STUFF(
(SELECT DISTINCT ',' + LocationCode
from ICSLocation wh
LEFT JOIN ICSWareHouseLotInfo lotinfo on wh.LocationCode=lotinfo.LocationCode and wh.WorkPoint=lotinfo.WorkPoint
WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and lotinfo.Quantity>0
FOR xml path('')
),1,1,''
) AS LocationCode,";
}
else if (mode.itemCode.Equals("LocationRemind03"))//最近一次出入库的库位,显示库位名称
{
columnsLONAME = @"
(SELECT Top 1 locat.LocationName
FROM ICSWareHouseLotInfoLog log
LEFT JOIN ICSLocation locat ON locat.LocationCode = log.ToLocationCode AND log.WorkPoint = locat.WorkPoint
WHERE (log.TransType = '1' OR log.TransType = '2')
AND a.InvCode = log.InvCode
AND a.WorkPoint = log.WorkPoint
AND (
NOT EXISTS (
SELECT 1
FROM Sys_SRM_Items a2
INNER JOIN Sys_SRM_ItemsDetail b ON b.F_ItemId = a2.F_Id
WHERE a2.F_EnCode = 'ShelvesLocation'
)
OR
locat.LocationCode IN (
SELECT d.LocationCode
FROM Sys_SRM_Items a2
INNER JOIN Sys_SRM_ItemsDetail b ON b.F_ItemId = a2.F_Id
INNER JOIN ICSWarehouse c ON c.WarehouseCode=b.F_ItemCode
INNER JOIN ICSLocation d ON d.WHID=c.ID AND d.WorkPoint=c.WorkPoint
WHERE a2.F_EnCode = 'ShelvesLocation'
)
)
ORDER BY log.Mtime desc) AS LocationName,";
columnsLOCODE = @"
(SELECT Top 1 locat.LocationCode
FROM ICSWareHouseLotInfoLog log
LEFT JOIN ICSLocation locat ON locat.LocationCode = log.ToLocationCode AND log.WorkPoint = locat.WorkPoint
WHERE (log.TransType = '1' OR log.TransType = '2')
AND a.InvCode = log.InvCode
AND a.WorkPoint = log.WorkPoint
AND (
NOT EXISTS (
SELECT 1
FROM Sys_SRM_Items a2
INNER JOIN Sys_SRM_ItemsDetail b ON b.F_ItemId = a2.F_Id
WHERE a2.F_EnCode = 'ShelvesLocation'
)
OR
locat.LocationCode IN (
SELECT d.LocationCode
FROM Sys_SRM_Items a2
INNER JOIN Sys_SRM_ItemsDetail b ON b.F_ItemId = a2.F_Id
INNER JOIN ICSWarehouse c ON c.WarehouseCode=b.F_ItemCode
INNER JOIN ICSLocation d ON d.WHID=c.ID AND d.WorkPoint=c.WorkPoint
WHERE a2.F_EnCode = 'ShelvesLocation'
)
)
ORDER BY log.Mtime desc) AS LocationCode,";
}
}
else
{
if (DBHelper.IsPNU9())
{
columnsLONAME = @" '' AS LocationName,";
columnsLOCODE = @" '' AS LocationCode,";
}
else
{
columnsLONAME = @"
STUFF(
(SELECT DISTINCT ',' + LocationName
from ICSLocation wh
LEFT JOIN ICSWareHouseLotInfoLog lotinfo on wh.LocationCode=lotinfo.ToLocationCode and wh.WorkPoint=lotinfo.WorkPoint
WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and (lotinfo.TransType='2' OR lotinfo.TransType='3')
FOR xml path('')
),1,1,''
) AS LocationName,";
columnsLOCODE = @"
STUFF(
(SELECT DISTINCT ',' + LocationCode
from ICSLocation wh
LEFT JOIN ICSWareHouseLotInfoLog lotinfo on wh.LocationCode=lotinfo.ToLocationCode and wh.WorkPoint=lotinfo.WorkPoint
WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and (lotinfo.TransType='2' OR lotinfo.TransType='3')
FOR xml path('')
),1,1,''
) AS LocationCode,";
}
}
#region 根据条码类型找到单据仓库信息
if (LotType.Equals("1"))
{//生产退料
columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='1'),'') AS WHCode";
columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='1') AND WorkPoint=a.WorkPoint),'') AS WHName";
}
else if (LotType.Equals("2"))
{//委外退料
columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='1'),'') AS WHCode";
columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='1') AND WorkPoint=a.WorkPoint),'') AS WHName";
}
else if (LotType.Equals("3"))
{//工单
columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSMO a WHERE a.MOCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint),'') AS WHCode";
columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSMO a WHERE a.MOCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName";
}
else if (LotType.Equals("4"))
{//销售退货
columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSSDN a WHERE a.SDNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint),'') AS WHCode";
columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSSDN a WHERE a.SDNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName";
}
else if (LotType.Equals("5"))
{//其他入库
columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSOtherIn a WHERE a.InCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint),'') AS WHCode";
columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSOtherIn a WHERE a.InCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName";
}
else if (LotType.Equals("6"))
{//归还单
columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSReturn a WHERE a.ReturnCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint),'') AS WHCode";
columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSReturn a WHERE a.ReturnCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName";
}
else if (LotType.Equals("7"))
{//采购到货单
columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSDeliveryNotice a WHERE a.DNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint AND a.DNType='1'),'') AS WHCode";
columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSDeliveryNotice a WHERE a.DNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint AND a.DNType='1') AND WorkPoint=a.WorkPoint),'') AS WHName";
}
else if (LotType.Equals("8"))
{//委外到货单
columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSODeliveryNotice a WHERE a.ODNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint and a.ODNType='1'),'') AS WHCode";
columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSODeliveryNotice a WHERE a.ODNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint and a.ODNType='1') AND WorkPoint=a.WorkPoint),'') AS WHName";
}
else if (LotType.Equals("9"))
{//成品入库单
columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSManufactureReceive a WHERE a.RCVCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint),'') AS WHCode";
columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSManufactureReceive a WHERE a.RCVCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName";
}
else if (LotType.Equals("10"))
{//拒收单
columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSDeliveryNotice a WHERE a.DNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint AND a.DNType='3'),'') AS WHCode";
columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSDeliveryNotice a WHERE a.DNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint AND a.DNType='3') AND WorkPoint=a.WorkPoint),'') AS WHName";
}
else if (LotType.Equals("11"))
{//委外拒收单
columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSODeliveryNotice a WHERE a.ODNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint and a.ODNType='3'),'') AS WHCode";
columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSODeliveryNotice a WHERE a.ODNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint and a.ODNType='3') AND WorkPoint=a.WorkPoint),'') AS WHName";
}
else if (LotType.Equals("12"))
{//领料申请退料
columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='2'),'') AS WHCode";
columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='2') AND WorkPoint=a.WorkPoint),'') AS WHName";
}
else if (LotType.Equals("13"))
{//材料出库退料
columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='3'),'') AS WHCode";
columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='3') AND WorkPoint=a.WorkPoint),'') AS WHName";
}
else if (LotType.Equals("14"))
{//委外领料申请退料
columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='2'),'') AS WHCode";
columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='2') AND WorkPoint=a.WorkPoint),'') AS WHName";
}
else if (LotType.Equals("15"))
{//委外材料出库退料
columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='3'),'') AS WHCode";
columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='3') AND WorkPoint=a.WorkPoint),'') AS WHName";
}
else if (LotType.Equals("16"))
{//返工工单
columnsWHCODE = @"ISNULL((SELECT pick.WHCode FROM ICSMOPick pick LEFT JOIN ICSMO moo ON pick.MODetailID=moo.MODetailID AND pick.WorkPoint=moo.WorkPoint
WHERE moo.MOCode=lotdd.TransCode AND pick.Sequence=lotdd.TransSequence AND pick.WorkPoint=lotdd.WorkPoint),'') AS WHCode ";
columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT pick.WHCode FROM ICSMOPick pick LEFT JOIN ICSMO moo ON pick.MODetailID=moo.MODetailID AND pick.WorkPoint=moo.WorkPoint
WHERE moo.MOCode=lotdd.TransCode AND pick.Sequence=lotdd.TransSequence AND pick.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName ";
}
else if (LotType.Equals("22"))
{//采购入库单
columnsWHCODE = @"ISNULL((SELECT ssd.WHCode FROM ICSPurchaseReceive ssd
WHERE ssd.RCVCode=lotdd.TransCode AND ssd.Sequence=lotdd.TransSequence AND ssd.WorkPoint=lotdd.WorkPoint),'') AS WHCode ";
columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT ssd.WHCode FROM ICSPurchaseReceive ssd
WHERE ssd.RCVCode=lotdd.TransCode AND ssd.Sequence=lotdd.TransSequence AND ssd.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName";
}
else if (LotType.Equals("23"))
{//委外入库单
columnsWHCODE = @"ISNULL((SELECT ssd.WHCode FROM ICSOutsourcingReceive ssd
WHERE ssd.RCVCode=lotdd.TransCode AND ssd.Sequence=lotdd.TransSequence AND ssd.WorkPoint=lotdd.WorkPoint),'') AS WHCode ";
columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT ssd.WHCode FROM ICSOutsourcingReceive ssd
WHERE ssd.RCVCode=lotdd.TransCode AND ssd.Sequence=lotdd.TransSequence AND ssd.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName";
}
else if (LotType.Equals("24"))
{//销售发货-红字出库单
columnsWHCODE = @"ISNULL((SELECT ssd.WHCode FROM ICSSSD ssd
WHERE ssd.SSDCode=lotdd.TransCode AND ssd.Sequence=lotdd.TransSequence AND ssd.WorkPoint=lotdd.WorkPoint),'') AS WHCode ";
columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT ssd.WHCode FROM ICSSSD ssd
WHERE ssd.SSDCode=lotdd.TransCode AND ssd.Sequence=lotdd.TransSequence AND ssd.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName";
}
else
{
columnsWHCODE = @"'' AS WHCode";
columnsWHNAME = @"'' AS WHName";
}
#endregion
if ((TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.PurchaseReceiveDRCoffeeDoc.GetDescription() || TransType == TransTypeEnum.DeliveryNotice.GetDescription()
|| TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription() || TransType == TransTypeEnum.ODeliveryNotice.GetDescription()
|| TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription() || TransType == TransTypeEnum.ManufactureReceiveDRCoffeeDoc.GetDescription()
|| TransType == TransTypeEnum.MOStockINByProductNoTrans.GetDescription() || TransType == TransTypeEnum.JHManufactureReceiveDoc.GetDescription()
|| TransType == TransTypeEnum.ManufactureReceive.GetDescription() || TransType == TransTypeEnum.OOStockINByProduct.GetDescription()
|| TransType == TransTypeEnum.MOStockINByProduct.GetDescription() || TransType == TransTypeEnum.OtherInDoc.GetDescription() || TransType == TransTypeEnum.OutsourcingReceiveRevDoc.GetDescription()
|| TransType == TransTypeEnum.PurchaseReceiveRevDoc.GetDescription() || TransType == TransTypeEnum.ManufactureMESReceive.GetDescription()) && needIns)
{
if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.PurchaseReceiveDRCoffeeDoc.GetDescription())
{
columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, asde.DNQuantity) AS Quantity,
asde.DNQuantity*(a.Amount/a.Quantity) AS Amount,
{0},{2},
lotdd.TransCode,lotdd.TransSequence,
{3}
{1}
ext.BatchCode AS BatchCode,";
tableName = @"ICSInventoryLot a
INNER JOIN ICSASNDetail asde ON asde.LotNo=a.LotNo AND asde.WorkPoint=a.WorkPoint AND asde.DNQuantity>0
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1";
}
else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
{
columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, asde.ODNQuantity) AS Quantity,
asde.ODNQuantity*(a.Amount/a.Quantity) AS Amount,
{0},{2},
lotdd.TransCode,lotdd.TransSequence,
{3}
{1}
ext.BatchCode AS BatchCode,";
tableName = @"ICSInventoryLot a
left JOIN ICSOASNDetail asde ON asde.LotNo=a.LotNo AND asde.WorkPoint=a.WorkPoint AND asde.ODNQuantity>0
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1";
}
else if (TransType == TransTypeEnum.MOStockINByProduct.GetDescription())
{
columns = @"ISNULL(ins.QualifiedQuantity+ins.UnqualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
a.Quantity*(a.Amount/a.Quantity) AS Amount,
{0},{2},
lotdd.TransCode,lotdd.TransSequence,
{3}
{1}
ext.BatchCode AS BatchCode,";
tableName = @"ICSInventoryLot a
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1";
}
else
{
columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
a.Quantity*(a.Amount/a.Quantity) AS Amount,
{0},{2},
lotdd.TransCode,lotdd.TransSequence,
{3}
{1}
ext.BatchCode AS BatchCode,";
tableName = @"ICSInventoryLot a
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1";
}
}
else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
{
columns = @"a.Quantity AS Quantity,
a.Quantity*(a.Amount/a.Quantity) AS Amount,
{0},{2},
{3}
{1}
ext.BatchCode AS BatchCode,
isnull(lotdd.TransCode,'') as TransCode,isnull(lotdd.TransSequence,'') as TransSequence,
sdn.SOCode,";
tableName = @"ICSInventoryLot a
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
INNER join ICSSDN sdn on lotdd.transcode=sdn.sdncode and lotdd.TransSequence=sdn.Sequence and lotdd.WorkPoint=sdn.WorkPoint";
}
else if (TransType == TransTypeEnum.RTTwoStepTransferDocIn.GetDescription())
{
columns = @"a.Quantity AS Quantity,
a.Quantity*(a.Amount/a.Quantity) AS Amount,
'','',
'',
'',
ext.BatchCode AS BatchCode,
isnull(lotdd.TransCode,'') as TransCode,isnull(lotdd.TransSequence,'') as TransSequence,";
tableName = @"ICSInventoryLot a
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint";
}
else
{
columns = @"a.Quantity AS Quantity,
a.Quantity*(a.Amount/a.Quantity) AS Amount,
{0},{2},
{3}
{1}
ext.BatchCode AS BatchCode,
isnull(lotdd.TransCode,'') as TransCode,isnull(lotdd.TransSequence,'') as TransSequence,";
tableName = @"ICSInventoryLot a
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint";
}
columns = string.Format(columns, columnsWHCODE, columnsLONAME, columnsWHNAME, columnsLOCODE);
}
else
{
//检查容器内条码是否已经入库
string existsSql = string.Format(@"IF EXISTS(SELECT 1
FROM ICSContainer con
INNER JOIN ICSContainerLot conlot ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSWareHouseLotInfo info ON info.LotNo=conlot.LotNo AND info.WorkPoint=conlot.WorkPoint
WHERE con.ContainerCode='{0}' AND con.WorkPoint='{1}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo164") + @"',16,1);
RETURN
END", JsonData.Code, JsonData.WorkPoint);
DBHelper.ExecuteNonQuery(existsSql, cmd);
string inspectedSql = string.Format(@"WITH ICSBomALL AS
(
SELECT
ContainerCode AS TContainerCode,
ContainerCode AS PContainerCode,
ContainerCode AS ContainerCode,
ID,
ContainerID,
0 AS [Level],
CAST(1 AS nvarchar(MAX)) AS SortSeq,
CAST('00001' AS nvarchar(MAX)) AS Sort
FROM ICSContainer
WHERE ContainerCode='{0}'
UNION ALL
SELECT
b.TContainerCode,
b.ContainerCode AS PContainerCode,
a.ContainerCode,
a.ID,
a.ContainerID,
b.[Level]+1 AS [Level],
CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
FROM
ICSContainer a
INNER JOIN ICSBomALL b ON a.ContainerID=b.ID
)
SELECT *
INTO #TempICSBomALL
FROM ICSBomALL;
SELECT DISTINCT inv.InvCode FROM ICSInventoryLot a
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1
LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
LEFT JOIN #TempICSBomALL bom ON bom.ID=conlot.ContainerID
LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE bom.TContainerCode='{0}' AND a.WorkPoint='{1}' AND inv.InvIQC='1' AND ins.LotNo IS NULL
DROP TABLE #TempICSBomALL", JsonData.Code, JsonData.WorkPoint);
DataTable inspectDt = DBHelper.SQlReturnData(inspectedSql, cmd);
if (inspectDt != null && inspectDt.Rows.Count > 0)
{
var invCodeList = new List();
foreach (DataRow row in inspectDt.Rows)
{
invCodeList.Add(row["InvCode"].ToString());
}
string invCodeString = string.Join(",", invCodeList);
throw new Exception(language.GetNameByCode("WMSAPIInfo536") + invCodeString);
}
sql = @"
WITH ICSBomALL AS
(
SELECT
ContainerCode AS TContainerCode,
ContainerCode AS PContainerCode,
ContainerCode AS ContainerCode,
ID,
ContainerID,
0 AS [Level],
CAST(1 AS nvarchar(MAX)) AS SortSeq,
CAST('00001' AS nvarchar(MAX)) AS Sort
FROM ICSContainer
WHERE ContainerCode='{2}'
UNION ALL
SELECT
b.TContainerCode,
b.ContainerCode AS PContainerCode,
a.ContainerCode,
a.ID,
a.ContainerID,
b.[Level]+1 AS [Level],
CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
FROM
ICSContainer a
INNER JOIN ICSBomALL b ON a.ContainerID=b.ID
)
SELECT *
INTO #TempICSBomALL
FROM ICSBomALL;
-- IF EXISTS(SELECT 1 FROM ICSInventoryLot a
-- INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
-- LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
-- LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1
-- LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
-- LEFT JOIN #TempICSBomALL bom ON bom.ID=conlot.ContainerID
-- LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
-- INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
-- WHERE bom.TContainerCode='{2}' AND a.WorkPoint='{3}' AND inv.InvIQC='1' AND ins.LotNo IS NULL)
-- BEGIN
-- RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"',16,1);
-- RETURN;
-- END
" + sql + @"
DROP TABLE #TempICSBomALL";
if ((TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.PurchaseReceiveDRCoffeeDoc.GetDescription() || TransType == TransTypeEnum.DeliveryNotice.GetDescription()
|| TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription() || TransType == TransTypeEnum.ODeliveryNotice.GetDescription()
|| TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription() || TransType == TransTypeEnum.ManufactureReceiveDRCoffeeDoc.GetDescription()
|| TransType == TransTypeEnum.ManufactureReceive.GetDescription() || TransType == TransTypeEnum.JHManufactureReceiveDoc.GetDescription()
|| TransType == TransTypeEnum.MOStockINByProduct.GetDescription() || TransType == TransTypeEnum.MOStockINByProductNoTrans.GetDescription()
|| TransType == TransTypeEnum.OOStockINByProduct.GetDescription() || TransType == TransTypeEnum.OtherInDoc.GetDescription() || TransType == TransTypeEnum.OutsourcingReceiveRevDoc.GetDescription()
|| TransType == TransTypeEnum.PurchaseReceiveRevDoc.GetDescription() || TransType == TransTypeEnum.ManufactureMESReceive.GetDescription()) && needIns)
{
if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.PurchaseReceiveDRCoffeeDoc.GetDescription())
{
columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, asde.DNQuantity) AS Quantity,
asde.DNQuantity*(a.Amount/a.Quantity) AS Amount,
lotdd.TransCode,lotdd.TransSequence,
'' AS WHCode,
'' AS WHName,
'' AS LocationCode,
'' AS LocationName,
ext.BatchCode AS BatchCode,";
tableName = @"ICSInventoryLot a
INNER JOIN ICSASNDetail asde ON asde.LotNo=a.LotNo AND asde.WorkPoint=a.WorkPoint AND asde.DNQuantity>0
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1";
QuantityWhere = " AND ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, asde.DNQuantity)>0";
}
else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
{
columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, asde.ODNQuantity) AS Quantity,
asde.ODNQuantity*(a.Amount/a.Quantity) AS Amount,
lotdd.TransCode,lotdd.TransSequence,
'' AS WHCode,
'' AS WHName,
'' AS LocationCode,
'' AS LocationName,
ext.BatchCode AS BatchCode,";
tableName = @"ICSInventoryLot a
INNER JOIN ICSOASNDetail asde ON asde.LotNo=a.LotNo AND asde.WorkPoint=a.WorkPoint AND asde.ODNQuantity>0
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1";
QuantityWhere = " AND ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, asde.ODNQuantity)>0";
}
else
{
columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
a.Quantity*(a.Amount/a.Quantity) AS Amount,
lotdd.TransCode,lotdd.TransSequence,
'' AS WHCode,
'' AS WHName,
'' AS LocationCode,
'' AS LocationName,
ext.BatchCode AS BatchCode,";
tableName = @"ICSInventoryLot a
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1";
QuantityWhere = " AND ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity)>0";
}
}
else
{
columns = @"a.Quantity AS Quantity,
a.Quantity*(a.Amount/a.Quantity) AS Amount,
lotdd.TransCode,lotdd.TransSequence,
'' AS WHCode,
'' AS WHName,
'' AS LocationCode,
'' AS LocationName,
ext.BatchCode AS BatchCode,";
tableName = @"ICSInventoryLot a
LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint";
}
}
}
}
if (TransType != TransTypeEnum.LocationSeatch.GetDescription() && TransType != TransTypeEnum.CodePrint.GetDescription())
{
if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName))
throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
}
if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
{
Losql = string.Format(Losql, columns, tableName, JsonData.Code, JsonData.WorkPoint, JsonData.BatchCode);
table = DBHelper.SQlReturnData(Losql, cmd);
}
else if (TransType == TransTypeEnum.LotJL.GetDescription())
{
LotJLSql = string.Format(LotJLSql, columns, tableName, JsonData.Code, JsonData.WorkPoint, JsonData.BatchCode);
table = DBHelper.SQlReturnData(LotJLSql, cmd);
}
else if (TransType == TransTypeEnum.WLotNoSearch.GetDescription())
{
WLosql = string.Format(WLosql, columns, tableName, JsonData.Code, JsonData.WorkPoint, JsonData.BatchCode);
log.Info("条码sql:" + WLosql);
table = DBHelper.SQlReturnData(WLosql, cmd);
}
else if (TransType == TransTypeEnum.CodeSplitSearch.GetDescription())
{
Lotsplitsql = string.Format(Lotsplitsql, columns, tableName, JsonData.Code, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(Lotsplitsql, cmd);
}
else if (DBHelper.IsPNU9() && TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
{
PNTranfersql = string.Format(PNTranfersql, columns, tableName, JsonData.Code, JsonData.WorkPoint, zlqty, JsonData.TransCode);
table = DBHelper.SQlReturnData(PNTranfersql, cmd);
}
else if (TransType == TransTypeEnum.CodePrint.GetDescription())
{
Printsql = string.Format(Printsql, columns, tableName, JsonData.Code, JsonData.WorkPoint);
table = DBHelper.SQlReturnData(Printsql, cmd);
}
else
{
sql = string.Format(sql, columns, tableName, JsonData.Code, JsonData.WorkPoint, zlqty, JsonData.TransCode, QuantityWhere);
//sql += DBHelper.SearchConditonGet("Search", "f6d34ca8-a5d2-4a35-9ded-b19626954f57", cmd);
log.Info("条码sql:" + sql);
table = DBHelper.SQlReturnData(sql, cmd);
}
if (table == null || table.Rows.Count <= 0)
throw new Exception(language.GetNameByCode("WMSAPIInfo008"));//"未查询到条码数据!"
#region 出库检验是否符合源头单据
log.Info("先进先出111");
string msg = string.Empty;
bool isLimit = false;
string sqlCheckSign = @"select F_EnabledMark from Sys_SRM_Items where F_EnCode = 'OutWithLocationCode' and F_EnabledMark = '1'";
DataTable flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
if (isOut && TransType != TransTypeEnum.GiftOutDoc.GetDescription()) // && TransType != TransTypeEnum.LOTSplit.GetDescription()
{//&& TransType != TransTypeEnum.TransferLibrary.GetDescription()
string Lot = "";
string workP = "";
if (TransType == TransTypeEnum.TransferLibrary.GetDescription())
{
foreach (DataRow drLot in table.Rows)
{
Lot = drLot["LotNo"].ToString();
sql = @"SELECT WarehouseCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
sql = string.Format(sql, Lot, JsonData.WorkPoint);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt == null || dt.Rows.Count <= 0)
{
throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), Lot));
}
string whcode = dt.Rows[0]["WarehouseCode"].ToString();
if (!JsonData.WHCode.Equals(whcode))
{
throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo395"), JsonData.WHCode, whcode));
}
}
}
else if (TransType != TransTypeEnum.LocationSeatch.GetDescription() && TransType != TransTypeEnum.StepNoTransferDocIn.GetDescription() && TransType != TransTypeEnum.JHStepNoTransferDocIn.GetDescription()
&& TransType != TransTypeEnum.CodePrint.GetDescription() && TransType != TransTypeEnum.CodeSplitSearch.GetDescription() && TransType != TransTypeEnum.LotJL.GetDescription())
{
log.Info("先进先出222");
if (string.IsNullOrEmpty(JsonData.TransCode))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
}
WMSSourceDocumentModel model = new WMSSourceDocumentModel();
model.TransCode = JsonData.TransCode;
model.TransType = JsonData.TransType;
model.WorkPoint = JsonData.WorkPoint;
model.User = JsonData.User;
DataTable TransData = new DataTable();
DataView dataView = TransData.DefaultView;
if (null == JsonData.DepType || "" == JsonData.DepType)//海格连续扫单据出库 暂不判断条码与单据
{
TransData = TransInformationGet(model);
dataView = TransData.DefaultView;
}
log.Info("先进先出333");
foreach (DataRow drLot in table.Rows)
{
log.Info("先进先出444");
String sqlnew = "";
Lot = drLot["LotNo"].ToString();
//盘点不需要对比以下属性
if (TransType == TransTypeEnum.Check.GetDescription() || TransType == TransTypeEnum.JHMOIssueDoc.GetDescription())
continue;
if (null == JsonData.DepType || "" == JsonData.DepType)
{//海格连续扫单据出库 暂不判断条码与单据
string rowFilter = "InvCode='" + drLot["InvCode"] + "'";
CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo041"), Lot, drLot["InvCode"]));
if (JsonData.checkWarehouse == null || "" == JsonData.checkWarehouse)
{
rowFilter += " AND (LEN(ISNULL(WHCode,''))<=0 OR (LEN(ISNULL(WHCode,''))>0 AND WHCode='" + drLot["WHCode"] + "'))";
CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo042"), Lot, drLot["WHCode"]));
}
log.Info("先进先出qqq");
rowFilter += " AND (LEN(ISNULL(ProjectCode,''))<=0 OR (LEN(ISNULL(ProjectCode,''))>0 AND ProjectCode='" + drLot["ProjectCode"] + "'))";
log.Info("先进先出www");
CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["ProjectCode"], GetExtentionName("ProjectCode", JsonData.WorkPoint, cmd, language)));
log.Info("先进先出123:" + drLot["ProjectCode"]);
log.Info("先进先出456:" + Lot);
log.Info("先进先出789:");
rowFilter += "AND (LEN(ISNULL(BatchCode,''))<=0 OR (LEN(ISNULL(BatchCode,''))>0 AND BatchCode='" + drLot["BatchCode"] + "'))";
CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["BatchCode"], GetExtentionName("BatchCode", JsonData.WorkPoint, cmd, language)));
rowFilter += "AND (LEN(ISNULL(Version,''))<=0 OR (LEN(ISNULL(Version,''))>0 AND Version='" + drLot["Version"] + "'))";
CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["Version"], GetExtentionName("Version", JsonData.WorkPoint, cmd, language)));
rowFilter += "AND (LEN(ISNULL(Brand,''))<=0 OR (LEN(ISNULL(Brand,''))>0 AND Brand='" + drLot["Brand"] + "'))";
CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["Brand"], GetExtentionName("Brand", JsonData.WorkPoint, cmd, language)));
rowFilter += "AND (LEN(ISNULL(cFree1,''))<=0 OR (LEN(ISNULL(cFree1,''))>0 AND cFree1='" + drLot["cFree1"] + "'))";
CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree1"], GetExtentionName("cFree1", JsonData.WorkPoint, cmd, language)));
rowFilter += "AND (LEN(ISNULL(cFree2,''))<=0 OR (LEN(ISNULL(cFree2,''))>0 AND cFree2='" + drLot["cFree2"] + "'))";
CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree2"], GetExtentionName("cFree2", JsonData.WorkPoint, cmd, language)));
rowFilter += "AND (LEN(ISNULL(cFree3,''))<=0 OR (LEN(ISNULL(cFree3,''))>0 AND cFree3='" + drLot["cFree3"] + "'))";
CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree3"], GetExtentionName("cFree3", JsonData.WorkPoint, cmd, language)));
rowFilter += "AND (LEN(ISNULL(cFree4,''))<=0 OR (LEN(ISNULL(cFree4,''))>0 AND cFree4='" + drLot["cFree4"] + "'))";
CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree4"], GetExtentionName("cFree4", JsonData.WorkPoint, cmd, language)));
rowFilter += "AND (LEN(ISNULL(cFree5,''))<=0 OR (LEN(ISNULL(cFree5,''))>0 AND cFree5='" + drLot["cFree5"] + "'))";
CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree5"], GetExtentionName("cFree5", JsonData.WorkPoint, cmd, language)));
rowFilter += "AND (LEN(ISNULL(cFree6,''))<=0 OR (LEN(ISNULL(cFree6,''))>0 AND cFree6='" + drLot["cFree6"] + "'))";
CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree6"], GetExtentionName("cFree6", JsonData.WorkPoint, cmd, language)));
rowFilter += "AND (LEN(ISNULL(cFree7,''))<=0 OR (LEN(ISNULL(cFree7,''))>0 AND cFree7='" + drLot["cFree7"] + "'))";
CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree7"], GetExtentionName("cFree7", JsonData.WorkPoint, cmd, language)));
rowFilter += "AND (LEN(ISNULL(cFree8,''))<=0 OR (LEN(ISNULL(cFree8,''))>0 AND cFree8='" + drLot["cFree8"] + "'))";
CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree8"], GetExtentionName("cFree8", JsonData.WorkPoint, cmd, language)));
rowFilter += "AND (LEN(ISNULL(cFree9,''))<=0 OR (LEN(ISNULL(cFree9,''))>0 AND cFree9='" + drLot["cFree9"] + "'))";
CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree9"], GetExtentionName("cFree9", JsonData.WorkPoint, cmd, language)));
rowFilter += "AND (LEN(ISNULL(cFree10,''))<=0 OR (LEN(ISNULL(cFree10,''))>0 AND cFree10='" + drLot["cFree10"] + "'))";
CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree10"], GetExtentionName("cFree10", JsonData.WorkPoint, cmd, language)));
log.Info("先进先出bbb" + flag.Rows.Count);
if (flag != null && flag.Rows.Count > 0)
{
rowFilter += " AND LocationCode='" + drLot["LocationCode"] + "'";
CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo042"), Lot, drLot["LocationCode"]));
}
log.Info("先进先出555");
string rowFilternew = rowFilter + " AND LEN(ISNULL(ProjectCode,''))>0";
sqlnew = CheckTransnew(dataView, rowFilternew, "ProjectCode");
rowFilternew = rowFilter + " AND LEN(ISNULL(BatchCode,''))>0";
sqlnew += CheckTransnew(dataView, rowFilternew, "BatchCode");
rowFilternew = rowFilter + " AND LEN(ISNULL(Version,''))>0";
sqlnew += CheckTransnew(dataView, rowFilternew, "Version");
rowFilternew = rowFilter + " AND LEN(ISNULL(Brand,''))>0";
sqlnew += CheckTransnew(dataView, rowFilternew, "Brand");
rowFilternew = rowFilter + " AND LEN(ISNULL(cFree1,''))>0";
sqlnew += CheckTransnew(dataView, rowFilternew, "cFree1");
rowFilternew = rowFilter + " AND LEN(ISNULL(cFree2,''))>0";
sqlnew += CheckTransnew(dataView, rowFilternew, "cFree2");
rowFilternew = rowFilter + " AND LEN(ISNULL(cFree3,''))>0";
sqlnew += CheckTransnew(dataView, rowFilternew, "cFree3");
rowFilternew = rowFilter + " AND LEN(ISNULL(cFree4,''))>0";
sqlnew += CheckTransnew(dataView, rowFilternew, "cFree4");
rowFilternew = rowFilter + " AND LEN(ISNULL(cFree5,''))>0";
sqlnew += CheckTransnew(dataView, rowFilternew, "cFree5");
rowFilternew = rowFilter + " AND LEN(ISNULL(cFree6,''))>0";
sqlnew += CheckTransnew(dataView, rowFilternew, "cFree6");
rowFilternew = rowFilter + " AND LEN(ISNULL(cFree7,''))>0";
sqlnew += CheckTransnew(dataView, rowFilternew, "cFree7");
rowFilternew = rowFilter + " AND LEN(ISNULL(cFree8,''))>0 ";
sqlnew += CheckTransnew(dataView, rowFilternew, "cFree8");
rowFilternew = rowFilter + " AND LEN(ISNULL(cFree9,''))>0";
sqlnew += CheckTransnew(dataView, rowFilternew, "cFree9");
rowFilternew = rowFilter + " AND LEN(ISNULL(cFree10,''))>0";
sqlnew += CheckTransnew(dataView, rowFilternew, "cFree10");
}
else if (JsonData.ItemsControlCode == "P0001")
{
//海格工单领料将条码所在仓库与“拣配优先仓库配置项”比对,不在此配置中不许领料
string chkSql = string.Format(@"IF NOT EXISTS (SELECT 1
FROM Sys_SRM_Items a
INNER JOIN Sys_SRM_ItemsDetail b ON b.F_ItemId=a.F_Id
WHERE a.F_EnCode='P0001' AND F_ItemCode='{0}')
BEGIN
RAISERROR('条码不在拣配优先仓库配置中!',16,1)
Return
END", drLot["WHCode"]);
DBHelper.ExecuteNonQuery(chkSql, cmd);
}
log.Info("1");
//保质期管理
var resultEffective = Effective(Lot, JsonData.WorkPoint, JsonData.TransType, cmd, language);
//0 - 已经是最早的批次
//1 - 不管控
//2 - 提醒
//3 - 限制
if (resultEffective == "2")
{
msg += string.Format(language.GetNameByCode("WMSAPIInfo181"), Lot) + Environment.NewLine;
}
else if (resultEffective == "3")
{
msg += string.Format(language.GetNameByCode("WMSAPIInfo182"), Lot) + Environment.NewLine;
isLimit = true;
}
//先进先出判断
if (!string.IsNullOrWhiteSpace(JsonData.CheckPassWord))
{
if (JsonData.CheckPassWord == "0")
{
var result = CanOut(Lot, JsonData.WorkPoint, JsonData.ScanLotCode, sqlnew, JsonData.TransType, cmd, language);
//0 - 已经是最早的批次
//1 - 不管控
//2 - 提醒
//3 - 限制
if (result == "2")
{
msg += string.Format(language.GetNameByCode("WMSAPIInfo178"), Lot) + Environment.NewLine;
}
else if (result == "3")
{
msg += string.Format(language.GetNameByCode("WMSAPIInfo179"), Lot) + Environment.NewLine;
isLimit = true;
}
}
}
else
{
var result = CanOut(Lot, JsonData.WorkPoint, JsonData.ScanLotCode, sqlnew, JsonData.TransType, cmd, language);
//0 - 已经是最早的批次
//1 - 不管控
//2 - 提醒
//3 - 限制
if (result == "2")
{
string tsql = @"
SELECT Top 1 a.F_ItemName
FROM Sys_SRM_ItemsDetail a
INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
WHERE b.F_EnCode='MtimeControl' AND a.F_EnabledMark='1'
ORDER BY a.F_SortCode DESC";
tsql = string.Format(tsql);
DataTable dttt = DBHelper.SQlReturnData(tsql, cmd);
string Cansql = @"DECLARE @CountNO INT,@Days INT
SELECT @Days=F_Description FROM Sys_SRM_Items WHERE F_EnCode='FIFO'
--排除在拣料之外的仓库
SELECT WarehouseCode INTO #TEMPWareHouse FROM ICSWareHouse
where WarehouseCode NOT IN
(select B.F_Define1 from Sys_SRM_Items A
INNER JOIN Sys_SRM_ItemsDetail B ON B.F_ItemId=A.F_Id
WHERE A.F_EnCode='FIFO_Wareouse')
and WorkPoint='{1}'
SELECT top 1 a.LotNO,loca.LocationName FROM ICSWareHouseLotInfo a
INNER JOIN ICSInventoryLot b ON a.LotNO=b.LotNO --AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSExtension bext on b.ExtensionID=bext.id --AND b.WorkPoint=bext.WorkPoint
INNER JOIN ICSLocation loca on loca.LocationCode=a.LocationCode AND loca.WorkPoint=a.WorkPoint
WHERE a.warehousecode in (select WarehouseCode from #TEMPWareHouse) and
a.warehousecode in (select WarehouseCode from ICSWareHouseLotInfo where LotNO='{0}') and
ISNULL(a.Quantity,0)>0 AND 1=1
AND CONVERT(varchar(100), {2}, 23)<
(SELECT DATEADD(DAY, -@Days, CONVERT(varchar(100), {3}, 23)) FROM ICSWareHouseLotInfo x
INNER JOIN ICSInventoryLot y ON x.LotNO=y.LotNO --AND x.WorkPoint=y.WorkPoint
INNER JOIN ICSExtension yext on y.ExtensionID=yext.id --AND b.WorkPoint=yext.WorkPoint
WHERE x.LotNO='{0}' AND y.INVCode=b.INVCode " + sqlnew + @")
drop table #TEMPWareHouse";
if (!string.IsNullOrWhiteSpace(JsonData.ScanLotCode))
{
Cansql = @"DECLARE @CountNO INT,@Days INT
SELECT @Days=F_Description FROM Sys_SRM_Items WHERE F_EnCode='FIFO'
--排除在拣料之外的仓库
SELECT WarehouseCode INTO #TEMPWareHouse FROM ICSWareHouse
where WarehouseCode NOT IN
(select B.F_Define1 from Sys_SRM_Items A
INNER JOIN Sys_SRM_ItemsDetail B ON B.F_ItemId=A.F_Id
WHERE A.F_EnCode='FIFO_Wareouse')
and WorkPoint='{1}'
SELECT top 1 a.LotNO,loca.LocationName FROM ICSWareHouseLotInfo a
INNER JOIN ICSInventoryLot b ON a.LotNO=b.LotNO --AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSExtension bext on b.ExtensionID=bext.id --AND b.WorkPoint=bext.WorkPoint
INNER JOIN ICSLocation loca on loca.LocationCode=a.LocationCode AND loca.WorkPoint=a.WorkPoint
LEFT JOIN ICSWarehouseLotInfo loco ON a.LotNO = loco.LotNO AND loco.LotNO IN (" + JsonData.ScanLotCode + @")
WHERE a.warehousecode in (select WarehouseCode from #TEMPWareHouse) and
a.warehousecode in (select WarehouseCode from ICSWareHouseLotInfo where LotNO='{0}') and
ISNULL(a.Quantity,0)>0 AND 1=1
AND CONVERT(varchar(100), {2}, 23)<
(SELECT DATEADD(DAY, -@Days, CONVERT(varchar(100), {3}, 23)) FROM ICSWareHouseLotInfo x
INNER JOIN ICSInventoryLot y ON x.LotNO=y.LotNO --AND x.WorkPoint=y.WorkPoint
INNER JOIN ICSExtension yext on y.ExtensionID=yext.id --AND b.WorkPoint=yext.WorkPoint
WHERE x.LotNO='{0}' AND y.INVCode=b.INVCode " + sqlnew + @")
drop table #TEMPWareHouse";
Cansql = Cansql.Replace("1=1", "loco.LotNO is NULL");
}
if (dttt.Rows[0]["F_ItemName"].ToString() == "失效日期")
{
Cansql = string.Format(Cansql, Lot, JsonData.WorkPoint, "ISNULL(b.ExpirationDate,b.ProductDate)", "ISNULL(y.ExpirationDate,y.ProductDate)");
}
else if (dttt.Rows[0]["F_ItemName"].ToString() == "生产日期")
{
Cansql = string.Format(Cansql, Lot, JsonData.WorkPoint, "b.ProductDate", "y.ProductDate");
}
else
{
Cansql = string.Format(Cansql, Lot, JsonData.WorkPoint, "a.InDate", "x.InDate");
}
DataTable Newdttt = DBHelper.SQlReturnData(Cansql, cmd);
msg += string.Format(language.GetNameByCode("WMSAPIInfo178"), Lot) + "推荐条码:" + Newdttt.Rows[0]["LotNO"] + ",推荐库位:" + Newdttt.Rows[0]["LocationName"] + Environment.NewLine;
}
else if (result == "3")
{
string tsql = @"
SELECT Top 1 a.F_ItemName
FROM Sys_SRM_ItemsDetail a
INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
WHERE b.F_EnCode='MtimeControl' AND a.F_EnabledMark='1'
ORDER BY a.F_SortCode DESC";
tsql = string.Format(tsql);
DataTable dttt = DBHelper.SQlReturnData(tsql, cmd);
string Cansql = @"DECLARE @CountNO INT,@Days INT
SELECT @Days=F_Description FROM Sys_SRM_Items WHERE F_EnCode='FIFO'
--排除在拣料之外的仓库
SELECT WarehouseCode INTO #TEMPWareHouse FROM ICSWareHouse
where WarehouseCode NOT IN
(select B.F_Define1 from Sys_SRM_Items A
INNER JOIN Sys_SRM_ItemsDetail B ON B.F_ItemId=A.F_Id
WHERE A.F_EnCode='FIFO_Wareouse')
and WorkPoint='{1}'
SELECT top 1 a.LotNO,loca.LocationName FROM ICSWareHouseLotInfo a
INNER JOIN ICSInventoryLot b ON a.LotNO=b.LotNO --AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSExtension bext on b.ExtensionID=bext.id --AND b.WorkPoint=bext.WorkPoint
INNER JOIN ICSLocation loca on loca.LocationCode=a.LocationCode AND loca.WorkPoint=a.WorkPoint
WHERE a.warehousecode in (select WarehouseCode from #TEMPWareHouse) and
a.warehousecode in (select WarehouseCode from ICSWareHouseLotInfo where LotNO='{0}') and
ISNULL(a.Quantity,0)>0 AND 1=1
AND CONVERT(varchar(100), {2}, 23)<
(SELECT DATEADD(DAY, -@Days, CONVERT(varchar(100), {3}, 23)) FROM ICSWareHouseLotInfo x
INNER JOIN ICSInventoryLot y ON x.LotNO=y.LotNO --AND x.WorkPoint=y.WorkPoint
INNER JOIN ICSExtension yext on y.ExtensionID=yext.id --AND b.WorkPoint=yext.WorkPoint
WHERE x.LotNO='{0}' AND y.INVCode=b.INVCode " + sqlnew + @")
drop table #TEMPWareHouse";
if (!string.IsNullOrWhiteSpace(JsonData.ScanLotCode))
{
Cansql = @"DECLARE @CountNO INT,@Days INT
SELECT @Days=F_Description FROM Sys_SRM_Items WHERE F_EnCode='FIFO'
--排除在拣料之外的仓库
SELECT WarehouseCode INTO #TEMPWareHouse FROM ICSWareHouse
where WarehouseCode NOT IN
(select B.F_Define1 from Sys_SRM_Items A
INNER JOIN Sys_SRM_ItemsDetail B ON B.F_ItemId=A.F_Id
WHERE A.F_EnCode='FIFO_Wareouse')
and WorkPoint='{1}'
SELECT top 1 a.LotNO,loca.LocationName FROM ICSWareHouseLotInfo a
INNER JOIN ICSInventoryLot b ON a.LotNO=b.LotNO --AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSExtension bext on b.ExtensionID=bext.id --AND b.WorkPoint=bext.WorkPoint
INNER JOIN ICSLocation loca on loca.LocationCode=a.LocationCode AND loca.WorkPoint=a.WorkPoint
LEFT JOIN ICSWarehouseLotInfo loco ON a.LotNO = loco.LotNO AND loco.LotNO IN (" + JsonData.ScanLotCode + @")
WHERE a.warehousecode in (select WarehouseCode from #TEMPWareHouse) and
a.warehousecode in (select WarehouseCode from ICSWareHouseLotInfo where LotNO='{0}') and
ISNULL(a.Quantity,0)>0 AND 1=1
AND CONVERT(varchar(100), {2}, 23)<
(SELECT DATEADD(DAY, -@Days, CONVERT(varchar(100), {3}, 23)) FROM ICSWareHouseLotInfo x
INNER JOIN ICSInventoryLot y ON x.LotNO=y.LotNO --AND x.WorkPoint=y.WorkPoint
INNER JOIN ICSExtension yext on y.ExtensionID=yext.id --AND b.WorkPoint=yext.WorkPoint
WHERE x.LotNO='{0}' AND y.INVCode=b.INVCode " + sqlnew + @")
drop table #TEMPWareHouse";
Cansql = Cansql.Replace("1=1", "loco.LotNO is NULL");
}
if (dttt.Rows[0]["F_ItemName"].ToString() == "失效日期")
{
Cansql = string.Format(Cansql, Lot, JsonData.WorkPoint, "ISNULL(b.ExpirationDate,b.ProductDate)", "ISNULL(y.ExpirationDate,y.ProductDate)");
}
else if (dttt.Rows[0]["F_ItemName"].ToString() == "生产日期")
{
Cansql = string.Format(Cansql, Lot, JsonData.WorkPoint, "b.ProductDate", "y.ProductDate");
}
else
{
Cansql = string.Format(Cansql, Lot, JsonData.WorkPoint, "a.InDate", "x.InDate");
}
DataTable Newdttt = DBHelper.SQlReturnData(Cansql, cmd);
msg += string.Format(language.GetNameByCode("WMSAPIInfo179"), Lot) + "推荐条码:" + Newdttt.Rows[0]["LotNO"] + ",推荐库位:" + Newdttt.Rows[0]["LocationName"] + Environment.NewLine;
isLimit = true;
}
}
}
}
}
else if (TransType == TransTypeEnum.GiftOutDoc.GetDescription())
{
//赠品出库不检验源头单据
}
else
{
//自定义档案 每次入库是否只控制一张单据
sqlCheckSign = @"select b.F_ItemCode as Code ,b.F_Define2 as Name,b.F_EnabledMark AS Enable,b.F_Define1 AS BusinessCode
from Sys_SRM_Items a
left join Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
where a.F_EnCode='InvInControl' and b.F_Define1 = '" + EnumHelper.GetDBValue(typeof(TransTypeEnum), TransType) + "' and b.F_EnabledMark= 1 order by cast(b.F_SortCode as int) asc";
flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
if (flag != null && flag.Rows.Count > 0)
{
if (JsonData.TransCode != null && JsonData.TransCode != "" && table.Rows[0]["TransCode"].ToString() != JsonData.TransCode) throw new Exception("本次入库只能扫" + JsonData.TransCode + "单据内条码!");
}
}
#endregion
//return table;
Result res = new Result();
res.Success = true;
res.Message = msg;// "接口调用成功!";
if (!isLimit)
res.Data = table;
return res;
//出库时
//Message无值、Data有值,可直接处理
//Message有值、Data有值,弹出提醒框(可点击确定、取消,确定后继续出库,取消后不处理这批条码),显示Message信息
//Message有值、Data无值,弹出警告框(只能点击确定,且不处理这批条码),显示Message信息
}
catch (Exception ex)
{
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
public static Result BarCodeForCheckByLoc(BarCodeModel JsonData)
{
var language = LanguageHelper.GetName("WMSAPIInfo");
DataTable table = new DataTable();
DataTable ZLtable = new DataTable();
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
try
{
string sql = @"IF not EXISTS(select 1 from ICSCheckDetail a inner join icscheck b on a.checkid = b.id and a.WorkPoint = b.workpoint where b.checkcode = '{0}' and a.locationcode = '{1}' AND a.WorkPoint='{2}')
BEGIN
RAISERROR('当前盘点单不包含此库位', 16, 1);
END
SELECT a.ID,
con.ContainerCode,
con.ContainerName,
a.LotNo,
a.InvCode,
ISNULL(inv.EATTRIBUTE10,'') AS KInvCode,
inv.InvName,
inv.InvStd,
inv.InvUnit,
inv.LotEnable,
(a.Quantity-a.lockQuantity) AS Quantity,
(a.Quantity-a.lockQuantity)*(lot.Amount/lot.Quantity) AS Amount,
aa.Quantity AS IssueQuantity,
'' AS LogID,
a.WarehouseCode AS WHCode,
wh.WarehouseName AS WHName,
inv.LotEnable,
a.LocationCode,
loc.LocationName,
'0' AS SUMLotCount,
'0' AS ISSUMLotCount,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
inv.AmountUnit,
ext.ID AS ExtensionID,
ext.ProjectCode,
ext.Version,
--ext.BatchCode,
isnull((select a.F_EnabledMark from Sys_SRM_ItemsDetail a
inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
where b.F_id='500fb2a3-c597-4371-ab18-b280b55d571e'),'') AS LotSplitEnable,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MTIME AS [MTime],
'LOTNO' AS ScanType
FROM ICSWareHouseLotInfo a
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
inner join iCSCheckDetail aa on aa.lotno = a.lotno and aa.WorkPoint = a.workpoint
inner join icscheck bb on aa.checkid = bb.id and aa.WorkPoint = bb.workpoint
WHERE bb.checkcode = '{0}' AND a.WorkPoint='{2}' and aa.locationcode ='{1}'";
sql = string.Format(sql, JsonData.TransCode, JsonData.Code, JsonData.WorkPoint);
//sql += DBHelper.SearchConditonGet("Search", "f6d34ca8-a5d2-4a35-9ded-b19626954f57", cmd);
log.Info("条码sql:" + sql);
table = DBHelper.SQlReturnData(sql, cmd);
if (table == null || table.Rows.Count <= 0)
throw new Exception(language.GetNameByCode("WMSAPIInfo008"));//"未查询到条码数据!"
//return table;
Result res = new Result();
res.Success = true;
res.Message = "接口调用成功!";// ;
res.Data = table;
return res;
//出库时
//Message无值、Data有值,可直接处理
//Message有值、Data有值,弹出提醒框(可点击确定、取消,确定后继续出库,取消后不处理这批条码),显示Message信息
//Message有值、Data无值,弹出警告框(只能点击确定,且不处理这批条码),显示Message信息
}
catch (Exception ex)
{
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
///
/// 校验条码对应的物料、自由项等信息是否与源头单据匹配
///
private static DataView CheckTrans(DataView dataView, string rowFilter, string message)
{
log.Debug("abc:" + rowFilter);
dataView.RowFilter = rowFilter;
if (dataView == null || dataView.Count <= 0)
throw new Exception(message);
return dataView;
}
#endregion
private static string CheckTransnew(DataView dataView, string rowFilter, string aaa)
{
dataView.RowFilter = rowFilter;
if (dataView == null || dataView.Count <= 0)
return "";
return " AND bext." + aaa + "=yext." + aaa;
}
///
/// 上架
/// BusinessCode,TransType 两个类型
///
///
public static DataTable LOTStockCreate(List JsonData, SqlCommand command = null)
{
string PalletCode = string.Empty;
//拼接所有条码——>批量查询赠品
StringBuilder LotNosForGift = new StringBuilder();
var language = LanguageHelper.GetName("WMSAPIInfo");
if (JsonData.Count <= 0)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
}
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
SqlCommand cmd;
if (command == null)
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
}
else
cmd = command;
string BusinessCode = string.Empty;
string UserCode = string.Empty;
try
{
DataTable dtable = new DataTable();
string result = string.Empty;
string IsDx = string.Empty;
string TransType = string.Empty;
string TransTypeOriginal = string.Empty;//记录不合格入库条码的原条码的类型
string Identification = Guid.NewGuid().ToString();
bool needRefuse = false;
foreach (var item in JsonData)
{
if (string.IsNullOrEmpty(item.IsDx))
{
IsDx = "";
}
else
{
IsDx = item.IsDx;
}
TransType = item.TransType;
if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
{
throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
}
string WHTransType = "2";
UserCode = item.User;
foreach (var itemInfo in item.detail)
{
if (itemInfo.ContainerOrLotNo != "" && itemInfo.ContainerOrLotNo != null)
{
PalletCode = itemInfo.ContainerOrLotNo;
}
#region 晶华立库虚拟库位逻辑 仓库对应库位如果在wms不存在的话 那就从自定义档案里去找库位 如果存在 那就用传参里的库位 传什么库位就入什么库位
string checksql = @"IF NOT EXISTS(select d.id from ICSLocation d
where d.Locationcode='{2}')
BEGIN
SELECT DISTINCT
b.F_ItemCode
FROM Sys_SRM_Items a
LEFT JOIN Sys_SRM_ItemsDetail b ON a.F_Id = b.F_ItemId
WHERE a.F_EnCode = 'locationOfliku' and b.F_Define1='{0}'
END
";
checksql = string.Format(checksql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
if (chekdt.Rows.Count != 0 && chekdt != null)
{
itemInfo.LocationCode = chekdt.Rows[0]["F_ItemCode"].ToString();
}
#endregion
#region 两步调入
if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
{
//更新源头单据数量
ICSWareHouseService.TwoStepTransferDocIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
//入库
ICSWareHouseLotInfoService.WareHouseLotInfoTwoStepTransferDocIn(Identification, itemInfo.TransCode, itemInfo.TransSequence,
itemInfo.WarehouseCode, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity, item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocIn.GetDescription(), cmd, language);
}
#endregion
#region 晶华两步调入
else if (TransType == TransTypeEnum.JHTwoStepTransferDocIn.GetDescription())
{
//更新源头单据数量
ICSWareHouseService.JHTwoStepTransferDocIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
//入库
ICSWareHouseLotInfoService.WareHouseLotInfoTwoStepTransferDocIn(Identification, itemInfo.TransCode, itemInfo.TransSequence,
itemInfo.WarehouseCode, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity, item.User, item.WorkPoint, "6", TransTypeEnum.JHTwoStepTransferDocIn.GetDescription(), cmd, language);
}
#endregion
#region 锐腾两步调入
else if (TransType == TransTypeEnum.RTTwoStepTransferDocIn.GetDescription())
{
//更新源头单据数量
ICSWareHouseService.RTTwoStepTransferDocIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
//入库
ICSWareHouseLotInfoService.RTWareHouseLotInfoTwoStepTransferDocIn(Identification, itemInfo.TransCode, itemInfo.TransSequence,
itemInfo.WarehouseCode, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity, item.User, item.WorkPoint, "6", TransTypeEnum.RTTwoStepTransferDocIn.GetDescription(), cmd, language);
}
#endregion
#region 销售退货-原条码
else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
{
//更新源头单据数量
ICSSalesService.SalesReturnBackIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
//入库
BusinessCode = TransTypeEnum.SalesReturnBack.GetDescription();
//入库
ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode, "", "", itemInfo.InvCode);
//更新日志表源头单据信息
string sql = @"UPDATE ICSWareHouseLotInfoLog SET TransCode='{3}',TransSequence='{4}'
WHERE LotNo='{0}' AND WorkPoint='{1}' AND Identification='{2}' ";
sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, Identification, itemInfo.TransCode, itemInfo.TransSequence);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
}
}
#endregion
#region 销售退货-原条码
else if (TransType == TransTypeEnum.SalesShipmentOutRedYuanDoc.GetDescription())
{
//更新源头单据数量
ICSSalesService.SalesShipmentOutRedYuanDocIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
//入库
BusinessCode = TransTypeEnum.SalesShipmentOutRedYuanDoc.GetDescription();
//入库
ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode, "", "", itemInfo.InvCode);
//更新日志表源头单据信息
string sql = @"UPDATE ICSWareHouseLotInfoLog SET TransCode='{3}',TransSequence='{4}'
WHERE LotNo='{0}' AND WorkPoint='{1}' AND Identification='{2}' ";
sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, Identification, itemInfo.TransCode, itemInfo.TransSequence);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo531"));//"红字销售出库单更新失败!");
}
}
#endregion
else
{
#region 采购入库
if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
{
if(item.IsShortShipped){
log.Debug("采购短料上架");
needRefuse = true;
ICSPurchaseService.PurchaseReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, itemInfo.BadQty, itemInfo.InvCode, itemInfo.InvIQC, item.WorkPoint, cmd, language);
}
else
{
//更新源头单据数量
log.Debug("0");
ICSPurchaseService.PurchaseReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
}
BusinessCode = TransTypeEnum.PurchaseReceiveDoc.GetDescription();
}
#endregion
#region 采购入库-入库单
else if (TransType == TransTypeEnum.PurchaseReceiveRevDoc.GetDescription())
{
//更新源头单据数量
ICSPurchaseService.PurchaseReceiveRevDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.PurchaseReceiveRevDoc.GetDescription();
}
#endregion
#region 审核的到货单
else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
{
//更新源头单据数量
ICSPurchaseService.DeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription();
}
#endregion
#region 采购拒收
else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
{
//更新源头单据数量
ICSPurchaseService.PurchaseRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.PurchaseRejectDoc.GetDescription();
}
#endregion
#region 审核的委外到货单
else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
{
//更新源头单据数量
ICSOutsourcingService.ODeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.ODeliveryNotice.GetDescription();
}
#endregion
#region 委外拒收
else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
{
//更新源头单据数量
ICSOutsourcingService.OutsourcingRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.OutsourcingRejectDoc.GetDescription();
}
#endregion
#region 委外退料
else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
{
//更新源头单据数量
ICSOutsourcingService.OutsourcingIssueDoNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, itemInfo.TransCode, itemInfo.TransSequence, cmd, language);
BusinessCode = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription();
}
#endregion
#region 返工工单
else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
{
//更新源头单据数量
ICSManufactureService.ReWorkReceiveMo(itemInfo.LotNo, itemInfo.Quantity, itemInfo.WarehouseCode, itemInfo.LocationCode, item.WorkPoint, item.User, TransTypeEnum.ReWorkReceiveMo.GetDescription(), cmd, language);
BusinessCode = TransTypeEnum.ReWorkReceiveMo.GetDescription();
}
#endregion
#region 委外入库
else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
{
//更新源头单据数量
if (item.IsShortShipped)
{
log.Debug("委外短料上架");
needRefuse = true;
ICSOutsourcingService.OutsourcingReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, itemInfo.BadQty, itemInfo.InvCode, itemInfo.InvIQC, item.WorkPoint, cmd, language);
}
else
{
ICSOutsourcingService.OutsourcingReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
}
BusinessCode = TransTypeEnum.OutsourcingReceiveDoc.GetDescription();
}
#endregion
#region 委外入库-入库单
else if (TransType == TransTypeEnum.OutsourcingReceiveRevDoc.GetDescription())
{
//更新源头单据数量
ICSOutsourcingService.OutsourcingReceiveRcvDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.OutsourcingReceiveRevDoc.GetDescription();
if (LotNosForGift.Length > 0)
{
LotNosForGift.Append(",");
}
LotNosForGift.Append("'").Append(itemInfo.LotNo).Append("'");
}
//鑫隽渊委外收货
else if (TransType == TransTypeEnum.OutsourcingReceiveRevXJYDoc.GetDescription())
{
//更新源头单据数量
ICSOutsourcingService.OutsourcingReceiveRcvDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.OutsourcingReceiveRevXJYDoc.GetDescription();
if (LotNosForGift.Length > 0)
{
LotNosForGift.Append(",");
}
LotNosForGift.Append("'").Append(itemInfo.LotNo).Append("'");
}
#endregion
#region 生产退料
else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
|| TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
|| TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
{
ICSManufactureService.MOIssueDocNegative(TransType, itemInfo.LogID, itemInfo.LotNo,itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription();
log.Debug("生产退料5");
}
#endregion
#region 生产入库
else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
{
log.Debug("生产入库" + TransType);
//更新源头单据数量
ICSManufactureService.ManufactureReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.ManufactureReceiveDoc.GetDescription();
if (LotNosForGift.Length > 0)
{
LotNosForGift.Append(",");
}
LotNosForGift.Append("'").Append(itemInfo.LotNo).Append("'");
}
#endregion
#region 晶华生产入库
else if (TransType == TransTypeEnum.JHManufactureReceiveDoc.GetDescription())
{
log.Debug("晶华生产入库" + TransType);
//更新源头单据数量
ICSManufactureService.ManufactureReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.JHManufactureReceiveDoc.GetDescription();
}
#endregion
#region 开立的生产入库单
else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
{
//更新源头单据数量
ICSManufactureService.ManufactureReceive(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.ManufactureReceive.GetDescription();
}
#endregion
#region MES产成品入库单
else if (TransType == TransTypeEnum.ManufactureMESReceive.GetDescription())
{
//更新源头单据数量
ICSManufactureService.ManufactureMESReceive(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, itemInfo.TransCode, cmd, language);
BusinessCode = TransTypeEnum.ManufactureMESReceive.GetDescription();
}
#endregion
#region 销售退货
else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
{
//更新源头单据数量
ICSSalesService.SalesShipmentDocNegative(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.SalesShipmentDocNegative.GetDescription();
}
#endregion
#region 销售出库-红字出库单
else if (TransType == TransTypeEnum.SalesShipmentOutRedDoc.GetDescription())
{
//更新源头单据数量
ICSSalesService.SalesShipmentOutRedDocNegative(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.SalesShipmentOutRedDoc.GetDescription();
}
#endregion
#region 其他入库
else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
{
//更新源头单据数量
ICSWareHouseService.OtherInDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.OtherInDoc.GetDescription();
}
#endregion
#region 拆卸单
else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
{
ICSWareHouseService.DisassemblyDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
WHTransType = "11";
BusinessCode = TransTypeEnum.DisassemblyDoc.GetDescription();
}
#endregion
#region 归还
else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
{
//更新源头单据数量
ICSWareHouseService.ReturnDoc(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.LogID, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.ReturnDoc.GetDescription();
}
#endregion
#region 不合格入库
else if (TransType == TransTypeEnum.UnqualifiedIN.GetDescription())
{
string sql = @"SELECT b.Type FROM ICSInventoryLot a
LEFT JOIN ICSInventoryLot b ON a.EATTRIBUTE1=b.LotNo AND b.WorkPoint=a.WorkPoint
WHERE a.LotNo='{0}' AND a.Type='17' AND a.WorkPoint='{1}'";
sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count != 0)
{
TransTypeOriginal = dt.Rows[0]["Type"].ToString();
}
if (TransTypeOriginal == string.Empty)
{
//throw new Exception(language.GetNameByCode(""));
throw new Exception("未查询到条码" + itemInfo.LotNo + "的原条码");
}
#region 审核的到货单
else if (TransTypeOriginal == "7")
{
//更新源头单据数量
ICSPurchaseService.DeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
//BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription();
TransTypeOriginal = TransTypeEnum.DeliveryNotice.GetDescription();
}
#endregion
#region 审核的委外到货单
else if (TransTypeOriginal == "8")
{
//更新源头单据数量
ICSOutsourcingService.ODeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
//BusinessCode = TransTypeEnum.ODeliveryNotice.GetDescription();
TransTypeOriginal = TransTypeEnum.ODeliveryNotice.GetDescription();
}
#endregion
#region 委外退料
else if (TransTypeOriginal == "2"
|| TransTypeOriginal == "14"
|| TransTypeOriginal == "15")
{
//更新源头单据数量
ICSOutsourcingService.OutsourcingIssueDoNegative(TransTypeOriginal, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, itemInfo.TransCode, itemInfo.TransSequence, cmd, language);
//BusinessCode = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription();
TransTypeOriginal = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription();
}
#endregion
#region 生产退料
else if (TransTypeOriginal == "1"
|| TransTypeOriginal == "12"
|| TransTypeOriginal == "13")
{
log.Debug("生产退料1" + TransTypeEnum.MOIssueDocNegative.GetDescription());
log.Debug("生产退料2" + TransTypeEnum.MOIssueDocNegativeApply.GetDescription());
log.Debug("生产退料3" + TransTypeEnum.MOIssueDocNegativeIssue.GetDescription());
log.Debug("生产退料4" + TransTypeOriginal);
//更新源头单据数量
ICSManufactureService.MOIssueDocNegative(TransTypeOriginal, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
//BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription();
TransTypeOriginal = TransTypeEnum.MOIssueDocNegative.GetDescription();
}
#endregion
#region 生产入库
else if (TransTypeOriginal == "3")
{
log.Debug("生产入库" + TransTypeOriginal);
//更新源头单据数量
ICSManufactureService.ManufactureReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
//BusinessCode = TransTypeEnum.ManufactureReceiveDoc.GetDescription();
TransTypeOriginal = TransTypeEnum.ManufactureReceiveDoc.GetDescription();
}
#endregion
#region 销售退货
else if (TransTypeOriginal == "4")
{
//更新源头单据数量
ICSSalesService.SalesShipmentDocNegative(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
//BusinessCode = TransTypeEnum.SalesShipmentDocNegative.GetDescription();
TransTypeOriginal = TransTypeEnum.SalesShipmentDocNegative.GetDescription();
}
#endregion
#region 其他入库
else if (TransTypeOriginal == "5")
{
//更新源头单据数量
ICSWareHouseService.OtherInDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
//BusinessCode = TransTypeEnum.OtherInDoc.GetDescription();
TransTypeOriginal = TransTypeEnum.OtherInDoc.GetDescription();
}
#endregion
BusinessCode = TransTypeEnum.UnqualifiedIN.GetDescription();
}
#endregion
#region 副产品入库
else if (TransType == TransTypeEnum.MOStockINByProduct.GetDescription())
{
log.Debug("副产品入库" + TransType);
//更新源头单据数量
ICSManufactureService.MOStockINByProductDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.MOStockINByProduct.GetDescription();
}
#endregion
#region 委外副产品入库
else if (TransType == TransTypeEnum.OOStockINByProduct.GetDescription())
{
log.Debug("副产品入库" + TransType);
//更新源头单据数量
ICSManufactureService.OOStockINByProductDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.OOStockINByProduct.GetDescription();
}
#endregion
#region 无源头副产品入库
else if (TransType == TransTypeEnum.MOStockINByProductNoTrans.GetDescription())
{
log.Debug("无源头副产品入库" + TransType);
//更新源头单据数量
//ICSManufactureService.MOStockINByProductDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.MOStockINByProductNoTrans.GetDescription();
}
#endregion
else
{
throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
}
//晶华mes InvCode无法做到与条码一一对应;
if (itemInfo.InvCode == "")
{
string asql = @"SELECT InvCode FROM ICSInventoryLot where LotNo='{0}' AND WorkPoint='{1}'";
asql = string.Format(asql, itemInfo.LotNo, item.WorkPoint);
DataTable adtt = DBHelper.SQlReturnData(asql, cmd);
if (adtt.Rows.Count > 0 && adtt != null)
{
itemInfo.InvCode = adtt.Rows[0]["InvCode"].ToString();
}
}
//入库
ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode, itemInfo.TransCode, itemInfo.TransSequence, itemInfo.InvCode);
if ("CARTON".Equals(itemInfo.ScanType))
{
//整箱提交,解绑容器与父容器
ICSWareHouseService.ICSContainerConUntieWhenIn(itemInfo.ContainerCode, item.WorkPoint, item.User, "6", cmd, language);
}
else if ("LOTNO".Equals(itemInfo.ScanType))
{
if (!string.IsNullOrEmpty(itemInfo.ContainerCode))
{
//非整箱提交,解绑条码与容器
ICSWareHouseService.ICSContainerLotUntieWhenIn(itemInfo.ContainerCode, itemInfo.LotNo, item.WorkPoint, item.User, "8", cmd, language);
}
}
}
}
#region 拆卸单
if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
{
//更新套件锁定数量
ICSWareHouseService.DisassemblyDoc(Identification, cmd, language);
}
#endregion
if (LotNosForGift.Length > 0)
{
ICSWareHouseLotInfoService.GiftInStorage(conn, cmd.Transaction, cmd, language, Identification, LotNosForGift.ToString(), item.User, item.User, item.MTime, item.WorkPoint, BusinessCode, WHTransType);
}
//短料上架生成拒收单
if (needRefuse)
{
if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
{
List refuseList = ICSPurchaseService.GetPoRefuseMsg(item, cmd);
PurchaseRejectDocCreate(refuseList, cmd);
}
else if(TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
{
List refuseList = ICSOutsourcingService.GetOORefuseMsg(item, cmd);
OutsourcingRejectDocCreate(refuseList, cmd);
}
}
}
//上传ERP
if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
{
log.Debug("ERP接口");
if (TransTypeOriginal != string.Empty)
{
TransType = TransTypeOriginal;
}
//采购入库
if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
{
if (DBHelper.IsU9())
{ ICSPurchaseService.CreatePOArriveERP(TransType, Identification, cmd, language, BusinessCode, "RCV01"); }
else
{
log.Debug("2");
ICSPurchaseService.PurchaseReceiveDocERP(TransType, Identification, cmd, language, BusinessCode, PalletCode);
}
}
//采购入库-入库单
else if (TransType == TransTypeEnum.PurchaseReceiveRevDoc.GetDescription())
{
ICSPurchaseService.PurchaseReceiveRevDocERP(TransType, Identification, cmd, language, BusinessCode, UserCode);
}
//审核的到货单
else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
dtable = ICSPurchaseService.DeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode, PalletCode);
//采购拒收
else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
ICSPurchaseService.PurchaseRejectDocInERP(TransType, Identification, cmd, language, BusinessCode);
//审核的委外到货单
else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
ICSOutsourcingService.ODeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode);
//委外拒收
else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
ICSOutsourcingService.OutsourcingRejectDocInERP(TransType, Identification, cmd, language, BusinessCode);
//委外退料
else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
ICSOutsourcingService.OutsourcingIssueDoNegativeERP(TransType, Identification, cmd, language, BusinessCode);
//委外入库
else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
{
if (DBHelper.IsU9())
{ ICSOutsourcingService.CreateOOArriveERP(TransType, Identification, cmd, language, BusinessCode, "RCV11"); }
else
{
ICSOutsourcingService.OutsourcingReceiveDocERP(TransType, Identification, cmd, language, BusinessCode);
}
}
//委外入库
else if (TransType == TransTypeEnum.OutsourcingReceiveRevDoc.GetDescription())
{
ICSOutsourcingService.OutsourcingReceiveRcvDocERP(TransType, Identification, cmd, language, BusinessCode, UserCode);
}
//委外入库
else if (TransType == TransTypeEnum.OutsourcingReceiveRevXJYDoc.GetDescription())
{
ICSOutsourcingService.OutsourcingReceiveRcvXJYDocERP(TransType, Identification, cmd, language, BusinessCode, UserCode);
}
//生产退料
else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
|| TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
|| TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
{
if (DBHelper.IsDX())
{
ICSManufactureService.DXMOIssueDocNegativeERP(TransType, Identification, cmd, language, BusinessCode, IsDx);
}
else
{
ICSManufactureService.MOIssueDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
}
}
//生产入库
else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
ICSManufactureService.ManufactureReceiveDocERP(TransType, Identification, cmd, language, BusinessCode, PalletCode);
//晶华生产入库
else if (TransType == TransTypeEnum.JHManufactureReceiveDoc.GetDescription())
ICSManufactureService.JHManufactureReceiveDocERP(TransType, Identification, cmd, language, BusinessCode, PalletCode);
//副产品入库
else if (TransType == TransTypeEnum.MOStockINByProduct.GetDescription())
ICSManufactureService.MOStockINByProductDocERP(TransType, Identification, cmd, language, BusinessCode);
//委外副产品入库
else if (TransType == TransTypeEnum.OOStockINByProduct.GetDescription())
ICSManufactureService.OOStockINByProductDocERP(TransType, Identification, cmd, language, BusinessCode);
//无源头副产品入库
else if (TransType == TransTypeEnum.MOStockINByProductNoTrans.GetDescription())
ICSManufactureService.MOStockINByProductNoTransDocERP(TransType, Identification, cmd, language, BusinessCode);
//开立的生产入库单
else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
dtable = ICSManufactureService.ManufactureReceiveERP(TransType, Identification, cmd, language, BusinessCode);
//MES产成品入库单
else if (TransType == TransTypeEnum.ManufactureMESReceive.GetDescription())
ICSManufactureService.ManufactureMESReceiveERP(TransType, Identification, JsonData[0].TransCode, cmd, language, BusinessCode);
//返工工单
else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
ICSManufactureService.ReWorkReceiveMoERP(TransType, Identification, cmd, language, BusinessCode);
//销售退货
else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
{
if (DBHelper.IsU9())
ICSSalesService.U9SalesShipmentDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
else
ICSSalesService.SalesShipmentDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
}
//红字销售出库单
else if (TransType == TransTypeEnum.SalesShipmentOutRedDoc.GetDescription() || TransType == TransTypeEnum.SalesShipmentOutRedYuanDoc.GetDescription())
{
ICSSalesService.SalesShipmentDocOutRedERP(TransType, Identification, cmd, language, BusinessCode);
}
//两步调入
else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
ICSWareHouseService.TwoStepTransferDocInERP(TransType, Identification, cmd, language, BusinessCode);
//晶华两步调入
else if (TransType == TransTypeEnum.JHTwoStepTransferDocIn.GetDescription())
ICSWareHouseService.JHTwoStepTransferDocInERP(TransType, Identification, cmd, language, BusinessCode);
//两步调入
else if (TransType == TransTypeEnum.RTTwoStepTransferDocIn.GetDescription())
ICSWareHouseService.RTTwoStepTransferDocInERP(TransType, Identification, cmd, language, BusinessCode);
//销售退货-原条码
else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
ICSSalesService.SalesReturnBackInERP(TransType, Identification, cmd, language, BusinessCode);
//其他入库
else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
{
if (DBHelper.IsU9())
ICSWareHouseService.CreateOtherInDocERP(TransType, Identification, cmd, language, BusinessCode);
else
ICSWareHouseService.OtherInDocERP(TransType, Identification, cmd, language, BusinessCode);
}
//拆卸单
if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
ICSWareHouseService.DisassemblyDocERP(TransType, Identification, cmd, language, BusinessCode);
//归还
else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
ICSWareHouseService.ReturnDocERP(TransType, Identification, cmd, language, BusinessCode);
}
if (TransType == TransTypeEnum.DeliveryNotice.GetDescription() || TransType == TransTypeEnum.ManufactureReceive.GetDescription())
{
if (command == null)
cmd.Transaction.Commit();
return dtable;
}
//else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription() && DBHelper.IsPNU9())
//{
// string sql = @"SELECT c.LotNo AS WLotNo FROM ICSWareHouseLotInfoLog log
// INNER JOIN ICSMO a ON log.TransCode=a.MOCode AND log.TransSequence=a.Sequence AND a.WorkPoint=log.WorkPoint
// INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a.MOCode AND a.WorkPoint=log.WorkPoint
// INNER JOIN ICSInventoryLot c ON b.lotno=c.LotNo and b.WorkPoint=c.WorkPoint
// where log.Identification='{0}' AND c.LotNo NOT IN(SELECT LotNo FROM ICSWareHouseLotInfo)";
// sql = string.Format(sql, Identification);
// DataTable table = DBHelper.SQlReturnData(sql, cmd);
// cmd.Transaction.Commit();
// return table;
//}
else
{
DataTable table = GetData(Identification, 1, cmd);
if (command == null)
cmd.Transaction.Commit();
return table;
}
}
catch (Exception ex)
{
if (cmd.Transaction != null && command == null)
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
///
/// 新入库上架
/// BusinessCode,TransType 两个类型
///
///
public static DataTable NewLOTStockCreate(List JsonData)
{
var language = LanguageHelper.GetName("WMSAPIInfo");
if (JsonData.Count <= 0)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
}
DataSet TableNameds = new DataSet();
DataTable schemaTable = new DataTable();
DataTable dtable = new DataTable();
DataTable wdt0 = new DataTable();
DataTable wdt1 = new DataTable();
DataTable wdt = new DataTable();
DataTable logdt0 = new DataTable();
DataTable logdt1 = new DataTable();
DataTable logdt = new DataTable();
DataTable tableNames = new DataTable();
DataTable newDataTable = new DataTable();
string result = string.Empty;
string LOTNO = string.Empty;
string IsDx = string.Empty;
string dsql = string.Empty;
string cdsql = string.Empty;
string wsql = string.Empty;
string logsql = string.Empty;
string TransCode = string.Empty;
string Status = string.Empty;
string TransSequence = string.Empty;
string TableName = string.Empty;
string TotalQuantity = string.Empty;
string TransType = string.Empty;
string TransTypeOriginal = string.Empty;//记录不合格入库条码的原条码的类型
string Identification = Guid.NewGuid().ToString();
string BusinessCode = string.Empty;
string UserCode = string.Empty;
//查询数据
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
try
{
foreach (var item in JsonData)
{
TransType = item.TransType;
if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
{
throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
}
string WHTransType = "2";
UserCode = item.User;
#region 生产入库
if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
{
BusinessCode = TransTypeEnum.ManufactureReceiveDoc.GetDescription();
dsql = @"select MoCode,Sequence,RCVQuantity from ICSMO where 1<>1";
TableName = "ICSMO";
TransCode = "MoCode";
TransSequence = "Sequence";
TotalQuantity = "RCVQuantity";
Status = "ERPStatus";
}
else if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
{
BusinessCode = TransTypeEnum.PurchaseReceiveDoc.GetDescription();
dsql = @"select PoCode,Sequence,InQuantity AS RCVQuantity from ICSPurchaseOrder where 1<>1";
TableName = "ICSPurchaseOrder";
TransCode = "PoCode";
TransSequence = "Sequence";
TotalQuantity = "RCVQuantity";
Status = "Status";
}
#endregion
#region 鑫隽渊委外入库单入库
else if (TransType == TransTypeEnum.OutsourcingReceiveRevXJYDoc.GetDescription())
{
BusinessCode = TransTypeEnum.OutsourcingReceiveRevXJYDoc.GetDescription();
dsql = @"select RCVCode,Sequence,RcvQuantity AS RCVQuantity from ICSOutsourcingReceive where 1<>1";
TableName = "ICSOutsourcingReceive";
TransCode = "RCVCode";
TransSequence = "Sequence";
TotalQuantity = "RCVQuantity";
Status = "Status";
}
#endregion
else
{
throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
}
#region 单据信息预加载
//单据
schemaTable = new DataTable();
using (SqlCommand command = new SqlCommand(dsql, conn, sqlTran))
{
using (SqlDataAdapter adapter = new SqlDataAdapter(command))
{
adapter.FillSchema(schemaTable, SchemaType.Source);
}
}
dtable = schemaTable.Copy();
//TableNameds.Tables.Add(dtable);
// 1. 按 TransCode 分组,并计算每组 Quantity 的总和
var transCodeGroups = item.detail
.GroupBy(d => new { d.TransCode, d.TransSequence }) // 按 TransCode 和 TransSequence 分组
.Select(g => new
{
TransCode = g.Key.TransCode, // 分组键(TransCode)
TransSequence = g.Key.TransSequence, // 分组键(TransSequence)
TotalQuantity = g.Sum(x => decimal.Parse(x.Quantity)) // 汇总 Quantity
});
// 2. 将分组结果添加到 DataTable
foreach (var group in transCodeGroups)
{
DataRow row = dtable.NewRow();
row[TransCode] = group.TransCode;
row[TransSequence] = group.TransSequence;
row[TotalQuantity] = group.TotalQuantity;
dtable.Rows.Add(row);
}
//校验工单状态,关闭状态直接回滚
for (int i = 0; i < dtable.Rows.Count; i++)
{
dsql = @"SELECT c.{5} AS ERPStatus,c.{4} from {3} c
WHERE c.{4}='{0}' AND c.Sequence='{1}' and c.workpoint='{2}'";
dsql = string.Format(dsql, dtable.Rows[i][TransCode], dtable.Rows[i]["Sequence"], item.WorkPoint, TableName, TransCode, Status);
DataTable dataTable = DBHelper.SQlReturnData(dsql, cmd);
if (dataTable == null || dataTable.Rows.Count <= 0)
{
// 使用原始查询值而不是尝试访问空的数据表
throw new Exception($"订单: {dtable.Rows[i][TransCode]} 不存在!");
}
if (dataTable.Rows[0]["ERPStatus"].ToString() == "3")
{
throw new Exception("订单:" + dataTable.Rows[0][TransCode].ToString() + "已关闭!");
}
}
#endregion
//库存
schemaTable = new DataTable();
wsql = @"select * from ICSWareHouseLotInfo where 1<>1";
using (SqlCommand command = new SqlCommand(wsql, conn, sqlTran))
{
using (SqlDataAdapter adapter = new SqlDataAdapter(command))
{
adapter.FillSchema(schemaTable, SchemaType.Source);
}
}
wdt = schemaTable.Copy();
//TableNameds.Tables.Add(wdt);
//日志
schemaTable = new DataTable();
logsql = @"select * from ICSWareHouseLotInfoLog where 1<>1";
using (SqlCommand command = new SqlCommand(logsql, conn, sqlTran))
{
using (SqlDataAdapter adapter = new SqlDataAdapter(command))
{
adapter.FillSchema(schemaTable, SchemaType.Source);
}
}
logdt = schemaTable.Copy();
//TableNameds.Tables.Add(logdt);
foreach (var itemInfo in item.detail)
{
if (LOTNO != "")
{
LOTNO += ","; // 如果不是第一个元素,先加逗号
}
LOTNO += "'" + itemInfo.LotNo + "'"; // 每个元素用单引号包裹
}
wsql = @"select CAST(NEWID() AS NVARCHAR(50)) as ID,a.LotNo AS LotNo,'' AS WarehouseCode,'' AS LocationCode,a.InvCode AS InvCode,
CAST(0 AS decimal(18,6)) AS Quantity,SYSDATETIME() AS InDate,0 AS LockQuantity,0 as Freeze,0 as Inspect,f.F_Account AS MUSER,f.F_RealName As MUSERName,SYSDATETIME() AS MTIME,
a.WorkPoint AS WorkPoint FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo in ({0}) AND a.WorkPoint='{1}'";
wsql = string.Format(wsql, LOTNO, item.WorkPoint, item.User);
wdt0 = DBHelper.SQlReturnData(wsql, cmd);
wdt0.TableName = "ICSWareHouseLotInfo";
logsql = @"select CAST(NEWID() AS NVARCHAR(50)) as ID,'{3}' as Identification,b.TransID AS TransID,b.TransCode AS TransCode,b.TransSequence as TransSequence,
a.LotNo as LotNo,a.InvCode as InvCode,'' as FromWarehouseCode,'' as FromLocationCode,'' as ToWarehouseCode,'' as ToLocationCode,
CAST(0 AS decimal(18,6)) AS Quantity,'' AS Memo,0 AS Lock,'{4}' as TransType,'{5}' as BusinessCode,0 as ERPUpload,
'' as ERPID,'' as ERPDetailID, '' as ERPCode,'' as ERPSequence,
'' AS LogID,'' as MergeID,f.F_Account as MUSER,f.F_RealName as MUSERName,SYSDATETIME() AS MTIME,a.WorkPoint as WorkPoint
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
WHERE a.LotNo in ({0}) AND a.WorkPoint='{1}'";
logsql = string.Format(logsql, LOTNO, item.WorkPoint, item.User, Identification, WHTransType, BusinessCode
);
logdt0 = DBHelper.SQlReturnData(logsql, cmd);
logdt0.TableName = "ICSWareHouseLotInfoLog";
foreach (DataRow row in wdt0.Rows)
{
decimal quantity = Convert.ToDecimal(item.detail.Find(a => a.LotNo == row["LotNo"].ToString()).Quantity);
row["Quantity"] = quantity;
//row["Quantity"] = item.detail.Find(a => a.LotNo == row["LotNo"].ToString()).Quantity;
row["LocationCode"] = item.detail.Find(a => a.LotNo == row["LotNo"].ToString()).LocationCode;
row["WarehouseCode"] = item.detail.Find(a => a.LotNo == row["LotNo"].ToString()).WarehouseCode;
}
foreach (DataRow row in logdt0.Rows)
{
decimal quantity = Convert.ToDecimal(item.detail.Find(a => a.LotNo == row["LotNo"].ToString()).Quantity);
row["Quantity"] = quantity;
//row["Quantity"] = item.detail.Find(a => a.LotNo == row["LotNo"].ToString()).Quantity;
row["ToLocationCode"] = item.detail.Find(a => a.LotNo == row["LotNo"].ToString()).LocationCode;
row["ToWarehouseCode"] = item.detail.Find(a => a.LotNo == row["LotNo"].ToString()).WarehouseCode;
}
TableNameds.Tables.Add(wdt0);
TableNameds.Tables.Add(logdt0);
}
StringBuilder transCodesb = new StringBuilder();
for (int i = 0; i < dtable.Rows.Count; i++)
{
if (TransCode.Length > 0)
{
transCodesb.Append(",");
}
transCodesb = transCodesb.Append("'").Append(dtable.Rows[i][TransCode].ToString()).Append("'");
}
string orderChkSql = string.Format("SELECT {2} AS TransCode,Sequence,Quantity-ISNULL(InQuantity, 0) AS Quantity FROM {1} c WHERE c.{2} = '{0}'",
transCodesb.ToString(), TableName, TransCode);
DataTable orderDt = DBHelper.SQlReturnData(orderChkSql);
//回写逻辑拼接
StringBuilder sqlBuilder = new StringBuilder();
for (int i = 0; i < dtable.Rows.Count; i++)
{
bool flag = true;
string currentMoCode = dtable.Rows[i][TransCode].ToString();
string currentSequence = dtable.Rows[i]["Sequence"].ToString();
string rcvQuantity = dtable.Rows[i]["RCVQuantity"].ToString();
if (TransType == TransTypeEnum.OutsourcingReceiveRevXJYDoc.GetDescription())
{
flag = false;
for (int j = 0; j < orderDt.Rows.Count; j++)
{
if (orderDt.Rows[j]["TransCode"].ToString() == currentMoCode && orderDt.Rows[j]["Sequence"].ToString() == currentSequence)
{
if (Convert.ToDecimal(orderDt.Rows[j]["Quantity"]) == Convert.ToDecimal(rcvQuantity))
{
flag = true;
break;
}
}
}
}
if (flag)
{
sqlBuilder.AppendFormat(@"
UPDATE c SET InQuantity = ISNULL(InQuantity, 0) + {2}
FROM {3} c
WHERE c.{4} = '{0}' AND c.Sequence = '{1}';
IF EXISTS (
SELECT 1
FROM {3} c
WHERE c.{4} = '{0}' AND c.Sequence = '{1}'
AND c.Quantity < c.InQuantity
)
BEGIN
RAISERROR('{5}', 16, 1);
END",
currentMoCode,
currentSequence,
rcvQuantity,
TableName,
TransCode,
language.GetNameByCode("源头单据:" + currentMoCode + "已经入库数量不能大于订单数量!"));
}
}
cdsql = sqlBuilder.ToString();
}
catch (Exception ex)
{
//if (cmd.Transaction != null)
// cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
//写入WMS并调用ERP
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
try
{
BatchUpdate(conn, sqlTran, "", "", cdsql, TableNameds);
//上传ERP
if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
{
log.Debug("ERP接口");
if (TransTypeOriginal != string.Empty)
{
TransType = TransTypeOriginal;
}
//采购入库
if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
{
if (DBHelper.IsU9())
{ ICSPurchaseService.CreatePOArriveERP(TransType, Identification, cmd, language, BusinessCode, "RCV01"); }
else
{
//log.Debug("2");
ICSPurchaseService.PurchaseReceiveDocERP(TransType, Identification, cmd, language, BusinessCode, "");
}
}
//采购入库-入库单
else if (TransType == TransTypeEnum.PurchaseReceiveRevDoc.GetDescription())
{
ICSPurchaseService.PurchaseReceiveRevDocERP(TransType, Identification, cmd, language, BusinessCode, UserCode);
}
//审核的到货单
else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
dtable = ICSPurchaseService.DeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode, "");
//采购拒收
else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
ICSPurchaseService.PurchaseRejectDocInERP(TransType, Identification, cmd, language, BusinessCode);
//审核的委外到货单
else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
ICSOutsourcingService.ODeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode);
//委外拒收
else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
ICSOutsourcingService.OutsourcingRejectDocInERP(TransType, Identification, cmd, language, BusinessCode);
//委外退料
else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
ICSOutsourcingService.OutsourcingIssueDoNegativeERP(TransType, Identification, cmd, language, BusinessCode);
//委外入库
else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
{
if (DBHelper.IsU9())
{ ICSOutsourcingService.CreateOOArriveERP(TransType, Identification, cmd, language, BusinessCode, "RCV11"); }
else
{
ICSOutsourcingService.OutsourcingReceiveDocERP(TransType, Identification, cmd, language, BusinessCode);
}
}
//委外入库
else if (TransType == TransTypeEnum.OutsourcingReceiveRevDoc.GetDescription())
{
ICSOutsourcingService.OutsourcingReceiveRcvDocERP(TransType, Identification, cmd, language, BusinessCode, UserCode);
}
else if (TransType == TransTypeEnum.OutsourcingReceiveRevXJYDoc.GetDescription())
{
ICSOutsourcingService.OutsourcingReceiveRcvXJYDocERP(TransType, Identification, cmd, language, BusinessCode, UserCode);
}
//生产退料
else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
|| TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
|| TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
{
if (DBHelper.IsDX())
{
ICSManufactureService.DXMOIssueDocNegativeERP(TransType, Identification, cmd, language, BusinessCode, IsDx);
}
else
{
ICSManufactureService.MOIssueDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
}
}
//生产入库
else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
ICSManufactureService.ManufactureReceiveDocERP(TransType, Identification, cmd, language, BusinessCode, "");
//副产品入库
else if (TransType == TransTypeEnum.MOStockINByProduct.GetDescription())
ICSManufactureService.MOStockINByProductDocERP(TransType, Identification, cmd, language, BusinessCode);
//委外副产品入库
else if (TransType == TransTypeEnum.OOStockINByProduct.GetDescription())
ICSManufactureService.OOStockINByProductDocERP(TransType, Identification, cmd, language, BusinessCode);
//无源头副产品入库
else if (TransType == TransTypeEnum.MOStockINByProductNoTrans.GetDescription())
ICSManufactureService.MOStockINByProductNoTransDocERP(TransType, Identification, cmd, language, BusinessCode);
//开立的生产入库单
else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
dtable = ICSManufactureService.ManufactureReceiveERP(TransType, Identification, cmd, language, BusinessCode);
//MES产成品入库单
else if (TransType == TransTypeEnum.ManufactureMESReceive.GetDescription())
ICSManufactureService.ManufactureMESReceiveERP(TransType, Identification, JsonData[0].TransCode, cmd, language, BusinessCode);
//返工工单
else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
ICSManufactureService.ReWorkReceiveMoERP(TransType, Identification, cmd, language, BusinessCode);
//销售退货
else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
{
if (DBHelper.IsU9())
ICSSalesService.U9SalesShipmentDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
else
ICSSalesService.SalesShipmentDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
}
//红字销售出库单
else if (TransType == TransTypeEnum.SalesShipmentOutRedDoc.GetDescription() || TransType == TransTypeEnum.SalesShipmentOutRedYuanDoc.GetDescription())
{
ICSSalesService.SalesShipmentDocOutRedERP(TransType, Identification, cmd, language, BusinessCode);
}
//两步调入
else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
ICSWareHouseService.TwoStepTransferDocInERP(TransType, Identification, cmd, language, BusinessCode);
//两步调入
else if (TransType == TransTypeEnum.RTTwoStepTransferDocIn.GetDescription())
ICSWareHouseService.RTTwoStepTransferDocInERP(TransType, Identification, cmd, language, BusinessCode);
//销售退货-原条码
else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
ICSSalesService.SalesReturnBackInERP(TransType, Identification, cmd, language, BusinessCode);
//其他入库
else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
{
if (DBHelper.IsU9())
ICSWareHouseService.CreateOtherInDocERP(TransType, Identification, cmd, language, BusinessCode);
else
ICSWareHouseService.OtherInDocERP(TransType, Identification, cmd, language, BusinessCode);
}
//拆卸单
if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
ICSWareHouseService.DisassemblyDocERP(TransType, Identification, cmd, language, BusinessCode);
//归还
else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
ICSWareHouseService.ReturnDocERP(TransType, Identification, cmd, language, BusinessCode);
}
if (TransType == TransTypeEnum.DeliveryNotice.GetDescription() || TransType == TransTypeEnum.ManufactureReceive.GetDescription())
{
cmd.Transaction.Commit();
return dtable;
}
else
{
DataTable table = GetData(Identification, 1, cmd);
cmd.Transaction.Commit();
return table;
}
}
catch (Exception ex)
{
if (cmd.Transaction != null)
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
public static void BatchUpdate(SqlConnection conn, SqlTransaction transaction,
string crateTemplateSql, string tmpTable, string updateCommandSql, DataSet dset)
{
try
{
if (crateTemplateSql != "")
{
using (SqlCommand command = new SqlCommand(crateTemplateSql, conn, transaction))
{
command.ExecuteNonQuery();
}
}
foreach (DataTable dt in dset.Tables)
{
// 使用 SqlBulkCopy 插入更改到临时表
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(conn, SqlBulkCopyOptions.Default, transaction))
{
bulkCopy.DestinationTableName = dt.TableName;
bulkCopy.WriteToServer(dt);
bulkCopy.Close();
}
}
// 使用 SQL 更新主表
if (!string.IsNullOrEmpty(updateCommandSql))
{
using (SqlCommand command = new SqlCommand(updateCommandSql, conn, transaction))
{
command.ExecuteNonQuery();
}
}
// 注意:这里不再调用Commit,由外部调用者决定何时提交
}
catch (Exception)
{
throw;
}
}
///
/// 上架(奥美专用)
/// BusinessCode,TransType 两个类型
///
///
public static DataTable LOTStockCreateAM(List JsonData)
{
var language = LanguageHelper.GetName("WMSAPIInfo");
if (JsonData.Count <= 0)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
}
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
string BusinessCode = string.Empty;
try
{
string TransType = string.Empty;
DataTable dtable = new DataTable();
string TransTypeOriginal = string.Empty;//记录不合格入库条码的原条码的类型
string Identification = Guid.NewGuid().ToString();
foreach (var item in JsonData)
{
TransType = item.TransType;
if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
{
throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
}
string WHTransType = "2";
foreach (var itemInfo in item.detail)
{
#region 两步调入
if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
{
//更新源头单据数量
ICSWareHouseService.TwoStepTransferDocIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
//入库
ICSWareHouseLotInfoService.WareHouseLotInfoTwoStepTransferDocIn(Identification, itemInfo.TransCode, itemInfo.TransSequence,
itemInfo.WarehouseCode, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity, item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocIn.GetDescription(), cmd, language);
}
#endregion
#region 销售退货-原条码
else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
{
//更新源头单据数量
ICSSalesService.SalesReturnBackIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
//入库
BusinessCode = TransTypeEnum.SalesReturnBack.GetDescription();
//入库
ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode, "", "", itemInfo.InvCode);
//更新日志表源头单据信息
string sql = @"UPDATE ICSWareHouseLotInfoLog SET TransCode='{3}',TransSequence='{4}'
WHERE LotNo='{0}' AND WorkPoint='{1}' AND Identification='{2}' AND TransCode='' AND TransSequence=''";
sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, Identification, itemInfo.TransCode, itemInfo.TransSequence);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
}
}
#endregion
else
{
#region 采购入库
if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
{
//更新源头单据数量
ICSPurchaseService.PurchaseReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.PurchaseReceiveDoc.GetDescription();
}
#endregion
#region 审核的到货单
else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
{
//更新源头单据数量
ICSPurchaseService.DeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription();
}
#endregion
#region 采购拒收
else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
{
//更新源头单据数量
ICSPurchaseService.PurchaseRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.PurchaseRejectDoc.GetDescription();
}
#endregion
#region 审核的委外到货单
else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
{
//更新源头单据数量
ICSOutsourcingService.ODeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.ODeliveryNotice.GetDescription();
}
#endregion
#region 委外拒收
else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
{
//更新源头单据数量
ICSOutsourcingService.OutsourcingRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.OutsourcingRejectDoc.GetDescription();
}
#endregion
#region 委外退料
else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
{
//更新源头单据数量
ICSOutsourcingService.OutsourcingIssueDoNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, itemInfo.TransCode, itemInfo.TransSequence, cmd, language);
BusinessCode = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription();
}
#endregion
#region 返工工单
else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
{
//更新源头单据数量
ICSManufactureService.ReWorkReceiveMo(itemInfo.LotNo, itemInfo.Quantity, itemInfo.WarehouseCode, itemInfo.LocationCode, item.WorkPoint, item.User, TransTypeEnum.ReWorkReceiveMo.GetDescription(), cmd, language);
BusinessCode = TransTypeEnum.ReWorkReceiveMo.GetDescription();
}
#endregion
#region 委外入库
else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
{
//更新源头单据数量
ICSOutsourcingService.OutsourcingReceiveAMDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.OutsourcingReceiveDoc.GetDescription();
}
#endregion
#region 生产退料
else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
|| TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
|| TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
{
log.Debug("生产退料1" + TransTypeEnum.MOIssueDocNegative.GetDescription());
log.Debug("生产退料2" + TransTypeEnum.MOIssueDocNegativeApply.GetDescription());
log.Debug("生产退料3" + TransTypeEnum.MOIssueDocNegativeIssue.GetDescription());
log.Debug("生产退料4" + TransType);
//更新源头单据数量
ICSManufactureService.AMMOIssueDocNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, itemInfo.TransCode, itemInfo.TransSequence, cmd, language);
BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription();
log.Debug("生产退料5");
}
#endregion
#region 生产入库
else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
{
log.Debug("生产入库" + TransType);
//更新源头单据数量
ICSManufactureService.ManufactureReceiveDocAM(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.ManufactureReceiveDoc.GetDescription();
}
#endregion
#region 开立的生产入库单
else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
{
//更新源头单据数量
ICSManufactureService.ManufactureReceive(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.ManufactureReceive.GetDescription();
}
#endregion
#region 销售退货
else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
{
//更新源头单据数量
ICSSalesService.SalesShipmentDocNegative(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.SalesShipmentDocNegative.GetDescription();
}
#endregion
#region 其他入库
else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
{
//更新源头单据数量
ICSWareHouseService.OtherInDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.OtherInDoc.GetDescription();
}
#endregion
#region 拆卸单
else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
{
ICSWareHouseService.DisassemblyDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
WHTransType = "11";
BusinessCode = TransTypeEnum.DisassemblyDoc.GetDescription();
}
#endregion
#region 归还
else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
{
//更新源头单据数量
ICSWareHouseService.ReturnDoc(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.LogID, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.ReturnDoc.GetDescription();
}
#endregion
#region 不合格入库
else if (TransType == TransTypeEnum.UnqualifiedIN.GetDescription())
{
string sql = @"SELECT b.Type FROM ICSInventoryLot a
LEFT JOIN ICSInventoryLot b ON a.EATTRIBUTE1=b.LotNo AND b.WorkPoint=a.WorkPoint
WHERE a.LotNo='{0}' AND a.Type='17' AND a.WorkPoint='{1}'";
sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count != 0)
{
TransTypeOriginal = dt.Rows[0]["Type"].ToString();
}
if (TransTypeOriginal == string.Empty)
{
//throw new Exception(language.GetNameByCode(""));
throw new Exception("未查询到条码" + itemInfo.LotNo + "的原条码");
}
#region 审核的到货单
else if (TransTypeOriginal == "7")
{
//更新源头单据数量
ICSPurchaseService.DeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
//BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription();
TransTypeOriginal = TransTypeEnum.DeliveryNotice.GetDescription();
}
#endregion
#region 审核的委外到货单
else if (TransTypeOriginal == "8")
{
//更新源头单据数量
ICSOutsourcingService.ODeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
//BusinessCode = TransTypeEnum.ODeliveryNotice.GetDescription();
TransTypeOriginal = TransTypeEnum.ODeliveryNotice.GetDescription();
}
#endregion
#region 委外退料
else if (TransTypeOriginal == "2"
|| TransTypeOriginal == "14"
|| TransTypeOriginal == "15")
{
//更新源头单据数量
ICSOutsourcingService.OutsourcingIssueDoNegative(TransTypeOriginal, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, itemInfo.TransCode, itemInfo.TransSequence, cmd, language);
//BusinessCode = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription();
TransTypeOriginal = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription();
}
#endregion
#region 生产退料
else if (TransTypeOriginal == "1"
|| TransTypeOriginal == "12"
|| TransTypeOriginal == "13")
{
log.Debug("生产退料1" + TransTypeEnum.MOIssueDocNegative.GetDescription());
log.Debug("生产退料2" + TransTypeEnum.MOIssueDocNegativeApply.GetDescription());
log.Debug("生产退料3" + TransTypeEnum.MOIssueDocNegativeIssue.GetDescription());
log.Debug("生产退料4" + TransTypeOriginal);
//更新源头单据数量
ICSManufactureService.MOIssueDocNegative(TransTypeOriginal, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
//BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription();
TransTypeOriginal = TransTypeEnum.MOIssueDocNegative.GetDescription();
}
#endregion
#region 生产入库
else if (TransTypeOriginal == "3")
{
log.Debug("生产入库" + TransTypeOriginal);
//更新源头单据数量
ICSManufactureService.ManufactureReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
//BusinessCode = TransTypeEnum.ManufactureReceiveDoc.GetDescription();
TransTypeOriginal = TransTypeEnum.ManufactureReceiveDoc.GetDescription();
}
#endregion
#region 销售退货
else if (TransTypeOriginal == "4")
{
//更新源头单据数量
ICSSalesService.SalesShipmentDocNegative(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
//BusinessCode = TransTypeEnum.SalesShipmentDocNegative.GetDescription();
TransTypeOriginal = TransTypeEnum.SalesShipmentDocNegative.GetDescription();
}
#endregion
#region 其他入库
else if (TransTypeOriginal == "5")
{
//更新源头单据数量
ICSWareHouseService.OtherInDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
//BusinessCode = TransTypeEnum.OtherInDoc.GetDescription();
TransTypeOriginal = TransTypeEnum.OtherInDoc.GetDescription();
}
#endregion
BusinessCode = TransTypeEnum.UnqualifiedIN.GetDescription();
}
#endregion
#region 联副产品入库
else if (TransType == TransTypeEnum.MOStockINByProduct.GetDescription())
{
log.Debug("联副产品入库" + TransType);
//更新源头单据数量
ICSManufactureService.MOStockINByProductAMDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
BusinessCode = TransTypeEnum.MOStockINByProduct.GetDescription();
}
#endregion
else
{
throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
}
//入库
ICSWareHouseLotInfoService.WareHouseLotInfoUpAM(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode, itemInfo.TransCode, itemInfo.TransSequence);
}
}
#region 拆卸单
if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
{
//更新套件锁定数量
ICSWareHouseService.DisassemblyDoc(Identification, cmd, language);
}
#endregion}
}
//上传ERP
if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
{
if (TransTypeOriginal != string.Empty)
{
TransType = TransTypeOriginal;
}
//采购入库
if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
ICSPurchaseService.PurchaseReceiveDocERP(TransType, Identification, cmd, language, BusinessCode, "");
//审核的到货单
else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
dtable = ICSPurchaseService.DeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode, "");
//采购拒收
else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
ICSPurchaseService.PurchaseRejectDocInERP(TransType, Identification, cmd, language, BusinessCode);
//审核的委外到货单
else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
ICSOutsourcingService.ODeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode);
//委外拒收
else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
ICSOutsourcingService.OutsourcingRejectDocInERP(TransType, Identification, cmd, language, BusinessCode);
//委外退料
else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
|| TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
ICSOutsourcingService.OutsourcingIssueDoNegativeERP(TransType, Identification, cmd, language, BusinessCode);
//委外入库
else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
ICSOutsourcingService.OutsourcingReceiveDocERP(TransType, Identification, cmd, language, BusinessCode);
//生产退料
else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
|| TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
|| TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
ICSManufactureService.MOIssueDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
//生产入库
else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
ICSManufactureService.ManufactureReceiveDocERP(TransType, Identification, cmd, language, BusinessCode, "");
//副产品入库
else if (TransType == TransTypeEnum.MOStockINByProduct.GetDescription())
ICSManufactureService.MOStockINByProductDocERP(TransType, Identification, cmd, language, BusinessCode);
//委外副产品入库
else if (TransType == TransTypeEnum.OOStockINByProduct.GetDescription())
ICSManufactureService.OOStockINByProductDocERP(TransType, Identification, cmd, language, BusinessCode);
//开立的生产入库单
else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
dtable = ICSManufactureService.ManufactureReceiveERP(TransType, Identification, cmd, language, BusinessCode);
//返工工单
else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
ICSManufactureService.ReWorkReceiveMoERP(TransType, Identification, cmd, language, BusinessCode);
//销售退货
else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
ICSSalesService.SalesShipmentDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
//两步调入
else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
ICSWareHouseService.TwoStepTransferDocInERP(TransType, Identification, cmd, language, BusinessCode);
//销售退货-原条码
else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
ICSSalesService.SalesReturnBackInERP(TransType, Identification, cmd, language, BusinessCode);
//其他入库
else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
ICSWareHouseService.OtherInDocERP(TransType, Identification, cmd, language, BusinessCode);
//拆卸单
if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
ICSWareHouseService.DisassemblyDocERP(TransType, Identification, cmd, language, BusinessCode);
//归还
else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
ICSWareHouseService.ReturnDocERP(TransType, Identification, cmd, language, BusinessCode);
}
if (TransType == TransTypeEnum.DeliveryNotice.GetDescription() || TransType == TransTypeEnum.ManufactureReceive.GetDescription())
{
cmd.Transaction.Commit();
return dtable;
}
else
{
DataTable table = GetData(Identification, 1, cmd);
cmd.Transaction.Commit();
return table;
}
}
catch (Exception ex)
{
if (cmd.Transaction != null)
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
///
///
///
///
///
public static DataTable GetPickTable(string ID, string Type, string WorkPoint, SqlCommand cmd)
{
ID = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(',');
//string Code = SqlHelper.GetItemsDetailEnabledMark("MtimeControl");
string sql = @"EXEC ICSPicking '''{0}''','{1}','0','{2}'";
sql = string.Format(sql, ID, Type, WorkPoint);
DataSet dataset = DBHelper.SQlReturnDataSet(sql, cmd);//sql 查询
if (dataset.Tables[0].Rows.Count == 0)
return null;
DataTable table = dataset.Tables[0];
try
{
DataRow[] dss = table.Select("LotNO=''");
foreach (var item in dss)
{
DataRow[] dsss = table.Select("Code='" + item["Code"].ToString() + "' and Sequence='" + item["Sequence"].ToString() + "' and LotNO <> '' ");
if (dsss != null && dsss.Length > 0)
{
table.Rows.Remove(item);
}
}
var result = DBHelper.ConvertCellToString(table);
return result;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
public static DataTable LOTStockDownByCode(List JsonData)
{
string msg = string.Empty;
string Inputstr = string.Empty;//拣料结果
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
try
{
foreach (var item in JsonData)
{
DataTable dateTable = null;//2--东辉辅料领料
DataRow[] dateRows = null;
decimal ToltalCount = 0;
string ZDsql;
DataTable dtdd = null;
var dt = new DataTable();
string WorkPoint = item.WorkPoint;
string UserCode = item.User;
List lOTStockModels = new List();
string ID = item.TransCode;
//单据先进行拣料
if (item.TransType == TransTypeEnum.MOApply.GetDescription())
{
dateTable = GetPickTable(ID, "2", WorkPoint, cmd);//2--东辉辅料领料
dateRows = dateTable?.Select($@"LotNo <> '' And LotNo is not null");
ToltalCount = 0.0M;
ZDsql = $@" SELECT Sum(Quantity) AS Quantity FROM ICSMOApply WHERE ApplyCode in('{ID}') and WorkPoint='{WorkPoint}' ";
dt = DBHelper.SQlReturnData(ZDsql, cmd);
ZDsql = $@" SELECT ApplyCode as Code,ID, Sequence FROM ICSMOApply WHERE ApplyCode in('{ID}') and WorkPoint='{WorkPoint}' ";
dtdd = DBHelper.SQlReturnData(ZDsql, cmd);
}
if (item.TransType == TransTypeEnum.MOIssueDoc.GetDescription())
{
dateTable = GetPickTable(ID, "1", WorkPoint, cmd);//2--东辉工单备料
dateRows = dateTable?.Select($@"LotNo <> '' And LotNo is not null");
ToltalCount = 0.0M;
ZDsql = $@" SELECT Sum(a.Quantity) AS Quantity FROM ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
WHERE b.MOCode in('{ID}') and b.WorkPoint='{WorkPoint}' ";
dt = DBHelper.SQlReturnData(ZDsql, cmd);
ZDsql = $@" if not exists(SELECT a.F_itemCode
FROM Sys_SRM_ItemsDetail a
INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
WHERE b.F_EnCode='MO_Warehouse' AND a.F_define1=(select top 1 Eattribute3 from ICSMO where mocode = '{ID}')and a.F_enabledMark='1')
begin
RAISERROR('此工单类型不能使用一键出库功能!',16,1);
RETURN
end
SELECT b.MOCode as Code,a.ID, b.Sequence+'~'+a.Sequence as Sequence,b.Eattribute3 FROM ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
WHERE b.MOCode in('{ID}') and b.WorkPoint='{WorkPoint}' ";
dtdd = DBHelper.SQlReturnData(ZDsql, cmd);
}
if (dateRows == null || dateRows.Length <= 0)
{
throw new Exception("库存不足,请先检查库存");//"传送数据为空!"
}
else
{
string docCode = string.Empty;
string docCodeAfter = string.Empty;
LOTStockModel lOTStockModel = null;
// 使用 LINQ 根据 Code 字段对 DataRow[] 进行分组
var groups = dateRows.Cast().GroupBy(row => new
{
Code = row.Field("Code"),
Sequence = row.Field("Sequence"),
iQuantity = row.Field("iQuantity")
});
foreach (var group in groups)
{
var firstRow = group.First();
var code = firstRow["Code"];
decimal count = 0.0M;
DataRow[] idrow = dtdd?.Select($@"Code = '" + firstRow["Code"].ToString() + "' And Sequence ='" + firstRow["Sequence"].ToString() + "'");
lOTStockModel = new LOTStockModel
{
TransCode = firstRow["Code"].ToString(),
TransSequence = firstRow["Sequence"].ToString(),
Amount = "0",
User = UserCode,
MTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
WorkPoint = WorkPoint,
detail = new List(),
TransType = item.TransType,
TransID = idrow[0]["ID"].ToString()
};
foreach (var row in group)
{
count += Convert.ToDecimal(row["QTY"]);
LOTStockModelList lOTStockModelList = new LOTStockModelList
{
TransSequence = firstRow["Sequence"].ToString(),
CurrentQuantity = row["QTY"].ToString(),
LotNo = row["LotNo"].ToString(),
CurrentAmount = "0",
Sequence = row["Sequence"].ToString(),
WarehouseCode = row["WarehouseCode"].ToString(),
LocationCode = row["LocationCode"].ToString()
};
lOTStockModel.detail.Add(lOTStockModelList);
}
lOTStockModel.Quantity = count.ToString();
lOTStockModels.Add(lOTStockModel);
ToltalCount += count;
}
if (ToltalCount != Convert.ToDecimal(dt.Rows[0]["Quantity"]))
{
throw new Exception("库存不足,请先检查库存");//"传送数据为空!"
}
Inputstr = JsonConvert.SerializeObject(lOTStockModels);
conn.Close();
conn.Dispose();
}
}
return LOTStockDownCreate(JsonConvert.DeserializeObject>(Inputstr));//pda只能调用一张单据 pda传参一张单据
}
catch (Exception ex)
{
if (cmd.Transaction != null)
cmd.Transaction.Rollback();
throw ex;
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
public static DataTable BBLOTStockDownByCode(List JsonData)
{
string msg = string.Empty;
string Inputstr = string.Empty;//拣料结果
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
try
{
foreach (var item in JsonData)
{
DataTable dateTable = null;
DataRow[] dateRows = null;
decimal ToltalCount = 0;
string ZDsql;
DataTable dtdd = null;
var dt = new DataTable();
var dt2 = new DataTable();
string lotqty = string.Empty;
string WorkPoint = item.WorkPoint;
string UserCode = item.User;
List lOTStockModels = new List();
string ID = item.TransCode;
//单据先进行拣料
if (item.TransType == TransTypeEnum.OOIssue.GetDescription())
{
dateTable = GetPickTable(ID, "6", WorkPoint, cmd);
dateRows = dateTable?.Select($@"LotNo <> '' And LotNo is not null");
ToltalCount = 0.0M;
ZDsql = $@" SELECT SUM(Quantity-IssueQuantity) AS Quantity,InvCode FROM ICSOIssue WHERE IssueCode in('{ID}') and WorkPoint='{WorkPoint}' GROUP BY InvCode";
dt2 = DBHelper.SQlReturnData(ZDsql, cmd);
ZDsql = $@" SELECT Sum(Quantity) AS Quantity FROM ICSOIssue WHERE IssueCode in('{ID}') and WorkPoint='{WorkPoint}' ";
dt = DBHelper.SQlReturnData(ZDsql, cmd);
ZDsql = $@" SELECT IssueCode as Code,ID, Sequence FROM ICSOIssue WHERE IssueCode in('{ID}') and WorkPoint='{WorkPoint}' ";
dtdd = DBHelper.SQlReturnData(ZDsql, cmd);
}
if (dateRows == null || dateRows.Length <= 0)
{
throw new Exception("库存不足,请先检查库存");//"传送数据为空!"
}
else
{
string docCode = string.Empty;
string docCodeAfter = string.Empty;
LOTStockModel lOTStockModel = null;
// 使用 LINQ 根据 Code 字段对 DataRow[] 进行分组
var groups = dateRows.Cast().GroupBy(row => new
{
Code = row.Field("Code"),
Sequence = row.Field("Sequence"),
InvCode = row.Field("InvCode"),
iQuantity = row.Field("iQuantity")
});
foreach (var group in groups)
{
var firstRow = group.First();
var code = firstRow["Code"];
decimal count = 0.0M;
DataRow[] idrow = dtdd?.Select($@"Code = '" + firstRow["Code"].ToString() + "' And Sequence ='" + firstRow["Sequence"].ToString() + "'");
lOTStockModel = new LOTStockModel
{
TransCode = firstRow["Code"].ToString(),
TransSequence = firstRow["Sequence"].ToString(),
Amount = "0",
User = UserCode,
InvCode = firstRow["InvCode"].ToString(),
MTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
WorkPoint = WorkPoint,
detail = new List(),
TransType = item.TransType,
TransID = idrow[0]["ID"].ToString()
};
foreach (var row in group)
{
lotqty += "," + row["QTY"] + "";
count += Convert.ToDecimal(row["QTY"]);
LOTStockModelList lOTStockModelList = new LOTStockModelList
{
TransSequence = firstRow["Sequence"].ToString(),
CurrentQuantity = row["QTY"].ToString(),
LotNo = row["LotNo"].ToString(),
CurrentAmount = "0",
Sequence = row["Sequence"].ToString(),
WarehouseCode = row["WarehouseCode"].ToString(),
LocationCode = row["LocationCode"].ToString()
};
lOTStockModel.detail.Add(lOTStockModelList);
}
lOTStockModel.Quantity = count.ToString();
lOTStockModels.Add(lOTStockModel);
ToltalCount += count;
}
foreach (var model in lOTStockModels)
{
string invCode = model.InvCode;
}
// 1. 按 InvCode 分组,并计算每组 Quantity 的总和
var summarizedList = lOTStockModels
.GroupBy(model => model.InvCode) // 按物料分组
.Select(group => new LOTStockModel // 创建新的汇总对象
{
InvCode = group.Key, // 物料代码
Quantity = group.Sum(x => Convert.ToDecimal(x.Quantity)).ToString(), // 汇总数量
// 如果需要合并明细(detail),可以用 SelectMany
detail = group.SelectMany(x => x.detail).ToList()
})
.ToList(); // 转换为 List
// 2. 使用新的集合(summarizedList)
foreach (var item2 in summarizedList)
{
for (int i = 0; i < dt2.Rows.Count; i++)
{
string invcode2 = dt2.Rows[i]["InvCode"].ToString();
if (item2.InvCode == dt2.Rows[i]["InvCode"].ToString())
{
if (Convert.ToDecimal(item2.Quantity) != Convert.ToDecimal(dt2.Rows[i]["Quantity"]))
{
throw new Exception("库存不足,请先检查库存,物料:" + dt2.Rows[i]["InvCode"].ToString() + "条码:" + item2.Quantity + "单据:" + dt2.Rows[i]["Quantity"]);//"传送数据为空!"
}
}
}
}
//if (ToltalCount != Convert.ToDecimal(dt.Rows[0]["Quantity"]))
//{
// throw new Exception("库存不足,请先检查库存");//"传送数据为空!"
//}
Inputstr = JsonConvert.SerializeObject(lOTStockModels);
conn.Close();
conn.Dispose();
}
}
return LOTStockDownCreate(JsonConvert.DeserializeObject>(Inputstr));//pda只能调用一张单据 pda传参一张单据
}
catch (Exception ex)
{
if (cmd.Transaction != null)
cmd.Transaction.Rollback();
throw ex;
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
///
/// 下架
///
///
///
public static DataTable LOTStockDownCreate(List JsonData)
{
String PrintEnable = "";
string workPoint = "";
var language = LanguageHelper.GetName("WMSAPIInfo");
if (JsonData.Count <= 0)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
}
List model = new List();
DataTable printTable = new DataTable();
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
string BusinessCode = string.Empty;
string UserCode = string.Empty;
string VenCode = string.Empty;
try
{
string TransType = string.Empty;
string Identification = Guid.NewGuid().ToString();
foreach (var item in JsonData)
{
TransType = item.TransType;
if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
{
throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
}
else if (string.IsNullOrEmpty(item.TransCode))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
}
string[] trans = item.TransCode.Split('~');
string MergeID = "";
if (trans.Length == 2)
{
MergeID = trans[0];
item.TransCode = trans[1];
}
#region 采购退货
if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
{
BusinessCode = TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription();
//更新源头单据数量
ICSPurchaseService.PurchaseReceiveDoctNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, "");
}
}//PurchaseReceiveDoctNegativePo
else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegativePo.GetDescription())
{
BusinessCode = TransTypeEnum.PurchaseReceiveDoctNegativePo.GetDescription();
//更新源头单据数量
ICSPurchaseService.PurchaseReceiveDoctNegativePo(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, "");
}
}
#endregion
#region 委外发料
else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription() || TransType == TransTypeEnum.RTOutsourcingIssueDoc.GetDescription())
{
BusinessCode = TransTypeEnum.OutsourcingIssueDoc.GetDescription();
//更新源头单据数量
ICSOutsourcingService.OutsourcingIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingIssueDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 委外退货
else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
{
BusinessCode = TransTypeEnum.OutsourcingReturnBack.GetDescription();
//更新源头单据数量
ICSOutsourcingService.OutsourcingReturnBack(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReturnBack.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, "");
}
}
else if (TransType == TransTypeEnum.OutsourcingReturnBackPo.GetDescription())
{
BusinessCode = TransTypeEnum.OutsourcingReturnBack.GetDescription();
//更新源头单据数量
ICSOutsourcingService.OutsourcingReturnBackOO(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReturnBack.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, "");
}
}
#endregion
#region 生产发料
else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
{
if (DBHelper.IsJHU9())
{
string zqty = string.Empty;
decimal qqty = 0;
string dqty = string.Empty;
string sumdqty = string.Empty;
string ssql = string.Empty;
string whcode = string.Empty;
string whsql = string.Empty;
string Batch = string.Empty;
decimal sumqty = 0;
DataTable whdt = new DataTable();
//转子批号
string sql = @"select c.BatchCode,a.Quantity,a.InvCode,b.EATTRIBUTE9 from ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSExtension c ON b.ExtensionID=c.ID AND b.WorkPoint=c.WorkPoint
WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{1}' and a.WorkPoint='{2}'";
sql = string.Format(sql, item.TransCode, item.TransSequence, item.WorkPoint);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows[0]["BatchCode"].ToString() != "")
{
//根据转子批号找到定子订单
string Nsql = @"select a.ID,b.MoCode,b.Sequence+'~'+a.Sequence AS Sequence,a.Quantity,a.InvCode from ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSExtension c ON b.ExtensionID=c.ID AND b.WorkPoint=c.WorkPoint
WHERE c.BatchCode='{0}' and b.EATTRIBUTE9='{5}' AND b.MOCode<>'{1}' and a.WorkPoint='{3}' AND a.InvCode='{4}' AND a.Quantity-a.IssueQuantity>0";
Nsql = string.Format(Nsql, dt.Rows[0]["BatchCode"].ToString(), item.TransCode, item.TransSequence, item.WorkPoint, dt.Rows[0]["InvCode"].ToString(), dt.Rows[0]["EATTRIBUTE9"].ToString());
DataTable dtt = DBHelper.SQlReturnData(Nsql, cmd);
for (int i = 0; i < dtt.Rows.Count; i++)
{
//将分配订单里数量提前加好 BCDE
qqty += Convert.ToDecimal(dtt.Rows[i]["Quantity"].ToString());
}
//转子分配数量
//zqty = (Convert.ToDecimal(item.Quantity) * Convert.ToDecimal(dt.Rows[0]["Quantity"].ToString()) / (Convert.ToDecimal(dt.Rows[0]["Quantity"].ToString())+qqty)).ToString();
decimal value1 = Convert.ToDecimal(item.Quantity) * Convert.ToDecimal(dt.Rows[0]["Quantity"].ToString()) / (Convert.ToDecimal(dt.Rows[0]["Quantity"].ToString()) + qqty);
decimal truncatedValue1 = Math.Truncate(value1 * 1000) / 1000;
zqty = truncatedValue1.ToString();
log.Debug("转子分配数量" + zqty);
BusinessCode = TransTypeEnum.MOIssueDoc.GetDescription();
//更新源头单据数量
ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, zqty, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
if (null != itemInfo.VenCode)
{
VenCode = itemInfo.VenCode;
}
itemInfo.CurrentQuantity = item.Quantity;
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, zqty,
item.User, item.WorkPoint, "3", TransTypeEnum.MOIssueDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
for (int i = 0; i < dtt.Rows.Count; i++)
{
if (i == dtt.Rows.Count)
{
//算余数
//dqty= (Convert.ToDecimal(item.Quantity) - Convert.ToDecimal(sumdqty)- Convert.ToDecimal(zqty)).ToString();
decimal value3 = Convert.ToDecimal(item.Quantity) - Convert.ToDecimal(sumdqty) - Convert.ToDecimal(zqty);
decimal truncatedValue3 = Math.Truncate(value3 * 1000) / 1000;
dqty = truncatedValue3.ToString();
}
else
{
//dqty = (Convert.ToDecimal(item.Quantity) * Convert.ToDecimal(dtt.Rows[i]["Quantity"].ToString()) / ( qqty+ Convert.ToDecimal(dt.Rows[0]["Quantity"].ToString()))).ToString();
decimal value2 = Convert.ToDecimal(item.Quantity) * Convert.ToDecimal(dtt.Rows[i]["Quantity"].ToString()) / (qqty + Convert.ToDecimal(dt.Rows[0]["Quantity"].ToString()));
// 先乘以 10^6,取整,再除以 10^6(截断 6 位小数)
decimal truncatedValue2 = Math.Truncate(value2 * 1000) / 1000;
dqty = truncatedValue2.ToString();
sumdqty += dqty;
}
dqty = (Convert.ToDecimal(item.Quantity) - Convert.ToDecimal(zqty)).ToString();
log.Debug("定子分配数量" + dqty);
//更新定子源头单据数量
ICSManufactureService.MOIssueDoc(dtt.Rows[i]["MoCode"].ToString(), dtt.Rows[i]["Sequence"].ToString(), dqty, item.WorkPoint, cmd, language, enableCode, dtt.Rows[i]["ID"].ToString());
foreach (var itemInfo in item.detail)
{
//定子出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, dtt.Rows[i]["MoCode"].ToString(), dtt.Rows[i]["Sequence"].ToString(), itemInfo.LotNo, dqty,
item.User, item.WorkPoint, "3", TransTypeEnum.MOIssueDoc.GetDescription(), cmd, language, "", dtt.Rows[i]["ID"].ToString(), MergeID);
}
}
}
else
{
BusinessCode = TransTypeEnum.MOIssueDoc.GetDescription();
//更新源头单据数量
ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
if (null != itemInfo.VenCode)
{
VenCode = itemInfo.VenCode;
}
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.MOIssueDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
// 东辉日志表记录交接人EATTRIBUTE3
if (!String.IsNullOrWhiteSpace(item.Heir))
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdateHeir(Identification, TransTypeEnum.MOIssueDoc.GetDescription(), cmd, language, item.Heir);
}
}
else
{
BusinessCode = TransTypeEnum.MOIssueDoc.GetDescription();
//更新源头单据数量
ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
if (Convert.ToDecimal(itemInfo.CurrentQuantity) == 0)
{
throw new Exception("发料数量不能为0,请确认后重新提交!");
}
//晶华固定料入库
string aaasql = @"SELECT DISTINCT
b.F_Define1
FROM Sys_SRM_Items a
LEFT JOIN Sys_SRM_ItemsDetail b ON a.F_Id = b.F_ItemId
WHERE a.F_EnCode = 'InventoryLotWareHouseFixed' and b.F_EnabledMark='1' and b.F_Define1=(select top 1 InvCode from ICSInventoryLot where lotno like '{0}%' and workpoint='{1}')";
aaasql = string.Format(aaasql, itemInfo.LotNo, item.WorkPoint);
DataTable aadtt = DBHelper.SQlReturnData(aaasql, cmd);
if (aadtt.Rows.Count > 0 && aadtt != null)
{
string ccsql = string.Empty;
ccsql = @"SELECT
ext.ProjectCode,c.WorkPoint
FROM
ICSMO c
INNER JOIN ICSInventory inv ON c.InvCode = inv.InvCode AND c.WorkPoint = inv.WorkPoint
INNER JOIN ICSExtension ext ON c.ExtensionID = ext.ID AND c.WorkPoint = ext.WorkPoint
WHERE c.mocode='{0}' AND c.WorkPoint='{1}'";
ccsql = string.Format(ccsql, item.TransCode, item.WorkPoint);
DataTable aadtt2 = DBHelper.SQlReturnData(ccsql, cmd);
string cccsql = string.Empty;
cccsql = @"select top 1 InvCode from ICSInventoryLot where lotno like '{0}%' and workpoint='{1}'";
cccsql = string.Format(cccsql, itemInfo.LotNo, item.WorkPoint);
DataTable aadtt4 = DBHelper.SQlReturnData(cccsql, cmd);
if (aadtt2.Rows.Count > 0 && aadtt2 != null && aadtt4.Rows[0]["InvCode"].ToString().StartsWith("3"))
{
itemInfo.LotNo = itemInfo.LotNo + aadtt2.Rows[0]["ProjectCode"].ToString() + aadtt2.Rows[0]["WorkPoint"].ToString();
}
else
{
itemInfo.LotNo = itemInfo.LotNo + aadtt2.Rows[0]["WorkPoint"].ToString();
}
}
string checksql = @"select * from ICSWareHouseLotInfo where LotNo='{0}' and WorkPoint='{1}' and WareHouseCode in (SELECT DISTINCT
b.F_ItemCode
FROM Sys_SRM_Items a
LEFT JOIN Sys_SRM_ItemsDetail b ON a.F_Id = b.F_ItemId
WHERE a.F_EnCode = 'JinHuaLiKu')";
checksql = string.Format(checksql, itemInfo.LotNo, item.WorkPoint);
DataTable aadtt3 = DBHelper.SQlReturnData(checksql, cmd);
if (aadtt3.Rows.Count > 0 && aadtt3 != null)
{
throw new Exception("调拨单未整单完成,等待完成后进行扫码领料");//晶华立库卡控,不影响其他项目
}
if (null != itemInfo.VenCode)
{
VenCode = itemInfo.VenCode;
}
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.MOIssueDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
// 东辉日志表记录交接人EATTRIBUTE3
if (!String.IsNullOrWhiteSpace(item.Heir))
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdateHeir(Identification, TransTypeEnum.MOIssueDoc.GetDescription(), cmd, language, item.Heir);
}
}
#endregion
#region 生产发料
else if (TransType == TransTypeEnum.JHMOIssueDoc.GetDescription())
{
BusinessCode = TransTypeEnum.JHMOIssueDoc.GetDescription();
if (DBHelper.IsJHU9())
{
string zqty = string.Empty;
decimal qqty = 0;
string dqty = string.Empty;
string sumdqty = string.Empty;
string ssql = string.Empty;
string whcode = string.Empty;
string whsql = string.Empty;
string Batch = string.Empty;
decimal sumqty = 0;
string lotinvcode = string.Empty;
DataTable whdt = new DataTable();
DataTable lotinvdt = new DataTable();
string checksql = @"select a.id from ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
where b.mocode='{0}' and a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1' ";
checksql = string.Format(checksql, item.TransCode, item.WorkPoint);
DataTable checkdt = DBHelper.SQlReturnData(checksql, cmd);
if (checkdt.Rows.Count == 0 || checkdt == null)
{
foreach (var itemInfo in item.detail)
{
//根据条码找到物料
string lotinvsql = @"select a.InvCode from ICSInventoryLot a
where a.lotno='{0}' and a.WorkPoint='{1}'";
lotinvsql = string.Format(lotinvsql, itemInfo.LotNo, item.WorkPoint);
lotinvdt = DBHelper.SQlReturnData(lotinvsql, cmd);
}
lotinvcode = lotinvdt.Rows[0]["InvCode"].ToString();
//转子批号
string sql = @"select c.BatchCode from ICSMO b
INNER JOIN ICSExtension c ON b.ExtensionID=c.ID AND b.WorkPoint=c.WorkPoint
WHERE b.MOCode='{0}' AND b.Sequence='{1}' and b.WorkPoint='{2}' and isnull(c.BatchCode,'') <> ''";
sql = string.Format(sql, item.TransCode, item.TransSequence, item.WorkPoint);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt != null && dt.Rows.Count > 0)
{
//根据转子批号找到定子订单
string Nsql = @"select b.ID,b.MoCode,b.Sequence AS Sequence,b.Quantity,b.InvCode from ICSMO b
INNER JOIN ICSExtension c ON b.ExtensionID=c.ID AND b.WorkPoint=c.WorkPoint
WHERE c.BatchCode='{0}' AND b.MOCode<>'{1}' and b.WorkPoint='{2}'";
Nsql = string.Format(Nsql, dt.Rows[0]["BatchCode"].ToString(), item.TransCode, item.WorkPoint);
DataTable dtt = DBHelper.SQlReturnData(Nsql, cmd);
//根据物料找到转定子分配比例
string Invsql = @"select case when EATTRIBUTE5='' or EATTRIBUTE5 is null THEN '0.5' ELSE EATTRIBUTE5 END AS EATTRIBUTE5 from ICSInventory
WHERE InvCode='{0}' and WorkPoint='{1}'";
Invsql = string.Format(Invsql, lotinvcode, item.WorkPoint);
DataTable Invdt = DBHelper.SQlReturnData(Invsql, cmd);
//zqty = (Convert.ToDecimal(item.Quantity) * Convert.ToDecimal(Invdt.Rows[0]["EATTRIBUTE5"].ToString())).ToString();
decimal value1 = Convert.ToDecimal(item.Quantity) * Convert.ToDecimal(Invdt.Rows[0]["EATTRIBUTE5"].ToString());
decimal truncatedValue1 = Math.Truncate(value1 * 1000) / 1000;
zqty = truncatedValue1.ToString();
log.Debug("转子分配数量" + zqty);
BusinessCode = TransTypeEnum.JHMOIssueDoc.GetDescription();
//更新源头单据数量
//ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, zqty, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
if (null != itemInfo.VenCode)
{
VenCode = itemInfo.VenCode;
}
itemInfo.CurrentQuantity = item.Quantity;
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, zqty,
item.User, item.WorkPoint, "3", TransTypeEnum.JHMOIssueDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
//dqty = (Convert.ToDecimal(item.Quantity) - Convert.ToDecimal(zqty)).ToString();
decimal value3 = Convert.ToDecimal(item.Quantity) - Convert.ToDecimal(zqty);
decimal truncatedValue3 = Math.Truncate(value3 * 1000) / 1000;
dqty = truncatedValue3.ToString();
log.Debug("定子分配数量" + dqty);
//更新定子源头单据数量
//ICSManufactureService.MOIssueDoc(dtt.Rows[0]["MoCode"].ToString(), dtt.Rows[0]["Sequence"].ToString(), dqty, item.WorkPoint, cmd, language, enableCode, dtt.Rows[0]["ID"].ToString());
foreach (var itemInfo in item.detail)
{
//定子出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, dtt.Rows[0]["MoCode"].ToString(), dtt.Rows[0]["Sequence"].ToString(), itemInfo.LotNo, dqty,
item.User, item.WorkPoint, "3", TransTypeEnum.JHMOIssueDoc.GetDescription(), cmd, language, "", dtt.Rows[0]["ID"].ToString(), MergeID);
}
}
else
{
BusinessCode = TransTypeEnum.JHMOIssueDoc.GetDescription();
foreach (var itemInfo in item.detail)
{
if (null != itemInfo.VenCode)
{
VenCode = itemInfo.VenCode;
}
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.JHMOIssueDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
}
else
{
BusinessCode = TransTypeEnum.JHMOIssueDoc.GetDescription();
//转子批号
string sql = @"select c.BatchCode,a.Quantity,a.InvCode,b.EATTRIBUTE9 from ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSExtension c ON b.ExtensionID=c.ID AND b.WorkPoint=c.WorkPoint
WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{1}' and a.WorkPoint='{2}' and isnull(c.BatchCode,'') <> ''";
sql = string.Format(sql, item.TransCode, item.TransSequence, item.WorkPoint);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt != null && dt.Rows.Count > 0)
{
//根据转子批号找到定子订单
string Nsql = @"select a.ID,b.MoCode,b.Sequence+'~'+a.Sequence AS Sequence,a.Quantity,a.InvCode from ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSExtension c ON b.ExtensionID=c.ID AND b.WorkPoint=c.WorkPoint
WHERE c.BatchCode='{0}' and b.EATTRIBUTE9='{5}' AND b.MOCode<>'{1}' and a.WorkPoint='{3}' AND a.Quantity-a.IssueQuantity>0 --AND a.InvCode='020132-00015'";
Nsql = string.Format(Nsql, dt.Rows[0]["BatchCode"].ToString(), item.TransCode, item.TransSequence, item.WorkPoint, dt.Rows[0]["InvCode"].ToString(), dt.Rows[0]["EATTRIBUTE9"].ToString());
DataTable dtt = DBHelper.SQlReturnData(Nsql, cmd);
if (dtt != null && dtt.Rows.Count > 0)
{
for (int i = 0; i < dtt.Rows.Count; i++)
{
//将分配订单里数量提前加好 BCDE
qqty += Convert.ToDecimal(dtt.Rows[i]["Quantity"].ToString());
}
//转子分配数量
//zqty = (Convert.ToDecimal(item.Quantity) * Convert.ToDecimal(dt.Rows[0]["Quantity"].ToString()) / (Convert.ToDecimal(dt.Rows[0]["Quantity"].ToString())+qqty)).ToString("0.######");
decimal value1 = Convert.ToDecimal(item.Quantity) * Convert.ToDecimal(dt.Rows[0]["Quantity"].ToString()) / (Convert.ToDecimal(dt.Rows[0]["Quantity"].ToString()) + qqty);
decimal truncatedValue1 = Math.Truncate(value1 * 1000) / 1000;
zqty = truncatedValue1.ToString();
log.Debug("转子分配数量" + zqty);
//zqty = (Convert.ToDecimal(item.Quantity) * Convert.ToDecimal(dt.Rows[0]["Quantity"].ToString()) / (Convert.ToDecimal(dt.Rows[0]["Quantity"].ToString()) + Convert.ToDecimal(dtt.Rows[0]["Quantity"].ToString()))).ToString();
//log.Debug("转子分配数量" + zqty);
BusinessCode = TransTypeEnum.JHMOIssueDoc.GetDescription();
//更新源头单据数量
ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, zqty, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
if (null != itemInfo.VenCode)
{
VenCode = itemInfo.VenCode;
}
itemInfo.CurrentQuantity = item.Quantity;
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, zqty,
item.User, item.WorkPoint, "3", TransTypeEnum.JHMOIssueDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
for (int i = 0; i < dtt.Rows.Count; i++)
{
if (i == dtt.Rows.Count)
{
//算余数
//dqty = (Convert.ToDecimal(item.Quantity) - Convert.ToDecimal(sumdqty) - Convert.ToDecimal(zqty)).ToString();
decimal value3 = Convert.ToDecimal(item.Quantity) - Convert.ToDecimal(sumdqty) - Convert.ToDecimal(zqty);
decimal truncatedValue3 = Math.Truncate(value3 * 1000) / 1000;
dqty = truncatedValue3.ToString();
}
else
{
//dqty = (Convert.ToDecimal(item.Quantity) * Convert.ToDecimal(dtt.Rows[i]["Quantity"].ToString()) / (qqty + Convert.ToDecimal(dt.Rows[0]["Quantity"].ToString()))).ToString("0.######");
decimal value2 = Convert.ToDecimal(item.Quantity) * Convert.ToDecimal(dtt.Rows[i]["Quantity"].ToString())
/ (qqty + Convert.ToDecimal(dt.Rows[0]["Quantity"].ToString()));
// 先乘以 10^6,取整,再除以 10^6(截断 6 位小数)
decimal truncatedValue2 = Math.Truncate(value2 * 1000) / 1000;
dqty = truncatedValue2.ToString();
sumdqty += dqty;
}
//dqty = (Convert.ToDecimal(item.Quantity) - Convert.ToDecimal(zqty)).ToString();
log.Debug("定子分配数量" + dqty);
//更新定子源头单据数量
ICSManufactureService.MOIssueDoc(dtt.Rows[i]["MoCode"].ToString(), dtt.Rows[i]["Sequence"].ToString(), dqty, item.WorkPoint, cmd, language, enableCode, dtt.Rows[i]["ID"].ToString());
foreach (var itemInfo in item.detail)
{
//定子出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, dtt.Rows[i]["MoCode"].ToString(), dtt.Rows[i]["Sequence"].ToString(), itemInfo.LotNo, dqty,
item.User, item.WorkPoint, "3", TransTypeEnum.JHMOIssueDoc.GetDescription(), cmd, language, "", dtt.Rows[i]["ID"].ToString(), MergeID);
}
}
}
else
{
BusinessCode = TransTypeEnum.JHMOIssueDoc.GetDescription();
//更新源头单据数量
ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
if (null != itemInfo.VenCode)
{
VenCode = itemInfo.VenCode;
}
itemInfo.CurrentQuantity = item.Quantity;
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, item.Quantity,
item.User, item.WorkPoint, "3", TransTypeEnum.JHMOIssueDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
}
else
{
BusinessCode = TransTypeEnum.JHMOIssueDoc.GetDescription();
//更新源头单据数量
ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
if (null != itemInfo.VenCode)
{
VenCode = itemInfo.VenCode;
}
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.JHMOIssueDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
}
}
else
{
BusinessCode = TransTypeEnum.JHMOIssueDoc.GetDescription();
//更新源头单据数量
ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
if (null != itemInfo.VenCode)
{
VenCode = itemInfo.VenCode;
}
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.JHMOIssueDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
// 东辉日志表记录交接人EATTRIBUTE3
if (!String.IsNullOrWhiteSpace(item.Heir))
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdateHeir(Identification, TransTypeEnum.MOIssueDoc.GetDescription(), cmd, language, item.Heir);
}
}
#endregion
#region 生产发料——自动出库
else if (TransType == TransTypeEnum.MOIssueAutoDoc.GetDescription())
{
//生产发料自动出库ERP提交在Job中进行
BusinessCode = TransTypeEnum.MOIssueAutoDoc.GetDescription();
//更新源头单据数量
ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.MOIssueAutoDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 销售出库
else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
{
BusinessCode = TransTypeEnum.SalesShipmentDoc.GetDescription();
//更新源头单据数量
ICSSalesService.SalesShipmentDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID, item.CourierCode);
foreach (var itemInfo in item.detail)
{
workPoint = item.WorkPoint;
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.SalesShipmentDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 销售出库-出库单
else if (TransType == TransTypeEnum.SalesShipmentOutDoc.GetDescription())
{
UserCode = item.User;
BusinessCode = TransTypeEnum.SalesShipmentOutDoc.GetDescription();
//更新源头单据数量
ICSSalesService.SalesShipmentOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID, item.CourierCode);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.SalesShipmentOutDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 晶华销售出库-出库单
else if (TransType == TransTypeEnum.JHSalesShipmentOutDoc.GetDescription())
{
UserCode = item.User;
BusinessCode = TransTypeEnum.JHSalesShipmentOutDoc.GetDescription();
//更新源头单据数量
ICSSalesService.SalesShipmentOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID, item.CourierCode);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.JHSalesShipmentOutDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 两步调出
else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
{
BusinessCode = TransTypeEnum.TwoStepTransferDocOut.GetDescription();
//更新源头单据数量
ICSWareHouseService.TwoStepTransferDocOut(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocOut.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 晶华两步调出
else if (TransType == TransTypeEnum.JHTwoStepTransferDocOut.GetDescription())
{
BusinessCode = TransTypeEnum.JHTwoStepTransferDocOut.GetDescription();
//更新源头单据数量
ICSWareHouseService.JHTwoStepTransferDocOut(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "6", TransTypeEnum.JHTwoStepTransferDocOut.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 其他出库
else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
{
BusinessCode = TransTypeEnum.OtherOutDoc.GetDescription();
//更新源头单据数量
ICSWareHouseService.OtherOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OtherOutDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 其他出库——自动出库
else if (TransType == TransTypeEnum.OtherOutAutoDoc.GetDescription())
{
BusinessCode = TransTypeEnum.OtherOutAutoDoc.GetDescription();
//更新源头单据数量
ICSWareHouseService.OtherOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OtherOutDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 红字其他入库
else if (TransType == TransTypeEnum.OtherInRedDoc.GetDescription())
{
BusinessCode = TransTypeEnum.OtherInRedDoc.GetDescription();
//更新源头单据数量
ICSWareHouseService.OtherInRedDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OtherInRedDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 领料申请单发料
else if (TransType == TransTypeEnum.MOApply.GetDescription())
{
BusinessCode = TransTypeEnum.MOApply.GetDescription();
//更新源头单据数量
ICSManufactureService.MOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.MOApply.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 补料申请单发料
else if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
{
BusinessCode = TransTypeEnum.MOReplenishment.GetDescription();
//更新源头单据数量
ICSManufactureService.MOReplenishment(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.MOReplenishment.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 委外领料申请单发料
else if (TransType == TransTypeEnum.OOApply.GetDescription())
{
BusinessCode = TransTypeEnum.OOApply.GetDescription();
//更新源头单据数量
ICSOutsourcingService.OOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OOApply.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 开立材料出库
else if (TransType == TransTypeEnum.MOIssue.GetDescription())
{
BusinessCode = TransTypeEnum.MOIssue.GetDescription();
//更新源头单据数量
ICSManufactureService.MOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.MOIssue.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 开立委外材料出库
else if (TransType == TransTypeEnum.OOIssue.GetDescription())
{
BusinessCode = TransTypeEnum.OOIssue.GetDescription();
//更新源头单据数量
ICSOutsourcingService.OOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OOIssue.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 开立红字入库单
else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
{
BusinessCode = TransTypeEnum.PurchaseReceive.GetDescription();
//更新源头单据数量
ICSPurchaseService.PurchaseReceive(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceive.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, "");
}
}
#endregion
#region 开立委外红字入库单
else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
{
BusinessCode = TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription();
//更新源头单据数量
ICSOutsourcingService.OutsourcingReceiveDocNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, "");
}
}
#endregion
#region 借用
else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
{
BusinessCode = TransTypeEnum.BrrowDoc.GetDescription();
//更新源头单据数量
ICSWareHouseService.BrrowDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.BrrowDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
else
{
throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
}
}
//上传ERP
if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
{
//采购退货
if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
{
//if (DBHelper.IsRTU9())
//{
// ICSPurchaseService.RTPurchaseReceiveDoctNegativeERP(TransType, Identification, cmd, language, BusinessCode);
//}
//else
//{
ICSPurchaseService.PurchaseReceiveDoctNegativeERP(TransType, Identification, cmd, language, BusinessCode);
//}
}
else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegativePo.GetDescription())
{
ICSPurchaseService.PurchaseReceiveDoctNegativePoERP(TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription(), Identification, cmd, language, BusinessCode);
}
//委外发料
else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription() || TransType == TransTypeEnum.RTOutsourcingIssueDoc.GetDescription())
ICSOutsourcingService.OutsourcingIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
//委外退货
else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
{
if (DBHelper.IsU9())
{
ICSOutsourcingService.U9OutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode);
}
//else if (DBHelper.IsRTU9())
//{
// ICSOutsourcingService.RTOutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode);
//}
else
{
ICSOutsourcingService.OutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode);
}
}
//铭锋委外退货 源头单据采购订单(同步到到货单表)
else if (TransType == TransTypeEnum.OutsourcingReturnBackPo.GetDescription())
{
//铭锋委外退货 源头单据采购订单(同步到到货单表)
ICSOutsourcingService.OutsourcingReturnBackOOERP(TransTypeEnum.OutsourcingReturnBack.GetDescription(), Identification, cmd, language, BusinessCode);
}
//生产发料
else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
{
if (DBHelper.IsDX())
{
ICSManufactureService.DXMOIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
}
else
{
ICSManufactureService.MOIssueDocERP(TransType, Identification, cmd, language, BusinessCode, VenCode);
}
}
//生产发料
else if (TransType == TransTypeEnum.JHMOIssueDoc.GetDescription())
{
if (DBHelper.IsDX())
{
ICSManufactureService.DXMOIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
}
else
{
ICSManufactureService.JHMOIssueDocERP(TransType, Identification, cmd, language, BusinessCode, VenCode);
}
}
//生产发料——自动出库
else if (TransType == TransTypeEnum.MOIssueAutoDoc.GetDescription())
{
//生产发料自动出库ERP提交在Job中进行
//ICSManufactureService.MOIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
}
//销售出库
else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
{
//铭锋先进先出
if (!string.IsNullOrWhiteSpace(JsonData[0].passFlag) && JsonData[0].passFlag == "0")
{
string message = SubmitCanOut(Identification, "3", TransTypeEnum.SalesShipmentDoc.GetDescription(), workPoint, cmd);
if (!string.IsNullOrWhiteSpace(message))
{
throw new Exception(message);
}
}
if (DBHelper.IsU9() || DBHelper.IsPNU9())
{ ICSSalesService.U9SalesShipmentDocERP(TransType, Identification, cmd, language, BusinessCode); }
else { ICSSalesService.SalesShipmentDocERP(TransType, Identification, cmd, language, BusinessCode); }
}
//销售出库-出库单
else if (TransType == TransTypeEnum.SalesShipmentOutDoc.GetDescription())
{
ICSSalesService.SalesShipmentDocOutERP(TransType, Identification, cmd, language, BusinessCode, UserCode);
}
//晶华销售出库-出库单
else if (TransType == TransTypeEnum.JHSalesShipmentOutDoc.GetDescription())
{
ICSSalesService.JHSalesShipmentDocOutERP(TransType, Identification, cmd, language, BusinessCode, UserCode);
}
//两步调出
else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
ICSWareHouseService.TwoStepTransferDocOutERP(TransType, Identification, cmd, language, BusinessCode);
//晶华两步调出
else if (TransType == TransTypeEnum.JHTwoStepTransferDocOut.GetDescription())
ICSWareHouseService.JHTwoStepTransferDocOutERP(TransType, Identification, cmd, language, BusinessCode);
//其他出库
else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
{
if (DBHelper.IsU9())
{
ICSWareHouseService.CreateOtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
}
else
ICSWareHouseService.OtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
}
//其他出库——自动出库
else if (TransType == TransTypeEnum.OtherOutAutoDoc.GetDescription())
{
ICSWareHouseService.OtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
}
//红字其他入库
else if (TransType == TransTypeEnum.OtherInRedDoc.GetDescription())
{
ICSWareHouseService.OtherInRedDocERP(TransType, Identification, cmd, language, BusinessCode);
}
//领料申请单发料
if (TransType == TransTypeEnum.MOApply.GetDescription())
{
ICSManufactureService.MOApplyERP(TransType, Identification, cmd, language, BusinessCode);
}
//补料申请单发料
if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
ICSManufactureService.MOReplenishmentERP(TransType, Identification, cmd, language, BusinessCode);
//委外领料申请单发料
if (TransType == TransTypeEnum.OOApply.GetDescription())
ICSOutsourcingService.OOApplyERP(TransType, Identification, cmd, language, BusinessCode);
//开立材料出库
if (TransType == TransTypeEnum.MOIssue.GetDescription())
{
if (DBHelper.IsU9())
{ ICSManufactureService.U9MOIssueERP(TransType, Identification, cmd, language, BusinessCode); }
else { ICSManufactureService.MOIssueERP(TransType, Identification, cmd, language, BusinessCode); }
}
//开立委外材料出库
if (TransType == TransTypeEnum.OOIssue.GetDescription())
ICSOutsourcingService.OOIssueERP(TransType, Identification, cmd, language, BusinessCode);
//开立红字入库单
if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
ICSPurchaseService.PurchaseReceiveERP(TransType, Identification, cmd, language, BusinessCode);
//开立委外红字入库单
if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
ICSOutsourcingService.OutsourcingReceiveDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
//借用
if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
if (!DBHelper.IsBBU9())
{
ICSWareHouseService.BrrowDocERP(TransType, Identification, cmd, language, BusinessCode);
}
}
if (printTable != null && printTable.Rows.Count > 0)
{
cmd.Transaction.Commit();
return printTable;
}
else
{
DataTable table = GetData(Identification, 2, cmd);
cmd.Transaction.Commit();
return table;
}
}
catch (Exception ex)
{
if (cmd.Transaction != null)
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
public static DataTable LOTStockDownRoundCreate(List JsonData)
{
String PrintEnable = "";
string workPoint = "";
var language = LanguageHelper.GetName("WMSAPIInfo");
if (JsonData.Count <= 0)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
}
List model = new List();
DataTable printTable = new DataTable();
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
string BusinessCode = string.Empty;
string UserCode = string.Empty;
string VenCode = string.Empty;
try
{
string TransType = string.Empty;
string Identification = Guid.NewGuid().ToString();
foreach (var item in JsonData)
{
TransType = item.TransType;
if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
{
throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
}
else if (string.IsNullOrEmpty(item.TransCode))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
}
string[] trans = item.TransCode.Split('~');
string MergeID = "";
if (trans.Length == 2)
{
MergeID = trans[0];
item.TransCode = trans[1];
}
#region 采购退货
if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
{
BusinessCode = TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription();
//更新源头单据数量
ICSPurchaseService.PurchaseReceiveDoctNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, "");
}
}//PurchaseReceiveDoctNegativePo
else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegativePo.GetDescription())
{
BusinessCode = TransTypeEnum.PurchaseReceiveDoctNegativePo.GetDescription();
//更新源头单据数量
ICSPurchaseService.PurchaseReceiveDoctNegativePo(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, "");
}
}
#endregion
#region 委外发料
else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription() || TransType == TransTypeEnum.RTOutsourcingIssueDoc.GetDescription())
{
BusinessCode = TransTypeEnum.OutsourcingIssueDoc.GetDescription();
//更新源头单据数量
ICSOutsourcingService.OutsourcingIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingIssueDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 委外退货
else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
{
BusinessCode = TransTypeEnum.OutsourcingReturnBack.GetDescription();
//更新源头单据数量
ICSOutsourcingService.OutsourcingReturnBack(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReturnBack.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, "");
}
}
else if (TransType == TransTypeEnum.OutsourcingReturnBackPo.GetDescription())
{
BusinessCode = TransTypeEnum.OutsourcingReturnBack.GetDescription();
//更新源头单据数量
ICSOutsourcingService.OutsourcingReturnBackOO(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReturnBack.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, "");
}
}
#endregion
#region 生产发料
else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
{
BusinessCode = TransTypeEnum.MOIssueDoc.GetDescription();
//更新源头单据数量
ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.MOIssueDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
// 东辉日志表记录交接人EATTRIBUTE3
if (!String.IsNullOrWhiteSpace(item.Heir))
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdateHeir(Identification, TransTypeEnum.MOIssueDoc.GetDescription(), cmd, language, item.Heir);
}
#endregion
#region 生产发料——自动出库
else if (TransType == TransTypeEnum.MOIssueAutoDoc.GetDescription())
{
//生产发料自动出库ERP提交在Job中进行
BusinessCode = TransTypeEnum.MOIssueAutoDoc.GetDescription();
//更新源头单据数量
ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDownRound(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.MOIssueAutoDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 销售出库
else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
{
BusinessCode = TransTypeEnum.SalesShipmentDoc.GetDescription();
//更新源头单据数量
ICSSalesService.SalesShipmentDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID, item.CourierCode);
foreach (var itemInfo in item.detail)
{
workPoint = item.WorkPoint;
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.SalesShipmentDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 销售出库-出库单
else if (TransType == TransTypeEnum.SalesShipmentOutDoc.GetDescription())
{
UserCode = item.User;
BusinessCode = TransTypeEnum.SalesShipmentOutDoc.GetDescription();
//更新源头单据数量
ICSSalesService.SalesShipmentOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID, item.CourierCode);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.SalesShipmentOutDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 两步调出
else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
{
BusinessCode = TransTypeEnum.TwoStepTransferDocOut.GetDescription();
//更新源头单据数量
ICSWareHouseService.TwoStepTransferDocOut(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocOut.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 其他出库
else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
{
BusinessCode = TransTypeEnum.OtherOutDoc.GetDescription();
//更新源头单据数量
ICSWareHouseService.OtherOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OtherOutDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 其他出库——自动出库
else if (TransType == TransTypeEnum.OtherOutAutoDoc.GetDescription())
{
BusinessCode = TransTypeEnum.OtherOutAutoDoc.GetDescription();
//更新源头单据数量
ICSWareHouseService.OtherOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OtherOutDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 红字其他入库
else if (TransType == TransTypeEnum.OtherInRedDoc.GetDescription())
{
BusinessCode = TransTypeEnum.OtherInRedDoc.GetDescription();
//更新源头单据数量
ICSWareHouseService.OtherInRedDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OtherInRedDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 领料申请单发料
else if (TransType == TransTypeEnum.MOApply.GetDescription())
{
BusinessCode = TransTypeEnum.MOApply.GetDescription();
//更新源头单据数量
ICSManufactureService.MOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.MOApply.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 补料申请单发料
else if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
{
BusinessCode = TransTypeEnum.MOReplenishment.GetDescription();
//更新源头单据数量
ICSManufactureService.MOReplenishment(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.MOReplenishment.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 委外领料申请单发料
else if (TransType == TransTypeEnum.OOApply.GetDescription())
{
BusinessCode = TransTypeEnum.OOApply.GetDescription();
//更新源头单据数量
ICSOutsourcingService.OOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OOApply.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 开立材料出库
else if (TransType == TransTypeEnum.MOIssue.GetDescription())
{
BusinessCode = TransTypeEnum.MOIssue.GetDescription();
//更新源头单据数量
ICSManufactureService.MOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.MOIssue.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 开立委外材料出库
else if (TransType == TransTypeEnum.OOIssue.GetDescription())
{
BusinessCode = TransTypeEnum.OOIssue.GetDescription();
//更新源头单据数量
ICSOutsourcingService.OOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OOIssue.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 开立红字入库单
else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
{
BusinessCode = TransTypeEnum.PurchaseReceive.GetDescription();
//更新源头单据数量
ICSPurchaseService.PurchaseReceive(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceive.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, "");
}
}
#endregion
#region 开立委外红字入库单
else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
{
BusinessCode = TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription();
//更新源头单据数量
ICSOutsourcingService.OutsourcingReceiveDocNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, "");
}
}
#endregion
#region 借用
else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
{
BusinessCode = TransTypeEnum.BrrowDoc.GetDescription();
//更新源头单据数量
ICSWareHouseService.BrrowDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.BrrowDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
else
{
throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
}
}
//上传ERP
if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
{
//采购退货
if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
{
//if (DBHelper.IsRTU9())
//{
// ICSPurchaseService.RTPurchaseReceiveDoctNegativeERP(TransType, Identification, cmd, language, BusinessCode);
//}
//else
//{
ICSPurchaseService.PurchaseReceiveDoctNegativeERP(TransType, Identification, cmd, language, BusinessCode);
//}
}
else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegativePo.GetDescription())
{
ICSPurchaseService.PurchaseReceiveDoctNegativePoERP(TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription(), Identification, cmd, language, BusinessCode);
}
//委外发料
else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription() || TransType == TransTypeEnum.RTOutsourcingIssueDoc.GetDescription())
ICSOutsourcingService.OutsourcingIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
//委外退货
else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
{
if (DBHelper.IsU9())
{
ICSOutsourcingService.U9OutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode);
}
//else if (DBHelper.IsRTU9())
//{
// ICSOutsourcingService.RTOutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode);
//}
else
{
ICSOutsourcingService.OutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode);
}
}
//铭锋委外退货 源头单据采购订单(同步到到货单表)
else if (TransType == TransTypeEnum.OutsourcingReturnBackPo.GetDescription())
{
//铭锋委外退货 源头单据采购订单(同步到到货单表)
ICSOutsourcingService.OutsourcingReturnBackOOERP(TransTypeEnum.OutsourcingReturnBack.GetDescription(), Identification, cmd, language, BusinessCode);
}
//生产发料
else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
{
if (DBHelper.IsDX())
{
ICSManufactureService.DXMOIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
}
else
{
ICSManufactureService.MOIssueDocERP(TransType, Identification, cmd, language, BusinessCode, VenCode);
}
}
//生产发料——自动出库
else if (TransType == TransTypeEnum.MOIssueAutoDoc.GetDescription())
{
//生产发料自动出库ERP提交在Job中进行
//ICSManufactureService.MOIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
}
//销售出库
else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
{
//铭锋先进先出
if (!string.IsNullOrWhiteSpace(JsonData[0].passFlag) && JsonData[0].passFlag == "0")
{
string message = SubmitCanOut(Identification, "3", TransTypeEnum.SalesShipmentDoc.GetDescription(), workPoint, cmd);
if (!string.IsNullOrWhiteSpace(message))
{
throw new Exception(message);
}
}
if (DBHelper.IsU9() || DBHelper.IsPNU9())
{ ICSSalesService.U9SalesShipmentDocERP(TransType, Identification, cmd, language, BusinessCode); }
else { ICSSalesService.SalesShipmentDocERP(TransType, Identification, cmd, language, BusinessCode); }
}
//销售出库-出库单
else if (TransType == TransTypeEnum.SalesShipmentOutDoc.GetDescription())
{
ICSSalesService.SalesShipmentDocOutERP(TransType, Identification, cmd, language, BusinessCode, UserCode);
}
//两步调出
else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
ICSWareHouseService.TwoStepTransferDocOutERP(TransType, Identification, cmd, language, BusinessCode);
//其他出库
else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
{
if (DBHelper.IsU9())
{
ICSWareHouseService.CreateOtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
}
else
ICSWareHouseService.OtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
}
//其他出库——自动出库
else if (TransType == TransTypeEnum.OtherOutAutoDoc.GetDescription())
{
ICSWareHouseService.OtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
}
//红字其他入库
else if (TransType == TransTypeEnum.OtherInRedDoc.GetDescription())
{
ICSWareHouseService.OtherInRedDocERP(TransType, Identification, cmd, language, BusinessCode);
}
//领料申请单发料
if (TransType == TransTypeEnum.MOApply.GetDescription())
{
ICSManufactureService.MOApplyERP(TransType, Identification, cmd, language, BusinessCode);
}
//补料申请单发料
if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
ICSManufactureService.MOReplenishmentERP(TransType, Identification, cmd, language, BusinessCode);
//委外领料申请单发料
if (TransType == TransTypeEnum.OOApply.GetDescription())
ICSOutsourcingService.OOApplyERP(TransType, Identification, cmd, language, BusinessCode);
//开立材料出库
if (TransType == TransTypeEnum.MOIssue.GetDescription())
{
if (DBHelper.IsU9())
{ ICSManufactureService.U9MOIssueERP(TransType, Identification, cmd, language, BusinessCode); }
else { ICSManufactureService.MOIssueERP(TransType, Identification, cmd, language, BusinessCode); }
}
//开立委外材料出库
if (TransType == TransTypeEnum.OOIssue.GetDescription())
ICSOutsourcingService.OOIssueERP(TransType, Identification, cmd, language, BusinessCode);
//开立红字入库单
if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
ICSPurchaseService.PurchaseReceiveERP(TransType, Identification, cmd, language, BusinessCode);
//开立委外红字入库单
if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
ICSOutsourcingService.OutsourcingReceiveDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
//借用
if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
ICSWareHouseService.BrrowDocERP(TransType, Identification, cmd, language, BusinessCode);
}
if (!printTable.Equals("{}"))
{
cmd.Transaction.Commit();
return printTable;
}
else
{
DataTable table = GetData(Identification, 2, cmd);
cmd.Transaction.Commit();
return table;
}
}
catch (Exception ex)
{
if (cmd.Transaction != null)
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
///
/// 下架奥美
///
///
///
public static DataTable LOTStockDownAMCreate(List JsonData)
{
String PrintEnable = "";
var language = LanguageHelper.GetName("WMSAPIInfo");
if (JsonData.Count <= 0)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
}
List model = new List();
DataTable printTable = new DataTable();
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
string BusinessCode = string.Empty;
string VenCode = string.Empty;
try
{
string TransType = string.Empty;
string Identification = Guid.NewGuid().ToString();
foreach (var item in JsonData)
{
TransType = item.TransType;
if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
{
throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
}
else if (string.IsNullOrEmpty(item.TransCode))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
}
string[] trans = item.TransCode.Split('~');
string MergeID = "";
if (trans.Length == 2)
{
MergeID = trans[0];
item.TransCode = trans[1];
}
#region 采购退货
if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
{
BusinessCode = TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription();
//更新源头单据数量
ICSPurchaseService.PurchaseReceiveDoctNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, "");
}
}
#endregion
#region 委外发料
else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
{
BusinessCode = TransTypeEnum.OutsourcingIssueDoc.GetDescription();
//更新源头单据数量
ICSOutsourcingService.OutsourcingIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingIssueDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 委外退货
else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
{
BusinessCode = TransTypeEnum.OutsourcingReturnBack.GetDescription();
//更新源头单据数量
ICSOutsourcingService.OutsourcingReturnBack(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReturnBack.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, "");
}
}
#endregion
#region 生产发料
else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
{
BusinessCode = TransTypeEnum.MOIssueDoc.GetDescription();
//更新源头单据数量
ICSManufactureService.AMMOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.AMWareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.MOIssueDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 销售出库
else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
{
BusinessCode = TransTypeEnum.SalesShipmentDoc.GetDescription();
//更新源头单据数量
ICSSalesService.SalesShipmentDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID, item.CourierCode);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.SalesShipmentDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 两步调出
else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
{
BusinessCode = TransTypeEnum.TwoStepTransferDocOut.GetDescription();
//更新源头单据数量
ICSWareHouseService.TwoStepTransferDocOut(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocOut.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 其他出库
else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
{
BusinessCode = TransTypeEnum.OtherOutDoc.GetDescription();
//更新源头单据数量
ICSWareHouseService.OtherOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OtherOutDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 领料申请单发料
else if (TransType == TransTypeEnum.MOApply.GetDescription())
{
BusinessCode = TransTypeEnum.MOApply.GetDescription();
//更新源头单据数量
ICSManufactureService.MOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.MOApply.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 补料申请单发料
else if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
{
BusinessCode = TransTypeEnum.MOReplenishment.GetDescription();
//更新源头单据数量
ICSManufactureService.MOReplenishment(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.MOReplenishment.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 委外领料申请单发料
else if (TransType == TransTypeEnum.OOApply.GetDescription())
{
BusinessCode = TransTypeEnum.OOApply.GetDescription();
//更新源头单据数量
ICSOutsourcingService.OOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OOApply.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 开立材料出库
else if (TransType == TransTypeEnum.MOIssue.GetDescription())
{
BusinessCode = TransTypeEnum.MOIssue.GetDescription();
//更新源头单据数量
ICSManufactureService.MOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.MOIssue.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 开立委外材料出库
else if (TransType == TransTypeEnum.OOIssue.GetDescription())
{
BusinessCode = TransTypeEnum.OOIssue.GetDescription();
//更新源头单据数量
ICSOutsourcingService.OOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OOIssue.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
#region 开立红字入库单
else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
{
BusinessCode = TransTypeEnum.PurchaseReceive.GetDescription();
//更新源头单据数量
ICSPurchaseService.PurchaseReceive(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceive.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, "");
}
}
#endregion
#region 开立委外红字入库单
else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
{
BusinessCode = TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription();
//更新源头单据数量
ICSOutsourcingService.OutsourcingReceiveDocNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, "");
}
}
#endregion
#region 借用
else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
{
BusinessCode = TransTypeEnum.BrrowDoc.GetDescription();
//更新源头单据数量
ICSWareHouseService.BrrowDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
foreach (var itemInfo in item.detail)
{
//出库
printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
item.User, item.WorkPoint, "3", TransTypeEnum.BrrowDoc.GetDescription(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
}
}
#endregion
else
{
throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
}
}
//上传ERP
if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
{
//采购退货
if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
ICSPurchaseService.PurchaseReceiveDoctNegativeERP(TransType, Identification, cmd, language, BusinessCode);
//委外发料
else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
ICSOutsourcingService.OutsourcingIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
//委外退货
else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
{
if (DBHelper.IsU9())
{ ICSOutsourcingService.U9OutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode); }
else
ICSOutsourcingService.OutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode);
}
//生产发料
else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
ICSManufactureService.MOIssueDocERP(TransType, Identification, cmd, language, BusinessCode, VenCode);
//销售出库
else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
{
if (DBHelper.IsU9())
{ ICSSalesService.U9SalesShipmentDocERP(TransType, Identification, cmd, language, BusinessCode); }
else { ICSSalesService.SalesShipmentDocERP(TransType, Identification, cmd, language, BusinessCode); }
}
//两步调出
else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
ICSWareHouseService.TwoStepTransferDocOutERP(TransType, Identification, cmd, language, BusinessCode);
//其他出库
else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
{
if (DBHelper.IsU9())
{
ICSWareHouseService.CreateOtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
}
else
ICSWareHouseService.OtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
}
//领料申请单发料
if (TransType == TransTypeEnum.MOApply.GetDescription())
{
ICSManufactureService.MOApplyERP(TransType, Identification, cmd, language, BusinessCode);
}
//补料申请单发料
if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
ICSManufactureService.MOReplenishmentERP(TransType, Identification, cmd, language, BusinessCode);
//委外领料申请单发料
if (TransType == TransTypeEnum.OOApply.GetDescription())
ICSOutsourcingService.OOApplyERP(TransType, Identification, cmd, language, BusinessCode);
//开立材料出库
if (TransType == TransTypeEnum.MOIssue.GetDescription())
{
if (DBHelper.IsU9())
{ ICSManufactureService.U9MOIssueERP(TransType, Identification, cmd, language, BusinessCode); }
else { ICSManufactureService.MOIssueERP(TransType, Identification, cmd, language, BusinessCode); }
}
//开立委外材料出库
if (TransType == TransTypeEnum.OOIssue.GetDescription())
ICSOutsourcingService.OOIssueERP(TransType, Identification, cmd, language, BusinessCode);
//开立红字入库单
if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
ICSPurchaseService.PurchaseReceiveERP(TransType, Identification, cmd, language, BusinessCode);
//开立委外红字入库单
if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
ICSOutsourcingService.OutsourcingReceiveDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
//借用
if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
ICSWareHouseService.BrrowDocERP(TransType, Identification, cmd, language, BusinessCode);
}
if (!printTable.Equals("{}"))
{
cmd.Transaction.Commit();
return printTable;
}
else
{
DataTable table = GetData(Identification, 2, cmd);
cmd.Transaction.Commit();
return table;
}
}
catch (Exception ex)
{
if (cmd.Transaction != null)
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
///
/// 条码检验(海格)
///
///
///
public static DataTable InspectionCreate(List JsonData)
{
var language = LanguageHelper.GetName("WMSAPIInfo");
if (JsonData.Count <= 0)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
}
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
try
{
string asncodes = string.Empty;
string DNCodes = string.Empty;
string DNLotNo = string.Empty;
string sql = string.Empty;
string picname = string.Empty;
string Colspan = "";
string IDD = "";
string whcode = "";
foreach (var item in JsonData)
{
foreach (var itemInfo in item.detail)
{
//判断是否存在记录 存在--更新enable 不存在--insert
if (item.ASNCode != null || item.OASNCode != null)
sql = @"IF exists(select 1 from ICSInspection where lotno ='{4}' and enable = 1)
BEGIN
UPDATE ICSInspection set enable = 0 where lotno ='{4}' and enable = 1
end
insert into ICSInspection (ID,LotNo,InvCode,Quantity,QualifiedQuantity,unQualifiedQuantity,Type,enable,Muser,Musername,Mtime,workPoint,bccode,brcode,WaiveQuantity)
SELECT newid(),a.lotno,a.invcode,a.quantity,{0},a.quantity-{0},{1},1,e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'{5}','{6}','0'
FROM
ICSInventorylot a
INNER JOIN Sys_SRM_User e ON e.F_Account='{2}' AND e.F_Location='{3}'
where a.lotno = '{4}'";
else
sql = @"IF exists(select 1 from ICSInspection where lotno ='{4}' and enable = 1)
BEGIN
UPDATE ICSInspection set enable = 0 where lotno ='{4}' and enable = 1
end
insert into ICSInspection (ID,LotNo,InvCode,Quantity,QualifiedQuantity,unQualifiedQuantity,Type,enable,Muser,Musername,Mtime,workPoint,bccode,brcode,WaiveQuantity)
SELECT newid(),a.lotno,a.invcode,a.quantity,{0},a.quantity-{0},{1},1,e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'{5}','{6}','0'
FROM
ICSMOSubInventoryLot a
INNER JOIN Sys_SRM_User e ON e.F_Account='{2}' AND e.F_Location='{3}'
where a.lotno = '{4}'";
sql = string.Format(sql, itemInfo.Quantity, item.ASNCode == null ? 1 : 3, item.User, item.WorkPoint, itemInfo.LotNo, itemInfo.BCCode, itemInfo.BRCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo010")); //"送货单子表信息更新失败!");
}
}
}
cmd.Transaction.Commit();
return null;
}
catch (Exception ex)
{
if (cmd.Transaction != null)
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
#region 采购
///
/// 采购到货
///
///
///
public static DataTable DeliveryNoticeCreate(List JsonData)
{
var language = LanguageHelper.GetName("WMSAPIInfo");
string resultStr = string.Empty;
if (JsonData.Count <= 0)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
}
using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
{
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Transaction = sqlTran;
cmd.Connection = conn;
cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
try
{
string asncodes = string.Empty;
string DNCodes = string.Empty;
string DNLotNo = string.Empty;
string sql = string.Empty;
string picname = string.Empty;
string Colspan = "";
string IDD = "";
string whcode = "";
foreach (var item in JsonData)
{
if (string.IsNullOrEmpty(item.ASNCode))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!"
}
sql = @"SELECT a.DNCode FROM ICSDeliveryNotice a WHERE a.ASNCode='{0}' AND DNType = '1' AND a.WorkPoint='{1}'";
sql = string.Format(sql, item.ASNCode, item.WorkPoint);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count > 0)
{
DNCodes = dt.Rows[0]["DNCode"].ToString();
}
//获取单号
sql = @"IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.ASNCode='{0}' AND DNType = '1' AND a.WorkPoint='{1}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
RETURN
END
DECLARE @Status VARCHAR(10)
SELECT @Status=Status FROM ICSASN WHERE ASNCode='{0}' and WorkPoint='{1}'
IF (@Status IS NULL)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
RETURN
END
ELSE IF (@Status!='2')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
RETURN
END
DECLARE @MaxNO INT,@date varchar(20)='DN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
IF @MaxNO IS NULL
BEGIN
SELECT @date+'00001' AS Code
END
ELSE
BEGIN
SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
END ";
sql = string.Format(sql, item.ASNCode, item.WorkPoint, DNCodes);
string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
//修改送货单到货数量
foreach (var itemInfo in item.detail)
{
if (string.IsNullOrEmpty(itemInfo.TransSequence))
{
picname = "";
}
else
{
picname = itemInfo.TransSequence;
}
sql = @"
UPDATE ICSASNDetail SET DNQuantity=ISNULL(DNQuantity, 0)+'{2}'
WHERE LotNo='{0}' AND WorkPoint='{1}'
IF EXISTS(SELECT id FROM ICSASNDetail WHERE LotNo='{0}' AND WorkPoint='{1}' AND Quantity 0 && dtdao != null)
{
whcode = dtdao.Rows[0]["F_itemCode"].ToString();
//创建到货单信息
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
RETURN
END
Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10)
SELECT DISTINCT newid(),ISNULL(ext.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END+'~'+ISNULL(ext.Version, '')+'~'+ISNULL(ext.Brand, '')+'~'+
ISNULL(ext.cFree1, '')+'~'+ISNULL(ext.cFree2, '')+'~'+ISNULL(ext.cFree3, '')+'~'+ISNULL(ext.cFree4, '')+'~'+ISNULL(ext.cFree5, '')+'~'+ISNULL(ext.cFree6, '')+'~'+ISNULL(ext.cFree7, '')+'~'+ISNULL(ext.cFree8, '')+'~'+ISNULL(ext.cFree9, '')+'~'+ISNULL(ext.cFree10, ''),ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
FROM ICSASNDetail a
INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSExtension ext ON b.ExtensionID=ext.ID AND b.WorkPoint=ext.WorkPoint
LEFT JOIN ICSInventory inv ON b.InvCode=inv.InvCode AND b.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON b.InvCode=invBat.InvCode AND '{5}'=invBat.WHCode AND b.WorkPoint=invBat.WorkPoint
INNER JOIN ICSExtension extt ON ISNULL(ext.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END+'~'+ISNULL(ext.Version, '')+'~'+ISNULL(ext.Brand, '')+'~'+
ISNULL(ext.cFree1, '')+'~'+ISNULL(ext.cFree2, '')+'~'+ISNULL(ext.cFree3, '')+'~'+ISNULL(ext.cFree4, '')+'~'+ISNULL(ext.cFree5, '')+'~'+ISNULL(ext.cFree6, '')+'~'+ISNULL(ext.cFree7, '')+'~'+ISNULL(ext.cFree8, '')+'~'+ISNULL(ext.cFree9, '')+'~'+ISNULL(ext.cFree10, '')=extt.Colspan
WHERE a.ASNCode='{3}' AND a.WorkPoint='{2}' and a.DNQuantity>0 AND ext.id is NULL
INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
DNType,InvCode,Quantity,Amount,RCVQuantity,
UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
POID,PODetailID,DNID,DNDetailID,ExtensionID,
MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode,EATTRIBUTE8)
SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
'1',b.InvCode,SUM(a.DNQuantity),'0','0',
d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
d.POID,d.PODetailID,'{0}',newid(),extt.ID,
e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.ASNCode,'{4}'
FROM ICSASNDetail a
INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSExtension ext ON b.ExtensionID=ext.ID AND b.WorkPoint=ext.WorkPoint
LEFT JOIN ICSInventory inv ON b.InvCode=inv.InvCode AND b.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON b.InvCode=invBat.InvCode AND '{5}'=invBat.WHCode AND b.WorkPoint=invBat.WorkPoint
INNER JOIN ICSExtension extt ON ISNULL(ext.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END+'~'+ISNULL(ext.Version, '')+'~'+ISNULL(ext.Brand, '')+'~'+
ISNULL(ext.cFree1, '')+'~'+ISNULL(ext.cFree2, '')+'~'+ISNULL(ext.cFree3, '')+'~'+ISNULL(ext.cFree4, '')+'~'+ISNULL(ext.cFree5, '')+'~'+ISNULL(ext.cFree6, '')+'~'+ISNULL(ext.cFree7, '')+'~'+ISNULL(ext.cFree8, '')+'~'+ISNULL(ext.cFree9, '')+'~'+ISNULL(ext.cFree10, '')=extt.Colspan
INNER JOIN ICSPurchaseOrder d ON c.TransCode=d.POCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
WHERE a.ASNCode='{3}' AND a.WorkPoint='{2}' and a.DNQuantity>0
GROUP BY d.POID,d.PODetailID,d.VenCode,d.UnitPrice,d.Currency,d.DepCode,b.InvCode,a.ASNCode,e.F_Account,e.F_RealName,a.WorkPoint,extt.ID";
sql = string.Format(sql, Code, item.User, item.WorkPoint, item.ASNCode, picname, whcode);
}
else
{
//创建到货单信息
sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
BEGIN
RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
RETURN
END
INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
DNType,InvCode,Quantity,Amount,RCVQuantity,
UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
POID,PODetailID,DNID,DNDetailID,ExtensionID,
MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode,EATTRIBUTE8)
SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
'1',b.InvCode,SUM(a.DNQuantity),'0','0',
d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
d.POID,d.PODetailID,'{0}',newid(),b.ExtensionID,
e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.ASNCode,'{4}'
FROM ICSASNDetail a
INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSPurchaseOrder d ON c.TransCode=d.POCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
WHERE a.ASNCode='{3}' AND a.WorkPoint='{2}' and a.DNQuantity>0
GROUP BY d.POID,d.PODetailID,d.VenCode,d.UnitPrice,d.Currency,d.DepCode,b.ExtensionID,b.InvCode,a.ASNCode,e.F_Account,e.F_RealName,a.WorkPoint";
sql = string.Format(sql, Code, item.User, item.WorkPoint, item.ASNCode, picname);
}
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!");
}
string sqlCheckSign = @"select * from ICSConfiguration where code = 'UploadERP001' and enable = '1'";
DataTable flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
if (flag != null && flag.Rows.Count > 0)
{
if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
{
resultStr = ICSPurchaseService.DeliveryNoticeERP(Code, item.WorkPoint, cmd, language);
}
}
asncodes += "'" + item.ASNCode + item.WorkPoint + "',";
}
if (string.IsNullOrWhiteSpace(asncodes))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!");
}
#region 查询返回数据
sql = @"SELECT
n.POCode,
n.Sequence AS POSequence,
a.ASNCode,
a.DNCode,
a.Sequence,
a.VenCode,
a.DepCode,
a.InvCode,
inv.InvName,
inv.InvStd,
a.Quantity,
inv.InvUnit,
a.Amount,
inv.AmountUnit,
a.RCVQuantity,
a.UnitPrice,
a.Currency,
a.POID,
a.PODetailID,
a.DNID,
a.DNDetailID,
ext.ProjectCode,
ext.BatchCode,
ext.Version,
ext.Brand,
ext.cFree1,
ext.cFree2,
ext.cFree3,
ext.cFree4,
ext.cFree5,
ext.cFree6,
ext.cFree7,
ext.cFree8,
ext.cFree9,
ext.cFree10,
a.MUSER AS [User],
a.MTIME AS [MTime]
FROM ICSDeliveryNotice a
INNER JOIN ICSPurchaseOrder n ON a.POID =n.POID AND a.PODetailID=n.PODetailID AND a.WorkPoint=n.WorkPoint
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
WHERE a.ASNCode+a.WorkPoint IN ({0})";
sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1));
DataTable data = DBHelper.SQlReturnData(sql, cmd);
#endregion
cmd.Transaction.Commit();
return data;
}
catch (SqlException ex) when (ex.Number == 1205)
{
log.Error("采购到货捕获到死锁错误:" + Environment.NewLine + ex.ToString());
log.Error("ERP接口返回值:" + Environment.NewLine + resultStr);
if (resultStr != null && resultStr != string.Empty)
{
JArray paramArr = new JArray();
Result result = JsonConvert.DeserializeObject(resultStr);
JArray res = JsonConvert.DeserializeObject(result.Data.ToString());
foreach (var item in res)
{
JObject paramObj = new JObject();
JObject jo = (JObject)item;
paramObj.Add("DNCode", jo["DNCode"].ToString());
paramObj.Add("WorkPoint", jo["WorkPoint"].ToString());
paramObj.Add("User", JsonData[0].User);
paramObj.Add("MTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
paramArr.Add(paramObj);
}
log.Info("调用ERP删除到货单接口:" + Environment.NewLine + ERPUrl.CreatePOArriveDelete + Environment.NewLine + JsonConvert.SerializeObject(paramArr));
HTTPHelper.HttpPost("采购到货", ERPUrl.CreatePOArriveDelete, JsonConvert.SerializeObject(paramArr));
if (cmd.Transaction != null)
cmd.Transaction.Rollback();
}
throw new Exception(ex.Message);
}
catch (Exception ex)
{
if (ex.Message.Contains("死锁"))
{
log.Error("采购到货死锁:" + Environment.NewLine + ex.ToString());
log.Error("ERP接口返回值:" + Environment.NewLine + resultStr);
if (resultStr != null && resultStr != string.Empty)
{
JArray paramArr = new JArray();
Result result = JsonConvert.DeserializeObject(resultStr);
JArray res = JsonConvert.DeserializeObject(result.Data.ToString());
foreach (var item in res)
{
JObject paramObj = new JObject();
JObject jo = (JObject)item;
paramObj.Add("DNCode", jo["DNCode"].ToString());
paramObj.Add("WorkPoint", jo["WorkPoint"].ToString());
paramObj.Add("User", JsonData[0].User);
paramObj.Add("MTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
paramArr.Add(paramObj);
}
log.Info("调用ERP删除到货单接口:" + Environment.NewLine + ERPUrl.CreatePOArriveDelete + Environment.NewLine + JsonConvert.SerializeObject(paramArr));
HTTPHelper.HttpPost("采购到货", ERPUrl.CreatePOArriveDelete, JsonConvert.SerializeObject(paramArr));
}
}
if (cmd.Transaction != null)
cmd.Transaction.Rollback();
log.Error(ex.Message);
throw new Exception(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
conn.Dispose();
}
}
}
///