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.
383 lines
19 KiB
383 lines
19 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 SalesShipmentDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd)
|
|
{
|
|
try
|
|
{
|
|
string sql = @"DECLARE @Status VARCHAR(10)
|
|
SELECT @Status=a.Status FROM ICSSDN a
|
|
WHERE a.SDNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='1'
|
|
|
|
IF (@Status IS NULL)
|
|
BEGIN
|
|
RAISERROR('销售发货单:{0} 不存在!',16,1);
|
|
RETURN
|
|
END
|
|
ELSE IF (@Status!='2')
|
|
BEGIN
|
|
RAISERROR('销售发货单:{0} 不是审核状态!',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.WorkPoint='{1}' AND a.Type='1'
|
|
|
|
IF EXISTS(SELECT a.ID FROM ICSSDN a
|
|
WHERE a.SDNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='1' AND a.Quantity<a.SDNQuantity)
|
|
BEGIN
|
|
RAISERROR('单据号:{0},行号:{3} 对应的源头单据已发数量不能大于应发数量!',16,1);
|
|
RETURN
|
|
END";
|
|
|
|
sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
|
|
|
|
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 SalesShipmentDocERP(string TransType, string Identification, SqlCommand cmd)
|
|
{
|
|
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,0 AS Amount,b.SDNDetailID,Enable AS UpdateTodoQuantity
|
|
INTO #TempERP
|
|
FROM ICSWareHouseLotInfoLog a
|
|
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
|
|
WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1'
|
|
GROUP BY b.CusCode,a.FromWarehouseCode,b.SDNCode,a.MUSER,a.InvCode,b.SDNDetailID,Enable
|
|
|
|
SELECT DISTINCT Costre,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
|
|
SELECT Costre,Sequence,InvCode,Quantity,Amount,SDNDetailID FROM #TempERP
|
|
|
|
DROP TABLE #TempERP";
|
|
sql = string.Format(sql, Identification);
|
|
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
|
|
|
|
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
|
|
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.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;
|
|
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["SSDCode"].ToString(), det["Sequence"].ToString(), cmd);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Debug(ex.ToString());
|
|
log.Debug(resultStr);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw new Exception("ERP接口调用失败:"+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)
|
|
{
|
|
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('条码:{0} 对应的源头单据不存在!',16,1);
|
|
RETURN
|
|
END
|
|
ELSE IF (@Status!='2')
|
|
BEGIN
|
|
RAISERROR('条码:{0} 对应的源头单据不是审核状态!',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'
|
|
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 c.Quantity<c.SDNQuantity)
|
|
BEGIN
|
|
RAISERROR('条码:{0}对应的源头单据已退数量不能大于应退数量!',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)
|
|
{
|
|
try
|
|
{
|
|
#region ERP
|
|
string 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,0 AS Amount,c.SDNDetailID,Enable AS UpdateTodoQuantity
|
|
INTO #TempERP
|
|
FROM ICSWareHouseLotInfoLog 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 ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
|
|
WHERE a.Identification='{0}' AND ERPUpload='0' AND c.Type='2'
|
|
GROUP BY c.CusCode,a.ToWarehouseCode,c.SDNCode,a.MUSER,a.InvCode,c.SDNDetailID,Enable
|
|
|
|
SELECT DISTINCT Costre,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
|
|
SELECT Costre,Sequence,InvCode,Quantity,Amount,SDNDetailID AS SDNRTDetailID FROM #TempERP
|
|
|
|
DROP TABLE #TempERP";
|
|
sql = string.Format(sql, Identification);
|
|
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
|
|
|
|
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
|
|
|
|
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.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;
|
|
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNRTDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["SDNNEGCode"].ToString(), det["Sequence"].ToString(), cmd);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Debug(ex.ToString());
|
|
log.Debug(resultStr);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw new Exception("ERP接口调用失败:"+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)
|
|
{
|
|
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('条码:{0} 对应的源头单据不存在!',16,1);
|
|
RETURN
|
|
END
|
|
ELSE IF (@Status!='2')
|
|
BEGIN
|
|
RAISERROR('条码:{0} 对应的源头单据不是审核状态!',16,1);
|
|
RETURN
|
|
END
|
|
UPDATE sdn SET SDNQuantity=ISNULL(SDNQuantity,0)+'{2}'
|
|
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('条码:{0}对应的源头单据已退数量不能大于应退数量!',16,1);
|
|
END";
|
|
sql = string.Format(sql, LotNo, WorkPoint, Quantity, TransCode, TransSequence);
|
|
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 SalesReturnBackInERP(string TransType, string Identification, SqlCommand cmd)
|
|
{
|
|
try
|
|
{
|
|
#region ERP
|
|
string 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,0 AS Amount,c.SDNDetailID,Enable AS UpdateTodoQuantity
|
|
INTO #TempERP
|
|
FROM ICSWareHouseLotInfoLog a
|
|
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
|
|
WHERE a.Identification='{0}' AND ERPUpload='0' AND c.Type='2'
|
|
GROUP BY c.CusCode,a.ToWarehouseCode,c.SDNCode,a.MUSER,a.InvCode,c.SDNDetailID,Enable
|
|
|
|
SELECT DISTINCT Costre,CusCode,WarehouseCode AS WHCode,SDNCode AS SDNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
|
|
SELECT Costre,Sequence,InvCode,Quantity,Amount,SDNDetailID AS SDNRTDetailID FROM #TempERP
|
|
|
|
DROP TABLE #TempERP";
|
|
sql = string.Format(sql, Identification);
|
|
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
|
|
|
|
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
|
|
|
|
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.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;
|
|
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SDNRTDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["SDNNEGCode"].ToString(), det["Sequence"].ToString(), cmd);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.Debug(ex.ToString());
|
|
log.Debug(resultStr);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw new Exception("ERP接口调用失败:" + result.Message);
|
|
}
|
|
#endregion
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|