You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

3720 lines
277 KiB

using ICSSoft.Common;
using ICSSoft.Entity;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
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;
namespace ICSSoft.DataProject
{
/// <summary>
/// 使用中
/// 生产模块
/// </summary>
public class ICSManufactureService
{
private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#region 生产发料
/// <summary>
/// 生产发料
/// </summary>
/// <param name="TransCode"></param>
/// <param name="TransSequence"></param>
/// <param name="Quantity"></param>
/// <param name="WorkPoint"></param>
/// <param name="cmd"></param>
public static void MOIssueDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string enableCode,string TransID)
{
try
{
string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=b.ERPStatus FROM ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' and a.id='{5}' AND a.WorkPoint='{1}'
IF (@Status IS NULL)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo125") + @"',16,1);
RETURN
END
ELSE IF (@Status!='2')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo126") + @"',16,1);
RETURN
END
UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
FROM ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' and a.id='{5}' AND a.WorkPoint='{1}'
--IF EXISTS(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 b.Sequence+'~'+a.Sequence='{3}' and a.WorkPoint='{1}'
-- AND (dbo.GetExcessQty(a.InvCode, b.Sequence+'~'+a.Sequence, b.MOCode, a.WorkPoint,'{4}'))<a.IssueQuantity)
--BEGIN
--RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
--RETURN
--END
";
sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, enableCode, TransID);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo127"));//"生产领料单更新失败!");
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 生产发料
/// </summary>
/// <param name="TransCode"></param>
/// <param name="TransSequence"></param>
/// <param name="Quantity"></param>
/// <param name="WorkPoint"></param>
/// <param name="cmd"></param>
public static void AMMOIssueDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string enableCode)
{
try
{
string cheksql = @"select c.EATTRIBUTE1 FROM ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSInventory c on a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}' and c.AmountEnable='1'";
cheksql = string.Format(cheksql, TransCode, WorkPoint, Quantity, TransSequence, enableCode);
DataTable dt = DBHelper.SQlReturnData(cheksql, cmd);
if (dt.Rows.Count > 0)
{
Quantity = (decimal.Parse(Quantity) * decimal.Parse(dt.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
}
string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=b.ERPStatus FROM ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}'
IF (@Status IS NULL)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo125") + @"',16,1);
RETURN
END
ELSE IF (@Status!='2')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo126") + @"',16,1);
RETURN
END
UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
FROM ICSMOPick a
INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}'
--IF EXISTS(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 b.Sequence+'~'+a.Sequence='{3}' and a.WorkPoint='{1}'
-- AND (dbo.GetExcessQty(a.InvCode, b.Sequence+'~'+a.Sequence, b.MOCode, a.WorkPoint,'{4}'))<a.IssueQuantity)
--BEGIN
--RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
--RETURN
--END
";
sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, enableCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo127"));//"生产领料单更新失败!");
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 生产发料接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void MOIssueDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode,string VenCode)
{
try
{
#region ERP
string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode,transid
INTO #NewTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '{1}'
SELECT isnull(y.DepCode,'')+a.FromWarehouseCode+y.MOCode+a.MUSER AS Costre,y.DepCode,a.FromWarehouseCode AS WarehouseCode,y.MOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.FromWarehouseCode,y.MOCode,x.PickID,a.InvCode) AS Sequence,CAST(SUBSTRING(a.TransSequence, CHARINDEX('~', a.TransSequence) + 1, LEN(a.TransSequence)) AS INT) AS TransSequence,
a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(x.Amount/x.Quantity)) ELSE '0' END AS Amount,x.PickID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
,a.WorkPoint,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,conv.Enable AS CompleteVerification
,'1'as DocTypeCode,inv.InvRate
INTO #TempERP
FROM #NewTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSMO y ON a.TransCode=y.MOCode AND a.WorkPoint=y.WorkPoint
INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence and a.transid=x.id AND x.WorkPoint=y.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
GROUP BY conWhCode.Enable,a.TransSequence,inv.AmountEnable,y.DepCode,a.FromWarehouseCode,y.MOCode,a.MUSER,a.InvCode,x.PickID,x.MODetailID,con.Enable,conv.Enable,conStock.Enable,inv.InvRate
,a.WorkPoint,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, '')
SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'生产订单' AS SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock FROM #TempERP
SELECT TransSequence AS SubLineNO,WarehouseCode AS WHCode,Costre,'{2}' AS Vender,Sequence,InvCode,InvRate,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,PickID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
DROP TABLE #TempERP
DROP TABLE #NewTempERP";
sql = string.Format(sql, Identification, BusinessCode, VenCode);
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
string resultStr = "";
//if (DBHelper.IsU9())
//{
// resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9MOIssueDocURL, Inputstr);
//}
//else
//{
resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOIssueDocURL, Inputstr);
//}
Result result = new Result();
result = JsonConvert.DeserializeObject<Result>(resultStr);
if (result.Success)
{
try
{
JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
foreach (var item in res)
{
JObject jo = (JObject)item;
JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
foreach (var detail in resdetail)
{
JObject det = (JObject)detail;
string allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
+ det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol,cmd, language, BusinessCode);
}
}
}
catch (Exception ex)
{
log.Debug(ex.ToString());
log.Debug(resultStr);
}
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
}
#endregion
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 达翔生产发料接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void DXMOIssueDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
{
try
{
#region ERP
string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode,transid
INTO #NewTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '13'
SELECT isnull(y.DepCode,'')+a.FromWarehouseCode+y.MOCode+a.MUSER AS Costre,y.DepCode,a.FromWarehouseCode AS WarehouseCode,y.MOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.FromWarehouseCode,y.MOCode,x.PickID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(x.Amount/x.Quantity)) ELSE '0' END AS Amount,x.PickID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
,a.WorkPoint,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,conv.Enable AS CompleteVerification
,'1'as DocTypeCode
INTO #TempERP
FROM #NewTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSMO y ON a.TransCode=y.MOCode AND a.WorkPoint=y.WorkPoint
INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence and a.transid=x.id AND x.WorkPoint=y.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
GROUP BY inv.AmountEnable,y.DepCode,a.FromWarehouseCode,y.MOCode,a.MUSER,a.InvCode,x.PickID,x.MODetailID,con.Enable,conv.Enable,conStock.Enable
,a.WorkPoint,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, '')
SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'生产订单' AS SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock FROM #TempERP
SELECT WarehouseCode AS WHCode,Costre,Sequence,InvCode,Quantity,Amount,PickID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
DROP TABLE #TempERP
DROP TABLE #NewTempERP";
sql = string.Format(sql, Identification);
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
string resultStr = "";
//if (DBHelper.IsU9())
//{
// resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9MOIssueDocURL, Inputstr);
//}
//else
//{
resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DXMOIssueDocURL, Inputstr);
//}
Result result = new Result();
result = JsonConvert.DeserializeObject<Result>(resultStr);
if (result.Success)
{
try
{
JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
foreach (var item in res)
{
JObject jo = (JObject)item;
JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
foreach (var detail in resdetail)
{
JObject det = (JObject)detail;
string allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
+ det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
}
}
}
catch (Exception ex)
{
log.Debug(ex.ToString());
log.Debug(resultStr);
}
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
}
#endregion
}
catch (Exception)
{
throw;
}
}
#endregion
#region 补料申请单生产发料
/// <summary>
/// 补料申请单生产发料
/// </summary>
/// <param name="TransCode"></param>
/// <param name="TransSequence"></param>
/// <param name="Quantity"></param>
/// <param name="WorkPoint"></param>
/// <param name="cmd"></param>
public static void MOReplenishment(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string enableCode)
{
try
{
string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=a.Status FROM ICSMOReplenishment a
WHERE a.ReplenishmentCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
IF (@Status IS NULL)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo128") + @"',16,1);
RETURN
END
ELSE IF (@Status!='2')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo129") + @"',16,1);
RETURN
END
UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
FROM ICSMOReplenishment a
WHERE a.ReplenishmentCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
IF EXISTS(SELECT a.ID FROM ICSMOReplenishment a
WHERE a.ReplenishmentCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}'
AND (dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{4}',2,2,''))<a.IssueQuantity)
-- AND (dbo.GetExcessQty(a.InvCode, a.Sequence, a.ReplenishmentCode, a.WorkPoint,'{4}'))<a.IssueQuantity)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
RETURN
END";
sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence,enableCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo130"));//"领料申请单更新失败!");
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 补料申请单生产发料接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void MOReplenishmentERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
{
try
{
#region ERP
string sql = @"SELECT a.FromWarehouseCode+b.ReplenishmentCode+ISNULL(c.DepCode,'')+a.MUSER AS Costre,a.FromWarehouseCode AS WarehouseCode,b.ReplenishmentCode,ISNULL(c.DepCode,'')AS DepCode,b.SourceCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,b.ReplenishmentCode,b.ReplenishmentDetailID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(b.Amount/b.Quantity)) ELSE '0' END AS Amount,b.ReplenishmentDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
,a.WorkPoint,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,conv.Enable AS CompleteVerification
INTO #TempERP
FROM ICSWareHouseLotInfoLog 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSMOReplenishment b ON a.TransCode=b.ReplenishmentCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
LEFT JOIN ICSMO c ON b.SourceCode=c.MOCode AND b.SourceSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '49'
GROUP BY conWhCode.Enable,c.DepCode,inv.AmountEnable,a.FromWarehouseCode,b.ReplenishmentCode,b.SourceCode,a.MUSER,a.InvCode,b.ReplenishmentDetailID,con.Enable,conv.Enable,conStock.Enable
,a.WorkPoint,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, '')
SELECT DISTINCT Costre,WorkPoint,ISNULL(DepCode,'') AS DepCode,WarehouseCode AS WHCode,'补料申请单' AS SourceType,ReplenishmentCode AS SourceCode,SourceCode AS IssueCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock FROM #TempERP
SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,ReplenishmentDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
DROP TABLE #TempERP";
sql = string.Format(sql, Identification);
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOReplenishmentURL, Inputstr);
Result result = new Result();
result = JsonConvert.DeserializeObject<Result>(resultStr);
if (result.Success)
{
try
{
JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
foreach (var item in res)
{
JObject jo = (JObject)item;
JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
foreach (var detail in resdetail)
{
JObject det = (JObject)detail;
string allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
+ det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
}
}
}
catch (Exception ex)
{
log.Debug(ex.ToString());
log.Debug(resultStr);
}
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
}
#endregion
}
catch (Exception)
{
throw;
}
}
#endregion
#region 领料申请单生产发料
/// <summary>
/// 领料申请单生产发料
/// </summary>
/// <param name="TransCode"></param>
/// <param name="TransSequence"></param>
/// <param name="Quantity"></param>
/// <param name="WorkPoint"></param>
/// <param name="cmd"></param>
public static void MOApply(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string enableCode, string TransID)
{
try
{
string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=a.Status FROM ICSMOApply a
WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{5}'
IF (@Status IS NULL)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo128") + @"',16,1);
RETURN
END
ELSE IF (@Status!='2')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo129") + @"',16,1);
RETURN
END
UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
FROM ICSMOApply a
WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{5}'
IF EXISTS(SELECT a.ID FROM ICSMOApply a
WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' and a.id='{5}' and a.WorkPoint='{1}'
AND (dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{4}',2,2,''))<a.IssueQuantity)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
RETURN
END";
sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, enableCode, TransID);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo130"));//"领料申请单更新失败!");
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 领料申请单生产发料接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void MOApplyERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
{
try
{
#region ERP
string sql = string.Empty;
string Checksql = string.Empty;
Checksql = @"SELECT a.F_Id
FROM Sys_SRM_ItemsDetail a
INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
WHERE b.F_EnCode='BatchInOutErp' AND a.F_ItemCode='BatchOut' AND a.F_EnabledMark='1'";
Checksql = string.Format(Checksql);
DataTable dtdao = DBHelper.SQlReturnData(Checksql, cmd);
if (dtdao.Rows.Count > 0 && dtdao != null)
{
string checksql = @"select SUM(b.Quantity) AS SUMQty,SUM(b.IssueQuantity) AS ISSQty,a.transCode from ICSMOApply b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.ApplyCode AND a.WorkPoint=b.WorkPoint
where a.Identification='{0}' GROUP BY a.transCode";
checksql = string.Format(checksql, Identification);
DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
string trancode = chekdt.Rows[0]["transCode"].ToString();
if (SUMQty - ISSQty == 0)
{
string pnsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode,transid
INTO #NewTempERP
from ICSWareHouseLotInfoLog
WHERE TransCode='{0}' AND ERPUpload='0' AND BusinessCode = '14' and EATTRIBUTE1<>'1'
SELECT (CASE WHEN isnull(conWhCode.Enable,0)='0' then a.FromWarehouseCode ELSE '' END)+b.ApplyCode+a.MUSER+ISNULL(b.SourceCode,'')+ISNULL(c.DepCode,'') AS Costre,a.FromWarehouseCode AS WarehouseCode,b.ApplyCode,ISNULL(b.SourceCode,'') AS SourceCode,ISNULL(c.DepCode,'') AS DepCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,b.ApplyCode,b.ApplyDetailID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(b.Amount/b.Quantity)) ELSE '0' END AS Amount,b.ApplyDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
,a.WorkPoint,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,conv.Enable AS CompleteVerification
,b.EATTRIBUTE2 as DocType,b.EATTRIBUTE4 as ClientCode,b.EATTRIBUTE7 as Project,b.EATTRIBUTE as Dep,a.transcode as HcFree4,b.EATTRIBUTE5 as HcFree2,b.EATTRIBUTE8 as HcFree3,b.EATTRIBUTE3 as HcFree1
INTO #TempERP
FROM #NewTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSMOApply b ON a.TransCode=b.ApplyCode AND a.TransSequence=b.Sequence and a.transid=b.id AND a.WorkPoint=b.WorkPoint
LEFT JOIN ICSMO c ON b.SourceCode=c.MOCode AND b.SourceSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
GROUP BY inv.AmountEnable,conWhCode.Enable,a.FromWarehouseCode,b.ApplyCode,b.SourceCode,c.DepCode,a.MUSER,a.InvCode,b.ApplyDetailID,con.Enable,conv.Enable,conStock.Enable
,a.WorkPoint,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, ''),b.EATTRIBUTE2,b.EATTRIBUTE4,b.EATTRIBUTE,b.EATTRIBUTE7,a.transcode,b.EATTRIBUTE5 ,b.EATTRIBUTE8,b.EATTRIBUTE3
SELECT DISTINCT Costre,WorkPoint,ISNULL(DepCode,'') AS DepCode,CASE WHEN isnull(ErpWhCode,0)='0' then WarehouseCode ELSE '' END AS WHCode,'领料申请单' AS SourceType,ApplyCode AS SourceCode,ISNULL(SourceCode,'') AS IssueCode ,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,DocType,ClientCode,HcFree4,HcFree2,HcFree3,HcFree1 FROM #TempERP
SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,ApplyDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,Project,Dep FROM #TempERP
DROP TABLE #TempERP
DROP TABLE #NewTempERP";
pnsql = string.Format(pnsql, trancode);
DataSet dss = DBHelper.SQlReturnDataSet(pnsql, cmd);
string Inputstrr = DataToJsonHelper.DataSetToJson(dss, "details", "Costre");
string resultStrr = "";
if (DBHelper.IsU9())
{ resultStrr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateOtherOutDocURL, Inputstrr); }
else
{ resultStrr = HTTPHelper.HttpPost(TransType, ERPUrl.MOApplyURL, Inputstrr); }
Result result = new Result();
result = JsonConvert.DeserializeObject<Result>(resultStrr);
if (result.Success)
{
try
{
JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
foreach (var item in res)
{
JObject jo = (JObject)item;
JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
foreach (var detail in resdetail)
{
JObject det = (JObject)detail;
string allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
+ det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
}
}
}
catch (Exception ex)
{
log.Debug(ex.ToString());
log.Debug(resultStrr);
}
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
}
}
}
else
{
if (DBHelper.IsPNU9())
{
sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode,transid
INTO #NewTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '14'
SELECT (CASE WHEN isnull(conWhCode.Enable,0)='0' then a.FromWarehouseCode ELSE '' END)+b.ApplyCode+a.MUSER+ISNULL(c.DepCode,'') AS Costre,a.FromWarehouseCode AS WarehouseCode,b.ApplyCode,ISNULL(b.SourceCode,'') AS SourceCode,ISNULL(c.DepCode,'') AS DepCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,b.ApplyCode,b.ApplyDetailID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(b.Amount/b.Quantity)) ELSE '0' END AS Amount,b.ApplyDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
,a.WorkPoint,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,conv.Enable AS CompleteVerification
,b.EATTRIBUTE2 as DocType,b.EATTRIBUTE4 as ClientCode,b.EATTRIBUTE7 as Project,b.EATTRIBUTE as Dep,a.transcode as HcFree4,b.EATTRIBUTE5 as HcFree2,b.EATTRIBUTE8 as HcFree3,b.EATTRIBUTE3 as HcFree1
INTO #TempERP
FROM #NewTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSMOApply b ON a.TransCode=b.ApplyCode AND a.TransSequence=b.Sequence and a.transid=b.id AND a.WorkPoint=b.WorkPoint
LEFT JOIN ICSMO c ON b.SourceCode=c.MOCode AND b.SourceSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
GROUP BY inv.AmountEnable,conWhCode.Enable,a.FromWarehouseCode,b.ApplyCode,b.SourceCode,c.DepCode,a.MUSER,a.InvCode,b.ApplyDetailID,con.Enable,conv.Enable,conStock.Enable
,a.WorkPoint,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, ''),b.EATTRIBUTE2,b.EATTRIBUTE4,b.EATTRIBUTE,b.EATTRIBUTE7,a.transcode,b.EATTRIBUTE5 ,b.EATTRIBUTE8,b.EATTRIBUTE3
SELECT DISTINCT Costre,WorkPoint,ISNULL(DepCode,'') AS DepCode,CASE WHEN isnull(ErpWhCode,0)='0' then WarehouseCode ELSE '' END AS WHCode,'领料申请单' AS SourceType,ApplyCode AS SourceCode,'' AS IssueCode ,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,DocType,ClientCode,HcFree4,HcFree2,HcFree3,HcFree1 FROM #TempERP
SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,ApplyDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,Project,Dep FROM #TempERP
DROP TABLE #TempERP
DROP TABLE #NewTempERP";
}
else
{
sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode,transid
INTO #NewTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '14'
SELECT (CASE WHEN isnull(conWhCode.Enable,0)='0' then a.FromWarehouseCode ELSE '' END)+b.ApplyCode+a.MUSER+ISNULL(b.SourceCode,'')+ISNULL(c.DepCode,'') AS Costre,a.FromWarehouseCode AS WarehouseCode,b.ApplyCode,ISNULL(b.SourceCode,'') AS SourceCode,ISNULL(c.DepCode,'') AS DepCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,b.ApplyCode,b.ApplyDetailID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(b.Amount/b.Quantity)) ELSE '0' END AS Amount,b.ApplyDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
,a.WorkPoint,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,conv.Enable AS CompleteVerification
,b.EATTRIBUTE2 as DocType,b.EATTRIBUTE4 as ClientCode,b.EATTRIBUTE7 as Project,b.EATTRIBUTE as Dep,a.transcode as HcFree4,b.EATTRIBUTE5 as HcFree2,b.EATTRIBUTE8 as HcFree3,b.EATTRIBUTE3 as HcFree1
INTO #TempERP
FROM #NewTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSMOApply b ON a.TransCode=b.ApplyCode AND a.TransSequence=b.Sequence and a.transid=b.id AND a.WorkPoint=b.WorkPoint
LEFT JOIN ICSMO c ON b.SourceCode=c.MOCode AND b.SourceSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
GROUP BY inv.AmountEnable,conWhCode.Enable,a.FromWarehouseCode,b.ApplyCode,b.SourceCode,c.DepCode,a.MUSER,a.InvCode,b.ApplyDetailID,con.Enable,conv.Enable,conStock.Enable
,a.WorkPoint,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, ''),b.EATTRIBUTE2,b.EATTRIBUTE4,b.EATTRIBUTE,b.EATTRIBUTE7,a.transcode,b.EATTRIBUTE5 ,b.EATTRIBUTE8,b.EATTRIBUTE3
SELECT DISTINCT Costre,WorkPoint,ISNULL(DepCode,'') AS DepCode,CASE WHEN isnull(ErpWhCode,0)='0' then WarehouseCode ELSE '' END AS WHCode,'领料申请单' AS SourceType,ApplyCode AS SourceCode,ISNULL(SourceCode,'') AS IssueCode ,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,DocType,ClientCode,HcFree4,HcFree2,HcFree3,HcFree1 FROM #TempERP
SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,ApplyDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,Project,Dep FROM #TempERP
DROP TABLE #TempERP
DROP TABLE #NewTempERP";
}
//,ClientCode,HcFree4,HcFree2,HcFree3,HcFree1
sql = string.Format(sql, Identification);
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
string resultStr = "";
if (DBHelper.IsU9())
{ resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateOtherOutDocURL, Inputstr); }
else
{ resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOApplyURL, Inputstr); }
Result result = new Result();
result = JsonConvert.DeserializeObject<Result>(resultStr);
if (result.Success)
{
try
{
JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
foreach (var item in res)
{
JObject jo = (JObject)item;
JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
foreach (var detail in resdetail)
{
JObject det = (JObject)detail;
string allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
+ det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
}
}
}
catch (Exception ex)
{
log.Debug(ex.ToString());
log.Debug(resultStr);
}
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
}
}
#endregion
}
catch (Exception)
{
throw;
}
}
#endregion
#region 材料出库单生产发料
/// <summary>
/// 材料出库单生产发料
/// </summary>
/// <param name="TransCode"></param>
/// <param name="TransSequence"></param>
/// <param name="Quantity"></param>
/// <param name="WorkPoint"></param>
/// <param name="cmd"></param>
public static void MOIssue(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string enableCode,string TransID)
{
try
{
string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=a.Status FROM ICSMOIssue a
WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.id='{4}' AND a.WorkPoint='{1}'
IF (@Status IS NULL)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo131") + @"',16,1);
RETURN
END
ELSE IF (@Status!='1')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo132") + @"',16,1);
RETURN
END
UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
FROM ICSMOIssue a
WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.id='{4}' AND a.WorkPoint='{1}'
IF EXISTS(SELECT a.ID FROM ICSMOIssue a
WHERE a.IssueCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.id='{4}'
AND dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{5}',2,2,'')<a.IssueQuantity)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
RETURN
END";
sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID, enableCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo133"));//"材料出库单更新失败!");
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 材料出库单生产发料接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void MOIssueERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
{
try
{
#region ERP开立状态单据审核
string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
INTO #NewTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '15'
IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSMOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
WHERE a.Identification='{0}' AND b.Quantity>b.IssueQuantity)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo094") + @"',16,1);
RETURN
END
SELECT b.IssueID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity
,conStock.Enable AS UpdateStock,a.WorkPoint
FROM #NewTempERP a
INNER JOIN ICSMOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
GROUP BY b.IssueID,a.MUSER,con.Enable
,conStock.Enable,a.WorkPoint
DROP TABLE #NewTempERP";
sql = string.Format(sql, Identification);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
string Inputstr = JsonConvert.SerializeObject(dt);
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOIssueURL, Inputstr);
Result result = new Result();
result = JsonConvert.DeserializeObject<Result>(resultStr);
if (result.Success)
{
try
{
foreach (DataRow dr in dt.Rows)
{
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "",cmd, language, BusinessCode);
}
}
catch (Exception ex)
{
log.Debug(ex.ToString());
log.Debug(resultStr);
}
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
}
#endregion
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// U9超额领料单接口 审核改创建
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void U9MOIssueERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
{
try
{
#region ERP
// IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
// INNER JOIN ICSMOIssue b ON a.TransCode= b.IssueCode AND a.TransSequence= b.Sequence AND a.WorkPoint= b.WorkPoint
// WHERE a.Identification= '{0}' AND b.Quantity! = b.IssueQuantity)
// BEGIN
// RAISERROR('" + language.GetNameByCode("WMSAPIInfo094") + @"', 16, 1);
// RETURN
//END
string sql = @"
select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
INTO #NewTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '15'
SELECT --a.FromWarehouseCode+
b.IssueCode+a.MUSER+ISNULL(b.SourceCode,'')+ISNULL(c.DepCode,'') AS Costre,a.FromWarehouseCode AS WarehouseCode,b.IssueCode,ISNULL(b.SourceCode,'') AS SourceCode,ISNULL(c.DepCode,'') AS DepCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,b.IssueCode,b.IssueDetailID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(b.Amount/b.Quantity)) ELSE '0' END AS Amount,b.IssueDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
,a.WorkPoint,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,conv.Enable AS CompleteVerification
,b.EATTRIBUTE2 as DocType,b.EATTRIBUTE4 as ClientCode,b.EATTRIBUTE5 as SuperCollarMessage
INTO #TempERP
FROM #NewTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSMoIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
LEFT JOIN ICSMO c ON b.SourceCode=c.MOCode AND b.SourceSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
GROUP BY inv.AmountEnable,a.FromWarehouseCode,b.IssueCode,b.SourceCode,c.DepCode,a.MUSER,a.InvCode,b.IssueDetailID,con.Enable,conv.Enable,conStock.Enable
,a.WorkPoint,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, ''),b.EATTRIBUTE2,b.EATTRIBUTE4,b.EATTRIBUTE5
SELECT DISTINCT Costre,WorkPoint,ISNULL(DepCode,'') AS DepCode,'领料申请单' AS SourceType,ISNULL(SourceCode,'') AS SourceCode,ISNULL(SourceCode,'') AS IssueCode ,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock, '18' as DocTypeCode,ClientCode,SuperCollarMessage FROM #TempERP -- WarehouseCode AS WHCode ,IssueCode AS SourceCode
SELECT WarehouseCode AS WHCode,Costre,Sequence,InvCode,Quantity,Amount,IssueDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
DROP TABLE #TempERP
DROP TABLE #NewTempERP";
sql = string.Format(sql, Identification);
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
string resultStr = "";
//resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9MOApplyURL, Inputstr);
resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9MOIssueDocURL, Inputstr);
Result result = new Result();
result = JsonConvert.DeserializeObject<Result>(resultStr);
if (result.Success)
{
try
{
JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
foreach (var item in res)
{
JObject jo = (JObject)item;
JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
foreach (var detail in resdetail)
{
JObject det = (JObject)detail;
string allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
+ det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
}
}
}
catch (Exception ex)
{
log.Debug(ex.ToString());
log.Debug(resultStr);
}
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
}
#endregion
}
catch (Exception)
{
throw;
}
}
#endregion
#region 生产退料
/// <summary>
/// 生产退料
/// </summary>
/// <param name="TransCode"></param>
/// <param name="TransSequence"></param>
/// <param name="Quantity"></param>
/// <param name="WorkPoint"></param>
/// <param name="cmd"></param>
public static void MOIssueDocNegative(string TransType, string LogID, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
{
try
{
string table = "";
string table1 = "";
string sql = "";
string sqlMOIssueDocNegativeIssueDH = "";
string quantitySql = "c.Quantity";
if (string.IsNullOrWhiteSpace(LogID))
{
string type = "";
if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
{
table = "INNER JOIN ICSMOPick e ON c.SourceDetailID=e.PickID AND c.WorkPoint=e.WorkPoint";
type = "1";
quantitySql = "dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn017', c.Quantity,1,2,'')";
}
else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
{
table = "INNER JOIN ICSMOApply e ON c.SourceDetailID=e.ApplyDetailID AND c.WorkPoint=e.WorkPoint";
type = "2";
quantitySql = "dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn018', c.Quantity,1,2,'')";
}
else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
{
table = "INNER JOIN ICSMOIssue e ON c.SourceDetailID=e.IssueDetailID AND c.WorkPoint=e.WorkPoint";
table1 = " INNER JOIN ICSMOIssue ee ON c.SourceDetailID=ee.IssueDetailID AND c.WorkPoint=ee.WorkPoint " +
" INNER JOIN icsmopick e ON e.pickid = ee.pickid";
type = "3";
quantitySql = "dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn019', c.Quantity,1,2,'')";
//东辉退料单 修改工单子件数量
sqlMOIssueDocNegativeIssueDH = @" UPDATE e SET e.IssueQuantity=ISNULL(e.IssueQuantity,0)-'{2}'
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
INNER JOIN ICSMOApplyNegDetail c ON b.TransCode = c.ApplyNegCode AND b.TransSequence = c.Sequence AND b.WorkPoint = c.WorkPoint
INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode = d.ApplyNegCode AND c.WorkPoint = d.WorkPoint
{5}
WHERE a.LotNo = '{0}' AND a.WorkPoint = '{1}' AND d.Type = '{4}' and ISNULL(e.IssueQuantity,0)> 0";
sqlMOIssueDocNegativeIssueDH = string.Format(sqlMOIssueDocNegativeIssueDH, LotNo, WorkPoint, Quantity, table, type, table1);
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
}
#region 新条码
sql = @"UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND {6}<c.IssueNegQuantity)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
END
UPDATE e SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
{3}
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
{5}
IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
{3}
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND e.IssueQuantity<0)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
END";
sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, type, sqlMOIssueDocNegativeIssueDH, quantitySql);
#endregion
}
else
{
if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
{
table = @"INNER JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOPick c ON b.MODetailID = c.MODetailID AND b.WorkPoint = c.WorkPoint AND a.TransSequence = b.Sequence + '~' + c.Sequence";
}
else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
{
table = "INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
}
else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
{
table = "INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
}
#region 原条码
sql = @"UPDATE c SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
FROM ICSWareHouseLotInfoLog a
{3}
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}'
IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a
{3}
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' AND c.IssueQuantity<0)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
END";
sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, LogID);
#endregion
}
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo134"));//"生产退料单更新失败!");
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 生产退料(奥美专用)
/// </summary>
/// <param name="TransCode"></param>
/// <param name="TransSequence"></param>
/// <param name="Quantity"></param>
/// <param name="WorkPoint"></param>
/// <param name="cmd"></param>
public static void AMMOIssueDocNegative(string TransType, string LogID, string LotNo, string Quantity, string WorkPoint,string TransCode,string TransSequence, SqlCommand cmd, Dictionary<string, string> language)
{
try
{
string table = "";
string sql = "";
if (string.IsNullOrWhiteSpace(LogID))
{
string type = "";
if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
{
table = "INNER JOIN ICSMOPick e ON c.SourceDetailID=e.PickID AND c.WorkPoint=e.WorkPoint";
type = "1";
}
else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
{
table = "INNER JOIN ICSMOApply e ON c.SourceDetailID=e.ApplyDetailID AND c.WorkPoint=e.WorkPoint";
type = "2";
}
else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
{
table = "INNER JOIN ICSMOIssue e ON c.SourceDetailID=e.IssueDetailID AND c.WorkPoint=e.WorkPoint";
type = "3";
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
}
#region 新条码
sql = @"UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND c.Quantity<c.IssueNegQuantity)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
END
UPDATE e SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
{3}
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOApplyNeg d ON c.ApplyNegCode=d.ApplyNegCode AND c.WorkPoint=d.WorkPoint
{3}
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND e.IssueQuantity<0)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
END";
sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, type);
#endregion
}
else
{
if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
{
table = @"INNER JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOPick c ON b.MODetailID = c.MODetailID AND b.WorkPoint = c.WorkPoint AND a.TransSequence = b.Sequence + '~' + c.Sequence";
}
else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
{
table = "INNER JOIN ICSMOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
}
else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
{
table = "INNER JOIN ICSMOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
}
if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
{
#region 原条码
sql = @"UPDATE c SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
FROM ICSWareHouseLotInfoLog a
{3}
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' and b.MoCode='{5}' AND b.Sequence='{6}'
IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a
{3}
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' AND c.IssueQuantity<0 and b.MoCode='{5}' AND b.Sequence='{6}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
END";
sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, LogID, TransCode, TransSequence);
}
else
{
sql = @"UPDATE c SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
FROM ICSWareHouseLotInfoLog a
{3}
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}'
IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a
{3}
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' AND c.IssueQuantity<0)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo192") + @"',16,1);
END";
sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, LogID, TransCode, TransSequence);
}
#endregion
}
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo134"));//"生产退料单更新失败!");
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 生产退料接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void MOIssueDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
{
try
{
#region ERP
string sql = string.Empty;
if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
{
sql = @"select LotNo,a.WorkPoint,InvCode,ToWarehouseCode,a.MUSER,Quantity,con.Enable,conStock.Enable AS conStockEnable
INTO #NewTempERP
from ICSWareHouseLotInfoLog a
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
select LotNo,a.WorkPoint,InvCode,ToWarehouseCode,a.MUSER,Quantity,LogID,con.Enable,conStock.Enable AS conStockEnable
INTO #NewDouTempERP
from ICSWareHouseLotInfoLog a
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
SELECT y.DepCode+a.ToWarehouseCode+y.MOCode+a.MUSER AS Costre,y.DepCode,a.ToWarehouseCode AS WarehouseCode,y.MOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.ToWarehouseCode,y.MOCode,x.PickID,a.InvCode) AS Sequence,
a.InvCode,inv.InvRate,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,x.PickID AS SourceDetailID,a.Enable AS UpdateTodoQuantity,a.conStockEnable AS UpdateStock
,a.WorkPoint,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
INTO #TempERP
FROM #NewTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOPick x ON c.SourceDetailID=x.PickID AND c.WorkPoint=x.WorkPoint
INNER JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
GROUP BY inv.AmountEnable,y.DepCode,a.ToWarehouseCode,y.MOCode,a.MUSER,a.InvCode,inv.InvRate,lot.Amount,lot.Quantity,x.PickID,x.MODetailID,a.Enable,a.conStockEnable
,a.WorkPoint,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, '')
UNION ALL
SELECT y.DepCode+a.ToWarehouseCode+y.MOCode+a.MUSER AS Costre,y.DepCode,a.ToWarehouseCode AS WarehouseCode,y.MOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.ToWarehouseCode,y.MOCode,x.PickID,a.InvCode) AS Sequence,
a.InvCode,inv.InvRate,SUM(a.Quantity) AS Quantity,0 AS Amount,x.PickID AS SourceDetailID,a.Enable AS UpdateTodoQuantity,a.conStockEnable AS UpdateStock
,a.WorkPoint,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 #NewDouTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO y ON b.TransCode=y.MOCode AND b.WorkPoint=y.WorkPoint
INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
GROUP BY y.DepCode,a.ToWarehouseCode,y.MOCode,a.MUSER,a.InvCode,inv.InvRate,x.PickID,x.MODetailID,a.Enable,a.conStockEnable
,a.WorkPoint,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, '')
SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'生产订单' AS SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
SELECT Costre,Sequence,InvCode,InvRate,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ,WarehouseCode AS WHCode FROM #TempERP
DROP TABLE #TempERP
DROP TABLE #NewTempERP
DROP TABLE #NewDouTempERP";
}
else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
{
if (DBHelper.IsPNU9())
{
sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
INTO #NewTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
INTO #NewDouTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
SELECT a.ToWarehouseCode+z.ApplyNegCode+a.MUSER AS Costre,'' AS DepCode,a.ToWarehouseCode AS WarehouseCode,z.ApplyNegCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode,z.ApplyNegCode,c.id,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,c.id AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
,a.WorkPoint,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
INTO #TempERP
FROM #NewTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOApplyNeg z ON c.ApplyNegCode=z.ApplyNegCode AND c.WorkPoint=z.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
GROUP BY a.ToWarehouseCode,z.ApplyNegCode,a.MUSER,a.InvCode,c.id,con.Enable,conStock.Enable
,a.WorkPoint,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, '')
SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'领料申请单' AS SourceType,ApplyNegCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ,WarehouseCode AS WHCode FROM #TempERP
DROP TABLE #TempERP
DROP TABLE #NewTempERP
DROP TABLE #NewDouTempERP";
}
else
{
sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
INTO #NewTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
INTO #NewDouTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
SELECT a.ToWarehouseCode+z.ApplyCode+a.MUSER AS Costre,'' AS DepCode,a.ToWarehouseCode AS WarehouseCode,z.ApplyCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode,z.ApplyCode,z.ApplyDetailID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
,a.WorkPoint,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
INTO #TempERP
FROM #NewTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOApply z ON c.SourceDetailID=z.ApplyDetailID AND c.WorkPoint=z.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,z.ApplyDetailID,con.Enable,conStock.Enable
,a.WorkPoint,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, '')
UNION ALL
SELECT a.ToWarehouseCode+z.ApplyCode+a.MUSER AS Costre,'' AS DepCode,a.ToWarehouseCode AS WarehouseCode,z.ApplyCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode,z.ApplyCode,z.ApplyDetailID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
,a.WorkPoint,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 #NewDouTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,z.ApplyDetailID,con.Enable,conStock.Enable
,a.WorkPoint,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, '')
SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'领料申请单' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ,WarehouseCode AS WHCode FROM #TempERP
DROP TABLE #TempERP
DROP TABLE #NewTempERP
DROP TABLE #NewDouTempERP";
}
}
//根据材料出库单查询上游单据,根据上游单据生成红字材料出库
else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
{
sql = @"
select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
INTO #NewTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
INTO #NewDouTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
IF EXISTS(select * FROM #NewTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
where m.ApplyDetailID<>null and z.ApplyDetailID=null)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo480") + @"',16,1);
RETURN
END
IF EXISTS(select * FROM #NewDouTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
where m.ApplyDetailID<>null and z.ApplyDetailID=null)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo480") + @"',16,1);
RETURN
END
SELECT ISNULL(y.DepCode, '')+a.ToWarehouseCode+a.MUSER AS Costre,ISNULL(y.DepCode, '') AS DepCode,a.ToWarehouseCode AS WarehouseCode,CASE WHEN m.ApplyDetailID IS NOT NULL THEN '领料申请单' WHEN m.PickID IS NOT NULL THEN '生产订单' ELSE '' END AS SourceType,ISNULL(z.ApplyCode, y.MOCode) AS MOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),ISNULL(m.ApplyDetailID, m.PickID),a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
,a.WorkPoint,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
,m.issuecode as DocCode,m.Sequence as DocLineNo
INTO #TempERP
FROM #NewTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),a.MUSER,a.InvCode,m.ApplyDetailID, m.PickID,con.Enable,conStock.Enable
,m.issuecode,m.Sequence ,a.WorkPoint,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, '')
UNION ALL
SELECT ISNULL(y.DepCode, '')+a.ToWarehouseCode+a.MUSER AS Costre,ISNULL(y.DepCode, '') AS DepCode,a.ToWarehouseCode AS WarehouseCode,CASE WHEN m.ApplyDetailID IS NOT NULL THEN '领料申请单' WHEN m.PickID IS NOT NULL THEN '生产订单' ELSE '' END AS SourceType,ISNULL(z.ApplyCode, y.MOCode) AS MOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),ISNULL(m.ApplyDetailID, m.PickID),a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
,a.WorkPoint,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
,m.issuecode as DocCode,m.Sequence as DocLineNo
FROM #NewDouTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),a.MUSER,a.InvCode,m.ApplyDetailID, m.PickID,con.Enable,conStock.Enable
,m.issuecode,m.Sequence ,a.WorkPoint,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, '')
IF EXISTS(SELECT Costre FROM #TempERP WHERE SourceType='{0}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo135") + @"',16,1);
END
SELECT DISTINCT Costre+isnull(MOCode,'')+isnull(DocCode,'') as Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock,DocCode,'19' as DocTypeCode FROM #TempERP
SELECT Costre+isnull(MOCode,'')+isnull(DocCode,'') as Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ,WarehouseCode AS WHCode, DocLineNo FROM #TempERP
DROP TABLE #TempERP
DROP TABLE #NewTempERP
DROP TABLE #NewDouTempERP";
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
}
sql = string.Format(sql, Identification);
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
string resultStr = "";
if (DBHelper.IsU9())
{ resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9MOIssueDocNegativeURL, Inputstr); }
else
{ resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOIssueDocNegativeURL, Inputstr); }
Result result = new Result();
result = JsonConvert.DeserializeObject<Result>(resultStr);
if (result.Success)
{
try
{
JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
foreach (var item in res)
{
JObject jo = (JObject)item;
JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
foreach (var detail in resdetail)
{
JObject det = (JObject)detail;
string allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
+ det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
det["DetailID"].ToString(), jo["IssueNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
}
}
}
catch (Exception ex)
{
log.Debug(ex.ToString());
log.Debug(resultStr);
}
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
}
#endregion
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 生产退料接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void DXMOIssueDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode,string IsDx)
{
try
{
#region ERP
string sql = string.Empty;
if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription())
{
sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
INTO #NewTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
INTO #NewDouTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
SELECT y.DepCode+a.ToWarehouseCode+y.MOCode+a.MUSER AS Costre,y.DepCode,a.ToWarehouseCode AS WarehouseCode,y.MOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.ToWarehouseCode,y.MOCode,x.PickID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,x.PickID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
,a.WorkPoint,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
INTO #TempERP
FROM #NewTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOPick x ON c.SourceDetailID=x.PickID AND c.WorkPoint=x.WorkPoint
INNER JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
GROUP BY inv.AmountEnable,y.DepCode,a.ToWarehouseCode,y.MOCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,x.PickID,x.MODetailID,con.Enable,conStock.Enable
,a.WorkPoint,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, '')
UNION ALL
SELECT y.DepCode+a.ToWarehouseCode+y.MOCode+a.MUSER AS Costre,y.DepCode,a.ToWarehouseCode AS WarehouseCode,y.MOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.ToWarehouseCode,y.MOCode,x.PickID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,x.PickID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
,a.WorkPoint,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 #NewDouTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO y ON b.TransCode=y.MOCode AND b.WorkPoint=y.WorkPoint
INNER JOIN ICSMOPick x ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
GROUP BY y.DepCode,a.ToWarehouseCode,y.MOCode,a.MUSER,a.InvCode,x.PickID,x.MODetailID,con.Enable,conStock.Enable
,a.WorkPoint,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, '')
SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'生产订单' AS SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ,WarehouseCode AS WHCode FROM #TempERP
DROP TABLE #TempERP
DROP TABLE #NewTempERP
DROP TABLE #NewDouTempERP";
}
else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
{
sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
INTO #NewTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
INTO #NewDouTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
SELECT a.ToWarehouseCode+z.ApplyCode+a.MUSER AS Costre,'' AS DepCode,a.ToWarehouseCode AS WarehouseCode,z.ApplyCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode,z.ApplyCode,z.ApplyDetailID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
,a.WorkPoint,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
INTO #TempERP
FROM #NewTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOApply z ON c.SourceDetailID=z.ApplyDetailID AND c.WorkPoint=z.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,z.ApplyDetailID,con.Enable,conStock.Enable
,a.WorkPoint,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, '')
UNION ALL
SELECT a.ToWarehouseCode+z.ApplyCode+a.MUSER AS Costre,'' AS DepCode,a.ToWarehouseCode AS WarehouseCode,z.ApplyCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode,z.ApplyCode,z.ApplyDetailID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
,a.WorkPoint,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 #NewDouTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,z.ApplyDetailID,con.Enable,conStock.Enable
,a.WorkPoint,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, '')
SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'领料申请单' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ,WarehouseCode AS WHCode FROM #TempERP
DROP TABLE #TempERP
DROP TABLE #NewTempERP
DROP TABLE #NewDouTempERP";
}
//根据材料出库单查询上游单据,根据上游单据生成红字材料出库
else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
{
sql = @"
select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
INTO #NewTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
INTO #NewDouTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
IF EXISTS(select * FROM #NewTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
where m.ApplyDetailID<>null and z.ApplyDetailID=null)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo480") + @"',16,1);
RETURN
END
IF EXISTS(select * FROM #NewDouTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
where m.ApplyDetailID<>null and z.ApplyDetailID=null)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo480") + @"',16,1);
RETURN
END
SELECT ISNULL(y.DepCode, '')+a.ToWarehouseCode+a.MUSER AS Costre,ISNULL(y.DepCode, '') AS DepCode,a.ToWarehouseCode AS WarehouseCode,CASE WHEN m.ApplyDetailID IS NOT NULL THEN '领料申请单' WHEN m.PickID IS NOT NULL THEN '生产订单' ELSE '' END AS SourceType,ISNULL(z.ApplyCode, y.MOCode) AS MOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),ISNULL(m.ApplyDetailID, m.PickID),a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
,a.WorkPoint,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
,m.issuecode as DocCode,m.Sequence as DocLineNo
INTO #TempERP
FROM #NewTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOApplyNegDetail c ON b.TransCode=c.ApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),a.MUSER,a.InvCode,m.ApplyDetailID, m.PickID,con.Enable,conStock.Enable
,m.issuecode,m.Sequence ,a.WorkPoint,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, '')
UNION ALL
SELECT ISNULL(y.DepCode, '')+a.ToWarehouseCode+a.MUSER AS Costre,ISNULL(y.DepCode, '') AS DepCode,a.ToWarehouseCode AS WarehouseCode,CASE WHEN m.ApplyDetailID IS NOT NULL THEN '领料申请单' WHEN m.PickID IS NOT NULL THEN '生产订单' ELSE '' END AS SourceType,ISNULL(z.ApplyCode, y.MOCode) AS MOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),ISNULL(m.ApplyDetailID, m.PickID),a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
,a.WorkPoint,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
,m.issuecode as DocCode,m.Sequence as DocLineNo
FROM #NewDouTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
LEFT JOIN ICSMOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
LEFT JOIN ICSMO y ON x.MODetailID=y.MODetailID AND x.WorkPoint=y.WorkPoint
LEFT JOIN ICSMOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.MOCode),a.MUSER,a.InvCode,m.ApplyDetailID, m.PickID,con.Enable,conStock.Enable
,m.issuecode,m.Sequence ,a.WorkPoint,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, '')
IF EXISTS(SELECT Costre FROM #TempERP WHERE SourceType='{0}')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo135") + @"',16,1);
END
SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,SourceType,MOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock,DocCode,'19' as DocTypeCode FROM #TempERP
SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ,WarehouseCode AS WHCode, DocLineNo FROM #TempERP
DROP TABLE #TempERP
DROP TABLE #NewTempERP
DROP TABLE #NewDouTempERP";
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
}
sql = string.Format(sql, Identification);
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
string resultStr = "";
if (DBHelper.IsU9())
{ resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9MOIssueDocNegativeURL, Inputstr); }
else
{
if (IsDx == "1")
{
resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DXNewMOIssueDocNegativeURL, Inputstr);
}
else
{
resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DXMOIssueDocNegativeURL, Inputstr);
}
}
Result result = new Result();
result = JsonConvert.DeserializeObject<Result>(resultStr);
if (result.Success)
{
try
{
JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
foreach (var item in res)
{
JObject jo = (JObject)item;
JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
foreach (var detail in resdetail)
{
JObject det = (JObject)detail;
string allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
+ det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
det["DetailID"].ToString(), jo["IssueNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
}
}
}
catch (Exception ex)
{
log.Debug(ex.ToString());
log.Debug(resultStr);
}
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
}
#endregion
}
catch (Exception)
{
throw;
}
}
#endregion
#region 生产入库
/// <summary>
/// 生产入库
/// </summary>
/// <param name="TransCode"></param>
/// <param name="TransSequence"></param>
/// <param name="Quantity"></param>
/// <param name="WorkPoint"></param>
/// <param name="cmd"></param>
public static void ManufactureReceiveDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
{
try
{
string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
IF (@Status IS NULL)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
RETURN
END
ELSE IF (@Status='3')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
RETURN
END
UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn011', c.Quantity,1,2,'')<c.RCVQuantity)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
END";
sql = string.Format(sql, LotNo, WorkPoint, Quantity);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo136"));//"生产订单更新失败!");
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 生产入库(奥美专用)
/// </summary>
/// <param name="TransCode"></param>
/// <param name="TransSequence"></param>
/// <param name="Quantity"></param>
/// <param name="WorkPoint"></param>
/// <param name="cmd"></param>
public static void ManufactureReceiveDocAM(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
{
try
{
string cheksql = @"select d.EATTRIBUTE1 FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSInventory d on a.InvCode=d.InvCode and a.WorkPoint=d.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' and d.AmountEnable='1'";
cheksql = string.Format(cheksql, LotNo, WorkPoint);
DataTable dt = DBHelper.SQlReturnData(cheksql, cmd);
if (dt.Rows.Count > 0)
{
Quantity = (decimal.Parse(Quantity) * decimal.Parse(dt.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
}
string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
IF (@Status IS NULL)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
RETURN
END
ELSE IF (@Status='3')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
RETURN
END
UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
--IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
-- INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
-- INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
-- WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
-- AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn001', '{0}')<c.RCVQuantity)
--BEGIN
-- RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
--END";
sql = string.Format(sql, LotNo, WorkPoint, Quantity);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo136"));//"生产订单更新失败!");
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 生产入库接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void ManufactureReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
{
try
{
#region ERP
string sql = "";
string outwhcode = "";
DataTable flag = null;
string enablesql = @"select * from ICSConfiguration where code = 'OostackInBack002' and enable = '1'";
flag = DBHelper.SQlReturnData(enablesql, cmd);
if (DBHelper.IsU9()) { sql = @"SELECT ISNULL(c.DepCode,'')+a.ToWarehouseCode+c.MOCode+a.MUSER AS Costre,
c.MODetailID+CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END+ CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END
+ CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END AS Costre2,lot.EATTRIBUTE2,
c.DepCode,a.ToWarehouseCode AS WarehouseCode,c.MOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.DepCode,a.ToWarehouseCode,c.MOCode,c.MODetailID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,c.MODetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose
,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END 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,
CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END AS Version,
CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END AS Brand,
CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END AS cFree1,
CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END AS cFree2,
CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END AS cFree3,
CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END AS cFree4,
CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END AS cFree5,
CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END AS cFree6,
CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END AS cFree7,
CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END AS cFree8,
CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END AS cFree9,
CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END AS cFree10,
conv.Enable AS CompleteVerification,a.TransSequence
INTO #TempERP
FROM ICSWareHouseLotInfoLog 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSExtension docext ON docext.ID=c.ExtensionID AND docext.WorkPoint=c.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose001'
WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
GROUP BY inv.AmountEnable,c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,c.MODetailID,con.Enable,conv.Enable,conStock.Enable,conStocknew.Enable
,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END,lot.EATTRIBUTE2,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,
CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END,
CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END,a.TransSequence
SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,IsFillClose FROM #TempERP
SELECT Costre,Costre2,TransSequence,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,EATTRIBUTE2 as OutType
FROM #TempERP
SELECT a.FromWarehouseCode AS WHCode,c.MODetailID+te.ProjectCode+te.BatchCode+te.Version+te.Brand+te.cFree1+te.cFree2+te.cFree3+te.cFree4+te.cFree5+te.cFree6+te.cFree7+te.cFree8+te.cFree9+te.cFree10 AS Costre2,a.TransCode,a.TransSequence AS Sequence,a.InvCode,SUM(c.Quantity/b.Quantity*a.Quantity) as Quantity,SUM((c.Quantity/b.Quantity*a.Quantity)*(c.Amount/c.Quantity)) AS Amount,c.PickID,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 ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSMO b ON b.MOCode=a.TransCode AND b.WorkPoint=a.WorkPoint
INNER JOIN ICSMOPick c ON c.MODetailID=b.MODetailID AND c.WorkPoint=b.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
INNER JOIN ICSExtension ext ON ext.ID=c.ExtensionID AND ext.WorkPoint=c.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN #TempERP te ON te.TransSequence=SUBSTRING(a.TransSequence,1,CHARINDEX('~',a.TransSequence)-1)
WHERE a.Identification='{0}' AND a.TransType='12'
GROUP BY a.FromWarehouseCode,c.MODetailID,a.TransCode,a.TransSequence,a.InvCode,c.PickID,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, ''),a.TransSequence,te.ProjectCode,te.BatchCode,te.Version,te.Brand,te.cFree1,te.cFree2,te.cFree3,te.cFree4,te.cFree5,te.cFree6,te.cFree7,te.cFree8,te.cFree9,te.cFree10
DROP TABLE #TempERP"; }
else { sql = @"SELECT ISNULL(c.DepCode,'')+a.ToWarehouseCode+c.MOCode+a.MUSER AS Costre,
ISNULL(c.MODetailID,'')+ISNULL(a.TransCode,'')+ISNULL(a.TransSequence,'')+ISNULL(c.DepCode,'')+ISNULL(a.ToWarehouseCode,'')+ISNULL(c.MOCode,'')+ISNULL(a.MUSER,'')+ISNULL(a.InvCode,'')
+ISNULL(a.WorkPoint,'')+CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END+ CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END
+ CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END
+ CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END AS Costre2,ISNULL(c.EATTRIBUTE30,'') AS EATTRIBUTE30,
c.DepCode,a.ToWarehouseCode AS WarehouseCode,c.MOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.DepCode,a.ToWarehouseCode,c.MOCode,c.MODetailID,a.InvCode) AS Sequence,conWhCode.Enable AS ErpWhCode,
a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,c.MODetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose
,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END 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,
CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END AS Version,
CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END AS Brand,
CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END AS cFree1,
CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END AS cFree2,
CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END AS cFree3,
CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END AS cFree4,
CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END AS cFree5,
CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END AS cFree6,
CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END AS cFree7,
CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END AS cFree8,
CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END AS cFree9,
CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END AS cFree10,
conv.Enable AS CompleteVerification,a.TransSequence,lot.eattribute10 as Reason,a.TransCode,a.ToWarehouseCode
INTO #TempERP
FROM ICSWareHouseLotInfoLog 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSExtension docext ON docext.ID=c.ExtensionID AND docext.WorkPoint=c.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose001'
LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
GROUP BY c.EATTRIBUTE30,a.TransCode,conWhCode.Enable,inv.AmountEnable,c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,c.MODetailID,con.Enable,conv.Enable,conStock.Enable,conStocknew.Enable
,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,
CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END,
CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END,a.TransSequence,lot.eattribute10
SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,EATTRIBUTE30,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,IsFillClose FROM #TempERP
SELECT Costre,Costre2,Sequence,InvCode,Quantity,Amount,MODetailID,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,Reason
FROM #TempERP
SELECT a.EATTRIBUTE3,a.FromWarehouseCode AS WHCode,c.MODetailID+te.TransCode+te.TransSequence+te.DepCode+te.ToWarehouseCode+te.MOCode+te.MUSER+te.InvCode
+te.WorkPoint+te.ProjectCode+te.BatchCode+te.Version+te.Brand+te.cFree1+te.cFree2+te.cFree3+te.cFree4+te.cFree5+te.cFree6+te.cFree7+te.cFree8+te.cFree9+te.cFree10 AS Costre2,a.TransCode,a.TransSequence AS Sequence,a.InvCode,SUM(a.Quantity) as Quantity,SUM((a.Quantity)*(c.Amount/c.Quantity)) AS Amount,c.PickID,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 ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSMO b ON b.MOCode=a.TransCode AND b.WorkPoint=a.WorkPoint
INNER JOIN ICSMOPick c ON c.MODetailID=b.MODetailID AND c.WorkPoint=b.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
INNER JOIN ICSExtension ext ON ext.ID=lot.ExtensionID AND ext.WorkPoint=lot.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN #TempERP te ON te.TransSequence=SUBSTRING(a.TransSequence,1,CHARINDEX('~',a.TransSequence)-1) and c.MODetailID+a.EATTRIBUTE3=c.MODetailID+te.ProjectCode+te.BatchCode+te.Version+te.Brand+te.cFree1+te.cFree2+te.cFree3+te.cFree4+te.cFree5+te.cFree6+te.cFree7+te.cFree8+te.cFree9+te.cFree10
WHERE a.Identification='{0}' AND a.TransType='12' and a.businesscode ='61'
GROUP BY te.DepCode,te.ToWarehouseCode,te.MOCode,te.MUSER,te.InvCode
,te.WorkPoint,te.TransCode,te.TransSequence,a.EATTRIBUTE3,a.FromWarehouseCode,c.MODetailID,a.TransCode,a.TransSequence,a.InvCode,c.PickID,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, ''),a.TransSequence,te.ProjectCode,te.BatchCode,te.Version,te.Brand,te.cFree1,te.cFree2,te.cFree3,te.cFree4,te.cFree5,te.cFree6,te.cFree7,te.cFree8,te.cFree9,te.cFree10
DROP TABLE #TempERP"; }
sql = string.Format(sql, Identification, BusinessCode);
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre","detailss", "Costre2");
string resultStr = "";
if (DBHelper.IsU9())
{ resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9MOStockINByProductDocURL, Inputstr); }
else { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ManufactureReceiveDocURL, Inputstr); }
log.Debug("ERP成品入库单返回:"+ resultStr);
Result result = new Result();
result = JsonConvert.DeserializeObject<Result>(resultStr);
if (result.Success)
{
try
{
if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
{
string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
newsql = string.Format(newsql, Identification, BusinessCode);
DataTable dt = DBHelper.SQlReturnData(newsql, cmd);
JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
foreach (var item in res)
{
JObject jo = (JObject)item;
JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
foreach (var detail in resdetail)
{
JObject det = (JObject)detail;
string allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
+ det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
if (det["detailss"] != null)
{
JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
foreach (var details in resdetails)
{
JObject dets = (JObject)details;
if (dets != null)
{
//for (int i = 0; i < dt.Rows.Count; i++)
//{
//派纳倒冲排除仓库逻辑
string whsql = @"SELECT b.F_ItemCode,b.F_ItemName 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' and b.F_ItemCode='{0}'";
whsql = string.Format(whsql, dets["WHCode"].ToString());
DataTable dtt = DBHelper.SQlReturnData(whsql, cmd);
if (dtt.Rows.Count > 0 && dtt != null)
{
//if (!dtt.Rows[0]["F_ItemCode"].ToString().Equals(dets["WHCode"].ToString()))
//{
// ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["INVCode"].ToString(),
// dets["WHCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(),
// dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), "", "",
// "", "", "", "", "",
// "", "", "", "", "", "",
// "", cmd, language);
//}
//回写已领数量
sql = @"UPDATE ICSMOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + dets["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
sql = String.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString());
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
}
}
else
{
ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["INVCode"].ToString(),
dets["WHCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(),
dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), "", "",
"", "", "", "", "",
"", "", "", "", "", "",
"", cmd, language);
//回写已领数量
sql = @"UPDATE ICSMOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + dets["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
sql = String.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString());
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
}
}
}
}
}
}
}
}
else
{
if (result.Data != null)
{
JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
foreach (var item in res)
{
JObject jo = (JObject)item;
JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
foreach (var detail in resdetail)
{
JObject det = (JObject)detail;
log.Debug("111");
string allcol = jo["cWhCode"]==null? jo["WHCode"].ToString(): jo["cWhCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
+ det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
log.Debug("222");
if (det["detailss"] != null)
{
log.Debug("333");
JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
foreach (var details in resdetails)
{
JObject dets = (JObject)details;
if (dets != null)
{
//直接回写
string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
FROM ICSWareHouseLotInfoLog a
LEFT JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
LEFT JOIN ICSMOPick c ON b.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
WHERE c.PickID='{0}' and a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='61'";
ERPupdate = string.Format(ERPupdate, dets["SourceDetailID"].ToString(), Identification, dets["IDs"].ToString(), dets["DetailID"].ToString(), dets["MRCVCode"].ToString()
, dets["Sequence"].ToString(), BusinessCode);
if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
{
log.Error("倒冲回写sql:" + ERPupdate);
//throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"成品倒冲回写失败!";
}
}
}
}
}
}
}
}
}
catch (Exception ex)
{
log.Debug(ex.ToString());
log.Debug(resultStr);
throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
}
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
}
#endregion
}
catch (Exception)
{
throw;
}
}
#endregion
#region 副产品入库
/// <summary>
/// 副产品入库
/// </summary>
/// <param name="TransCode"></param>
/// <param name="TransSequence"></param>
/// <param name="Quantity"></param>
/// <param name="WorkPoint"></param>
/// <param name="cmd"></param>
public static void MOStockINByProductDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
{
try
{
string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
IF (@Status IS NULL)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
RETURN
END
ELSE IF (@Status='3')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
RETURN
END
UPDATE d SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn014', c.Quantity,1,2,'')<c.RCVQuantity)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
END";
sql = string.Format(sql, LotNo, WorkPoint, Quantity);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo136"));//"生产订单更新失败!");
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 委外副产品入库
/// </summary>
/// <param name="TransCode"></param>
/// <param name="TransSequence"></param>
/// <param name="Quantity"></param>
/// <param name="WorkPoint"></param>
/// <param name="cmd"></param>
public static void OOStockINByProductDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
{
try
{
string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=c.Status 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.WorkPoint=c.WorkPoint
INNER JOIN ICSOOPick d ON c.OODetailID=d.OODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
IF (@Status IS NULL)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
RETURN
END
ELSE IF (@Status='3')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
RETURN
END
UPDATE d SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
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.WorkPoint=c.WorkPoint
INNER JOIN ICSOOPick d ON c.OODetailID=d.OODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
IF EXISTS(SELECT a.LotNo 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.WorkPoint=c.WorkPoint
INNER JOIN ICSOOPick d ON c.OODetailID=d.OODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn007', c.Quantity,1,1,'')<c.InQuantity)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
END";
sql = string.Format(sql, LotNo, WorkPoint, Quantity);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo136"));//"生产订单更新失败!");
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 联副产品入库(奥美专用)
/// </summary>
/// <param name="LotNo"></param>
/// <param name="Quantity"></param>
/// <param name="WorkPoint"></param>
/// <param name="cmd"></param>
/// <param name="language"></param>
public static void MOStockINByProductAMDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
{
try
{
//条码表类型为19(无源头副产品条码),则不作数量卡控
string checkSql = @"SELECT Type FROM ICSInventoryLot WHERE LotNo='{0}'";
checkSql = string.Format(checkSql, LotNo);
string type = DBHelper.ExecuteScalar(checkSql, cmd).ToString();
if ("19".Equals(type))
{
return;
}
string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
IF (@Status IS NULL)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
RETURN
END
ELSE IF (@Status='3')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
RETURN
END
UPDATE d SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
DECLARE @MoTypeValue VARCHAR(50)
DECLARE @QtyBeyond DECIMAL(18,4)=9999
SELECT @MoTypeValue=c.EATTRIBUTE1 FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
IF(@MoTypeValue='0')--非标准
BEGIN
select
-- @QtyBeyond = cast( isnull(h.BL,0)*d.Quantity AS DECIMAL(18,4))
@QtyBeyond = 9999
from ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint AND c.MOStatus<>'3'
INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
left join
(
select MinBL as BL ,MODetailID from (
select a.MODetailID,
min(ALLBL)*max(isnull(F_Define1,0)/100.0) as MinBL
from (
select a.MODetailID ,
case when a.Quantity =0 then 0 when a.IssueQuantity=0 then 0 else a.IssueQuantity/a.Quantity end as ALLBL
from dbo.ICSMOPick a
inner join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
where a.EATTRIBUTE1<>'1' and a.IssueQuantity>0 )a
left join Sys_SRM_ItemsDetail flag on flag.F_ItemCode='GDCS0001'
group by MODetailID )a
) h on d.MODetailID=h.MODetailID
left join ICSExtension e on d.ExtensionID=e.ID and a.WorkPoint=e.WorkPoint
WHERE 1=1 AND a.LotNo='{0}' AND a.WorkPoint='{1}'
END
ELSE IF(@MoTypeValue='1')--标准
BEGIN
select
-- @QtyBeyond = cast( isnull(h.BL,0)*d.Quantity AS DECIMAL(18,4))
@QtyBeyond = 9999
from ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint AND c.MOStatus<>'3'
INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
left join
(
select case when Flag>0 then ( case when PSLNUM>MLNUM then MLNUM else PSLNUM end) else PSLNUM end as BL ,MODetailID from (
select a.MODetailID,
case when isnull(sum(a.PSLYL),0)=0 then 0 else sum(a.PSLLSS)/sum(a.PSLYL)* max(isnull(F_Define1,0)/100.0) end as PSLNUM,
case when isnull(sum(a.MLYL),0)=0 then 0 else sum(a.MLLSS)/sum(a.MLYL)*max(isnull(F_Define1,0)/100.0) end as MLNUM,
sum(Flag) as Flag
from (
select a.MODetailID ,
case when SUBSTRING(b.ClassCode, 1, 2) IN ('01','04','05') then a.Quantity else 0 end PSLYL,
case when SUBSTRING(b.ClassCode, 1, 2) IN ('01','04','05') then a.IssueQuantity else 0 end PSLLSS,
case when SUBSTRING(b.ClassCode, 1, 2) IN ('03') then a.Quantity else 0 end MLYL,
case when SUBSTRING(b.ClassCode, 1, 2) IN ('03') then a.IssueQuantity else 0 end MLLSS,
case when SUBSTRING(b.ClassCode, 1, 2) IN ('03') then 1 else 0 end Flag
from dbo.ICSMOPick a
inner join dbo.ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
where a.EATTRIBUTE1 <> '1')a
left join Sys_SRM_ItemsDetail flag on flag.F_ItemCode='GDCS0001'
group by MODetailID )a
) h on d.MODetailID=h.MODetailID
left join ICSExtension e on d.ExtensionID=e.ID and a.WorkPoint=e.WorkPoint
WHERE 1=1 AND a.LotNo='{0}' AND a.WorkPoint='{1}'
END
ELSE
BEGIN
RAISERROR('条码 {0} 对应工单副产品未准确标注工单类型!',16,1);
END
IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOPick d ON c.MODetailID=d.MODetailID AND b.TransSequence=c.Sequence+'~'+d.Sequence AND b.WorkPoint=d.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
AND @QtyBeyond<d.IssueQuantity)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
END
";
sql = string.Format(sql, LotNo, WorkPoint, Quantity);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo136"));//"生产订单更新失败!");
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 副产品入库接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void MOStockINByProductDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
{
try
{
#region ERP
string sql = @"SELECT ISNULL(c.DepCode,'')+a.ToWarehouseCode+c.MOCode+a.MUSER AS Costre,
c.DepCode,a.ToWarehouseCode AS WarehouseCode,c.MOCode,a.MUSER,mopick.Sequence,lot.EATTRIBUTE2,
a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,mopick.PickID AS MODetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose
,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END 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,
CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END AS Version,
CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END AS Brand,
CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END AS cFree1,
CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END AS cFree2,
CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END AS cFree3,
CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END AS cFree4,
CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END AS cFree5,
CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END AS cFree6,
CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END AS cFree7,
CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END AS cFree8,
CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END AS cFree9,
CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END AS cFree10,
conv.Enable AS CompleteVerification,a.TransSequence
INTO #TempERP
FROM ICSWareHouseLotInfoLog 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOPick mopick ON mopick.MODetailID=c.MODetailID AND b.TransSequence=c.Sequence+'~'+mopick.Sequence AND mopick.WorkPoint=c.WorkPoint
INNER JOIN ICSExtension docext ON docext.ID=c.ExtensionID AND docext.WorkPoint=c.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose001'
WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
GROUP BY inv.AmountEnable,c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,mopick.PickID,con.Enable,conv.Enable,conStock.Enable,conStocknew.Enable
,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END,c.MODetailID,mopick.Sequence,lot.EATTRIBUTE2,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,
CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END,
CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END,a.TransSequence
SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,'false' AS CompleteVerification,UpdateStock,IsFillClose FROM #TempERP
SELECT Costre,TransSequence,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,EATTRIBUTE2 as OutType
FROM #TempERP
DROP TABLE #TempERP";
sql = string.Format(sql, Identification, BusinessCode);
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
string resultStr = "";
if (DBHelper.IsU9())
{ resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9MOStockINByProductDocURL, Inputstr); }
else { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOStockINByProductDocURL, Inputstr); }
Result result = new Result();
result = JsonConvert.DeserializeObject<Result>(resultStr);
if (result.Success)
{
//try
//{
// JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
// foreach (var item in res)
// {
// JObject jo = (JObject)item;
// JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
// foreach (var detail in resdetail)
// {
// JObject det = (JObject)detail;
// string allcol = "" + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
// + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
// ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
// det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
// if (det["detailss"] != null)
// {
// JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
// foreach (var details in resdetails)
// {
// JObject dets = (JObject)details;
// if (dets != null)
// {
// //直接回写
// string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
// FROM ICSWareHouseLotInfoLog a
// LEFT JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
// LEFT JOIN ICSMOPick c ON b.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint AND a.TransSequence=b.Sequence+'-'+c.Sequence
// WHERE c.PickID='{0}' and a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{6}'";
// ERPupdate = string.Format(ERPupdate, dets["SourceDetailID"].ToString(), Identification, dets["IDs"].ToString(), dets["ERPDetailID"].ToString(), dets["MRCVCode"].ToString()
// , dets["Sequence"].ToString(), BusinessCode);
// if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
// {
// throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"成品倒冲回写失败!";
// }
// }
// }
// }
// }
// }
//}
//catch (Exception ex)
//{
// log.Debug(ex.ToString());
// log.Debug(resultStr);
// throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
//}
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
}
#endregion
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 委外副产品入库接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void OOStockINByProductDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
{
try
{
#region ERP
string sql = @"SELECT ISNULL(c.DepCode,'')+a.ToWarehouseCode+c.OOCode+a.MUSER AS Costre,c.VenCode,
c.DepCode,a.ToWarehouseCode AS WarehouseCode,c.OOCode,a.MUSER,mopick.Sequence,lot.EATTRIBUTE2,
a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,mopick.PickID AS OODetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose
,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END 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,
CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END AS Version,
CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END AS Brand,
CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END AS cFree1,
CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END AS cFree2,
CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END AS cFree3,
CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END AS cFree4,
CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END AS cFree5,
CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END AS cFree6,
CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END AS cFree7,
CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END AS cFree8,
CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END AS cFree9,
CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END AS cFree10,
conv.Enable AS CompleteVerification,a.TransSequence
INTO #TempERP
FROM ICSWareHouseLotInfoLog 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
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.WorkPoint=c.WorkPoint
INNER JOIN ICSOOPick mopick ON mopick.OODetailID=c.OODetailID AND b.TransSequence=c.Sequence+'~'+mopick.Sequence AND mopick.WorkPoint=c.WorkPoint
INNER JOIN ICSExtension docext ON docext.ID=c.ExtensionID AND docext.WorkPoint=c.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose001'
WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
GROUP BY inv.AmountEnable,c.DepCode,c.VenCode,a.ToWarehouseCode,c.OOCode,a.MUSER,a.InvCode,mopick.PickID,con.Enable,conv.Enable,conStock.Enable,conStocknew.Enable
,a.WorkPoint,CASE WHEN ISNULL(docext.ProjectCode,'')!='' Then ISNULL(ext.ProjectCode, '') ELSE '' END,c.OODetailID,mopick.Sequence,lot.EATTRIBUTE2,
CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,
CASE WHEN ISNULL(docext.Version,'')!='' Then ISNULL(ext.Version, '') ELSE '' END,
CASE WHEN ISNULL(docext.Brand,'')!='' THEN ISNULL(ext.Brand, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree1,'')!='' THEN ISNULL(ext.cFree1, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree2,'')!='' THEN ISNULL(ext.cFree2, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree3,'')!='' THEN ISNULL(ext.cFree3, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree4,'')!='' THEN ISNULL(ext.cFree4, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree5,'')!='' THEN ISNULL(ext.cFree5, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree6,'')!='' THEN ISNULL(ext.cFree6, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree7,'')!='' THEN ISNULL(ext.cFree7, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree8,'')!='' THEN ISNULL(ext.cFree8, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree9,'')!='' THEN ISNULL(ext.cFree9, '') ELSE '' END,
CASE WHEN ISNULL(docext.cFree10,'')!='' THEN ISNULL(ext.cFree10, '') ELSE '' END,a.TransSequence
SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,VenCode,OOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,'false' AS CompleteVerification,UpdateStock,IsFillClose FROM #TempERP
SELECT Costre,TransSequence AS ODNSequence,Sequence,InvCode,Quantity,Amount,OODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,EATTRIBUTE2 as OutType
FROM #TempERP
DROP TABLE #TempERP";
sql = string.Format(sql, Identification, BusinessCode);
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
string resultStr = "";
resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OOStockINByProductDocURL, Inputstr);
Result result = new Result();
result = JsonConvert.DeserializeObject<Result>(resultStr);
if (result.Success)
{
//try
//{
// JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
// foreach (var item in res)
// {
// JObject jo = (JObject)item;
// JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
// foreach (var detail in resdetail)
// {
// JObject det = (JObject)detail;
// string allcol = "" + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
// + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
// ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
// det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
// if (det["detailss"] != null)
// {
// JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
// foreach (var details in resdetails)
// {
// JObject dets = (JObject)details;
// if (dets != null)
// {
// //直接回写
// string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
// FROM ICSWareHouseLotInfoLog a
// LEFT JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
// LEFT JOIN ICSMOPick c ON b.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint AND a.TransSequence=b.Sequence+'-'+c.Sequence
// WHERE c.PickID='{0}' and a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{6}'";
// ERPupdate = string.Format(ERPupdate, dets["SourceDetailID"].ToString(), Identification, dets["IDs"].ToString(), dets["ERPDetailID"].ToString(), dets["MRCVCode"].ToString()
// , dets["Sequence"].ToString(), BusinessCode);
// if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
// {
// throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"成品倒冲回写失败!";
// }
// }
// }
// }
// }
// }
//}
//catch (Exception ex)
//{
// log.Debug(ex.ToString());
// log.Debug(resultStr);
// throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
//}
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
}
#endregion
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 副产品入库接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void MOStockINByProductNoTransDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
{
try
{
#region ERP
string sql = @"SELECT a.ToWarehouseCode+a.MUSER+a.LotNo AS Costre,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode,a.MUSER,a.LotNo) AS Sequence,
a.ToWarehouseCode AS WarehouseCode,lot.MUSER,
a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose
,a.WorkPoint,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,
conv.Enable AS CompleteVerification
INTO #TempERP
FROM ICSWareHouseLotInfoLog 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
LEFT JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification001' AND a.WorkPoint=conv.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose001'
WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
GROUP BY a.LotNo,inv.AmountEnable,a.ToWarehouseCode,lot.MUSER,a.InvCode,con.Enable,conv.Enable,conStock.Enable,conStocknew.Enable
,a.WorkPoint,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, '')
SELECT DISTINCT Costre,Sequence,WorkPoint,WarehouseCode AS WHCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,'false' AS CompleteVerification,UpdateStock,IsFillClose
,InvCode,Quantity,Amount,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
--SELECT Costre,TransSequence,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
--FROM #TempERP
DROP TABLE #TempERP";
sql = string.Format(sql, Identification, BusinessCode);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
string Inputstr = JsonConvert.SerializeObject(dt);
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MOStockINByProductNoTransDocURL, Inputstr);
Result result = new Result();
result = JsonConvert.DeserializeObject<Result>(resultStr);
if (result.Success)
{
//try
//{
// JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
// foreach (var item in res)
// {
// JObject jo = (JObject)item;
// JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
// foreach (var detail in resdetail)
// {
// JObject det = (JObject)detail;
// string allcol = "" + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
// + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
// ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
// det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
// if (det["detailss"] != null)
// {
// JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
// foreach (var details in resdetails)
// {
// JObject dets = (JObject)details;
// if (dets != null)
// {
// //直接回写
// string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
// FROM ICSWareHouseLotInfoLog a
// LEFT JOIN ICSMO b ON a.TransCode=b.MOCode AND a.WorkPoint=b.WorkPoint
// LEFT JOIN ICSMOPick c ON b.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint AND a.TransSequence=b.Sequence+'-'+c.Sequence
// WHERE c.PickID='{0}' and a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode ='{6}'";
// ERPupdate = string.Format(ERPupdate, dets["SourceDetailID"].ToString(), Identification, dets["IDs"].ToString(), dets["ERPDetailID"].ToString(), dets["MRCVCode"].ToString()
// , dets["Sequence"].ToString(), BusinessCode);
// if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
// {
// throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"成品倒冲回写失败!";
// }
// }
// }
// }
// }
// }
//}
//catch (Exception ex)
//{
// log.Debug(ex.ToString());
// log.Debug(resultStr);
// throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
//}
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
}
#endregion
}
catch (Exception)
{
throw;
}
}
#endregion
#region 开立的生产入库单
/// <summary>
/// 开立的生产入库单
/// </summary>
/// <param name="TransCode"></param>
/// <param name="TransSequence"></param>
/// <param name="Quantity"></param>
/// <param name="WorkPoint"></param>
/// <param name="cmd"></param>
public static void ManufactureReceive(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
{
try
{
string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=c.Status FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1'
IF (@Status IS NULL)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
RETURN
END
ELSE IF (@Status!='1')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
RETURN
END
UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1'
IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSManufactureReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1' --AND c.Quantity<c.RCVQuantity
AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn013', c.Quantity,1,2,'')<c.RCVQuantity
)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
END";
sql = string.Format(sql, LotNo, WorkPoint, Quantity);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo138"));//"生产入库单更新失败!");
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 开立的生产入库单
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static DataTable ManufactureReceiveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
{
try
{
string checklotno = "";
// string checksql = @"SELECT c.rcvcode,a.lotno FROM ICSInventoryLot a
//INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
//INNER JOIN (select RCVCode,Sequence,WorkPoint FROM ICSManufactureReceive) c ON b.TransCode=c.RCVCode
//AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
//WHERE c.rcvcode in (select TransCode from ICSWareHouseLotInfoLog
//where Identification='{0}' )
//and a.lotno NOT IN (select LotNo from ICSWareHouseLotInfoLog where Identification='{0}' )";
// checksql = string.Format(checksql, Identification);
// DataTable dtt = DBHelper.SQlReturnData(checksql, cmd);
// if (dtt.Rows.Count > 1)
// {
// // 如果dtt的行数大于1,将lotno以逗号隔开的形式加入checklotno中
// foreach (DataRow row in dtt.Rows)
// {
// checklotno += row["lotno"].ToString() + ",";
// }
// checklotno = checklotno.TrimEnd(','); // 去除最后一个逗号
// }
// else if (dtt.Rows.Count == 1)
// {
// // 如果dtt的行数等于1,直接将lotno赋值给checklotno
// checklotno = dtt.Rows[0]["lotno"].ToString();
// }
string checkrcvcode = "";
//string checknewsql = @"SELECT distinct c.rcvcode FROM ICSInventoryLot a
//INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
//INNER JOIN (select RCVCode,Sequence,WorkPoint FROM ICSManufactureReceive) c ON b.TransCode=c.RCVCode
//AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
//WHERE c.rcvcode in (select TransCode from ICSWareHouseLotInfoLog
//where Identification='{0}' )
//and a.lotno NOT IN (select LotNo from ICSWareHouseLotInfoLog where Identification='{0}' )";
//checknewsql = string.Format(checknewsql, Identification);
//DataTable dttnew = DBHelper.SQlReturnData(checknewsql, cmd);
//if (dttnew.Rows.Count > 1)
//{
// // 如果dtt的行数大于1,将lotno以逗号隔开的形式加入checklotno中
// foreach (DataRow row in dttnew.Rows)
// {
// checkrcvcode += row["rcvcode"].ToString() + ",";
// }
// checkrcvcode = checkrcvcode.TrimEnd(','); // 去除最后一个逗号
//}
//else if (dttnew.Rows.Count == 1)
//{
// // 如果dtt的行数等于1,直接将lotno赋值给checklotno
// checkrcvcode = dttnew.Rows[0]["rcvcode"].ToString();
//}
#region ERP开立状态单据审核
string checkksql = @"SELECT c.rcvcode,a.lotno FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN (select rcvcode,Sequence,WorkPoint FROM ICSManufactureReceive) c ON b.TransCode=c.rcvcode
AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
left join ICSWareHouseLotInfo d on a.lotno=d.lotno and a.WorkPoint=d.WorkPoint
WHERE c.rcvcode in (select TransCode from ICSWareHouseLotInfoLog
where Identification='{0}' )
and d.lotno is null";
checkksql = string.Format(checkksql, Identification);
DataTable dtt = DBHelper.SQlReturnData(checkksql, cmd);
if (dtt.Rows.Count > 1)
{
// 如果dtt的行数大于1,将lotno以逗号隔开的形式加入checklotno中1111111111111111111
foreach (DataRow row in dtt.Rows)
{
checklotno += row["lotno"].ToString() + ",";
}
checklotno = checklotno.TrimEnd(','); // 去除最后一个逗号
}
else if (dtt.Rows.Count == 1)
{
// 如果dtt的行数等于1,直接将lotno赋值给checklotno
checklotno = dtt.Rows[0]["lotno"].ToString();
}
string sql = string.Empty;
string ccsql = @"SELECT a.F_Id
FROM Sys_SRM_ItemsDetail a
INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
WHERE b.F_EnCode='BatchInOutErp' AND a.F_ItemCode='BatchIn' AND a.F_EnabledMark='1'";
ccsql = string.Format(ccsql);
DataTable dtdao = DBHelper.SQlReturnData(ccsql, cmd);
if (dtdao.Rows.Count > 0 && dtdao != null)
{
#region 原逻辑
// string checksql = @"select SUM(b.Quantity) AS SUMQty,SUM(b.RcvQuantity) AS ISSQty,a.transCode from ICSManufactureReceive b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.RCVCode AND a.WorkPoint=b.WorkPoint
// where a.Identification='{0}' GROUP BY a.transCode";
// checksql = string.Format(checksql, Identification);
// DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
// for (int i = 0; i < chekdt.Rows.Count; i++)
// {
// decimal SUMQty = Convert.ToDecimal(chekdt.Rows[i]["SUMQty"]);
// decimal ISSQty = Convert.ToDecimal(chekdt.Rows[i]["ISSQty"]);
// string trancode = chekdt.Rows[i]["transCode"].ToString();
// if (SUMQty - ISSQty == 0)
// {
// string pnsql = @"
// select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
// INTO #NewTempERP
// from ICSWareHouseLotInfoLog
// WHERE TransCode='{0}' AND ERPUpload='0'
// SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
// FROM #NewTempERP a
// INNER JOIN ICSManufactureReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
// INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
// INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
// GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
//DROP TABLE #NewTempERP";
// pnsql = string.Format(pnsql, trancode);
// DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
// string Inputstr = JsonConvert.SerializeObject(dt);
// //U9ICSManufactureReceiveURL
// string resultStr = "";
// log.Debug("入库单审核传入参数:" + Inputstr);
// if (DBHelper.IsU9())
// {
// log.Debug("入库单审核URL:" + ERPUrl.U9ICSManufactureReceiveURL);
// resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9ICSManufactureReceiveURL, Inputstr);
// }
// else
// resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSManufactureReceiveURL, Inputstr);
// Result result = new Result();
// result = JsonConvert.DeserializeObject<Result>(resultStr);
// if (result.Success)
// {
// try
// {
// foreach (DataRow dr in dt.Rows)
// {
// ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
// }
// }
// catch (Exception ex)
// {
// log.Debug(ex.ToString());
// log.Debug(resultStr);
// }
// }
// else
// {
// throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
// }
// }
// }
#endregion
string pnsql = @"
select DISTINCT a.LotNo,a.WorkPoint,a.InvCode,a.ToWarehouseCode,a.MUSER,a.Quantity,a.TransCode,a.TransSequence
INTO #NewTempERP
from ICSWareHouseLotInfoLog a
inner join ICSManufactureReceive b ON a.TransCode=b.RCVCode AND a.WorkPoint=b.WorkPoint
where a.Identification='{0}' AND ERPUpload='0'
GROUP BY a.LotNo,a.WorkPoint,a.InvCode,a.ToWarehouseCode,a.MUSER,a.Quantity,a.TransCode,a.TransSequence
HAVING SUM(b.Quantity)=SUM(b.RcvQuantity)
SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
FROM #NewTempERP a
INNER JOIN ICSManufactureReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
DROP TABLE #NewTempERP
SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
FROM #NewTempERP a
INNER JOIN ICSManufactureReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
DROP TABLE #NewTempERP";
pnsql = string.Format(pnsql, Identification);
DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
if (dt.Rows.Count>0&&dt!=null)
{
string Inputstr = JsonConvert.SerializeObject(dt);
//U9ICSManufactureReceiveURL
string resultStr = "";
log.Debug("入库单审核传入参数:" + Inputstr);
if (DBHelper.IsU9())
{
log.Debug("入库单审核URL:" + ERPUrl.U9ICSManufactureReceiveURL);
resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9ICSManufactureReceiveURL, Inputstr);
}
else
resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSManufactureReceiveURL, Inputstr);
Result result = new Result();
result = JsonConvert.DeserializeObject<Result>(resultStr);
if (result.Success)
{
try
{
foreach (DataRow dr in dt.Rows)
{
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
}
}
catch (Exception ex)
{
log.Debug(ex.ToString());
log.Debug(resultStr);
}
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
}
}
}
else
{
sql = @"DECLARE @quantity DECIMAL(38,4);
DECLARE @rcvquantity DECIMAL(38,4);
SELECT @quantity=SUM(Quantity),@rcvquantity=SUM(RCVQuantity) FROM ICSManufactureReceive b
WHERE b.RCVCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
IF (@quantity<>@rcvquantity)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo096") + @"',16,1);
RETURN
END
select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
INTO #NewTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0'
SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
FROM #NewTempERP a
INNER JOIN ICSManufactureReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
DROP TABLE #NewTempERP";
sql = string.Format(sql, Identification, checklotno, checkrcvcode);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
string Inputstr = JsonConvert.SerializeObject(dt);
//U9ICSManufactureReceiveURL
string resultStr = "";
log.Debug("入库单审核传入参数:" + Inputstr);
if (DBHelper.IsU9())
{
log.Debug("入库单审核URL:" + ERPUrl.U9ICSManufactureReceiveURL);
resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9ICSManufactureReceiveURL, Inputstr);
}
else
resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSManufactureReceiveURL, Inputstr);
Result result = new Result();
result = JsonConvert.DeserializeObject<Result>(resultStr);
if (result.Success)
{
try
{
foreach (DataRow dr in dt.Rows)
{
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
}
}
catch (Exception ex)
{
log.Debug(ex.ToString());
log.Debug(resultStr);
}
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
}
}
#endregion
DataTable chekdtt = new DataTable();
chekdtt.Columns.Add("checklotno", typeof(string));
DataRow newrow = chekdtt.NewRow();
newrow["checklotno"] = checklotno;
chekdtt.Rows.Add(newrow);
string aaaa = JsonConvert.SerializeObject(chekdtt);
return chekdtt;
}
catch (Exception)
{
throw;
}
}
#endregion
#region 产成品入库单(咖博士)
/// <summary>
/// 更新产成品入库单
/// </summary>
/// <param name="LotNo"></param>
/// <param name="Quantity"></param>
/// <param name="WorkPoint"></param>
/// <param name="cmd"></param>
/// <param name="language"></param>
public static void ManufactureMESReceive(string LotNo, string Quantity, string WorkPoint, string TransCode, SqlCommand cmd, Dictionary<string, string> language)
{
try
{
string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=c.Status FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO mo ON mo.MOCode=b.TransCode AND mo.Sequence=b.TransSequence AND mo.WorkPoint=b.WorkPoint
INNER JOIN ICSManufactureReceive c ON c.SourceCode=mo.MOCode AND c.SourceSequence=mo.Sequence AND c.WorkPoint=mo.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1'
IF (@Status IS NULL)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
RETURN
END
ELSE IF (@Status!='1')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
RETURN
END
UPDATE c SET c.RCVQuantity=ISNULL(c.RCVQuantity,0)+'{2}'
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO mo ON mo.MOCode=b.TransCode AND mo.Sequence=b.TransSequence AND mo.WorkPoint=b.WorkPoint
INNER JOIN ICSManufactureReceive c ON c.SourceCode=mo.MOCode AND c.SourceSequence=mo.Sequence AND c.WorkPoint=mo.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1' AND c.RCVCode='{3}'
IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO mo ON mo.MOCode=b.TransCode AND mo.Sequence=b.TransSequence AND mo.WorkPoint=b.WorkPoint
INNER JOIN ICSManufactureReceive c ON c.SourceCode=mo.MOCode AND c.SourceSequence=mo.Sequence AND c.WorkPoint=mo.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='1' AND c.RCVCode='{3}'
AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn013', c.Quantity,1,2,'')<c.RCVQuantity)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
END";
sql = string.Format(sql, LotNo, WorkPoint, Quantity, TransCode);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo138"));//"生产入库单更新失败!");
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// MES成品入库单调用ERP接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
/// <param name="language"></param>
/// <param name="BusinessCode"></param>
public static void ManufactureMESReceiveERP(string TransType, string Identification, string TransCode, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
{
try
{
string checklotno = "";
string checksql = @"SELECT c.rcvcode,a.lotno FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN (select RCVCode,Sequence,WorkPoint FROM ICSManufactureReceive) c ON b.TransCode=c.RCVCode
AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
left join ICSWareHouseLotInfo d on a.lotno=d.lotno and a.WorkPoint=d.WorkPoint
WHERE c.rcvcode in (select TransCode from ICSWareHouseLotInfoLog
where Identification='{0}' )
and d.lotno is null";
checksql = string.Format(checksql, Identification);
DataTable dtt = DBHelper.SQlReturnData(checksql, cmd);
if (dtt.Rows.Count > 1)
{
// 如果dtt的行数大于1,将lotno以逗号隔开的形式加入checklotno中
foreach (DataRow row in dtt.Rows)
{
checklotno += row["lotno"].ToString() + ",";
}
checklotno = checklotno.TrimEnd(','); // 去除最后一个逗号
}
else if (dtt.Rows.Count == 1)
{
// 如果dtt的行数等于1,直接将lotno赋值给checklotno
checklotno = dtt.Rows[0]["lotno"].ToString();
}
string checkrcvcode = "";
string checknewsql = @"SELECT distinct c.rcvcode FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN (select RCVCode,Sequence,WorkPoint FROM ICSManufactureReceive) c ON b.TransCode=c.RCVCode
AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
left join ICSWareHouseLotInfo d on a.lotno=d.lotno and a.WorkPoint=d.WorkPoint
WHERE c.rcvcode in (select TransCode from ICSWareHouseLotInfoLog
where Identification='{0}' )
and d.lotno is null";
checknewsql = string.Format(checknewsql, Identification);
DataTable dttnew = DBHelper.SQlReturnData(checknewsql, cmd);
if (dttnew.Rows.Count > 1)
{
// 如果dtt的行数大于1,将lotno以逗号隔开的形式加入checklotno中
foreach (DataRow row in dttnew.Rows)
{
checkrcvcode += row["rcvcode"].ToString() + ",";
}
checkrcvcode = checkrcvcode.TrimEnd(','); // 去除最后一个逗号
}
else if (dttnew.Rows.Count == 1)
{
// 如果dtt的行数等于1,直接将lotno赋值给checklotno
checkrcvcode = dttnew.Rows[0]["rcvcode"].ToString();
}
#region ERP开立状态单据审核
string sql = @"DECLARE @quantity DECIMAL(38,4);
DECLARE @rcvquantity DECIMAL(38,4);
SELECT @quantity=SUM(Quantity),@rcvquantity=SUM(RCVQuantity) FROM ICSManufactureReceive b
WHERE b.RCVCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
IF (@quantity<>@rcvquantity)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo096") + @"',16,1);
RETURN
END
select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
INTO #NewTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0'
SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
FROM #NewTempERP a
INNER JOIN ICSMO mo ON mo.MOCode=a.TransCode AND mo.Sequence=a.TransSequence AND mo.WorkPoint=a.WorkPoint
INNER JOIN ICSManufactureReceive b ON b.SourceCode=mo.MOCode AND b.Sequence=mo.Sequence AND b.WorkPoint=mo.WorkPoint AND b.RCVCode='{3}'
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock004' AND a.WorkPoint=conStock.WorkPoint
GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
DROP TABLE #NewTempERP";
sql = string.Format(sql, Identification, checklotno, checkrcvcode, TransCode);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
string Inputstr = JsonConvert.SerializeObject(dt);
log.Debug("MES成品入库单入库调用ERP接口传参:" + Environment.NewLine + Inputstr);
//U9ICSManufactureReceiveURL
string resultStr = "";
if (DBHelper.IsU9())
{ resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9ICSManufactureReceiveURL, Inputstr); }
else
resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSManufactureReceiveURL, Inputstr);
Result result = new Result();
result = JsonConvert.DeserializeObject<Result>(resultStr);
if (result.Success)
{
try
{
foreach (DataRow dr in dt.Rows)
{
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
}
}
catch (Exception ex)
{
log.Debug(ex.ToString());
log.Debug(resultStr);
}
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
}
#endregion
}
catch (Exception)
{
throw;
}
}
#endregion
#region 返工工单
/// <summary>
/// 返工工单
/// </summary>
/// <param name="TransCode"></param>
/// <param name="TransSequence"></param>
/// <param name="Quantity"></param>
/// <param name="WorkPoint"></param>
/// <param name="cmd"></param>
public static void ReWorkReceiveMo(string LotNo, string Quantity, string WarehouseCode,
string LocationCode, string WorkPoint, String User, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
{
try
{
string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=c.ERPStatus FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
IF (@Status IS NULL)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
RETURN
END
ELSE IF (@Status='3')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
RETURN
END
UPDATE d SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
AND d.IssueQuantity>dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn015', c.Quantity,1,2,''))
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
END";
sql = string.Format(sql, LotNo, WorkPoint, Quantity);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo366"));//"生产工单更新失败!");
}
}
catch (Exception)
{
throw;
}
}
/// <summary>
/// 返工工单
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void ReWorkReceiveMoERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
{
try
{
#region ERP开立状态单据审核
String sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
INTO #NewTempERP
from ICSWareHouseLotInfoLog
WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
SELECT c.DepCode+a.ToWarehouseCode+c.MOCode+a.MUSER AS Costre,c.DepCode,a.ToWarehouseCode AS WarehouseCode,c.MOCode,a.MUSER,d.Sequence AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,d.PickID AS MODetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
,a.WorkPoint,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
INTO #TempERP
FROM #NewTempERP 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 ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSMO c ON b.TransCode=c.MOCode AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSMOPick d ON d.MODetailID=c.MODetailID AND d.WorkPoint=c.WorkPoint and b.TransSequence=c.Sequence+'-'+d.Sequence
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock007' AND a.WorkPoint=conStock.WorkPoint
GROUP BY c.DepCode,a.ToWarehouseCode,c.MOCode,a.MUSER,a.InvCode,d.PickID,con.Enable,d.Sequence,conStock.Enable
,a.WorkPoint,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, '')
SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
SELECT Costre,Sequence,InvCode,Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
FROM #TempERP
DROP TABLE #TempERP
DROP TABLE #NewTempERP";
sql = string.Format(sql, Identification,BusinessCode);
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ICSReWorkReceiveMoURL, Inputstr);
Result result = new Result();
result = JsonConvert.DeserializeObject<Result>(resultStr);
if (result.Success)
{
try
{
JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
foreach (var item in res)
{
JObject jo = (JObject)item;
JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
foreach (var detail in resdetail)
{
JObject det = (JObject)detail;
string col = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
+ det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["MODetailID"].ToString(), Identification, jo["ID"].ToString(),
det["DetailID"].ToString(), jo["MRCVCode"].ToString(), det["Sequence"].ToString(), col, cmd, language, BusinessCode);
}
}
}
catch (Exception ex)
{
log.Debug(ex.ToString());
log.Debug(resultStr);
}
}
else
{
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
}
#endregion
}
catch (Exception)
{
throw;
}
}
#endregion
}
}