narsil/Tanshu.Accounts.Repository/BusinessLayer/FoodTableBI.cs
Tanshu 843d644154 Added ST Number to bill.
Fixed error were unprinted bill was not removed from table when voided.
2012-12-01 15:19:33 +05:30

72 lines
2.3 KiB
C#

using NHibernate;
using Tanshu.Accounts.Entities;
using System.Linq;
namespace Tanshu.Accounts.Repository
{
public class FoodTableBI : FluentGenericBase<FoodTable>
{
public FoodTableBI()
: base()
{ }
public FoodTableBI(bool beginTransaction)
: base(beginTransaction)
{ }
public FoodTableBI(ISession session)
: base(session)
{ }
public FoodTableBI(ISession session, bool beginTransaction)
: base(session, beginTransaction)
{ }
public void UpdateStatus(string name, int voucherID, string status)
{
var table = Get(x => x.Name == name);
table.VoucherID = string.IsNullOrEmpty(status) ? 0 : voucherID;
table.Status = status;
Session.Update(table);
}
public int Move(string name, FoodTable foodTable)
{
var oldTable = Get(x => x.Name == name);
foodTable.Status = oldTable.Status;
foodTable.VoucherID = oldTable.VoucherID;
oldTable.Status = null;
oldTable.VoucherID = 0;
Session.Update(foodTable);
Session.Update(oldTable);
var voucher = Session.Get<Voucher>(foodTable.VoucherID);
voucher.TableID = foodTable.Name;
Session.Update(voucher);
return voucher.VoucherID;
}
public void UpdateStatus(Voucher voucher)
{
string status;
if (!voucher.Printed && !voucher.Void)
status = "running";
else if (voucher.Settlements.Count(x => x.Settled == SettleOption.Unsettled) != 0 && !voucher.Void)
status = "printed";
else
status = null;
UpdateStatus(voucher.TableID, voucher.VoucherID, status);
}
public void TableSettled(Voucher voucher)
{
if (voucher.Settlements.Count(x => x.Settled == SettleOption.Unsettled) != 0 && voucher.Void == false)
return;
var table = Get(x => x.Name == voucher.TableID && x.VoucherID == voucher.VoucherID);
if (table == null)
return;
table.VoucherID = 0;
table.Status = null;
Session.Update(table);
}
}
}