Added Basecode to Product
Added Voucher Type During Printing Added Discount Report Fixed Void bill table not getting cleared error Added PAX to table Removed Itital Setup button in MainForm as it was not doing anything
This commit is contained in:
28
Tanshu.Accounts.Repository/BusinessLayer/InventoryBI.cs
Normal file
28
Tanshu.Accounts.Repository/BusinessLayer/InventoryBI.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using NHibernate;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class InventoryBI : FluentGenericBase<Inventory>
|
||||
{
|
||||
public InventoryBI()
|
||||
: base()
|
||||
{ }
|
||||
|
||||
public InventoryBI(bool beginTransaction)
|
||||
: base(beginTransaction)
|
||||
{ }
|
||||
|
||||
public InventoryBI(ISession session)
|
||||
: base(session)
|
||||
{ }
|
||||
|
||||
public InventoryBI(ISession session, bool beginTransaction)
|
||||
: base(session, beginTransaction)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@ -1,85 +1,172 @@
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Text;
|
||||
//using System.Data.SqlClient;
|
||||
//using Tanshu.Accounts.Contracts;
|
||||
//using Tanshu.Data.DAO;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Data.SqlClient;
|
||||
using NHibernate;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using Tanshu.Data.DAO;
|
||||
|
||||
//namespace Tanshu.Accounts.Repository
|
||||
//{
|
||||
// public class ManagementBI
|
||||
// {
|
||||
// public decimal GetBalance(decimal? tax, DateTime startDate, DateTime endDate)
|
||||
// {
|
||||
// GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
||||
// using (IConnectionDAO connection = factory.Connection)
|
||||
// {
|
||||
// using (IManagementDAO dao = factory.GetManagementDAO(startDate, endDate, connection))
|
||||
// {
|
||||
// return dao.GetBalance(tax);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// public List<Guid> GetUpdateBillList(decimal tax, bool voided, bool paid, bool creditCard, DateTime startDate, DateTime endDate)
|
||||
// {
|
||||
// GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
||||
// using (IConnectionDAO connection = factory.Connection)
|
||||
// {
|
||||
// using (IManagementDAO dao = factory.GetManagementDAO(startDate, endDate, connection))
|
||||
// {
|
||||
// return dao.GetUpdateBillList(tax, voided, paid, creditCard);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// public decimal Update(Guid voucherID, decimal tax, DateTime startDate, DateTime endDate)
|
||||
// {
|
||||
// GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
||||
// using (IConnectionDAO connection = factory.Connection)
|
||||
// {
|
||||
// using (IManagementDAO dao = factory.GetManagementDAO(startDate, endDate, connection))
|
||||
// {
|
||||
// return dao.Update(voucherID, tax);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// public void Reorder(DateTime startDate, DateTime endDate, ShowProgessDelegate showProgressDelegate)
|
||||
// {
|
||||
// GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
||||
// using (IConnectionDAO connection = factory.Connection)
|
||||
// {
|
||||
// using (IManagementDAO dao = factory.GetManagementDAO(startDate, endDate, connection))
|
||||
// {
|
||||
// dao.Reorder(showProgressDelegate);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// public bool MergeData(DateTime startDate, DateTime endDate, string sourceDB, string targetDB)
|
||||
// {
|
||||
// GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
||||
// using (IConnectionDAO connection = factory.Connection)
|
||||
// {
|
||||
// using (IManagementDAO dao = factory.GetManagementDAO(startDate, endDate, connection))
|
||||
// {
|
||||
// return dao.MergeData(sourceDB, targetDB);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// public List<PendingBills> GetPaidBills(DateTime startDate, DateTime finishDate)
|
||||
// {
|
||||
// GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
||||
// using (IConnectionDAO connection = factory.Connection)
|
||||
// {
|
||||
// using (IManagementDAO dao = factory.GetManagementDAO(startDate, finishDate, connection))
|
||||
// {
|
||||
// return dao.GetPaidBills();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class ManagementBI : FluentBasicBase
|
||||
{
|
||||
public ManagementBI()
|
||||
: base()
|
||||
{ }
|
||||
|
||||
public ManagementBI(bool beginTransaction)
|
||||
: base(beginTransaction)
|
||||
{ }
|
||||
|
||||
public ManagementBI(ISession session)
|
||||
: base(session)
|
||||
{ }
|
||||
|
||||
public ManagementBI(ISession session, bool beginTransaction)
|
||||
: base(session, beginTransaction)
|
||||
{ }
|
||||
|
||||
public decimal GetQuantity(int baseCode, DateTime startDate, DateTime finishDate)
|
||||
{
|
||||
const string query = @"
|
||||
select sum(i.Quantity * p.Quantity) as 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 p.BaseCode = :baseCode
|
||||
";
|
||||
var qty = Session
|
||||
.CreateQuery(query)
|
||||
.SetParameter("startDate", startDate)
|
||||
.SetParameter("finishDate", finishDate)
|
||||
.SetParameter("baseCode", baseCode)
|
||||
.UniqueResult();
|
||||
return qty == null ? 0 : (decimal)qty;
|
||||
}
|
||||
public decimal SetQuantity(int baseCode, decimal quantity, DateTime startDate, DateTime finishDate)
|
||||
{
|
||||
var list = Randomize(new VoucherBI().List(x => x.Date >= startDate && x.Date <= finishDate && x.Void == false));
|
||||
var current = GetQuantity(baseCode, startDate, finishDate);
|
||||
foreach (var item in list)
|
||||
{
|
||||
if (current <= quantity)
|
||||
continue;
|
||||
foreach (var kot in item.Kots)
|
||||
{
|
||||
if (current <= quantity)
|
||||
continue;
|
||||
foreach (var inventory in kot.Inventories)
|
||||
{
|
||||
if (current <= quantity)
|
||||
continue;
|
||||
if (inventory.Product.BaseCode == baseCode)
|
||||
{
|
||||
using (var bi = new InventoryBI())
|
||||
{
|
||||
if (inventory.Quantity * inventory.Product.Quantity > current - quantity)
|
||||
{
|
||||
current = quantity;
|
||||
inventory.Quantity = (current - quantity) / inventory.Product.Quantity;
|
||||
var i = bi.Get(x => x.InventoryID == inventory.InventoryID);
|
||||
i.Quantity = current - quantity;
|
||||
bi.Update(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
current -= inventory.Quantity * inventory.Product.Quantity;
|
||||
bi.Delete(x => x.InventoryID == inventory.InventoryID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return GetQuantity(baseCode, startDate, finishDate);
|
||||
}
|
||||
// public decimal GetBalance(decimal? tax, DateTime startDate, DateTime endDate)
|
||||
// {
|
||||
// GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
||||
// using (IConnectionDAO connection = factory.Connection)
|
||||
// {
|
||||
// using (IManagementDAO dao = factory.GetManagementDAO(startDate, endDate, connection))
|
||||
// {
|
||||
// return dao.GetBalance(tax);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// public List<Guid> GetUpdateBillList(decimal tax, bool voided, bool paid, bool creditCard, DateTime startDate, DateTime endDate)
|
||||
// {
|
||||
// GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
||||
// using (IConnectionDAO connection = factory.Connection)
|
||||
// {
|
||||
// using (IManagementDAO dao = factory.GetManagementDAO(startDate, endDate, connection))
|
||||
// {
|
||||
// return dao.GetUpdateBillList(tax, voided, paid, creditCard);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// public decimal Update(Guid voucherID, decimal tax, DateTime startDate, DateTime endDate)
|
||||
// {
|
||||
// GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
||||
// using (IConnectionDAO connection = factory.Connection)
|
||||
// {
|
||||
// using (IManagementDAO dao = factory.GetManagementDAO(startDate, endDate, connection))
|
||||
// {
|
||||
// return dao.Update(voucherID, tax);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// public void Reorder(DateTime startDate, DateTime endDate, ShowProgessDelegate showProgressDelegate)
|
||||
// {
|
||||
// GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
||||
// using (IConnectionDAO connection = factory.Connection)
|
||||
// {
|
||||
// using (IManagementDAO dao = factory.GetManagementDAO(startDate, endDate, connection))
|
||||
// {
|
||||
// dao.Reorder(showProgressDelegate);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// public bool MergeData(DateTime startDate, DateTime endDate, string sourceDB, string targetDB)
|
||||
// {
|
||||
// GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
||||
// using (IConnectionDAO connection = factory.Connection)
|
||||
// {
|
||||
// using (IManagementDAO dao = factory.GetManagementDAO(startDate, endDate, connection))
|
||||
// {
|
||||
// return dao.MergeData(sourceDB, targetDB);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// public List<PendingBills> GetPaidBills(DateTime startDate, DateTime finishDate)
|
||||
// {
|
||||
// GetFactory factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
|
||||
// using (IConnectionDAO connection = factory.Connection)
|
||||
// {
|
||||
// using (IManagementDAO dao = factory.GetManagementDAO(startDate, finishDate, connection))
|
||||
// {
|
||||
// return dao.GetPaidBills();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
private static IList<T> Randomize<T>(IEnumerable<T> list)
|
||||
{
|
||||
var tList = list.ToArray();
|
||||
var rand = new Random();
|
||||
for (var i = tList.Length - 1; i > 0; i--)
|
||||
{
|
||||
var swapIndex = rand.Next(i + 1);
|
||||
var tmp = tList[i];
|
||||
tList[i] = tList[swapIndex];
|
||||
tList[swapIndex] = tmp;
|
||||
}
|
||||
return tList.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -10,7 +10,7 @@ namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class SalesAnalysisBI
|
||||
{
|
||||
public ICollection<SalesAnalysisDetail> GetSaleDetail(DateTime startDate, DateTime finishDate)
|
||||
public IList<SalesAnalysisDetail> GetSaleDetail(DateTime startDate, DateTime finishDate)
|
||||
{
|
||||
|
||||
startDate = startDate.Date.AddHours(6);
|
||||
@ -20,6 +20,7 @@ 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
|
||||
from Voucher v
|
||||
@ -28,7 +29,7 @@ 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 and vs.Settled != :unsettled and vs.Settled != :amount and vs.Settled != :roundoff)
|
||||
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
|
||||
order by p.ProductGroup, concat(p.Name, ' ', p.Units)
|
||||
";
|
||||
@ -40,11 +41,13 @@ order by p.ProductGroup, concat(p.Name, ' ', p.Units)
|
||||
.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
|
||||
@ -67,8 +70,32 @@ order by p.ProductGroup, concat(p.Name, ' ', p.Units)
|
||||
outList[(string)item[0]].NC = (decimal)item[1];
|
||||
else
|
||||
outList.Add((string)item[0], new SalesAnalysisDetail() { Product = (string)item[0], NC = (decimal)item[1] });
|
||||
|
||||
return outList.Values;
|
||||
#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 = :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<SalesAnalysis> GetSale(DateTime startDate, DateTime finishDate)
|
||||
@ -88,7 +115,7 @@ inner join i.Product p
|
||||
inner join p.ProductGroup g
|
||||
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 != :noCharge and vs.Settled != :unsettled and vs.Settled != :amount and vs.Settled != :roundoff and vs.Settled != :staff)
|
||||
group by g.GroupType
|
||||
order by g.GroupType
|
||||
";
|
||||
@ -100,6 +127,7 @@ order by g.GroupType
|
||||
.SetParameter("unsettled", SettleOption.Unsettled)
|
||||
.SetParameter("amount", SettleOption.Amount)
|
||||
.SetParameter("roundoff", SettleOption.RoundOff)
|
||||
.SetParameter("staff", SettleOption.Staff)
|
||||
.List<object[]>();
|
||||
var outList = new List<SalesAnalysis>();
|
||||
decimal amount = 0;
|
||||
@ -149,6 +177,40 @@ order by v.BillID, s.Settled
|
||||
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);
|
||||
@ -245,7 +307,7 @@ inner join v.Kots k
|
||||
inner join k.Inventories i
|
||||
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 != :noCharge and vs.Settled != :unsettled and vs.Settled != :amount and vs.Settled != :roundoff and vs.Settled != :staff)
|
||||
";
|
||||
var amt = session
|
||||
.CreateQuery(query)
|
||||
@ -255,6 +317,7 @@ and vs.Settled != :noCharge and vs.Settled != :unsettled and vs.Settled != :amou
|
||||
.SetParameter("unsettled", SettleOption.Unsettled)
|
||||
.SetParameter("amount", SettleOption.Amount)
|
||||
.SetParameter("roundoff", SettleOption.RoundOff)
|
||||
.SetParameter("staff", SettleOption.Staff)
|
||||
.UniqueResult() ?? 0M;
|
||||
outList.Add(new SalesAnalysis() { GroupType = "Service Charge", Amount = (decimal)amt });
|
||||
#endregion
|
||||
@ -266,7 +329,7 @@ inner join v.Kots k
|
||||
inner join k.Inventories i
|
||||
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 != :noCharge and vs.Settled != :unsettled and vs.Settled != :amount and vs.Settled != :roundoff and vs.Settled != :staff)
|
||||
group by i.Tax
|
||||
";
|
||||
var list = session
|
||||
@ -277,6 +340,7 @@ group by i.Tax
|
||||
.SetParameter("unsettled", SettleOption.Unsettled)
|
||||
.SetParameter("amount", SettleOption.Amount)
|
||||
.SetParameter("roundoff", SettleOption.RoundOff)
|
||||
.SetParameter("staff", SettleOption.Staff)
|
||||
.List<object[]>();
|
||||
foreach (var item in list)
|
||||
outList.Add(new SalesAnalysis() { GroupType = string.Format("Tax {0:P}", (decimal)item[0]), Amount = (decimal)item[1] });
|
||||
|
||||
@ -1,4 +1,7 @@
|
||||
using NHibernate.Criterion;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using NHibernate.Criterion;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using Tanshu.Common.Helpers;
|
||||
using NHibernate;
|
||||
@ -21,13 +24,11 @@ namespace Tanshu.Accounts.Repository
|
||||
: base(session, beginTransaction)
|
||||
{ }
|
||||
|
||||
public bool IsVoucherPrinted(int voucherID)
|
||||
public IList<Voucher> List(Expression<Func<Voucher, bool>> query)
|
||||
{
|
||||
return Session.Get<Voucher>(voucherID).Printed;
|
||||
}
|
||||
public bool IsVoucherVoid(int voucherID)
|
||||
{
|
||||
return Session.Get<Voucher>(voucherID).Void;
|
||||
return Session.QueryOver<Voucher>()
|
||||
.Where(query)
|
||||
.List();
|
||||
}
|
||||
public int? Insert(Voucher voucher)
|
||||
{
|
||||
@ -36,7 +37,7 @@ namespace Tanshu.Accounts.Repository
|
||||
voucher.SetValue(VoucherFields.LastEditDate, dt);
|
||||
voucher.SetValue(VoucherFields.Date, dt);
|
||||
voucher.SetValue(VoucherFields.KotID, DbValues.KotID);
|
||||
voucher.SetValue(VoucherFields.BillID, voucher.Printed ? DbValues.BillID : voucher.KotID);
|
||||
voucher.SetValue(VoucherFields.BillID, voucher.Printed ? DbValues.BillID(voucher.VoucherType) : voucher.KotID);
|
||||
Kot addedKot = null;
|
||||
foreach (var item in voucher.Kots.Where(item => item.KotID == 0))
|
||||
{
|
||||
@ -47,18 +48,13 @@ namespace Tanshu.Accounts.Repository
|
||||
item.User = voucher.User;
|
||||
item.Code = DbValues.KotCode;
|
||||
}
|
||||
UpdateBill(voucher);
|
||||
var amount = -1 * voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount));
|
||||
VoucherSettlementBI.UpdateSettlements(voucher.Settlements, amount);
|
||||
|
||||
Session.Save(voucher);
|
||||
return addedKot == null ? (int?)null : addedKot.KotID;
|
||||
}
|
||||
public void Delete(int voucherID)
|
||||
{
|
||||
var voucher = Session.Get<Voucher>(voucherID);
|
||||
Session.Delete(voucher);
|
||||
using (var ft = new FoodTableBI(Session, false))
|
||||
ft.UpdateStatus(voucher.TableID, voucherID, null);
|
||||
}
|
||||
public int? Update(Voucher voucher)
|
||||
{
|
||||
var dt = DbValues.Date;
|
||||
@ -66,7 +62,7 @@ namespace Tanshu.Accounts.Repository
|
||||
if (voucher.Date == null)
|
||||
{
|
||||
voucher.SetValue(VoucherFields.Date, dt);
|
||||
voucher.SetValue(VoucherFields.BillID, DbValues.BillID );
|
||||
voucher.SetValue(VoucherFields.BillID, DbValues.BillID(voucher.VoucherType));
|
||||
}
|
||||
|
||||
Kot addedKot = null;
|
||||
@ -79,15 +75,18 @@ namespace Tanshu.Accounts.Repository
|
||||
item.User = voucher.User;
|
||||
item.Code = DbValues.KotCode;
|
||||
}
|
||||
UpdateBill(voucher);
|
||||
var amount = -1 * voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount));
|
||||
VoucherSettlementBI.UpdateSettlements(voucher.Settlements, amount);
|
||||
Session.Update(voucher);
|
||||
return addedKot == null ? (int?) null : addedKot.KotID;
|
||||
return addedKot == null ? (int?)null : addedKot.KotID;
|
||||
}
|
||||
|
||||
public Voucher Get(int voucherID)
|
||||
public Voucher Get(Expression<Func<Voucher, bool>> query)
|
||||
{
|
||||
var voucher = Session.Get<Voucher>(voucherID);
|
||||
var voucher = Session.QueryOver<Voucher>()
|
||||
.Where(query)
|
||||
.SingleOrDefault();
|
||||
NHibernateUtil.Initialize(voucher.Customer);
|
||||
NHibernateUtil.Initialize(voucher.Waiter);
|
||||
NHibernateUtil.Initialize(voucher.User);
|
||||
@ -108,12 +107,16 @@ namespace Tanshu.Accounts.Repository
|
||||
NHibernateUtil.Initialize(item);
|
||||
return voucher;
|
||||
}
|
||||
public Voucher Get(string billID)
|
||||
public void Delete(int voucherID)
|
||||
{
|
||||
var voucher = Session.CreateCriteria<Voucher>()
|
||||
.Add(Restrictions.Eq("BillID", billID))
|
||||
.UniqueResult<Voucher>();
|
||||
return voucher != null ? Get(voucher.VoucherID) : null;
|
||||
var voucher = Session.Get<Voucher>(voucherID);
|
||||
Delete(voucher);
|
||||
}
|
||||
public void Delete(Voucher voucher)
|
||||
{
|
||||
Session.Delete(voucher);
|
||||
using (var ft = new FoodTableBI(Session, false))
|
||||
ft.UpdateStatus(voucher.TableID, voucher.VoucherID, null);
|
||||
}
|
||||
|
||||
public void VoidBill(int voucherID, string reason)
|
||||
@ -132,6 +135,15 @@ namespace Tanshu.Accounts.Repository
|
||||
Session.Update(voucher);
|
||||
return voucher.VoucherID;
|
||||
}
|
||||
public int MergeTables(int voucherID, FoodTable foodTable)
|
||||
{
|
||||
var voucher = Session.Get<Voucher>(foodTable.VoucherID);
|
||||
var oldVoucher = Session.Get<Voucher>(voucherID);
|
||||
foreach (var kot in oldVoucher.Kots)
|
||||
voucher.Kots.Add(kot);
|
||||
Session.Update(voucher);
|
||||
return voucher.VoucherID;
|
||||
}
|
||||
public int MergeKot(int kotID, Voucher voucher)
|
||||
{
|
||||
var kot = Session.Get<Kot>(kotID);
|
||||
@ -140,5 +152,31 @@ namespace Tanshu.Accounts.Repository
|
||||
return voucher.VoucherID;
|
||||
}
|
||||
|
||||
private static void UpdateBill(Voucher voucher)
|
||||
{
|
||||
switch (voucher.VoucherType)
|
||||
{
|
||||
case VoucherType.Regular:
|
||||
break;
|
||||
case VoucherType.NoCharge:
|
||||
foreach (var item in voucher.Kots.SelectMany(kot => kot.Inventories))
|
||||
{
|
||||
item.ServiceCharge = 0;
|
||||
item.Tax = 0;
|
||||
}
|
||||
break;
|
||||
case VoucherType.TakeAway:
|
||||
foreach (var item in voucher.Kots.SelectMany(kot => kot.Inventories))
|
||||
item.ServiceCharge = 0;
|
||||
break;
|
||||
case VoucherType.Staff:
|
||||
foreach (var item in voucher.Kots.SelectMany(kot => kot.Inventories))
|
||||
{
|
||||
item.ServiceCharge = 0;
|
||||
item.Tax = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,67 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using System.Data.SqlClient;
|
||||
using Tanshu.Data.DAO;
|
||||
using System.Collections.Generic;
|
||||
using NHibernate;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using Tanshu.Accounts.SqlDAO;
|
||||
using NHibernate.Criterion;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public static class WaiterBI
|
||||
public class WaiterBI : FluentGenericBase<Waiter>
|
||||
{
|
||||
public static void Insert(Waiter waiter)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Save(waiter);
|
||||
}
|
||||
}
|
||||
public static void Update(Waiter waiter)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Update(waiter);
|
||||
}
|
||||
}
|
||||
public static bool Delete(int waiterID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Delete(new Waiter() { WaiterID = waiterID });
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static Waiter GetWaiter(int waiterID)
|
||||
public WaiterBI()
|
||||
: base()
|
||||
{ }
|
||||
public WaiterBI(bool beginTransaction)
|
||||
: base(beginTransaction)
|
||||
{ }
|
||||
public WaiterBI(ISession session)
|
||||
: base(session)
|
||||
{ }
|
||||
public WaiterBI(ISession session, bool beginTransaction)
|
||||
: base(session, beginTransaction)
|
||||
{ }
|
||||
|
||||
public static IList<Waiter> List(Dictionary<string, string> filter)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.Get<Waiter>(waiterID);
|
||||
}
|
||||
}
|
||||
public static IList<Waiter> GetWaiters()
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.CreateCriteria<Waiter>()
|
||||
.List<Waiter>();
|
||||
}
|
||||
}
|
||||
public static IList<Waiter> GetWaiters(string name)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.CreateCriteria<Waiter>()
|
||||
.Add(Restrictions.InsensitiveLike("Name", string.Format("%{0}%", name)))
|
||||
.List<Waiter>();
|
||||
}
|
||||
}
|
||||
public static IList<Waiter> GetFilteredWaiters(Dictionary<string, string> filter)
|
||||
{
|
||||
return GetWaiters(filter["Name"]);
|
||||
using (var bi = new WaiterBI(false))
|
||||
return bi.Query()
|
||||
.WhereRestrictionOn(x => x.Name).IsLike(string.Format("%{0}%", filter["Name"]))
|
||||
.List();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Tanshu.Accounts.Entities;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
@ -39,25 +40,38 @@ namespace Tanshu.Accounts.Repository
|
||||
}
|
||||
}
|
||||
}
|
||||
public static string BillID
|
||||
public static string BillID(VoucherType voucherType)
|
||||
{
|
||||
get
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
const string query = @"
|
||||
var query = "";
|
||||
switch (voucherType)
|
||||
{
|
||||
case VoucherType.Regular:
|
||||
case VoucherType.TakeAway:
|
||||
query = @"
|
||||
DECLARE @BillID nvarchar(10)
|
||||
SELECT @BillID = ISNULL(CAST(MAX(CAST(REPLACE(BillID, '-', '') AS int)) + 1 AS nvarchar(9)), '010001') FROM Entities_Vouchers WHERE BillID LIKE '__-____'
|
||||
AND BillID NOT LIKE 'NC-%' AND BillID NOT LIKE 'ST-%'
|
||||
IF LEN(@BillID) = 5
|
||||
SET @BillID = '0' + @BillID
|
||||
SET @BillID = SUBSTRING(@BillID, 1, 2) + '-' + SUBSTRING(@BillID, 3, 7)
|
||||
IF SUBSTRING(@BillID,3,7) = '-0000'
|
||||
SET @BillID = SUBSTRING(@BillID, 1, 2) + '-0001'
|
||||
SELECT @BillID";
|
||||
break;
|
||||
case VoucherType.NoCharge:
|
||||
query = @"SELECT ISNULL('NC-' + CAST(MAX(CAST(SUBSTRING(BillID, 4,9) AS int)) + 1 AS nvarchar(9)), 'NC-1') FROM Entities_Vouchers WHERE BillID LIKE 'NC-%'";
|
||||
break;
|
||||
case VoucherType.Staff:
|
||||
query = @"SELECT ISNULL('ST-' + CAST(MAX(CAST(SUBSTRING(BillID, 4,9) AS int)) + 1 AS nvarchar(9)), 'ST-1') FROM Entities_Vouchers WHERE BillID LIKE 'ST-%'";
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException("voucherType");
|
||||
}
|
||||
var sqlQuery = session.CreateSQLQuery(query);
|
||||
return (string)sqlQuery.UniqueResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,6 +84,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BusinessLayer\CheckoutBI.cs" />
|
||||
<Compile Include="BusinessLayer\InventoryBI.cs" />
|
||||
<Compile Include="BusinessLayer\ReprintBI.cs" />
|
||||
<Compile Include="BusinessLayer\FluentBasicBaseBI.cs" />
|
||||
<Compile Include="BusinessLayer\VoucherSettlementBI.cs" />
|
||||
|
||||
Reference in New Issue
Block a user