Errors updated. Do not use old build.
This commit is contained in:
64
Tanshu.Accounts.Repository/BusinessLayer/AdvanceBI.cs
Normal file
64
Tanshu.Accounts.Repository/BusinessLayer/AdvanceBI.cs
Normal file
@ -0,0 +1,64 @@
|
||||
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 void Insert(Advance advance)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
using (var trans = session.BeginTransaction())
|
||||
{
|
||||
session.Save(advance);
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
350
Tanshu.Accounts.Repository/BusinessLayer/CheckoutBI.cs
Normal file
350
Tanshu.Accounts.Repository/BusinessLayer/CheckoutBI.cs
Normal file
@ -0,0 +1,350 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using Tanshu.Accounts.Entities.Auth;
|
||||
using NHibernate.Criterion;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class CheckoutBI
|
||||
{
|
||||
#region Properties
|
||||
public decimal Opening { get; private set; }
|
||||
public decimal Receipts { get; private set; }
|
||||
public decimal AdvanceReceipts { get; private set; }
|
||||
public decimal CcReceipts { get; private set; }
|
||||
public decimal NcReceipts { get; private set; }
|
||||
public decimal BtcReceipts { get; private set; }
|
||||
public decimal AdvanceAdjusted { get; private set; }
|
||||
public decimal CashPayments { get; private set; }
|
||||
public decimal AdditionalVoids { get; private set; }
|
||||
public decimal VoidsInSystem { get; private set; }
|
||||
public decimal Discount { get; private set; }
|
||||
public decimal PendingBills { get; private set; }
|
||||
public decimal NetSales { get; private set; }
|
||||
public decimal ClosingBalance { get; private set; }
|
||||
public decimal RetainedOvernight { get; private set; }
|
||||
public decimal CashDeposited { get; private set; } //
|
||||
public decimal Excess { get; private set; } //
|
||||
public string Status { get; private set; } //
|
||||
public string Cashiers { get; private set; } //
|
||||
public User Cashier { get; private set; }
|
||||
|
||||
public decimal OldPending { get; private set; }
|
||||
public decimal OldReceipts { get; private set; }
|
||||
public decimal OldVoided { get; private set; }
|
||||
|
||||
public DateTime StartDate { get; private set; }
|
||||
public DateTime FinishDate { get; private set; }
|
||||
|
||||
public string PendingString { get; private set; }
|
||||
public string CcString { get; private set; }
|
||||
public string NcString { get; private set; }
|
||||
public string BtcString { get; private set; }
|
||||
public string VoidsString { get; private set; }
|
||||
public string DiscountString { get; private set; }
|
||||
|
||||
public string PaymentString { get; private set; }
|
||||
public string Manager
|
||||
{
|
||||
get { return Session.User.Name; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
public CheckoutBI(int cashier, DateTime startDate, DateTime finishDate)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
this.Cashier = UserBI.GetUser(cashier);
|
||||
this.StartDate = startDate.Date.AddHours(6);
|
||||
this.FinishDate = finishDate.Date.AddDays(1).AddHours(5);
|
||||
|
||||
string info;
|
||||
PendingBills = GetPending(out info);
|
||||
PendingString = info;
|
||||
CcReceipts = GetCreditCard(out info);
|
||||
CcString = info;
|
||||
NcReceipts = GetNoCharge(out info);
|
||||
NcString = info;
|
||||
BtcReceipts = GetBillToCompany(out info);
|
||||
BtcString = info;
|
||||
VoidsInSystem = GetVoids(out info);
|
||||
VoidsString = info;
|
||||
// Opening = dao.GetOpenings();
|
||||
// Receipts = GetReceipts();
|
||||
PaymentString = "";
|
||||
// CashPayments = dao.GetPayments();
|
||||
// AdditionalVoids = dao.GetAdditionalVoids();
|
||||
// RetainedOvernight = dao.GetRetainedOvernight();
|
||||
|
||||
AdvanceReceipts = GetAdvancesReceived();
|
||||
AdvanceAdjusted = GetAdvancesAdjusted();
|
||||
// PaymentString = dao.GetPaymentString();
|
||||
|
||||
// OldPending = dao.GetOldPending();
|
||||
// OldReceipts = dao.GetOldReceipts();
|
||||
// OldVoided = dao.GetOldVoided();
|
||||
|
||||
|
||||
Cashiers = GetActiveCashiers();
|
||||
NetSales = GetNetSales();
|
||||
Discount = GetDiscountBills(.1M, out info);
|
||||
DiscountString = info;
|
||||
ClosingBalance = Opening
|
||||
+ Receipts
|
||||
+ AdvanceReceipts
|
||||
- CcReceipts
|
||||
- BtcReceipts
|
||||
- AdvanceAdjusted
|
||||
- CashPayments
|
||||
- AdditionalVoids
|
||||
+ NetSales;
|
||||
}
|
||||
}
|
||||
|
||||
private decimal GetAdvancesAdjusted()
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
var amt = session.QueryOver<Advance>()
|
||||
.Where(i => i.DateOut >= StartDate && i.DateOut <= FinishDate && i.CashierOut == Cashier)
|
||||
.SelectList(k => k.SelectSum(j => j.Amount))
|
||||
.SingleOrDefault<decimal>();
|
||||
return amt;
|
||||
}
|
||||
}
|
||||
|
||||
private decimal GetAdvancesReceived()
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
var amt = session.QueryOver<Advance>()
|
||||
.Where(i => i.DateIn >= StartDate && i.DateIn <= FinishDate && i.CashierIn == Cashier)
|
||||
.SelectList(k => k.SelectSum(j => j.Amount))
|
||||
.SingleOrDefault<decimal>();
|
||||
return amt;
|
||||
}
|
||||
}
|
||||
public void Calculate(decimal cashDeposited, decimal retainedOvernight)
|
||||
{
|
||||
this.CashDeposited = cashDeposited;
|
||||
this.RetainedOvernight = retainedOvernight;
|
||||
Excess = CashDeposited - ClosingBalance;
|
||||
Status = string.Format("{0:Extra Cash Rs #,##0.00; Cash Short Rs #,##0.00;Cash Perfect}", Excess);
|
||||
}
|
||||
|
||||
private decimal GetPending(out string info)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
Voucher voucher = null;
|
||||
decimal amount;
|
||||
decimal discount;
|
||||
info = "\n\r--- Pending Bills ------------------------";
|
||||
var list = session.QueryOver<Voucher>(() => voucher)
|
||||
.Where(i => i.LastEditDate >= StartDate &&
|
||||
i.LastEditDate <= FinishDate &&
|
||||
i.User == Cashier &&
|
||||
i.Void == false)
|
||||
.WithSubquery.WhereExists(QueryOver.Of<VoucherSettlement>().Where(x => x.Voucher.VoucherID == voucher.VoucherID && x.Settled == SettleOption.Unsettled).Select(x => x.Voucher))
|
||||
.List();
|
||||
GetInfo(list, SettleOption.Unsettled, out amount, out discount, ref info);
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
|
||||
private decimal GetNoCharge(out string info)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
Voucher voucher = null;
|
||||
decimal amount;
|
||||
decimal discount;
|
||||
info = "\n\r--- No Charge ----------------------------";
|
||||
var list = session.QueryOver<Voucher>(() => voucher)
|
||||
.Where(i => i.LastEditDate >= StartDate &&
|
||||
i.LastEditDate <= FinishDate &&
|
||||
i.User == Cashier &&
|
||||
i.Void == false)
|
||||
.WithSubquery.WhereExists(QueryOver.Of<VoucherSettlement>().Where(x => x.Voucher.VoucherID == voucher.VoucherID && x.Settled == SettleOption.NoCharge).Select(x => x.Voucher))
|
||||
.List();
|
||||
GetInfo(list, SettleOption.NoCharge, out amount, out discount, ref info);
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
private decimal GetBillToCompany(out string info)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
Voucher voucher = null;
|
||||
decimal amount;
|
||||
decimal discount;
|
||||
info = "\n\r--- Bill To Company ----------------------";
|
||||
var list = session.QueryOver<Voucher>(() => voucher)
|
||||
.Where(i => i.LastEditDate >= StartDate &&
|
||||
i.LastEditDate <= FinishDate &&
|
||||
i.User == Cashier &&
|
||||
i.Void == false)
|
||||
.WithSubquery.WhereExists(QueryOver.Of<VoucherSettlement>().Where(x => x.Voucher.VoucherID == voucher.VoucherID && x.Settled == SettleOption.BillToCompany).Select(x => x.Voucher))
|
||||
.List();
|
||||
GetInfo(list, SettleOption.BillToCompany, out amount, out discount, ref info);
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
private decimal GetCreditCard(out string info)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
Voucher voucher = null;
|
||||
decimal amount;
|
||||
decimal discount;
|
||||
info = "\n\r--- Credit Card Bills --------------------";
|
||||
var list = session.QueryOver<Voucher>(() => voucher)
|
||||
.Where(i => i.LastEditDate >= StartDate &&
|
||||
i.LastEditDate <= FinishDate &&
|
||||
i.User == Cashier &&
|
||||
i.Void == false)
|
||||
.WithSubquery.WhereExists(QueryOver.Of<VoucherSettlement>().Where(x => x.Voucher.VoucherID == voucher.VoucherID && x.Settled == SettleOption.CreditCard).Select(x => x.Voucher))
|
||||
.List();
|
||||
|
||||
GetInfo(list, SettleOption.CreditCard, out amount, out discount, ref info);
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
private decimal GetVoids(out string info)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
decimal amount;
|
||||
decimal discount;
|
||||
info = "\n\r--- Void Bills ---------------------------";
|
||||
var list = (from i in session.QueryOver<Voucher>()
|
||||
where i.LastEditDate >= StartDate &&
|
||||
i.LastEditDate <= FinishDate &&
|
||||
i.User == Cashier &&
|
||||
i.Void == true
|
||||
select i).List();
|
||||
GetInfo(list, out amount, out discount, ref info);
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
private decimal GetDiscountBills(decimal disount, out string info)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
decimal amount;
|
||||
decimal discount;
|
||||
info = "\n\r--- High Discount Bills ------------------";
|
||||
const string query = @"
|
||||
select distinct(v) from Voucher v
|
||||
inner join v.Kots k
|
||||
inner join k.Inventories i
|
||||
where v.Date >= :startDate and v.Date <= :finishDate and v.User = :cashierID 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 i.Discount >= :discount";
|
||||
var list = session.CreateQuery(query)
|
||||
.SetParameter("startDate", StartDate)
|
||||
.SetParameter("finishDate", FinishDate)
|
||||
.SetParameter("cashierID", Cashier.UserID)
|
||||
.SetParameter("unSettled", SettleOption.Unsettled)
|
||||
.SetParameter("noCharge", SettleOption.NoCharge)
|
||||
.SetParameter("amount", SettleOption.Amount)
|
||||
.SetParameter("roundoff", SettleOption.RoundOff)
|
||||
.SetParameter("discount", disount)
|
||||
.List<Voucher>();
|
||||
|
||||
GetInfo(list, out amount, out discount, ref info);
|
||||
return discount;
|
||||
}
|
||||
}
|
||||
|
||||
private decimal GetNetSales()
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
const string query = @"
|
||||
select sum(i.Amount) from Voucher v
|
||||
inner join v.Kots k
|
||||
inner join k.Inventories i
|
||||
where v.Date >= :startDate and v.Date <= :finishDate and v.User = :cashierID 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)
|
||||
";
|
||||
var amount = session.CreateQuery(query)
|
||||
.SetParameter("startDate", StartDate)
|
||||
.SetParameter("finishDate", FinishDate)
|
||||
.SetParameter("cashierID", Cashier.UserID)
|
||||
.SetParameter("unSettled", SettleOption.Unsettled)
|
||||
.SetParameter("noCharge", SettleOption.NoCharge)
|
||||
.SetParameter("amount", SettleOption.Amount)
|
||||
.SetParameter("roundoff", SettleOption.RoundOff)
|
||||
.UniqueResult<decimal>();
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
|
||||
private static void GetInfo(ICollection<Voucher> list, out decimal amount, out decimal discount, ref string info)
|
||||
{
|
||||
amount = 0;
|
||||
discount = 0;
|
||||
if (list.Count == 0)
|
||||
{
|
||||
info = string.Empty;
|
||||
return;
|
||||
}
|
||||
foreach (var item in list)
|
||||
{
|
||||
var amt = item.Settlements.Where(x => x.Settled == SettleOption.Amount).Sum(x => x.Amount) * -1;
|
||||
var disc = item.Kots.Sum(x => x.Inventories.Sum(y => y.Quantity * y.Rate * y.Discount));
|
||||
info += string.Format("\n\r{0:dd-MMM-yyyy HH:mm:ss} {1} {2}", item.Date, item.BillID, item.Customer.Name);
|
||||
info += string.Format("\n\rAmount: {0:#0.00} :: Discount: {1:#0.00}", amt, disc);
|
||||
info += "\n\r------------------------------------------";
|
||||
amount += amt;
|
||||
discount += disc;
|
||||
}
|
||||
}
|
||||
|
||||
private static void GetInfo(ICollection<Voucher> list, SettleOption settleOption, out decimal amount, out decimal discount, ref string info)
|
||||
{
|
||||
amount = 0;
|
||||
discount = 0;
|
||||
if (list.Count == 0)
|
||||
{
|
||||
info = string.Empty;
|
||||
return;
|
||||
}
|
||||
foreach (var item in list)
|
||||
{
|
||||
var amt = item.Settlements.Where(x => x.Settled == settleOption).Sum(x => x.Amount);
|
||||
var disc = item.Kots.Sum(x => x.Inventories.Sum(y => y.Quantity * y.Rate * y.Discount));
|
||||
info += string.Format("\n\r{0:dd-MMM-yyyy HH:mm:ss} {1} {2}", item.Date, item.BillID, item.Customer.Name);
|
||||
info += string.Format("\n\rAmount: {0:#0.00} :: Discount: {1:#0.00}", amt, disc);
|
||||
info += "\n\r------------------------------------------";
|
||||
amount += amt;
|
||||
discount += disc;
|
||||
}
|
||||
}
|
||||
|
||||
private string GetActiveCashiers()
|
||||
{
|
||||
var cashiers = "";
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
const string query = @"
|
||||
select distinct(u.Name) from Voucher v
|
||||
inner join v.User u
|
||||
where v.Date >= :startDate and v.Date <= :finishDate";
|
||||
var list = session.CreateQuery(query)
|
||||
.SetParameter("startDate", StartDate)
|
||||
.SetParameter("finishDate", FinishDate)
|
||||
.List<string>();
|
||||
foreach (var item in list)
|
||||
cashiers += item + ", ";
|
||||
return cashiers;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
75
Tanshu.Accounts.Repository/BusinessLayer/CustomerBI.cs
Normal file
75
Tanshu.Accounts.Repository/BusinessLayer/CustomerBI.cs
Normal file
@ -0,0 +1,75 @@
|
||||
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 Tanshu.Accounts.Entities;
|
||||
using NHibernate.Criterion;
|
||||
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class CustomerBI
|
||||
{
|
||||
public Customer GetCustomer(int customerID)
|
||||
{
|
||||
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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
126
Tanshu.Accounts.Repository/BusinessLayer/FoodTableBI.cs
Normal file
126
Tanshu.Accounts.Repository/BusinessLayer/FoodTableBI.cs
Normal file
@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NHibernate;
|
||||
using NHibernate.Criterion;
|
||||
using Tanshu.Accounts.Entities;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class FoodTableBI : IDisposable
|
||||
{
|
||||
private readonly bool _disposeSession;
|
||||
private readonly ISession _session;
|
||||
private readonly bool _useTransaction;
|
||||
|
||||
public FoodTableBI()
|
||||
{
|
||||
_session = SessionManager.Session;
|
||||
_disposeSession = true;
|
||||
_useTransaction = false;
|
||||
}
|
||||
|
||||
public FoodTableBI(ISession session)
|
||||
{
|
||||
this._session = session;
|
||||
_disposeSession = false;
|
||||
_useTransaction = false;
|
||||
}
|
||||
|
||||
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 GetByName(string name)
|
||||
{
|
||||
return _session.CreateCriteria<FoodTable>()
|
||||
.Add(Restrictions.Eq("Name", name))
|
||||
.UniqueResult<FoodTable>();
|
||||
}
|
||||
|
||||
public IList<FoodTable> List()
|
||||
{
|
||||
return _session.CreateCriteria<FoodTable>().List<FoodTable>();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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 voucher = _session.Get<Voucher>(foodTable.VoucherID);
|
||||
voucher.TableID = foodTable.Name;
|
||||
_session.Update(voucher);
|
||||
trans.Commit();
|
||||
return voucher.VoucherID;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
85
Tanshu.Accounts.Repository/BusinessLayer/ManagementBI.cs
Normal file
85
Tanshu.Accounts.Repository/BusinessLayer/ManagementBI.cs
Normal file
@ -0,0 +1,85 @@
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Text;
|
||||
//using System.Data.SqlClient;
|
||||
//using Tanshu.Accounts.Contracts;
|
||||
//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();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
211
Tanshu.Accounts.Repository/BusinessLayer/MembershipBI.cs
Normal file
211
Tanshu.Accounts.Repository/BusinessLayer/MembershipBI.cs
Normal file
@ -0,0 +1,211 @@
|
||||
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 Tanshu.Accounts.Entities.Auth;
|
||||
using NHibernate.Criterion;
|
||||
using NHibernate.Linq;
|
||||
using NHibernate;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public static class MembershipBI
|
||||
{
|
||||
|
||||
//public string[] GetAllRoles()
|
||||
//{
|
||||
// using (var session = SessionManager.Session)
|
||||
// {
|
||||
// var roleList = session.CreateCriteria<Role>().List<Role>();
|
||||
// string[] list = new string[roleList.Count];
|
||||
// for (int i = 0; i < list.Length; i++)
|
||||
// {
|
||||
// list[i] = roleList[i].Name;
|
||||
// }
|
||||
// return list;
|
||||
// }
|
||||
//}
|
||||
|
||||
//public string[] GetRolesForUser(string username)
|
||||
//{
|
||||
// using (var session = SessionManager.Session)
|
||||
// {
|
||||
// var user = session.CreateCriteria<User>()
|
||||
// .Add(Restrictions.Eq("Name", username))
|
||||
// .UniqueResult<User>();
|
||||
|
||||
// List<string> roles = new List<string>();
|
||||
// foreach (var group in user.Groups)
|
||||
// {
|
||||
// foreach (var item in group.RoleGroups)
|
||||
// {
|
||||
// roles.Add(item.Role.Name);
|
||||
// }
|
||||
// }
|
||||
// return roles.ToArray();
|
||||
// }
|
||||
//}
|
||||
|
||||
//public bool IsUserInRole(string username, string roleName)
|
||||
//{
|
||||
// using (var session = SessionManager.Session)
|
||||
// {
|
||||
// var user = session.CreateCriteria<User>()
|
||||
// .Add(Restrictions.Eq("Name", username))
|
||||
// .UniqueResult<User>();
|
||||
// return IsUserInRole(user.UserID, roleName);
|
||||
// }
|
||||
//}
|
||||
|
||||
public static bool IsUserInRole(int userID, string roleName)
|
||||
{
|
||||
string query = @"
|
||||
SELECT COUNT(*) AS Role_Count FROM
|
||||
Auth_UserGroups ug INNER JOIN Auth_RoleGroups rg ON ug.GroupID = rg.GroupID
|
||||
INNER JOIN Auth_Roles r ON rg.RoleID = r.RoleID
|
||||
WHERE ug.UserID = :UserID AND r.Name = :Role;";
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session
|
||||
.CreateSQLQuery(query)
|
||||
.AddScalar("Role_Count", NHibernateUtil.Int32)
|
||||
.SetInt32("UserID", userID)
|
||||
.SetString("Role", roleName)
|
||||
.UniqueResult<int>() > 0;
|
||||
}
|
||||
}
|
||||
#region UserGroup
|
||||
public static IList<Group> GetGroups()
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.CreateCriteria<Group>()
|
||||
.List<Group>();
|
||||
}
|
||||
}
|
||||
public static IList<Group> GetGroupsOfUser(int userID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
string query = "select ug.Group from UserGroup ug where ug.User.UserID = :userID";
|
||||
var list = session.CreateQuery(query)
|
||||
.SetParameter("userID", userID)
|
||||
.List<Group>();
|
||||
foreach (var item in list)
|
||||
NHibernateUtil.Initialize(item);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
public static IList<Group> GetGroupsNotOfUser(int userID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
string query = "select g from Group g where g not in (select ug.Group from UserGroup ug where ug.User.UserID = :userID)";
|
||||
var list = session.CreateQuery(query)
|
||||
.SetParameter("userID", userID)
|
||||
.List<Group>();
|
||||
foreach (var item in list)
|
||||
NHibernateUtil.Initialize(item);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
public static void AddUserToGroup(int userID, int groupID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
var userGroup = session.CreateQuery("select count(*) from UserGroup ug where ug.User.UserID = :userID and ug.Group.GroupID = :groupID")
|
||||
.SetParameter("userID", userID)
|
||||
.SetParameter("groupID", groupID)
|
||||
.UniqueResult<long>();
|
||||
if (userGroup == 0)
|
||||
{
|
||||
var user = session.Get<User>(userID);
|
||||
var group = session.Get<Group>(groupID);
|
||||
session.Save(new UserGroup() { User = user, Group = group });
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void RemoveUserFromGroup(int userID, int groupID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
string query = "delete UserGroup ug where ug.User.UserID = :userID and ug.Group.GroupID = :groupID";
|
||||
session.CreateQuery(query)
|
||||
.SetParameter("userID", userID)
|
||||
.SetParameter("groupID", groupID)
|
||||
.ExecuteUpdate();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region RoleGroup
|
||||
public static IList<Role> GetRoles()
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.CreateCriteria<Role>()
|
||||
.List<Role>();
|
||||
}
|
||||
}
|
||||
public static IList<Role> GetRolesOfGroup(int groupID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
string query = "select rg.Role from RoleGroup rg where rg.Group.GroupID = :groupID";
|
||||
var list = session.CreateQuery(query)
|
||||
.SetParameter("groupID", groupID)
|
||||
.List<Role>();
|
||||
foreach (var item in list)
|
||||
NHibernateUtil.Initialize(item);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
public static IList<Role> GetRolesNotOfGroup(int groupID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
string query = "select r from Role r where r not in (select rg.Role from RoleGroup rg where rg.Group.GroupID = :groupID)";
|
||||
var list = session.CreateQuery(query)
|
||||
.SetParameter("groupID", groupID)
|
||||
.List<Role>();
|
||||
foreach (var item in list)
|
||||
NHibernateUtil.Initialize(item);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
public static void AddRoleToGroup(int roleID, int groupID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
var roleGroup = session.CreateQuery("select count(*) from RoleGroup rg where rg.Role.RoleID = :roleID and rg.Group.GroupID = :groupID")
|
||||
.SetParameter("roleID", roleID)
|
||||
.SetParameter("groupID", groupID)
|
||||
.UniqueResult<long>();
|
||||
if (roleGroup == 0)
|
||||
{
|
||||
var role = session.Get<Role>(roleID);
|
||||
var group = session.Get<Group>(groupID);
|
||||
session.Save(new RoleGroup() { Role = role, Group = group });
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void RemoveRoleFromGroup(int roleID, int groupID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
string query = "delete RoleGroup rg where rg.Role.RoleID = :roleID and rg.Group.GroupID = :groupID";
|
||||
session.CreateQuery(query)
|
||||
.SetParameter("roleID", roleID)
|
||||
.SetParameter("groupID", groupID)
|
||||
.ExecuteUpdate();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
51
Tanshu.Accounts.Repository/BusinessLayer/ModifierBI.cs
Normal file
51
Tanshu.Accounts.Repository/BusinessLayer/ModifierBI.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Tanshu.Data.DAO;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using Tanshu.Accounts.SqlDAO;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public static class ModifierBI
|
||||
{
|
||||
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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
87
Tanshu.Accounts.Repository/BusinessLayer/PrintLocationBI.cs
Normal file
87
Tanshu.Accounts.Repository/BusinessLayer/PrintLocationBI.cs
Normal file
@ -0,0 +1,87 @@
|
||||
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 Tanshu.Accounts.Entities;
|
||||
using Tanshu.Accounts.SqlDAO;
|
||||
using NHibernate.Criterion;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class PrintLocationBI
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
89
Tanshu.Accounts.Repository/BusinessLayer/ProductBI.cs
Normal file
89
Tanshu.Accounts.Repository/BusinessLayer/ProductBI.cs
Normal file
@ -0,0 +1,89 @@
|
||||
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 NHibernate.Criterion;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public static class ProductBI
|
||||
{
|
||||
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 static bool Delete(int productID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
session.Delete(new Product() { ProductID = productID });
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public static Product GetProductFromName(string nameAndUnits)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
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>();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<ProductDisplaySmall> GetFilteredProducts(Dictionary<string, string> filter)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static List<ProductDisplaySmall> GetUnFilteredProducts()
|
||||
{
|
||||
Dictionary<string, string> filter = new Dictionary<string, string>();
|
||||
filter.Add("Name", "");
|
||||
filter.Add("Type", "");
|
||||
return GetFilteredProducts(filter);
|
||||
}
|
||||
public static IList<Product> GetProducts(int productGroupID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return (from product in session.QueryOver<Product>()
|
||||
where product.ProductGroup.ProductGroupID == productGroupID
|
||||
select product).List();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
76
Tanshu.Accounts.Repository/BusinessLayer/ProductGroupBI.cs
Normal file
76
Tanshu.Accounts.Repository/BusinessLayer/ProductGroupBI.cs
Normal file
@ -0,0 +1,76 @@
|
||||
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 NHibernate.Criterion;
|
||||
using NHibernate;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class ProductGroupBI
|
||||
{
|
||||
public ProductGroup GetProductGroup(int productGroupID)
|
||||
{
|
||||
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>();
|
||||
}
|
||||
}
|
||||
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>();
|
||||
}
|
||||
}
|
||||
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>();
|
||||
NHibernateUtil.Initialize(item);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,97 @@
|
||||
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 NHibernate.Criterion;
|
||||
using NHibernate;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public static class ProductGroupModifierBI
|
||||
{
|
||||
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 static IList<Modifier> GetProductGroupModifiers(int productGroupID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
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)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
var l = from gf in session.QueryOver<ProductGroupModifier>()
|
||||
where gf.ShowAutomatically == true && (gf.ProductGroup == null || gf.ProductGroup.ProductGroupID == productGroupID)
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
91
Tanshu.Accounts.Repository/BusinessLayer/RoleBI.cs
Normal file
91
Tanshu.Accounts.Repository/BusinessLayer/RoleBI.cs
Normal file
@ -0,0 +1,91 @@
|
||||
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;
|
||||
//bool elevated;
|
||||
//AccountsPrincipal originalUser;
|
||||
//AuthenticateUser authenticateUser;
|
||||
public RoleBI(string roleName, int userID)
|
||||
{
|
||||
this.roleName = roleName;
|
||||
this.userID = userID;
|
||||
if (userID == 0)
|
||||
isAllowed = false;
|
||||
else
|
||||
isAllowed = MembershipBI.IsUserInRole(userID, this.roleName);
|
||||
disposed = false;
|
||||
}
|
||||
|
||||
public bool IsAllowed
|
||||
{ get { return isAllowed; } }
|
||||
|
||||
//public bool IsElevated
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// return elevated;
|
||||
// }
|
||||
//}
|
||||
|
||||
//public void Evelvate(AuthenticateUser authenticateUser)
|
||||
//{
|
||||
// this.authenticateUser = authenticateUser;
|
||||
// string userName;
|
||||
// if (this.authenticateUser(out userName))
|
||||
// {
|
||||
// originalUser = (AccountsPrincipal)Thread.CurrentPrincipal;
|
||||
// SetElevation(userName);
|
||||
// }
|
||||
//}
|
||||
//private void SetElevation(string userName)
|
||||
//{
|
||||
// if (userName.Contains(":"))
|
||||
// userName = userName.Substring(userName.IndexOf(":") + 1);
|
||||
|
||||
// Session.User = MembershipBI.GetUserFromName(userName));
|
||||
|
||||
// // bind the generic principal to the thread
|
||||
// Thread.CurrentPrincipal = principal;
|
||||
// userName = ((AccountsIdentity)principal.Identity).UserInfo.Name;
|
||||
// userID = ((AccountsIdentity)principal.Identity).UserInfo.UserID;
|
||||
// elevated = true;
|
||||
//}
|
||||
|
||||
#region IDisposable
|
||||
bool disposed;
|
||||
~RoleBI()
|
||||
{
|
||||
// call Dispose with false. Since we're in the
|
||||
// destructor call, the managed resources will be
|
||||
// disposed of anyways.
|
||||
Dispose(false);
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (!this.disposed)
|
||||
{
|
||||
//if (elevated)
|
||||
// Thread.CurrentPrincipal = originalUser;
|
||||
|
||||
// Note disposing has been done.
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
199
Tanshu.Accounts.Repository/BusinessLayer/SalesAnalysisBI.cs
Normal file
199
Tanshu.Accounts.Repository/BusinessLayer/SalesAnalysisBI.cs
Normal file
@ -0,0 +1,199 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using Tanshu.Common;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class SalesAnalysisBI
|
||||
{
|
||||
public ICollection<SalesAnalysisDetail> GetSaleDetail(DateTime startDate, DateTime finishDate)
|
||||
{
|
||||
|
||||
startDate = startDate.Date.AddHours(6);
|
||||
finishDate = finishDate.Date.AddDays(1).AddHours(5);
|
||||
if (finishDate <= startDate)
|
||||
return new List<SalesAnalysisDetail>();
|
||||
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
var query = @"
|
||||
select concat(p.Name, ' ', p.Units) as Product, Sum(i.Quantity) as Amount
|
||||
from Voucher v
|
||||
inner join v.Kots k
|
||||
inner join k.Inventories i
|
||||
inner join i.Product p
|
||||
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)
|
||||
group by concat(p.Name, ' ', p.Units), p.ProductGroup
|
||||
order by p.ProductGroup, concat(p.Name, ' ', p.Units)
|
||||
";
|
||||
var list = session
|
||||
.CreateQuery(query)
|
||||
.SetParameter("startDate", startDate)
|
||||
.SetParameter("finishDate", finishDate)
|
||||
.SetParameter("noCharge", SettleOption.NoCharge)
|
||||
.SetParameter("unsettled", SettleOption.Unsettled)
|
||||
.SetParameter("amount", SettleOption.Amount)
|
||||
.SetParameter("roundoff", SettleOption.RoundOff)
|
||||
.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] });
|
||||
|
||||
query = @"
|
||||
select concat(p.Name, ' ', p.Units) as Product, Sum(i.Quantity) as Amount
|
||||
from Voucher v
|
||||
inner join v.Kots k
|
||||
inner join k.Inventories i
|
||||
inner join i.Product p
|
||||
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false
|
||||
and exists (select Voucher from VoucherSettlement vs where vs.Voucher = v and vs.Settled = :noCharge)
|
||||
group by concat(p.Name, ' ', p.Units), p.ProductGroup
|
||||
order by p.ProductGroup, concat(p.Name, ' ', p.Units)
|
||||
";
|
||||
list = session
|
||||
.CreateQuery(query)
|
||||
.SetParameter("startDate", startDate)
|
||||
.SetParameter("finishDate", finishDate)
|
||||
.SetParameter("noCharge", SettleOption.NoCharge)
|
||||
.List<object[]>();
|
||||
foreach (var item in list)
|
||||
if (outList.ContainsKey((string)item[0]))
|
||||
outList[(string)item[0]].NC = (decimal)item[1];
|
||||
else
|
||||
outList.Add((string)item[0], new SalesAnalysisDetail() { Product = (string)item[0], NC = (decimal)item[1] });
|
||||
|
||||
return outList.Values;
|
||||
}
|
||||
}
|
||||
public IList<SalesAnalysis> GetSale(DateTime startDate, DateTime finishDate)
|
||||
{
|
||||
startDate = startDate.Date.AddHours(6);
|
||||
finishDate = finishDate.Date.AddDays(1).AddHours(5);
|
||||
if (finishDate <= startDate)
|
||||
return new List<SalesAnalysis>();
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
const string query = @"
|
||||
select g.GroupType as GroupType, Sum(i.Quantity * i.Rate * (1 - i.Discount)) as Amount
|
||||
from Voucher v
|
||||
inner join v.Kots k
|
||||
inner join k.Inventories i
|
||||
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)
|
||||
group by g.GroupType
|
||||
order by g.GroupType
|
||||
";
|
||||
var list = session
|
||||
.CreateQuery(query)
|
||||
.SetParameter("startDate", startDate)
|
||||
.SetParameter("finishDate", finishDate)
|
||||
.SetParameter("noCharge", SettleOption.NoCharge)
|
||||
.SetParameter("unsettled", SettleOption.Unsettled)
|
||||
.SetParameter("amount", SettleOption.Amount)
|
||||
.SetParameter("roundoff", SettleOption.RoundOff)
|
||||
.List<object[]>();
|
||||
var outList = new List<SalesAnalysis>();
|
||||
decimal amount = 0;
|
||||
foreach (var item in list)
|
||||
{
|
||||
amount += (decimal)item[1];
|
||||
outList.Add(new SalesAnalysis() { GroupType = (string)item[0], Amount = (decimal)item[1] });
|
||||
}
|
||||
outList.Add(new SalesAnalysis() { GroupType = "Total Settled", Amount = amount });
|
||||
return GetSettlement(outList, startDate, finishDate);
|
||||
}
|
||||
}
|
||||
private static IList<SalesAnalysis> GetSettlement(IList<SalesAnalysis> outList, DateTime startDate, DateTime finishDate)
|
||||
{
|
||||
outList.Add(new SalesAnalysis() { GroupType = " -- ", Amount = 0 });
|
||||
if (finishDate <= startDate)
|
||||
return new List<SalesAnalysis>();
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
//select v.Settled, Sum(i.Quantity * i.Rate * (1 - i.Discount) * (1 + i.ServiceCharge) * (1 + i.Tax)) as Amount
|
||||
const string query = @"
|
||||
select s.Settled, Sum(s.Amount)
|
||||
from Voucher v
|
||||
inner join v.Settlements s
|
||||
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = false
|
||||
group by s.Settled
|
||||
order by s.Settled
|
||||
";
|
||||
var list = session
|
||||
.CreateQuery(query)
|
||||
.SetParameter("startDate", startDate)
|
||||
.SetParameter("finishDate", finishDate)
|
||||
.List<object[]>();
|
||||
decimal amount = 0;
|
||||
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 = "Total", Amount = amount });
|
||||
return GetOtherDetails(outList, startDate, finishDate);
|
||||
}
|
||||
}
|
||||
private static IList<SalesAnalysis> GetOtherDetails(IList<SalesAnalysis> outList, DateTime startDate, DateTime finishDate)
|
||||
{
|
||||
outList.Add(new SalesAnalysis() { GroupType = " -- ", Amount = 0 });
|
||||
if (finishDate <= startDate)
|
||||
return new List<SalesAnalysis>();
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
#region Service Charge
|
||||
var query = @"
|
||||
select Sum(i.Quantity * i.Rate * (1 - i.Discount) * i.ServiceCharge)
|
||||
from Voucher v
|
||||
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)
|
||||
";
|
||||
var amt = session
|
||||
.CreateQuery(query)
|
||||
.SetParameter("startDate", startDate)
|
||||
.SetParameter("finishDate", finishDate)
|
||||
.SetParameter("noCharge", SettleOption.NoCharge)
|
||||
.SetParameter("unsettled", SettleOption.Unsettled)
|
||||
.SetParameter("amount", SettleOption.Amount)
|
||||
.SetParameter("roundoff", SettleOption.RoundOff)
|
||||
.UniqueResult() ?? 0M;
|
||||
outList.Add(new SalesAnalysis() { GroupType = "Service Charge", Amount = (decimal)amt });
|
||||
#endregion
|
||||
#region Tax
|
||||
query = @"
|
||||
select i.Tax, Sum(i.Quantity * i.Rate * (1 - i.Discount) * (1 + i.ServiceCharge) * i.Tax)
|
||||
from Voucher v
|
||||
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)
|
||||
group by i.Tax
|
||||
";
|
||||
var list = session
|
||||
.CreateQuery(query)
|
||||
.SetParameter("startDate", startDate)
|
||||
.SetParameter("finishDate", finishDate)
|
||||
.SetParameter("noCharge", SettleOption.NoCharge)
|
||||
.SetParameter("unsettled", SettleOption.Unsettled)
|
||||
.SetParameter("amount", SettleOption.Amount)
|
||||
.SetParameter("roundoff", SettleOption.RoundOff)
|
||||
.List<object[]>();
|
||||
foreach (var item in list)
|
||||
outList.Add(new SalesAnalysis() { GroupType = string.Format("Tax {0:P}", (decimal)item[0]), Amount = (decimal)item[1] });
|
||||
#endregion
|
||||
return outList;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
60
Tanshu.Accounts.Repository/BusinessLayer/TaxBI.cs
Normal file
60
Tanshu.Accounts.Repository/BusinessLayer/TaxBI.cs
Normal file
@ -0,0 +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 Tanshu.Accounts.Entities.Auth;
|
||||
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public static class TaxBI
|
||||
{
|
||||
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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
144
Tanshu.Accounts.Repository/BusinessLayer/UserBI.cs
Normal file
144
Tanshu.Accounts.Repository/BusinessLayer/UserBI.cs
Normal file
@ -0,0 +1,144 @@
|
||||
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 Tanshu.Accounts.Entities.Auth;
|
||||
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public static class UserBI
|
||||
{
|
||||
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 static User GetUser(int userID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.Get<User>(userID);
|
||||
}
|
||||
}
|
||||
public static User GetUserFromName(string name)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return (User)session.CreateCriteria<User>()
|
||||
.Add(Restrictions.Eq("Name", name))
|
||||
.UniqueResult();
|
||||
}
|
||||
}
|
||||
|
||||
public static IList<User> GetUsers()
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.CreateCriteria<User>()
|
||||
.List<User>();
|
||||
}
|
||||
}
|
||||
public static IList<User> GetFilteredUsers(Dictionary<string, string> filter)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
return session.CreateCriteria<User>()
|
||||
.Add(Restrictions.Like("Name", string.Format("%{0}%", filter["Name"])))
|
||||
.List<User>();
|
||||
}
|
||||
}
|
||||
public static bool ChangePassword(User userData, string newPassword)
|
||||
{
|
||||
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)
|
||||
.SetParameter("startDate", startDate)
|
||||
.SetParameter("finishDate", finishDate)
|
||||
.List<User>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
247
Tanshu.Accounts.Repository/BusinessLayer/VoucherBI.cs
Normal file
247
Tanshu.Accounts.Repository/BusinessLayer/VoucherBI.cs
Normal file
@ -0,0 +1,247 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using Tanshu.Accounts.Entities.Auth;
|
||||
using NHibernate;
|
||||
using System.Linq;
|
||||
|
||||
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)
|
||||
{
|
||||
return session.Get<Voucher>(voucherID).Printed;
|
||||
}
|
||||
}
|
||||
static public int? Insert(Voucher voucher)
|
||||
{
|
||||
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);
|
||||
session.Save(voucher);
|
||||
UpdateTable(voucher, session);
|
||||
trans.Commit();
|
||||
return addedKot == null ? (int?)null : addedKot.KotID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateSettlements(Voucher voucher, ISession session)
|
||||
{
|
||||
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)
|
||||
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;
|
||||
}
|
||||
|
||||
public static void Delete(int voucherID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
using (var trans = session.BeginTransaction())
|
||||
{
|
||||
session.Delete(session.Get<Voucher>(voucherID));
|
||||
using (var ft = new FoodTableBI(session, true))
|
||||
{
|
||||
var table = session.QueryOver<FoodTable>()
|
||||
.Where(x => x.VoucherID == voucherID)
|
||||
.SingleOrDefault();
|
||||
ft.UpdateStatus(table.Name, voucherID, null);
|
||||
}
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public int? Update(Voucher voucher)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
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);
|
||||
session.Update(voucher);
|
||||
UpdateTable(voucher, session);
|
||||
trans.Commit();
|
||||
if (addedKot == null)
|
||||
return null;
|
||||
else
|
||||
return addedKot.KotID;
|
||||
}
|
||||
}
|
||||
}
|
||||
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 GetVoucher(int voucherID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
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);
|
||||
foreach (var item in kot.Inventories)
|
||||
{
|
||||
NHibernateUtil.Initialize(item);
|
||||
NHibernateUtil.Initialize(item.Product);
|
||||
foreach (var inmod in item.InventoryModifier)
|
||||
NHibernateUtil.Initialize(inmod.Modifier);
|
||||
}
|
||||
}
|
||||
foreach (var item in voucher.Settlements)
|
||||
NHibernateUtil.Initialize(item);
|
||||
return voucher;
|
||||
}
|
||||
}
|
||||
|
||||
static public void VoidBill(int voucherID, string reason)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
using (var trans = session.BeginTransaction())
|
||||
{
|
||||
var saleVoucher = session.Get<Voucher>(voucherID);
|
||||
saleVoucher.Void = true;
|
||||
saleVoucher.VoidReason = reason;
|
||||
session.Save(saleVoucher);
|
||||
UpdateTable(saleVoucher, session);
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public void SettleVoucher(User user, int voucherID, IDictionary<SettleOption, decimal> values)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
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);
|
||||
voucher.User = user;
|
||||
voucher.LastEditDate = DbValues.Date;
|
||||
session.Update(voucher);
|
||||
UpdateTable(voucher, session);
|
||||
trans.Commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
public static int MoveKot(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);
|
||||
trans.Commit();
|
||||
return voucher.VoucherID;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
67
Tanshu.Accounts.Repository/BusinessLayer/WaiterBI.cs
Normal file
67
Tanshu.Accounts.Repository/BusinessLayer/WaiterBI.cs
Normal file
@ -0,0 +1,67 @@
|
||||
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 NHibernate.Criterion;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public static class WaiterBI
|
||||
{
|
||||
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)
|
||||
{
|
||||
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"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user