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 System.Text;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Data.SqlClient;
|
|
|
|
|
using Tanshu.Data.DAO;
|
|
|
|
|
using Tanshu.Accounts.SqlDAO;
|
|
|
|
|
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-01-30 07:14:05 +00:00
|
|
|
|
|
|
|
|
|
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; }
|
2011-02-04 19:30:55 +00:00
|
|
|
|
public decimal NCReceipts { get; private set; }
|
|
|
|
|
public decimal BTCReceipts { get; private set; }
|
2011-02-09 12:03:22 +00:00
|
|
|
|
public decimal StaffReceipts { get; private set; }
|
2011-01-30 07:14:05 +00:00
|
|
|
|
public decimal AdvanceAdjusted { get; private set; }
|
|
|
|
|
public decimal CashPayments { get; private set; }
|
|
|
|
|
public decimal AdditionalVoids { get; private set; }
|
|
|
|
|
public decimal VoidsInSystem { get; private set; }
|
2011-02-09 12:03:22 +00:00
|
|
|
|
public decimal Discount { get; private set; }
|
2011-01-30 07:14:05 +00:00
|
|
|
|
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; } //
|
2011-02-04 19:30:55 +00:00
|
|
|
|
public User Cashier { get; private set; }
|
2011-01-30 07:14:05 +00:00
|
|
|
|
|
|
|
|
|
public decimal OldPending { get; private set; }
|
|
|
|
|
public decimal OldReceipts { get; private set; }
|
|
|
|
|
public decimal OldVoided { get; private set; }
|
|
|
|
|
|
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
|
|
|
|
|
2011-02-04 19:30:55 +00:00
|
|
|
|
public string PendingString { get; private set; }
|
|
|
|
|
public string CCString { get; private set; }
|
|
|
|
|
public string NCString { get; private set; }
|
|
|
|
|
public string BTCString { get; private set; }
|
2011-02-09 12:03:22 +00:00
|
|
|
|
public string StaffString { get; private set; }
|
2011-02-04 19:30:55 +00:00
|
|
|
|
public string VoidsString { get; private set; }
|
|
|
|
|
public string DiscountString { get; private set; }
|
2011-01-30 07:14:05 +00:00
|
|
|
|
|
2011-02-09 12:03:22 +00:00
|
|
|
|
public string PaymentString { 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
|
|
|
|
|
|
|
|
|
|
public CheckoutBI(int cashier, DateTime startDate, DateTime finishDate)
|
|
|
|
|
{
|
|
|
|
|
using (var session = SessionManager.Session)
|
|
|
|
|
{
|
2011-02-04 19:30:55 +00:00
|
|
|
|
this.Cashier = UserBI.GetUser(cashier);
|
2011-02-09 12:03:22 +00:00
|
|
|
|
this.StartDate = startDate.Date.AddHours(6);
|
|
|
|
|
this.FinishDate = finishDate.Date.AddDays(1).AddHours(5);
|
2011-01-30 07:14:05 +00:00
|
|
|
|
|
2011-02-04 19:30:55 +00:00
|
|
|
|
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;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
StaffReceipts = GetStaffBills(out info);
|
|
|
|
|
StaffString = info;
|
2011-02-04 19:30:55 +00:00
|
|
|
|
VoidsInSystem = GetVoids(out info);
|
|
|
|
|
VoidsString = info;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
// Opening = dao.GetOpenings();
|
2011-02-04 19:30:55 +00:00
|
|
|
|
// Receipts = GetReceipts();
|
2011-02-09 12:03:22 +00:00
|
|
|
|
PaymentString = "";
|
2011-01-30 07:14:05 +00:00
|
|
|
|
// CashPayments = dao.GetPayments();
|
|
|
|
|
// AdditionalVoids = dao.GetAdditionalVoids();
|
|
|
|
|
// RetainedOvernight = dao.GetRetainedOvernight();
|
2011-02-04 19:30:55 +00:00
|
|
|
|
|
|
|
|
|
AdvanceReceipts = GetAdvancesReceived();
|
|
|
|
|
AdvanceAdjusted = GetAdvancesAdjusted();
|
2011-01-30 07:14:05 +00:00
|
|
|
|
// PaymentString = dao.GetPaymentString();
|
|
|
|
|
|
|
|
|
|
// OldPending = dao.GetOldPending();
|
|
|
|
|
// OldReceipts = dao.GetOldReceipts();
|
|
|
|
|
// OldVoided = dao.GetOldVoided();
|
|
|
|
|
|
|
|
|
|
|
2011-02-09 12:03:22 +00:00
|
|
|
|
Cashiers = GetActiveCashiers();
|
2011-02-04 19:30:55 +00:00
|
|
|
|
NetSales = GetNetSales();
|
2011-02-09 12:03:22 +00:00
|
|
|
|
Discount = GetDiscountBills(.1M, out info);
|
2011-02-04 19:30:55 +00:00
|
|
|
|
DiscountString = info;
|
|
|
|
|
ClosingBalance = Opening
|
|
|
|
|
+ Receipts
|
|
|
|
|
+ AdvanceReceipts
|
|
|
|
|
- CCReceipts
|
2011-02-09 12:03:22 +00:00
|
|
|
|
- BTCReceipts
|
2011-02-04 19:30:55 +00:00
|
|
|
|
- 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;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-04 19:30:55 +00:00
|
|
|
|
private decimal GetPending(out string info)
|
|
|
|
|
{
|
|
|
|
|
using (var session = SessionManager.Session)
|
|
|
|
|
{
|
|
|
|
|
decimal amount;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
decimal discount;
|
2011-02-04 19:30:55 +00:00
|
|
|
|
info = "\n\r--- Pending Bills ------------------------";
|
|
|
|
|
var list = (from i in session.QueryOver<SaleVoucher>()
|
|
|
|
|
where i.LastEditDate >= StartDate &&
|
|
|
|
|
i.LastEditDate <= FinishDate &&
|
|
|
|
|
i.User == Cashier &&
|
|
|
|
|
i.Void == false &&
|
|
|
|
|
i.Settled == SettleOptionFactory.OUnsettled
|
|
|
|
|
select i).List();
|
2011-02-09 12:03:22 +00:00
|
|
|
|
GetInfo(list, out amount, out discount, ref info);
|
2011-02-04 19:30:55 +00:00
|
|
|
|
return amount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private decimal GetNoCharge(out string info)
|
|
|
|
|
{
|
|
|
|
|
using (var session = SessionManager.Session)
|
|
|
|
|
{
|
|
|
|
|
decimal amount;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
decimal discount;
|
2011-02-04 19:30:55 +00:00
|
|
|
|
info = "\n\r--- No Charge ----------------------------";
|
|
|
|
|
var list = (from i in session.QueryOver<SaleVoucher>()
|
|
|
|
|
where i.LastEditDate >= StartDate &&
|
|
|
|
|
i.LastEditDate <= FinishDate &&
|
|
|
|
|
i.User == Cashier &&
|
|
|
|
|
i.Void == false &&
|
|
|
|
|
i.Settled == SettleOptionFactory.ONoCharge
|
|
|
|
|
select i).List();
|
2011-02-09 12:03:22 +00:00
|
|
|
|
GetInfo(list, out amount, out discount, ref info);
|
2011-02-04 19:30:55 +00:00
|
|
|
|
return amount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private decimal GetBillToCompany(out string info)
|
|
|
|
|
{
|
|
|
|
|
using (var session = SessionManager.Session)
|
|
|
|
|
{
|
|
|
|
|
decimal amount;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
decimal discount;
|
2011-02-04 19:30:55 +00:00
|
|
|
|
info = "\n\r--- Bill To Company ----------------------";
|
|
|
|
|
var list = (from i in session.QueryOver<SaleVoucher>()
|
|
|
|
|
where i.LastEditDate >= StartDate &&
|
|
|
|
|
i.LastEditDate <= FinishDate &&
|
|
|
|
|
i.User == Cashier &&
|
|
|
|
|
i.Void == false &&
|
|
|
|
|
i.Settled == SettleOptionFactory.OBillToCompany
|
|
|
|
|
select i).List();
|
2011-02-09 12:03:22 +00:00
|
|
|
|
GetInfo(list, out amount, out discount, ref info);
|
|
|
|
|
return amount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private decimal GetStaffBills(out string info)
|
|
|
|
|
{
|
|
|
|
|
using (var session = SessionManager.Session)
|
|
|
|
|
{
|
|
|
|
|
decimal amount;
|
|
|
|
|
decimal discount;
|
|
|
|
|
info = "\n\r--- Staff Bills --------------------------";
|
|
|
|
|
var list = (from i in session.QueryOver<SaleVoucher>()
|
|
|
|
|
where i.LastEditDate >= StartDate &&
|
|
|
|
|
i.LastEditDate <= FinishDate &&
|
|
|
|
|
i.User == Cashier &&
|
|
|
|
|
i.Void == false &&
|
|
|
|
|
i.Settled == SettleOptionFactory.OStaff
|
|
|
|
|
select i).List();
|
|
|
|
|
GetInfo(list, out amount, out discount, ref info);
|
2011-02-04 19:30:55 +00:00
|
|
|
|
return amount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private decimal GetCreditCard(out string info)
|
|
|
|
|
{
|
|
|
|
|
using (var session = SessionManager.Session)
|
|
|
|
|
{
|
|
|
|
|
decimal amount;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
decimal discount;
|
2011-02-04 19:30:55 +00:00
|
|
|
|
info = "\n\r--- Credit Card Bills --------------------";
|
|
|
|
|
var list = (from i in session.QueryOver<SaleVoucher>()
|
|
|
|
|
where i.LastEditDate >= StartDate &&
|
|
|
|
|
i.LastEditDate <= FinishDate &&
|
|
|
|
|
i.User == Cashier &&
|
|
|
|
|
i.Void == false &&
|
|
|
|
|
i.Settled == SettleOptionFactory.OCreditCard
|
|
|
|
|
select i).List();
|
2011-02-09 12:03:22 +00:00
|
|
|
|
GetInfo(list, out amount, out discount, ref info);
|
2011-02-04 19:30:55 +00:00
|
|
|
|
return amount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private decimal GetVoids(out string info)
|
|
|
|
|
{
|
|
|
|
|
using (var session = SessionManager.Session)
|
|
|
|
|
{
|
|
|
|
|
decimal amount;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
decimal discount;
|
2011-02-04 19:30:55 +00:00
|
|
|
|
info = "\n\r--- Void Bills ---------------------------";
|
|
|
|
|
var list = (from i in session.QueryOver<SaleVoucher>()
|
|
|
|
|
where i.LastEditDate >= StartDate &&
|
|
|
|
|
i.LastEditDate <= FinishDate &&
|
|
|
|
|
i.User == Cashier &&
|
|
|
|
|
i.Void == true
|
|
|
|
|
select i).List();
|
2011-02-09 12:03:22 +00:00
|
|
|
|
GetInfo(list, out amount, out discount, ref info);
|
2011-02-04 19:30:55 +00:00
|
|
|
|
return amount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private decimal GetDiscountBills(decimal disount, out string info)
|
|
|
|
|
{
|
|
|
|
|
using (var session = SessionManager.Session)
|
|
|
|
|
{
|
|
|
|
|
decimal amount;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
decimal discount;
|
2011-02-04 19:30:55 +00:00
|
|
|
|
info = "\n\r--- High Discount Bills ------------------";
|
|
|
|
|
string query = @"
|
2011-02-09 12:03:22 +00:00
|
|
|
|
select distinct(v) from SaleVoucher v
|
|
|
|
|
inner join v.Inventories i
|
2011-02-04 19:30:55 +00:00
|
|
|
|
where v.Date >= :startDate and v.Date <= :finishDate and v.User = :cashierID and v.Void = false and v.Settled != :unSettled and v.Settled != :noCharge
|
|
|
|
|
and i.Discount >= :discount";
|
|
|
|
|
var list = session.CreateQuery(query)
|
|
|
|
|
.SetParameter("startDate", StartDate)
|
|
|
|
|
.SetParameter("finishDate", FinishDate)
|
|
|
|
|
.SetParameter("cashierID", Cashier.UserID)
|
|
|
|
|
.SetParameter("unSettled", SettleOptionFactory.Unsettled)
|
|
|
|
|
.SetParameter("noCharge", SettleOptionFactory.NoCharge)
|
|
|
|
|
.SetParameter("discount", disount)
|
|
|
|
|
.List<SaleVoucher>();
|
|
|
|
|
|
2011-02-09 12:03:22 +00:00
|
|
|
|
GetInfo(list, out amount, out discount, ref info);
|
|
|
|
|
return discount;
|
2011-02-04 19:30:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private decimal GetNetSales()
|
|
|
|
|
{
|
|
|
|
|
using (var session = SessionManager.Session)
|
|
|
|
|
{
|
|
|
|
|
decimal amount = 0;
|
|
|
|
|
string query = @"
|
|
|
|
|
select sum(i.Amount) from SaleVoucher v
|
|
|
|
|
inner join v.Inventories i
|
|
|
|
|
where v.Date >= :startDate and v.Date <= :finishDate and v.User = :cashierID and v.Void = false and v.Settled != :unSettled and v.Settled != :noCharge";
|
|
|
|
|
amount = session.CreateQuery(query)
|
|
|
|
|
.SetParameter("startDate", StartDate)
|
|
|
|
|
.SetParameter("finishDate", FinishDate)
|
|
|
|
|
.SetParameter("cashierID", Cashier.UserID)
|
|
|
|
|
.SetParameter("unSettled", SettleOptionFactory.Unsettled)
|
|
|
|
|
.SetParameter("noCharge", SettleOptionFactory.NoCharge)
|
|
|
|
|
.UniqueResult<decimal>();
|
|
|
|
|
return amount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-09 12:03:22 +00:00
|
|
|
|
private void GetInfo(IList<SaleVoucher> list, out decimal amount, out decimal discount, ref string info)
|
2011-02-04 19:30:55 +00:00
|
|
|
|
{
|
|
|
|
|
amount = 0;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
discount = 0;
|
2011-02-04 19:30:55 +00:00
|
|
|
|
if (list.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
info = string.Empty;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
decimal amt, disc;
|
|
|
|
|
amt = item.Inventories.Sum(x => x.Amount);
|
2011-02-09 12:03:22 +00:00
|
|
|
|
disc = item.Inventories.Sum(x => x.Quantity * x.Rate * x.Discount);
|
2011-02-04 19:30:55 +00:00
|
|
|
|
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;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
discount += disc;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetActiveCashiers()
|
|
|
|
|
{
|
|
|
|
|
string cashiers = "";
|
|
|
|
|
using (var session = SessionManager.Session)
|
|
|
|
|
{
|
|
|
|
|
string query = @"
|
|
|
|
|
select distinct(u.Name) from SaleVoucher 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;
|
2011-02-04 19:30:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|