Updated NH, Code Refactoring, made all DB transactions atomic.
Must use the Repositories with Using or else bad things will happen.
This commit is contained in:
@ -1,64 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using System.Data.SqlClient;
|
||||
using Tanshu.Data.DAO;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using Tanshu.Accounts.SqlDAO;
|
||||
using Tanshu.Accounts.Entities.Auth;
|
||||
using NHibernate;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class AdvanceBI
|
||||
public class AdvanceBI : FluentGenericBase<Advance>
|
||||
{
|
||||
public void Insert(Advance advance)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
using (var trans = session.BeginTransaction())
|
||||
{
|
||||
session.Save(advance);
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
public AdvanceBI()
|
||||
: base()
|
||||
{ }
|
||||
public AdvanceBI(bool beginTransaction)
|
||||
: base(beginTransaction)
|
||||
{ }
|
||||
public AdvanceBI(ISession session)
|
||||
: base(session)
|
||||
{ }
|
||||
public AdvanceBI(ISession session, bool beginTransaction)
|
||||
: base(session, beginTransaction)
|
||||
{ }
|
||||
|
||||
public IList<Advance> GetAdvances(DateTime startDate, DateTime finishDate, bool all)
|
||||
{
|
||||
startDate = startDate.Date;
|
||||
finishDate = finishDate.Date.AddHours(23).AddMinutes(59).AddSeconds(59);
|
||||
using (var session = SessionManager.Session)
|
||||
var query = from ad in Session.QueryOver<Advance>()
|
||||
where ad.DateIn >= startDate && ad.DateIn <= finishDate
|
||||
select ad;
|
||||
if (!all)
|
||||
query = from a in query
|
||||
where a.CashierOut == null
|
||||
select a;
|
||||
var list = query.List();
|
||||
foreach (var item in list)
|
||||
{
|
||||
var query = from ad in session.QueryOver<Advance>()
|
||||
where ad.DateIn >= startDate && ad.DateIn <= finishDate
|
||||
select ad;
|
||||
if (!all)
|
||||
query = from a in query
|
||||
where a.CashierOut == null
|
||||
select a;
|
||||
var list = query.List();
|
||||
foreach (var item in list)
|
||||
{
|
||||
NHibernateUtil.Initialize(item.CashierIn);
|
||||
NHibernateUtil.Initialize(item.CashierOut);
|
||||
}
|
||||
return list;
|
||||
NHibernateUtil.Initialize(item.CashierIn);
|
||||
NHibernateUtil.Initialize(item.CashierOut);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
public void Adjust(int advanceID, int userID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
using (var trans = session.BeginTransaction())
|
||||
{
|
||||
var advance = session.Get<Advance>(advanceID);
|
||||
advance.DateOut = DbValues.Date;
|
||||
advance.CashierOut = session.Get<User>(userID);
|
||||
session.Update(advance);
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
var advance = Session.Get<Advance>(advanceID);
|
||||
advance.DateOut = DbValues.Date;
|
||||
advance.CashierOut = Session.Get<User>(userID);
|
||||
Session.Update(advance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,75 +1,30 @@
|
||||
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.SqlDAO;
|
||||
using System.Collections.Generic;
|
||||
using NHibernate;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using NHibernate.Criterion;
|
||||
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class CustomerBI
|
||||
public class CustomerBI : FluentGenericBase<Customer>
|
||||
{
|
||||
public Customer GetCustomer(int customerID)
|
||||
public CustomerBI()
|
||||
: base()
|
||||
{ }
|
||||
public CustomerBI(bool beginTransaction)
|
||||
: base(beginTransaction)
|
||||
{ }
|
||||
public CustomerBI(ISession session)
|
||||
: base(session)
|
||||
{ }
|
||||
public CustomerBI(ISession session, bool beginTransaction)
|
||||
: base(session, beginTransaction)
|
||||
{ }
|
||||
public static IList<Customer> List(Dictionary<string, string> filter)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.Get<Customer>(customerID);
|
||||
}
|
||||
}
|
||||
public IList<Customer> GetCustomers()
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.CreateCriteria<Customer>().List<Customer>();
|
||||
}
|
||||
}
|
||||
public IList<Customer> GetSingleCustomers(int customerID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.CreateCriteria<Customer>()
|
||||
.Add(Restrictions.Eq("CustomerID", customerID))
|
||||
.List<Customer>();
|
||||
}
|
||||
}
|
||||
public void Update(Customer customer)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Update(customer);
|
||||
}
|
||||
}
|
||||
public bool Delete(int customerID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Delete(new Customer() { CustomerID = customerID });
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public void Insert(Customer customer)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Save(customer);
|
||||
}
|
||||
}
|
||||
|
||||
public IList<Customer> GetFilteredCustomers(Dictionary<string, string> filter)
|
||||
{
|
||||
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
string name = string.Format("%{0}%", filter["Universal"]);
|
||||
return session.CreateCriteria<Customer>()
|
||||
.Add(Restrictions.Like("Name", name))
|
||||
.List<Customer>();
|
||||
}
|
||||
using (var bi = new CustomerBI(false))
|
||||
return bi.Query()
|
||||
.WhereRestrictionOn(x => x.Name).IsLike(string.Format("%{0}%", filter["Universal"]))
|
||||
.List();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using NHibernate;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class FluentBasicBase : IDisposable
|
||||
{
|
||||
protected readonly bool DisposeSession;
|
||||
protected readonly ISession Session;
|
||||
protected readonly ITransaction Transaction;
|
||||
|
||||
public FluentBasicBase()
|
||||
{
|
||||
Session = SessionManager.Session;
|
||||
DisposeSession = true;
|
||||
Transaction = Session.BeginTransaction();
|
||||
|
||||
}
|
||||
public FluentBasicBase(bool beginTransaction)
|
||||
{
|
||||
Session = SessionManager.Session;
|
||||
DisposeSession = true;
|
||||
if (beginTransaction)
|
||||
Transaction = Session.BeginTransaction();
|
||||
}
|
||||
public FluentBasicBase(ISession session)
|
||||
{
|
||||
this.Session = session;
|
||||
DisposeSession = false;
|
||||
}
|
||||
public FluentBasicBase(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();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -5,32 +5,32 @@ using NHibernate;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class FluentBase<T> : IDisposable, IRepository<T> where T : class
|
||||
public class FluentGenericBase<T> : IDisposable, IRepository<T> where T : class
|
||||
{
|
||||
protected readonly bool DisposeSession;
|
||||
protected readonly ISession Session;
|
||||
protected readonly ITransaction Transaction;
|
||||
|
||||
public FluentBase()
|
||||
public FluentGenericBase()
|
||||
{
|
||||
Session = SessionManager.Session;
|
||||
DisposeSession = true;
|
||||
Transaction = Session.BeginTransaction();
|
||||
|
||||
}
|
||||
public FluentBase(bool beginTransaction)
|
||||
public FluentGenericBase(bool beginTransaction)
|
||||
{
|
||||
Session = SessionManager.Session;
|
||||
DisposeSession = true;
|
||||
if (beginTransaction)
|
||||
Transaction = Session.BeginTransaction();
|
||||
}
|
||||
public FluentBase(ISession session)
|
||||
public FluentGenericBase(ISession session)
|
||||
{
|
||||
this.Session = session;
|
||||
DisposeSession = false;
|
||||
}
|
||||
public FluentBase(ISession session, bool beginTransaction)
|
||||
public FluentGenericBase(ISession session, bool beginTransaction)
|
||||
{
|
||||
this.Session = session;
|
||||
DisposeSession = false;
|
||||
@ -71,7 +71,7 @@ namespace Tanshu.Accounts.Repository
|
||||
// }
|
||||
// // get rid of unmanaged resources
|
||||
//}
|
||||
//~FluentBase()
|
||||
//~FluentGenericBase()
|
||||
//{
|
||||
// Dispose(false);
|
||||
//}
|
||||
@ -131,6 +131,10 @@ namespace Tanshu.Accounts.Repository
|
||||
Delete(item);
|
||||
}
|
||||
|
||||
public IQueryOver<T, T> Query()
|
||||
{
|
||||
return Session.QueryOver<T>();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -1,13 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NHibernate;
|
||||
using NHibernate.Criterion;
|
||||
using NHibernate;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using System.Linq;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class FoodTableBI : FluentBase<FoodTable>
|
||||
public class FoodTableBI : FluentGenericBase<FoodTable>
|
||||
{
|
||||
public FoodTableBI()
|
||||
: base()
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using NHibernate;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
@ -17,5 +18,7 @@ namespace Tanshu.Accounts.Repository
|
||||
|
||||
IList<T> List();
|
||||
IList<T> List(Expression<Func<T, bool>> query);
|
||||
|
||||
IQueryOver<T, T> Query();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
using System.Text;
|
||||
using System.Data.SqlClient;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using Tanshu.Data.DAO;
|
||||
using Tanshu.Accounts.SqlDAO;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using System.Collections.Generic;
|
||||
using Tanshu.Accounts.Entities.Auth;
|
||||
using NHibernate.Criterion;
|
||||
using NHibernate.Linq;
|
||||
using NHibernate;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
|
||||
@ -3,19 +3,19 @@ using Tanshu.Accounts.Entities;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class ModifierBI : FluentBase<Modifier>
|
||||
public class ModifierBI : FluentGenericBase<Modifier>
|
||||
{
|
||||
public ModifierBI(ISession session)
|
||||
: base(session)
|
||||
{ }
|
||||
public ModifierBI()
|
||||
: base()
|
||||
{ }
|
||||
public ModifierBI(bool useTransaction)
|
||||
: base(useTransaction)
|
||||
public ModifierBI(bool beginTransaction)
|
||||
: base(beginTransaction)
|
||||
{ }
|
||||
public ModifierBI(ISession session, bool useTransaction)
|
||||
: base(session, useTransaction)
|
||||
public ModifierBI(ISession session)
|
||||
: base(session)
|
||||
{ }
|
||||
public ModifierBI(ISession session, bool beginTransaction)
|
||||
: base(session, beginTransaction)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,23 +1,36 @@
|
||||
using System.Configuration;
|
||||
using NHibernate;
|
||||
using Tanshu.Accounts.Entities;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class PrintLocationBI : FluentBase<PrintLocation>
|
||||
public class PrintLocationBI : FluentGenericBase<PrintLocation>
|
||||
{
|
||||
public PrintLocationBI()
|
||||
: base()
|
||||
{ }
|
||||
public PrintLocationBI(bool beginTransaction)
|
||||
: base(beginTransaction)
|
||||
{ }
|
||||
public PrintLocationBI(ISession session)
|
||||
: base(session)
|
||||
{ }
|
||||
public PrintLocationBI(ISession session, bool beginTransaction)
|
||||
: base(session, beginTransaction)
|
||||
{ }
|
||||
public static PrintLocation BasePrinter
|
||||
{
|
||||
get
|
||||
{
|
||||
var location = ConfigurationManager.AppSettings["Location"].ToLowerInvariant();
|
||||
using (var bi = new PrintLocationBI())
|
||||
using (var bi = new PrintLocationBI(false))
|
||||
return bi.Get(x => x.Location == location && x.ProductGroup == null);
|
||||
}
|
||||
}
|
||||
public static PrintLocation KotPrinter(int productGroupID)
|
||||
{
|
||||
var location = ConfigurationManager.AppSettings["Location"].ToLowerInvariant();
|
||||
using (var bi = new PrintLocationBI())
|
||||
using (var bi = new PrintLocationBI(false))
|
||||
return bi.Get(x => x.Location == location && x.ProductGroup.ProductGroupID == productGroupID) ??
|
||||
bi.Get(x => x.Location == location && x.ProductGroup == null);
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ using NHibernate;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class ProductBI : FluentBase<Product>
|
||||
public class ProductBI : FluentGenericBase<Product>
|
||||
{
|
||||
public ProductBI()
|
||||
: base()
|
||||
@ -32,7 +32,11 @@ namespace Tanshu.Accounts.Repository
|
||||
}
|
||||
public new IList<Product> List(Expression<Func<Product, bool>> query)
|
||||
{
|
||||
var list = base.List(query);
|
||||
var list = Query()
|
||||
.Where(query)
|
||||
.OrderBy(x => x.SortOrder).Asc
|
||||
.ThenBy(x => x.Name).Asc
|
||||
.List();
|
||||
foreach (var item in list)
|
||||
{
|
||||
NHibernateUtil.Initialize(item.ProductGroup);
|
||||
@ -43,7 +47,11 @@ namespace Tanshu.Accounts.Repository
|
||||
|
||||
public new IList<Product> List()
|
||||
{
|
||||
var list = base.List();
|
||||
var list = Query()
|
||||
.OrderBy(x => x.ProductGroup).Asc
|
||||
.ThenBy(x => x.SortOrder).Asc
|
||||
.ThenBy(x => x.Name).Asc
|
||||
.List();
|
||||
foreach (var item in list)
|
||||
{
|
||||
NHibernateUtil.Initialize(item.ProductGroup);
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using NHibernate;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class ProductGroupBI : FluentBase<ProductGroup>
|
||||
public class ProductGroupBI : FluentGenericBase<ProductGroup>
|
||||
{
|
||||
public ProductGroupBI()
|
||||
: base()
|
||||
@ -24,8 +26,17 @@ namespace Tanshu.Accounts.Repository
|
||||
|
||||
public new IList<ProductGroup> List()
|
||||
{
|
||||
return Session.QueryOver<ProductGroup>()
|
||||
.OrderBy(x => x.Name).Asc
|
||||
return Query()
|
||||
.OrderBy(x => x.SortOrder).Asc
|
||||
.ThenBy(x => x.Name).Asc
|
||||
.List();
|
||||
}
|
||||
public new IList<ProductGroup> List(Expression<Func<ProductGroup, bool>> query)
|
||||
{
|
||||
return Query()
|
||||
.Where(query)
|
||||
.OrderBy(x => x.SortOrder).Asc
|
||||
.ThenBy(x => x.Name).Asc
|
||||
.List();
|
||||
}
|
||||
public IList<string> GetProductGroupTypes()
|
||||
|
||||
@ -1,62 +1,37 @@
|
||||
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 static class ProductGroupModifierBI
|
||||
public class ProductGroupModifierBI : FluentGenericBase<ProductGroupModifier>
|
||||
{
|
||||
public static void Insert(ProductGroupModifier productGroupModifier)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Save(productGroupModifier);
|
||||
}
|
||||
}
|
||||
public static void Update(ProductGroupModifier productGroupModifier)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Update(productGroupModifier);
|
||||
}
|
||||
}
|
||||
public static void Delete(int productGroupModifierID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Delete(new ProductGroupModifier() { ProductGroupModifierID = productGroupModifierID });
|
||||
}
|
||||
}
|
||||
public static IList<ProductGroupModifier> GetProductGroupModifiers()
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.CreateCriteria<ProductGroupModifier>()
|
||||
.List<ProductGroupModifier>();
|
||||
}
|
||||
}
|
||||
public ProductGroupModifierBI()
|
||||
: base()
|
||||
{ }
|
||||
|
||||
public static IList<Modifier> GetProductGroupModifiers(int productGroupID)
|
||||
public ProductGroupModifierBI(bool beginTransaction)
|
||||
: base(beginTransaction)
|
||||
{ }
|
||||
|
||||
public ProductGroupModifierBI(ISession session)
|
||||
: base(session)
|
||||
{ }
|
||||
|
||||
public ProductGroupModifierBI(ISession session, bool beginTransaction)
|
||||
: base(session, beginTransaction)
|
||||
{ }
|
||||
|
||||
public IList<Modifier> List(int productGroupID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
var list = (from pgm in session.QueryOver<ProductGroupModifier>()
|
||||
var list = (from pgm in Session.QueryOver<ProductGroupModifier>()
|
||||
where pgm.ProductGroup == null || pgm.ProductGroup.ProductGroupID == productGroupID
|
||||
select pgm.Modifier).Fetch(x => x.Modifier).Eager.List<Modifier>();
|
||||
//NHibernateUtil.Initialize(list);
|
||||
foreach (var item in list)
|
||||
NHibernateUtil.Initialize(item);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
public static bool HasCompulsoryModifier(int productGroupID)
|
||||
public bool HasCompulsoryModifier(int productGroupID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
@ -65,32 +40,6 @@ namespace Tanshu.Accounts.Repository
|
||||
select gf;
|
||||
int c = l.RowCount();
|
||||
return c > 0;
|
||||
// var a = session.CreateQuery(@"
|
||||
//select count(pgm)
|
||||
//from ProductGroupModifier as pgm
|
||||
//where pgm.ShowAutomatically = true
|
||||
//and (ProductGroupID is null or ProductGroupID = :ProductGroupID")
|
||||
// .SetInt32("ProductGroupID", productGroupID)
|
||||
// .UniqueResult<int>();
|
||||
// return a > 0;
|
||||
//var count1 = session.CreateCriteria<ProductGroupModifier>()
|
||||
// .Add(Restrictions.Eq("ShowAutomatically", true))
|
||||
// .Add(Restrictions.IsNull("ProductGroupID"))
|
||||
// .SetProjection(Projections.Count("ProductGroupModifierID")).UniqueResult();
|
||||
//return (int)count1 > 0;
|
||||
|
||||
////var count = session.CreateSQLQuery (@"
|
||||
////SELECT COUNT(*) FROM Entities_ProductGroupModifiers WHERE
|
||||
////var counts = session.QueryOver<ProductGroupModifier>()
|
||||
//// .Where(c => c.ShowAutomatically == true)
|
||||
//// .Select(Projections.Count("ProductGroupModifierID"));
|
||||
//var count = session.CreateCriteria<ProductGroupModifier>()
|
||||
// .Add(Restrictions.Eq("ShowAutomatically", true))
|
||||
// .Add(Expression.Conjunction()
|
||||
// .Add(Restrictions.Eq("ProductGroupID", productGroupID))
|
||||
// .Add(Restrictions.IsNull("ProductGroupID")))
|
||||
// .SetProjection(Projections.Count("ProductGroupModifierID")).UniqueResult();
|
||||
//return (int)count > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,19 +4,19 @@ using Tanshu.Accounts.Entities;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class TaxBI : FluentBase<Tax>
|
||||
public class TaxBI : FluentGenericBase<Tax>
|
||||
{
|
||||
public TaxBI(ISession session)
|
||||
: base(session)
|
||||
{ }
|
||||
public TaxBI()
|
||||
: base()
|
||||
{ }
|
||||
public TaxBI(bool useTransaction)
|
||||
: base(useTransaction)
|
||||
public TaxBI(bool beginTransaction)
|
||||
: base(beginTransaction)
|
||||
{ }
|
||||
public TaxBI(ISession session, bool useTransaction)
|
||||
: base(session, useTransaction)
|
||||
public TaxBI(ISession session)
|
||||
: base(session)
|
||||
{ }
|
||||
public TaxBI(ISession session, bool beginTransaction)
|
||||
: base(session, beginTransaction)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,24 +6,24 @@ using Tanshu.Accounts.Entities.Auth;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class UserBI : FluentBase<User>
|
||||
public class UserBI : FluentGenericBase<User>
|
||||
{
|
||||
public UserBI()
|
||||
: base()
|
||||
{ }
|
||||
public UserBI(bool useTransaction)
|
||||
: base(useTransaction)
|
||||
public UserBI(bool beginTransaction)
|
||||
: base(beginTransaction)
|
||||
{ }
|
||||
public UserBI(ISession session)
|
||||
: base(session)
|
||||
{ }
|
||||
public UserBI(ISession session, bool useTransaction)
|
||||
: base(session, useTransaction)
|
||||
public UserBI(ISession session, bool beginTransaction)
|
||||
: base(session, beginTransaction)
|
||||
{ }
|
||||
|
||||
public IList<User> GetFilteredUsers(Dictionary<string, string> filter)
|
||||
{
|
||||
return Session.QueryOver<User>()
|
||||
return Query()
|
||||
.WhereRestrictionOn(x => x.Name).IsLike(string.Format("%{0}%", filter["Name"]))
|
||||
.List();
|
||||
}
|
||||
@ -46,15 +46,15 @@ namespace Tanshu.Accounts.Repository
|
||||
}
|
||||
public IList<User> ListActive(DateTime startDate, DateTime finishDate)
|
||||
{
|
||||
const string query = @"
|
||||
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)
|
||||
.SetParameter("startDate", startDate)
|
||||
.SetParameter("finishDate", finishDate)
|
||||
.List<User>();
|
||||
}
|
||||
return Session.CreateQuery(query)
|
||||
.SetParameter("startDate", startDate)
|
||||
.SetParameter("finishDate", finishDate)
|
||||
.List<User>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,266 +1,145 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NHibernate.Criterion;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using NHibernate.Criterion;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using Tanshu.Accounts.Entities.Auth;
|
||||
using NHibernate;
|
||||
using System.Linq;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public static class VoucherBI
|
||||
public class VoucherBI : FluentBasicBase
|
||||
{
|
||||
static public bool IsBillPrinted(int voucherID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.Get<Voucher>(voucherID).Printed;
|
||||
}
|
||||
}
|
||||
static public int? Insert(Voucher voucher, bool updateTable)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
using (var trans = session.BeginTransaction())
|
||||
{
|
||||
var dt = DbValues.Date;
|
||||
voucher.CreationDate = dt;
|
||||
voucher.LastEditDate = dt;
|
||||
voucher.Date = dt;
|
||||
voucher.KotID = DbValues.KotID;
|
||||
voucher.BillID = voucher.Printed ? DbValues.BillID : voucher.KotID;
|
||||
Kot addedKot = null;
|
||||
foreach (var item in voucher.Kots.Where(item => item.KotID == 0))
|
||||
{
|
||||
addedKot = item;
|
||||
item.Date = dt;
|
||||
item.Printed = true;
|
||||
item.TableID = voucher.TableID;
|
||||
item.User = voucher.User;
|
||||
item.Code = DbValues.KotCode;
|
||||
}
|
||||
UpdateSettlements(voucher);
|
||||
session.Save(voucher);
|
||||
if (updateTable)
|
||||
using (var ft = new FoodTableBI(session, false))
|
||||
ft.UpdateStatus(voucher);
|
||||
trans.Commit();
|
||||
return addedKot == null ? (int?)null : addedKot.KotID;
|
||||
}
|
||||
}
|
||||
}
|
||||
public VoucherBI()
|
||||
: base()
|
||||
{ }
|
||||
public VoucherBI(bool beginTransaction)
|
||||
: base(beginTransaction)
|
||||
{ }
|
||||
public VoucherBI(ISession session)
|
||||
: base(session)
|
||||
{ }
|
||||
public VoucherBI(ISession session, bool beginTransaction)
|
||||
: base(session, beginTransaction)
|
||||
{ }
|
||||
|
||||
private static void UpdateSettlements(Voucher voucher)
|
||||
public bool IsVoucherPrinted(int voucherID)
|
||||
{
|
||||
return Session.Get<Voucher>(voucherID).Printed;
|
||||
}
|
||||
public int? Insert(Voucher voucher)
|
||||
{
|
||||
var dt = DbValues.Date;
|
||||
voucher.CreationDate = dt;
|
||||
voucher.LastEditDate = dt;
|
||||
voucher.Date = dt;
|
||||
voucher.KotID = DbValues.KotID;
|
||||
voucher.BillID = voucher.Printed ? DbValues.BillID : voucher.KotID;
|
||||
Kot addedKot = null;
|
||||
foreach (var item in voucher.Kots.Where(item => item.KotID == 0))
|
||||
{
|
||||
addedKot = item;
|
||||
item.Date = dt;
|
||||
item.Printed = true;
|
||||
item.TableID = voucher.TableID;
|
||||
item.User = voucher.User;
|
||||
item.Code = DbValues.KotCode;
|
||||
}
|
||||
var amount = -1 * voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount));
|
||||
amount = Math.Round(amount, 5);
|
||||
if (voucher.Settlements.Count(x => x.Settled == SettleOption.Amount) == 0)
|
||||
voucher.Settlements.Add(new VoucherSettlement() { Amount = amount, Settled = SettleOption.Amount });
|
||||
else
|
||||
voucher.Settlements.Single(x => x.Settled == SettleOption.Amount).Amount = amount;
|
||||
|
||||
var roundoff = Math.Round(amount) - amount;
|
||||
if (voucher.Settlements.Count(x => x.Settled == SettleOption.RoundOff) == 0)
|
||||
voucher.Settlements.Add(new VoucherSettlement() { Amount = roundoff, Settled = SettleOption.RoundOff });
|
||||
else
|
||||
voucher.Settlements.Single(x => x.Settled == SettleOption.RoundOff).Amount = roundoff;
|
||||
|
||||
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)
|
||||
{
|
||||
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
|
||||
voucher.Settlements.Single(x => x.Settled == SettleOption.Unsettled).Amount = balance;
|
||||
VoucherSettlementBI.UpdateSettlements(voucher.Settlements, amount);
|
||||
Session.Save(voucher);
|
||||
return addedKot == null ? (int?)null : addedKot.KotID;
|
||||
}
|
||||
|
||||
public static void Delete(int voucherID)
|
||||
public void Delete(int voucherID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
using (var trans = session.BeginTransaction())
|
||||
{
|
||||
var voucher = session.Get<Voucher>(voucherID);
|
||||
session.Delete(voucher);
|
||||
using (var ft = new FoodTableBI(session, false))
|
||||
{
|
||||
//var table = ft.Get(x=>x.VoucherID == voucherID);
|
||||
ft.UpdateStatus(voucher.TableID, voucherID, null);
|
||||
}
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
var voucher = Session.Get<Voucher>(voucherID);
|
||||
Session.Delete(voucher);
|
||||
using (var ft = new FoodTableBI(Session, false))
|
||||
ft.UpdateStatus(voucher.TableID, voucherID, null);
|
||||
}
|
||||
|
||||
static public int? Update(Voucher voucher, bool updateTable)
|
||||
public int? Update(Voucher voucher)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
var dt = DbValues.Date;
|
||||
voucher.LastEditDate = dt;
|
||||
if (voucher.Date == null)
|
||||
{
|
||||
using (var trans = session.BeginTransaction())
|
||||
{
|
||||
var dt = DbValues.Date;
|
||||
voucher.LastEditDate = dt;
|
||||
if (voucher.Date == null)
|
||||
{
|
||||
voucher.Date = dt;
|
||||
voucher.BillID = DbValues.BillID;
|
||||
}
|
||||
if (!voucher.Printed)
|
||||
voucher.Date = dt;
|
||||
Kot addedKot = null;
|
||||
foreach (var item in voucher.Kots.Where(item => item.KotID == 0))
|
||||
{
|
||||
addedKot = item;
|
||||
item.Date = dt;
|
||||
item.Printed = true;
|
||||
item.TableID = voucher.TableID;
|
||||
item.User = voucher.User;
|
||||
item.Code = DbValues.KotCode;
|
||||
}
|
||||
UpdateSettlements(voucher);
|
||||
session.Update(voucher);
|
||||
if (updateTable)
|
||||
using (var ft = new FoodTableBI(session, false))
|
||||
ft.UpdateStatus(voucher);
|
||||
trans.Commit();
|
||||
if (addedKot == null)
|
||||
return null;
|
||||
else
|
||||
return addedKot.KotID;
|
||||
}
|
||||
voucher.Date = dt;
|
||||
voucher.BillID = DbValues.BillID;
|
||||
}
|
||||
}
|
||||
//static private void UpdateTable(Voucher voucher, ISession session)
|
||||
//{
|
||||
// using (var ft = new FoodTableBI(session, true))
|
||||
// {
|
||||
// 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;
|
||||
// ft.UpdateStatus(voucher.TableID, voucher.VoucherID, status);
|
||||
// }
|
||||
//}
|
||||
static public Voucher Get(int voucherID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
if (!voucher.Printed)
|
||||
voucher.Date = dt;
|
||||
Kot addedKot = null;
|
||||
foreach (var item in voucher.Kots.Where(item => item.KotID == 0))
|
||||
{
|
||||
var voucher = session.Get<Voucher>(voucherID);
|
||||
NHibernateUtil.Initialize(voucher.Customer);
|
||||
NHibernateUtil.Initialize(voucher.Waiter);
|
||||
NHibernateUtil.Initialize(voucher.User);
|
||||
foreach (var kot in voucher.Kots)
|
||||
addedKot = item;
|
||||
item.Date = dt;
|
||||
item.Printed = true;
|
||||
item.TableID = voucher.TableID;
|
||||
item.User = voucher.User;
|
||||
item.Code = DbValues.KotCode;
|
||||
}
|
||||
var amount = -1 * voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount));
|
||||
VoucherSettlementBI.UpdateSettlements(voucher.Settlements, amount);
|
||||
Session.Update(voucher);
|
||||
if (addedKot == null)
|
||||
return null;
|
||||
else
|
||||
return addedKot.KotID;
|
||||
}
|
||||
|
||||
public Voucher Get(int voucherID)
|
||||
{
|
||||
var voucher = Session.Get<Voucher>(voucherID);
|
||||
NHibernateUtil.Initialize(voucher.Customer);
|
||||
NHibernateUtil.Initialize(voucher.Waiter);
|
||||
NHibernateUtil.Initialize(voucher.User);
|
||||
foreach (var kot in voucher.Kots)
|
||||
{
|
||||
NHibernateUtil.Initialize(kot);
|
||||
NHibernateUtil.Initialize(kot.User);
|
||||
foreach (var item in kot.Inventories)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
foreach (var item in voucher.Settlements)
|
||||
NHibernateUtil.Initialize(item);
|
||||
return voucher;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
using (var trans = session.BeginTransaction())
|
||||
{
|
||||
var voucher = session.Get<Voucher>(voucherID);
|
||||
voucher.Void = true;
|
||||
voucher.VoidReason = reason;
|
||||
session.Save(voucher);
|
||||
using (var ft = new FoodTableBI(session, true))
|
||||
ft.UpdateStatus(voucher);
|
||||
trans.Commit();
|
||||
NHibernateUtil.Initialize(item.Product);
|
||||
NHibernateUtil.Initialize(item.Product.ProductGroup);
|
||||
foreach (var inmod in item.InventoryModifier)
|
||||
NHibernateUtil.Initialize(inmod.Modifier);
|
||||
}
|
||||
}
|
||||
foreach (var item in voucher.Settlements)
|
||||
NHibernateUtil.Initialize(item);
|
||||
return voucher;
|
||||
}
|
||||
|
||||
static public void SettleVoucher(User user, int voucherID, IDictionary<SettleOption, decimal> values)
|
||||
public Voucher Get(string billID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
using (var trans = session.BeginTransaction())
|
||||
{
|
||||
var voucher = session.Get<Voucher>(voucherID);
|
||||
|
||||
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, false))
|
||||
ft.TableSettled(voucher);
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
var voucher = Session.CreateCriteria<Voucher>()
|
||||
.Add(Restrictions.Eq("BillID", billID))
|
||||
.UniqueResult<Voucher>();
|
||||
return voucher != null ? Get(voucher.VoucherID) : null;
|
||||
}
|
||||
public static int MergeKot(int kotID, FoodTable foodTable)
|
||||
|
||||
public void VoidBill(int voucherID, string reason)
|
||||
{
|
||||
var session = SessionManager.Session;
|
||||
using (var trans = session.BeginTransaction())
|
||||
{
|
||||
var kot = session.Get<Kot>(kotID);
|
||||
var voucher = session.Get<Voucher>(foodTable.VoucherID);
|
||||
voucher.Kots.Add(kot);
|
||||
session.Update(voucher);
|
||||
trans.Commit();
|
||||
return voucher.VoucherID;
|
||||
}
|
||||
var voucher = Session.Get<Voucher>(voucherID);
|
||||
voucher.Void = true;
|
||||
voucher.VoidReason = reason;
|
||||
Session.Save(voucher);
|
||||
}
|
||||
public static int MergeKot(int kotID, Voucher voucher)
|
||||
|
||||
public int MergeKot(int kotID, FoodTable foodTable)
|
||||
{
|
||||
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;
|
||||
}
|
||||
var kot = Session.Get<Kot>(kotID);
|
||||
var voucher = Session.Get<Voucher>(foodTable.VoucherID);
|
||||
voucher.Kots.Add(kot);
|
||||
Session.Update(voucher);
|
||||
return voucher.VoucherID;
|
||||
}
|
||||
public int MergeKot(int kotID, Voucher voucher)
|
||||
{
|
||||
var kot = Session.Get<Kot>(kotID);
|
||||
voucher.Kots.Add(kot);
|
||||
Session.Update(voucher);
|
||||
return voucher.VoucherID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using Tanshu.Accounts.Entities.Auth;
|
||||
using NHibernate;
|
||||
using System.Linq;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class VoucherSettlementBI : FluentBasicBase
|
||||
{
|
||||
public VoucherSettlementBI()
|
||||
: base()
|
||||
{ }
|
||||
public VoucherSettlementBI(bool beginTransaction)
|
||||
: base(beginTransaction)
|
||||
{ }
|
||||
public VoucherSettlementBI(ISession session)
|
||||
: base(session)
|
||||
{ }
|
||||
public VoucherSettlementBI(ISession session, bool beginTransaction)
|
||||
: base(session, beginTransaction)
|
||||
{ }
|
||||
|
||||
public static void UpdateSettlements(IList<VoucherSettlement> list, decimal amount)
|
||||
{
|
||||
amount = Math.Round(amount, 5);
|
||||
if (list.Count(x => x.Settled == SettleOption.Amount) == 0)
|
||||
list.Add(new VoucherSettlement() { Amount = amount, Settled = SettleOption.Amount });
|
||||
else
|
||||
list.Single(x => x.Settled == SettleOption.Amount).Amount = amount;
|
||||
|
||||
var roundoff = Math.Round(amount) - amount;
|
||||
if (list.Count(x => x.Settled == SettleOption.RoundOff) == 0)
|
||||
list.Add(new VoucherSettlement() { Amount = roundoff, Settled = SettleOption.RoundOff });
|
||||
else
|
||||
list.Single(x => x.Settled == SettleOption.RoundOff).Amount = roundoff;
|
||||
|
||||
var balance = list.Where(x => x.Settled != SettleOption.Unsettled).Sum(x => x.Amount) * -1;
|
||||
if (list.Count(x => x.Settled == SettleOption.Unsettled) == 0)
|
||||
{
|
||||
if (balance != 0)
|
||||
list.Add(new VoucherSettlement() { Amount = balance, Settled = SettleOption.Unsettled });
|
||||
}
|
||||
else if (balance == 0)
|
||||
list.Remove(list.Single(x => x.Settled == SettleOption.Unsettled));
|
||||
else
|
||||
list.Single(x => x.Settled == SettleOption.Unsettled).Amount = balance;
|
||||
}
|
||||
|
||||
public void SettleVoucher(User user, int voucherID, IDictionary<SettleOption, decimal> values)
|
||||
{
|
||||
var voucher = Session.Get<Voucher>(voucherID);
|
||||
|
||||
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 });
|
||||
}
|
||||
var amount = -1 * voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount));
|
||||
UpdateSettlements(voucher.Settlements, amount);
|
||||
voucher.User = user;
|
||||
voucher.LastEditDate = DbValues.Date;
|
||||
Session.Update(voucher);
|
||||
using (var ft = new FoodTableBI(Session, false))
|
||||
ft.TableSettled(voucher);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user