|
|
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 ICSOutsourcingService { 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 OutsourcingIssueDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language) { try { string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=b.Status FROM ICSOOPick a INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint WHERE b.OOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}'
IF (@Status IS NULL) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo104") + @"',16,1); RETURN END ELSE IF (@Status!='2') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo105") + @"',16,1); RETURN END UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}' FROM ICSOOPick a INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint WHERE b.OOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}'
IF EXISTS(SELECT a.ID FROM ICSOOPick a INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint WHERE b.OOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' and b.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1); RETURN END";
sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
if (!DBHelper.ExecuteNonQuery(sql, cmd)) { throw new Exception(language.GetNameByCode("WMSAPIInfo107")); } } catch (Exception) { throw; } }
/// <summary>
/// 委外发料接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void OutsourcingIssueDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language) { try { #region ERP
string sql = @"SELECT y.DepCode+a.FromWarehouseCode+y.OOCode+a.MUSER AS Costre,y.DepCode,a.FromWarehouseCode AS WarehouseCode,y.OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.FromWarehouseCode,y.OOCode,x.PickID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,x.PickID,con.Enable AS UpdateTodoQuantity ,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 ICSOutsourcingOrder y ON a.TransCode=y.OOCode AND a.WorkPoint=y.WorkPoint INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence 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='CompleteVerification' AND a.WorkPoint=conv.WorkPoint WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '5' GROUP BY y.DepCode,a.FromWarehouseCode,y.OOCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,x.PickID,x.OODetailID,con.Enable,conv.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,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification FROM #TempERP SELECT 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";
sql = string.Format(sql, Identification); DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre"); string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingIssueDocURL, 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; ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), cmd, language); } } } 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 OOApply(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language) { try { string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=a.Status FROM ICSOApply a WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
IF (@Status IS NULL) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo108") + @"',16,1); RETURN END ELSE IF (@Status!='2') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo109") + @"',16,1); RETURN END UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}' FROM ICSOApply a WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
IF EXISTS(SELECT a.ID FROM ICSOApply a WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1); RETURN END";
sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
if (!DBHelper.ExecuteNonQuery(sql, cmd)) { throw new Exception(language.GetNameByCode("WMSAPIInfo110")); } } catch (Exception) { throw; } }
/// <summary>
/// 委外领料申请单生产发料接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void OOApplyERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language) { try { #region ERP
string sql = @"SELECT a.FromWarehouseCode+b.ApplyCode+a.MUSER AS Costre,a.FromWarehouseCode AS WarehouseCode,b.ApplyCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,b.ApplyCode,b.ApplyDetailID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,b.ApplyDetailID,con.Enable AS UpdateTodoQuantity ,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 ICSOApply b ON a.TransCode=b.ApplyCode 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 conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '6' GROUP BY a.FromWarehouseCode,b.ApplyCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,b.ApplyDetailID,con.Enable,conv.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,'' AS DepCode,WarehouseCode AS WHCode,'委外领料申请单' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification FROM #TempERP SELECT Costre,Sequence,InvCode,Quantity,Amount,ApplyDetailID 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.OOApplyURL, 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; ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), cmd, language); } } } 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 OOIssue(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language) { try { string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=a.Status FROM ICSOIssue a WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
IF (@Status IS NULL) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo111") + @"',16,1); RETURN END ELSE IF (@Status!='1') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo112") + @"',16,1); RETURN END UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}' FROM ICSOIssue a WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
IF EXISTS(SELECT a.ID FROM ICSOIssue a WHERE a.IssueCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1); RETURN END";
sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
if (!DBHelper.ExecuteNonQuery(sql, cmd)) { throw new Exception(language.GetNameByCode("WMSAPIInfo113")); } } catch (Exception) { throw; } }
/// <summary>
/// 委外材料出库单生产发料接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void OOIssueERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language) { try { #region ERP开立状态单据审核
string sql = @"IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSOIssue 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("WMSAPIInfo095") + @"',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 ICSWareHouseLotInfoLog a INNER JOIN ICSOIssue 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 WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '7' GROUP BY b.IssueID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
sql = string.Format(sql, Identification); DataTable dt = DBHelper.SQlReturnData(sql, cmd);
string Inputstr = JsonConvert.SerializeObject(dt); string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OOIssueURL, 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); } } 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 OutsourcingIssueDoNegative(string TransType, string LogID, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language) { try { string table = ""; string sql = ""; if (string.IsNullOrWhiteSpace(LogID)) { string type = ""; if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()) { table = "INNER JOIN ICSOOPick e ON c.SourceDetailID=e.PickID AND c.WorkPoint=e.WorkPoint"; type = "1"; } else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()) { table = "INNER JOIN ICSOApply e ON c.SourceDetailID=e.ApplyDetailID AND c.WorkPoint=e.WorkPoint"; type = "2"; } else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription()) { table = "INNER JOIN ICSOIssue 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 ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode 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 ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode 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 ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode 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 ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode 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("WMSAPIInfo193") + @"',16,1); END";
sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, type); #endregion
} else { if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()) { table = @"INNER JOIN ICSOutsourcingOrder b ON a.TransCode=b.OOCode AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSOOPick c ON b.OODetailID = c.OODetailID AND b.WorkPoint = c.WorkPoint AND a.TransSequence = b.Sequence + '~' + c.Sequence";
} else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()) { table = "INNER JOIN ICSOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint"; } else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription()) { table = "INNER JOIN ICSOIssue 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("WMSAPIInfo193") + @"',16,1); END";
sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, LogID); #endregion
} if (!DBHelper.ExecuteNonQuery(sql, cmd)) { throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
} } catch (Exception) { throw; } }
/// <summary>
/// 委外退料接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void OutsourcingIssueDoNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language) { try { #region ERP
string sql = string.Empty; if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()) { sql = @"SELECT y.DepCode+a.ToWarehouseCode+y.OOCode+a.MUSER AS Costre,y.DepCode,a.ToWarehouseCode AS WarehouseCode,y.OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.ToWarehouseCode,y.OOCode,x.PickID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,x.PickID AS SourceDetailID,con.Enable AS UpdateTodoQuantity ,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 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 ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint INNER JOIN ICSOOPick x ON c.SourceDetailID=x.PickID AND c.WorkPoint=x.WorkPoint INNER JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')='' GROUP BY y.DepCode,a.ToWarehouseCode,y.OOCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,x.PickID,con.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.OOCode+a.MUSER AS Costre,y.DepCode,a.ToWarehouseCode AS WarehouseCode,y.OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.ToWarehouseCode,y.OOCode,x.PickID,a.InvCode) AS Sequence, a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,x.PickID AS SourceDetailID,con.Enable AS UpdateTodoQuantity ,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 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 ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint INNER JOIN ICSOutsourcingOrder y ON b.TransCode=y.OOCode AND b.WorkPoint=y.WorkPoint INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID 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 WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')<>'' GROUP BY y.DepCode,a.ToWarehouseCode,y.OOCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,x.PickID,con.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,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
DROP TABLE #TempERP";
} else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()) { sql = @"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,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity ,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 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 ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint INNER JOIN ICSOApply z ON c.SourceDetailID=z.ApplyDetailID AND c.WorkPoint=z.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')='' GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,z.ApplyDetailID,con.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,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity ,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 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 ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint INNER JOIN ICSOApply 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 WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')<>'' GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,z.ApplyDetailID,con.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 FROM #TempERP SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
DROP TABLE #TempERP";
} //根据材料出库单查询上游单据,根据上游单据生成红字材料出库
else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription()) { sql = @"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.OOCode) AS OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.OOCode),a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity ,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 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 ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint INNER JOIN ICSOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint LEFT JOIN ICSOApply 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 a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')='' GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.OOCode),a.MUSER,a.InvCode,m.PickID,m.ApplyDetailID,con.Enable,lot.Amount,lot.Quantity ,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.OOCode) AS OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.OOCode),a.InvCode) AS Sequence, a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity ,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 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 ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint LEFT JOIN ICSOApply 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 a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')<>'' GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.OOCode),a.MUSER,a.InvCode,m.PickID,m.ApplyDetailID,con.Enable,lot.Amount,lot.Quantity ,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("WMSAPIInfo116") + @"',16,1); END
SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
DROP TABLE #TempERP";
} 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 = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingIssueDoNegativeURL, 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; ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["IssueNEGCode"].ToString(), det["Sequence"].ToString(), cmd, language); } } //List<ICSERPReturnIssueNEG> negList = JsonConvert.DeserializeObject<List<ICSERPReturnIssueNEG>>(result.Data.ToString());
//foreach (var neg in negList)
//{
// foreach (var detail in neg.details)
// {
// ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, detail.SourceDetailID, Identification, neg.ID, detail.DetailID, neg.IssueNEGCode, detail.Sequence, cmd);
// }
//}
} 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="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void OutsourcingDeliveryNoticeERP(string ODNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language) { try { #region ERP
string sql = @"SELECT a.VenCode+a.DepCode+y.OOCode+a.MUSER AS Costre,a.VenCode,a.DepCode,y.OOCode,a.MUSER,a.MTIME,
a.Sequence,a.InvCode,a.Quantity,a.Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,a.OODetailID ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN 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 ICSODeliveryNotice a INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint LEFT JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint INNER JOIN ICSOutsourcingOrder y ON a.OODetailID=y.OODetailID AND a.WorkPoint=y.WorkPoint WHERE a.ODNCode='{0}' AND a.WorkPoint='{1}'
SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,OOCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,OODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
DROP TABLE #TempERP";
sql = string.Format(sql, ODNCode, WorkPoint); DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre"); string resultStr = HTTPHelper.HttpPost("委外到货", ERPUrl.ODeliveryNoticeURL, 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 ERPupdate = @"update ICSODeliveryNotice set ODNCode='{0}',Sequence='{1}',ODNID='{2}',ODNDetailID='{3}'
where OODetailID='{4}' AND ODNType='1' AND ODNCode='{5}' ";
ERPupdate = string.Format(ERPupdate, jo["ODNCode"], det["Sequence"], jo["ID"], det["DetailID"], det["OODetailID"], ODNCode);
if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd)) { throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
} } } } 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 OutsourcingReceiveDoc(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.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 InQuantity=ISNULL(InQuantity,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.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 ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<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("WMSAPIInfo115"));//"委外退料单更新失败!");
} } catch (Exception) { throw; } }
/// <summary>
/// 委外入库接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void OutsourcingReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language) { try { #region ERP
string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.OOCode+a.MUSER+f.ODNCode AS Costre,c.OODetailID AS Costre2,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.OOCode,c.OOID,f.ODNCode,f.ODNDetailID,a.MUSER,f.Sequence AS ODNSequence,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.OOCode,c.OODetailID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.OODetailID,con.Enable AS UpdateTodoQuantity,conn.Enable ,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 INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint INNER JOIN ICSOASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint INNER JOIN ICSODeliveryNotice f ON g.OASNCode=f.OASNCode AND g.WorkPoint=f.WorkPoint INNER JOIN ICSOutsourcingOrder c ON b.TransCode = c.OOCode AND b.TransSequence = c.Sequence AND f.OODetailID = c.OODetailID AND b.WorkPoint = c.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conn ON con.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001' INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint WHERE a.Identification='{0}' AND ERPUpload='0' GROUP BY c.VenCode,a.ToWarehouseCode,c.OOCode,a.MUSER,lot.Amount,lot.Quantity,f.ODNCode,f.ODNDetailID,f.Sequence,a.InvCode,c.OOID,c.OODetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conn.Enable,conv.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,VenCode,WarehouseCode AS WHCode,OOCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity,CompleteVerification FROM #TempERP SELECT Costre,Costre2,Sequence,ODNSequence,InvCode,Quantity,Amount,OODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP SELECT c.OODetailID AS Costre2,a.TransCode,a.TransSequence AS Sequence,a.InvCode,a.Quantity,c.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 ICSOutsourcingOrder b ON b.OOCode=a.TransCode AND b.WorkPoint=a.WorkPoint INNER JOIN ICSOOPick c ON c.OODetailID=b.OODetailID 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 WHERE a.Identification='{0}' AND a.TransType='12'
DROP TABLE #TempERP";
sql = string.Format(sql, Identification); DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "detailss", "Costre2"); string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocURL, 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; ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language); JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString()); foreach (var details in resdetails) { JObject dets = (JObject)details; ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, det["IDSS"].ToString(), dets["DetailID"].ToString(), dets["MRCVCode"].ToString(), dets["Sequence"].ToString(), cmd, language); } } } } 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 ODeliveryNoticeIn(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 ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='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 ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='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 ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1' AND c.Quantity<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("WMSAPIInfo117"));//"委外到货单更新失败!");
} } catch (Exception) { throw; } }
/// <summary>
/// 审核的委外到货单接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void ODeliveryNoticeInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language) { try { #region ERP
string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.ODNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.ODNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.ODNDetailID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.ODNDetailID,con.Enable AS UpdateTodoQuantity,conn.Enable ,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 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 ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conn ON con.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001' WHERE a.Identification='{0}' AND ERPUpload='0' GROUP BY c.VenCode,a.ToWarehouseCode,c.ODNCode,a.MUSER,lot.Amount,lot.Quantity,a.InvCode,c.ODNDetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conn.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,VenCode,WarehouseCode AS WHCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity FROM #TempERP SELECT Costre,Sequence,InvCode,Quantity,Amount,ODNDetailID,Currency,UnitPrice,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.ODeliveryNoticeInURL, 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; ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language); } } } 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 OutsourcingRejectDocIn(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 ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
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 ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='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 ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3' AND c.Quantity<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("WMSAPIInfo118"));//"委外拒收单更新失败!");
} } catch (Exception) { throw; } }
/// <summary>
/// 委外拒收接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void OutsourcingRejectDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language) { // try
// {
// #region ERP
// string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.ODNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,d.ODNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.ODNCode,c.ODNDetailID,a.InvCode) AS Sequence,
// a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,d.ODNDetailID,Enable AS UpdateTodoQuantity
// ,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 ICSWareHouseLotInfoLog a
// INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
// INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
// INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
// INNER JOIN 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 ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
// INNER JOIN ICSODeliveryNotice d ON c.OODetailID=d.ODNDetailID AND d.WorkPoint=c.WorkPoint
// INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
// WHERE a.Identification='{0}' AND ERPUpload='0'
// GROUP BY c.VenCode,a.ToWarehouseCode,c.ODNCode,d.ODNCode,a.MUSER,a.InvCode,d.ODNDetailID,c.ODNDetailID,isnull((c.UnitPrice),0),c.Currency,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,VenCode,WarehouseCode AS WHCode,ODNCode AS DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint FROM #TempERP
//SELECT Costre,Sequence,InvCode,Quantity,Amount,ODNDetailID AS DNDetailID,Currency,UnitPrice,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, "Vouchs", "Costre");
// string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateWPuArrivalVouchURL, 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;
// ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["OODetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
// }
// }
// }
// 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 OutsourcingRejectDocInNewERP(string ODNCode, string OJDNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language) { try { #region ERP
string sql = @"SELECT a.VenCode+a.DepCode+a.DNCode+a.MUSER AS Costre,a.VenCode,a.DepCode,a.ODNCode AS DNCode,a.MUSER,a.MTIME,
a.Sequence,a.InvCode,Sum(x.Quantity) AS Quantity,a.Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,a.ODNDetailID AS DNDetailID ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN 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 ICSODeliveryNotice a INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint LEFT JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint INNER JOIN ICSODeliveryNotice x ON a.ODNDetailID=x.OODetailID AND a.WorkPoint=x.WorkPoint WHERE a.ODNCode='{0}' AND a.WorkPoint='{1}' GROUP BY a.VenCode,a.DepCode,a.ODNCode,a.MUSER,a.MTIME,a.Sequence,a.InvCode,a.Amount,a.Quantity,a.UnitPrice,a.Currency,a.ODNDetailID, a.WorkPoint,ISNULL(ext.ProjectCode, ''),ISNULL(invBat.BatchEnable, ''),ISNULL(ext.BatchCode, ''),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,VenCode,DepCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,DNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
DROP TABLE #TempERP";
sql = string.Format(sql, ODNCode, WorkPoint); DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre"); string resultStr = HTTPHelper.HttpPost("委外拒收", ERPUrl.CreateWPuArrivalVouchURL, 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; //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RJTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
string ERPupdate = @"update ICSODeliveryNotice set ODNCode='{0}',Sequence='{1}',ODNID='{2}',ODNDetailID='{3}'
where OODetailID='{4}' AND ODNType='3' AND ODNCode='{5}' ";
ERPupdate = string.Format(ERPupdate, jo["RJTCode"], det["Sequence"], jo["ID"], det["DetailID"], det["DNDetailID"], OJDNCode);
if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd)) { throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
} } } } 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 OutsourcingReturnBack(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language) { try { string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' AND ODNType='2' and WorkPoint='{1}'
IF (@Status IS NULL) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo119") + @"',16,1); RETURN END ELSE IF (@Status!='2') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo120") + @"',16,1); RETURN END
UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}' FROM ICSODeliveryNotice a WHERE a.ODNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND ODNType='2'
IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.RCVQuantity AND ODNType='2') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1); RETURN END";
sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
if (!DBHelper.ExecuteNonQuery(sql, cmd)) { throw new Exception(language.GetNameByCode("WMSAPIInfo121"));//"委外退货单更新失败!");
} } catch (Exception) { throw; } }
/// <summary>
/// 委外退货接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void OutsourcingReturnBackERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language) { try { #region ERP
string sql = @"SELECT y.VenCode+a.FromWarehouseCode+y.ODNCode+a.MUSER AS Costre,y.VenCode,a.FromWarehouseCode AS WarehouseCode,y.ODNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.VenCode,a.FromWarehouseCode,y.ODNCode,y.ODNDetailID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,con.Enable AS UpdateTodoQuantity ,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 ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '11' GROUP BY y.VenCode,a.FromWarehouseCode,y.ODNCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),con.Enable,conv.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,VenCode,WarehouseCode AS WHCode,ODNCode AS ODNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification FROM #TempERP SELECT Costre,Sequence,InvCode,Quantity,Amount,ODNDetailID AS ODNRTDetailID,Currency,UnitPrice,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.OutsourcingReturnBackURL, 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; ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["ORCVNEGCode"].ToString(), det["Sequence"].ToString(), cmd, language); } } } 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 OutsourcingReceiveDocNegative(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language) { try { string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=a.Status FROM ICSOutsourcingReceive a WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
IF (@Status IS NULL) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo122") + @"',16,1); RETURN END ELSE IF (@Status!='1') BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo123") + @"',16,1); RETURN END UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}' FROM ICSOutsourcingReceive a WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
IF EXISTS(SELECT a.ID FROM ICSOutsourcingReceive a WHERE a.RCVCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='2' AND a.Quantity<a.RCVQuantity) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1); RETURN END";
sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
if (!DBHelper.ExecuteNonQuery(sql, cmd)) { throw new Exception(language.GetNameByCode("WMSAPIInfo124"));//"委外红字入库单更新失败!");
} } catch (Exception) { throw; } }
/// <summary>
/// 开立委外红字入库接口
/// </summary>
/// <param name="TransType"></param>
/// <param name="Identification"></param>
/// <param name="cmd"></param>
public static void OutsourcingReceiveDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language) { try { #region ERP开立状态单据审核
string sql = @"IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity) BEGIN RAISERROR('" + language.GetNameByCode("WMSAPIInfo103") + @"',16,1); RETURN END SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint FROM ICSWareHouseLotInfoLog a INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode 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='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '12' GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
sql = string.Format(sql, Identification); DataTable dt = DBHelper.SQlReturnData(sql, cmd);
string Inputstr = JsonConvert.SerializeObject(dt); string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocNegativeURL, 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); } } catch (Exception ex) { log.Debug(ex.ToString()); log.Debug(resultStr); } } else { throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message); } #endregion
} catch (Exception) { throw; } } #endregion
} }
|