Finally Deployed. Don't know the total amount of changes.
This commit is contained in:
@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Configuration;
|
||||
using Tanshu.Accounts.Entities.Auth;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
@ -14,6 +15,9 @@ namespace Tanshu.Accounts.Repository
|
||||
private static Dictionary<int, PrintLocation> locations = new Dictionary<int, PrintLocation>();
|
||||
private static string location = ConfigurationManager.AppSettings["Location"].ToLowerInvariant();
|
||||
|
||||
private static IList<Role> roles = null;
|
||||
|
||||
private static bool _log = false;
|
||||
public static IList<ProductGroup> ProductGroups()
|
||||
{
|
||||
if (cache == null)
|
||||
@ -58,10 +62,31 @@ namespace Tanshu.Accounts.Repository
|
||||
}
|
||||
return locations[location.GetHashCode() ^ productGroupID.GetHashCode()];
|
||||
}
|
||||
public static IList<Role> UserRoles(Guid userID)
|
||||
{
|
||||
if (roles == null)
|
||||
{
|
||||
using (var bi = new UserBI())
|
||||
{
|
||||
roles = bi.Roles(userID);
|
||||
}
|
||||
}
|
||||
return roles;
|
||||
}
|
||||
public static void ClearRoles()
|
||||
{
|
||||
roles = null;
|
||||
}
|
||||
|
||||
public static void Invalidate()
|
||||
{
|
||||
cache = null;
|
||||
locations = new Dictionary<int, PrintLocation>();
|
||||
}
|
||||
public static bool Log
|
||||
{
|
||||
get { return _log; }
|
||||
set { _log = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,317 +6,107 @@ using Tanshu.Accounts.Entities.Auth;
|
||||
using NHibernate.Criterion;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using Tanshu.Common.Helpers;
|
||||
using NHibernate;
|
||||
using NHibernate.Transform;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class CheckoutBI
|
||||
{
|
||||
#region Properties
|
||||
public decimal CcReceipts { get; private set; }
|
||||
public decimal NcReceipts { get; private set; }
|
||||
public decimal BtcReceipts { get; private set; }
|
||||
public decimal VoidsInSystem { get; private set; }
|
||||
public decimal Discount { get; private set; }
|
||||
public decimal PendingBills { get; private set; }
|
||||
public decimal CashReceipts { get; private set; }
|
||||
public decimal ClosingBalance { get; private set; }
|
||||
public decimal Excess { get; private set; }
|
||||
public string Status { get; private set; }
|
||||
public Dictionary<SettleOption, int> amounts = new Dictionary<SettleOption, int>();
|
||||
public Dictionary<SettleOption, string> info = new Dictionary<SettleOption, string>();
|
||||
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
|
||||
protected readonly ISession _session;
|
||||
|
||||
private IDictionary<SettleOption, IList<Voucher>> vList = new Dictionary<SettleOption, IList<Voucher>>();
|
||||
public CheckoutBI(Guid cashier, DateTime startDate, DateTime finishDate)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
using (var bi = new UserBI())
|
||||
this.Cashier = bi.Get(x => x.UserID == cashier);
|
||||
this.StartDate = startDate.Date.AddHours(6);
|
||||
this.FinishDate = finishDate.Date.AddDays(1).AddHours(5);
|
||||
_session = SessionManager.Session;
|
||||
StartDate = startDate.Date.AddHours(6);
|
||||
FinishDate = finishDate.Date.AddDays(1).AddHours(5);
|
||||
|
||||
string info;
|
||||
PendingBills = GetPrintInfo(out info, SettleOption.Unsettled);
|
||||
PendingString = info;
|
||||
CcReceipts = GetPrintInfo(out info, SettleOption.CreditCard);
|
||||
CcString = info;
|
||||
NcReceipts = GetPrintInfo(out info, SettleOption.NoCharge);
|
||||
NcString = info;
|
||||
BtcReceipts = GetPrintInfo(out info, SettleOption.BillToCompany);
|
||||
BtcString = info;
|
||||
VoidsInSystem = GetVoids(out info);
|
||||
VoidsString = info;
|
||||
// Opening = dao.GetOpenings();
|
||||
// Receipts = GetReceipts();
|
||||
// CashPayments = dao.GetPayments();
|
||||
// AdditionalVoids = dao.GetAdditionalVoids();
|
||||
// RetainedOvernight = dao.GetRetainedOvernight();
|
||||
|
||||
// PaymentString = dao.GetPaymentString();
|
||||
|
||||
// OldPending = dao.GetOldPending();
|
||||
// OldReceipts = dao.GetOldReceipts();
|
||||
// OldVoided = dao.GetOldVoided();
|
||||
|
||||
|
||||
Cashiers = GetActiveCashiers();
|
||||
CashReceipts = GetPrintInfo(out info, SettleOption.Cash);
|
||||
Discount = GetDiscountBills(.1M, out info);
|
||||
DiscountString = info;
|
||||
ClosingBalance = CashReceipts;
|
||||
}
|
||||
Cashier = _session.QueryOver<User>()
|
||||
.Where(x => x.UserID == cashier)
|
||||
.SingleOrDefault();
|
||||
Cashiers = GetActiveCashiers();
|
||||
GetBillDetails();
|
||||
}
|
||||
|
||||
public void Calculate()
|
||||
public void GetBillDetails()
|
||||
{
|
||||
Excess = ClosingBalance;
|
||||
Status = string.Format("{0:Extra Cash Rs #,##0.00; Cash Short Rs #,##0.00;Cash Perfect}", Excess);
|
||||
}
|
||||
|
||||
private decimal GetPrintInfo(out string info, SettleOption settleOption)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
Voucher voucher = null;
|
||||
decimal amount;
|
||||
decimal discount;
|
||||
info = string.Format("\n\r--- {0} ", settleOption.Display()).PadRight(44, '-');
|
||||
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).Select(x => x.Voucher))
|
||||
.List();
|
||||
GetInfo(list, settleOption, out amount, out discount, ref info);
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
|
||||
//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 GetCashReceipts(out string info)
|
||||
//{
|
||||
// using (var session = SessionManager.Session)
|
||||
// {
|
||||
// Voucher voucher = null;
|
||||
// decimal amount;
|
||||
// decimal discount;
|
||||
// info = "\n\r--- Cash Settlement ----------------------";
|
||||
// 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.Cash).Select(x => x.Voucher))
|
||||
// .List();
|
||||
// GetInfo(list, SettleOption.Cash, 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 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;
|
||||
if (FinishDate <= StartDate)
|
||||
return;
|
||||
}
|
||||
Voucher vAlias = null;
|
||||
VoucherSettlement vsAlias = null;
|
||||
|
||||
var list = _session.QueryOver<Voucher>(() => vAlias)
|
||||
.Left.JoinAlias(x => x.Settlements, () => vsAlias)
|
||||
.Where(x => x.Date >= StartDate && x.Date <= FinishDate && x.User == Cashier)
|
||||
.OrderBy(x => x.VoucherType).Asc
|
||||
.ThenBy(x => x.BillID).Asc
|
||||
.TransformUsing(Transformers.DistinctRootEntity)
|
||||
.List();
|
||||
|
||||
//voidInfo = "\n\r--- Void Bills ---------------------------";
|
||||
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.Price * 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;
|
||||
}
|
||||
}
|
||||
if (item.Void)
|
||||
{
|
||||
if (!amounts.ContainsKey(SettleOption.Void))
|
||||
{
|
||||
amounts.Add(SettleOption.Void, 0);
|
||||
info.Add(SettleOption.Void, string.Format("\n\r--- {0} ", SettleOption.Void.Display()).PadRight(44, '-'));
|
||||
}
|
||||
|
||||
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.Price * 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;
|
||||
var amount = (int)(item.Settlements.Single(x => x.Settled == SettleOption.Amount).Amount * -1);
|
||||
amounts[SettleOption.Void] += amount;
|
||||
info[SettleOption.Void] += string.Format("\n\r{0:dd-MMM-yyyy HH:mm:ss} {1} {2}", item.Date, item.FullBillID, item.Customer.Name);
|
||||
info[SettleOption.Void] += string.Format("\n\rAmount: {0:#0.00}", amount);
|
||||
info[SettleOption.Void] += "\n\r------------------------------------------";
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var so in item.Settlements.Where(x => x.Settled.Visible()))
|
||||
{
|
||||
if (!amounts.ContainsKey(so.Settled))
|
||||
{
|
||||
amounts.Add(so.Settled, 0);
|
||||
info.Add(so.Settled, string.Format("\n\r--- {0} ", so.Settled.Display()).PadRight(44, '-'));
|
||||
}
|
||||
var amount = (int)so.Amount;
|
||||
amounts[so.Settled] += amount;
|
||||
info[so.Settled] += string.Format("\n\r{0:dd-MMM-yyyy HH:mm:ss} {1} {2}", item.Date, item.FullBillID, item.Customer.Name);
|
||||
info[so.Settled] += string.Format("\n\rAmount: {0:#0.00}", amount);
|
||||
info[so.Settled] += "\n\r------------------------------------------";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string GetActiveCashiers()
|
||||
{
|
||||
var cashiers = "";
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
const string query = @"
|
||||
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;
|
||||
}
|
||||
var list = _session.CreateQuery(query)
|
||||
.SetParameter("startDate", StartDate)
|
||||
.SetParameter("finishDate", FinishDate)
|
||||
.List<string>();
|
||||
foreach (var item in list)
|
||||
cashiers += item + ", ";
|
||||
return cashiers;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,18 +45,6 @@ namespace Tanshu.Accounts.Repository
|
||||
return list;
|
||||
}
|
||||
|
||||
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> List(Guid productGroupID)
|
||||
{
|
||||
using (var session = SessionManager.Session)
|
||||
|
||||
@ -45,18 +45,20 @@ namespace Tanshu.Accounts.Repository
|
||||
|
||||
public void Debug(object message)
|
||||
{
|
||||
if (!Cache.Log) return;
|
||||
if (message == null) return;
|
||||
var msg = message.ToString();
|
||||
if (!msg.Contains("oucher") && !_key.Contains("oucher")) return;
|
||||
if (_key != "NHibernate.SQL") return;
|
||||
Console.WriteLine(string.Format(" -- {0} ---+ {1} +---", _key, DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.ff")));
|
||||
Console.WriteLine(message.ToString().Trim());
|
||||
}
|
||||
|
||||
public void Debug(object message, Exception exception)
|
||||
{
|
||||
if (!Cache.Log) return;
|
||||
if (message == null || exception == null) return;
|
||||
var msg = message.ToString();
|
||||
if (!msg.Contains("oucher") && !_key.Contains("oucher")) return;
|
||||
if (_key != "NHibernate.SQL") return;
|
||||
Console.WriteLine(string.Format(" -- {0} ---+ {1} +---", _key, DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.ff")));
|
||||
Console.WriteLine(message.ToString().Trim());
|
||||
Console.WriteLine(exception.ToString());
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
using System;
|
||||
using Tanshu.Accounts.Entities.Auth;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class RoleBI : UnitOfWork<Role>
|
||||
{
|
||||
public bool IsAllowed(Guid userID, string roleName)
|
||||
{ throw new NotImplementedException(); }
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,8 @@ using Tanshu.Accounts.Entities;
|
||||
using Tanshu.Common;
|
||||
using Tanshu.Common.Helpers;
|
||||
using System.Linq;
|
||||
using NHibernate.Transform;
|
||||
using NHibernate.Criterion;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
@ -147,31 +149,42 @@ order by g.GroupType
|
||||
return new List<BillDetail>();
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
const string query = @"
|
||||
select v.Date, v.BillID, s.Settled, s.Amount, v.Void, v.VoidReason
|
||||
from Voucher v
|
||||
inner join v.Settlements s
|
||||
where v.Date >= :startDate and v.Date <= :finishDate
|
||||
order by v.BillID, s.Settled
|
||||
";
|
||||
var list = session
|
||||
.CreateQuery(query)
|
||||
.SetParameter("startDate", startDate)
|
||||
.SetParameter("finishDate", finishDate)
|
||||
.List<object[]>();
|
||||
Voucher vAlias = null;
|
||||
VoucherSettlement vsAlias = null;
|
||||
|
||||
var list = session.QueryOver<Voucher>(() => vAlias)
|
||||
.Left.JoinAlias(x => x.Settlements, () => vsAlias)
|
||||
.Where(x => x.Date >= startDate && x.Date <= finishDate)
|
||||
.OrderBy(x => x.VoucherType).Asc
|
||||
.ThenBy(x => x.BillID).Asc
|
||||
.TransformUsing(Transformers.DistinctRootEntity)
|
||||
.List();
|
||||
|
||||
var outList = new List<BillDetail>();
|
||||
foreach (var item in list)
|
||||
{
|
||||
var settlement = ((SettleOption)item[2]).Display();
|
||||
if ((bool)item[4])
|
||||
settlement = string.Format("Void: {0}", (string)item[5]);
|
||||
outList.Add(new BillDetail()
|
||||
{
|
||||
Date = (DateTime)item[0],
|
||||
BillID = (string)item[1],
|
||||
Settlement = settlement,
|
||||
Amount = Math.Round((decimal)item[3],2)
|
||||
});
|
||||
if (item.Void)
|
||||
outList.Add(new BillDetail()
|
||||
{
|
||||
Date = item.Date,
|
||||
BillID = item.FullBillID,
|
||||
Settlement = string.Format("Void: {0}", item.VoidReason),
|
||||
Amount = Math.Round(item.Settlements.Single(x => x.Settled == SettleOption.Amount).Amount * -1, 2)
|
||||
});
|
||||
|
||||
else
|
||||
{
|
||||
foreach (var so in item.Settlements.Where(x => x.Settled.Visible()))
|
||||
{
|
||||
outList.Add(new BillDetail()
|
||||
{
|
||||
Date = item.Date,
|
||||
BillID = item.FullBillID,
|
||||
Settlement = so.Settled.Display(),
|
||||
Amount = Math.Round(so.Amount, 2)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return outList;
|
||||
}
|
||||
@ -218,28 +231,27 @@ order by pg.GroupType
|
||||
return new List<BillDetail>();
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
const string query = @"
|
||||
select v.Date, v.BillID, s.Amount, v.VoidReason
|
||||
from Voucher v
|
||||
inner join v.Settlements s
|
||||
where v.Date >= :startDate and v.Date <= :finishDate and v.Void = true and s.Settled = :settled
|
||||
order by v.BillID, s.Settled
|
||||
";
|
||||
var listVoids = session
|
||||
.CreateQuery(query)
|
||||
.SetParameter("startDate", startDate)
|
||||
.SetParameter("finishDate", finishDate)
|
||||
.SetParameter("settled", SettleOption.Amount)
|
||||
.List<object[]>();
|
||||
Voucher vAlias = null;
|
||||
VoucherSettlement vsAlias = null;
|
||||
ICriterion amount = Restrictions.Where<VoucherSettlement>(x => x.Settled == SettleOption.Amount);
|
||||
|
||||
var listVoids = session.QueryOver<Voucher>(() => vAlias)
|
||||
.Left.JoinAlias(x => x.Settlements, () => vsAlias, amount)
|
||||
.Where(x => x.Date >= startDate && x.Date <= finishDate && x.Void == true)
|
||||
.OrderBy(x => x.VoucherType).Asc
|
||||
.ThenBy(x => x.BillID).Asc
|
||||
.TransformUsing(Transformers.DistinctRootEntity)
|
||||
.List();
|
||||
|
||||
var outList = new List<BillDetail>();
|
||||
foreach (var item in listVoids)
|
||||
{
|
||||
outList.Add(new BillDetail()
|
||||
{
|
||||
Date = (DateTime)item[0],
|
||||
BillID = (string)item[1],
|
||||
Settlement = string.Format("Void: {0}", (string)item[3]),
|
||||
Amount = (decimal)item[2] * -1
|
||||
Date = item.Date,
|
||||
BillID = item.FullBillID,
|
||||
Settlement = string.Format("Void: {0}", item.VoidReason),
|
||||
Amount = Math.Round(item.Settlements.SingleOrDefault().Amount * -1, 2)
|
||||
});
|
||||
}
|
||||
var listReprint = session.QueryOver<Reprint>()
|
||||
@ -250,7 +262,7 @@ order by v.BillID, s.Settled
|
||||
outList.Add(new BillDetail()
|
||||
{
|
||||
Date = item.Date,
|
||||
BillID = item.Voucher.BillID.Value.ToString(),
|
||||
BillID = item.Voucher.FullBillID,
|
||||
Settlement = string.Format("Reprinted by {0}", item.User.Name),
|
||||
Amount = item.Voucher.Settlements.Single(x => x.Settled == SettleOption.Amount).Amount * -1
|
||||
});
|
||||
@ -267,7 +279,6 @@ order by v.BillID, s.Settled
|
||||
return new List<SalesAnalysis>();
|
||||
using (var session = SessionManager.Session)
|
||||
{
|
||||
//select v.Settled, Sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + i.ServiceCharge) * (1 + i.Tax)) as Amount
|
||||
const string query = @"
|
||||
select s.Settled, Sum(s.Amount)
|
||||
from Voucher v
|
||||
@ -322,7 +333,7 @@ and vs.Settled != :noCharge and vs.Settled != :unsettled and vs.Settled != :amou
|
||||
#endregion
|
||||
#region Service Tax
|
||||
query = @"
|
||||
select Sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.ServiceTax)
|
||||
select Sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.ServiceTaxRate)
|
||||
from Voucher v
|
||||
inner join v.Kots k
|
||||
inner join k.Inventories i
|
||||
@ -344,14 +355,14 @@ and vs.Settled != :noCharge and vs.Settled != :unsettled and vs.Settled != :amou
|
||||
#endregion
|
||||
#region Vat
|
||||
query = @"
|
||||
select i.Vat, Sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.Vat)
|
||||
select i.VatRate, Sum(i.Quantity * i.Price * (1 - i.Discount) * (1 + case when i.IsScTaxable then i.ServiceCharge else 0 end) * i.VatRate)
|
||||
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 and vs.Settled != :staff)
|
||||
group by i.Vat
|
||||
group by i.VatRate
|
||||
";
|
||||
var list = session
|
||||
.CreateQuery(query)
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Tanshu.Accounts.Entities.Auth;
|
||||
using System.Linq;
|
||||
using Tanshu.Accounts.Repository;
|
||||
|
||||
namespace Tanshu.Accounts.Contracts
|
||||
@ -27,6 +28,7 @@ namespace Tanshu.Accounts.Contracts
|
||||
_currentUser = null;
|
||||
IsAuthenticated = false;
|
||||
_roles = null;
|
||||
Cache.ClearRoles();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -37,7 +39,7 @@ namespace Tanshu.Accounts.Contracts
|
||||
if (_roles == null)
|
||||
_roles = new Dictionary<string, bool>();
|
||||
if (!_roles.ContainsKey(role))
|
||||
_roles.Add(role, new UserBI().IsUserInRole(_currentUser.UserID, role));
|
||||
_roles.Add(role, Cache.UserRoles(_currentUser.UserID).Any(x => x.Name == role));
|
||||
return _roles[role];
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,7 +81,6 @@ namespace Tanshu.Accounts.Repository
|
||||
db.IsolationLevel = IsolationLevel.ReadCommitted;
|
||||
db.ConnectionStringName = "Con";
|
||||
db.Timeout = 10;
|
||||
|
||||
// enabled for testing
|
||||
//db.LogFormattedSql = true;
|
||||
//db.LogSqlInConsole = true;
|
||||
@ -91,8 +90,10 @@ namespace Tanshu.Accounts.Repository
|
||||
var mapping = GetMappings();
|
||||
configure.AddDeserializedMapping(mapping, "NHSchemaTest");
|
||||
//SchemaMetadataUpdater.QuoteTableAndColumns(configure);
|
||||
//configure.SetInterceptor(new NHSQLInterceptor());
|
||||
configure.SetInterceptor(new VoucherDirty());
|
||||
|
||||
var timeout = TimeSpan.FromMinutes(10).TotalSeconds;
|
||||
configure.SetProperty("command_timeout", timeout.ToString());
|
||||
return configure;
|
||||
}
|
||||
private static HbmMapping GetMappings()
|
||||
|
||||
@ -79,7 +79,6 @@
|
||||
<Compile Include="ProductGroupModifierBI.cs" />
|
||||
<Compile Include="QueryStore.cs" />
|
||||
<Compile Include="ReprintBI.cs" />
|
||||
<Compile Include="RoleBI.cs" />
|
||||
<Compile Include="SalesAnalysisBI.cs" />
|
||||
<Compile Include="TaxBI.cs" />
|
||||
<Compile Include="UnitOfWork.cs">
|
||||
|
||||
@ -70,12 +70,19 @@ order by u.Name";
|
||||
}
|
||||
}
|
||||
}
|
||||
public bool IsUserInRole(Guid userID, string roleName)
|
||||
public IList<Role> Roles(Guid userID)
|
||||
{
|
||||
var user = _session.QueryOver<User>()
|
||||
.Where(x => x.UserID == userID)
|
||||
.SingleOrDefault();
|
||||
return user.UserGroups.SelectMany(x => x.Group.RoleGroups).Any(y=>y.Role.Name == roleName);
|
||||
const string query = @"
|
||||
select distinct(r) from UserGroup ug
|
||||
inner join ug.User u
|
||||
inner join ug.Group g
|
||||
inner join g.RoleGroups rg
|
||||
inner join rg.Role r
|
||||
where u.UserID = :userID
|
||||
order by r.Name";
|
||||
return _session.CreateQuery(query)
|
||||
.SetParameter("userID", userID)
|
||||
.List<Role>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,6 +119,8 @@ namespace Tanshu.Accounts.Repository
|
||||
var voucher = _session.QueryOver<Voucher>()
|
||||
.Where(query)
|
||||
.SingleOrDefault();
|
||||
if (voucher == null)
|
||||
return voucher;
|
||||
NHibernateUtil.Initialize(voucher.Customer);
|
||||
NHibernateUtil.Initialize(voucher.Waiter);
|
||||
NHibernateUtil.Initialize(voucher.User);
|
||||
@ -200,7 +202,7 @@ namespace Tanshu.Accounts.Repository
|
||||
_session.Update(oldTable);
|
||||
return newVoucher.VoucherID;
|
||||
}
|
||||
private static void UpdateBillType(Voucher voucher)
|
||||
private void UpdateBillType(Voucher voucher)
|
||||
{
|
||||
switch (voucher.VoucherType)
|
||||
{
|
||||
@ -212,6 +214,8 @@ namespace Tanshu.Accounts.Repository
|
||||
item.ServiceCharge = 0;
|
||||
item.ServiceTaxRate = 0;
|
||||
item.VatRate = 0;
|
||||
if (item.InventoryID != Guid.Empty)
|
||||
_session.Update(item);
|
||||
}
|
||||
break;
|
||||
case VoucherType.TakeAway:
|
||||
@ -219,6 +223,8 @@ namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
item.ServiceCharge = 0;
|
||||
item.ServiceTaxRate = 0;
|
||||
if (item.InventoryID != Guid.Empty)
|
||||
_session.Update(item);
|
||||
}
|
||||
break;
|
||||
case VoucherType.Staff:
|
||||
@ -227,6 +233,8 @@ namespace Tanshu.Accounts.Repository
|
||||
item.ServiceCharge = 0;
|
||||
item.ServiceTaxRate = 0;
|
||||
item.VatRate = 0;
|
||||
if (item.InventoryID != Guid.Empty)
|
||||
_session.Update(item);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -286,7 +294,7 @@ namespace Tanshu.Accounts.Repository
|
||||
var oldVoucher = _session.Get<Voucher>(oldVoucherID);
|
||||
oldVoucher.User = Session.User;
|
||||
oldVoucher.Void = true;
|
||||
oldVoucher.VoidReason = string.Format("Bill Discounted / Changed. New Bill ID is {0}", newVoucher.BillID);
|
||||
oldVoucher.VoidReason = string.Format("Bill Discounted / Changed. New Bill ID is {0}", newVoucher.FullBillID);
|
||||
|
||||
Insert(newVoucher);
|
||||
Update(oldVoucher);
|
||||
|
||||
Reference in New Issue
Block a user