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.
1402 lines
103 KiB
1402 lines
103 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 ICSSalesService
|
|
{
|
|
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 SalesShipmentInspectDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string TransID, string CourierCode)
|
|
{
|
|
try
|
|
{
|
|
string sql = @"DECLARE @Status VARCHAR(10)
|
|
SELECT @Status=a.Status FROM ICSSDN a
|
|
WHERE a.SDNCode='{0}' AND a.Sequence='{3}' and a.id='{4}' AND a.WorkPoint='{1}' AND a.Type='1'
|
|
|
|
IF (@Status IS NULL)
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo139") + @"',16,1);
|
|
RETURN
|
|
END
|
|
ELSE IF (@Status!='2')
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo140") + @"',16,1);
|
|
RETURN
|
|
END
|
|
UPDATE a SET a.EATTRIBUTE5='已检验'
|
|
FROM ICSSDN a
|
|
WHERE a.SDNCode='{0}' AND a.Sequence='{3}' and a.id='{4}' AND a.WorkPoint='{1}' AND a.Type='1'
|
|
|
|
";
|
|
|
|
sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID, CourierCode);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo141"));//"销售领料单更新失败!");
|
|
}
|
|
}
|
|
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 SalesShipmentDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string TransID, string CourierCode)
|
|
{
|
|
try
|
|
{
|
|
string sql = @"DECLARE @Status VARCHAR(10)
|
|
SELECT @Status=a.Status FROM ICSSDN a
|
|
WHERE a.SDNCode='{0}' AND a.Sequence='{3}' and a.id='{4}' AND a.WorkPoint='{1}' AND a.Type='1'
|
|
|
|
IF (@Status IS NULL)
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo139") + @"',16,1);
|
|
RETURN
|
|
END
|
|
ELSE IF (@Status!='2')
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo140") + @"',16,1);
|
|
RETURN
|
|
END
|
|
UPDATE a SET SDNQuantity=ISNULL(SDNQuantity,0)+'{2}'
|
|
FROM ICSSDN a
|
|
WHERE a.SDNCode='{0}' AND a.Sequence='{3}' and a.id='{4}' AND a.WorkPoint='{1}' AND a.Type='1'
|
|
|
|
IF EXISTS(SELECT a.ID FROM ICSSDN a
|
|
WHERE a.SDNCode='{0}' AND a.Sequence='{3}' and a.id='{4}' and a.WorkPoint='{1}' AND a.Type='1' AND a.Quantity<a.SDNQuantity)
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
|
|
RETURN
|
|
END";
|
|
|
|
sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID, CourierCode);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo141"));//"销售领料单更新失败!");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 销售出库接口
|
|
/// </summary>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void SalesShipmentDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
|
|
{
|
|
try
|
|
{
|
|
#region ERP
|
|
string sql = @"--+b.SOCode
|
|
SELECT b.CusCode+a.FromWarehouseCode+b.SDNCode+a.MUSER AS Costre
|
|
,a.TransCode+a.TransSequence+b.CusCode+a.FromWarehouseCode+b.SDNCode+b.SOCode+a.MUSER AS Costre2
|
|
,b.CusCode,a.FromWarehouseCode AS WarehouseCode,b.SDNCode,b.SOCode,b.SOSequence,a.MUSER,ROW_NUMBER() OVER (ORDER BY b.CusCode,a.FromWarehouseCode,b.SDNCode,b.SDNDetailID,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.SDNDetailID,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
|
|
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 ICSSDN b ON a.TransCode=b.SDNCode AND a.TransSequence=b.Sequence and a.transid=b.id 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='UpdateStock005' 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 b.Type='1' AND a.BusinessCode = '{1}'
|
|
GROUP BY a.TransCode,a.TransSequence,conWhCode.Enable,inv.AmountEnable,b.CusCode,a.FromWarehouseCode,b.SDNCode,b.SOCode,b.SOSequence,a.MUSER,a.InvCode,b.SDNDetailID,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,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
|
|
SELECT Costre,Costre2,Sequence,SOCode,SOSequence,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,InvCode,Quantity,Amount,SDNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
|
|
|
|
SELECT a.LotNo,a.Quantity,lot.ExpirationDate,b.EATTRIBUTE3 AS TrackingNO,
|
|
a.TransCode+a.TransSequence+b.CusCode+a.FromWarehouseCode+b.SDNCode+b.SOCode+a.MUSER AS Costre2
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
|
|
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
|
|
INNER JOIN ICSSDN b ON a.TransCode=b.SDNCode AND a.TransSequence=b.Sequence and a.transid=b.id AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1' AND a.BusinessCode = '{1}'
|
|
|
|
DROP TABLE #TempERP";//--分组去除了SOCode SOSequence;(重新加上了,改为表体中)
|
|
sql = string.Format(sql, Identification, BusinessCode);
|
|
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
|
|
|
|
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
|
|
//string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
|
|
log.Debug("销售发货ERP接口传参:" + Environment.NewLine + Inputstr);
|
|
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesDeliveryNoticeURL, 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["SDNDetailID"].ToString(), Identification, jo["ID"].ToString(),
|
|
det["DetailID"].ToString(), jo["SSDCode"].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;
|
|
}
|
|
}
|
|
|
|
public static void U9SalesShipmentDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
|
|
{
|
|
try
|
|
{
|
|
#region ERP
|
|
string sql = @"SELECT b.CusCode+a.FromWarehouseCode+b.SDNCode+a.MUSER AS Costre,b.CusCode,a.FromWarehouseCode AS WarehouseCode,b.SDNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY b.CusCode,a.FromWarehouseCode,b.SDNCode,b.SDNDetailID,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.SDNDetailID,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 ,b.SOCode,b.SOSequence as SrcDocSubLineNo,b.EATTRIBUTE2 as PrivateDescSeg3
|
|
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 ICSSDN b ON a.TransCode=b.SDNCode 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='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
|
|
WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1' AND a.BusinessCode = '19'
|
|
GROUP BY inv.AmountEnable,b.CusCode,a.FromWarehouseCode,b.SDNCode,a.MUSER,a.InvCode,b.SDNDetailID,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, ''),b.SOCode,b.SOSequence,b.EATTRIBUTE2
|
|
|
|
SELECT DISTINCT Costre,WorkPoint,CusCode,WarehouseCode AS WHCode,SOCode AS SDNCode,SrcDocSubLineNo,MUSER AS [User],SYSDATETIME() AS ShipDate,'ST1' as ShipDocTypeCode ,cast(0 as bit) as SOIsConsign,UpdateTodoQuantity,UpdateStock,InvCode,Quantity,Amount,SDNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,PrivateDescSeg3 FROM #TempERP
|
|
|
|
DROP TABLE #TempERP";
|
|
sql = string.Format(sql, Identification);
|
|
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
|
|
|
|
string Inputstr = DataToJsonHelper.ToJson(ds.Tables[0]);
|
|
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9SalesShipDocURL, Inputstr);
|
|
Result result = new Result();
|
|
result = JsonConvert.DeserializeObject<Result>(resultStr);
|
|
if (result.Success)
|
|
{
|
|
try
|
|
{
|
|
if (result.Data.ToString() != "")
|
|
{
|
|
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["SDNDetailID"].ToString(), Identification, jo["ID"].ToString(),
|
|
det["DetailID"].ToString(), jo["SSDCode"].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 SalesShipmentOutDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string TransID, string CourierCode)
|
|
{
|
|
try
|
|
{
|
|
string sql = @"DECLARE @Status VARCHAR(10)
|
|
SELECT @Status=a.Status FROM ICSSSD a
|
|
WHERE a.SSDCode='{0}' AND a.Sequence='{3}' and a.id='{4}' AND a.WorkPoint='{1}' AND a.Type='1'
|
|
|
|
IF (@Status IS NULL)
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo139") + @"',16,1);
|
|
RETURN
|
|
END
|
|
ELSE IF (@Status!='1')
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo140") + @"',16,1);
|
|
RETURN
|
|
END
|
|
UPDATE a SET SSDQuantity=ISNULL(SSDQuantity,0)+'{2}',EATTRIBUTE3='{5}'
|
|
FROM ICSSSD a
|
|
WHERE a.SSDCode='{0}' AND a.Sequence='{3}' and a.id='{4}' AND a.WorkPoint='{1}' AND a.Type='1'
|
|
|
|
IF EXISTS(SELECT a.ID FROM ICSSSD a
|
|
WHERE a.SSDCode='{0}' AND a.Sequence='{3}' and a.id='{4}' and a.WorkPoint='{1}' AND a.Type='1' AND a.Quantity<a.SSDQuantity)
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
|
|
RETURN
|
|
END";
|
|
|
|
sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID, CourierCode);
|
|
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo141"));//"销售领料单更新失败!");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 销售出库-出库单接口
|
|
/// </summary>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void SalesShipmentDocOutERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode,string UserCode)
|
|
{
|
|
try
|
|
{
|
|
string sql = "";
|
|
#region ERP开立状态单据审核
|
|
if (DBHelper.IsPNU9())
|
|
{
|
|
sql = @"SELECT b.CusCode+a.FromWarehouseCode+b.SSDCode+a.MUSER AS Costre
|
|
,a.TransCode+a.TransSequence+b.CusCode+a.FromWarehouseCode+b.SSDCode+a.MUSER AS Costre2
|
|
,b.CusCode,a.FromWarehouseCode AS WarehouseCode,b.SSDCode,b.Sequence,a.MUSER,
|
|
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.SSDDetailID,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
|
|
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 ICSSSD b ON a.TransCode=b.SSDCode 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='UpdateStock005' 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 BusinessCode = '55' AND b.Type='1'
|
|
GROUP BY a.TransCode,a.TransSequence,conWhCode.Enable,inv.AmountEnable,b.CusCode,a.FromWarehouseCode,b.SSDCode,b.Sequence,a.MUSER,a.InvCode,b.SSDDetailID,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,SSDCode AS DocNo,0 AS ID FROM #TempERP
|
|
SELECT Costre,Costre2,Sequence,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,InvCode,Quantity,Quantity AS IssuedQuantity,Amount,SSDDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
|
|
|
|
SELECT a.LotNo,a.Quantity,lot.ExpirationDate,b.EATTRIBUTE3 AS TrackingNO,
|
|
a.TransCode+a.TransSequence+b.CusCode+a.FromWarehouseCode+b.SSDCode+b.SDNCode+a.MUSER AS Costre2
|
|
FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
|
|
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
|
|
INNER JOIN ICSSSD b ON a.TransCode=b.SSDCode AND a.TransSequence=b.Sequence and a.transid=b.id AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1' AND a.BusinessCode = '{1}'
|
|
|
|
DROP TABLE #TempERP";
|
|
sql = string.Format(sql, Identification, BusinessCode);
|
|
|
|
|
|
|
|
|
|
string checksql = @"select SUM(b.Quantity) AS SUMQty,SUM(b.SSDQuantity) AS ISSQty,a.transCode from ICSSSD b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.SSDCode 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 b.SSDCode AS Costre
|
|
,a.TransCode+a.TransSequence+b.CusCode+a.FromWarehouseCode+b.SSDCode+a.MUSER AS Costre2
|
|
,b.CusCode,a.FromWarehouseCode AS WarehouseCode,b.SSDCode,b.Sequence,a.MUSER,
|
|
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.SSDDetailID,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
|
|
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 ICSSSD b ON a.TransCode=b.SSDCode 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='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
|
|
INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
|
|
WHERE a.TransCode='{0}' AND ERPUpload='0' AND BusinessCode = '55' AND b.Type='1' and a.EATTRIBUTE1<>'1'
|
|
GROUP BY a.TransCode,a.TransSequence,conWhCode.Enable,inv.AmountEnable,b.CusCode,a.FromWarehouseCode,b.SSDCode,b.Sequence,a.MUSER,a.InvCode,b.SSDDetailID,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,SSDCode AS DocNo,0 AS ID,1 AS IsEnd FROM #TempERP
|
|
SELECT Costre,Sequence,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,InvCode,Quantity,Quantity AS IssuedQuantity,Amount,SSDDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
|
|
|
|
DROP TABLE #TempERP";
|
|
pnsql = string.Format(pnsql, trancode);
|
|
DataSet ds = DBHelper.SQlReturnDataSet(pnsql, cmd);
|
|
|
|
string Inputstr = DataToJsonHelper.DataSetToJson2(ds, "details", "Costre");
|
|
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SMShipURL, Inputstr);
|
|
Result result = new Result();
|
|
|
|
//sql = string.Format(sql, Identification);
|
|
////DataTable dt = DBHelper.SQlReturnData(sql, cmd);
|
|
//DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
|
|
|
|
////string Inputstr = JsonConvert.SerializeObject(dt);
|
|
//string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
|
|
//string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PNSalesDeliveryNoticeOutURL, 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 a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1',Quantity='{6}'
|
|
// FROM ICSWareHouseLotInfoLog a
|
|
// INNER JOIN ICSSSD c ON a.TransCode=c.SSDCOde AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
//INNER JOIN ICSInventoryLot lot on a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
|
|
//INNER JOIN ICSExtension d ON lot.ExtensionID=d.id and lot.WorkPoint=d.WorkPoint
|
|
// WHERE c.SSDCode='{0}' AND a.BusinessCode ='{7}' AND d.BatchCode='{8}' AND lot.InvCode='{1}'";
|
|
// ERPupdate = string.Format(ERPupdate);
|
|
// if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
|
|
// {
|
|
// throw new Exception(TransType + language.GetNameByCode("WMSAPIInfo175"));//"回写日志失败!");
|
|
// }
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Debug(ex.ToString());
|
|
log.Debug(resultStr);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string newchecksql = @"select DISTINCT b.Quantity AS CountQty,b.SSDQuantity AS CountISSQty,a.transCode,a.transSequence from ICSSSD b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.SSDCode and a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
|
|
where a.Identification='{0}' and BusinessCode='55'";
|
|
newchecksql = string.Format(newchecksql, Identification);
|
|
DataTable newchekdt = DBHelper.SQlReturnData(newchecksql, cmd);
|
|
for (int i = 0; i < newchekdt.Rows.Count; i++)
|
|
{
|
|
decimal CountQty = Convert.ToDecimal(newchekdt.Rows[i]["CountQty"]);
|
|
decimal CountISSQty = Convert.ToDecimal(newchekdt.Rows[i]["CountISSQty"]);
|
|
string Counttrancode = newchekdt.Rows[i]["transCode"].ToString();
|
|
string CounttransSequence = newchekdt.Rows[i]["transSequence"].ToString();
|
|
if (CountQty - CountISSQty == 0)
|
|
{
|
|
string pnsql = @"SELECT b.SSDCode AS Costre
|
|
,a.TransCode+a.TransSequence+b.CusCode+a.FromWarehouseCode+b.SSDCode+a.MUSER AS Costre2
|
|
,b.CusCode,a.FromWarehouseCode AS WarehouseCode,b.SSDCode,b.Sequence,a.MUSER,
|
|
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.SSDDetailID,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
|
|
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 ICSSSD b ON a.TransCode=b.SSDCode 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='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
|
|
INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
|
|
WHERE a.TransCode='{0}' and a.TransSequence='{1}' AND ERPUpload='0' AND BusinessCode = '55' AND b.Type='1' and a.EATTRIBUTE1<>'1'
|
|
GROUP BY a.TransCode,a.TransSequence,conWhCode.Enable,inv.AmountEnable,b.CusCode,a.FromWarehouseCode,b.SSDCode,b.Sequence,a.MUSER,a.InvCode,b.SSDDetailID,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,SSDCode AS DocNo,0 AS ID,0 AS IsEnd FROM #TempERP
|
|
SELECT Costre,Sequence,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,InvCode,Quantity,Quantity AS IssuedQuantity,Amount,SSDDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
|
|
|
|
DROP TABLE #TempERP";
|
|
pnsql = string.Format(pnsql, Counttrancode, CounttransSequence);
|
|
DataSet ds = DBHelper.SQlReturnDataSet(pnsql, cmd);
|
|
|
|
string Inputstr = DataToJsonHelper.DataSetToJson2(ds, "details", "Costre");
|
|
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SMShipURL, Inputstr);
|
|
Result result = new Result();
|
|
|
|
//sql = string.Format(sql, Identification);
|
|
////DataTable dt = DBHelper.SQlReturnData(sql, cmd);
|
|
//DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
|
|
|
|
////string Inputstr = JsonConvert.SerializeObject(dt);
|
|
//string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
|
|
//string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PNSalesDeliveryNoticeOutURL, Inputstr);
|
|
//Result result = new Result();
|
|
result = JsonConvert.DeserializeObject<Result>(resultStr);
|
|
if (result.Success)
|
|
{
|
|
try
|
|
{
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Debug(ex.ToString());
|
|
log.Debug(resultStr);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
//审核销售出库单接口是否分批提交 1为是 0为否
|
|
string ssql = @"select F_EnabledMark from Sys_SRM_Items where F_EnCode='allin' and F_EnabledMark='1'";
|
|
DataTable dt = DBHelper.SQlReturnData(ssql, cmd);
|
|
|
|
if (dt.Rows.Count == 0)
|
|
{
|
|
sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode,transid
|
|
INTO #NewTempERP
|
|
from ICSWareHouseLotInfoLog
|
|
WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '55'
|
|
|
|
IF EXISTS(SELECT b.ID FROM ICSSSD b
|
|
WHERE b.SSDCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
|
|
AND b.Quantity!=b.SSDQuantity and b.type='1')
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo529") + @"',16,1);
|
|
RETURN
|
|
END
|
|
|
|
SELECT a.TransCode AS Costre,b.SSDID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint,b.CusCode
|
|
FROM #NewTempERP a
|
|
INNER JOIN ICSSSD b ON a.TransCode=b.SSDCode AND a.TransSequence=b.Sequence and a.transid=b.id AND a.WorkPoint=b.WorkPoint and b.type='1'
|
|
INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
|
|
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
|
|
GROUP BY b.SSDID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint,a.TransCode,b.CusCode
|
|
|
|
SELECT DISTINCT a.TransCode AS Costre,a.TransCode+a.TransSequence+a.InvCode AS Costre2,a.InvCode FROM #NewTempERP a
|
|
|
|
SELECT DISTINCT a.TransCode+a.TransSequence+a.InvCode AS Costre2,a.LotNo,lot.ExpirationDate,'' AS TrackingNO
|
|
FROM #NewTempERP a
|
|
INNER JOIN ICSInventoryLot lot ON lot.LotNo=a.lotNo AND lot.WorkPoint=a.WorkPoint
|
|
INNER JOIN ICSSSD b ON b.SSDCode=a.TransCode AND b.WorkPoint=a.WorkPoint
|
|
LEFT JOIN ICSSDN sdn ON sdn.SDNCode=b.SDNCode AND sdn.WorkPoint=b.WorkPoint
|
|
ORDER BY Costre2,a.LotNo,lot.ExpirationDate
|
|
|
|
DROP TABLE #NewTempERP";
|
|
sql = string.Format(sql, Identification);
|
|
//DataTable dt = DBHelper.SQlReturnData(sql, cmd);
|
|
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
|
|
|
|
//string Inputstr = JsonConvert.SerializeObject(dt);
|
|
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
|
|
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesDeliveryNoticeOutURL, Inputstr);
|
|
Result result = new Result();
|
|
result = JsonConvert.DeserializeObject<Result>(resultStr);
|
|
if (result.Success)
|
|
{
|
|
try
|
|
{
|
|
foreach (DataRow dr in ds.Tables[0].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
|
|
{
|
|
//判断数量 数量满足再调用erp接口,不满足数量只走wms逻辑
|
|
string checksql = @"select SUM(Quantity) AS SUMQty,SUM(SSDQuantity) AS ISSQty,SSDCode AS transCode from ICSSSD
|
|
where SSDCode in (select top 1 TransCode from ICSWareHouseLotInfoLog where Identification='{0}' AND BusinessCode='55')
|
|
GROUP BY SSDCode";
|
|
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)
|
|
{
|
|
sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode,transid
|
|
INTO #NewTempERP
|
|
from ICSWareHouseLotInfoLog
|
|
WHERE TransCode='{0}' AND ERPUpload='0' AND BusinessCode = '55'
|
|
|
|
SELECT DISTINCT a.TransCode AS Costre,b.SSDID AS ID,'{1}' AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint,b.CusCode
|
|
FROM #NewTempERP a
|
|
INNER JOIN ICSSSD b ON a.TransCode=b.SSDCode AND a.TransSequence=b.Sequence and a.transid=b.id AND a.WorkPoint=b.WorkPoint and b.type='1'
|
|
INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
|
|
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
|
|
GROUP BY b.SSDID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint,a.TransCode,b.CusCode
|
|
|
|
SELECT DISTINCT a.TransCode AS Costre,a.TransCode+a.TransSequence+a.InvCode AS Costre2,a.InvCode FROM #NewTempERP a
|
|
|
|
SELECT DISTINCT a.TransCode+a.TransSequence+a.InvCode AS Costre2,a.LotNo,lot.ExpirationDate,'' AS TrackingNO
|
|
FROM #NewTempERP a
|
|
INNER JOIN ICSInventoryLot lot ON lot.LotNo=a.lotNo AND lot.WorkPoint=a.WorkPoint
|
|
INNER JOIN ICSSSD b ON b.SSDCode=a.TransCode AND b.WorkPoint=a.WorkPoint
|
|
LEFT JOIN ICSSDN sdn ON sdn.SDNCode=b.SDNCode AND sdn.WorkPoint=b.WorkPoint
|
|
ORDER BY Costre2,a.LotNo,lot.ExpirationDate
|
|
|
|
DROP TABLE #NewTempERP";
|
|
sql = string.Format(sql, trancode, UserCode);
|
|
//DataTable dt = DBHelper.SQlReturnData(sql, cmd);
|
|
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
|
|
|
|
//string Inputstr = JsonConvert.SerializeObject(dt);
|
|
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
|
|
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesDeliveryNoticeOutURL, Inputstr);
|
|
Result result = new Result();
|
|
result = JsonConvert.DeserializeObject<Result>(resultStr);
|
|
if (result.Success)
|
|
{
|
|
try
|
|
{
|
|
foreach (DataRow dr in ds.Tables[0].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 SalesShipmentOutRedDocNegative(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 ICSSSD c ON b.TransCode=c.SSDCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'
|
|
|
|
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 SSDQuantity=ISNULL(SSDQuantity,0)+'{2}'
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSSSD c ON b.TransCode=c.SSDCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'";
|
|
sql = string.Format(sql, LotNo, WorkPoint, Quantity);
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception("销售出库单更新失败!");
|
|
}
|
|
}
|
|
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 SalesShipmentOutRedYuanDocIn(string TransCode, string TransSequence, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
|
|
{
|
|
try
|
|
{
|
|
string sql = @"DECLARE @Status VARCHAR(10)
|
|
SELECT @Status=sdn.Status FROM ICSSSD sdn
|
|
INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
|
|
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SSDCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2'
|
|
|
|
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 sdn SET SSDQuantity=ISNULL(SSDQuantity,0)+'{4}'
|
|
FROM ICSSSD sdn
|
|
INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
|
|
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SSDCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2'
|
|
IF EXISTS(SELECT a.LotNo FROM ICSSSD sdn
|
|
INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
|
|
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SSDCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2' AND sdn.Quantity<sdn.SSDQuantity)
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
|
|
END";
|
|
sql = string.Format(sql, LotNo, WorkPoint, TransCode, TransSequence, Quantity);
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 销售出库-红字出库单接口
|
|
/// </summary>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void SalesShipmentDocOutRedERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
|
|
{
|
|
try
|
|
{
|
|
string sql = string.Empty;
|
|
if (DBHelper.IsPNU9())
|
|
{
|
|
sql = @"SELECT b.CusCode+a.ToWarehouseCode+b.SSDCode+a.MUSER AS Costre
|
|
,a.TransCode+a.TransSequence+b.CusCode+a.ToWarehouseCode+b.SSDCode+a.MUSER AS Costre2
|
|
,b.CusCode,a.ToWarehouseCode AS WarehouseCode,b.SSDCode,b.Sequence,a.MUSER,
|
|
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.SSDDetailID,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
|
|
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 ICSSSD b ON a.TransCode=b.SSDCode 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='UpdateStock005' 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 BusinessCode='56' AND b.Type='2'
|
|
GROUP BY a.TransCode,a.TransSequence,conWhCode.Enable,inv.AmountEnable,b.CusCode,a.ToWarehouseCode,b.SSDCode,b.Sequence,a.MUSER,a.InvCode,b.SSDDetailID,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,SSDCode AS DocNo,0 AS ID FROM #TempERP
|
|
SELECT Costre,Costre2,Sequence,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,InvCode,Quantity,Quantity AS RcvQuantity,Amount,SSDDetailID 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.DataSetToJson2(ds, "details", "Costre");
|
|
string checksql = @"select SUM(b.Quantity) AS SUMQty,SUM(b.SSDQuantity) AS ISSQty,a.transCode from ICSSSD b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.SSDCode 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 b.CusCode+a.ToWarehouseCode+b.SSDCode+a.MUSER AS Costre
|
|
,a.TransCode+a.TransSequence+b.CusCode+a.ToWarehouseCode+b.SSDCode+a.MUSER AS Costre2
|
|
,b.CusCode,a.ToWarehouseCode AS WarehouseCode,b.SSDCode,b.Sequence,a.MUSER,
|
|
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.SSDDetailID,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
|
|
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 ICSSSD b ON a.TransCode=b.SSDCode 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='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
|
|
INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
|
|
WHERE a.TransCode='{0}' AND ERPUpload='0' and BusinessCode='56' AND b.Type='2' and a.EATTRIBUTE1<>'1'
|
|
GROUP BY a.TransCode,a.TransSequence,conWhCode.Enable,inv.AmountEnable,b.CusCode,a.ToWarehouseCode,b.SSDCode,b.Sequence,a.MUSER,a.InvCode,b.SSDDetailID,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,SSDCode AS DocNo,0 AS ID FROM #TempERP
|
|
SELECT Costre,Costre2,Sequence,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,InvCode,Quantity,Quantity AS RcvQuantity,Amount,SSDDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
|
|
|
|
DROP TABLE #TempERP
|
|
|
|
";
|
|
pnsql = string.Format(pnsql, trancode);
|
|
DataSet ds = DBHelper.SQlReturnDataSet(pnsql, cmd);
|
|
|
|
string Inputstr = DataToJsonHelper.DataSetToJson2(ds, "details", "Costre");
|
|
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.RMAToRCVURL, Inputstr);
|
|
Result result = new Result();
|
|
|
|
//sql = string.Format(sql, Identification);
|
|
////DataTable dt = DBHelper.SQlReturnData(sql, cmd);
|
|
//DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
|
|
|
|
////string Inputstr = JsonConvert.SerializeObject(dt);
|
|
//string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
|
|
//string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PNSalesDeliveryNoticeOutURL, 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 a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1',Quantity='{6}'
|
|
// FROM ICSWareHouseLotInfoLog a
|
|
// INNER JOIN ICSSSD c ON a.TransCode=c.SSDCOde AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
//INNER JOIN ICSInventoryLot lot on a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
|
|
//INNER JOIN ICSExtension d ON lot.ExtensionID=d.id and lot.WorkPoint=d.WorkPoint
|
|
// WHERE c.SSDCode='{0}' AND a.BusinessCode ='{7}' AND d.BatchCode='{8}' AND lot.InvCode='{1}'";
|
|
// ERPupdate = string.Format(ERPupdate);
|
|
// if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
|
|
// {
|
|
// throw new Exception(TransType + language.GetNameByCode("WMSAPIInfo175"));//"回写日志失败!");
|
|
// }
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Debug(ex.ToString());
|
|
log.Debug(resultStr);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
#region ERP开立状态单据审核
|
|
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}'
|
|
|
|
IF EXISTS(SELECT b.ID FROM ICSSSD b
|
|
WHERE b.SSDCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
|
|
AND b.Quantity!=b.SSDQuantity and b.type='2')
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo529") + @"',16,1);
|
|
RETURN
|
|
END
|
|
|
|
SELECT b.SSDCode AS SDNRTCode, b.SSDID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
|
|
FROM #NewTempERP a
|
|
INNER JOIN ICSSSD b ON a.TransCode=b.SSDCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint and b.type='2'
|
|
INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
|
|
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
|
|
GROUP BY b.SSDCode,b.SSDID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
|
|
|
|
DROP TABLE #NewTempERP";
|
|
sql = string.Format(sql, Identification, BusinessCode);
|
|
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
|
|
|
|
string Inputstr = JsonConvert.SerializeObject(dt);
|
|
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesDeliveryNoticeOutRedURL, 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 SalesShipmentDocNegative(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 ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'
|
|
|
|
IF (@Status IS NULL)
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
|
|
RETURN
|
|
END
|
|
ELSE IF (@Status!='2')
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
|
|
RETURN
|
|
END
|
|
UPDATE c SET SDNQuantity=ISNULL(SDNQuantity,0)+'{2}'
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'
|
|
|
|
--东辉退货 销售订单已发数量减少
|
|
UPDATE d SET SoQuantity=ISNULL(SoQuantity,0)-'{2}'
|
|
FROM ICSInventoryLot a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
inner join ICSSO d on c.socode=d.socode and c.SoSequence=d.Sequence
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'
|
|
|
|
IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSSDN c ON b.TransCode=c.SDNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Type='2'
|
|
AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn020', c.Quantity,1,3,'')<c.SDNQuantity)
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
|
|
END";
|
|
sql = string.Format(sql, LotNo, WorkPoint, Quantity);
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception("销售退货单更新失败!");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 销售退货接口
|
|
/// </summary>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void SalesShipmentDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
|
|
{
|
|
try
|
|
{
|
|
string sql = "";
|
|
DataTable flag = null;
|
|
string enablesql = @"select * from ICSConfiguration where code = 'RTDisReturn' and enable = '1'";
|
|
flag = DBHelper.SQlReturnData(enablesql, cmd);
|
|
#region ERP
|
|
if (flag != null && flag.Rows.Count > 0)
|
|
{
|
|
sql = @"
|
|
IF EXISTS(SELECT b.ID FROM ICSSDN b
|
|
WHERE b.SDNCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
|
|
AND b.Quantity!=b.SDNQuantity AND b.Type='2')
|
|
BEGIN
|
|
RAISERROR('销售退货单下的条码必须一次性扫描完成!',16,1);
|
|
RETURN
|
|
END
|
|
SELECT c.CusCode+a.ToWarehouseCode+c.SDNCode+a.MUSER AS Costre,c.CusCode,a.ToWarehouseCode AS WarehouseCode,c.SDNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.CusCode,a.ToWarehouseCode,c.SDNCode,c.SDNDetailID,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.SDNDetailID,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
|
|
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 ICSSDN c ON b.TransCode=c.SDNCode 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 conStock ON conStock.Code='UpdateStock005' 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 c.Type='2' AND BusinessCode='{1}'
|
|
GROUP BY conWhCode.Enable,inv.AmountEnable,c.CusCode,a.ToWarehouseCode,c.SDNCode,a.MUSER,a.InvCode,c.SDNDetailID,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,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
|
|
SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,SDNDetailID AS SDNRTDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
|
|
|
|
DROP TABLE #TempERP";
|
|
}
|
|
else
|
|
{
|
|
sql = @"SELECT c.CusCode+a.ToWarehouseCode+c.SDNCode+a.MUSER AS Costre,c.CusCode,a.ToWarehouseCode AS WarehouseCode,c.SDNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.CusCode,a.ToWarehouseCode,c.SDNCode,c.SDNDetailID,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.SDNDetailID,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
|
|
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 ICSSDN c ON b.TransCode=c.SDNCode 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 conStock ON conStock.Code='UpdateStock005' 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 c.Type='2' AND BusinessCode='{1}'
|
|
GROUP BY inv.AmountEnable,conWhCode.Enable,c.CusCode,a.ToWarehouseCode,c.SDNCode,a.MUSER,a.InvCode,c.SDNDetailID,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,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
|
|
SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,SDNDetailID AS SDNRTDetailID,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);
|
|
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
|
|
|
|
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
|
|
|
|
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesReturnBackURL, 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["SDNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
|
|
det["DetailID"].ToString(), jo["SDNNEGCode"].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;
|
|
}
|
|
}
|
|
|
|
public static void U9SalesShipmentDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
|
|
{
|
|
try
|
|
{
|
|
#region ERP
|
|
string sql = @"IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSSDN b ON a.TransCode=b.SDNCode AND a.WorkPoint=b.WorkPoint
|
|
WHERE a.Identification='{0}' AND b.Quantity!=b.SDNQuantity)
|
|
BEGIN
|
|
RAISERROR('销售退货单相关条码需要一次性扫描入库',16,1);
|
|
RETURN
|
|
END
|
|
|
|
SELECT c.CusCode+a.ToWarehouseCode+c.SDNCode+a.MUSER AS Costre,c.CusCode,a.ToWarehouseCode AS WarehouseCode,c.SDNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.CusCode,a.ToWarehouseCode,c.SDNCode,c.SDNDetailID,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.SDNDetailID,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 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 ICSSDN c ON b.TransCode=c.SDNCode 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 conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
|
|
WHERE a.Identification='{0}' AND ERPUpload='0' AND c.Type='2' AND BusinessCode='{1}'
|
|
GROUP BY inv.AmountEnable,c.CusCode,a.ToWarehouseCode,c.SDNCode,a.MUSER,a.InvCode,c.SDNDetailID,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 WorkPoint,CusCode,SDNCode AS SDNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP -- Costre,WarehouseCode AS WHCode,
|
|
--SELECT Costre,Sequence,InvCode,Quantity,Amount,SDNDetailID AS SDNRTDetailID,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);
|
|
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
|
|
|
|
//string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
|
|
|
|
string Inputstr = JsonConvert.SerializeObject(ds.Tables[0]);
|
|
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesReturnBackURL, 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["SDNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
|
|
det["DetailID"].ToString(), jo["SDNNEGCode"].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 SalesReturnBackIn(string TransCode, string TransSequence, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
|
|
{
|
|
try
|
|
{
|
|
string sql = @"DECLARE @Status VARCHAR(10)
|
|
SELECT @Status=sdn.Status FROM ICSSDN sdn
|
|
INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
|
|
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SDNCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2'
|
|
|
|
IF (@Status IS NULL)
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
|
|
RETURN
|
|
END
|
|
ELSE IF (@Status!='2')
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
|
|
RETURN
|
|
END
|
|
UPDATE sdn SET SDNQuantity=ISNULL(SDNQuantity,0)+'{4}'
|
|
FROM ICSSDN sdn
|
|
INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
|
|
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SDNCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2'
|
|
IF EXISTS(SELECT a.LotNo FROM ICSSDN sdn
|
|
INNER JOIN ICSWareHouseLotInfoLog log ON sdn.WorkPoint=log.WorkPoint
|
|
INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND sdn.SDNCode='{2}' AND sdn.Sequence='{3}' AND sdn.Type='2' AND sdn.Quantity<sdn.SDNQuantity)
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
|
|
END";
|
|
sql = string.Format(sql, LotNo, WorkPoint, TransCode, TransSequence, Quantity);
|
|
if (!DBHelper.ExecuteNonQuery(sql, cmd))
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 销售退货-原条码接口
|
|
/// </summary>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void SalesReturnBackInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
|
|
{
|
|
try
|
|
{
|
|
#region ERP
|
|
string sql = @"SELECT c.CusCode+a.FromWarehouseCode+c.SDNCode+a.MUSER AS Costre,c.CusCode,a.FromWarehouseCode AS WarehouseCode,c.SDNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.CusCode,a.FromWarehouseCode,c.SDNCode,c.SDNDetailID,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.SDNDetailID,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
|
|
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 ICSSDN c ON a.TransCode=c.SDNCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
|
|
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
|
|
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' 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 c.Type='2' AND BusinessCode='{1}'
|
|
GROUP BY conWhCode.Enable,inv.AmountEnable,c.CusCode,a.FromWarehouseCode,c.SDNCode,a.MUSER,a.InvCode,c.SDNDetailID,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,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock,ErpWhCode FROM #TempERP
|
|
SELECT Costre,Sequence,InvCode,Quantity,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,Amount,SDNDetailID AS SDNRTDetailID,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);
|
|
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
|
|
|
|
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
|
|
|
|
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.SalesReturnBackURL, 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["SDNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
|
|
det["DetailID"].ToString(), jo["SDNNEGCode"].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
|
|
|
|
}
|
|
}
|