/********************************************************************************
|
|
** auth: ZH
|
|
** date: 2018/12/26
|
|
** desc: 批分拓展方法
|
|
** Ver.: V1.0.0
|
|
*********************************************************************************/
|
using HH.WMS.Entitys;
|
using HH.WMS.Entitys.Common;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Web;
|
using HH.WMS.BLL;
|
using HH.WMS.Entitys.Entitys;
|
|
namespace HH.WMS.WebApi.Extension
|
{
|
public static class BatchesExtension
|
{
|
#region 批分托盘物料关联主子表,降数量
|
/// <summary>
|
/// 批分托盘物料关联主子表,降数量
|
/// </summary>
|
/// <param name="batchesList"></param>
|
/// <returns></returns>
|
public static List<TN_WM_B_TRAY_ITEM_MSTEntity> BatchesDropTrayItemQty(this List<BatchesEntity> batchesList, bool dropAlloc = true)
|
{
|
var trayItemMstList = BLLCreator.CreateDapper<TN_WM_B_TRAY_ITEM_MSTEntity>().GetList(new
|
{
|
CN_S_TRAY_CODE = batchesList.Select(x => x.TrayCode).ToList(),
|
CN_S_ITEM_CODE = batchesList.Select(x => x.ItemCode).ToList()
|
});
|
foreach (var trayItemMst in trayItemMstList)
|
{
|
trayItemMst.TrayItemDtlList = new List<TN_WM_B_TRAY_ITEM_DTLEntity>();
|
//属于当前托盘,当前物料的分拣明细
|
var currentBatches = batchesList.Where(x => x.ItemCode == trayItemMst.CN_S_ITEM_CODE && x.TrayCode == trayItemMst.CN_S_TRAY_CODE);
|
decimal qty = currentBatches.Sum(y => y.Qty);
|
if (qty == 0) continue;
|
|
bool batches = false;
|
if (dropAlloc)
|
batches = trayItemMst.CN_F_QUANTITY >= qty &&
|
trayItemMst.CN_F_ALLOC_QTY >= qty;
|
else
|
batches = trayItemMst.CN_F_QUANTITY - trayItemMst.CN_F_ALLOC_QTY >= qty;
|
|
if (batches)
|
{
|
trayItemMst.CN_F_QUANTITY -= qty;
|
if (dropAlloc)
|
trayItemMst.CN_F_ALLOC_QTY -= qty;
|
|
trayItemMst.TrayItemDtlList = BLLCreator.CreateDapper<TN_WM_B_TRAY_ITEM_DTLEntity>().GetList(new
|
{
|
CN_PARENT_GUID = trayItemMst.CN_GUID
|
}).OrderBy(x => x.CN_S_LOT_NO).ToList();
|
|
foreach (var cs in currentBatches)
|
{
|
var csQty = cs.Qty;
|
foreach (var trayItemDtl in trayItemMst.TrayItemDtlList)
|
{
|
if (csQty == 0) break;
|
if (trayItemDtl.CN_F_QUANTITY == 0) continue;
|
if ((string.IsNullOrEmpty(cs.ItemProductionLot) || cs.ItemProductionLot.Equals(trayItemDtl.CN_S_PRODUCTION_BATCH)) &&
|
(string.IsNullOrEmpty(cs.ItemArrivalLot) || cs.ItemArrivalLot.Equals(trayItemDtl.CN_S_LOT_NO)))
|
{
|
if (trayItemDtl.CN_F_QUANTITY >= csQty)
|
{
|
trayItemDtl.CN_F_QUANTITY -= csQty;
|
csQty = 0;
|
}
|
else
|
{
|
csQty -= trayItemDtl.CN_F_QUANTITY;
|
trayItemDtl.CN_F_QUANTITY = 0;
|
}
|
}
|
}
|
}
|
}
|
}
|
return trayItemMstList;
|
}
|
#endregion
|
}
|
}
|