mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-19 22:47:15 +00:00
wip
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using bnhtrade.Core.Data.Database.UnitOfWork;
|
||||
using bnhtrade.Core.Logic.Account;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -22,9 +23,9 @@ namespace bnhtrade.Core.Logic.Inventory
|
||||
|
||||
return WithUnitOfWork(uow =>
|
||||
{
|
||||
stockJournalEntryDate = uow.AccountJournalRepository.ReadJournalEntryDate(accountJournalId);
|
||||
int result = uow.StockRepository.WIP_StockInsertSub(
|
||||
productId, conditionId, accountTaxCodeId, accountJournalId, stockJournalTypeId, stockJournalEntryDate, quantity, statusDebitId);
|
||||
stockJournalEntryDate = new AccountJournalService(uow).ReadJournalEntryDate(accountJournalId);
|
||||
int result = WIP_StockInsertSub(
|
||||
uow, productId, conditionId, accountTaxCodeId, accountJournalId, stockJournalTypeId, stockJournalEntryDate, quantity, statusDebitId);
|
||||
CommitIfOwned(uow);
|
||||
return result;
|
||||
});
|
||||
@@ -48,15 +49,68 @@ namespace bnhtrade.Core.Logic.Inventory
|
||||
int quantity, int productId, int conditionId, int accountTaxCodeId, DateTime entryDate, int debitStatusId)
|
||||
{
|
||||
// add account journal entry
|
||||
int accountJournalId = new Logic.Account.JournalService(uow).JournalInsert(accountJournalType, entryDate, currencyCode, amount);
|
||||
int accountJournalId = new Logic.Account.AccountJournalService(uow).JournalInsert(accountJournalType, entryDate, currencyCode, amount);
|
||||
|
||||
// make the stock insert
|
||||
int stockId = uow.StockRepository.WIP_StockInsertSub(productId, conditionId, accountTaxCodeId,
|
||||
int stockId = WIP_StockInsertSub(uow, productId, conditionId, accountTaxCodeId,
|
||||
accountJournalId, stockJournalType, entryDate, quantity, debitStatusId);
|
||||
|
||||
return stockId;
|
||||
}
|
||||
|
||||
private int WIP_StockInsertSub(IUnitOfWork uow, int productId, int conditionId, int accountTaxCodeId,
|
||||
int accountJournalId, int stockJournalTypeId, DateTime stockJournalEntryDate, int quantity, int statusDebitId)
|
||||
{
|
||||
stockJournalEntryDate = DateTime.SpecifyKind(stockJournalEntryDate, DateTimeKind.Utc);
|
||||
|
||||
// ensure account journal id hasn't already been added to stock table
|
||||
int count = uow.StockRepository.CountStockTableRecords(new List<int> { accountJournalId });
|
||||
|
||||
if (count == 1)
|
||||
{
|
||||
throw new Exception("Add account journal entry already assigned to stock line.");
|
||||
}
|
||||
else if (count > 1)
|
||||
{
|
||||
throw new Exception("Houston we have a problem! An account journal entry is assigned to " + count + " stock lines.");
|
||||
}
|
||||
|
||||
// ensure the debit for the account journal transaction is to an 'Asset' account type
|
||||
bool isIt = uow.AccountJournalRepository.IsJournalDebitAssetType(accountJournalId);
|
||||
if (!isIt)
|
||||
{
|
||||
throw new Exception("Supplied AccountJournal entry must debit an 'Asset' account type.");
|
||||
}
|
||||
|
||||
// get statusCreditId for stock journal type
|
||||
int? statusCreditId = uow.StockJournalRepository.ReadTypeIdStatusCreditId(stockJournalTypeId);
|
||||
|
||||
if (statusCreditId == null)
|
||||
{
|
||||
throw new Exception("Default credit status not set for StockJournalTypeID=" + stockJournalTypeId);
|
||||
}
|
||||
|
||||
// get/set an skuId
|
||||
int skuId = new Logic.Inventory.SkuService(uow).GetSkuId(productId, conditionId, accountTaxCodeId, true);
|
||||
|
||||
// add the entry to the stock table (minus stockJournalId)
|
||||
int stockId = uow.StockRepository.InsertNewStock(skuId, accountJournalId);
|
||||
|
||||
// insert stock journal entry
|
||||
var journalPosts = new List<(int statusId, int quantity)>();
|
||||
journalPosts.Add((statusDebitId, quantity));
|
||||
journalPosts.Add((statusCreditId.Value, (quantity * -1)));
|
||||
int stockJournalId = uow.StockJournalRepository.StockJournalInsert(stockJournalTypeId, stockId, journalPosts, stockJournalEntryDate, true);
|
||||
|
||||
// update the stock table
|
||||
count = uow.StockRepository.UpdateStockJournalId(stockId, stockJournalId);
|
||||
if (count < 1)
|
||||
{
|
||||
throw new Exception("New stock insert cancelled, failed to update StockJournalID");
|
||||
}
|
||||
|
||||
return stockId;
|
||||
}
|
||||
|
||||
public void WIP_StockDeletePurchase(int stockId)
|
||||
{
|
||||
@@ -162,8 +216,7 @@ namespace bnhtrade.Core.Logic.Inventory
|
||||
}
|
||||
|
||||
// delete account journal entry
|
||||
uow.AccountJournalRepository.DeleteJournal(accountJournalId);
|
||||
new AccountJournalService(uow).DeleteJournal(accountJournalId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user