Browse Source

调整拣料接口,修复bug

master
lilili 2 years ago
parent
commit
fae905ce68
  1. 601
      WMS-BS/NFine.Application/WMS/PickMaterialApp.cs

601
WMS-BS/NFine.Application/WMS/PickMaterialApp.cs

@ -803,81 +803,314 @@ where a.IssueCode='{0}' and a.WorkPoint='{1}'";
public DataTable GetICSMOPickMergeTemp(string ID,string Type)
// public DataTable GetICSMOPickMergeTemp(string ID,string Type)
// {
// string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
// ID = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(',');
// #region sql
// string sql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
// c.Code,
// c.InvCode,
// c.InvName,
// c.InvStd,
// c.InvUnit,
// FLOOR(c.iQuantity) AS iQuantity,
// d.WarehouseCode,
// m.LotNO,
// (case when m.LotNo is null then 0 else FLOOR(ISNULL(d.Quantity, 0)) end) AS QTY,
// (case when m.LotNo is null then null else d.LocationCode end) AS LocationCode,
// CONVERT(varchar(100),d.MTIME, 23) MTIME,
// FLOOR(f.QTYTotal) QTYTotal INTO #temp
// FROM
// ({0}) c
// LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='{1}' AND d.Quantity>0
// left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
// LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{1}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
//DECLARE @ItemCode VARCHAR(50),
// @QTY DECIMAL(18,3),
// @ItemCodeCurrent VARCHAR(50),
// @Lotno VARCHAR(50),
// @QTYCurrent DECIMAL(18,3),
// @iQuantityCurrent DECIMAL(18,3),
// @CanDelete BIT,
// @Row INT,
// @rowCurrent INT
//SET @Row = @@rowcount
//SET @rowCurrent=1
//SET @CanDelete=0
//SET @ItemCode=''
//SET @Lotno = ''
//WHILE @rowCurrent<=@Row
// BEGIN
// SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity,@Lotno = Lotno FROM #temp WHERE rowNo=@rowCurrent
//PRINT(@rowCurrent)
// IF @ItemCode<>@ItemCodeCurrent
// BEGIN
// SET @ItemCode=@ItemCodeCurrent
// SET @QTY=0
// SET @CanDelete=0
// END
// IF @CanDelete=1
// BEGIN
// DELETE FROM #temp WHERE rowNo=@rowCurrent
// SET @rowCurrent += 1
// CONTINUE
// END
// SET @QTY += @QTYCurrent
// IF @LotNo is null or @QTY>=@iQuantityCurrent
// BEGIN
// SET @CanDelete=1
// END
// SET @rowCurrent += 1
// END
//SELECT * FROM #temp
//DROP TABLE #temp
//";
// #endregion
// string sqls = "";
// if (Type=="1")
// {
// #region 工单备料sql
// sqls = @" SELECT
// c.MOCode as Code,
// a.InvCode,
// b.InvName,
// b.InvStd,
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
// a.WhCode,
// b.InvUnit,
// a.ExtensionID
// FROM
// ICSMOPick a
// inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
// WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
// GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
// #endregion
// }
// if (Type == "2")
// {
// return GetICSMOPickMergeByWorkorder(ID, WorkPoint);
// }
// if (Type=="3")
// {
// #region 工单材料出库SQL
// sqls = @" select
// a.IssueCode as Code,
// a.InvCode,
// b.InvName,
// b.InvStd,
// b.InvUnit,
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
// a.WhCode,
// a.ExtensionID
// FROM
// ICSMOIssue a
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
// WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
// GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
// #endregion
// }
// if (Type=="4")
// {
// #region 委外备料SQL
// sqls = @" select
// c.OOCode as Code,
// a.InvCode,
// b.InvName,
// b.InvStd,
// b.InvUnit,
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
// a.WhCode,
// a.ExtensionID
// FROM
// ICSOOPick a
// left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
// WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
// GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
// #endregion
// }
// if (Type=="5")
// {
// #region 委外领料SQL
// sqls = @" select
// a.ApplyCode as Code,
// a.InvCode,
// b.InvName,
// b.InvStd,
//b.InvUnit,
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
// a.WhCode,
// a.ExtensionID
// FROM
// ICSOApply a
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
// WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
// GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
// #endregion
// }
// if (Type=="6")
// {
// #region 委外材料出库SQL
// sqls = @" select
// a.IssueCode as Code,
// a.InvCode,
// b.InvName,
// b.InvStd,
//b.InvUnit,
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
// a.WhCode,
//a.ExtensionID
// FROM
// ICSOIssue a
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
// WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
// GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
// #endregion
// }
// if (Type=="7")
// {
// #region 销售发货SQL
// sqls = @" select
// a.SDNCode as Code,
// a.InvCode,
// b.InvName,
// b.InvStd,
//b.InvUnit,
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
// a.WhCode,
//a.ExtensionID
// FROM
// ICSSDN a
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
// WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
// GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
// #endregion
// }
// if (Type=="8")
// {
// #region 其它出库SQL
// sqls = @" select
// a.OutCode as Code,
// a.InvCode,
// b.InvName,
// b.InvStd,
// b.InvUnit,
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
// a.WhCode,
// a.ExtensionID
// FROM
// ICSOtherOut a
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
// WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
// GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
// #endregion
// }
// if (Type == "9")
// {
// #region 借用SQL
// sqls = @"select
// a.BrrowCode as Code,
// a.InvCode,
// b.InvName,
// b.InvStd,
//b.InvUnit,
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
// a.WhCode,
//a.ExtensionID
// FROM
// ICSBrrow a
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
// WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
// GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
// #endregion
// }
// if (Type == "10")
// {
// #region 物料调拨
// sqls = @" select
// a.TransferNO as Code,
// a.InvCode,
// b.InvName,
// b.InvStd,
//b.InvUnit,
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
// a.FromWarehouseCode as WhCode,
//a.ExtensionID
// FROM
// ICSTransfer a
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
// WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
// GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID";
// #endregion
// }
// if (Type == "11")
// {
// #region 两步调出
// sqls = @"select
// a.OutCode as Code,
// a.InvCode,
// b.InvName,
// b.InvStd,
//b.InvUnit,
// SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
// a.WHCode ,
//a.ExtensionID
// from ICSOtherOut a
// INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
// WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
// GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID";
// #endregion
// }
// sqls = string.Format(sqls, ID,WorkPoint);
// sql = string.Format(sql, sqls, WorkPoint);
// DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
// DataTable dtCloned = table.Clone();
// foreach (DataColumn col in dtCloned.Columns)
// {
// col.DataType = typeof(string);
// }
// foreach (DataRow row in table.Rows)
// {
// DataRow newrow = dtCloned.NewRow();
// foreach (DataColumn column in dtCloned.Columns)
// {
// newrow[column.ColumnName] = row[column.ColumnName].ToString();
// }
// dtCloned.Rows.Add(newrow);
// }
// if (Invmes.Rows.Count > 0)
// {
// dtCloned.Merge(Invmes, false);
// }
// return dtCloned;
// }
public DataTable GetICSMOPickMergeTemp(string ID, string Type)
{
string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
ID = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(',');
#region sql
string sql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
c.Code,
c.InvCode,
c.InvName,
c.InvStd,
c.InvUnit,
FLOOR(c.iQuantity) AS iQuantity,
d.WarehouseCode,
m.LotNO,
(case when m.LotNo is null then 0 else FLOOR(ISNULL(d.Quantity, 0)) end) AS QTY,
(case when m.LotNo is null then null else d.LocationCode end) AS LocationCode,
CONVERT(varchar(100),d.MTIME, 23) MTIME,
FLOOR(f.QTYTotal) QTYTotal INTO #temp
FROM
({0}) c
LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode AND d.WorkPoint='{1}' AND d.Quantity>0
left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{1}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
DECLARE @ItemCode VARCHAR(50),
@QTY DECIMAL(18,3),
@ItemCodeCurrent VARCHAR(50),
@Lotno VARCHAR(50),
@QTYCurrent DECIMAL(18,3),
@iQuantityCurrent DECIMAL(18,3),
@CanDelete BIT,
@Row INT,
@rowCurrent INT
SET @Row = @@rowcount
SET @rowCurrent=1
SET @CanDelete=0
SET @ItemCode=''
SET @Lotno = ''
WHILE @rowCurrent<=@Row
BEGIN
SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity,@Lotno = Lotno FROM #temp WHERE rowNo=@rowCurrent
PRINT(@rowCurrent)
IF @ItemCode<>@ItemCodeCurrent
BEGIN
SET @ItemCode=@ItemCodeCurrent
SET @QTY=0
SET @CanDelete=0
END
IF @CanDelete=1
BEGIN
DELETE FROM #temp WHERE rowNo=@rowCurrent
SET @rowCurrent += 1
CONTINUE
END
SET @QTY += @QTYCurrent
IF @LotNo is null or @QTY>=@iQuantityCurrent
BEGIN
SET @CanDelete=1
END
SET @rowCurrent += 1
END
SELECT * FROM #temp
DROP TABLE #temp
";
#endregion
string sqls = "";
if (Type=="1")
if (Type == "1")
{
#region 工单备料sql
sqls = @" SELECT
sqls = @" SELECT
c.MOCode as Code,
a.InvCode,
b.InvName,
@ -892,28 +1125,13 @@ DROP TABLE #temp
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
#endregion
}
if (Type == "2")
{
#region 工单领料SQL
sqls = @" select
a.ApplyCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
FROM
ICSMOApply a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
return GetICSMOPickMergeByWorkorder(ID, WorkPoint);
}
if (Type=="3")
if (Type == "3")
{
#region 工单材料出库SQL
sqls = @" select
@ -932,7 +1150,7 @@ DROP TABLE #temp
GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (Type=="4")
if (Type == "4")
{
#region 委外备料SQL
sqls = @" select
@ -952,18 +1170,17 @@ DROP TABLE #temp
GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
#endregion
}
if (Type=="5")
if (Type == "5")
{
#region 委外领料SQL
sqls = @" select
sqls = @"select
a.ApplyCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
a.WhCode,a.ExtensionID
FROM
ICSOApply a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
@ -971,7 +1188,7 @@ b.InvUnit,
GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (Type=="6")
if (Type == "6")
{
#region 委外材料出库SQL
sqls = @" select
@ -979,10 +1196,10 @@ b.InvUnit,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
a.ExtensionID
FROM
ICSOIssue a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
@ -990,7 +1207,7 @@ a.ExtensionID
GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (Type=="7")
if (Type == "7")
{
#region 销售发货SQL
sqls = @" select
@ -998,10 +1215,10 @@ a.ExtensionID
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
a.ExtensionID
FROM
ICSSDN a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
@ -1009,7 +1226,7 @@ a.ExtensionID
GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
#endregion
}
if (Type=="8")
if (Type == "8")
{
#region 其它出库SQL
sqls = @" select
@ -1034,13 +1251,12 @@ a.ExtensionID
sqls = @"select
a.BrrowCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WhCode,
a.ExtensionID
a.ExtensionID
FROM
ICSBrrow a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
@ -1051,16 +1267,15 @@ a.ExtensionID
if (Type == "10")
{
#region 物料调拨
sqls = @" select
sqls = @"select
a.TransferNO as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.FromWarehouseCode as WhCode,
a.ExtensionID
a.ExtensionID
FROM
ICSTransfer a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
@ -1074,30 +1289,182 @@ a.ExtensionID
sqls = @"select
a.OutCode as Code,
a.InvCode,
b.InvName,
b.InvStd,
b.InvUnit,
b.InvUnit,
SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
a.WHCode ,
a.ExtensionID
from ICSOtherOut a
a.ExtensionID
from ICSOtherOut a
INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID";
#endregion
}
sqls = string.Format(sqls, ID, WorkPoint);
sqls = string.Format(sqls, string.IsNullOrWhiteSpace(ID)?"''":ID.TrimEnd(','),WorkPoint);
sql = string.Format(sql, sqls, WorkPoint);
DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
DataTable dtCloned = table.Clone();
string sql = $@"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
c.Code,
c.InvCode,
c.InvName,
c.InvStd,
c.InvUnit,
FLOOR(c.iQuantity) AS iQuantity,
d.WarehouseCode,
d.LotNO,
FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
d.LocationCode AS LocationCode,
CONVERT(varchar(100),d.MTIME, 23) MTIME,
FLOOR(f.QTYTotal) QTYTotal
FROM
({sqls}) c
left join (select d.WarehouseCode,d.Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID
from ICSWareHouseLotInfo d ,ICSInventoryLot m
where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
and d.WorkPoint='{WorkPoint}' AND d.Quantity>0 ) d
on c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode and d.ExtensionID=c.ExtensionID
LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='1701' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
order by c.Code,c.InvCode,d.MTIME ";
var dataset = Repository().FindDataSetBySql(sql);
if (dataset.Tables.Count == 0)
return null;
DataTable table = dataset.Tables[0];
decimal qtyCount = 0;
bool remove = false;
List<int> removeList = new List<int>();
for (int i = 0; i < table.Rows.Count; i++)
{
if (i != 0
&& !table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString()))
{
qtyCount = 0;
remove = false;
}
if (remove)
{
removeList.Add(i);
}
else
{
var lotQty = table.Rows[i]["QTY"].ToString().ToDecimal();
var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
qtyCount += lotQty;
if (qtyCount >= orderQty)
{
remove = true;
}
}
}
if (removeList.Count > 0)
{
removeList.Reverse();
foreach (var item in removeList)
{
table.Rows.RemoveAt(item);
}
}
var result = ConvertCellToString(table);
if (Invmes.Rows.Count > 0)
{
result.Merge(Invmes, false);
}
return result;
}
/// <summary>
/// 工单领料推荐
/// </summary>
/// <param name="Id"></param>
/// <param name="workPoint"></param>
/// <returns></returns>
public DataTable GetICSMOPickMergeByWorkorder(string Id,string workPoint)
{
string sql = $@"SELECT row_number() over (partition by c.Code,c.InvCode order by c.Code,c.InvCode,d.MTIME) AS rowNo,
c.Code,
c.InvCode,
c.InvName,
c.InvStd,
c.InvUnit,
FLOOR(c.iQuantity) AS iQuantity,
d.WarehouseCode,
d.LotNO,
FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
d.LocationCode LocationCode,
CONVERT(varchar(100),d.MTIME, 23) MTIME,
FLOOR(f.QTYTotal) QTYTotal
FROM
(select
a.ApplyCode as Code, a.InvCode, b.InvName, b.InvStd, b.InvUnit, SUM(ISNULL(a.Quantity, 0)) AS iQuantity, a.WhCode,a.ExtensionID
FROM
ICSMOApply a
LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
WHERE a.ApplyCode in ({Id}) AND a.WorkPoint = '{workPoint}'
GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID) c
left join (select d.WarehouseCode,d.Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID from ICSWareHouseLotInfo d ,ICSInventoryLot m
where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
and d.WorkPoint='{workPoint}' AND d.Quantity>0 ) d on c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode and d.ExtensionID=c.ExtensionID
LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='1701' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
order by c.Code,c.InvCode,d.MTIME";
var dataset = Repository().FindDataSetBySql(sql);
if (dataset.Tables.Count == 0)
return null;
DataTable table = dataset.Tables[0];
decimal qtyCount = 0;
bool remove = false;
List<int> removeList = new List<int>();
for (int i = 0; i < table.Rows.Count; i++)
{
if(i != 0
&& !table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i-1]["InvCode"].ToString()))
{
qtyCount = 0;
remove = false;
}
if (remove)
{
removeList.Add(i);
}
else
{
var lotQty = table.Rows[i]["QTY"].ToString().ToDecimal();
var orderQty = table.Rows[i]["iQuantity"].ToString().ToDecimal();
qtyCount += lotQty;
if (qtyCount >= orderQty)
{
remove = true;
}
}
}
if(removeList.Count > 0)
{
removeList.Reverse();
foreach (var item in removeList)
{
table.Rows.RemoveAt(item);
}
}
var result = ConvertCellToString(table);
if (Invmes.Rows.Count > 0)
{
result.Merge(Invmes, false);
}
return result;
}
public DataTable ConvertCellToString(DataTable data)
{
DataTable dtCloned = data.Clone();
foreach (DataColumn col in dtCloned.Columns)
{
col.DataType = typeof(string);
}
foreach (DataRow row in table.Rows)
foreach (DataRow row in data.Rows)
{
DataRow newrow = dtCloned.NewRow();
foreach (DataColumn column in dtCloned.Columns)
@ -1107,10 +1474,6 @@ a.ExtensionID
}
dtCloned.Rows.Add(newrow);
}
if (Invmes.Rows.Count > 0)
{
dtCloned.Merge(Invmes, false);
}
return dtCloned;
}

Loading…
Cancel
Save