Various bug fixs and improvements to stock SKU reconciliation

This commit is contained in:
Bobbie Hodgetts
2020-10-05 22:40:55 +01:00
parent cc2534a3e1
commit ddd2b62743
25 changed files with 1026 additions and 467 deletions

View File

@@ -1,17 +1,16 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Model.Stock
{
public class JournalEntry
public class JournalEntry : IValidatableObject
{
public string TypeTitle { get; set; }
public int StockId { get; set; }
public int StockNumber { get; set; }
public DateTime EntryDate { get; set; }
@@ -21,5 +20,25 @@ namespace bnhtrade.Core.Model.Stock
public DateTime LastModified { get; set; }
public bool IsLocked { get; set; }
public List<JournalEntryPost> JournalPosts { get; set; } = new List<JournalEntryPost>();
public class JournalEntryPost
{
public int JournalPostId { get; set; }
public int StockStatusId { get; set; }
[Required()]
public string StockStatus { get; set; }
[Required()]
public int Quantity { get; set; }
}
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
throw new NotImplementedException();
}
}
}

View File

@@ -1,34 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Model.Stock
{
public class JournalEntryPost : IValidatableObject
{
public int JournalPostId { get; set; }
public int StockStatusId { get; set; }
[Required()]
public string StockStatus { get; set; }
[Required()]
public int Quantity { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
throw new NotImplementedException();
var resultList = new List<ValidationResult>();
if (Quantity == 0)
{
resultList.Add(new ValidationResult("Quantity must be greater than, or less than, zero"));
}
}
}
}

View File

@@ -200,10 +200,10 @@ namespace bnhtrade.Core.Model.Stock
{
result.Add(new ValidationResult("Quantity is not set"));
}
if (!IsSetSkuTransactionId)
{
result.Add(new ValidationResult("Stock Transaction Id is not set"));
}
//if (!IsSetSkuTransactionId)
//{
// result.Add(new ValidationResult("Stock Transaction Id is not set"));
//}
if (IsSetStockJournalId && (!IsSetIsProcessed || IsProcessed == false))
{
result.Add(new ValidationResult("Stock Journal Id is set, IsProcessed must be set to true"));

View File

@@ -0,0 +1,106 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Model.Stock
{
public class StatusBalance
{
public int StockStatusId { get; set; }
public string Sku { get; set; }
public List<ByDate> ByDateList { get; private set; } = new List<ByDate>();
public class ByDate
{
public DateTime EntryDate { get; set; }
public int StockNumber { get; set; }
public int Quantity { get; set; }
}
public void AddBalanceTransaction(DateTime entryDate, int stockNumber, int quantity)
{
if (entryDate == new DateTime())
{
throw new Exception("Entry date set to default value");
}
var item = new ByDate();
item.EntryDate = entryDate;
item.StockNumber = stockNumber;
item.Quantity = quantity;
if (ByDateList == null) { ByDateList = new List<ByDate>(); }
if (ByDateList.Count == 0 || ByDateList.Last().EntryDate <= item.EntryDate)
{
ByDateList.Add(item);
}
else
{
for (int i = 0; i < ByDateList.Count; i++)
{
if (entryDate <= ByDateList[i].EntryDate)
{
i++;
ByDateList.Insert(i, item);
}
}
}
}
public bool CheckAvaliableQuantity(int quantity, DateTime onDateTime)
{
if (GetAvaliableQuantity(onDateTime) < quantity)
{
return false;
}
else
{
return true;
}
}
public int GetAvaliableQuantity()
{
if (!ByDateList.Any())
{
return 0;
}
int qty = 0;
for (int i = 0; i < ByDateList.Count; i++)
{
qty += ByDateList[i].Quantity;
}
return qty;
}
public int GetAvaliableQuantity(DateTime onDateTime)
{
if (!ByDateList.Any())
{
return 0;
}
int qty = 0;
for (int i = 0; i < ByDateList.Count; i++)
{
if (ByDateList[i].EntryDate <= onDateTime)
{
qty += ByDateList[i].Quantity;
}
}
return qty;
}
}
}

View File

@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bnhtrade.Core.Model.Stock
{
public class StatusTransaction
{
public int StockStatusId { get; set; }
public string Sku { get; set; }
public int Balance
{
get
{
if (TransactionList.Any())
{
return TransactionList.Sum(x => x.Quantity);
}
else
{
return 0;
}
}
}
public List<Transaction> TransactionList { get; private set; } = new List<Transaction>();
public class Transaction
{
public DateTime EntryDate { get; set; }
public int StockNumber { get; set; }
public int Quantity { get; set; }
}
public void AddBalanceTransaction(DateTime entryDate, int stockNumber, int quantity)
{
if (entryDate == new DateTime())
{
throw new Exception("Entry date set to default value");
}
var item = new Transaction();
item.EntryDate = entryDate;
item.StockNumber = stockNumber;
item.Quantity = quantity;
if (TransactionList == null) { TransactionList = new List<Transaction>(); }
if (TransactionList.Count == 0 || TransactionList.Last().EntryDate <= item.EntryDate )
{
TransactionList.Add(item);
}
else
{
for (int i = 0; i < TransactionList.Count; i++)
{
if (entryDate <= TransactionList[i].EntryDate)
{
i++;
TransactionList.Insert(i, item);
}
}
}
}
}
}