Changed Checkout to correctly reflect cash. Minor updates.

This commit is contained in:
unknown 2011-04-11 18:25:45 +05:30
parent 7229ebc0bb
commit 0cb7d3cf09
14 changed files with 254 additions and 195 deletions

View File

@ -0,0 +1,14 @@
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Contracts;
namespace Tanshu.Common.Helpers
{
public static class EnumHelper
{
public static string Display(this SettleOption settleOption)
{
var attribute = (DisplayAttribute)settleOption.GetType().GetField(settleOption.ToString()).GetCustomAttributes(typeof(DisplayAttribute), false)[0];
return attribute != null ? attribute.Name : "";
}
}
}

View File

@ -113,6 +113,7 @@
<Compile Include="Data Contracts Display\ProductDisplayBO.cs" />
<Compile Include="Data Contracts Display\ProductDisplaySmallBO.cs" />
<Compile Include="Data Contracts\ProductGroupBO.cs" />
<Compile Include="Helper Functions\EnumHelper.cs" />
<Compile Include="nHibernate\IAuditable.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Data Contracts Display\SalesAnalysisBO.cs" />

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="FluentCon" connectionString="Server=frodo;Initial Catalog=Pets;User ID=sa;Password=123456" />
<add name="FluentCon" connectionString="Server=Sovereign;Initial Catalog=Pets;User ID=sa;Password=123456" />
</connectionStrings>
<appSettings>
<add key ="Location" value ="Office"/>
@ -9,4 +9,13 @@
<add key ="LogConnection" value ="connection"/>
<add key ="LogLevel" value ="Warn"/>
</appSettings>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="myListener" type="System.Diagnostics.TextWriterTraceListener"
initializeData="TraceOutput.log" />
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
</configuration>

View File

@ -288,7 +288,7 @@ namespace Tanshu.Accounts.PointOfSale
ClearBill();
bill.Clear();
_billInfo = null;
_billInfo = VoucherBI.GetVoucher(voucherID);
_billInfo = VoucherBI.Get(voucherID);
_customer = _billInfo.Customer;
_saleForm.ShowInfo(_billInfo.BillID, _billInfo.KotID, _billInfo.CreationDate, _billInfo.Date.Value,
@ -352,7 +352,7 @@ namespace Tanshu.Accounts.PointOfSale
{
if (!string.IsNullOrEmpty(tableName))
{
var table = new FoodTableBI().GetByName(tableName);
var table = new FoodTableBI().Get(tableName);
if (table != null && table.VoucherID != 0)
{
LoadBill(table.VoucherID);
@ -366,7 +366,7 @@ namespace Tanshu.Accounts.PointOfSale
var tableID = result.Text.Trim();
if ((tableID != "C") && (tableID != "") && (!tableID.Contains(".")))
{
var table = new FoodTableBI().GetByName(tableName);
var table = new FoodTableBI().Get(tableName);
if (table != null && table.VoucherID != 0)
{
LoadBill(table.VoucherID);

View File

@ -18,22 +18,15 @@ namespace Tanshu.Accounts.PointOfSale
private User form_userEvent(object sender, UserEventArgs e)
{
User user = e.User;
var user = e.User;
if (user == null)
{
using (var form = new UserForm(null))
{
form.ShowDialog();
}
}
else
{
using (var form = new UserForm(user.UserID))
{
form.ShowDialog();
}
}
e.Handled = true;
return new User();
}
@ -66,10 +59,8 @@ namespace Tanshu.Accounts.PointOfSale
private void btnCustomer_Click(object sender, EventArgs e)
{
using (var Customer = new CustomersForm(null, ""))
{
Customer.ShowDialog();
}
using (var frm = new CustomersForm(null, ""))
frm.ShowDialog();
}
private void btnInitial_Click(object sender, EventArgs e)

View File

@ -56,7 +56,7 @@
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.txtPayments = new System.Windows.Forms.TextBox();
this.txtAdvanceAdjusted = new System.Windows.Forms.TextBox();
this.txtCashReceipts = new System.Windows.Forms.TextBox();
this.txtCCReceipts = new System.Windows.Forms.TextBox();
this.txtAdditionalVoids = new System.Windows.Forms.TextBox();
this.txtVoidsInSystem = new System.Windows.Forms.TextBox();
@ -95,7 +95,7 @@
this.dtpFinish.Name = "dtpFinish";
this.dtpFinish.Size = new System.Drawing.Size(110, 20);
this.dtpFinish.TabIndex = 42;
this.dtpFinish.ValueChanged += new System.EventHandler(this.dtpFinish_ValueChanged);
this.dtpFinish.ValueChanged += new System.EventHandler(this.DtpFinishValueChanged);
//
// dtpStart
//
@ -103,7 +103,7 @@
this.dtpStart.Name = "dtpStart";
this.dtpStart.Size = new System.Drawing.Size(110, 20);
this.dtpStart.TabIndex = 41;
this.dtpStart.ValueChanged += new System.EventHandler(this.dtpStart_ValueChanged);
this.dtpStart.ValueChanged += new System.EventHandler(this.DtpStartValueChanged);
//
// label17
//
@ -167,7 +167,7 @@
this.btnCalculate.TabIndex = 39;
this.btnCalculate.Text = "&Calculate";
this.btnCalculate.UseVisualStyleBackColor = true;
this.btnCalculate.Click += new System.EventHandler(this.btnCalculate_Click);
this.btnCalculate.Click += new System.EventHandler(this.BtnCalculateClick);
//
// btnPrint
//
@ -177,7 +177,7 @@
this.btnPrint.TabIndex = 40;
this.btnPrint.Text = "&Print";
this.btnPrint.UseVisualStyleBackColor = true;
this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);
this.btnPrint.Click += new System.EventHandler(this.BtnPrintClick);
//
// txtStatus
//
@ -221,7 +221,7 @@
this.cmbCashier.Name = "cmbCashier";
this.cmbCashier.Size = new System.Drawing.Size(200, 21);
this.cmbCashier.TabIndex = 37;
this.cmbCashier.SelectedIndexChanged += new System.EventHandler(this.cmbCashier_SelectedIndexChanged);
this.cmbCashier.SelectedIndexChanged += new System.EventHandler(this.CmbCashierSelectedIndexChanged);
//
// label10
//
@ -273,9 +273,9 @@
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(12, 224);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(73, 13);
this.label5.Size = new System.Drawing.Size(76, 13);
this.label5.TabIndex = 63;
this.label5.Text = "Adv. Adjusted";
this.label5.Text = "Cash Receipts";
//
// label4
//
@ -322,14 +322,14 @@
this.txtPayments.Size = new System.Drawing.Size(200, 20);
this.txtPayments.TabIndex = 48;
//
// txtAdvanceAdjusted
// txtCashReceipts
//
this.txtAdvanceAdjusted.Location = new System.Drawing.Point(99, 221);
this.txtAdvanceAdjusted.Name = "txtAdvanceAdjusted";
this.txtAdvanceAdjusted.ReadOnly = true;
this.txtAdvanceAdjusted.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.txtAdvanceAdjusted.Size = new System.Drawing.Size(200, 20);
this.txtAdvanceAdjusted.TabIndex = 47;
this.txtCashReceipts.Location = new System.Drawing.Point(99, 221);
this.txtCashReceipts.Name = "txtCashReceipts";
this.txtCashReceipts.ReadOnly = true;
this.txtCashReceipts.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.txtCashReceipts.Size = new System.Drawing.Size(200, 20);
this.txtCashReceipts.TabIndex = 47;
//
// txtCCReceipts
//
@ -439,7 +439,7 @@
this.txtNC.Size = new System.Drawing.Size(200, 20);
this.txtNC.TabIndex = 74;
//
// Cashier_Checkout_Form
// CashierCheckoutForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
@ -476,7 +476,7 @@
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtPayments);
this.Controls.Add(this.txtAdvanceAdjusted);
this.Controls.Add(this.txtCashReceipts);
this.Controls.Add(this.txtCCReceipts);
this.Controls.Add(this.txtAdditionalVoids);
this.Controls.Add(this.txtVoidsInSystem);
@ -489,7 +489,7 @@
this.Name = "CashierCheckoutForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Cashier Checkout Form";
this.Load += new System.EventHandler(this.Cashier_Checkout_Form_Load);
this.Load += new System.EventHandler(this.CashierCheckoutFormLoad);
this.ResumeLayout(false);
this.PerformLayout();
@ -525,7 +525,7 @@
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtPayments;
private System.Windows.Forms.TextBox txtAdvanceAdjusted;
private System.Windows.Forms.TextBox txtCashReceipts;
private System.Windows.Forms.TextBox txtCCReceipts;
private System.Windows.Forms.TextBox txtAdditionalVoids;
private System.Windows.Forms.TextBox txtVoidsInSystem;

View File

@ -2,7 +2,6 @@
using System.Windows.Forms;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Print;
using Tanshu.Accounts.Helpers;
namespace Tanshu.Accounts.PointOfSale
{
@ -10,14 +9,13 @@ namespace Tanshu.Accounts.PointOfSale
{
CheckoutBI _coProxy;
bool _loading;
//private static readonly Tanshu.Logging.SqlLogger log = new Tanshu.Logging.SqlLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public CashierCheckoutForm()
{
_loading = true;
InitializeComponent();
}
private void Cashier_Checkout_Form_Load(object sender, EventArgs e)
private void CashierCheckoutFormLoad(object sender, EventArgs e)
{
dtpStart.Format = DateTimePickerFormat.Custom;
dtpStart.CustomFormat = "dd-MMM-yyyy";
@ -31,12 +29,15 @@ namespace Tanshu.Accounts.PointOfSale
private void FillUsers()
{
var loading = _loading;
_loading = true;
cmbCashier.DisplayMember = "Name";
cmbCashier.ValueMember = "UserID";
cmbCashier.DataSource = UserBI.ListActive(dtpStart.Value.Date.AddHours(7), dtpFinish.Value.Date.AddDays(1).AddHours(7));
_loading = loading;
}
private void cmbCashier_SelectedIndexChanged(object sender, EventArgs e)
private void CmbCashierSelectedIndexChanged(object sender, EventArgs e)
{
EmployeeStatus();
//log.Warn(string.Format("User Checkout: {0} by {1}", coProxy.Cashier, Session.User.Name));
@ -47,34 +48,34 @@ namespace Tanshu.Accounts.PointOfSale
if (_loading || cmbCashier.SelectedValue == null)
return;
_coProxy = new CheckoutBI((int)cmbCashier.SelectedValue, dtpStart.Value, dtpFinish.Value);
txtOpening.Text = string.Format("{0:#,##0.00}", _coProxy);
txtOpening.Text = string.Format("{0:#,##0.00}", _coProxy.Opening);
txtReceipts.Text = string.Format("{0:#,##0.00}", _coProxy.Receipts);
txtAdvanceReceived.Text = string.Format("{0:#,##0.00}", _coProxy.AdvanceReceipts);
txtCCReceipts.Text = string.Format("{0:#,##0.00}", _coProxy.CcReceipts);
txtNC.Text = string.Format("{0:#,##0.00}", _coProxy.NcReceipts);
txtBillToCompany.Text = string.Format("{0:#,##0.00}", _coProxy.BtcReceipts);
txtAdvanceAdjusted.Text = string.Format("{0:#,##0.00}", _coProxy.AdvanceAdjusted);
txtCashReceipts.Text = string.Format("{0:#,##0.00}", _coProxy.CashReceipts);
txtPayments.Text = string.Format("{0:#,##0.00}", _coProxy.CashPayments);
txtAdditionalVoids.Text = string.Format("{0:#,##0.00}", _coProxy.AdditionalVoids);
txtVoidsInSystem.Text = string.Format("{0:#,##0.00}", _coProxy.VoidsInSystem);
txtDiscounts.Text = string.Format("{0:#,##0.00}", _coProxy.Discount);
txtPending.Text = string.Format("{0:#,##0.00}", _coProxy.PendingBills);
txtSales.Text = string.Format("{0:#,##0.00}", _coProxy.NetSales);
txtSales.Text = string.Format("{0:#,##0.00}", _coProxy.CashReceipts);
txtClosingCash.Text = string.Format("{0:#,##0.00}", _coProxy.ClosingBalance);
txtStatus.Text = _coProxy.Status;
}
private void dtpStart_ValueChanged(object sender, EventArgs e)
private void DtpStartValueChanged(object sender, EventArgs e)
{
EmployeeStatus();
FillUsers();
}
private void dtpFinish_ValueChanged(object sender, EventArgs e)
private void DtpFinishValueChanged(object sender, EventArgs e)
{
EmployeeStatus();
FillUsers();
}
private void btnCalculate_Click(object sender, EventArgs e)
private void BtnCalculateClick(object sender, EventArgs e)
{
decimal deposited = 0;
if (!decimal.TryParse(txtDeposited.Text, out deposited))
@ -84,7 +85,7 @@ namespace Tanshu.Accounts.PointOfSale
txtStatus.Text = _coProxy.Status;
}
private void btnPrint_Click(object sender, EventArgs e)
private void BtnPrintClick(object sender, EventArgs e)
{
Thermal.PrintClosing(_coProxy);
}

View File

@ -21,25 +21,25 @@ namespace Tanshu.Accounts.Print
[MarshalAs(UnmanagedType.LPStr)]
public string pDataType;
}
[DllImport("winspool.Drv", EntryPoint = "OpenPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
[DllImport("winspool.drv", EntryPoint = "OpenPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
internal static extern bool OpenPrinter([MarshalAs(UnmanagedType.LPStr)] string szPrinter, out IntPtr hPrinter, IntPtr pd);
[DllImport("winspool.Drv", EntryPoint = "ClosePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
[DllImport("winspool.drv", EntryPoint = "ClosePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
internal static extern bool ClosePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint = "StartDocPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
[DllImport("winspool.drv", EntryPoint = "StartDocPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
internal static extern bool StartDocPrinter(IntPtr hPrinter, Int32 level, [In, MarshalAs(UnmanagedType.LPStruct)] DOCINFOA di);
[DllImport("winspool.Drv", EntryPoint = "EndDocPrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
[DllImport("winspool.drv", EntryPoint = "EndDocPrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
internal static extern bool EndDocPrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint = "StartPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
[DllImport("winspool.drv", EntryPoint = "StartPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
internal static extern bool StartPagePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint = "EndPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
[DllImport("winspool.drv", EntryPoint = "EndPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
internal static extern bool EndPagePrinter(IntPtr hPrinter);
[DllImport("winspool.Drv", EntryPoint = "WritePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
[DllImport("winspool.drv", EntryPoint = "WritePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
internal static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, Int32 dwCount, out Int32 dwWritten);
#endregion

View File

@ -6,6 +6,7 @@ using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Entities.Auth;
using Tanshu.Accounts.Repository;
using System.Diagnostics;
namespace Tanshu.Accounts.Print
{
@ -271,13 +272,14 @@ namespace Tanshu.Accounts.Print
billText += string.Format("\n\rCC Receipts : {0,26:#,##0.00}", details.CcReceipts);
billText += string.Format("\n\rNC Amount : {0,26:#,##0.00}", details.NcReceipts);
billText += string.Format("\n\rBTC Amount : {0,26:#,##0.00}", details.BtcReceipts);
billText += string.Format("\n\rCash Amount : {0,26:#,##0.00}", details.CashReceipts);
billText += string.Format("\n\rAdvance Adj. : {0,26:#,##0.00}", details.AdvanceAdjusted);
//BillText += string.Format("\n\rPayments : {0,26:#,##0.00}", details.CashPayments);
//BillText += string.Format("\n\rAddl. Voids : {0,26:#,##0.00}", details.AdditionalVoids);
billText += string.Format("\n\rVoids in Sys. : {0,26:#,##0.00}", details.VoidsInSystem);
billText += string.Format("\n\rDiscounts : {0,26:#,##0.00}", details.Discount);
billText += string.Format("\n\rPending Bills : {0,26:#,##0.00}", details.PendingBills);
billText += string.Format("\n\rNet Sales : {0,26:#,##0.00}", details.NetSales);
billText += string.Format("\n\rNet Sales : {0,26:#,##0.00}", details.CashReceipts);
billText += string.Format("\n\rClosing Bal. : {0,26:#,##0.00}", details.ClosingBalance);
billText += string.Format("\n\rCash Dep. : {0,26:#,##0.00}", details.CashDeposited);
billText += DrawLine;
@ -325,13 +327,15 @@ namespace Tanshu.Accounts.Print
public static void PrintBill(int voucherID)
{
var voucher = VoucherBI.GetVoucher(voucherID);
var voucher = VoucherBI.Get(voucherID);
PrintRaw(PrintLocationBI.BasePrinter, DesignBill(voucher), "Bill");
}
public static void PrintKot(int voucherID, int kotID)
{
var voucher = VoucherBI.GetVoucher(voucherID);
var stopwatch = new Stopwatch();
stopwatch.Start();
var voucher = VoucherBI.Get(voucherID);
var dict = new Dictionary<PrintLocation, List<Inventory>>();
foreach (var item in voucher.Kots.Where(x => x.KotID == kotID))
{
@ -346,13 +350,20 @@ namespace Tanshu.Accounts.Print
dict[printer].Add(inventory);
}
}
stopwatch.Stop();
Trace.TraceWarning("kot and printers built in {0} ms",stopwatch.ElapsedMilliseconds);
stopwatch.Reset();
foreach (var item in dict)
{
for (var i = 0; i < item.Key.Copies; i++)
{
stopwatch.Start();
PrintRaw(item.Key,
DesignKot(voucher, voucher.Kots.Where(x => x.KotID == kotID).Single().Code, item.Value, i),
"KOT");
stopwatch.Stop();
Trace.TraceWarning("kot designed and printed in {0} ms", stopwatch.ElapsedMilliseconds);
stopwatch.Reset();
}
}
}

View File

@ -5,6 +5,7 @@ using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Entities.Auth;
using NHibernate.Criterion;
using Tanshu.Accounts.Contracts;
using Tanshu.Common.Helpers;
namespace Tanshu.Accounts.Repository
{
@ -23,7 +24,7 @@ namespace Tanshu.Accounts.Repository
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 CashReceipts { get; private set; }
public decimal ClosingBalance { get; private set; }
public decimal RetainedOvernight { get; private set; }
public decimal CashDeposited { get; private set; } //
@ -62,13 +63,13 @@ namespace Tanshu.Accounts.Repository
this.FinishDate = finishDate.Date.AddDays(1).AddHours(5);
string info;
PendingBills = GetPending(out info);
PendingBills = GetPrintInfo(out info,SettleOption.Unsettled);
PendingString = info;
CcReceipts = GetCreditCard(out info);
CcReceipts = GetPrintInfo(out info,SettleOption.CreditCard);
CcString = info;
NcReceipts = GetNoCharge(out info);
NcReceipts = GetPrintInfo(out info, SettleOption.CreditCard);
NcString = info;
BtcReceipts = GetBillToCompany(out info);
BtcReceipts = GetPrintInfo(out info, SettleOption.BillToCompany);
BtcString = info;
VoidsInSystem = GetVoids(out info);
VoidsString = info;
@ -89,21 +90,19 @@ namespace Tanshu.Accounts.Repository
Cashiers = GetActiveCashiers();
NetSales = GetNetSales();
CashReceipts = GetPrintInfo(out info, SettleOption.Cash);
Discount = GetDiscountBills(.1M, out info);
DiscountString = info;
ClosingBalance = Opening
+ Receipts
+ AdvanceReceipts
- CcReceipts
- BtcReceipts
- AdvanceAdjusted
- CashPayments
- AdditionalVoids
+ NetSales;
+ CashReceipts;
}
}
#region Advances
private decimal GetAdvancesAdjusted()
{
using (var session = SessionManager.Session)
@ -127,6 +126,8 @@ namespace Tanshu.Accounts.Repository
return amt;
}
}
#endregion
public void Calculate(decimal cashDeposited, decimal retainedOvernight)
{
this.CashDeposited = cashDeposited;
@ -135,84 +136,123 @@ namespace Tanshu.Accounts.Repository
Status = string.Format("{0:Extra Cash Rs #,##0.00; Cash Short Rs #,##0.00;Cash Perfect}", Excess);
}
private decimal GetPending(out string info)
private decimal GetPrintInfo(out string info, SettleOption settleOption)
{
using (var session = SessionManager.Session)
{
Voucher voucher = null;
decimal amount;
decimal discount;
info = "\n\r--- Pending Bills ------------------------";
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.Unsettled).Select(x => x.Voucher))
.WithSubquery.WhereExists(QueryOver.Of<VoucherSettlement>().Where(x => x.Voucher.VoucherID == voucher.VoucherID && x.Settled == settleOption).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();
//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;
// }
//}
GetInfo(list, SettleOption.CreditCard, 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)
@ -261,31 +301,6 @@ and i.Discount >= :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;

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using NHibernate;
using NHibernate.Criterion;
using Tanshu.Accounts.Entities;
using System.Linq;
namespace Tanshu.Accounts.Repository
{
@ -63,7 +64,7 @@ namespace Tanshu.Accounts.Repository
return _session.Get<FoodTable>(foodTableID);
}
public FoodTable GetByName(string name)
public FoodTable Get(string name)
{
return _session.CreateCriteria<FoodTable>()
.Add(Restrictions.Eq("Name", name))
@ -122,5 +123,17 @@ namespace Tanshu.Accounts.Repository
return voucher.VoucherID;
}
}
public void UpdateStatus(Voucher voucher)
{
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;
UpdateStatus(voucher.TableID, voucher.VoucherID, status);
}
}
}

View File

@ -67,7 +67,8 @@ namespace Tanshu.Accounts.Repository
}
UpdateSettlements(voucher, session);
session.Save(voucher);
UpdateTable(voucher, session);
using (var ft = new FoodTableBI(session, true))
ft.UpdateStatus(voucher);
trans.Commit();
return addedKot == null ? (int?)null : addedKot.KotID;
}
@ -144,7 +145,8 @@ namespace Tanshu.Accounts.Repository
}
UpdateSettlements(voucher, session);
session.Update(voucher);
UpdateTable(voucher, session);
using (var ft = new FoodTableBI(session, true))
ft.UpdateStatus(voucher);
trans.Commit();
if (addedKot == null)
return null;
@ -153,21 +155,21 @@ namespace Tanshu.Accounts.Repository
}
}
}
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)
//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 Get(int voucherID)
{
using (var session = SessionManager.Session)
{
@ -198,11 +200,12 @@ namespace Tanshu.Accounts.Repository
{
using (var trans = session.BeginTransaction())
{
var saleVoucher = session.Get<Voucher>(voucherID);
saleVoucher.Void = true;
saleVoucher.VoidReason = reason;
session.Save(saleVoucher);
UpdateTable(saleVoucher, session);
var voucher = session.Get<Voucher>(voucherID);
voucher.Void = true;
voucher.VoidReason = reason;
session.Save(voucher);
using (var ft = new FoodTableBI(session, true))
ft.UpdateStatus(voucher);
trans.Commit();
}
}
@ -223,7 +226,8 @@ namespace Tanshu.Accounts.Repository
voucher.User = user;
voucher.LastEditDate = DbValues.Date;
session.Update(voucher);
UpdateTable(voucher, session);
using (var ft = new FoodTableBI(session, true))
ft.UpdateStatus(voucher);
trans.Commit();
}
}

View File

@ -21,7 +21,7 @@ namespace Tanshu.Accounts.Repository
{
using (var session = SessionManager.Session)
{
string query = @"SELECT ISNULL('K-' + CAST(MAX(CAST(SUBSTRING(KotID, 3,8) AS int)) + 1 AS nvarchar(8)), 'K-1') FROM Entities_Vouchers";
const string query = @"SELECT ISNULL('K-' + CAST(MAX(CAST(SUBSTRING(KotID, 3,8) AS int)) + 1 AS nvarchar(8)), 'K-1') FROM Entities_Vouchers";
var sqlQuery = session.CreateSQLQuery(query);
return (string)sqlQuery.UniqueResult();
}
@ -33,7 +33,7 @@ namespace Tanshu.Accounts.Repository
{
using (var session = SessionManager.Session)
{
string query = @"SELECT ISNULL('S-' + CAST(MAX(CAST(SUBSTRING(Code, 3,8) AS int)) + 1 AS nvarchar(8)), 'S-1') FROM Entities_Kots";
const string query = @"SELECT ISNULL('S-' + CAST(MAX(CAST(SUBSTRING(Code, 3,8) AS int)) + 1 AS nvarchar(8)), 'S-1') FROM Entities_Kots";
var sqlQuery = session.CreateSQLQuery(query);
return (string)sqlQuery.UniqueResult();
}
@ -45,7 +45,7 @@ namespace Tanshu.Accounts.Repository
{
using (var session = SessionManager.Session)
{
string query = @"
const string query = @"
DECLARE @BillID nvarchar(10)
SELECT @BillID = ISNULL(CAST(MAX(CAST(REPLACE(BillID, '-', '') AS int)) + 1 AS nvarchar(9)), '010001') FROM Entities_Vouchers WHERE BillID LIKE '__-____'
IF LEN(@BillID) = 5

View File

@ -11,39 +11,39 @@ namespace Tanshu.Accounts.Contracts
{
public static class Session
{
private static Dictionary<string, bool> roles;
private static User currentUser;
private static Dictionary<string, bool> _roles;
private static User _currentUser;
public static bool IsAuthenticated { get; private set; }
public static User User
{
get
{
return currentUser;
return _currentUser;
}
set
{
if (value != null)
{
currentUser = value;
_currentUser = value;
IsAuthenticated = true;
}
else
{
currentUser = null;
_currentUser = null;
IsAuthenticated = false;
roles = null;
_roles = null;
}
}
}
public static bool IsAllowed(RoleConstants role)
{
if (currentUser == null)
if (_currentUser == null)
return false;
if (roles == null)
roles = new Dictionary<string, bool>();
if (!roles.ContainsKey(role.Role))
roles.Add(role.Role, MembershipBI.IsUserInRole(currentUser.UserID, role.Role));
return roles[role.Role];
if (_roles == null)
_roles = new Dictionary<string, bool>();
if (!_roles.ContainsKey(role.Role))
_roles.Add(role.Role, MembershipBI.IsUserInRole(_currentUser.UserID, role.Role));
return _roles[role.Role];
}