narsil/Tanshu.Accounts.BI/CheckoutBI.cs
2011-12-05 14:53:02 +05:30

151 lines
6.0 KiB
C#

using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.Threading;
using System.Data.SqlClient;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.DAOFactory;
using Tanshu.Data.DAO;
namespace Tanshu.Accounts.BI
{
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 CreditCardReceipts { 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 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 Guid CashierID { get; private set; } //
public string Cashier { get; private set; } //
public decimal StaffReceipts { get; set; }
public decimal CreditReceipts { get; 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; } //
private string pendingString;
public string PendingString
{
get { return pendingString; }
}
private string creditCardString;
public string CCString
{
get { return creditCardString; }
}
private readonly string _voidsString;
public string VoidsString
{
get { return _voidsString; }
}
private readonly string _discountString;
public string DiscountString
{
get { return _discountString; }
}
private readonly string _staffString;
public string StaffString
{
get { return _staffString; }
}
private readonly string _creditString;
public string CreditString
{
get { return _creditString; }
}
//public string PendingString { get; private set; } //
//public string CCString { 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 Thread.CurrentPrincipal.Identity.Name; }
}
#endregion
public CheckoutBI(Guid cashier, DateTime startDate, DateTime finishDate)
{
var factory = GetFactory.GetDAOFactory(Database.GetFactoryType);
using (var connection = factory.Connection)
{
using (var dao = factory.GetCheckoutDAO(startDate, finishDate, cashier, connection))
{
//Actual Closing
this.CashierID = cashier;
this.StartDate = Convert.ToDateTime(string.Format("{0:dd-MMM-yyyy} 00:00:00", startDate));
this.FinishDate = Convert.ToDateTime(string.Format("{0:dd-MMM-yyyy} 23:59:59", finishDate));
Cashier = new UserBI().GetUser(CashierID).Name;
PendingBills = dao.GetDetail(ref pendingString, PaidStatus.Pending, "\n\r--- Pending Bills ------------------------");
CreditCardReceipts = dao.GetDetail(ref creditCardString, PaidStatus.CreditCard, "\n\r--- Credit Card Bills --------------------");
VoidsInSystem = dao.GetDetail(ref _voidsString, PaidStatus.Void, "\n\r--- Void Bills ---------------------------");
StaffReceipts = dao.GetDetail(ref _staffString, PaidStatus.Staff, "\n\r--- Staff Bills --------------------------");
CreditReceipts = dao.GetDetail(ref _creditString, PaidStatus.Credit, "\n\r--- Credit Bills -------------------------");
Opening = dao.GetOpenings();
Receipts = dao.GetReceipts();
CashPayments = dao.GetPayments();
AdditionalVoids = dao.GetAdditionalVoids();
RetainedOvernight = dao.GetRetainedOvernight();
AdvanceReceipts = dao.GetAdvancesReceived();
AdvanceAdjusted = dao.GetAdvancesAdjusted();
PaymentString = dao.GetPaymentString();
OldPending = dao.GetOldPending();
OldReceipts = dao.GetOldReceipts();
OldVoided = dao.GetOldVoided();
Cashiers = dao.GetActiveCashiers();
NetSales = dao.GetNetSales();
dao.GetDiscountsBills(ref _discountString);
ClosingBalance = Opening
+ Receipts
+ AdvanceReceipts
+ NetSales
- CreditCardReceipts
- StaffReceipts
- CreditReceipts
- AdvanceAdjusted
- CashPayments
- AdditionalVoids;
}
}
}
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);
}
}
}