mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-21 15:27:15 +00:00
Various bug fixs and improvements to stock SKU reconciliation
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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"));
|
||||
|
||||
106
src/bnhtrade.Core/Model/Stock/StatusBalance.cs
Normal file
106
src/bnhtrade.Core/Model/Stock/StatusBalance.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
72
src/bnhtrade.Core/Model/Stock/StatusTransaction.cs
Normal file
72
src/bnhtrade.Core/Model/Stock/StatusTransaction.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user