Refactor: Instead of a concept of Price/FullPrice, happy hour is now a checkbox in the product.
This needed major refactor in all parts dealing with product or inventory.
This commit is contained in:
@ -77,6 +77,33 @@ namespace Tanshu.Accounts.Repository
|
||||
}
|
||||
_productGroups = list;
|
||||
}
|
||||
foreach (var item in _productGroups)
|
||||
{
|
||||
for (var i = item.Products.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (item.Products[i].HasHappyHour)
|
||||
{
|
||||
var product = item.Products[i];
|
||||
product.HasHappyHour = false;
|
||||
item.Products.Insert(i + 1, new Product() {
|
||||
ProductID = product.ProductID,
|
||||
Name = product.FullName,
|
||||
Units = product.Units,
|
||||
ProductGroup = product.ProductGroup,
|
||||
Vat = product.Vat,
|
||||
ServiceTax = product.ServiceTax,
|
||||
ServiceCharge = product.ServiceCharge,
|
||||
IsScTaxable = product.IsScTaxable,
|
||||
Price = product.Price,
|
||||
HasHappyHour = true,
|
||||
IsActive = product.IsActive,
|
||||
IsNotAvailable = product.IsNotAvailable,
|
||||
SortOrder = product.SortOrder,
|
||||
Quantity = product.Quantity
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return _productGroups;
|
||||
}
|
||||
|
||||
@ -29,7 +29,6 @@ namespace Tanshu.Accounts.Repository
|
||||
#endregion
|
||||
protected readonly ISession _session;
|
||||
|
||||
private IDictionary<SettleOption, IList<Voucher>> vList = new Dictionary<SettleOption, IList<Voucher>>();
|
||||
public CheckoutBI(Guid cashier, DateTime startDate, DateTime finishDate)
|
||||
{
|
||||
_session = SessionManager.Session;
|
||||
|
||||
@ -636,9 +636,10 @@ where v.Date >= :startDate and v.Date <= :finishDate and i.VatRate = :vat and v.
|
||||
{
|
||||
get
|
||||
{
|
||||
var effectivePrice = IsHappyHour ? 0 : Price;
|
||||
if (IsScTaxable)
|
||||
return Quantity * Price * (1 - Discount) * (1 + ServiceCharge);
|
||||
return Quantity * Price * (1 - Discount);
|
||||
return Quantity * effectivePrice * (1 - Discount) * (1 + ServiceCharge);
|
||||
return Quantity * effectivePrice * (1 - Discount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class ReportsBI
|
||||
{
|
||||
public IList<SalesAnalysisDetail> GetSaleDetail(DateTime startDate, DateTime finishDate)
|
||||
public IList<SalesAnalysisDetail> SaleQuantity(DateTime startDate, DateTime finishDate)
|
||||
{
|
||||
startDate = startDate.Date.AddHours(6);
|
||||
finishDate = finishDate.Date.AddDays(1).AddHours(5);
|
||||
@ -21,9 +21,8 @@ namespace Tanshu.Accounts.Repository
|
||||
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
#region Sale
|
||||
var query = @"
|
||||
select concat(p.Name, ' ', p.Units) as Product, Sum(i.Quantity) as Amount
|
||||
const string query = @"
|
||||
select p.ProductID, p.FullName, i.IsHappyHour, Sum(i.Quantity)
|
||||
from Voucher v
|
||||
inner join v.Kots k
|
||||
inner join k.Inventories i
|
||||
@ -31,75 +30,56 @@ inner join i.Product p
|
||||
inner join p.ProductGroup pg
|
||||
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false
|
||||
and exists (select Voucher from VoucherSettlement vs where vs.Voucher = v
|
||||
and vs.Settled != :noCharge and vs.Settled != :unsettled and vs.Settled != :amount and vs.Settled != :roundoff and vs.Settled != :staff)
|
||||
group by concat(p.Name, ' ', p.Units), p.ProductGroup, pg.GroupType
|
||||
order by pg.GroupType, p.ProductGroup, concat(p.Name, ' ', p.Units)
|
||||
and vs.Settled in (:cash, :creditCard, :billToCompany, :staff))
|
||||
group by p.ProductID, p.FullName, i.IsHappyHour, p.ProductGroup, pg.GroupType
|
||||
order by pg.GroupType, p.ProductGroup, p.FullName, i.IsHappyHour
|
||||
";
|
||||
var list = session
|
||||
.CreateQuery(query)
|
||||
.SetParameter("startDate", startDate)
|
||||
.SetParameter("finishDate", finishDate)
|
||||
.SetParameter("cash", SettleOption.Cash)
|
||||
.SetParameter("creditCard", SettleOption.CreditCard)
|
||||
.SetParameter("billToCompany", SettleOption.BillToCompany)
|
||||
.SetParameter("staff", SettleOption.Staff)
|
||||
.List<object[]>();
|
||||
var outList = new List<SalesAnalysisDetail>();
|
||||
foreach (var item in list)
|
||||
outList.Add(new SalesAnalysisDetail() { ProductID = (Guid)item[0], Name = (string)item[1], IsHappyHour = (bool)item[2], Sale = (decimal)item[3] });
|
||||
return outList;
|
||||
}
|
||||
}
|
||||
public IList<SalesAnalysisDetail> NcQuantity(DateTime startDate, DateTime finishDate)
|
||||
{
|
||||
startDate = startDate.Date.AddHours(6);
|
||||
finishDate = finishDate.Date.AddDays(1).AddHours(5);
|
||||
if (finishDate <= startDate)
|
||||
return new List<SalesAnalysisDetail>();
|
||||
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
const string query = @"
|
||||
select p.ProductID, p.FullName, i.IsHappyHour, Sum(i.Quantity)
|
||||
from Voucher v
|
||||
inner join v.Kots k
|
||||
inner join k.Inventories i
|
||||
inner join i.Product p
|
||||
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false
|
||||
and exists (select Voucher from VoucherSettlement vs where vs.Voucher = v and vs.Settled = :noCharge)
|
||||
group by p.ProductID, p.FullName, i.IsHappyHour
|
||||
";
|
||||
var list = session
|
||||
.CreateQuery(query)
|
||||
.SetParameter("startDate", startDate)
|
||||
.SetParameter("finishDate", finishDate)
|
||||
.SetParameter("noCharge", SettleOption.NoCharge)
|
||||
.SetParameter("unsettled", SettleOption.Unsettled)
|
||||
.SetParameter("amount", SettleOption.Amount)
|
||||
.SetParameter("roundoff", SettleOption.RoundOff)
|
||||
.SetParameter("staff", SettleOption.Staff)
|
||||
.List<object[]>();
|
||||
var outList = new OrderedDictionary<string, SalesAnalysisDetail>();
|
||||
.List<object[]>(); var outList = new List<SalesAnalysisDetail>();
|
||||
foreach (var item in list)
|
||||
outList.Add((string)item[0], new SalesAnalysisDetail() { Product = (string)item[0], Sale = (decimal)item[1] });
|
||||
#endregion
|
||||
#region NC
|
||||
query = @"
|
||||
select concat(p.Name, ' ', p.Units) as Product, Sum(i.Quantity) as Amount
|
||||
from Voucher v
|
||||
inner join v.Kots k
|
||||
inner join k.Inventories i
|
||||
inner join i.Product p
|
||||
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false
|
||||
and exists (select Voucher from VoucherSettlement vs where vs.Voucher = v and vs.Settled = :noCharge)
|
||||
group by concat(p.Name, ' ', p.Units), p.ProductGroup
|
||||
order by p.ProductGroup, concat(p.Name, ' ', p.Units)
|
||||
";
|
||||
list = session
|
||||
.CreateQuery(query)
|
||||
.SetParameter("startDate", startDate)
|
||||
.SetParameter("finishDate", finishDate)
|
||||
.SetParameter("noCharge", SettleOption.NoCharge)
|
||||
.List<object[]>();
|
||||
foreach (var item in list)
|
||||
if (outList.ContainsKey((string)item[0]))
|
||||
outList[(string)item[0]].NC = (decimal)item[1];
|
||||
else
|
||||
outList.Add((string)item[0], new SalesAnalysisDetail() { Product = (string)item[0], NC = (decimal)item[1] });
|
||||
#endregion
|
||||
#region Staff
|
||||
query = @"
|
||||
select concat(p.Name, ' ', p.Units) as Product, Sum(i.Quantity) as Amount
|
||||
from Voucher v
|
||||
inner join v.Kots k
|
||||
inner join k.Inventories i
|
||||
inner join i.Product p
|
||||
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false
|
||||
and exists (select Voucher from VoucherSettlement vs where vs.Voucher = v and vs.Settled = :staff)
|
||||
group by concat(p.Name, ' ', p.Units), p.ProductGroup
|
||||
order by p.ProductGroup, concat(p.Name, ' ', p.Units)
|
||||
";
|
||||
list = session
|
||||
.CreateQuery(query)
|
||||
.SetParameter("startDate", startDate)
|
||||
.SetParameter("finishDate", finishDate)
|
||||
.SetParameter("staff", SettleOption.Staff)
|
||||
.List<object[]>();
|
||||
foreach (var item in list)
|
||||
if (outList.ContainsKey((string)item[0]))
|
||||
outList[(string)item[0]].Staff = (decimal)item[1];
|
||||
else
|
||||
outList.Add((string)item[0], new SalesAnalysisDetail() { Product = (string)item[0], Staff = (decimal)item[1] });
|
||||
#endregion
|
||||
return outList.Values.ToList();
|
||||
outList.Add(new SalesAnalysisDetail() { ProductID = (Guid)item[0], Name = (string)item[1], IsHappyHour = (bool)item[2], NC = (decimal)item[3] });
|
||||
return outList;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<BillDetail> GetBillDetails(DateTime startDate, DateTime finishDate)
|
||||
{
|
||||
startDate = startDate.Date.AddHours(6);
|
||||
@ -157,7 +137,7 @@ order by p.ProductGroup, concat(p.Name, ' ', p.Units)
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
const string query = @"
|
||||
select pg.GroupType, sum(i.Quantity * i.Price * i.Discount)
|
||||
select pg.GroupType, sum(i.Quantity * i.EffectivePrice * i.Discount)
|
||||
from Inventory i
|
||||
inner join i.Kot k
|
||||
inner join k.Voucher v
|
||||
|
||||
@ -22,7 +22,7 @@ namespace Tanshu.Accounts.Repository
|
||||
public IList<SalesAnalysis> GetSale(DateTime startDate, DateTime finishDate)
|
||||
{
|
||||
const string query = @"
|
||||
select g.GroupType as GroupType, Sum(i.Quantity * i.Price * (1 - i.Discount)) as Amount
|
||||
select g.GroupType as GroupType, Sum(i.Quantity * i.EffectivePrice * (1 - i.Discount)) as Amount
|
||||
from Voucher v
|
||||
inner join v.Kots k
|
||||
inner join k.Inventories i
|
||||
@ -82,7 +82,7 @@ order by s.Settled
|
||||
public SalesAnalysis GetServiceCharge(DateTime startDate, DateTime finishDate)
|
||||
{
|
||||
var query = @"
|
||||
select coalesce(Sum(i.Quantity * i.Price * (1 - i.Discount) * i.ServiceCharge), 0)
|
||||
select coalesce(Sum(i.Quantity * i.EffectivePrice * (1 - i.Discount) * i.ServiceCharge), 0)
|
||||
from Voucher v
|
||||
inner join v.Kots k
|
||||
inner join k.Inventories i
|
||||
@ -108,8 +108,8 @@ and vs.Settled != :noCharge and vs.Settled != :unsettled and vs.Settled != :amou
|
||||
{
|
||||
var outList = new List<TaxAnalysis>();
|
||||
var query = @"
|
||||
select i.ServiceTaxRate, coalesce(Sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.ServiceTaxRate), 0),
|
||||
coalesce(Sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end)), 0)
|
||||
select i.ServiceTaxRate, coalesce(Sum(i.Quantity * i.EffectivePrice * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.ServiceTaxRate), 0),
|
||||
coalesce(Sum(i.Quantity * i.EffectivePrice * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end)), 0)
|
||||
from Voucher v
|
||||
inner join v.Kots k
|
||||
inner join k.Inventories i
|
||||
@ -135,8 +135,8 @@ group by i.ServiceTaxRate";
|
||||
{
|
||||
var outList = new List<TaxAnalysis>();
|
||||
var query = @"
|
||||
select va.Name, i.VatRate, coalesce(Sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.VatRate), 0),
|
||||
coalesce(Sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end)), 0)
|
||||
select va.Name, i.VatRate, coalesce(Sum(i.Quantity * i.EffectivePrice * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.VatRate), 0),
|
||||
coalesce(Sum(i.Quantity * i.EffectivePrice * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end)), 0)
|
||||
from Voucher v
|
||||
inner join v.Kots k
|
||||
inner join k.Inventories i
|
||||
|
||||
Reference in New Issue
Block a user