Fix: Update settlements was broken and would remove the Amount and Roundoff settlements
Chore: SalesAnalysis report refactored
This commit is contained in:
@ -401,7 +401,6 @@ namespace Tanshu.Accounts.PointOfSale
|
|||||||
return;
|
return;
|
||||||
IDictionary<SettleOption, decimal> options;
|
IDictionary<SettleOption, decimal> options;
|
||||||
var amount = -1 * _billInfo.Kots.Sum(x => x.Inventories.Sum(y => y.Amount));
|
var amount = -1 * _billInfo.Kots.Sum(x => x.Inventories.Sum(y => y.Amount));
|
||||||
VoucherSettlementBI.UpdateSettlements(_billInfo.Settlements, amount);
|
|
||||||
using (var frm = new SettleChoicesForm(Math.Round(amount) * -1, _billInfo.VoucherType))
|
using (var frm = new SettleChoicesForm(Math.Round(amount) * -1, _billInfo.VoucherType))
|
||||||
{
|
{
|
||||||
frm.ShowDialog();
|
frm.ShowDialog();
|
||||||
|
|||||||
@ -26,7 +26,7 @@ namespace Tanshu.Accounts.PointOfSale
|
|||||||
if (_loading) return;
|
if (_loading) return;
|
||||||
if (DateTime.Today.Subtract(dtpStart.Value.Date).Days > 5 && !Session.IsAllowed("Accounts Audit"))
|
if (DateTime.Today.Subtract(dtpStart.Value.Date).Days > 5 && !Session.IsAllowed("Accounts Audit"))
|
||||||
return;
|
return;
|
||||||
_list = new SalesAnalysisBI().GetBillDetails(dtpStart.Value, dtpFinish.Value);
|
_list = new ReportsBI().GetBillDetails(dtpStart.Value, dtpFinish.Value);
|
||||||
dgvSale.AutoGenerateColumns = true;
|
dgvSale.AutoGenerateColumns = true;
|
||||||
dgvSale.DataSource = _list;
|
dgvSale.DataSource = _list;
|
||||||
dgvSale.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
|
dgvSale.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
|
||||||
|
|||||||
@ -23,7 +23,7 @@ namespace Tanshu.Accounts.PointOfSale
|
|||||||
{
|
{
|
||||||
if (DateTime.Today.Subtract(dtpStart.Value.Date).Days > 5 && !Session.IsAllowed("Accounts Audit"))
|
if (DateTime.Today.Subtract(dtpStart.Value.Date).Days > 5 && !Session.IsAllowed("Accounts Audit"))
|
||||||
return;
|
return;
|
||||||
_list = new SalesAnalysisBI().DiscountReport(dtpStart.Value, dtpFinish.Value);
|
_list = new ReportsBI().DiscountReport(dtpStart.Value, dtpFinish.Value);
|
||||||
dgvSale.AutoGenerateColumns = true;
|
dgvSale.AutoGenerateColumns = true;
|
||||||
dgvSale.DataSource = _list;
|
dgvSale.DataSource = _list;
|
||||||
dgvSale.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
|
dgvSale.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
|
||||||
|
|||||||
@ -41,7 +41,7 @@ namespace Tanshu.Accounts.PointOfSale
|
|||||||
!Session.IsAllowed("Accounts Audit"))
|
!Session.IsAllowed("Accounts Audit"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_list = new SalesAnalysisBI().GetSale(dtpStart.Value, dtpFinish.Value);
|
_list = new SalesAnalysisBI().GetSaleAnalysis(dtpStart.Value, dtpFinish.Value);
|
||||||
|
|
||||||
dgvSale.AutoGenerateColumns = true;
|
dgvSale.AutoGenerateColumns = true;
|
||||||
dgvSale.DataSource = _list;
|
dgvSale.DataSource = _list;
|
||||||
|
|||||||
@ -23,7 +23,7 @@ namespace Tanshu.Accounts.PointOfSale
|
|||||||
{
|
{
|
||||||
if (DateTime.Today.Subtract(dtpStart.Value.Date).Days > 5 && !Session.IsAllowed("Accounts Audit"))
|
if (DateTime.Today.Subtract(dtpStart.Value.Date).Days > 5 && !Session.IsAllowed("Accounts Audit"))
|
||||||
return;
|
return;
|
||||||
_list = new SalesAnalysisBI().GetSaleDetail(dtpStart.Value, dtpFinish.Value);
|
_list = new ReportsBI().GetSaleDetail(dtpStart.Value, dtpFinish.Value);
|
||||||
dgvSale.AutoGenerateColumns = true;
|
dgvSale.AutoGenerateColumns = true;
|
||||||
dgvSale.DataSource = _list;
|
dgvSale.DataSource = _list;
|
||||||
dgvSale.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
|
dgvSale.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
|
||||||
|
|||||||
@ -43,6 +43,9 @@
|
|||||||
this.dgvSale.AllowUserToAddRows = false;
|
this.dgvSale.AllowUserToAddRows = false;
|
||||||
this.dgvSale.AllowUserToDeleteRows = false;
|
this.dgvSale.AllowUserToDeleteRows = false;
|
||||||
this.dgvSale.AllowUserToResizeRows = false;
|
this.dgvSale.AllowUserToResizeRows = false;
|
||||||
|
this.dgvSale.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||||
|
| System.Windows.Forms.AnchorStyles.Left)
|
||||||
|
| System.Windows.Forms.AnchorStyles.Right)));
|
||||||
this.dgvSale.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
this.dgvSale.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
this.dgvSale.Location = new System.Drawing.Point(12, 41);
|
this.dgvSale.Location = new System.Drawing.Point(12, 41);
|
||||||
this.dgvSale.MultiSelect = false;
|
this.dgvSale.MultiSelect = false;
|
||||||
|
|||||||
@ -24,7 +24,7 @@ namespace Tanshu.Accounts.PointOfSale
|
|||||||
{
|
{
|
||||||
if (DateTime.Today.Subtract(dtpStart.Value.Date).Days > 5 && !Session.IsAllowed("Accounts Audit"))
|
if (DateTime.Today.Subtract(dtpStart.Value.Date).Days > 5 && !Session.IsAllowed("Accounts Audit"))
|
||||||
return;
|
return;
|
||||||
_list = new SalesAnalysisBI().VoidOrReprintedBillsList(dtpStart.Value, dtpFinish.Value);
|
_list = new ReportsBI().VoidOrReprintedBillsList(dtpStart.Value, dtpFinish.Value);
|
||||||
dgvSale.AutoGenerateColumns = true;
|
dgvSale.AutoGenerateColumns = true;
|
||||||
dgvSale.DataSource = _list;
|
dgvSale.DataSource = _list;
|
||||||
dgvSale.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
|
dgvSale.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
|
||||||
|
|||||||
@ -157,7 +157,7 @@ order by v.Date desc
|
|||||||
}
|
}
|
||||||
|
|
||||||
query = @"
|
query = @"
|
||||||
select isnull(v.BillID + 1, 1)
|
select coalesce(v.BillID + 1, 1)
|
||||||
from Voucher v
|
from Voucher v
|
||||||
where v.Date < :startDate and v.Void = false and v.VoucherType = :nc
|
where v.Date < :startDate and v.Void = false and v.VoucherType = :nc
|
||||||
order by v.Date desc
|
order by v.Date desc
|
||||||
|
|||||||
234
Tanshu.Accounts.Repository/ReportsBI.cs
Normal file
234
Tanshu.Accounts.Repository/ReportsBI.cs
Normal file
@ -0,0 +1,234 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Tanshu.Accounts.Contracts;
|
||||||
|
using Tanshu.Accounts.Entities;
|
||||||
|
using Tanshu.Common;
|
||||||
|
using Tanshu.Common.Helpers;
|
||||||
|
using System.Linq;
|
||||||
|
using NHibernate.Transform;
|
||||||
|
using NHibernate.Criterion;
|
||||||
|
|
||||||
|
namespace Tanshu.Accounts.Repository
|
||||||
|
{
|
||||||
|
public class ReportsBI
|
||||||
|
{
|
||||||
|
public IList<SalesAnalysisDetail> GetSaleDetail(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)
|
||||||
|
{
|
||||||
|
#region Sale
|
||||||
|
var 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
|
||||||
|
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)
|
||||||
|
";
|
||||||
|
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>();
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public IList<BillDetail> GetBillDetails(DateTime startDate, DateTime finishDate)
|
||||||
|
{
|
||||||
|
startDate = startDate.Date.AddHours(6);
|
||||||
|
finishDate = finishDate.Date.AddDays(1).AddHours(5);
|
||||||
|
if (finishDate <= startDate)
|
||||||
|
return new List<BillDetail>();
|
||||||
|
using (var session = SessionManager.Session)
|
||||||
|
{
|
||||||
|
Voucher vAlias = null;
|
||||||
|
VoucherSettlement vsAlias = null;
|
||||||
|
|
||||||
|
var list = session.QueryOver<Voucher>(() => vAlias)
|
||||||
|
.Left.JoinAlias(x => x.Settlements, () => vsAlias)
|
||||||
|
.Where(x => x.Date >= startDate && x.Date <= finishDate)
|
||||||
|
.OrderBy(x => x.VoucherType).Asc
|
||||||
|
.ThenBy(x => x.BillID).Asc
|
||||||
|
.TransformUsing(Transformers.DistinctRootEntity)
|
||||||
|
.List();
|
||||||
|
|
||||||
|
var outList = new List<BillDetail>();
|
||||||
|
foreach (var item in list)
|
||||||
|
{
|
||||||
|
if (item.Void)
|
||||||
|
outList.Add(new BillDetail()
|
||||||
|
{
|
||||||
|
Date = item.Date,
|
||||||
|
BillID = item.FullBillID,
|
||||||
|
Settlement = string.Format("Void: {0}", item.VoidReason),
|
||||||
|
Amount = Math.Round(item.Settlements.Single(x => x.Settled == SettleOption.Amount).Amount * -1, 2)
|
||||||
|
});
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (var so in item.Settlements.Where(x => x.Settled.Visible()))
|
||||||
|
{
|
||||||
|
outList.Add(new BillDetail()
|
||||||
|
{
|
||||||
|
Date = item.Date,
|
||||||
|
BillID = item.FullBillID,
|
||||||
|
Settlement = so.Settled.Display(),
|
||||||
|
Amount = Math.Round(so.Amount, 2)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return outList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public IList<SalesAnalysis> DiscountReport(DateTime startDate, DateTime finishDate)
|
||||||
|
{
|
||||||
|
startDate = startDate.Date.AddHours(6);
|
||||||
|
finishDate = finishDate.Date.AddDays(1).AddHours(5);
|
||||||
|
if (finishDate <= startDate)
|
||||||
|
return new List<SalesAnalysis>();
|
||||||
|
using (var session = SessionManager.Session)
|
||||||
|
{
|
||||||
|
const string query = @"
|
||||||
|
select pg.GroupType, sum(i.Quantity * i.Price * i.Discount)
|
||||||
|
from Inventory i
|
||||||
|
inner join i.Kot k
|
||||||
|
inner join k.Voucher v
|
||||||
|
inner join i.Product p
|
||||||
|
inner join p.ProductGroup pg
|
||||||
|
where v.Date >= :startDate and v.Date <= :finishDate and i.Discount != 0
|
||||||
|
and v not in (select Voucher from VoucherSettlement vs where vs.Voucher = v and (vs.Settled = :noCharge or vs.Settled = :staff))
|
||||||
|
group by pg.GroupType
|
||||||
|
order by pg.GroupType
|
||||||
|
";
|
||||||
|
var list = session
|
||||||
|
.CreateQuery(query)
|
||||||
|
.SetParameter("startDate", startDate)
|
||||||
|
.SetParameter("finishDate", finishDate)
|
||||||
|
.SetParameter("noCharge", SettleOption.NoCharge)
|
||||||
|
.SetParameter("staff", SettleOption.Staff)
|
||||||
|
.List<object[]>();
|
||||||
|
return list.Select(item => new SalesAnalysis()
|
||||||
|
{
|
||||||
|
GroupType = (string)item[0],
|
||||||
|
Amount = (decimal)item[1]
|
||||||
|
}).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public IList<BillDetail> VoidOrReprintedBillsList(DateTime startDate, DateTime finishDate)
|
||||||
|
{
|
||||||
|
startDate = startDate.Date.AddHours(6);
|
||||||
|
finishDate = finishDate.Date.AddDays(1).AddHours(5);
|
||||||
|
if (finishDate <= startDate)
|
||||||
|
return new List<BillDetail>();
|
||||||
|
using (var session = SessionManager.Session)
|
||||||
|
{
|
||||||
|
Voucher vAlias = null;
|
||||||
|
VoucherSettlement vsAlias = null;
|
||||||
|
ICriterion amount = Restrictions.Where<VoucherSettlement>(x => x.Settled == SettleOption.Amount);
|
||||||
|
|
||||||
|
var listVoids = session.QueryOver<Voucher>(() => vAlias)
|
||||||
|
.Left.JoinAlias(x => x.Settlements, () => vsAlias, amount)
|
||||||
|
.Where(x => x.Date >= startDate && x.Date <= finishDate && x.Void == true)
|
||||||
|
.OrderBy(x => x.VoucherType).Asc
|
||||||
|
.ThenBy(x => x.BillID).Asc
|
||||||
|
.TransformUsing(Transformers.DistinctRootEntity)
|
||||||
|
.List();
|
||||||
|
|
||||||
|
var outList = new List<BillDetail>();
|
||||||
|
foreach (var item in listVoids)
|
||||||
|
{
|
||||||
|
outList.Add(new BillDetail()
|
||||||
|
{
|
||||||
|
Date = item.Date,
|
||||||
|
BillID = item.FullBillID,
|
||||||
|
Settlement = string.Format("Void: {0}", item.VoidReason),
|
||||||
|
Amount = Math.Round(item.Settlements.SingleOrDefault().Amount * -1, 2)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
var listReprint = session.QueryOver<Reprint>()
|
||||||
|
.Where(x => x.Date >= startDate && x.Date <= finishDate)
|
||||||
|
.List();
|
||||||
|
foreach (var item in listReprint)
|
||||||
|
{
|
||||||
|
outList.Add(new BillDetail()
|
||||||
|
{
|
||||||
|
Date = item.Date,
|
||||||
|
BillID = item.Voucher.FullBillID,
|
||||||
|
Settlement = string.Format("Reprinted by {0}", item.User.Name),
|
||||||
|
Amount = item.Voucher.Settlements.Single(x => x.Settled == SettleOption.Amount).Amount * -1
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return outList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,105 +7,39 @@ using Tanshu.Common.Helpers;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NHibernate.Transform;
|
using NHibernate.Transform;
|
||||||
using NHibernate.Criterion;
|
using NHibernate.Criterion;
|
||||||
|
using NHibernate;
|
||||||
|
|
||||||
namespace Tanshu.Accounts.Repository
|
namespace Tanshu.Accounts.Repository
|
||||||
{
|
{
|
||||||
public class SalesAnalysisBI
|
public class SalesAnalysisBI
|
||||||
{
|
{
|
||||||
public IList<SalesAnalysisDetail> GetSaleDetail(DateTime startDate, DateTime finishDate)
|
protected readonly ISession _session;
|
||||||
|
public SalesAnalysisBI()
|
||||||
{
|
{
|
||||||
startDate = startDate.Date.AddHours(6);
|
_session = SessionManager.Session;
|
||||||
finishDate = finishDate.Date.AddDays(1).AddHours(5);
|
}
|
||||||
if (finishDate <= startDate)
|
|
||||||
return new List<SalesAnalysisDetail>();
|
|
||||||
|
|
||||||
using (var session = SessionManager.Session)
|
public IList<SalesAnalysis> GetSaleAnalysis(DateTime startDate, DateTime finishDate)
|
||||||
{
|
{
|
||||||
#region Sale
|
var start = startDate.Date.AddHours(6);
|
||||||
var query = @"
|
var finish = finishDate.Date.AddDays(1).AddHours(5);
|
||||||
select concat(p.Name, ' ', p.Units) as Product, Sum(i.Quantity) as Amount
|
List<SalesAnalysis> list = new List<SalesAnalysis>();
|
||||||
from Voucher v
|
if (finish <= start)
|
||||||
inner join v.Kots k
|
return list;
|
||||||
inner join k.Inventories i
|
list.AddRange(GetSale(start, finish));
|
||||||
inner join i.Product p
|
list.Add(new SalesAnalysis() { GroupType = " -- ", Amount = 0 });
|
||||||
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false
|
list.AddRange(GetSettlements(start, finish));
|
||||||
and exists (select Voucher from VoucherSettlement vs where vs.Voucher = v
|
list.Add(new SalesAnalysis() { GroupType = " -- ", Amount = 0 });
|
||||||
and vs.Settled != :noCharge and vs.Settled != :unsettled and vs.Settled != :amount and vs.Settled != :roundoff and vs.Settled != :staff)
|
var sc = GetServiceCharge(start, finish);
|
||||||
group by concat(p.Name, ' ', p.Units), p.ProductGroup
|
if (sc != null)
|
||||||
order by p.ProductGroup, concat(p.Name, ' ', p.Units)
|
list.Add(sc);
|
||||||
";
|
var st = GetServiceTax(start, finish);
|
||||||
var list = session
|
if (st != null)
|
||||||
.CreateQuery(query)
|
list.Add(st);
|
||||||
.SetParameter("startDate", startDate)
|
list.AddRange(GetVat(start, finish));
|
||||||
.SetParameter("finishDate", finishDate)
|
return list;
|
||||||
.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>();
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
private IList<SalesAnalysis> GetSale(DateTime startDate, DateTime finishDate)
|
||||||
public IList<SalesAnalysis> GetSale(DateTime startDate, DateTime finishDate)
|
|
||||||
{
|
|
||||||
startDate = startDate.Date.AddHours(6);
|
|
||||||
finishDate = finishDate.Date.AddDays(1).AddHours(5);
|
|
||||||
if (finishDate <= startDate)
|
|
||||||
return new List<SalesAnalysis>();
|
|
||||||
using (var session = SessionManager.Session)
|
|
||||||
{
|
{
|
||||||
const string query = @"
|
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.Price * (1 - i.Discount)) as Amount
|
||||||
@ -120,7 +54,7 @@ and vs.Settled != :noCharge and vs.Settled != :unsettled and vs.Settled != :amou
|
|||||||
group by g.GroupType
|
group by g.GroupType
|
||||||
order by g.GroupType
|
order by g.GroupType
|
||||||
";
|
";
|
||||||
var list = session
|
var list = _session
|
||||||
.CreateQuery(query)
|
.CreateQuery(query)
|
||||||
.SetParameter("startDate", startDate)
|
.SetParameter("startDate", startDate)
|
||||||
.SetParameter("finishDate", finishDate)
|
.SetParameter("finishDate", finishDate)
|
||||||
@ -138,146 +72,9 @@ order by g.GroupType
|
|||||||
outList.Add(new SalesAnalysis() { GroupType = (string)item[0], Amount = (decimal)item[1] });
|
outList.Add(new SalesAnalysis() { GroupType = (string)item[0], Amount = (decimal)item[1] });
|
||||||
}
|
}
|
||||||
outList.Add(new SalesAnalysis() { GroupType = "Total Settled", Amount = amount });
|
outList.Add(new SalesAnalysis() { GroupType = "Total Settled", Amount = amount });
|
||||||
return GetSettlement(outList, startDate, finishDate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public IList<BillDetail> GetBillDetails(DateTime startDate, DateTime finishDate)
|
|
||||||
{
|
|
||||||
startDate = startDate.Date.AddHours(6);
|
|
||||||
finishDate = finishDate.Date.AddDays(1).AddHours(5);
|
|
||||||
if (finishDate <= startDate)
|
|
||||||
return new List<BillDetail>();
|
|
||||||
using (var session = SessionManager.Session)
|
|
||||||
{
|
|
||||||
Voucher vAlias = null;
|
|
||||||
VoucherSettlement vsAlias = null;
|
|
||||||
|
|
||||||
var list = session.QueryOver<Voucher>(() => vAlias)
|
|
||||||
.Left.JoinAlias(x => x.Settlements, () => vsAlias)
|
|
||||||
.Where(x => x.Date >= startDate && x.Date <= finishDate)
|
|
||||||
.OrderBy(x => x.VoucherType).Asc
|
|
||||||
.ThenBy(x => x.BillID).Asc
|
|
||||||
.TransformUsing(Transformers.DistinctRootEntity)
|
|
||||||
.List();
|
|
||||||
|
|
||||||
var outList = new List<BillDetail>();
|
|
||||||
foreach (var item in list)
|
|
||||||
{
|
|
||||||
if (item.Void)
|
|
||||||
outList.Add(new BillDetail()
|
|
||||||
{
|
|
||||||
Date = item.Date,
|
|
||||||
BillID = item.FullBillID,
|
|
||||||
Settlement = string.Format("Void: {0}", item.VoidReason),
|
|
||||||
Amount = Math.Round(item.Settlements.Single(x => x.Settled == SettleOption.Amount).Amount * -1, 2)
|
|
||||||
});
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach (var so in item.Settlements.Where(x => x.Settled.Visible()))
|
|
||||||
{
|
|
||||||
outList.Add(new BillDetail()
|
|
||||||
{
|
|
||||||
Date = item.Date,
|
|
||||||
BillID = item.FullBillID,
|
|
||||||
Settlement = so.Settled.Display(),
|
|
||||||
Amount = Math.Round(so.Amount, 2)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return outList;
|
return outList;
|
||||||
}
|
}
|
||||||
}
|
private IList<SalesAnalysis> GetSettlements(DateTime startDate, DateTime finishDate)
|
||||||
public IList<SalesAnalysis> DiscountReport(DateTime startDate, DateTime finishDate)
|
|
||||||
{
|
|
||||||
startDate = startDate.Date.AddHours(6);
|
|
||||||
finishDate = finishDate.Date.AddDays(1).AddHours(5);
|
|
||||||
if (finishDate <= startDate)
|
|
||||||
return new List<SalesAnalysis>();
|
|
||||||
using (var session = SessionManager.Session)
|
|
||||||
{
|
|
||||||
const string query = @"
|
|
||||||
select pg.GroupType, sum(i.Quantity * i.Price * i.Discount)
|
|
||||||
from Inventory i
|
|
||||||
inner join i.Kot k
|
|
||||||
inner join k.Voucher v
|
|
||||||
inner join i.Product p
|
|
||||||
inner join p.ProductGroup pg
|
|
||||||
where v.Date >= :startDate and v.Date <= :finishDate and i.Discount != 0
|
|
||||||
and v not in (select Voucher from VoucherSettlement vs where vs.Voucher = v and (vs.Settled = :noCharge or vs.Settled = :staff))
|
|
||||||
group by pg.GroupType
|
|
||||||
order by pg.GroupType
|
|
||||||
";
|
|
||||||
var list = session
|
|
||||||
.CreateQuery(query)
|
|
||||||
.SetParameter("startDate", startDate)
|
|
||||||
.SetParameter("finishDate", finishDate)
|
|
||||||
.SetParameter("noCharge", SettleOption.NoCharge)
|
|
||||||
.SetParameter("staff", SettleOption.Staff)
|
|
||||||
.List<object[]>();
|
|
||||||
return list.Select(item => new SalesAnalysis()
|
|
||||||
{
|
|
||||||
GroupType = (string)item[0],
|
|
||||||
Amount = (decimal)item[1]
|
|
||||||
}).ToList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public IList<BillDetail> VoidOrReprintedBillsList(DateTime startDate, DateTime finishDate)
|
|
||||||
{
|
|
||||||
startDate = startDate.Date.AddHours(6);
|
|
||||||
finishDate = finishDate.Date.AddDays(1).AddHours(5);
|
|
||||||
if (finishDate <= startDate)
|
|
||||||
return new List<BillDetail>();
|
|
||||||
using (var session = SessionManager.Session)
|
|
||||||
{
|
|
||||||
Voucher vAlias = null;
|
|
||||||
VoucherSettlement vsAlias = null;
|
|
||||||
ICriterion amount = Restrictions.Where<VoucherSettlement>(x => x.Settled == SettleOption.Amount);
|
|
||||||
|
|
||||||
var listVoids = session.QueryOver<Voucher>(() => vAlias)
|
|
||||||
.Left.JoinAlias(x => x.Settlements, () => vsAlias, amount)
|
|
||||||
.Where(x => x.Date >= startDate && x.Date <= finishDate && x.Void == true)
|
|
||||||
.OrderBy(x => x.VoucherType).Asc
|
|
||||||
.ThenBy(x => x.BillID).Asc
|
|
||||||
.TransformUsing(Transformers.DistinctRootEntity)
|
|
||||||
.List();
|
|
||||||
|
|
||||||
var outList = new List<BillDetail>();
|
|
||||||
foreach (var item in listVoids)
|
|
||||||
{
|
|
||||||
outList.Add(new BillDetail()
|
|
||||||
{
|
|
||||||
Date = item.Date,
|
|
||||||
BillID = item.FullBillID,
|
|
||||||
Settlement = string.Format("Void: {0}", item.VoidReason),
|
|
||||||
Amount = Math.Round(item.Settlements.SingleOrDefault().Amount * -1, 2)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
var listReprint = session.QueryOver<Reprint>()
|
|
||||||
.Where(x => x.Date >= startDate && x.Date <= finishDate)
|
|
||||||
.List();
|
|
||||||
foreach (var item in listReprint)
|
|
||||||
{
|
|
||||||
outList.Add(new BillDetail()
|
|
||||||
{
|
|
||||||
Date = item.Date,
|
|
||||||
BillID = item.Voucher.FullBillID,
|
|
||||||
Settlement = string.Format("Reprinted by {0}", item.User.Name),
|
|
||||||
Amount = item.Voucher.Settlements.Single(x => x.Settled == SettleOption.Amount).Amount * -1
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return outList;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IList<SalesAnalysis> GetSettlement(IList<SalesAnalysis> outList, DateTime startDate, DateTime finishDate)
|
|
||||||
{
|
|
||||||
outList.Add(new SalesAnalysis() { GroupType = " -- ", Amount = 0 });
|
|
||||||
if (finishDate <= startDate)
|
|
||||||
return new List<SalesAnalysis>();
|
|
||||||
using (var session = SessionManager.Session)
|
|
||||||
{
|
{
|
||||||
const string query = @"
|
const string query = @"
|
||||||
select s.Settled, Sum(s.Amount)
|
select s.Settled, Sum(s.Amount)
|
||||||
@ -287,11 +84,12 @@ where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false
|
|||||||
group by s.Settled
|
group by s.Settled
|
||||||
order by s.Settled
|
order by s.Settled
|
||||||
";
|
";
|
||||||
var list = session
|
var list = _session
|
||||||
.CreateQuery(query)
|
.CreateQuery(query)
|
||||||
.SetParameter("startDate", startDate)
|
.SetParameter("startDate", startDate)
|
||||||
.SetParameter("finishDate", finishDate)
|
.SetParameter("finishDate", finishDate)
|
||||||
.List<object[]>();
|
.List<object[]>();
|
||||||
|
var outList = new List<SalesAnalysis>();
|
||||||
decimal amount = 0;
|
decimal amount = 0;
|
||||||
foreach (var item in list)
|
foreach (var item in list)
|
||||||
{
|
{
|
||||||
@ -299,19 +97,12 @@ order by s.Settled
|
|||||||
outList.Add(new SalesAnalysis() { GroupType = ((SettleOption)item[0]).Display(), Amount = (decimal)item[1] });
|
outList.Add(new SalesAnalysis() { GroupType = ((SettleOption)item[0]).Display(), Amount = (decimal)item[1] });
|
||||||
}
|
}
|
||||||
outList.Add(new SalesAnalysis() { GroupType = "Total", Amount = amount });
|
outList.Add(new SalesAnalysis() { GroupType = "Total", Amount = amount });
|
||||||
return GetOtherDetails(outList, startDate, finishDate);
|
return outList;
|
||||||
}
|
}
|
||||||
}
|
private SalesAnalysis GetServiceCharge(DateTime startDate, DateTime finishDate)
|
||||||
private static IList<SalesAnalysis> GetOtherDetails(IList<SalesAnalysis> outList, DateTime startDate, DateTime finishDate)
|
|
||||||
{
|
{
|
||||||
outList.Add(new SalesAnalysis() { GroupType = " -- ", Amount = 0 });
|
|
||||||
if (finishDate <= startDate)
|
|
||||||
return new List<SalesAnalysis>();
|
|
||||||
using (var session = SessionManager.Session)
|
|
||||||
{
|
|
||||||
#region Service Charge
|
|
||||||
var query = @"
|
var query = @"
|
||||||
select Sum(i.Quantity * i.Price * (1 - i.Discount) * i.ServiceCharge)
|
select coalesce(Sum(i.Quantity * i.Price * (1 - i.Discount) * i.ServiceCharge), 0)
|
||||||
from Voucher v
|
from Voucher v
|
||||||
inner join v.Kots k
|
inner join v.Kots k
|
||||||
inner join k.Inventories i
|
inner join k.Inventories i
|
||||||
@ -319,7 +110,7 @@ where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false
|
|||||||
and exists (select Voucher from VoucherSettlement vs where vs.Voucher = v
|
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)
|
and vs.Settled != :noCharge and vs.Settled != :unsettled and vs.Settled != :amount and vs.Settled != :roundoff and vs.Settled != :staff)
|
||||||
";
|
";
|
||||||
var amt = session
|
var amt = _session
|
||||||
.CreateQuery(query)
|
.CreateQuery(query)
|
||||||
.SetParameter("startDate", startDate)
|
.SetParameter("startDate", startDate)
|
||||||
.SetParameter("finishDate", finishDate)
|
.SetParameter("finishDate", finishDate)
|
||||||
@ -328,12 +119,15 @@ and vs.Settled != :noCharge and vs.Settled != :unsettled and vs.Settled != :amou
|
|||||||
.SetParameter("amount", SettleOption.Amount)
|
.SetParameter("amount", SettleOption.Amount)
|
||||||
.SetParameter("roundoff", SettleOption.RoundOff)
|
.SetParameter("roundoff", SettleOption.RoundOff)
|
||||||
.SetParameter("staff", SettleOption.Staff)
|
.SetParameter("staff", SettleOption.Staff)
|
||||||
.UniqueResult() ?? 0M;
|
.UniqueResult<decimal>();
|
||||||
outList.Add(new SalesAnalysis() { GroupType = "Service Charge", Amount = (decimal)amt });
|
if (amt != 0)
|
||||||
#endregion
|
return new SalesAnalysis() { GroupType = "Service Charge", Amount = amt };
|
||||||
#region Service Tax
|
return null;
|
||||||
query = @"
|
}
|
||||||
select Sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.ServiceTaxRate)
|
private SalesAnalysis GetServiceTax(DateTime startDate, DateTime finishDate)
|
||||||
|
{
|
||||||
|
var query = @"
|
||||||
|
select coalesce(Sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.ServiceTaxRate), 0)
|
||||||
from Voucher v
|
from Voucher v
|
||||||
inner join v.Kots k
|
inner join v.Kots k
|
||||||
inner join k.Inventories i
|
inner join k.Inventories i
|
||||||
@ -341,7 +135,7 @@ where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false
|
|||||||
and exists (select Voucher from VoucherSettlement vs where vs.Voucher = v
|
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)
|
and vs.Settled != :noCharge and vs.Settled != :unsettled and vs.Settled != :amount and vs.Settled != :roundoff and vs.Settled != :staff)
|
||||||
";
|
";
|
||||||
amt = session
|
var amt = _session
|
||||||
.CreateQuery(query)
|
.CreateQuery(query)
|
||||||
.SetParameter("startDate", startDate)
|
.SetParameter("startDate", startDate)
|
||||||
.SetParameter("finishDate", finishDate)
|
.SetParameter("finishDate", finishDate)
|
||||||
@ -350,21 +144,26 @@ and vs.Settled != :noCharge and vs.Settled != :unsettled and vs.Settled != :amou
|
|||||||
.SetParameter("amount", SettleOption.Amount)
|
.SetParameter("amount", SettleOption.Amount)
|
||||||
.SetParameter("roundoff", SettleOption.RoundOff)
|
.SetParameter("roundoff", SettleOption.RoundOff)
|
||||||
.SetParameter("staff", SettleOption.Staff)
|
.SetParameter("staff", SettleOption.Staff)
|
||||||
.UniqueResult() ?? 0M;
|
.UniqueResult<decimal>();
|
||||||
outList.Add(new SalesAnalysis() { GroupType = "Service Tax", Amount = (decimal)amt });
|
if (amt != 0)
|
||||||
#endregion
|
return new SalesAnalysis() { GroupType = "Service Tax", Amount = amt };
|
||||||
#region Vat
|
return null;
|
||||||
query = @"
|
}
|
||||||
select i.VatRate, Sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.VatRate)
|
private IList<SalesAnalysis> GetVat(DateTime startDate, DateTime finishDate)
|
||||||
|
{
|
||||||
|
var outList = new List<SalesAnalysis>();
|
||||||
|
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)
|
||||||
from Voucher v
|
from Voucher v
|
||||||
inner join v.Kots k
|
inner join v.Kots k
|
||||||
inner join k.Inventories i
|
inner join k.Inventories i
|
||||||
|
inner join i.Vat va
|
||||||
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false
|
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false
|
||||||
and exists (select Voucher from VoucherSettlement vs where vs.Voucher = v
|
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)
|
and vs.Settled != :noCharge and vs.Settled != :unsettled and vs.Settled != :amount and vs.Settled != :roundoff and vs.Settled != :staff)
|
||||||
group by i.VatRate
|
group by i.VatRate, va.Name
|
||||||
";
|
";
|
||||||
var list = session
|
var list = _session
|
||||||
.CreateQuery(query)
|
.CreateQuery(query)
|
||||||
.SetParameter("startDate", startDate)
|
.SetParameter("startDate", startDate)
|
||||||
.SetParameter("finishDate", finishDate)
|
.SetParameter("finishDate", finishDate)
|
||||||
@ -375,10 +174,9 @@ group by i.VatRate
|
|||||||
.SetParameter("staff", SettleOption.Staff)
|
.SetParameter("staff", SettleOption.Staff)
|
||||||
.List<object[]>();
|
.List<object[]>();
|
||||||
foreach (var item in list)
|
foreach (var item in list)
|
||||||
outList.Add(new SalesAnalysis() { GroupType = string.Format("Tax {0:P}", (decimal)item[0]), Amount = (decimal)item[1] });
|
if ((decimal)item[2] != 0)
|
||||||
#endregion
|
outList.Add(new SalesAnalysis() { GroupType = string.Format("{0} - {1:#.##%}", (string)item[0], (decimal)item[1]), Amount = (decimal)item[2] });
|
||||||
return outList;
|
return outList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -65,6 +65,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="CheckoutBI.cs" />
|
<Compile Include="CheckoutBI.cs" />
|
||||||
<Compile Include="Cache.cs" />
|
<Compile Include="Cache.cs" />
|
||||||
|
<Compile Include="ReportsBI.cs" />
|
||||||
<Compile Include="GroupBI.cs" />
|
<Compile Include="GroupBI.cs" />
|
||||||
<Compile Include="CustomerBI.cs" />
|
<Compile Include="CustomerBI.cs" />
|
||||||
<Compile Include="FoodTableBI.cs" />
|
<Compile Include="FoodTableBI.cs" />
|
||||||
|
|||||||
@ -95,7 +95,7 @@ namespace Tanshu.Accounts.Repository
|
|||||||
foreach (var settlement in voucher.Settlements)
|
foreach (var settlement in voucher.Settlements)
|
||||||
{
|
{
|
||||||
settlement.Voucher = voucher;
|
settlement.Voucher = voucher;
|
||||||
if (settlement.Amount == 0 && settlement.Settled != SettleOption.Amount)
|
if (settlement.Amount == 0)
|
||||||
{
|
{
|
||||||
if (settlement.VoucherSettlementID != Guid.Empty)
|
if (settlement.VoucherSettlementID != Guid.Empty)
|
||||||
_session.Delete(settlement);
|
_session.Delete(settlement);
|
||||||
|
|||||||
@ -37,13 +37,34 @@ namespace Tanshu.Accounts.Repository
|
|||||||
public void SettleVoucher(User user, Guid voucherID, IDictionary<SettleOption, decimal> values)
|
public void SettleVoucher(User user, Guid voucherID, IDictionary<SettleOption, decimal> values)
|
||||||
{
|
{
|
||||||
var voucher = _session.Get<Voucher>(voucherID);
|
var voucher = _session.Get<Voucher>(voucherID);
|
||||||
|
var amount = Math.Round(-1 * voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount)), 5);
|
||||||
|
values.Add(SettleOption.Amount, Math.Round(amount, 5));
|
||||||
|
var roundoff = Math.Round(amount) - amount;
|
||||||
|
if (roundoff != 0)
|
||||||
|
values.Add(SettleOption.RoundOff, roundoff);
|
||||||
|
var unsettled = values.Sum(x => x.Value) * -1;
|
||||||
|
if (unsettled != 0)
|
||||||
|
values.Add(SettleOption.Unsettled, unsettled);
|
||||||
|
|
||||||
|
UpdateOld(voucher, values);
|
||||||
|
AddNew(voucher, values);
|
||||||
|
|
||||||
|
voucher.User = user;
|
||||||
|
_session.Update(voucher);
|
||||||
|
|
||||||
|
var table = _session.QueryOver<FoodTable>()
|
||||||
|
.Where(x => x.FoodTableID == voucher.Table.FoodTableID && x.VoucherID == voucher.VoucherID)
|
||||||
|
.SingleOrDefault();
|
||||||
|
table.VoucherID = null;
|
||||||
|
table.Status = null;
|
||||||
|
_session.Update(table);
|
||||||
|
}
|
||||||
|
private void UpdateOld(Voucher voucher, IDictionary<SettleOption, decimal> values)
|
||||||
|
{
|
||||||
for (var i = voucher.Settlements.Count - 1; i >= 0; i--)
|
for (var i = voucher.Settlements.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
var item = voucher.Settlements[i];
|
var item = voucher.Settlements[i];
|
||||||
if (item.Settled == SettleOption.Amount || item.Settled == SettleOption.RoundOff || item.Settled == SettleOption.Unsettled)
|
if (!values.ContainsKey(item.Settled) || (values[item.Settled] == 0 && item.Settled != SettleOption.Amount))
|
||||||
_session.Update(item);
|
|
||||||
if (!values.ContainsKey(item.Settled))
|
|
||||||
{
|
{
|
||||||
voucher.Settlements.Remove(item);
|
voucher.Settlements.Remove(item);
|
||||||
_session.Delete(item);
|
_session.Delete(item);
|
||||||
@ -52,32 +73,18 @@ namespace Tanshu.Accounts.Repository
|
|||||||
{
|
{
|
||||||
item.Amount = values[item.Settled];
|
item.Amount = values[item.Settled];
|
||||||
_session.Update(item);
|
_session.Update(item);
|
||||||
|
values.Remove(item.Settled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (var item in values)
|
}
|
||||||
|
private void AddNew(Voucher voucher, IDictionary<SettleOption, decimal> values)
|
||||||
{
|
{
|
||||||
if (voucher.Settlements.Count(x => x.Settled == item.Key) == 0)
|
foreach (var item in values)
|
||||||
{
|
{
|
||||||
var set = new VoucherSettlement { Settled = item.Key, Amount = item.Value, Voucher = voucher };
|
var set = new VoucherSettlement { Settled = item.Key, Amount = item.Value, Voucher = voucher };
|
||||||
voucher.Settlements.Add(set);
|
voucher.Settlements.Add(set);
|
||||||
_session.Save(set);
|
_session.Save(set);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
voucher.User = user;
|
|
||||||
_session.Update(voucher);
|
|
||||||
|
|
||||||
if (voucher.Settlements.Count(x => x.Settled == SettleOption.Unsettled) == 0 || voucher.Void)
|
|
||||||
{
|
|
||||||
var table = _session.QueryOver<FoodTable>()
|
|
||||||
.Where(x => x.FoodTableID == voucher.Table.FoodTableID && x.VoucherID == voucher.VoucherID)
|
|
||||||
.SingleOrDefault();
|
|
||||||
if (table != null)
|
|
||||||
{
|
|
||||||
table.VoucherID = null;
|
|
||||||
table.Status = null;
|
|
||||||
_session.Update(table);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user