This commit is contained in:
@@ -40,14 +40,63 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//CREATE (adjustment version)
|
||||
//CREATE (public facing adjustment version)
|
||||
//
|
||||
internal async Task<PartInventory> CreateAsync(dtPartInventory newDtObject, IDbContextTransaction parentTransaction = null)
|
||||
internal async Task<PartInventory> CreateAsync(dtPartInventory newDtObject)
|
||||
{
|
||||
IDbContextTransaction transaction = null;
|
||||
if (parentTransaction == null)
|
||||
transaction = await ct.Database.BeginTransactionAsync();
|
||||
using (var transaction = await ct.Database.BeginTransactionAsync())
|
||||
{
|
||||
try
|
||||
{
|
||||
//get the last record if exists (will not if opening balance)
|
||||
var LastEntry = await ct.PartInventory.OrderByDescending(m => m.EntryDate).FirstOrDefaultAsync(m => m.PartId == newDtObject.PartId && m.PartWarehouseId == newDtObject.PartWarehouseId);
|
||||
PartInventory newObject = new PartInventory();
|
||||
newObject.Description = newDtObject.Description;
|
||||
newObject.EntryDate = DateTime.UtcNow;
|
||||
newObject.PartId = newDtObject.PartId;
|
||||
newObject.PartWarehouseId = newDtObject.PartWarehouseId;
|
||||
newObject.SourceId = null;
|
||||
newObject.SourceType = null;
|
||||
newObject.Quantity = newDtObject.Quantity;
|
||||
|
||||
if (LastEntry != null)
|
||||
{
|
||||
newObject.LastEntryDate = LastEntry.EntryDate;
|
||||
newObject.LastBalance = LastEntry.Balance;
|
||||
newObject.Balance = LastEntry.Balance + newObject.Quantity;
|
||||
}
|
||||
else
|
||||
{
|
||||
newObject.Balance = newObject.Quantity;
|
||||
}
|
||||
|
||||
await ValidateAsync(newObject);
|
||||
if (HasErrors)
|
||||
return null;
|
||||
else
|
||||
{
|
||||
await ct.PartInventory.AddAsync(newObject);
|
||||
await ct.SaveChangesAsync();
|
||||
await transaction.CommitAsync();
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
|
||||
await SearchIndexAsync(newObject, true);
|
||||
return newObject;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Just re-throw for now, let exception handler deal, but in future may want to deal with this more here
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//CREATE (internal version)
|
||||
//
|
||||
internal async Task<PartInventory> CreateAsync(dtPOPartInventory newDtObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
//get the last record if exists (will not if opening balance)
|
||||
@@ -57,8 +106,8 @@ namespace AyaNova.Biz
|
||||
newObject.EntryDate = DateTime.UtcNow;
|
||||
newObject.PartId = newDtObject.PartId;
|
||||
newObject.PartWarehouseId = newDtObject.PartWarehouseId;
|
||||
newObject.SourceId = null;
|
||||
newObject.SourceType = null;
|
||||
newObject.SourceId = newDtObject.SourceId;
|
||||
newObject.SourceType = newDtObject.SourceType;
|
||||
newObject.Quantity = newDtObject.Quantity;
|
||||
|
||||
if (LastEntry != null)
|
||||
@@ -79,9 +128,6 @@ namespace AyaNova.Biz
|
||||
{
|
||||
await ct.PartInventory.AddAsync(newObject);
|
||||
await ct.SaveChangesAsync();
|
||||
//all good do the commit if it's ours
|
||||
if (parentTransaction == null)
|
||||
await transaction.CommitAsync();
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
|
||||
await SearchIndexAsync(newObject, true);
|
||||
return newObject;
|
||||
@@ -96,26 +142,6 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//CREATE (internal version)
|
||||
//
|
||||
internal async Task<PartInventory> CreateAsync(PartInventory newObject)
|
||||
{
|
||||
await ValidateAsync(newObject);
|
||||
if (HasErrors)
|
||||
return null;
|
||||
else
|
||||
{
|
||||
|
||||
await ct.PartInventory.AddAsync(newObject);
|
||||
await ct.SaveChangesAsync();
|
||||
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, newObject.Id, BizType, AyaEvent.Created), ct);
|
||||
await SearchIndexAsync(newObject, true);
|
||||
|
||||
return newObject;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//GET
|
||||
//
|
||||
|
||||
@@ -8,7 +8,7 @@ using Microsoft.Extensions.Logging;
|
||||
using AyaNova.Models;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
|
||||
namespace AyaNova.Biz
|
||||
{
|
||||
@@ -263,7 +263,7 @@ namespace AyaNova.Biz
|
||||
//BIZ ACTIONS
|
||||
//
|
||||
|
||||
private async Task BizActionsAsync(AyaEvent ayaEvent, PurchaseOrder proposedObj, PurchaseOrder currentObj, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction transaction)
|
||||
private async Task BizActionsAsync(AyaEvent ayaEvent, PurchaseOrder proposedObj, PurchaseOrder currentObj, IDbContextTransaction transaction)
|
||||
{
|
||||
//TODO: BIZ ACTIONS TO FIXUP INVENTORY ON CHANGES ETC
|
||||
|
||||
@@ -274,14 +274,24 @@ namespace AyaNova.Biz
|
||||
//if received on woitempartrequest then need to update woitempartrequest (notification separate not a concern here)
|
||||
//if workorderitempartrequest item removed, need to fixup woitempartrequest
|
||||
|
||||
PartInventoryBiz pib = new PartInventoryBiz(ct, UserId, UserTranslationId, CurrentUserRoles);
|
||||
|
||||
switch (ayaEvent)
|
||||
{
|
||||
case AyaEvent.Created:
|
||||
//any received go into inventory
|
||||
var inventoryAffectingItems = proposedObj.Items.Where(z => z.QuantityReceived > 0).ToList();
|
||||
foreach(var poItem in inventoryAffectingItems){
|
||||
foreach (var poItem in inventoryAffectingItems)
|
||||
{
|
||||
//make inventory adjustment here
|
||||
|
||||
dtPOPartInventory i = new dtPOPartInventory();
|
||||
i.PartId = poItem.PartId;
|
||||
i.PartWarehouseId = poItem.PartWarehouseId;
|
||||
i.Quantity = poItem.QuantityReceived;
|
||||
i.SourceType = AyaType.PurchaseOrder;
|
||||
i.SourceId = proposedObj.Id;
|
||||
await pib.CreateAsync(i);
|
||||
|
||||
}
|
||||
break;
|
||||
case AyaEvent.Modified:
|
||||
|
||||
@@ -25,10 +25,10 @@ namespace AyaNova.Models
|
||||
public long PartId { get; set; }
|
||||
[Required]
|
||||
public long PartWarehouseId { get; set; }
|
||||
|
||||
public long? SourceId { get; set; }
|
||||
|
||||
public long? SourceId { get; set; }
|
||||
public AyaType? SourceType { get; set; }
|
||||
|
||||
|
||||
[Required]
|
||||
public decimal Quantity { get; set; }
|
||||
[Required]
|
||||
@@ -39,7 +39,7 @@ namespace AyaNova.Models
|
||||
|
||||
public PartInventory()
|
||||
{
|
||||
EntryDate = DateTime.UtcNow;
|
||||
EntryDate = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace AyaNova.Models
|
||||
public class dtPartInventory
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public uint Concurrency { get; set; }
|
||||
public uint Concurrency { get; set; }//wtf? This is never an update, shouldn't this be not here?
|
||||
|
||||
[Required]
|
||||
public string Description { get; set; }
|
||||
@@ -66,6 +66,27 @@ namespace AyaNova.Models
|
||||
|
||||
}//eoc
|
||||
|
||||
//internal purchase order version
|
||||
public class dtPOPartInventory
|
||||
{
|
||||
public long Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Description { get; set; }
|
||||
|
||||
[Required]
|
||||
public long PartId { get; set; }
|
||||
[Required]
|
||||
public long PartWarehouseId { get; set; }
|
||||
|
||||
[Required]
|
||||
public decimal Quantity { get; set; }
|
||||
|
||||
public long? SourceId { get; set; }
|
||||
public AyaType? SourceType { get; set; }
|
||||
|
||||
}//eoc
|
||||
|
||||
|
||||
}//eons
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user