mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-19 06:27:15 +00:00
Feature: stock replenishment
This commit is contained in:
@@ -119,5 +119,54 @@ namespace bnhtrade.Core.Data.Database.Stock
|
||||
}
|
||||
return statusBalance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of SKUs avaliable against a specified statusId
|
||||
/// </summary>
|
||||
/// <param name="statusId">The stock status id</param>
|
||||
/// <returns>Dictionary of SKUs and the balance of each</returns>
|
||||
public Dictionary<string, int> ByStatusId(int statusId)
|
||||
{
|
||||
var returnList = new Dictionary<string, int>();
|
||||
|
||||
using (SqlConnection conn = new SqlConnection(SqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
using (SqlCommand cmd = new SqlCommand(@"
|
||||
SELECT sub.*
|
||||
FROM (
|
||||
SELECT tblSku.skuSkuID
|
||||
,tblSku.skuSkuNumber
|
||||
,SUM(tblStockJournalPost.Quantity) AS Balance
|
||||
FROM tblStockJournal
|
||||
INNER JOIN tblStockJournalPost ON tblStockJournal.StockJournalID = tblStockJournalPost.StockJournalID
|
||||
INNER JOIN tblStock ON tblStockJournal.StockID = tblStock.StockID
|
||||
INNER JOIN tblSku ON tblStock.SkuID = tblSku.skuSkuID
|
||||
WHERE (tblStockJournalPost.StockStatusID = @statusId)
|
||||
GROUP BY tblSku.skuSkuID
|
||||
,tblSku.skuSkuNumber
|
||||
) sub
|
||||
WHERE sub.Balance <> 0
|
||||
", conn))
|
||||
{
|
||||
// add parameters
|
||||
cmd.Parameters.AddWithValue("@statusId", statusId);
|
||||
|
||||
// execute
|
||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
string sku = reader.GetString(1);
|
||||
int qty = reader.GetInt32(2);
|
||||
|
||||
returnList.Add(sku, qty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace bnhtrade.Core.Data.Database.Stock
|
||||
|
||||
foreach (var item in dbresults)
|
||||
{
|
||||
result.Sku = item.SkuNumber;
|
||||
result.SkuNumber = item.SkuNumber;
|
||||
result.AddBalanceTransaction(item.EntryDate, item.StockNumber, item.Quantity);
|
||||
}
|
||||
}
|
||||
@@ -125,15 +125,15 @@ namespace bnhtrade.Core.Data.Database.Stock
|
||||
/// Gets list of stock status debits and credits. Includes stock numbers with balance greater than or less than zero.
|
||||
/// </summary>
|
||||
/// <param name="stockStatusId">Required, filters results by stock status Id</param>
|
||||
/// <param name="sku">Required, filters results by sku number</param>
|
||||
/// <param name="skuNumber">Required, filters results by sku number</param>
|
||||
/// <returns>Tuple list is assending order</returns>
|
||||
public Model.Stock.StatusTransaction BySku(int stockStatusId, string sku)
|
||||
public Model.Stock.StatusTransaction BySku(int stockStatusId, string skuNumber)
|
||||
{
|
||||
var result = new Model.Stock.StatusTransaction();
|
||||
result.Sku = sku;
|
||||
result.SkuNumber = skuNumber;
|
||||
result.StockStatusId = stockStatusId;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(sku))
|
||||
if (string.IsNullOrWhiteSpace(skuNumber))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
@@ -176,7 +176,7 @@ namespace bnhtrade.Core.Data.Database.Stock
|
||||
{
|
||||
var param = new Dapper.DynamicParameters();
|
||||
param.Add("@stockStatusId", stockStatusId);
|
||||
param.Add("@sku", sku);
|
||||
param.Add("@sku", skuNumber);
|
||||
|
||||
var dbList = conn.Query(strSQL, param);
|
||||
|
||||
|
||||
115
src/bnhtrade.Core/Data/Database/Stock/Status.cs
Normal file
115
src/bnhtrade.Core/Data/Database/Stock/Status.cs
Normal file
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static bnhtrade.Core.Data.Database.Constants;
|
||||
|
||||
namespace bnhtrade.Core.Data.Database.Stock
|
||||
{
|
||||
internal class Status : Connection
|
||||
{
|
||||
private bnhtrade.Core.Data.Database.SqlWhereBuilder sqlBuilder;
|
||||
|
||||
public List<int> StatusIds { get; set; }
|
||||
|
||||
public List<int> StatusTypeIds { get; set; }
|
||||
|
||||
public Status ()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
sqlBuilder = new SqlWhereBuilder();
|
||||
StatusIds = new List<int>();
|
||||
StatusTypeIds = new List<int>();
|
||||
}
|
||||
|
||||
public List<Model.Stock.Status> Read()
|
||||
{
|
||||
var returnList = new List<Model.Stock.Status>();
|
||||
sqlBuilder.Init();
|
||||
|
||||
//build sql query
|
||||
string sql = @"
|
||||
SELECT [StockStatusID]
|
||||
,[StatusCode]
|
||||
,[StockStatus]
|
||||
,[StockStatusTypeID]
|
||||
,[Reference]
|
||||
,[ForeignKeyID]
|
||||
,[IsCreditOnly]
|
||||
,[IsClosed]
|
||||
,[RecordCreated]
|
||||
FROM [e2A].[dbo].[tblStockStatus]
|
||||
WHERE 1=1 ";
|
||||
|
||||
// build the where statments
|
||||
if (StatusIds.Any())
|
||||
{
|
||||
sqlBuilder.In("StockStatusID", StatusIds, "AND");
|
||||
}
|
||||
if (StatusTypeIds.Any())
|
||||
{
|
||||
sqlBuilder.In("StockStatusTypeID", StatusTypeIds, "AND");
|
||||
}
|
||||
|
||||
// append where string to the sql
|
||||
if (sqlBuilder.IsSetSqlWhereString)
|
||||
{
|
||||
sql = sql + sqlBuilder.SqlWhereString;
|
||||
}
|
||||
|
||||
using (SqlConnection conn = new SqlConnection(SqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
using (SqlCommand cmd = new SqlCommand(sql, conn))
|
||||
{
|
||||
sqlBuilder.AddParametersToSqlCommand(cmd);
|
||||
|
||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
if (reader.HasRows)
|
||||
{
|
||||
var typeDict = new Data.Database.Stock.StatusType().Read();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
int statusId = reader.GetInt32(0);
|
||||
int? statusCode = null;
|
||||
if (!reader.IsDBNull(1)) { statusCode = reader.GetInt32(1); }
|
||||
string stockStatus = reader.GetString(2);
|
||||
int typeId = reader.GetInt32(3);
|
||||
string reference = null;
|
||||
if (!reader.IsDBNull(4)) { reference = reader.GetString(4); }
|
||||
int? foreignKeyId = null;
|
||||
if (!reader.IsDBNull(5)) { foreignKeyId = reader.GetInt32(5); }
|
||||
bool isCreditOnly = reader.GetBoolean(6);
|
||||
bool isClosed = reader.GetBoolean(7);
|
||||
DateTime recordCreated = DateTime.SpecifyKind(reader.GetDateTime(8), DateTimeKind.Utc);
|
||||
|
||||
var newItem = new Model.Stock.Status(statusId
|
||||
, statusCode
|
||||
, stockStatus
|
||||
, typeDict[typeId]
|
||||
, reference
|
||||
, foreignKeyId
|
||||
, isCreditOnly
|
||||
, isClosed
|
||||
, recordCreated
|
||||
);
|
||||
|
||||
returnList.Add(newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
}
|
||||
}
|
||||
63
src/bnhtrade.Core/Data/Database/Stock/StatusType.cs
Normal file
63
src/bnhtrade.Core/Data/Database/Stock/StatusType.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace bnhtrade.Core.Data.Database.Stock
|
||||
{
|
||||
public class StatusType : Connection
|
||||
{
|
||||
public StatusType()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads all Status Types from database
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Dictionary<int, Model.Stock.StatusType> Read()
|
||||
{
|
||||
var returnDict = new Dictionary<int, Model.Stock.StatusType>();
|
||||
|
||||
// get all account info before we start
|
||||
var accountDict = new Data.Database.Account.ReadAccountCode().All();
|
||||
|
||||
using (SqlConnection conn = new SqlConnection(SqlConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
using (SqlCommand cmd = new SqlCommand(@"
|
||||
SELECT [StockStatusTypeID]
|
||||
,[StatusTypeName]
|
||||
,[ForeignKeyType]
|
||||
,[ReferenceType]
|
||||
,[AccountChartOfID]
|
||||
FROM [e2A].[dbo].[tblStockStatusType]
|
||||
", conn))
|
||||
{
|
||||
using (SqlDataReader reader = cmd.ExecuteReader())
|
||||
{
|
||||
var accountIdDict = new Dictionary<int, int>();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
int statusTypeId = reader.GetInt32(0);
|
||||
string name = reader.GetString(1);
|
||||
string foreignKey = null;
|
||||
if (!reader.IsDBNull(2)) { foreignKey = reader.GetString(2); }
|
||||
string reference = null;
|
||||
if (!reader.IsDBNull(3)) { reference = reader.GetString(3); }
|
||||
uint accountId = (uint)reader.GetInt32(4);
|
||||
|
||||
var statusType = new Model.Stock.StatusType(statusTypeId, name, foreignKey, reference, accountDict[accountId]);
|
||||
returnDict.Add(statusTypeId, statusType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnDict;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user