Added inverse Attribute to ProductGroup.
BillInventory Renamed. Refactored Bill to be more usable. Added Bill Detail Report. Added Open Bill and Bill Details Roles. Zero Rate Products have Yellow background Color. Refactored UserBI, FoodTableBI, ModifierBI, PrintLocationBI, ProductBI, ProductGroupBI, TaxBI, UserBI, Cached the Products List. Product and Product Group Form Working.
This commit is contained in:
@ -58,16 +58,17 @@ namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
this.Cashier = UserBI.GetUser(cashier);
|
||||
using (var bi = new UserBI(session, false))
|
||||
this.Cashier = bi.Get(x => x.UserID == cashier);
|
||||
this.StartDate = startDate.Date.AddHours(6);
|
||||
this.FinishDate = finishDate.Date.AddDays(1).AddHours(5);
|
||||
|
||||
string info;
|
||||
PendingBills = GetPrintInfo(out info,SettleOption.Unsettled);
|
||||
PendingBills = GetPrintInfo(out info, SettleOption.Unsettled);
|
||||
PendingString = info;
|
||||
CcReceipts = GetPrintInfo(out info,SettleOption.CreditCard);
|
||||
CcReceipts = GetPrintInfo(out info, SettleOption.CreditCard);
|
||||
CcString = info;
|
||||
NcReceipts = GetPrintInfo(out info, SettleOption.CreditCard);
|
||||
NcReceipts = GetPrintInfo(out info, SettleOption.NoCharge);
|
||||
NcString = info;
|
||||
BtcReceipts = GetPrintInfo(out info, SettleOption.BillToCompany);
|
||||
BtcString = info;
|
||||
@ -143,7 +144,7 @@ namespace Tanshu.Accounts.Repository
|
||||
Voucher voucher = null;
|
||||
decimal amount;
|
||||
decimal discount;
|
||||
info = string.Format("\n\r--- {0} ", settleOption.Display()).PadRight(44,'-');
|
||||
info = string.Format("\n\r--- {0} ", settleOption.Display()).PadRight(44, '-');
|
||||
var list = session.QueryOver<Voucher>(() => voucher)
|
||||
.Where(i => i.LastEditDate >= StartDate &&
|
||||
i.LastEditDate <= FinishDate &&
|
||||
@ -151,7 +152,7 @@ namespace Tanshu.Accounts.Repository
|
||||
i.Void == false)
|
||||
.WithSubquery.WhereExists(QueryOver.Of<VoucherSettlement>().Where(x => x.Voucher.VoucherID == voucher.VoucherID && x.Settled == settleOption).Select(x => x.Voucher))
|
||||
.List();
|
||||
GetInfo(list, SettleOption.Unsettled, out amount, out discount, ref info);
|
||||
GetInfo(list, settleOption, out amount, out discount, ref info);
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
|
||||
136
Tanshu.Accounts.Repository/BusinessLayer/FluentBaseBI.cs
Normal file
136
Tanshu.Accounts.Repository/BusinessLayer/FluentBaseBI.cs
Normal file
@ -0,0 +1,136 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using NHibernate;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class FluentBase<T> : IDisposable, IRepository<T> where T : class
|
||||
{
|
||||
protected readonly bool DisposeSession;
|
||||
protected readonly ISession Session;
|
||||
protected readonly ITransaction Transaction;
|
||||
|
||||
public FluentBase()
|
||||
{
|
||||
Session = SessionManager.Session;
|
||||
DisposeSession = true;
|
||||
Transaction = Session.BeginTransaction();
|
||||
|
||||
}
|
||||
public FluentBase(bool beginTransaction)
|
||||
{
|
||||
Session = SessionManager.Session;
|
||||
DisposeSession = true;
|
||||
if (beginTransaction)
|
||||
Transaction = Session.BeginTransaction();
|
||||
}
|
||||
public FluentBase(ISession session)
|
||||
{
|
||||
this.Session = session;
|
||||
DisposeSession = false;
|
||||
}
|
||||
public FluentBase(ISession session, bool beginTransaction)
|
||||
{
|
||||
this.Session = session;
|
||||
DisposeSession = false;
|
||||
if (beginTransaction)
|
||||
Transaction = Session.BeginTransaction();
|
||||
}
|
||||
|
||||
#region IDisposable Members
|
||||
public void Dispose()
|
||||
{
|
||||
if (Transaction != null)
|
||||
{
|
||||
Transaction.Commit();
|
||||
Transaction.Dispose();
|
||||
}
|
||||
if (DisposeSession && Session != null)
|
||||
Session.Dispose();
|
||||
}
|
||||
//public void Dispose()
|
||||
//{
|
||||
// Dispose(true);
|
||||
// GC.SuppressFinalize(this);
|
||||
//}
|
||||
|
||||
//protected virtual void Dispose(bool disposing)
|
||||
//{
|
||||
// if (Transaction != null)
|
||||
// {
|
||||
// Transaction.Commit();
|
||||
// Transaction.Dispose();
|
||||
// }
|
||||
// if (DisposeSession && Session != null)
|
||||
// Session.Dispose();
|
||||
|
||||
// if (disposing)
|
||||
// {
|
||||
// // get rid of managed resources
|
||||
// }
|
||||
// // get rid of unmanaged resources
|
||||
//}
|
||||
//~FluentBase()
|
||||
//{
|
||||
// Dispose(false);
|
||||
//}
|
||||
#endregion
|
||||
|
||||
#region IRepository<T> Members
|
||||
|
||||
public void Insert(T item)
|
||||
{
|
||||
Session.Save(item);
|
||||
}
|
||||
|
||||
public void Update(T item)
|
||||
{
|
||||
Session.Update(item);
|
||||
}
|
||||
|
||||
public void Delete(T item)
|
||||
{
|
||||
Session.Delete(item);
|
||||
}
|
||||
|
||||
public void Delete(Expression<Func<T, bool>> query)
|
||||
{
|
||||
Delete(Get(query));
|
||||
}
|
||||
|
||||
public void DeleteList(Expression<Func<T, bool>> query)
|
||||
{
|
||||
foreach (T item in List(query))
|
||||
Delete(item);
|
||||
}
|
||||
|
||||
public T Get(Expression<Func<T, bool>> query)
|
||||
{
|
||||
return Session.QueryOver<T>()
|
||||
.Where(query)
|
||||
.SingleOrDefault();
|
||||
}
|
||||
|
||||
public IList<T> List()
|
||||
{
|
||||
return Session.CreateCriteria<T>()
|
||||
.List<T>();
|
||||
}
|
||||
|
||||
public IList<T> List(Expression<Func<T, bool>> query)
|
||||
{
|
||||
return Session.QueryOver<T>()
|
||||
.Where(query)
|
||||
.List();
|
||||
}
|
||||
|
||||
public void DeleteList(IList<T> list)
|
||||
{
|
||||
foreach (T item in list)
|
||||
Delete(item);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -7,133 +7,69 @@ using System.Linq;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class FoodTableBI : IDisposable
|
||||
public class FoodTableBI : FluentBase<FoodTable>
|
||||
{
|
||||
private readonly bool _disposeSession;
|
||||
private readonly ISession _session;
|
||||
private readonly bool _useTransaction;
|
||||
|
||||
public FoodTableBI()
|
||||
{
|
||||
_session = SessionManager.Session;
|
||||
_disposeSession = true;
|
||||
_useTransaction = false;
|
||||
}
|
||||
: base()
|
||||
{ }
|
||||
|
||||
public FoodTableBI(bool beginTransaction)
|
||||
: base(beginTransaction)
|
||||
{ }
|
||||
|
||||
public FoodTableBI(ISession session)
|
||||
{
|
||||
this._session = session;
|
||||
_disposeSession = false;
|
||||
_useTransaction = false;
|
||||
}
|
||||
: base(session)
|
||||
{ }
|
||||
|
||||
public FoodTableBI(ISession session, bool useTransaction)
|
||||
{
|
||||
this._session = session;
|
||||
_disposeSession = false;
|
||||
this._useTransaction = useTransaction;
|
||||
}
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposeSession)
|
||||
_session.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void Insert(FoodTable foodTable)
|
||||
{
|
||||
_session.Save(foodTable);
|
||||
}
|
||||
|
||||
public void Update(FoodTable foodTable)
|
||||
{
|
||||
_session.Update(foodTable);
|
||||
}
|
||||
|
||||
public void Delete(int foodTableID)
|
||||
{
|
||||
_session.Delete(new FoodTable {FoodTableID = foodTableID});
|
||||
}
|
||||
|
||||
public FoodTable Get(int foodTableID)
|
||||
{
|
||||
return _session.Get<FoodTable>(foodTableID);
|
||||
}
|
||||
|
||||
public FoodTable Get(string name)
|
||||
{
|
||||
return _session.CreateCriteria<FoodTable>()
|
||||
.Add(Restrictions.Eq("Name", name))
|
||||
.UniqueResult<FoodTable>();
|
||||
}
|
||||
|
||||
public IList<FoodTable> List()
|
||||
{
|
||||
return _session.CreateCriteria<FoodTable>().List<FoodTable>();
|
||||
}
|
||||
public FoodTableBI(ISession session, bool beginTransaction)
|
||||
: base(session, beginTransaction)
|
||||
{ }
|
||||
|
||||
public void UpdateStatus(string name, int voucherID, string status)
|
||||
{
|
||||
if (!_useTransaction)
|
||||
using (var trans = _session.BeginTransaction())
|
||||
{
|
||||
var table = _session.CreateCriteria<FoodTable>()
|
||||
.Add(Restrictions.Eq("Name", name))
|
||||
.UniqueResult<FoodTable>();
|
||||
if (table == null)
|
||||
return;
|
||||
table.VoucherID = string.IsNullOrEmpty(status) ? 0 : voucherID;
|
||||
table.Status = status;
|
||||
_session.Update(table);
|
||||
trans.Commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
var table = _session.CreateCriteria<FoodTable>()
|
||||
.Add(Restrictions.Eq("Name", name))
|
||||
.UniqueResult<FoodTable>();
|
||||
table.VoucherID = string.IsNullOrEmpty(status) ? 0 : voucherID;
|
||||
table.Status = status;
|
||||
_session.Update(table);
|
||||
}
|
||||
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)
|
||||
{
|
||||
using (var trans = _session.BeginTransaction())
|
||||
{
|
||||
var oldTable = _session.CreateCriteria<FoodTable>()
|
||||
.Add(Restrictions.Eq("Name", name))
|
||||
.UniqueResult<FoodTable>();
|
||||
foodTable.Status = oldTable.Status;
|
||||
foodTable.VoucherID = oldTable.VoucherID;
|
||||
oldTable.Status = null;
|
||||
oldTable.VoucherID = 0;
|
||||
_session.Merge(foodTable);
|
||||
_session.Update(oldTable);
|
||||
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);
|
||||
trans.Commit();
|
||||
return voucher.VoucherID;
|
||||
}
|
||||
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)
|
||||
status = "running";
|
||||
else if (voucher.Settlements.Count(x => x.Settled == SettleOption.Unsettled) != 0 && voucher.Void == false)
|
||||
status = "printed";
|
||||
else
|
||||
status = null;
|
||||
UpdateStatus(voucher.TableID, voucher.VoucherID, status);
|
||||
string status;
|
||||
if (!voucher.Printed)
|
||||
status = "running";
|
||||
else if (voucher.Settlements.Count(x => x.Settled == SettleOption.Unsettled) != 0 && voucher.Void == false)
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Tanshu.Accounts.Repository/BusinessLayer/IRepositoryBI.cs
Normal file
21
Tanshu.Accounts.Repository/BusinessLayer/IRepositoryBI.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public interface IRepository<T>
|
||||
{
|
||||
void Insert(T item);
|
||||
void Update(T item);
|
||||
void Delete(T item);
|
||||
void Delete(Expression<Func<T, bool>> query);
|
||||
void DeleteList(Expression<Func<T, bool>> query);
|
||||
void DeleteList(IList<T> list);
|
||||
|
||||
T Get(Expression<Func<T, bool>> query);
|
||||
|
||||
IList<T> List();
|
||||
IList<T> List(Expression<Func<T, bool>> query);
|
||||
}
|
||||
}
|
||||
@ -1,51 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Tanshu.Data.DAO;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using NHibernate;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using Tanshu.Accounts.SqlDAO;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public static class ModifierBI
|
||||
public class ModifierBI : FluentBase<Modifier>
|
||||
{
|
||||
public static void Insert(Modifier modifier)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Save(modifier);
|
||||
}
|
||||
}
|
||||
public static void Update(Modifier modifier)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Update(modifier);
|
||||
}
|
||||
}
|
||||
public static void Delete(int modifierID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Delete(new Modifier() { ModifierID = modifierID });
|
||||
}
|
||||
}
|
||||
public static Modifier GetModifier(int modifierID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.Get<Modifier>(modifierID);
|
||||
}
|
||||
}
|
||||
public static IList<Modifier> GetModifiers()
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.CreateCriteria<Modifier>().List<Modifier>();
|
||||
}
|
||||
}
|
||||
public ModifierBI(ISession session)
|
||||
: base(session)
|
||||
{ }
|
||||
public ModifierBI()
|
||||
: base()
|
||||
{ }
|
||||
public ModifierBI(bool useTransaction)
|
||||
: base(useTransaction)
|
||||
{ }
|
||||
public ModifierBI(ISession session, bool useTransaction)
|
||||
: base(session, useTransaction)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,87 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using System.Data.SqlClient;
|
||||
using Tanshu.Data.DAO;
|
||||
using System.Configuration;
|
||||
using System.Configuration;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using Tanshu.Accounts.SqlDAO;
|
||||
using NHibernate.Criterion;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class PrintLocationBI
|
||||
public class PrintLocationBI : FluentBase<PrintLocation>
|
||||
{
|
||||
public void Insert(PrintLocation printLocation)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Save(printLocation);
|
||||
}
|
||||
}
|
||||
public void Update(PrintLocation printLocation)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Update(printLocation);
|
||||
}
|
||||
}
|
||||
public void Delete(int printLocationID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Delete(new PrintLocation() { PrintLocationID = printLocationID });
|
||||
}
|
||||
}
|
||||
public PrintLocation GetPrintLocation(int printLocationID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.Get<PrintLocation>(printLocationID);
|
||||
}
|
||||
}
|
||||
public PrintLocation GetPrintLocation(int productGroupID, string location)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return (from pl in session.QueryOver<PrintLocation>()
|
||||
where pl.ProductGroup.ProductGroupID == productGroupID && pl.Location == location
|
||||
select pl).SingleOrDefault();
|
||||
//return session.CreateCriteria<PrintLocation>()
|
||||
// .Add(Restrictions.Eq("ProductGroupID", productGroupID))
|
||||
// .Add(Restrictions.Eq("Location", location))
|
||||
// .UniqueResult<PrintLocation>();
|
||||
}
|
||||
}
|
||||
public PrintLocation GetPrintLocation(string location)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return (from pl in session.QueryOver<PrintLocation>()
|
||||
where pl.Location == location && pl.ProductGroup.ProductGroupID == null
|
||||
select pl).SingleOrDefault();
|
||||
//return session.CreateCriteria<PrintLocation>()
|
||||
// .Add(Restrictions.IsNull("ProductGroupID"))
|
||||
// .Add(Restrictions.Eq("Location", location))
|
||||
// .UniqueResult<PrintLocation>();
|
||||
}
|
||||
}
|
||||
public static PrintLocation BasePrinter
|
||||
{
|
||||
get
|
||||
{
|
||||
string location = ConfigurationManager.AppSettings["Location"].ToLowerInvariant();
|
||||
return new PrintLocationBI().GetPrintLocation(location);
|
||||
var location = ConfigurationManager.AppSettings["Location"].ToLowerInvariant();
|
||||
using (var bi = new PrintLocationBI())
|
||||
return bi.Get(x => x.Location == location && x.ProductGroup == null);
|
||||
}
|
||||
}
|
||||
public static PrintLocation KotPrinter(int productGroupID)
|
||||
{
|
||||
string location = ConfigurationManager.AppSettings["Location"].ToLowerInvariant();
|
||||
PrintLocation p = new PrintLocationBI().GetPrintLocation(productGroupID, location);
|
||||
if (p == null)
|
||||
p = new PrintLocationBI().GetPrintLocation(location);
|
||||
return p;
|
||||
var location = ConfigurationManager.AppSettings["Location"].ToLowerInvariant();
|
||||
using (var bi = new PrintLocationBI())
|
||||
return bi.Get(x => x.Location == location && x.ProductGroup.ProductGroupID == productGroupID) ??
|
||||
bi.Get(x => x.Location == location && x.ProductGroup == null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,67 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Linq.Expressions;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using System.Data.SqlClient;
|
||||
using Tanshu.Data.DAO;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using Tanshu.Accounts.SqlDAO;
|
||||
using NHibernate.Criterion;
|
||||
using NHibernate;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public static class ProductBI
|
||||
public class ProductBI : FluentBase<Product>
|
||||
{
|
||||
public static void Insert(Product product)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Save(product);
|
||||
}
|
||||
}
|
||||
public static void Update(Product product)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Update(product);
|
||||
}
|
||||
public ProductBI()
|
||||
: base()
|
||||
{ }
|
||||
|
||||
}
|
||||
public static bool Delete(int productID)
|
||||
public ProductBI(bool beginTransaction)
|
||||
: base(beginTransaction)
|
||||
{ }
|
||||
|
||||
public ProductBI(ISession session)
|
||||
: base(session)
|
||||
{ }
|
||||
|
||||
public ProductBI(ISession session, bool beginTransaction)
|
||||
: base(session, beginTransaction)
|
||||
{ }
|
||||
|
||||
|
||||
public Product Get(string nameAndUnits)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
return Get(x => x.Name + " (" + x.Units + ")" == nameAndUnits);
|
||||
}
|
||||
public new IList<Product> List(Expression<Func<Product, bool>> query)
|
||||
{
|
||||
var list = base.List(query);
|
||||
foreach (var item in list)
|
||||
{
|
||||
session.Delete(new Product() { ProductID = productID });
|
||||
return true;
|
||||
NHibernateUtil.Initialize(item.ProductGroup);
|
||||
NHibernateUtil.Initialize(item.Tax);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
public static Product GetProductFromName(string nameAndUnits)
|
||||
|
||||
public new IList<Product> List()
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
var list = base.List();
|
||||
foreach (var item in list)
|
||||
{
|
||||
return session.CreateCriteria<Product>()
|
||||
.Add(Expression.Eq("Name + ' (' + Units + ')'", nameAndUnits))
|
||||
.UniqueResult<Product>();
|
||||
}
|
||||
}
|
||||
public static Product GetProduct(int productID)
|
||||
{
|
||||
using (var sessioin = SessionManager.Session)
|
||||
{
|
||||
return sessioin.Get<Product>(productID);
|
||||
}
|
||||
}
|
||||
public static decimal GetProductStock(DateTime date, int productID, int? voucherID)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public static IList<Product> GetProducts()
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.CreateCriteria<Product>()
|
||||
.List<Product>();
|
||||
NHibernateUtil.Initialize(item.ProductGroup);
|
||||
NHibernateUtil.Initialize(item.Tax);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<ProductDisplaySmall> GetFilteredProducts(Dictionary<string, string> filter)
|
||||
@ -76,7 +64,7 @@ namespace Tanshu.Accounts.Repository
|
||||
filter.Add("Type", "");
|
||||
return GetFilteredProducts(filter);
|
||||
}
|
||||
public static IList<Product> GetProducts(int productGroupID)
|
||||
public static IList<Product> List(int productGroupID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
|
||||
@ -1,73 +1,46 @@
|
||||
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 Tanshu.Accounts.Entities;
|
||||
using Tanshu.Accounts.SqlDAO;
|
||||
using NHibernate.Criterion;
|
||||
using NHibernate;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class ProductGroupBI
|
||||
public class ProductGroupBI : FluentBase<ProductGroup>
|
||||
{
|
||||
public ProductGroup GetProductGroup(int productGroupID)
|
||||
public ProductGroupBI()
|
||||
: base()
|
||||
{ }
|
||||
|
||||
public ProductGroupBI(bool beginTransaction)
|
||||
: base(beginTransaction)
|
||||
{ }
|
||||
|
||||
public ProductGroupBI(ISession session)
|
||||
: base(session)
|
||||
{ }
|
||||
|
||||
public ProductGroupBI(ISession session, bool beginTransaction)
|
||||
: base(session, beginTransaction)
|
||||
{ }
|
||||
|
||||
public new IList<ProductGroup> List()
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.Get<ProductGroup>(productGroupID);
|
||||
}
|
||||
}
|
||||
public ProductGroup GetProductGroupByName(string name)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.CreateCriteria<ProductGroup>()
|
||||
.Add(Restrictions.Eq("Name", name))
|
||||
.UniqueResult<ProductGroup>();
|
||||
}
|
||||
}
|
||||
public void Insert(ProductGroup productGroup)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Save(productGroup);
|
||||
}
|
||||
}
|
||||
public void Update(ProductGroup productGroup)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Update(productGroup);
|
||||
}
|
||||
}
|
||||
public IList<ProductGroup> GetProductGroups()
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.CreateCriteria<ProductGroup>()
|
||||
.AddOrder(Order.Asc("Name"))
|
||||
.List<ProductGroup>();
|
||||
}
|
||||
return Session.QueryOver<ProductGroup>()
|
||||
.OrderBy(x => x.Name).Asc
|
||||
.List();
|
||||
}
|
||||
public IList<string> GetProductGroupTypes()
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
string query = @"select distinct(pg.GroupType) from ProductGroup pg order by pg.GroupType";
|
||||
var hnq = session.CreateQuery(query);
|
||||
return hnq.List<string>();
|
||||
}
|
||||
const string query = @"select distinct(pg.GroupType) from ProductGroup pg order by pg.GroupType";
|
||||
var hnq = Session.CreateQuery(query);
|
||||
return hnq.List<string>();
|
||||
}
|
||||
public ProductGroup GetProductGroupOfProduct(int productID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
var item = (from p in session.QueryOver<Product>()
|
||||
where p.ProductID == productID
|
||||
select p.ProductGroup).SingleOrDefault<ProductGroup>();
|
||||
where p.ProductID == productID
|
||||
select p.ProductGroup).SingleOrDefault<ProductGroup>();
|
||||
NHibernateUtil.Initialize(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
@ -1,33 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public delegate bool AuthenticateUser(out string userName);
|
||||
public class RoleBI : IDisposable
|
||||
{
|
||||
string roleName;
|
||||
int userID;
|
||||
bool isAllowed;
|
||||
readonly string _roleName;
|
||||
int _userID;
|
||||
readonly bool _isAllowed;
|
||||
//bool elevated;
|
||||
//AccountsPrincipal originalUser;
|
||||
//AuthenticateUser authenticateUser;
|
||||
public RoleBI(string roleName, int userID)
|
||||
{
|
||||
this.roleName = roleName;
|
||||
this.userID = userID;
|
||||
this._roleName = roleName;
|
||||
this._userID = userID;
|
||||
if (userID == 0)
|
||||
isAllowed = false;
|
||||
_isAllowed = false;
|
||||
else
|
||||
isAllowed = MembershipBI.IsUserInRole(userID, this.roleName);
|
||||
_isAllowed = MembershipBI.IsUserInRole(userID, this._roleName);
|
||||
disposed = false;
|
||||
}
|
||||
|
||||
public bool IsAllowed
|
||||
{ get { return isAllowed; } }
|
||||
{ get { return _isAllowed; } }
|
||||
|
||||
//public bool IsElevated
|
||||
//{
|
||||
|
||||
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using Tanshu.Common;
|
||||
using Tanshu.Common.Helpers;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
@ -110,6 +111,40 @@ order by g.GroupType
|
||||
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)
|
||||
{
|
||||
const string query = @"
|
||||
select v.Date, v.BillID, s.Settled, s.Amount
|
||||
from Voucher v
|
||||
inner join v.Settlements s
|
||||
where v.Date >= :startDate and v.Date <= :finishDate
|
||||
order by v.BillID, s.Settled
|
||||
";
|
||||
var list = session
|
||||
.CreateQuery(query)
|
||||
.SetParameter("startDate", startDate)
|
||||
.SetParameter("finishDate", finishDate)
|
||||
.List<object[]>();
|
||||
var outList = new List<BillDetail>();
|
||||
foreach (var item in list)
|
||||
{
|
||||
outList.Add(new BillDetail()
|
||||
{
|
||||
Date = (DateTime)item[0],
|
||||
BillID = (string)item[1],
|
||||
Settlement = ((SettleOption)item[2]).Display(),
|
||||
Amount = (decimal)item[3]
|
||||
});
|
||||
}
|
||||
return outList;
|
||||
}
|
||||
}
|
||||
private static IList<SalesAnalysis> GetSettlement(IList<SalesAnalysis> outList, DateTime startDate, DateTime finishDate)
|
||||
{
|
||||
outList.Add(new SalesAnalysis() { GroupType = " -- ", Amount = 0 });
|
||||
@ -135,7 +170,7 @@ order by s.Settled
|
||||
foreach (var item in list)
|
||||
{
|
||||
amount += (decimal)item[1];
|
||||
outList.Add(new SalesAnalysis() { GroupType = ((SettleOption)item[0]).ToString(), 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 });
|
||||
return GetOtherDetails(outList, startDate, finishDate);
|
||||
|
||||
@ -1,60 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
using System.Text;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using System.Data.SqlClient;
|
||||
using Tanshu.Data.DAO;
|
||||
using NHibernate;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using Tanshu.Accounts.SqlDAO;
|
||||
using NHibernate.Criterion;
|
||||
using Tanshu.Accounts.Entities.Auth;
|
||||
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public static class TaxBI
|
||||
public class TaxBI : FluentBase<Tax>
|
||||
{
|
||||
public static void Insert(Tax tax)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Save(tax);
|
||||
}
|
||||
}
|
||||
public static void Update(Tax tax)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
using (var trans = session.BeginTransaction())
|
||||
{
|
||||
session.Update(tax);
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void Delete(int taxID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Delete(new Tax() { TaxID = taxID });
|
||||
}
|
||||
}
|
||||
|
||||
public static Tax GetTax(int taxID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.Get<Tax>(taxID);
|
||||
}
|
||||
}
|
||||
public static IList<Tax> GetTaxes()
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.CreateCriteria<Tax>()
|
||||
.List<Tax>();
|
||||
}
|
||||
}
|
||||
public TaxBI(ISession session)
|
||||
: base(session)
|
||||
{ }
|
||||
public TaxBI()
|
||||
: base()
|
||||
{ }
|
||||
public TaxBI(bool useTransaction)
|
||||
: base(useTransaction)
|
||||
{ }
|
||||
public TaxBI(ISession session, bool useTransaction)
|
||||
: base(session, useTransaction)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,144 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
using System.Text;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using System.Data.SqlClient;
|
||||
using Tanshu.Data.DAO;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using Tanshu.Accounts.SqlDAO;
|
||||
using NHibernate.Criterion;
|
||||
using NHibernate;
|
||||
using Tanshu.Accounts.Entities.Auth;
|
||||
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public static class UserBI
|
||||
public class UserBI : FluentBase<User>
|
||||
{
|
||||
public static void Insert(User user)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Save(user);
|
||||
}
|
||||
}
|
||||
public static void Update(User user)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
using (var trans = session.BeginTransaction())
|
||||
{
|
||||
session.Update(user);
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void Delete(int userID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Delete(new User() { UserID = userID });
|
||||
}
|
||||
}
|
||||
public UserBI()
|
||||
: base()
|
||||
{ }
|
||||
public UserBI(bool useTransaction)
|
||||
: base(useTransaction)
|
||||
{ }
|
||||
public UserBI(ISession session)
|
||||
: base(session)
|
||||
{ }
|
||||
public UserBI(ISession session, bool useTransaction)
|
||||
: base(session, useTransaction)
|
||||
{ }
|
||||
|
||||
public static User GetUser(int userID)
|
||||
public IList<User> GetFilteredUsers(Dictionary<string, string> filter)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.Get<User>(userID);
|
||||
}
|
||||
return Session.QueryOver<User>()
|
||||
.WhereRestrictionOn(x => x.Name).IsLike(string.Format("%{0}%", filter["Name"]))
|
||||
.List();
|
||||
}
|
||||
public static User GetUserFromName(string name)
|
||||
public bool ChangePassword(User userData, string newPassword)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return (User)session.CreateCriteria<User>()
|
||||
.Add(Restrictions.Eq("Name", name))
|
||||
.UniqueResult();
|
||||
}
|
||||
var dbUser = Get(x => x.Name == userData.Name && x.Password == userData.Password);
|
||||
if (dbUser == null)
|
||||
return false;
|
||||
dbUser.Password = newPassword;
|
||||
Session.Update(dbUser);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static IList<User> GetUsers()
|
||||
public User ValidateUser(string name, string password)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.CreateCriteria<User>()
|
||||
.List<User>();
|
||||
}
|
||||
return Get(x => x.Name == name && x.Password == password);
|
||||
}
|
||||
public static IList<User> GetFilteredUsers(Dictionary<string, string> filter)
|
||||
public User MsrValidateUser(string msrString)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.CreateCriteria<User>()
|
||||
.Add(Restrictions.Like("Name", string.Format("%{0}%", filter["Name"])))
|
||||
.List<User>();
|
||||
}
|
||||
return Get(x => x.MsrString == msrString);
|
||||
}
|
||||
public static bool ChangePassword(User userData, string newPassword)
|
||||
public IList<User> ListActive(DateTime startDate, DateTime finishDate)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
using (var trans = session.BeginTransaction())
|
||||
{
|
||||
var dbUser = session.CreateCriteria<User>()
|
||||
.Add(Restrictions.Eq("Name", userData.Name))
|
||||
.Add(Restrictions.Eq("Password", userData.Password))
|
||||
.UniqueResult<User>();
|
||||
if (dbUser == null)
|
||||
return false;
|
||||
dbUser.Password = newPassword;
|
||||
session.Update(dbUser);
|
||||
trans.Commit();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public static bool Exists(string userName)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
var count = session.CreateCriteria<User>()
|
||||
.Add(Restrictions.Eq("Name", userName))
|
||||
.SetProjection(Projections.Count("UserID")).UniqueResult();
|
||||
return (int)count > 0;
|
||||
}
|
||||
}
|
||||
public static User ValidateUser(string name, string password)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.CreateCriteria<User>()
|
||||
.Add(Restrictions.Eq("Name", name))
|
||||
.Add(Restrictions.Eq("Password", password))
|
||||
.UniqueResult<User>();
|
||||
}
|
||||
}
|
||||
public static User MsrValidateUser(string msrString)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
var user = session.CreateCriteria<User>()
|
||||
.Add(Restrictions.Eq("MsrString", msrString))
|
||||
.UniqueResult<User>();
|
||||
return user;
|
||||
}
|
||||
}
|
||||
public static IList<User> ListActive(DateTime startDate, DateTime finishDate)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
const string query = @"
|
||||
select distinct(u) from Voucher v
|
||||
inner join v.User u
|
||||
where v.Date >= :startDate and v.Date <= :finishDate
|
||||
order by u.Name";
|
||||
return session.CreateQuery(query)
|
||||
return Session.CreateQuery(query)
|
||||
.SetParameter("startDate", startDate)
|
||||
.SetParameter("finishDate", finishDate)
|
||||
.List<User>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NHibernate.Criterion;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using Tanshu.Accounts.Entities.Auth;
|
||||
@ -10,32 +11,6 @@ namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public static class VoucherBI
|
||||
{
|
||||
static public BillInventory GetDefaultSaleBillItem(int productID)
|
||||
{
|
||||
Product product;
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
product = session.Get<Product>(productID);
|
||||
return new BillInventory()
|
||||
{
|
||||
ProductID = product.ProductID,
|
||||
Name = product.Units == string.Empty ? product.Name : product.Name + " (" + product.Units + ")",
|
||||
Price = product.SalePrice,
|
||||
Tax = product.Tax.Rate,
|
||||
ServiceCharge = product.ServiceCharge,
|
||||
Discount = 0,
|
||||
Printed = false,
|
||||
Quantity = 1,
|
||||
};
|
||||
}
|
||||
}
|
||||
static public decimal GetProductDiscountLimit(int productID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.Get<Product>(productID).ProductGroup.DiscountLimit;
|
||||
}
|
||||
}
|
||||
static public bool IsBillPrinted(int voucherID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
@ -43,7 +18,7 @@ namespace Tanshu.Accounts.Repository
|
||||
return session.Get<Voucher>(voucherID).Printed;
|
||||
}
|
||||
}
|
||||
static public int? Insert(Voucher voucher)
|
||||
static public int? Insert(Voucher voucher, bool updateTable)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
@ -65,17 +40,18 @@ namespace Tanshu.Accounts.Repository
|
||||
item.User = voucher.User;
|
||||
item.Code = DbValues.KotCode;
|
||||
}
|
||||
UpdateSettlements(voucher, session);
|
||||
UpdateSettlements(voucher);
|
||||
session.Save(voucher);
|
||||
using (var ft = new FoodTableBI(session, true))
|
||||
ft.UpdateStatus(voucher);
|
||||
if (updateTable)
|
||||
using (var ft = new FoodTableBI(session, false))
|
||||
ft.UpdateStatus(voucher);
|
||||
trans.Commit();
|
||||
return addedKot == null ? (int?)null : addedKot.KotID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateSettlements(Voucher voucher, ISession session)
|
||||
private static void UpdateSettlements(Voucher voucher)
|
||||
{
|
||||
var amount = -1 * voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount));
|
||||
amount = Math.Round(amount, 5);
|
||||
@ -92,7 +68,10 @@ namespace Tanshu.Accounts.Repository
|
||||
|
||||
var balance = voucher.Settlements.Where(x => x.Settled != SettleOption.Unsettled).Sum(x => x.Amount) * -1;
|
||||
if (voucher.Settlements.Count(x => x.Settled == SettleOption.Unsettled) == 0)
|
||||
voucher.Settlements.Add(new VoucherSettlement() { Amount = balance, Settled = SettleOption.Unsettled });
|
||||
{
|
||||
if (balance != 0)
|
||||
voucher.Settlements.Add(new VoucherSettlement() { Amount = balance, Settled = SettleOption.Unsettled });
|
||||
}
|
||||
else if (balance == 0)
|
||||
voucher.Settlements.Remove(voucher.Settlements.Single(x => x.Settled == SettleOption.Unsettled));
|
||||
else
|
||||
@ -105,20 +84,19 @@ namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
using (var trans = session.BeginTransaction())
|
||||
{
|
||||
session.Delete(session.Get<Voucher>(voucherID));
|
||||
using (var ft = new FoodTableBI(session, true))
|
||||
var voucher = session.Get<Voucher>(voucherID);
|
||||
session.Delete(voucher);
|
||||
using (var ft = new FoodTableBI(session, false))
|
||||
{
|
||||
var table = session.QueryOver<FoodTable>()
|
||||
.Where(x => x.VoucherID == voucherID)
|
||||
.SingleOrDefault();
|
||||
ft.UpdateStatus(table.Name, voucherID, null);
|
||||
//var table = ft.Get(x=>x.VoucherID == voucherID);
|
||||
ft.UpdateStatus(voucher.TableID, voucherID, null);
|
||||
}
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public int? Update(Voucher voucher)
|
||||
static public int? Update(Voucher voucher, bool updateTable)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
@ -143,10 +121,11 @@ namespace Tanshu.Accounts.Repository
|
||||
item.User = voucher.User;
|
||||
item.Code = DbValues.KotCode;
|
||||
}
|
||||
UpdateSettlements(voucher, session);
|
||||
UpdateSettlements(voucher);
|
||||
session.Update(voucher);
|
||||
using (var ft = new FoodTableBI(session, true))
|
||||
ft.UpdateStatus(voucher);
|
||||
if (updateTable)
|
||||
using (var ft = new FoodTableBI(session, false))
|
||||
ft.UpdateStatus(voucher);
|
||||
trans.Commit();
|
||||
if (addedKot == null)
|
||||
return null;
|
||||
@ -180,10 +159,12 @@ namespace Tanshu.Accounts.Repository
|
||||
foreach (var kot in voucher.Kots)
|
||||
{
|
||||
NHibernateUtil.Initialize(kot);
|
||||
NHibernateUtil.Initialize(kot.User);
|
||||
foreach (var item in kot.Inventories)
|
||||
{
|
||||
NHibernateUtil.Initialize(item);
|
||||
NHibernateUtil.Initialize(item.Product);
|
||||
NHibernateUtil.Initialize(item.Product.ProductGroup);
|
||||
foreach (var inmod in item.InventoryModifier)
|
||||
NHibernateUtil.Initialize(inmod.Modifier);
|
||||
}
|
||||
@ -194,6 +175,17 @@ namespace Tanshu.Accounts.Repository
|
||||
}
|
||||
}
|
||||
|
||||
static public Voucher Get(string billID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
var voucher = session.CreateCriteria<Voucher>()
|
||||
.Add(Restrictions.Eq("BillID", billID))
|
||||
.UniqueResult<Voucher>();
|
||||
return voucher != null ? Get(voucher.VoucherID) : null;
|
||||
}
|
||||
}
|
||||
|
||||
static public void VoidBill(int voucherID, string reason)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
@ -218,27 +210,39 @@ namespace Tanshu.Accounts.Repository
|
||||
using (var trans = session.BeginTransaction())
|
||||
{
|
||||
var voucher = session.Get<Voucher>(voucherID);
|
||||
foreach (var item in voucher.Settlements.Where(x => x.Settled != SettleOption.Amount && x.Settled != SettleOption.RoundOff && x.Settled != SettleOption.Unsettled))
|
||||
session.Delete(item);
|
||||
foreach (var item in values.Where(x => x.Key != SettleOption.Amount && x.Key != SettleOption.RoundOff && x.Key != SettleOption.Unsettled))
|
||||
voucher.Settlements.Add(new VoucherSettlement { Settled = item.Key, Amount = item.Value });
|
||||
UpdateSettlements(voucher, session);
|
||||
|
||||
for (var i = voucher.Settlements.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var item = voucher.Settlements[i];
|
||||
if (item.Settled == SettleOption.Amount || item.Settled == SettleOption.RoundOff || item.Settled == SettleOption.Unsettled)
|
||||
continue;
|
||||
if (!values.ContainsKey(item.Settled))
|
||||
voucher.Settlements.Remove(item);
|
||||
else
|
||||
item.Amount = values[item.Settled];
|
||||
|
||||
}
|
||||
foreach (var item in values)
|
||||
{
|
||||
if (voucher.Settlements.Count(x => x.Settled == item.Key) == 0)
|
||||
voucher.Settlements.Add(new VoucherSettlement { Settled = item.Key, Amount = item.Value });
|
||||
}
|
||||
UpdateSettlements(voucher);
|
||||
voucher.User = user;
|
||||
voucher.LastEditDate = DbValues.Date;
|
||||
session.Update(voucher);
|
||||
using (var ft = new FoodTableBI(session, true))
|
||||
ft.UpdateStatus(voucher);
|
||||
using (var ft = new FoodTableBI(session, false))
|
||||
ft.TableSettled(voucher);
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static int MoveKot(int kotID, FoodTable foodTable)
|
||||
public static int MergeKot(int kotID, FoodTable foodTable)
|
||||
{
|
||||
var session = SessionManager.Session;
|
||||
using (var trans = session.BeginTransaction())
|
||||
{
|
||||
var kot = session.Get<Kot>(kotID);
|
||||
foodTable = session.Get<FoodTable>(foodTable.FoodTableID);
|
||||
var voucher = session.Get<Voucher>(foodTable.VoucherID);
|
||||
voucher.Kots.Add(kot);
|
||||
session.Update(voucher);
|
||||
@ -246,6 +250,17 @@ namespace Tanshu.Accounts.Repository
|
||||
return voucher.VoucherID;
|
||||
}
|
||||
}
|
||||
|
||||
public static int MergeKot(int kotID, Voucher voucher)
|
||||
{
|
||||
var session = SessionManager.Session;
|
||||
using (var trans = session.BeginTransaction())
|
||||
{
|
||||
var kot = session.Get<Kot>(kotID);
|
||||
voucher.Kots.Add(kot);
|
||||
session.Update(voucher);
|
||||
trans.Commit();
|
||||
return voucher.VoucherID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user