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.
1185 lines
78 KiB
1185 lines
78 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 ICSPurchaseService
|
|
{
|
|
private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
#region 采购到货
|
|
/// <summary>
|
|
/// 采购到货接口
|
|
/// </summary>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void DeliveryNoticeERP(string DNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
|
|
{
|
|
try
|
|
{
|
|
#region ERP
|
|
string sql = @"SELECT a.VenCode+a.DepCode+y.POCode+a.MUSER AS Costre,a.VenCode,a.DepCode,y.POCode,a.MUSER,a.MTIME,
|
|
a.Sequence,a.InvCode,a.Quantity,CASE invBat.AmountEnable WHEN '1' THEN a.Amount ELSE '0' END AS Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,a.PODetailID
|
|
,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 ICSDeliveryNotice 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 ICSPurchaseOrder y ON a.PODetailID=y.PODetailID AND a.WorkPoint=y.WorkPoint
|
|
WHERE a.DNCode='{0}' AND a.WorkPoint='{1}'
|
|
|
|
SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,POCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
|
|
SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,PODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
|
|
FROM #TempERP
|
|
|
|
DROP TABLE #TempERP";
|
|
sql = string.Format(sql, DNCode, WorkPoint);
|
|
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
|
|
|
|
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
|
|
string resultStr = HTTPHelper.HttpPost("采购到货", ERPUrl.CreatePOArrivURL, 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 ICSDeliveryNotice set DNCode='{0}',Sequence='{1}',DNID='{2}',DNDetailID='{3}'
|
|
where PODetailID='{4}' AND DNType='1' AND DNCode='{5}' and Sequence='{1}'";
|
|
ERPupdate = string.Format(ERPupdate, jo["DNCode"], det["Sequence"], jo["ID"], det["DetailID"], det["PODetailID"],DNCode);
|
|
|
|
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 PurchaseReceiveDoc(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 ICSPurchaseOrder c ON b.TransCode=c.POCode 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 ICSPurchaseOrder c ON b.TransCode=c.POCode 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 ICSPurchaseOrder c ON b.TransCode=c.POCode 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("WMSAPIInfo104"));//"采购入库单更新失败!");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 采购入库接口
|
|
/// </summary>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void PurchaseReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
|
|
{
|
|
try
|
|
{
|
|
#region ERP
|
|
string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence
|
|
INTO #NewTempERP
|
|
from ICSWareHouseLotInfoLog
|
|
WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
|
|
|
|
SELECT c.VenCode+a.ToWarehouseCode+c.POCode+a.MUSER+CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END AS Costre,a.lotno AS Costre2,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.POCode,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END AS DNCode,CASE WHEN(LEN(f.DNID)>=20) THEN '1' ELSE '0' END AS HasDN,a.MUSER,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.Sequence END AS DNSequence,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.POCode,c.PODetailID,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,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.PODetailID,con.Enable AS UpdateTodoQuantity,conn.Enable,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose
|
|
,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
|
|
ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
|
|
INTO #TempERP
|
|
FROM #NewTempERP a
|
|
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
|
|
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
|
|
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
|
|
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
|
|
INNER JOIN ICSDeliveryNotice f ON g.ASNCode=f.ASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
|
|
INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint
|
|
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
|
|
INNER JOIN ICSConfiguration conn ON a.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
|
|
INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='UpdateStock001'
|
|
INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose003'
|
|
GROUP BY a.LotNo,a.TransSequence,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.POCode,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END,f.DNID,a.MUSER,a.InvCode,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.Sequence END,c.PODetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conn.Enable,conStock.Enable,conStocknew.Enable
|
|
,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
|
|
ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, '')
|
|
|
|
SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,POCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity,UpdateStock,IsFillClose FROM #TempERP
|
|
SELECT Costre,Costre2,Sequence,DNSequence,InvCode,Quantity,Amount,PODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
|
|
FROM #TempERP
|
|
SELECT a.LotNo,SUM(a.Quantity) AS Quantity,a.LotNo AS Costre2
|
|
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 ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
|
|
INNER JOIN ICSDeliveryNotice f ON g.ASNCode=f.ASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
|
|
INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint
|
|
INNER JOIN #TempERP te ON te.Sequence=a.TransSequence
|
|
WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
|
|
GROUP BY a.LotNo
|
|
|
|
SELECT DISTINCT HasDN FROM #TempERP
|
|
|
|
|
|
|
|
|
|
DROP TABLE #TempERP
|
|
DROP TABLE #NewTempERP";
|
|
sql = string.Format(sql, Identification, BusinessCode);
|
|
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
|
|
|
|
|
|
//string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
|
|
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
|
|
|
|
var IsDNCode = ds.Tables[3];
|
|
if (IsDNCode == null || IsDNCode.Rows.Count != 1)
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo463"));//ERP到货单只能选择启用或不启用中的一种!
|
|
}
|
|
string dncode = Convert.ToString(IsDNCode.Rows[0]["HasDN"]);
|
|
if (dncode.Equals(""))
|
|
{
|
|
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DeliveryNoticeURL, 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["DNDetailID"].ToString(), Identification, jo["ID"].ToString(),
|
|
det["DetailID"].ToString(), jo["RCVTCode"].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);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseOrderURL, 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["PODetailID"].ToString(), Identification, jo["ID"].ToString(),
|
|
det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Debug(ex.ToString());
|
|
log.Debug(resultStr);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建标准收货单U9(采购)
|
|
/// </summary>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void CreatePOArriveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode,string doctype)
|
|
{
|
|
try
|
|
{
|
|
#region ERP
|
|
string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence
|
|
INTO #NewTempERP
|
|
from ICSWareHouseLotInfoLog
|
|
WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
|
|
|
|
SELECT c.VenCode+a.ToWarehouseCode+c.POCode+a.MUSER+CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.POCode,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END AS DNCode,CASE WHEN(LEN(f.DNID)>=20) THEN '1' ELSE '0' END AS HasDN,a.MUSER,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.Sequence END AS DNSequence,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.POCode,c.PODetailID,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,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.PODetailID,con.Enable AS UpdateTodoQuantity,conn.Enable,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose
|
|
--,a.lotno AS Costre2
|
|
,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 ,'{2}' as DocTyppe,getdate() as DocDate,c.Sequence as srcDocPOLineNo
|
|
INTO #TempERP
|
|
FROM #NewTempERP a
|
|
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
|
|
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
|
|
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
|
|
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
|
|
INNER JOIN ICSDeliveryNotice f ON g.ASNCode=f.ASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
|
|
INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint
|
|
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
|
|
INNER JOIN ICSConfiguration conn ON a.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
|
|
INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='UpdateStock001'
|
|
INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose003'
|
|
GROUP BY-- a.LotNo,
|
|
a.TransSequence,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.POCode,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END,f.DNID,a.MUSER,a.InvCode,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.Sequence END,c.PODetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conn.Enable,conStock.Enable,conStocknew.Enable
|
|
,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
|
|
ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, ''),c.Sequence
|
|
|
|
SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WhCode,POCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity,UpdateStock,IsFillClose,DocTyppe, DocDate, DocDate as ArrDate FROM #TempERP
|
|
SELECT Costre,
|
|
--Costre2,
|
|
Sequence,DNSequence,InvCode,Quantity,Amount,PODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WarehouseCode AS WhCode,srcDocPOLineNo
|
|
FROM #TempERP
|
|
SELECT SUM(a.Quantity) AS Quantity--,a.LotNo AS Costre2,a.LotNo,
|
|
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 ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
|
|
INNER JOIN ICSDeliveryNotice f ON g.ASNCode=f.ASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
|
|
INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint
|
|
INNER JOIN #TempERP te ON te.Sequence=a.TransSequence
|
|
WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
|
|
--GROUP BY a.LotNo
|
|
|
|
SELECT DISTINCT HasDN FROM #TempERP
|
|
|
|
|
|
|
|
|
|
DROP TABLE #TempERP
|
|
DROP TABLE #NewTempERP";
|
|
sql = string.Format(sql, Identification, BusinessCode,doctype);
|
|
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
|
|
|
|
|
|
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
|
|
//string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
|
|
|
|
var IsDNCode = ds.Tables[3];
|
|
if (IsDNCode == null || IsDNCode.Rows.Count != 1)
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo463"));//ERP到货单只能选择启用或不启用中的一种!
|
|
}
|
|
|
|
|
|
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9CreatePOArrivURL, 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["cWhCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
|
|
// + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
|
|
// ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["PODetailID"].ToString(), Identification, jo["ID"].ToString(),
|
|
// det["DetailID"].ToString(), jo["RCVTCode"].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 DeliveryNoticeIn(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 ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='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 ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='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 ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='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("WMSAPIInfo079"));//"到货单更新失败!");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 审核的到货单接口
|
|
/// </summary>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="cmd"></param>
|
|
public static DataTable DeliveryNoticeInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
|
|
{
|
|
try
|
|
{
|
|
|
|
DataTable dtablee = new DataTable();
|
|
string checklotno = "";
|
|
|
|
string checksql = @"SELECT c.dncode,a.lotno FROM ICSInventoryLot a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN (select dncode,Sequence,WorkPoint FROM ICSDeliveryNotice) c ON b.TransCode=c.dncode
|
|
AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
WHERE c.dncode in (select TransCode from ICSWareHouseLotInfoLog
|
|
where Identification='{0}' )
|
|
and a.lotno NOT IN (select LotNo from ICSWareHouseLotInfo)";
|
|
checksql = string.Format(checksql, Identification);
|
|
DataTable dtt = DBHelper.SQlReturnData(checksql, cmd);
|
|
if (dtt.Rows.Count > 1)
|
|
{
|
|
// 如果dtt的行数大于1,将lotno以逗号隔开的形式加入checklotno中
|
|
foreach (DataRow row in dtt.Rows)
|
|
{
|
|
checklotno += row["lotno"].ToString() + ",";
|
|
}
|
|
checklotno = checklotno.TrimEnd(','); // 去除最后一个逗号
|
|
}
|
|
else if (dtt.Rows.Count == 1)
|
|
{
|
|
// 如果dtt的行数等于1,直接将lotno赋值给checklotno
|
|
checklotno = dtt.Rows[0]["lotno"].ToString();
|
|
}
|
|
|
|
string checkrcvcode = "";
|
|
string checknewsql = @"SELECT distinct c.DNCode FROM ICSInventoryLot a
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN (select DNCode,Sequence,WorkPoint FROM ICSDeliveryNotice) c ON b.TransCode=c.DNCode
|
|
AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
WHERE c.DNCode in (select TransCode from ICSWareHouseLotInfoLog
|
|
where Identification='{0}' )
|
|
and a.lotno NOT IN (select LotNo from ICSWareHouseLotInfo)";
|
|
checknewsql = string.Format(checknewsql, Identification);
|
|
DataTable dttnew = DBHelper.SQlReturnData(checknewsql, cmd);
|
|
if (dttnew.Rows.Count > 1)
|
|
{
|
|
// 如果dtt的行数大于1,将lotno以逗号隔开的形式加入checklotno中
|
|
foreach (DataRow row in dttnew.Rows)
|
|
{
|
|
checkrcvcode += row["DNCode"].ToString() + ",";
|
|
}
|
|
checkrcvcode = checkrcvcode.TrimEnd(','); // 去除最后一个逗号
|
|
}
|
|
else if (dttnew.Rows.Count == 1)
|
|
{
|
|
// 如果dtt的行数等于1,直接将lotno赋值给checklotno
|
|
checkrcvcode = dttnew.Rows[0]["DNCode"].ToString();
|
|
}
|
|
|
|
|
|
|
|
#region ERP
|
|
log.Debug("11111111");
|
|
string sql = @"
|
|
|
|
select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
|
|
INTO #NewTempERP
|
|
from ICSWareHouseLotInfoLog
|
|
WHERE Identification='{0}' AND ERPUpload='0'
|
|
|
|
SELECT c.VenCode+a.ToWarehouseCode+c.DNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.DNCode ,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.DNDetailID,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,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.DNDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
|
|
,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
|
|
ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
|
|
INTO #TempERP
|
|
FROM #NewTempERP a
|
|
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
|
|
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
|
|
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
|
|
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
|
|
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
|
|
INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode 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='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
|
|
GROUP BY inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.DNCode,c.DNID,a.MUSER,a.InvCode,c.DNDetailID,isnull((c.UnitPrice),0),c.Currency,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,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
|
|
SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
|
|
FROM #TempERP
|
|
|
|
DROP TABLE #TempERP
|
|
DROP TABLE #NewTempERP";
|
|
sql = string.Format(sql, Identification,checklotno, checkrcvcode);
|
|
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
|
|
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
|
|
|
|
|
|
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DeliveryNoticeURL, 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)
|
|
{
|
|
log.Debug("2222222");
|
|
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["DNDetailID"].ToString(), Identification, jo["ID"].ToString(),
|
|
det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
|
|
log.Debug("33333333");
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Debug(ex.ToString());
|
|
log.Debug(resultStr);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
|
|
}
|
|
|
|
//sql= @" SELECT {1},{2} FROM ICSDeliveryNotice b
|
|
// WHERE b.DNCode + b.WorkPoint IN(SELECT a.TransCode + a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification = '{0}'
|
|
// and SUM(Quantity)<>SUM(RCVQuantity))";
|
|
//sql = string.Format(sql, Identification, checklotno, checkrcvcode);
|
|
log.Debug("4444444");
|
|
DataTable chekdt = new DataTable();
|
|
chekdt.Columns.Add("checkrcvcode", typeof(string));
|
|
chekdt.Columns.Add("checklotno", typeof(string));
|
|
DataRow newrow = chekdt.NewRow();
|
|
newrow["checkrcvcode"] = checkrcvcode;
|
|
newrow["checklotno"] = checklotno;
|
|
chekdt.Rows.Add(newrow);
|
|
string aaaa = JsonConvert.SerializeObject(chekdt);
|
|
return chekdt;
|
|
|
|
|
|
|
|
#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 PurchaseRejectDocIn(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 ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='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 ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='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 ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='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("WMSAPIInfo084"));//"拒收单更新失败!");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 采购拒收接口
|
|
/// </summary>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void PurchaseRejectDocInNewERP(string DNCode, string JDNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
|
|
{
|
|
//try
|
|
//{
|
|
// #region ERP
|
|
// string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.DNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,d.DNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.DNCode,c.DNDetailID,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,d.DNDetailID,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 VerificationEnable
|
|
// 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 ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
// INNER JOIN ICSDeliveryNotice d ON c.PODetailID=d.DNDetailID AND d.WorkPoint=c.WorkPoint
|
|
// INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
|
|
// INNER JOIN ICSConfiguration conv ON con.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
|
|
// WHERE a.Identification='{0}' AND ERPUpload='0'
|
|
// GROUP BY c.VenCode,a.ToWarehouseCode,c.DNCode,d.DNCode,a.MUSER,lot.Amount,lot.Quantity,a.InvCode,d.DNDetailID,c.DNDetailID,isnull((c.UnitPrice),0),c.Currency,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,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,VerificationEnable,WorkPoint FROM #TempERP
|
|
// SELECT Costre,Sequence,InvCode,Quantity,Amount,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.CreatePuArrivalVouchURL, 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["RCVTCode"].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;
|
|
//}
|
|
try
|
|
{
|
|
#region ERP
|
|
string sql = @"SELECT ISNULL(a.VenCode,'')+ISNULL(a.DepCode,'')+ISNULL(x.DNCode,'')+ISNULL(a.MUSER,'') AS Costre,a.VenCode,ISNULL(a.DepCode,'') AS DepCode,x.DNCode,a.MUSER,a.MTIME,
|
|
a.Sequence,a.InvCode,Sum(a.Quantity) AS Quantity,CASE invBat.AmountEnable WHEN '1' THEN a.Amount ELSE '0' END AS Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,x.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 ICSDeliveryNotice a
|
|
INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
|
|
INNER JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
|
|
INNER JOIN ICSDeliveryNotice x ON x.DNDetailID=a.PODetailID AND a.WorkPoint=x.WorkPoint
|
|
WHERE a.DNCode='{0}' AND a.WorkPoint='{1}'
|
|
GROUP BY a.VenCode,a.DepCode,x.DNCode,a.MUSER,a.MTIME,a.Sequence,invBat.AmountEnable,a.InvCode,a.Amount,a.Quantity,a.UnitPrice,a.Currency,x.DNDetailID,
|
|
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, JDNCode, WorkPoint);
|
|
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
|
|
|
|
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
|
|
string resultStr = HTTPHelper.HttpPost("采购拒收", ERPUrl.CreatePuArrivalVouchURL, 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 ICSDeliveryNotice set DNCode='{0}',Sequence='{1}',DNID='{2}',DNDetailID='{3}'
|
|
where PODetailID='{4}' AND DNType='3' AND DNCode='{5}' ";
|
|
ERPupdate = string.Format(ERPupdate, jo["RJTCode"], det["Sequence"], jo["ID"], det["DetailID"], det["DNDetailID"], JDNCode);
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 采购拒收接口
|
|
/// </summary>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void PurchaseRejectDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
|
|
{
|
|
//try
|
|
//{
|
|
// #region ERP
|
|
// string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.DNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,d.DNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.DNCode,c.DNDetailID,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,d.DNDetailID,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 VerificationEnable
|
|
// 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 ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
|
|
// INNER JOIN ICSDeliveryNotice d ON c.PODetailID=d.DNDetailID AND d.WorkPoint=c.WorkPoint
|
|
// INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
|
|
// INNER JOIN ICSConfiguration conv ON con.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
|
|
// WHERE a.Identification='{0}' AND ERPUpload='0'
|
|
// GROUP BY c.VenCode,a.ToWarehouseCode,c.DNCode,d.DNCode,a.MUSER,a.InvCode,d.DNDetailID,c.DNDetailID,isnull((c.UnitPrice),0),c.Currency,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,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,VerificationEnable,WorkPoint FROM #TempERP
|
|
// SELECT Costre,Sequence,InvCode,Quantity,Amount,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.CreatePuArrivalVouchURL, 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["RCVTCode"].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 PurchaseReceiveDoctNegative(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 ICSDeliveryNotice WHERE DNCode='{0}' AND DNType='2' AND WorkPoint='{1}'
|
|
|
|
IF (@Status IS NULL)
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo085") + @"',16,1);
|
|
RETURN
|
|
END
|
|
ELSE IF (@Status!='2')
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo086") + @"',16,1);
|
|
RETURN
|
|
END
|
|
|
|
UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
|
|
FROM ICSDeliveryNotice a
|
|
WHERE a.DNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND DNType='2'
|
|
|
|
IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a
|
|
WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.RCVQuantity AND DNType='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("WMSAPIInfo088"));//"采购退货单更新失败!");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 采购退货接口
|
|
/// </summary>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void PurchaseReceiveDoctNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
|
|
{
|
|
try
|
|
{
|
|
#region ERP
|
|
string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
|
|
INTO #NewTempERP
|
|
from ICSWareHouseLotInfoLog
|
|
WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '3'
|
|
|
|
SELECT y.VenCode+a.FromWarehouseCode+y.DNCode+a.MUSER AS Costre,y.VenCode,a.FromWarehouseCode AS WarehouseCode,y.DNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.VenCode,a.FromWarehouseCode,y.DNCode,y.DNDetailID,a.InvCode) AS Sequence,
|
|
a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(y.Amount/y.Quantity)) ELSE '0' END AS Amount,y.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
|
|
,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
|
|
ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
|
|
INTO #TempERP
|
|
FROM #NewTempERP a
|
|
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
|
|
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
|
|
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
|
|
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
|
|
INNER JOIN ICSDeliveryNotice y ON a.TransCode=y.DNCode 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 conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
|
|
GROUP BY inv.AmountEnable,y.VenCode,a.FromWarehouseCode,y.DNCode,a.MUSER,a.InvCode,y.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),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,VenCode,WarehouseCode AS WHCode,DNCode AS DNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
|
|
SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID AS DNRTDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
|
|
FROM #TempERP
|
|
|
|
DROP TABLE #TempERP
|
|
DROP TABLE #NewTempERP";
|
|
sql = string.Format(sql, Identification);
|
|
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
|
|
|
|
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
|
|
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReturnBackURL, 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["DNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
|
|
det["DetailID"].ToString(), jo["RCVNEGCode"].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 PurchaseReceive(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 ICSPurchaseReceive 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("WMSAPIInfo089") + @"',16,1);
|
|
RETURN
|
|
END
|
|
ELSE IF (@Status!='1')
|
|
BEGIN
|
|
RAISERROR('" + language.GetNameByCode("WMSAPIInfo090") + @"',16,1);
|
|
RETURN
|
|
END
|
|
UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
|
|
FROM ICSPurchaseReceive a
|
|
WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
|
|
|
|
IF EXISTS(SELECT a.ID FROM ICSPurchaseReceive 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("WMSAPIInfo092"));//"红字入库单更新失败!");
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开立红字入库接口
|
|
/// </summary>
|
|
/// <param name="TransType"></param>
|
|
/// <param name="Identification"></param>
|
|
/// <param name="cmd"></param>
|
|
public static void PurchaseReceiveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
|
|
{
|
|
try
|
|
{
|
|
#region ERP开立状态单据审核
|
|
string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
|
|
INTO #NewTempERP
|
|
from ICSWareHouseLotInfoLog
|
|
WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '4'
|
|
|
|
IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
|
|
INNER JOIN ICSPurchaseReceive 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("WMSAPIInfo093") + @"',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 #NewTempERP a
|
|
INNER JOIN ICSPurchaseReceive 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
|
|
GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
|
|
|
|
DROP TABLE #NewTempERP";
|
|
sql = string.Format(sql, Identification);
|
|
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
|
|
|
|
string Inputstr = JsonConvert.SerializeObject(dt);
|
|
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReceiveDoctNegativeURL, 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
|
|
|
|
}
|
|
}
|