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
{
///
/// 使用中
/// 库内作业模块
///
public class ICSWareHouseService
{
private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#region 一步调拨
///
/// 一步调拨
///
///
///
///
///
///
public static void OneStepTransferDocIn(string TransCode, string TransSequence, string WorkPoint, string Quantity, SqlCommand cmd, Dictionary language)
{
try
{
string sql = @"UPDATE ICSTransfer SET TransferQuantity=ISNULL(TransferQuantity,0)+'{2}'
WHERE TransferNO='{0}' AND Sequence='{3}' AND WorkPoint='{1}' AND Type='1'
IF EXISTS(SELECT a.ID FROM ICSTransfer a
WHERE a.TransferNO='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='1'
AND a.Quantity
/// 一步调拨(调拨申请单)
///
///
///
///
///
///
public static void OneStepTransferApplicationIn(string TransCode, string TransSequence, string WorkPoint, string Quantity, SqlCommand cmd, Dictionary language)
{
try
{
string sql = @"UPDATE ICSTransferApplication SET TransferQuantity=ISNULL(TransferQuantity,0)+'{2}'
WHERE TransferNO='{0}' AND Sequence='{3}' AND WorkPoint='{1}' AND Type='1'
IF EXISTS(SELECT a.ID FROM ICSTransferApplication a
WHERE a.TransferNO='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='1' AND a.TransferQuantity
/// 一步调拨接口
///
///
///
///
public static void OneStepTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary language, string BusinessCode)
{
try
{
#region SAP(三层结构)
string IsSuccess = "";
string ErrorMessage = "";
string sql = @" select Distinct A.TransferNO,A.WorkPoint from ICSTransfer A
LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.TransferNO AND B.WorkPoint=A.WorkPoint
where B.Identification='{0}' AND BusinessCode='21'";
sql = string.Format(sql, Identification);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count > 1)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
}
for (int i = 0; i < dt.Rows.Count; i++)
{
string chksql = @"select SUM(Quantity) AS Quantity,SUM(TransferQuantity) AS TransferQuantity from ICSTransfer
where TransferNO='{0}' and WorkPoint='{1}'
GROUP BY TransferNO,WorkPoint";
chksql = string.Format(chksql, dt.Rows[i]["TransferNO"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) == Convert.ToDecimal(chkdt.Rows[0]["TransferQuantity"]))
{
SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
Info.NEWID = Identification;
Info.DANJU = dt.Rows[i]["TransferNO"].ToString();
Info.STATE = "0";
List ItemList = new List();
List ItemLineList = new List();
Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
sql = @" select A.TransferNO,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.TransferQuantity
,ISNULL(B.BatchCode,'') AS BatchCode from ICSTransfer A
LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
WHERE TransferNO='{0}' AND A.WorkPoint='{1}'";
sql = string.Format(sql, dt.Rows[i]["TransferNO"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
foreach (DataRow dr in Sapdt.Rows)
{
if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["TransferQuantity"].ToString()))
{
SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
Item.DANJU = dr["TransferNO"].ToString();
Item.POSNR = dr["SAPSequence"].ToString();
Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
ItemList.Add(Item);
if (dr["BatchCode"].ToString() != "")
{
ItemLine.DANJU = dr["TransferNO"].ToString();
ItemLine.POSNR = dr["SAPSequence"].ToString();
ItemLine.MATNR = dr["InvCode"].ToString();
ItemLine.GERNR = dr["BatchCode"].ToString();
ItemLineList.Add(ItemLine);
}
}
}
if (ItemList.Count > 0)
{
Info.Z_ITEM = ItemList.ToArray();
if (ItemLineList.Count > 0)
{
Info.Z_GERNR = ItemLineList.ToArray();
}
else
{
Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
}
SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
result = Client.CallZWMS_SK_WS_PZ(Info);
if (result.Z_NULL == "N")
{
foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
{
IsSuccess = "N";
ErrorMessage += resultItem.L_MESSAGE + "/r/n";
}
}
}
}
}
if (IsSuccess == "N")
{
throw new Exception(ErrorMessage);
}
#endregion
}
catch (Exception)
{
throw;
}
}
#endregion
#region 调拨
///
/// 调拨接口
///
///
///
///
public static void StepTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary language, string BusinessCode)
{
try
{
#region ERP开立状态单据审核
//检验调拨单是否一次性发完
string sql = @"SELECT a.ToWarehouseCode+a.MUSER+a.FromWarehouseCode AS Costre,a.ToWarehouseCode AS ToWHCode,a.FromWarehouseCode AS FromWHCode,a.MUSER,'' AS FromDepCode,'' AS ToDepCode,NULL AS TACode,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode) AS Sequence,NULL AS TADetailID,
a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,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 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 ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
WHERE a.Identification='{0}' AND ERPUpload='0'
GROUP BY a.ToWarehouseCode,a.MUSER,a.InvCode,conStock.Enable,con.Enable,a.FromWarehouseCode
,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,ToWHCode,FromWHCode,FromDepCode ,ToDepCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint,TACode,UpdateStock FROM #TempERP
SELECT Costre,Sequence,InvCode,Quantity,Amount,TADetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
FROM #TempERP
DROP TABLE #TempERP";
sql = string.Format(sql, Identification);
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.StepTransferDocInURL, Inputstr);
Result result = new Result();
result = JsonConvert.DeserializeObject(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["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);
}
#endregion
}
catch (Exception)
{
throw;
}
}
#endregion
#region 调拨申请单接口
///
/// 调拨申请单接口
///
///
///
///
public static void StepTransferApplicationERP(string TransType, string Identification, SqlCommand cmd, Dictionary language, string BusinessCode)
{
try
{
#region ERP开立状态单据审核
//检验调拨单是否一次性发完
string sql = @"SELECT c.TransferDetailID as TADetailID,a.ToWarehouseCode+a.MUSER+a.FromWarehouseCode AS Costre,a.ToWarehouseCode AS ToWHCode,a.FromWarehouseCode AS FromWHCode,a.MUSER,'' AS FromDepCode,'' AS ToDepCode,a.TransCode AS TACode,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,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 ICSTransfer c ON a.TransCode=c.TransferNO and a.TransSequence=c.Sequence and a.WorkPoint=c.WorkPoint
--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 ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
WHERE a.Identification='{0}' AND ERPUpload='0'
GROUP BY a.ToWarehouseCode,a.MUSER,c.TransferDetailID,a.InvCode,conStock.Enable,con.Enable,a.FromWarehouseCode
,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, ''),a.TransCode
SELECT DISTINCT Costre,ToWHCode,FromWHCode,FromDepCode ,ToDepCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint,TACode,UpdateStock FROM #TempERP
SELECT Costre,Sequence,InvCode,Quantity,Amount,TADetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
FROM #TempERP
DROP TABLE #TempERP";
sql = string.Format(sql, Identification);
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.StepTransferApplicationURL, Inputstr);
Result result = new Result();
result = JsonConvert.DeserializeObject(resultStr);
if (result.Success)
{
try
{
JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
foreach (var item in res)
{
JObject jo = (JObject)item;
JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
foreach (var detail in resdetail)
{
JObject det = (JObject)detail;
string allcol = "" + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
+ det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["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);
}
#endregion
}
catch (Exception)
{
throw;
}
}
#endregion
#region 两步调出
///
/// 两步调出
///
///
///
///
///
///
public static void TwoStepTransferDocOut(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary language)
{
try
{
string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=a.Status FROM ICSOtherOut a
INNER JOIN ICSTransfer b ON a.TransferDetailID=b.TransferDetailID AND a.WorkPoint=b.WorkPoint
WHERE a.OutCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
IF (@Status IS NULL)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo146") + @"',16,1);
RETURN
END
ELSE IF (@Status!='1')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo147") + @"',16,1);
RETURN
END
UPDATE a SET OutQuantity=ISNULL(OutQuantity,0)+'{2}'
FROM ICSOtherOut a
INNER JOIN ICSTransfer b ON a.TransferDetailID=b.TransferDetailID AND a.WorkPoint=b.WorkPoint
WHERE a.OutCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
IF EXISTS(SELECT a.ID FROM ICSOtherOut a
INNER JOIN ICSTransfer b ON a.TransferDetailID=b.TransferDetailID AND a.WorkPoint=b.WorkPoint
WHERE a.OutCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity
/// 两步调出接口
///
///
///
///
public static void TwoStepTransferDocOutERP(string TransType, string Identification, SqlCommand cmd, Dictionary language, string BusinessCode)
{
try
{
#region ERP开立状态单据审核
string sql = @"IF EXISTS(SELECT b.ID FROM ICSOtherOut b
INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
WHERE b.OutCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
AND b.Quantity!=b.OutQuantity)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo098") + @"',16,1);
RETURN
END
SELECT b.OutID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSOtherOut b ON a.TransCode=b.OutCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
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
WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '22'
GROUP BY b.OutID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
sql = string.Format(sql, Identification);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
string Inputstr = JsonConvert.SerializeObject(dt);
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.TwoStepTransferDocOutURL, Inputstr);
Result result = new Result();
result = JsonConvert.DeserializeObject(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 两步调入
///
/// 两步调入
///
///
///
///
///
///
public static void TwoStepTransferDocIn(string TransCode, string TransSequence, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary language)
{
//需要关联其他入库单
try
{
string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=Otin.Status FROM ICSOtherIn Otin
INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.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 Otin.InCode='{2}' AND Otin.Sequence='{3}'
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 Otin SET InQuantity=ISNULL(InQuantity,0)+'{4}'
FROM ICSOtherIn Otin
INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.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 Otin.InCode='{2}' AND Otin.Sequence='{3}'
IF EXISTS(SELECT a.LotNo FROM ICSOtherIn Otin
INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.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 Otin.InCode='{2}' AND Otin.Sequence='{3}' AND Otin.Quantity
/// 两步调入接口
///
///
///
///
public static void TwoStepTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary language, string BusinessCode)
{
try
{
#region ERP开立状态单据审核
string sql = @"IF EXISTS(SELECT b.ID FROM ICSOtherIn b
INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
WHERE b.InCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
AND b.Quantity!=b.InQuantity)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo099") + @"',16,1);
RETURN
END
SELECT b.InID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID 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='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
WHERE a.Identification='{0}' AND ERPUpload='0'
GROUP BY b.InID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
sql = string.Format(sql, Identification);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
string Inputstr = JsonConvert.SerializeObject(dt);
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.TwoStepTransferDocInURL, Inputstr);
Result result = new Result();
result = JsonConvert.DeserializeObject(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 其他出库
///
/// 其他出库
///
///
///
///
///
///
public static void OtherOutDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary language)
{
try
{
string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=a.Status FROM ICSOtherOut a
WHERE a.OutCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
IF (@Status IS NULL)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo151") + @"',16,1);
RETURN
END
ELSE IF (@Status!='1')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo152") + @"',16,1);
RETURN
END
UPDATE a SET OutQuantity=ISNULL(OutQuantity,0)+'{2}'
FROM ICSOtherOut a
WHERE a.OutCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
IF EXISTS(SELECT a.ID FROM ICSOtherOut a
WHERE a.OutCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity
/// 其他出库接口
///
///
///
///
public static void OtherOutDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary language, string BusinessCode)
{
try
{
#region SAP(三层结构)
string IsSuccess = "";
string ErrorMessage = "";
string sql = @" select Distinct A.OutCode,A.WorkPoint from ICSOtherOut A
LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.OutCode AND B.WorkPoint=A.WorkPoint
where B.Identification='{0}' AND BusinessCode='24'";
sql = string.Format(sql, Identification);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count > 1)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
}
for (int i = 0; i < dt.Rows.Count; i++)
{
string chksql = @"select SUM(Quantity) AS Quantity,SUM(OutQuantity) AS OutQuantity from ICSOtherOut
where OutCode='{0}' and WorkPoint='{1}'
GROUP BY OutCode,WorkPoint";
chksql = string.Format(chksql, dt.Rows[i]["OutCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) == Convert.ToDecimal(chkdt.Rows[0]["OutQuantity"]))
{
SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
Info.NEWID = Identification;
Info.DANJU = dt.Rows[i]["OutCode"].ToString();
Info.STATE = "0";
List ItemList = new List();
List ItemLineList = new List();
Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
sql = @"select A.OutCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.OutQuantity
,ISNULL(B.BatchCode,'') AS BatchCode from ICSOtherOut A
LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
WHERE OutCode='{0}' AND A.WorkPoint='{1}'";
sql = string.Format(sql, dt.Rows[i]["OutCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
foreach (DataRow dr in Sapdt.Rows)
{
if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["OutQuantity"].ToString()))
{
SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
Item.DANJU = dr["OutCode"].ToString();
Item.POSNR = dr["SAPSequence"].ToString();
Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
ItemList.Add(Item);
if (dr["BatchCode"].ToString() != "")
{
ItemLine.DANJU = dr["OutCode"].ToString();
ItemLine.POSNR = dr["SAPSequence"].ToString();
ItemLine.MATNR = dr["InvCode"].ToString();
ItemLine.GERNR = dr["BatchCode"].ToString();
ItemLineList.Add(ItemLine);
}
}
}
if (ItemList.Count > 0)
{
Info.Z_ITEM = ItemList.ToArray();
if (ItemLineList.Count > 0)
{
Info.Z_GERNR = ItemLineList.ToArray();
}
else
{
Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
}
SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
result = Client.CallZWMS_SK_WS_PZ(Info);
if (result.Z_NULL == "N")
{
foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
{
IsSuccess = "N";
ErrorMessage += resultItem.L_MESSAGE + "/r/n";
}
}
}
}
}
if (IsSuccess == "N")
{
throw new Exception(ErrorMessage);
}
#endregion
}
catch (Exception)
{
throw;
}
}
#endregion
#region 其他入库
///
/// 其他入库
///
///
///
///
///
///
public static void OtherInDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary 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 ICSOtherIn c ON b.TransCode=c.InCode 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!='1')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',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 ICSOtherIn c ON b.TransCode=c.InCode 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 ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity
/// 其他入库接口
///
///
///
///
public static void OtherInDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary language, string BusinessCode)
{
try
{
#region SAP(三层结构)
string IsSuccess = "";
string ErrorMessage = "";
string sql = @" select Distinct A.InCode,A.WorkPoint from ICSOtherIn A
LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.InCode AND B.WorkPoint=A.WorkPoint
where B.Identification='{0}' AND BusinessCode='25'";
sql = string.Format(sql, Identification);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count > 1)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
}
for (int i = 0; i < dt.Rows.Count; i++)
{
string chksql = @"select SUM(Quantity) AS Quantity,SUM(InQuantity) AS InQuantity from ICSOtherIn
where InCode='{0}' and WorkPoint='{1}'
GROUP BY InCode,WorkPoint";
chksql = string.Format(chksql, dt.Rows[i]["InCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) == Convert.ToDecimal(chkdt.Rows[0]["InQuantity"]))
{
SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
Info.NEWID = Identification;
Info.DANJU = dt.Rows[i]["InCode"].ToString();
Info.STATE = "0";
List ItemList = new List();
List ItemLineList = new List();
Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
sql = @"select A.InCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.InQuantity
,ISNULL(B.BatchCode,'') AS BatchCode from ICSOtherIn A
LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
WHERE InCode='{0}' AND A.WorkPoint='{1}'";
sql = string.Format(sql, dt.Rows[i]["InCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
foreach (DataRow dr in Sapdt.Rows)
{
if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["InQuantity"].ToString()))
{
SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
Item.DANJU = dr["InCode"].ToString();
Item.POSNR = dr["SAPSequence"].ToString();
Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
ItemList.Add(Item);
if (dr["BatchCode"].ToString() != "")
{
ItemLine.DANJU = dr["InCode"].ToString();
ItemLine.POSNR = dr["SAPSequence"].ToString();
ItemLine.MATNR = dr["InvCode"].ToString();
ItemLine.GERNR = dr["BatchCode"].ToString();
ItemLineList.Add(ItemLine);
}
}
}
if (ItemList.Count > 0)
{
Info.Z_ITEM = ItemList.ToArray();
if (ItemLineList.Count > 0)
{
Info.Z_GERNR = ItemLineList.ToArray();
}
else
{
Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
}
SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
result = Client.CallZWMS_SK_WS_PZ(Info);
if (result.Z_NULL == "N")
{
foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
{
IsSuccess = "N";
ErrorMessage += resultItem.L_MESSAGE + "/r/n";
}
}
}
}
}
if (IsSuccess == "N")
{
throw new Exception(ErrorMessage);
}
#endregion
}
catch (Exception)
{
throw;
}
}
#endregion
#region 拆卸单
///
/// 拆卸单
///
///
///
///
///
///
public static void DisassemblyDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary 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 ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DABDOCType='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 DABDOCQuantity=ISNULL(DABDOCQuantity,0)+'{2}'
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode 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 ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity
/// 拆卸单更新套件锁定数量
///
///
///
public static void DisassemblyDoc(string Identification, SqlCommand cmd, Dictionary language)
{
try
{
string sql = @"UPDATE ICSDisassemblyDoc SET DABDOCQuantity=Quantity
WHERE DABDOCCode+Sequence+WorkPoint IN(SELECT DISTINCT d.TransCode+d.TransSequence+d.WorkPoint
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
WHERE a.Identification='{0}' AND d.ERPUpload='0' AND d.Lock='1')
UPDATE ICSWareHouseLotInfo SET Quantity=Quantity-LockQuantity,LockQuantity=0
WHERE LotNo+WorkPoint IN(SELECT DISTINCT d.LotNo+d.WorkPoint
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
WHERE a.Identification='{0}' AND d.ERPUpload='0' AND d.Lock='1')";
sql = string.Format(sql, Identification);
if (!DBHelper.ExecuteNonQuery(sql, cmd))
{
throw new Exception(language.GetNameByCode("WMSAPIInfo158"));//"拆卸单套件更新失败!");
}
}
catch (Exception)
{
throw;
}
}
///
/// 拆卸单接口
///
///
///
///
public static void DisassemblyDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary language, string BusinessCode)
{
try
{
#region ERP开立状态单据审核
string sql = @"IF EXISTS(SELECT b.ID FROM ICSDisassemblyDoc b
WHERE b.DABDOCCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
AND b.Quantity!=b.DABDOCQuantity)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo102") + @"',16,1);
RETURN
END
SELECT b.DABDOCID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSDisassemblyDoc b ON a.TransCode=b.DABDOCCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
WHERE a.Identification='{0}' AND ERPUpload='0'
GROUP BY b.DABDOCID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
sql = string.Format(sql, Identification);
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
string Inputstr = JsonConvert.SerializeObject(dt);
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DisassemblyDocURL, Inputstr);
Result result = new Result();
result = JsonConvert.DeserializeObject(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 借用
///
/// 借用
///
///
///
///
///
///
public static void BrrowDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary language)
{
try
{
string sql = @"DECLARE @Status VARCHAR(10)
SELECT @Status=a.Status FROM ICSBrrow a
WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
IF (@Status IS NULL)
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo159") + @"',16,1);
RETURN
END
ELSE IF (@Status!='2')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo160") + @"',16,1);
RETURN
END
UPDATE a SET BrrowQuantity=ISNULL(BrrowQuantity,0)+'{2}'
FROM ICSBrrow a
WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
IF EXISTS(SELECT a.ID FROM ICSBrrow a
WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity
/// 借用接口
///
///
///
///
public static void BrrowDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary language, string BusinessCode)
{
try
{
#region ERP
string sql = @"SELECT a.FromWarehouseCode+b.BrrowCode+a.MUSER AS Costre,a.FromWarehouseCode AS WarehouseCode,b.BrrowCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,b.BrrowCode,b.BrrowDetailID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(b.Amount/b.Quantity)) AS Amount,b.BrrowDetailID,Enable AS UpdateTodoQuantity
,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
INTO #TempERP
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSBrrow b ON a.TransCode=b.BrrowCode 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 a.BusinessCode = '26'
GROUP BY a.FromWarehouseCode,b.BrrowCode,a.MUSER,a.InvCode,b.BrrowDetailID,Enable
,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, '')
SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'借用单' AS SourceType,BrrowCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
SELECT Costre,Sequence,InvCode,Quantity,Amount,BrrowDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
DROP TABLE #TempERP";
sql = string.Format(sql, Identification);
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.BrrowDocURL, Inputstr);
Result result = new Result();
result = JsonConvert.DeserializeObject(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["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
det["DetailID"].ToString(), jo["OtherOutCode"].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 归还
///
/// 归还
///
///
///
///
///
///
public static void ReturnDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary 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 ICSReturn c ON b.TransCode=c.ReturnCode 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!='2')
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
RETURN
END
UPDATE c SET ReturnQuantity=ISNULL(ReturnQuantity,0)+'{2}'
FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode 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 ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity
/// 归还接口
///
///
///
///
public static void ReturnDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary language, string BusinessCode)
{
try
{
#region ERP
string sql = @"SELECT a.ToWarehouseCode+b.ReturnCode+a.MUSER AS Costre,a.ToWarehouseCode AS WarehouseCode,b.ReturnCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode,b.ReturnCode,b.ReturnDetailID,a.InvCode) AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,b.ReturnDetailID,Enable AS UpdateTodoQuantity
,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
INTO #TempERP
FROM ICSWareHouseLotInfoLog a
INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSReturn b ON a.TransCode=b.ReturnCode 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 BusinessCode='{1}'
GROUP BY a.ToWarehouseCode,b.ReturnCode,a.MUSER,a.InvCode,b.ReturnDetailID,Enable
,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, '')
SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'归还单' AS SourceType,ReturnCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
SELECT Costre,Sequence,InvCode,Quantity,Amount,ReturnDetailID 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, BusinessCode);
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ReturnDocURL, Inputstr);
Result result = new Result();
result = JsonConvert.DeserializeObject(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["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
det["DetailID"].ToString(), jo["OtherInCode"].ToString(), det["Sequence"].ToString(), "", 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 形态转换
///
/// 形态转换
///
///
///
///
///
///
public static void MTDoc(string TransCode, string TransSequence,string User, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary language)
{
try
{
string code = string.Format(language.GetNameByCode("WMSAPIInfo060"), User);
string error = string.Format(language.GetNameByCode("WMSAPIInfo091"), TransCode,"","", TransSequence);
string sql = $@"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{User}' AND F_Location='{WorkPoint}')
BEGIN
RAISERROR('{code}',16,1);
RETURN
END
UPDATE a SET MTDOCQuantity=ISNULL(MTDOCQuantity,0)+'{Quantity}'
FROM ICSMTDOC a
WHERE a.MTDOCCode='{TransCode}' AND a.Sequence='{TransSequence}' AND a.WorkPoint='{WorkPoint}'
IF EXISTS(SELECT a.ID FROM ICSMTDOC a
WHERE a.MTDOCCode='{TransCode}' AND a.Sequence='{TransSequence}' and a.WorkPoint='{WorkPoint}' AND a.Quantity
/// 形态转换接口
///
///
///
///
public static void MTDocDocERP(string Trancode, SqlCommand cmd, Dictionary language, string BusinessCode)
{
try
{
#region SAP(三层结构)
string IsSuccess = "";
string ErrorMessage = "";
string sql = $@" select Distinct A.MTDOCCode,A.WorkPoint from ICSMTDOC A
where A.MTDOCCode='{Trancode}' AND A.MTDOCType='2' ";
DataTable dt = DBHelper.SQlReturnData(sql, cmd);
if (dt.Rows.Count > 1)
{
throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
}
for (int i = 0; i < dt.Rows.Count; i++)
{
string chksql = @"select SUM(Quantity) AS Quantity,SUM(MTDOCQuantity) AS MTDOCQuantity from ICSMTDOC
where MTDOCCode='{0}' and WorkPoint='{1}'
GROUP BY MTDOCCode,WorkPoint";
chksql = string.Format(chksql, dt.Rows[i]["MTDOCCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) == Convert.ToDecimal(chkdt.Rows[0]["MTDOCQuantity"]))
{
SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
Info.NEWID = Guid.NewGuid().ToString();
Info.DANJU = dt.Rows[i]["MTDOCCode"].ToString();
Info.STATE = "0";
List ItemList = new List();
List ItemLineList = new List();
Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
sql = @"select Distinct A.MTDOCCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.MTDOCQuantity
,ISNULL(B.BatchCode,'') AS BatchCode from ICSMTDOC A
LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
WHERE MTDOCCode='{0}' AND A.WorkPoint='{1}'";
sql = string.Format(sql, dt.Rows[i]["MTDOCCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
foreach (DataRow dr in Sapdt.Rows)
{
if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["MTDOCQuantity"].ToString()))
{
SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
Item.DANJU = dr["MTDOCCode"].ToString();
Item.POSNR = dr["SAPSequence"].ToString();
Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
ItemList.Add(Item);
if (dr["BatchCode"].ToString() != "")
{
ItemLine.DANJU = dr["MTDOCCode"].ToString();
ItemLine.POSNR = dr["SAPSequence"].ToString();
ItemLine.MATNR = dr["InvCode"].ToString();
ItemLine.GERNR = dr["BatchCode"].ToString();
ItemLineList.Add(ItemLine);
}
}
}
if (ItemList.Count > 0)
{
Info.Z_ITEM = ItemList.ToArray();
if (ItemLineList.Count > 0)
{
Info.Z_GERNR = ItemLineList.ToArray();
}
else
{
Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
}
SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
result = Client.CallZWMS_SK_WS_PZ(Info);
if (result.Z_NULL == "N")
{
foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
{
IsSuccess = "N";
ErrorMessage += resultItem.L_MESSAGE + "/r/n";
}
}
}
}
}
if (IsSuccess == "N")
{
throw new Exception(ErrorMessage);
}
#endregion
}
catch (Exception)
{
throw;
}
}
#endregion
#endregion
}
}