Browse Source

副产品生成产成品入库单修改

master
姜鹏 2 years ago
parent
commit
8f7bf1294a
  1. 226
      ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSManufactureService.cs

226
ICSSoft.WMS.WebAPI/ICSSoft.DataProject/ICSManufactureService.cs

@ -798,8 +798,119 @@ namespace ICSSoft.DataProject
#endregion
#region ERP
string sql = "";
Result result = new Result();
DataSet ds;
#region 副产品生成产成品入库单
try {
sql = @"-- 判断本工单中对应行号与本批次副产品是否已生成入库单号
IF(
SELECT DISTINCT bypro.BatchCode
FROM ICSWareHouseLotInfoLog a
LEFT JOIN ICSInventoryLot b ON b.LotNo = a.LotNo AND b.WorkPoint = a.WorkPoint
LEFT JOIN ICSExtension c ON c.ID = b.ExtensionID AND c.WorkPoint = b.WorkPoint
LEFT JOIN ICSMOByProductLog bypro ON bypro.MoCode = a.TransCode AND bypro.Sequence = a.TransSequence AND bypro.BatchCode = c.BatchCode AND bypro.WorkPoint = a.WorkPoint
WHERE a.Identification='{0}'
) IS NULL
BEGIN
--
DECLARE @BatchCount VARCHAR(10)
SELECT @BatchCount=COUNT(DISTINCT c.BatchCode)
FROM ICSWareHouseLotInfoLog a
LEFT JOIN ICSInventoryLot b ON b.LotNo = a.LotNo AND b.WorkPoint = a.WorkPoint
LEFT JOIN ICSExtension c ON c.ID = b.ExtensionID AND c.WorkPoint = b.WorkPoint
LEFT JOIN ICSInventoryLotDetail d ON d.LotNo = b.LotNo AND d.WorkPoint = b.WorkPoint
LEFT JOIN ICSMO e ON e.MOCode = d.TransCode AND e.WorkPoint = d.WorkPoint
LEFT JOIN ICSMOPick f ON f.MODetailID = e.MODetailID AND f.WorkPoint = d.WorkPoint
WHERE a.Identification = '{0}'
AND(SELECT 1 FROM ICSMOByProductLog bypro WHERE bypro.MoCode = a.TransCode AND bypro.Sequence = a.TransSequence AND bypro.BatchCode = c.BatchCode AND bypro.WorkPoint = a.WorkPoint) IS NULL
-- SELECT @BatchCount
--
SELECT e.DepCode+f.WHCode+e.MOCode+a.MUSER AS Costre,e.DepCode,f.WHCode AS WarehouseCode,e.MoCode,a.MUSER,f.Sequence AS Sequence,f.InvCode,f.EATTRIBUTE2 AS Quantity,0 AS Amount,f.PickID as MODetailID,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
LEFT JOIN ICSInventoryLot b ON b.LotNo=a.LotNo AND b.WorkPoint=a.WorkPoint
LEFT JOIN ICSExtension ext ON ext.ID=b.ExtensionID AND ext.WorkPoint=b.WorkPoint
LEFT JOIN ICSInventoryLotDetail d ON d.LotNo=b.LotNo AND d.WorkPoint=b.WorkPoint
LEFT JOIN ICSMO e ON e.MOCode=d.TransCode AND e.Sequence=d.TransSequence AND e.WorkPoint=d.WorkPoint
LEFT JOIN ICSMOPick f ON f.MODetailID=e.MODetailID AND f.WorkPoint=d.WorkPoint
INNER JOIN ICSInventory inv ON f.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON f.InvCode=invBat.InvCode AND f.WHCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
WHERE a.Identification='{0}'
AND f.EATTRIBUTE1='1'
AND (SELECT 1 FROM ICSMOByProductLog bypro WHERE bypro.MoCode=e.MoCode AND bypro.Sequence=f.Sequence AND bypro.BatchCode=ext.BatchCode AND bypro.WorkPoint=a.WorkPoint) IS NULL
GROUP BY e.DepCode,f.WHCode,e.MoCode,a.MUSER,f.InvCode,f.EATTRIBUTE2,f.Sequence,f.PickID,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, '' as TYPE,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
SELECT Costre,Sequence,InvCode,Quantity*@BatchCount AS Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
FROM #TempERP
DROP TABLE #TempERP
END
ELSE
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo467") + @"',16,1);
-- RAISERROR('',16,1)
END";
sql = string.Format(sql, Identification);
log.Debug("副产品生成入库单逻辑:");
log.Debug(sql);
ds = DBHelper.SQlReturnDataSet(sql, cmd);
string ByProductInputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
string byProductResultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ManufactureReceiveDocASKURL, ByProductInputstr);
result = new Result();
result = JsonConvert.DeserializeObject<Result>(byProductResultStr);
if (result.Success)
{
//向ICSMOByProductLog表中插入数据
sql = @"SELECT a.TransCode,a.TransSequence,a.Quantity,c.BatchCode,b.InvCode,a.WorkPoint
FROM ICSWareHouseLotInfoLog a
LEFT JOIN ICSInventoryLot b ON b.LotNo=a.LotNo AND b.WorkPoint=a.WorkPoint
LEFT JOIN ICSExtension c ON c.ID=b.ExtensionID AND c.WorkPoint=a.WorkPoint
WHERE a.Identification='{0}'";
sql = string.Format(sql,Identification);
log.Debug("查询入库的主产品及批次SQL:");
log.Error(sql);
DataTable dtt = DBHelper.SQlReturnData(sql, cmd);
string jsonStr = JsonConvert.SerializeObject(dtt);
log.Debug("SQL执行结果:" + jsonStr);
List<MoStockInModel> moStockIns = JsonConvert.DeserializeObject<List<MoStockInModel>>(jsonStr);
foreach (MoStockInModel moStockIn in moStockIns)
{
try
{
sql = @"INSERT INTO ICSMOByProductLog VALUES(NEWID(),'{0}','{1}',{2},'{3}','{4}','{5}')";
sql = string.Format(sql, moStockIn.TransCode, moStockIn.TransSequence, moStockIn.Quantity, moStockIn.BatchCode, moStockIn.InvCode, moStockIn.WorkPoint);
log.Debug("向ICSMOByProductLog表中插入数据:");
log.Debug(sql);
DBHelper.ExecuteNonQuery(sql, cmd);
}
catch
{
throw new Exception(language.GetNameByCode("WMSAPIInfo466"));
}
}
log.Debug(language.GetNameByCode("WMSAPIInfo465") + ":" + result.ToString());
}
else
{
log.Debug(language.GetNameByCode("WMSAPIInfo080") + result.Message);
}
}
catch(Exception ex)
{
log.Debug(ex.Message);
}
#endregion
#region SQL
string sql = @"SELECT c.DepCode+a.ToWarehouseCode+c.MOCode+a.MUSER AS Costre,c.MODetailID+ext.BatchCode AS Costre2,c.DepCode,a.ToWarehouseCode AS WarehouseCode,c.MOCode,a.MUSER,'' AS Sequence,
sql = @"SELECT c.DepCode+a.ToWarehouseCode+c.MOCode+a.MUSER AS Costre,c.MODetailID+ext.BatchCode AS Costre2,c.DepCode,a.ToWarehouseCode AS WarehouseCode,c.MOCode,a.MUSER,'' AS Sequence,
a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,c.MODetailID,con.Enable AS UpdateTodoQuantity
,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10,conv.Enable AS CompleteVerification,a.TransSequence
@ -921,13 +1032,12 @@ ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.
// DROP TABLE #TempERP";
#endregion
sql = string.Format(sql, Identification);
DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
ds = DBHelper.SQlReturnDataSet(sql, cmd);
string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "detailss", "Costre2");
string inputjson = Inputstr;
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ManufactureReceiveDocASKURL, Inputstr);
Result result = new Result();
string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ManufactureReceiveDocASKURL, Inputstr);
result = JsonConvert.DeserializeObject<Result>(resultStr);
if (result.Success)
{
@ -959,114 +1069,6 @@ ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.
log.Debug(resultStr);
}
#region 副产品生成产成品入库单
try {
sql = @"-- 判断本工单中对应行号与本批次副产品是否已生成入库单号
IF(
SELECT DISTINCT bypro.BatchCode
FROM ICSWareHouseLotInfoLog a
LEFT JOIN ICSInventoryLot b ON b.LotNo = a.LotNo AND b.WorkPoint = a.WorkPoint
LEFT JOIN ICSExtension c ON c.ID = b.ExtensionID AND c.WorkPoint = b.WorkPoint
LEFT JOIN ICSMOByProductLog bypro ON bypro.MoCode = a.TransCode AND bypro.Sequence = a.TransSequence AND bypro.BatchCode = c.BatchCode AND bypro.WorkPoint = a.WorkPoint
WHERE a.Identification='{0}'
) IS NULL
BEGIN
--
DECLARE @BatchCount VARCHAR(10)
SELECT @BatchCount=COUNT(DISTINCT c.BatchCode)
FROM ICSWareHouseLotInfoLog a
LEFT JOIN ICSInventoryLot b ON b.LotNo = a.LotNo AND b.WorkPoint = a.WorkPoint
LEFT JOIN ICSExtension c ON c.ID = b.ExtensionID AND c.WorkPoint = b.WorkPoint
LEFT JOIN ICSInventoryLotDetail d ON d.LotNo = b.LotNo AND d.WorkPoint = b.WorkPoint
LEFT JOIN ICSMO e ON e.MOCode = d.TransCode AND e.WorkPoint = d.WorkPoint
LEFT JOIN ICSMOPick f ON f.MODetailID = e.MODetailID AND f.WorkPoint = d.WorkPoint
WHERE a.Identification = '{0}'
AND(SELECT 1 FROM ICSMOByProductLog bypro WHERE bypro.MoCode = a.TransCode AND bypro.Sequence = a.TransSequence AND bypro.BatchCode = c.BatchCode AND bypro.WorkPoint = a.WorkPoint) IS NULL
-- SELECT @BatchCount
--
SELECT e.DepCode+f.WHCode+e.MOCode+a.MUSER AS Costre,e.DepCode,f.WHCode AS WarehouseCode,e.MoCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY e.DepCode,f.WHCode,e.MOCode,e.MODetailID,f.InvCode) AS Sequence,f.InvCode,f.EATTRIBUTE2 AS Quantity,0 AS Amount,e.MODetailID,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
LEFT JOIN ICSInventoryLot b ON b.LotNo=a.LotNo AND b.WorkPoint=a.WorkPoint
LEFT JOIN ICSExtension ext ON ext.ID=b.ExtensionID AND ext.WorkPoint=b.WorkPoint
LEFT JOIN ICSInventoryLotDetail d ON d.LotNo=b.LotNo AND d.WorkPoint=b.WorkPoint
LEFT JOIN ICSMO e ON e.MOCode=d.TransCode AND e.Sequence=d.TransSequence AND e.WorkPoint=d.WorkPoint
LEFT JOIN ICSMOPick f ON f.MODetailID=e.MODetailID AND f.WorkPoint=d.WorkPoint
INNER JOIN ICSInventory inv ON f.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
LEFT JOIN ICSInventoryBatchEnable invBat ON f.InvCode=invBat.InvCode AND f.WHCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
WHERE a.Identification='{0}'
AND f.EATTRIBUTE1='1'
AND (SELECT 1 FROM ICSMOByProductLog bypro WHERE bypro.MoCode=e.MoCode AND bypro.Sequence=f.Sequence AND bypro.BatchCode=ext.BatchCode AND bypro.WorkPoint=a.WorkPoint) IS NULL
GROUP BY e.DepCode,f.WHCode,e.MoCode,a.MUSER,f.InvCode,f.EATTRIBUTE2,e.MODetailID,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, '' as TYPE,WorkPoint,DepCode,WarehouseCode AS WHCode,MOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
SELECT Costre,Sequence,InvCode,Quantity*@BatchCount AS Quantity,Amount,MODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
FROM #TempERP
DROP TABLE #TempERP
END
ELSE
BEGIN
RAISERROR('" + language.GetNameByCode("WMSAPIInfo467") + @"',16,1);
-- RAISERROR('',16,1)
END";
sql = string.Format(sql, Identification);
log.Debug("副产品生成入库单逻辑:");
log.Debug(sql);
ds = DBHelper.SQlReturnDataSet(sql, cmd);
string ByProductInputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
string byProductResultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ManufactureReceiveDocASKURL, ByProductInputstr);
result = new Result();
result = JsonConvert.DeserializeObject<Result>(byProductResultStr);
if (result.Success)
{
//向ICSMOByProductLog表中插入数据
sql = @"SELECT a.TransCode,a.TransSequence,a.Quantity,c.BatchCode,b.InvCode,a.WorkPoint
FROM ICSWareHouseLotInfoLog a
LEFT JOIN ICSInventoryLot b ON b.LotNo=a.LotNo AND b.WorkPoint=a.WorkPoint
LEFT JOIN ICSExtension c ON c.ID=b.ExtensionID AND c.WorkPoint=a.WorkPoint
WHERE a.Identification='{0}'";
sql = string.Format(sql,Identification);
log.Debug("查询入库的主产品及批次SQL:");
log.Error(sql);
DataTable dtt = DBHelper.SQlReturnData(sql, cmd);
string jsonStr = JsonConvert.SerializeObject(dtt);
log.Debug("SQL执行结果:" + jsonStr);
List<MoStockInModel> moStockIns = JsonConvert.DeserializeObject<List<MoStockInModel>>(jsonStr);
foreach (MoStockInModel moStockIn in moStockIns)
{
try
{
sql = @"INSERT INTO ICSMOByProductLog VALUES(NEWID(),'{0}','{1}',{2},'{3}','{4}','{5}')";
sql = string.Format(sql, moStockIn.TransCode, moStockIn.TransSequence, moStockIn.Quantity, moStockIn.BatchCode, moStockIn.InvCode, moStockIn.WorkPoint);
log.Debug("向ICSMOByProductLog表中插入数据:");
log.Debug(sql);
DBHelper.ExecuteNonQuery(sql, cmd);
}
catch
{
throw new Exception(language.GetNameByCode("WMSAPIInfo466"));
}
}
log.Debug(language.GetNameByCode("WMSAPIInfo465") + ":" + result.ToString());
}
else
{
log.Debug(language.GetNameByCode("WMSAPIInfo080") + result.Message);
}
}
catch(Exception ex)
{
log.Debug(ex.Message);
}
#endregion
}
else
{

Loading…
Cancel
Save