2011-01-30 07:14:05 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2011-02-04 19:30:55 +00:00
|
|
|
|
using System.Linq;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
using Tanshu.Accounts.Entities;
|
2011-02-04 19:30:55 +00:00
|
|
|
|
using Tanshu.Accounts.Entities.Auth;
|
|
|
|
|
using NHibernate.Criterion;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
using Tanshu.Accounts.Contracts;
|
2011-04-11 12:55:45 +00:00
|
|
|
|
using Tanshu.Common.Helpers;
|
2014-11-06 10:39:11 +00:00
|
|
|
|
using NHibernate;
|
|
|
|
|
using NHibernate.Transform;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.Repository
|
|
|
|
|
{
|
|
|
|
|
public class CheckoutBI
|
|
|
|
|
{
|
|
|
|
|
#region Properties
|
2014-11-06 10:39:11 +00:00
|
|
|
|
public Dictionary<SettleOption, int> amounts = new Dictionary<SettleOption, int>();
|
|
|
|
|
public Dictionary<SettleOption, string> info = new Dictionary<SettleOption, string>();
|
2014-10-12 09:41:45 +00:00
|
|
|
|
public string Cashiers { get; private set; }
|
2011-02-04 19:30:55 +00:00
|
|
|
|
public User Cashier { get; private set; }
|
2011-01-30 07:14:05 +00:00
|
|
|
|
|
2011-02-04 19:30:55 +00:00
|
|
|
|
public DateTime StartDate { get; private set; }
|
|
|
|
|
public DateTime FinishDate { get; private set; }
|
2011-01-30 07:14:05 +00:00
|
|
|
|
|
|
|
|
|
public string Manager
|
|
|
|
|
{
|
2011-02-09 12:03:22 +00:00
|
|
|
|
get { return Session.User.Name; }
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
|
|
|
|
#endregion
|
2014-11-06 10:39:11 +00:00
|
|
|
|
protected readonly ISession _session;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
|
2014-11-06 10:39:11 +00:00
|
|
|
|
private IDictionary<SettleOption, IList<Voucher>> vList = new Dictionary<SettleOption, IList<Voucher>>();
|
2014-10-12 09:41:45 +00:00
|
|
|
|
public CheckoutBI(Guid cashier, DateTime startDate, DateTime finishDate)
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2014-11-06 10:39:11 +00:00
|
|
|
|
_session = SessionManager.Session;
|
|
|
|
|
StartDate = startDate.Date.AddHours(6);
|
|
|
|
|
FinishDate = finishDate.Date.AddDays(1).AddHours(5);
|
|
|
|
|
|
|
|
|
|
Cashier = _session.QueryOver<User>()
|
|
|
|
|
.Where(x => x.UserID == cashier)
|
|
|
|
|
.SingleOrDefault();
|
|
|
|
|
Cashiers = GetActiveCashiers();
|
|
|
|
|
GetBillDetails();
|
2011-03-11 18:49:48 +00:00
|
|
|
|
}
|
2014-11-06 10:39:11 +00:00
|
|
|
|
public void GetBillDetails()
|
2011-02-04 19:30:55 +00:00
|
|
|
|
{
|
2014-11-06 10:39:11 +00:00
|
|
|
|
if (FinishDate <= StartDate)
|
2011-02-04 19:30:55 +00:00
|
|
|
|
return;
|
2014-11-06 10:39:11 +00:00
|
|
|
|
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 ---------------------------";
|
2011-02-04 19:30:55 +00:00
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
2014-11-06 10:39:11 +00:00
|
|
|
|
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, '-'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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------------------------------------------";
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-09 12:03:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetActiveCashiers()
|
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
var cashiers = "";
|
2014-11-06 10:39:11 +00:00
|
|
|
|
const string query = @"
|
2011-02-18 16:54:48 +00:00
|
|
|
|
select distinct(u.Name) from Voucher v
|
2011-02-09 12:03:22 +00:00
|
|
|
|
inner join v.User u
|
|
|
|
|
where v.Date >= :startDate and v.Date <= :finishDate";
|
2014-11-06 10:39:11 +00:00
|
|
|
|
var list = _session.CreateQuery(query)
|
|
|
|
|
.SetParameter("startDate", StartDate)
|
|
|
|
|
.SetParameter("finishDate", FinishDate)
|
|
|
|
|
.List<string>();
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
cashiers += item + ", ";
|
|
|
|
|
return cashiers;
|
2011-02-04 19:30:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|