This commit is contained in:
@@ -4819,35 +4819,42 @@ namespace AyaNova.Biz
|
|||||||
//message = list: part name, -xx (short quantity), no text if possible so no translate needed
|
//message = list: part name, -xx (short quantity), no text if possible so no translate needed
|
||||||
|
|
||||||
//collect the parts on the pm
|
//collect the parts on the pm
|
||||||
List<PMRestockListItem> PartStockRequired = new List<PMRestockListItem>();
|
List<PMRestockListItem> PartsOnPM = new List<PMRestockListItem>();
|
||||||
foreach (PMItem pmi in p.Items)
|
foreach (PMItem pmi in p.Items)
|
||||||
{
|
{
|
||||||
foreach (PMItemPart pmp in pmi.Parts)
|
foreach (PMItemPart pmp in pmi.Parts)
|
||||||
{
|
{
|
||||||
var CurrentInventory = await ct.PartInventory.AsNoTracking().OrderByDescending(m => m.EntryDate).FirstOrDefaultAsync(m => m.PartId == pmp.PartId && m.PartWarehouseId == pmp.PartWarehouseId);
|
if (pmp.Quantity > 0)
|
||||||
if (CurrentInventory.Balance < pmp.Quantity)
|
|
||||||
{
|
{
|
||||||
var i = new PMRestockListItem() { PartId = pmp.PartId, WarehouseId = pmp.PartWarehouseId, QuantityRequired = pmp.Quantity - (decimal)CurrentInventory.Balance };
|
var i = new PMRestockListItem() { PartId = pmp.PartId, WarehouseId = pmp.PartWarehouseId, QuantityRequired = pmp.Quantity };
|
||||||
PartStockRequired.Add(i);
|
PartsOnPM.Add(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PartStockRequired.Count == 0) continue;
|
if (PartsOnPM.Count == 0) continue;
|
||||||
|
|
||||||
//summarize and notify
|
//group parts and whs, summarize totals
|
||||||
var sumList = PartStockRequired.GroupBy(x => new { x.WarehouseId, x.PartId })
|
var SummarizedPartsOnPM = PartsOnPM.GroupBy(x => new { x.WarehouseId, x.PartId })
|
||||||
.OrderBy(g => g.Key.PartId)
|
.OrderBy(g => g.Key.PartId)
|
||||||
.ThenBy(g => g.Key.WarehouseId)
|
.ThenBy(g => g.Key.WarehouseId)
|
||||||
.Select(cl => new PMRestockListItem() { PartId = cl.First().PartId, WarehouseId = cl.First().WarehouseId, QuantityRequired = cl.Sum(c => c.QuantityRequired) });
|
.Select(cl => new PMRestockListItem() { PartId = cl.First().PartId, WarehouseId = cl.First().WarehouseId, QuantityRequired = cl.Sum(c => c.QuantityRequired) });
|
||||||
|
|
||||||
//ok, should have all summarized partid/warehouseid required combos, can now build output
|
//ok, should have all summarized partid/warehouseid required combos, can now build output
|
||||||
System.Text.StringBuilder sb = new System.Text.StringBuilder();
|
System.Text.StringBuilder sb = new System.Text.StringBuilder();
|
||||||
foreach (var i in sumList)
|
foreach (var i in SummarizedPartsOnPM)
|
||||||
{
|
{
|
||||||
var part = await ct.Part.AsNoTracking().Where(x => x.Id == i.PartId).Select(x => x.PartNumber).FirstOrDefaultAsync();
|
//check inventory and add to sb if necessary
|
||||||
var whs = await ct.PartWarehouse.AsNoTracking().Where(x => x.Id == i.WarehouseId).Select(x => x.Name).FirstOrDefaultAsync();
|
var CurrentInventory = await ct.PartInventory.AsNoTracking().OrderByDescending(m => m.EntryDate).FirstOrDefaultAsync(m => m.PartId == i.PartId && m.PartWarehouseId == i.WarehouseId);
|
||||||
sb.AppendLine($"{part} {whs} - {i.QuantityRequired}");
|
decimal dBalance = 0;
|
||||||
|
if (CurrentInventory != null)
|
||||||
|
dBalance = CurrentInventory.Balance;
|
||||||
|
if (dBalance < i.QuantityRequired)
|
||||||
|
{
|
||||||
|
var part = await ct.Part.AsNoTracking().Where(x => x.Id == i.PartId).Select(x => x.PartNumber).FirstOrDefaultAsync();
|
||||||
|
var whs = await ct.PartWarehouse.AsNoTracking().Where(x => x.Id == i.WarehouseId).Select(x => x.Name).FirstOrDefaultAsync();
|
||||||
|
sb.AppendLine($"{part} @ {whs}: {i.QuantityRequired - dBalance}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (sb.Length > 0)
|
if (sb.Length > 0)
|
||||||
{
|
{
|
||||||
@@ -5151,10 +5158,14 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
//not already requested, so check inventory, this is new
|
//not already requested, so check inventory, this is new
|
||||||
var CurrentInventory = await ct.PartInventory.AsNoTracking().OrderByDescending(m => m.EntryDate).FirstOrDefaultAsync(m => m.PartId == pmp.PartId && m.PartWarehouseId == pmp.PartWarehouseId);
|
var CurrentInventory = await ct.PartInventory.AsNoTracking().OrderByDescending(m => m.EntryDate).FirstOrDefaultAsync(m => m.PartId == pmp.PartId && m.PartWarehouseId == pmp.PartWarehouseId);
|
||||||
if (CurrentInventory.Balance < pmp.Quantity)
|
decimal dBalance = 0;
|
||||||
|
if (CurrentInventory != null)//can be null if it has no opening balance for that warehouse yet
|
||||||
|
dBalance = CurrentInventory.Balance;
|
||||||
|
|
||||||
|
if (dBalance < pmp.Quantity)
|
||||||
{
|
{
|
||||||
//we will need a part request here and also need to reserve what there is available
|
//we will need a part request here and also need to reserve what there is available
|
||||||
wipQuantity = (decimal)CurrentInventory.Balance;
|
wipQuantity = dBalance;
|
||||||
requestQuantity = pmp.Quantity - wipQuantity;
|
requestQuantity = pmp.Quantity - wipQuantity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user