Multiple settlement options. Upgrade SQL Script included.

This commit is contained in:
unknown
2011-03-12 00:19:48 +05:30
parent 9ed5843dbd
commit aea41a9d24
42 changed files with 1917 additions and 1550 deletions

View File

@ -1,101 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tanshu.Common;
using Tanshu.Accounts.Contracts;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Entities;
using Tanshu.Common;
namespace Tanshu.Accounts.PointOfSale
namespace Tanshu.Accounts.PointOfSale.Sales
{
public class BillHelperFunctions
{
BindingSource bindingSource;
OrderedDictionary<BillItemKey, BillInventory> bill;
BillItemKey newKey;
public BillHelperFunctions(BindingSource bindingSource, OrderedDictionary<BillItemKey, BillInventory> bill, int productID)
private readonly OrderedDictionary<BillItemKey, BillInventory> bill;
private readonly BindingSource _bindingSource;
private readonly BillItemKey _newKey;
public BillHelperFunctions(BindingSource bindingSource, OrderedDictionary<BillItemKey, BillInventory> bill,
int productID)
{
this.bindingSource = bindingSource;
this._bindingSource = bindingSource;
this.bill = bill;
this.newKey = new BillItemKey(productID, 0);
_newKey = new BillItemKey(productID, 0);
}
public void SetDiscount(string name, decimal discount)
{
if (discount > 1 || discount < 0)
return;
decimal maxDiscount = VoucherBI.GetProductDiscountLimit(newKey.ProductID);
decimal maxDiscount = VoucherBI.GetProductDiscountLimit(_newKey.ProductID);
if (discount > maxDiscount)
MessageBox.Show(string.Format("Maximum discount for {0} is {1:P}", name, maxDiscount), "Excessive Discount", MessageBoxButtons.OK, MessageBoxIcon.Warning);
MessageBox.Show(string.Format("Maximum discount for {0} is {1:P}", name, maxDiscount),
"Excessive Discount", MessageBoxButtons.OK, MessageBoxIcon.Warning);
foreach (var item in bill)
{
if (item.Value.ProductID == newKey.ProductID)
if (item.Value.ProductID == _newKey.ProductID)
item.Value.Discount = discount;
}
}
#region Add Product
public BillInventory AddProduct()
{
BillInventory product;
if (bill.ContainsKey(newKey))
{
bindingSource.CurrencyManager.Position = bill.IndexOfKey(newKey);
product = bill[newKey];
product.Quantity += 1;
}
else
{ //Has only old
product = VoucherBI.GetDefaultSaleBillItem(newKey.ProductID);
foreach (var item in bill)
{
if (item.Key.ProductID == newKey.ProductID)
{
product.Discount = item.Value.Discount;
product.Price = item.Value.Price;
}
}
product = AddProduct(product);
}
return product;
}
private BillInventory AddProduct(BillInventory product)
{
bill.Add(new BillItemKey(product.ProductID, 0), product);
bindingSource.DataSource = bill.Values;
bindingSource.CurrencyManager.Position = bindingSource.CurrencyManager.Count + 1;
return product;
}
#endregion
#region Quantity
public void SetQuantity(BillInventory product, decimal quantity, bool prompt)
{
if (product.Printed)
return;
if (prompt && !GetInput("Price", ref quantity))
return;
if (!prompt)
quantity += product.Quantity;
SetQuantity(product, quantity);
}
private void SetQuantity(BillInventory product, decimal quantity)
{
if (quantity < 0 && !Session.IsAllowed(RoleConstants.EDIT_PRINTED_PRODUCT))
return;
var total = quantity;
foreach (var item in bill)
{
if (item.Value.ProductID == newKey.ProductID)
total += item.Value.Quantity;
}
if (total < 0)
quantity -= total;
product.Quantity = quantity;
}
#endregion
public void SetPrice(BillInventory product)
{
if (!Allowed(product, RoleConstants.CHANGE_RATE))
@ -107,13 +46,15 @@ namespace Tanshu.Accounts.PointOfSale
return;
foreach (var item in bill)
{
if (item.Value.ProductID == newKey.ProductID)
if (item.Value.ProductID == _newKey.ProductID)
item.Value.Price = rate;
}
}
private void InputBox_Validating(object sender, InputBoxValidatingArgs e)
{
}
private bool Allowed(BillInventory item, RoleConstants role)
{
if (item == null)
@ -122,6 +63,7 @@ namespace Tanshu.Accounts.PointOfSale
return false;
return true;
}
private bool GetInput(string prompt, ref decimal amount)
{
InputBoxResult result = InputBox.Show(prompt, amount.ToString(), InputBox_Validating);
@ -131,5 +73,70 @@ namespace Tanshu.Accounts.PointOfSale
return false;
return true;
}
#region Add Product
public BillInventory AddProduct()
{
BillInventory product;
if (bill.ContainsKey(_newKey))
{
_bindingSource.CurrencyManager.Position = bill.IndexOfKey(_newKey);
product = bill[_newKey];
product.Quantity += 1;
}
else
{
//Has only old
product = VoucherBI.GetDefaultSaleBillItem(_newKey.ProductID);
foreach (var item in bill)
{
if (item.Key.ProductID == _newKey.ProductID)
{
product.Discount = item.Value.Discount;
product.Price = item.Value.Price;
}
}
product = AddProduct(product);
}
return product;
}
private BillInventory AddProduct(BillInventory product)
{
bill.Add(new BillItemKey(product.ProductID, 0), product);
_bindingSource.DataSource = bill.Values.ToList();
_bindingSource.CurrencyManager.Position = _bindingSource.CurrencyManager.Count - 1;
return product;
}
#endregion
#region Quantity
public void SetQuantity(BillInventory product, decimal quantity, bool prompt)
{
if (product.Printed)
return;
if (prompt && !GetInput("Price", ref quantity))
return;
if (!prompt)
quantity += product.Quantity;
SetQuantity(product, quantity);
}
private void SetQuantity(BillInventory product, decimal quantity)
{
if (quantity < 0 && !Session.IsAllowed(RoleConstants.EDIT_PRINTED_PRODUCT))
return;
var total = quantity + bill.Where(item => item.Value.ProductID == _newKey.ProductID).Sum(item => item.Value.Quantity);
if (total < 0)
quantity -= total;
product.Quantity = quantity;
}
#endregion
}
}
}

View File

@ -1,129 +0,0 @@
namespace Tanshu.Accounts.PointOfSale
{
partial class BillSettleForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnCash = new System.Windows.Forms.Button();
this.btnCreditCard = new System.Windows.Forms.Button();
this.btnNC = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.btnStaff = new System.Windows.Forms.Button();
this.btnBillToCompany = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnCash
//
this.btnCash.Location = new System.Drawing.Point(12, 12);
this.btnCash.Name = "btnCash";
this.btnCash.Size = new System.Drawing.Size(75, 75);
this.btnCash.TabIndex = 0;
this.btnCash.Text = "Cash";
this.btnCash.UseVisualStyleBackColor = true;
this.btnCash.Click += new System.EventHandler(this.btnCash_Click);
//
// btnCreditCard
//
this.btnCreditCard.Location = new System.Drawing.Point(93, 12);
this.btnCreditCard.Name = "btnCreditCard";
this.btnCreditCard.Size = new System.Drawing.Size(75, 75);
this.btnCreditCard.TabIndex = 1;
this.btnCreditCard.Text = "Credit Card";
this.btnCreditCard.UseVisualStyleBackColor = true;
this.btnCreditCard.Click += new System.EventHandler(this.btnCreditCard_Click);
//
// btnNC
//
this.btnNC.Location = new System.Drawing.Point(174, 12);
this.btnNC.Name = "btnNC";
this.btnNC.Size = new System.Drawing.Size(75, 75);
this.btnNC.TabIndex = 2;
this.btnNC.Text = "No Charge";
this.btnNC.UseVisualStyleBackColor = true;
this.btnNC.Click += new System.EventHandler(this.btnNC_Click);
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(417, 12);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 75);
this.btnCancel.TabIndex = 3;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// btnStaff
//
this.btnStaff.Location = new System.Drawing.Point(255, 12);
this.btnStaff.Name = "btnStaff";
this.btnStaff.Size = new System.Drawing.Size(75, 75);
this.btnStaff.TabIndex = 4;
this.btnStaff.Text = "Staff";
this.btnStaff.UseVisualStyleBackColor = true;
this.btnStaff.Click += new System.EventHandler(this.btnStaff_Click);
//
// btnBillToCompany
//
this.btnBillToCompany.Location = new System.Drawing.Point(336, 12);
this.btnBillToCompany.Name = "btnBillToCompany";
this.btnBillToCompany.Size = new System.Drawing.Size(75, 75);
this.btnBillToCompany.TabIndex = 5;
this.btnBillToCompany.Text = "Bill To Company";
this.btnBillToCompany.UseVisualStyleBackColor = true;
this.btnBillToCompany.Click += new System.EventHandler(this.btnBillToCompany_Click);
//
// BillSettleForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(504, 99);
this.ControlBox = false;
this.Controls.Add(this.btnBillToCompany);
this.Controls.Add(this.btnStaff);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnNC);
this.Controls.Add(this.btnCreditCard);
this.Controls.Add(this.btnCash);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.MaximizeBox = false;
this.Name = "BillSettleForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Settle Bill";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button btnCash;
private System.Windows.Forms.Button btnCreditCard;
private System.Windows.Forms.Button btnNC;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Button btnStaff;
private System.Windows.Forms.Button btnBillToCompany;
}
}

View File

@ -1,65 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.SqlDAO;
namespace Tanshu.Accounts.PointOfSale
{
public partial class BillSettleForm : Form
{
private SettleOption settleOption = SettleOption.Unsettled;
public BillSettleForm()
{
InitializeComponent();
}
private void btnCash_Click(object sender, EventArgs e)
{
settleOption = SettleOption.Cash;
this.Close();
}
private void btnCreditCard_Click(object sender, EventArgs e)
{
settleOption = SettleOption.CreditCard;
this.Close();
}
private void btnNC_Click(object sender, EventArgs e)
{
settleOption = SettleOption.NoCharge;
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
settleOption = SettleOption.Unsettled;
this.Close();
}
private void btnStaff_Click(object sender, EventArgs e)
{
settleOption = SettleOption.Staff;
this.Close();
}
private void btnBillToCompany_Click(object sender, EventArgs e)
{
settleOption = SettleOption.BillToCompany;
this.Close();
}
public SettleOption optionChosen
{
get
{
return settleOption;
}
}
}
}

View File

@ -0,0 +1,80 @@
namespace Tanshu.Accounts.PointOfSale
{
partial class FrmSettleAmounts
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.txtAmount = new System.Windows.Forms.TextBox();
this.txtCurrentAmount = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// txtAmount
//
this.txtAmount.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtAmount.Location = new System.Drawing.Point(3, 3);
this.txtAmount.Name = "txtAmount";
this.txtAmount.ReadOnly = true;
this.txtAmount.Size = new System.Drawing.Size(173, 20);
this.txtAmount.TabIndex = 1;
//
// txtCurrentAmount
//
this.txtCurrentAmount.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtCurrentAmount.Location = new System.Drawing.Point(3, 26);
this.txtCurrentAmount.Name = "txtCurrentAmount";
this.txtCurrentAmount.Size = new System.Drawing.Size(173, 20);
this.txtCurrentAmount.TabIndex = 0;
this.txtCurrentAmount.KeyDown += new System.Windows.Forms.KeyEventHandler(this.TxtCurrentAmountKeyDown);
//
// FrmSettleAmounts
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(179, 249);
this.ControlBox = false;
this.Controls.Add(this.txtCurrentAmount);
this.Controls.Add(this.txtAmount);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.MaximizeBox = false;
this.Name = "FrmSettleAmounts";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Settle Bill";
this.Load += new System.EventHandler(this.SettleChoicesFormLoad);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox txtAmount;
private System.Windows.Forms.TextBox txtCurrentAmount;
}
}

View File

@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Contracts;
using Tanshu.Common.KeyboardControl;
namespace Tanshu.Accounts.PointOfSale
{
public partial class FrmSettleAmounts : Form
{
private IKeyboardControl _keyboardControl;
private readonly decimal _amount;
private readonly SettleOption _settleOption;
private decimal _settleAmount;
public FrmSettleAmounts(IKeyboardControl keyboardControl, SettleOption settleOption, decimal amount)
{
InitializeComponent();
_keyboardControl = keyboardControl;
_amount = amount;
_settleOption = settleOption;
_settleAmount = 0;
var control = keyboardControl as UserControl;
if (control != null)
{
control.Location = new System.Drawing.Point(3, 49);
this.Controls.Add(control);
this.Size = this.SizeFromClientSize(new Size(3 + control.Width + 3, 49 + control.Height + 3));
}
}
public decimal AmountSettled
{
get
{
return _settleAmount;
}
}
private void SettleChoicesFormLoad(object sender, EventArgs e)
{
var attribute = (DisplayAttribute)_settleOption.GetType().GetField(_settleOption.ToString()).GetCustomAttributes(typeof(DisplayAttribute), false)[0];
this.Text = attribute.Name;
txtAmount.Text = string.Format("Pending Amount: Rs. {0}", _amount);
txtCurrentAmount.Text = string.Format("{0:#,#00}", _amount);
txtCurrentAmount.Focus();
}
private void TxtCurrentAmountKeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Escape:
_settleAmount = 0;
this.Close();
break;
case Keys.Return:
{
decimal settleAmount;
if (!Decimal.TryParse(txtCurrentAmount.Text, out settleAmount))
return;
if (settleAmount > _amount)
settleAmount = _amount;
_settleAmount = settleAmount;
this.Close();
}
break;
}
}
}
}

View File

@ -1,4 +1,4 @@
namespace Tanshu.Accounts.PointOfSale
namespace Tanshu.Accounts.PointOfSale.Sales
{
partial class SalesForm
{
@ -666,6 +666,7 @@
private System.Windows.Forms.DataGridViewTextBoxColumn printedDataGridViewTextBoxColumn;
private System.Windows.Forms.Button btnMore;
private System.Windows.Forms.Button btnMoveKot;
private readonly BillController _billController;
}
}

View File

@ -1,34 +1,63 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Helpers;
using Tanshu.Common;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Helpers;
using Tanshu.Accounts.Repository;
using Tanshu.Common;
namespace Tanshu.Accounts.PointOfSale
namespace Tanshu.Accounts.PointOfSale.Sales
{
public partial class SalesForm : Form, ISaleForm
{
BillController billController;
public SalesForm(BillController billController)
{
InitializeComponent();
this.billController = billController;
this._billController = billController;
billController.InitGui(this);
}
#region ISaleForm Members
public void SetUserName(string name)
{
this.Text = name;
Text = name;
}
public void SetCustomerDisplay(string name)
{
btnCustomer.Text = name;
}
public void ShowInfo(string billID, string kotID, DateTime creationDate, DateTime date, DateTime lastEditDate,
string customer, string tableID, int waiterID, string waiter)
{
txtBillID.Text = billID;
txtKotID.Text = kotID;
txtCreationDate.Text = creationDate.ToString("HH:mm dd-MMM-yyyy");
txtDate.Text = date.ToString("HH:mm dd-MMM-yyyy");
txtLastEditDate.Text = lastEditDate.ToString("HH:mm dd-MMM-yyyy");
btnCustomer.Text = customer;
txtTableID.Text = tableID;
btnWaiter.Tag = waiterID;
btnWaiter.Text = string.Format("{0} - F5", waiter);
}
public BindingSource BindingSource
{
get { return bindingSource; }
}
public void CloseWindow()
{
Close();
}
#endregion
private void SalesForm_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
@ -46,7 +75,7 @@ namespace Tanshu.Accounts.PointOfSale
case Keys.F4:
{
if (!e.Alt)
billController.ShowCustomerList(false);
_billController.ShowCustomerList(false);
break;
}
case Keys.F5:
@ -56,17 +85,17 @@ namespace Tanshu.Accounts.PointOfSale
}
case Keys.F7:
{
using (SelectProduct selectProduct = new SelectProduct(ProductBI.GetFilteredProducts, true))
using (var selectProduct = new SelectProduct(ProductBI.GetFilteredProducts, true))
{
selectProduct.ShowDialog();
if (selectProduct.SelectedItem != null)
billController.AddProductToGrid(selectProduct.SelectedItem.ProductID);
_billController.AddProductToGrid(selectProduct.SelectedItem.ProductID);
}
break;
}
case Keys.F8:
{
billController.LoadBillFromTable(null);
_billController.LoadBillFromTable(null);
break;
}
case Keys.F11:
@ -81,17 +110,17 @@ namespace Tanshu.Accounts.PointOfSale
}
case Keys.Delete:
{
billController.ProductRemove();
_billController.ProductRemove();
break;
}
case Keys.Add:
{
billController.SetQuantity(1, false);
_billController.SetQuantity(1, false);
break;
}
case Keys.Subtract:
{
billController.SetQuantity(-1, false);
_billController.SetQuantity(-1, false);
break;
}
case Keys.Up:
@ -108,207 +137,49 @@ namespace Tanshu.Accounts.PointOfSale
}
case Keys.Escape:
{
billController.CancelBillChanges();
_billController.CancelBillChanges();
break;
}
}
}
#region Helper Functions
public void ClearBill(OrderedDictionary<BillItemKey, BillInventory> bill)
{
this.txtBillID.Text = "";
this.txtKotID.Text = "";
this.txtCreationDate.Text = "";
this.txtDate.Text = "";
this.txtLastEditDate.Text = "";
this.txtTableID.Text = "";
this.btnWaiter.Text = "Waiter - F5";
this.btnWaiter.Tag = null;
txtGrossTax.Text = "0.00";
txtDiscount.Text = "0.00";
txtServiceCharge.Text = "0.00";
txtGrossAmount.Text = "0.00";
txtAmount.Text = "0.00";
bindingSource.DataSource = bill.Values;
MoreButton(false);
ChangeFormState(SaleFormState.Waiting);
}
private void ChangeFormState(SaleFormState state)
{
flpGroup.Controls.Clear();
flpMain.Controls.Clear();
if (state == SaleFormState.Billing)
{
var list = new ProductGroupBI().GetProductGroups();
ControlFactory.GenerateGroups(ref flpGroup, new Point(75, 75), 0, list, new ButtonClickDelegate(productTypeButton_Click));
}
else
{
ControlFactory.GenerateTables(ref flpMain, new Point(75, 75), 0, new FoodTableBI().List(), new ButtonClickDelegate(tableButton_Click));
}
}
private void productTypeButton_Click(object sender, EventArgs e)
{
Button button = sender as Button;
if (button == null)
return;
var item = button.Tag as ProductGroup;
if (item.Name == "Previous" || item.Name == "Next")
{
int start = item.ProductGroupID;
if (start < 0)
start = 0;
var list = new ProductGroupBI().GetProductGroups();
ControlFactory.GenerateGroups(ref flpGroup, new Point(75, 75), start, list, new ButtonClickDelegate(productTypeButton_Click));
}
else
{
ControlFactory.GenerateProducts(ref flpMain, new Point(75, 75), 0, ProductBI.GetProducts(item.ProductGroupID), new ButtonClickDelegate(productButton_Click));
}
}
private void productButton_Click(object sender, EventArgs e)
{
Button button = sender as Button;
if (button == null)
return;
var item = button.Tag as Product;
if (item.Name == "Previous" || item.Name == "Next")
{
int start = item.ProductID;
if (start < 0)
start = 0;
var list = ProductBI.GetProducts();
ControlFactory.GenerateProducts(ref flpMain, new Point(75, 75), start, list, new ButtonClickDelegate(productButton_Click));
}
else
{
billController.AddProductToGrid(item.ProductID);
}
}
private void tableButton_Click(object sender, EventArgs e)
{
Button button = sender as Button;
if (button == null)
return;
var item = button.Tag as FoodTable;
if (item.Name == "Previous" || item.Name == "Next")
{
int start = item.FoodTableID;
if (start < 0)
start = 0;
var list = new FoodTableBI().List();
ControlFactory.GenerateTables(ref flpMain, new Point(75, 75), start, list, new ButtonClickDelegate(tableButton_Click));
}
else
{
string tableName = item.Name;
billController.LoadBillFromTable(tableName);
txtTableID.Text = tableName;
ChangeFormState(SaleFormState.Billing);
}
}
public void ShowAmount(decimal discountAmount, decimal grossAmount, decimal serviceChargeAmount, decimal taxAmount, decimal valueAmount, List<BillInventory> bill)
{
txtGrossTax.Text = string.Format("{0:#0.00}", taxAmount);
txtDiscount.Text = string.Format("{0:#0.00}", discountAmount);
txtServiceCharge.Text = string.Format("{0:#0.00}", serviceChargeAmount);
txtGrossAmount.Text = string.Format("{0:#0.00}", grossAmount);
txtAmount.Text = string.Format("{0:#0.00}", Math.Round(valueAmount));
bindingSource.DataSource = bill;
dgvProducts.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
}
private void btnPrintBill_Click(object sender, EventArgs e)
{
if (btnWaiter.Tag == null)
btnWaiter.Tag = WaiterBI.GetWaiters()[0].WaiterID;
billController.Save(true, (int)btnWaiter.Tag, txtTableID.Text);
}
private void btnPrintKot_Click(object sender, EventArgs e)
{
if (btnWaiter.Tag == null)
btnWaiter.Tag = WaiterBI.GetWaiters()[0].WaiterID;
billController.Save(false, (int)btnWaiter.Tag, txtTableID.Text);
}
private void btnCancel_Click(object sender, EventArgs e)
{
billController.CancelBillChanges();
}
private void btnQuantity_Click(object sender, EventArgs e)
{
billController.SetQuantity(0, true);
}
private void btnDiscount_Click(object sender, EventArgs e)
{
billController.ShowDiscount();
//if (dgvProducts.Rows.Count > 0)
// billController.SetDiscount(billController.CurrentProduct, -1);
}
#endregion
private void SalesForm_Load(object sender, EventArgs e)
{
billController.FormLoad();
_billController.FormLoad();
ChangeFormState(SaleFormState.Waiting);
}
private void btnCustomer_Click(object sender, EventArgs e)
{
billController.ShowCustomerList(false);
_billController.ShowCustomerList(false);
}
public void SetCustomerDisplay(string name)
{
btnCustomer.Text = name;
}
public void ShowInfo(string billID, string kotID, DateTime creationDate, DateTime date, DateTime lastEditDate, string customer, string tableID, int waiterID, string waiter)
{
this.txtBillID.Text = billID;
this.txtKotID.Text = kotID;
this.txtCreationDate.Text = creationDate.ToString("HH:mm dd-MMM-yyyy");
this.txtDate.Text = date.ToString("HH:mm dd-MMM-yyyy");
this.txtLastEditDate.Text = lastEditDate.ToString("HH:mm dd-MMM-yyyy");
this.btnCustomer.Text = customer;
this.txtTableID.Text = tableID;
this.btnWaiter.Tag = waiterID;
this.btnWaiter.Text = string.Format("{0} - F5", waiter);
}
public BindingSource BindingSource
{
get
{
return bindingSource;
}
}
private void btnVoid_Click(object sender, EventArgs e)
{
try
{
billController.VoidBill();
_billController.VoidBill();
}
catch (PermissionException ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnRate_Click(object sender, EventArgs e)
{
billController.ChangeRate();
_billController.ChangeRate();
}
private void btnClear_Click(object sender, EventArgs e)
{
billController.CancelBillChanges();
_billController.CancelBillChanges();
}
private void dgvProducts_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
DataGridView dgv = sender as DataGridView;
BillInventory data = dgv.Rows[e.RowIndex].DataBoundItem as BillInventory;
var dgv = sender as DataGridView;
var data = dgv.Rows[e.RowIndex].DataBoundItem as BillInventory;
if (data.Tax == -1)
{
@ -329,9 +200,9 @@ namespace Tanshu.Accounts.PointOfSale
private void btnWaiter_Click(object sender, EventArgs e)
{
using (SelectWaiter selectWaiter = new SelectWaiter(WaiterBI.GetFilteredWaiters, true))
using (var selectWaiter = new SelectWaiter(WaiterBI.GetFilteredWaiters, true))
{
selectWaiter.waiterEvent += new WaiterEventHandler(selectWaiter_waiterEvent);
selectWaiter.waiterEvent += selectWaiter_waiterEvent;
selectWaiter.ShowDialog();
if (selectWaiter.SelectedItem != null)
{
@ -345,7 +216,8 @@ namespace Tanshu.Accounts.PointOfSale
}
}
}
Waiter selectWaiter_waiterEvent(object sender, WaiterEventArgs e)
private Waiter selectWaiter_waiterEvent(object sender, WaiterEventArgs e)
{
Waiter waiter = e.Waiter;
if (!Thread.CurrentPrincipal.IsInRole("Waiter/Master"))
@ -368,33 +240,29 @@ namespace Tanshu.Accounts.PointOfSale
throw new ArgumentException();
}
}
public void CloseWindow()
{
this.Close();
}
private void btnSettle_Click(object sender, EventArgs e)
{
billController.SettleBill();
_billController.SettleBill();
}
private void btnModifier_Click(object sender, EventArgs e)
{
var item = billController.CurrentProduct;
BillInventory item = _billController.CurrentProduct;
if (item == null)
return;
var id = new ProductGroupBI().GetProductGroupOfProduct(item.ProductID).ProductGroupID;
billController.ShowModifiers(id, item);
int id = new ProductGroupBI().GetProductGroupOfProduct(item.ProductID).ProductGroupID;
_billController.ShowModifiers(id, item);
}
private void btnDelete_Click(object sender, EventArgs e)
{
billController.SetQuantity(-1, false);
_billController.SetQuantity(-1, false);
}
private void btnMoveTable_Click(object sender, EventArgs e)
{
billController.MoveTable();
_billController.MoveTable();
}
private void btnMore_Click(object sender, EventArgs e)
@ -407,6 +275,7 @@ namespace Tanshu.Accounts.PointOfSale
else
throw new InvalidOperationException("Button State incorrect");
}
private void MoreButton(bool more)
{
btnMore.Text = more ? "Less" : "More";
@ -418,15 +287,159 @@ namespace Tanshu.Accounts.PointOfSale
btnMoveTable.Visible = more;
btnMoveKot.Visible = more;
btnVoid.Visible = more;
}
private void btnMoveKot_Click(object sender, EventArgs e)
{
billController.MergeKot();
_billController.MergeKot();
}
#region Helper Functions
public void ClearBill(OrderedDictionary<BillItemKey, BillInventory> bill)
{
txtBillID.Text = "";
txtKotID.Text = "";
txtCreationDate.Text = "";
txtDate.Text = "";
txtLastEditDate.Text = "";
txtTableID.Text = "";
btnWaiter.Text = "Waiter - F5";
btnWaiter.Tag = null;
txtGrossTax.Text = "0.00";
txtDiscount.Text = "0.00";
txtServiceCharge.Text = "0.00";
txtGrossAmount.Text = "0.00";
txtAmount.Text = "0.00";
bindingSource.DataSource = bill.Values;
MoreButton(false);
ChangeFormState(SaleFormState.Waiting);
}
public void ShowAmount(decimal discountAmount, decimal grossAmount, decimal serviceChargeAmount,
decimal taxAmount, decimal valueAmount, List<BillInventory> bill)
{
txtGrossTax.Text = string.Format("{0:#0.00}", taxAmount);
txtDiscount.Text = string.Format("{0:#0.00}", discountAmount);
txtServiceCharge.Text = string.Format("{0:#0.00}", serviceChargeAmount);
txtGrossAmount.Text = string.Format("{0:#0.00}", grossAmount);
txtAmount.Text = string.Format("{0:#0.00}", Math.Round(valueAmount));
bindingSource.DataSource = bill;
dgvProducts.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
}
private void ChangeFormState(SaleFormState state)
{
flpGroup.Controls.Clear();
flpMain.Controls.Clear();
if (state == SaleFormState.Billing)
{
IList<ProductGroup> list = new ProductGroupBI().GetProductGroups();
ControlFactory.GenerateGroups(ref flpGroup, new Point(75, 75), 0, list, productTypeButton_Click);
}
else
{
ControlFactory.GenerateTables(ref flpMain, new Point(75, 75), 0, new FoodTableBI().List(),
tableButton_Click);
}
}
private void productTypeButton_Click(object sender, EventArgs e)
{
var button = sender as Button;
if (button == null)
return;
var item = button.Tag as ProductGroup;
if (item.Name == "Previous" || item.Name == "Next")
{
int start = item.ProductGroupID;
if (start < 0)
start = 0;
IList<ProductGroup> list = new ProductGroupBI().GetProductGroups();
ControlFactory.GenerateGroups(ref flpGroup, new Point(75, 75), start, list, productTypeButton_Click);
}
else
{
ControlFactory.GenerateProducts(ref flpMain, new Point(75, 75), 0,
ProductBI.GetProducts(item.ProductGroupID), productButton_Click);
}
}
private void productButton_Click(object sender, EventArgs e)
{
var button = sender as Button;
if (button == null)
return;
var item = button.Tag as Product;
if (item.Name == "Previous" || item.Name == "Next")
{
int start = item.ProductID;
if (start < 0)
start = 0;
IList<Product> list = ProductBI.GetProducts();
ControlFactory.GenerateProducts(ref flpMain, new Point(75, 75), start, list, productButton_Click);
}
else
{
_billController.AddProductToGrid(item.ProductID);
}
}
private void tableButton_Click(object sender, EventArgs e)
{
var button = sender as Button;
if (button == null)
return;
var item = button.Tag as FoodTable;
if (item.Name == "Previous" || item.Name == "Next")
{
int start = item.FoodTableID;
if (start < 0)
start = 0;
IList<FoodTable> list = new FoodTableBI().List();
ControlFactory.GenerateTables(ref flpMain, new Point(75, 75), start, list, tableButton_Click);
}
else
{
string tableName = item.Name;
_billController.LoadBillFromTable(tableName);
txtTableID.Text = tableName;
ChangeFormState(SaleFormState.Billing);
}
}
private void btnPrintBill_Click(object sender, EventArgs e)
{
if (btnWaiter.Tag == null)
btnWaiter.Tag = WaiterBI.GetWaiters()[0].WaiterID;
_billController.Save(true, (int) btnWaiter.Tag, txtTableID.Text);
}
private void btnPrintKot_Click(object sender, EventArgs e)
{
if (btnWaiter.Tag == null)
btnWaiter.Tag = WaiterBI.GetWaiters()[0].WaiterID;
_billController.Save(false, (int) btnWaiter.Tag, txtTableID.Text);
}
private void btnCancel_Click(object sender, EventArgs e)
{
_billController.CancelBillChanges();
}
private void btnQuantity_Click(object sender, EventArgs e)
{
_billController.SetQuantity(0, true);
}
private void btnDiscount_Click(object sender, EventArgs e)
{
_billController.ShowDiscount();
//if (dgvProducts.Rows.Count > 0)
// billController.SetDiscount(billController.CurrentProduct, -1);
}
#endregion
}
}
}

View File

@ -0,0 +1,78 @@
namespace Tanshu.Accounts.PointOfSale
{
partial class SettleChoicesForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.txtAmount = new System.Windows.Forms.TextBox();
this.flpSettlement = new System.Windows.Forms.FlowLayoutPanel();
this.flpSettlement.SuspendLayout();
this.SuspendLayout();
//
// txtAmount
//
this.txtAmount.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
this.txtAmount.Location = new System.Drawing.Point(3, 3);
this.txtAmount.Name = "txtAmount";
this.txtAmount.ReadOnly = true;
this.txtAmount.Size = new System.Drawing.Size(598, 20);
this.txtAmount.TabIndex = 6;
//
// flpSettlement
//
this.flpSettlement.Controls.Add(this.txtAmount);
this.flpSettlement.Dock = System.Windows.Forms.DockStyle.Fill;
this.flpSettlement.Location = new System.Drawing.Point(0, 0);
this.flpSettlement.Name = "flpSettlement";
this.flpSettlement.Size = new System.Drawing.Size(604, 107);
this.flpSettlement.TabIndex = 7;
//
// SettleChoicesForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(604, 107);
this.ControlBox = false;
this.Controls.Add(this.flpSettlement);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.MaximizeBox = false;
this.Name = "SettleChoicesForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Settle Bill";
this.Load += new System.EventHandler(this.SettleChoicesFormLoad);
this.flpSettlement.ResumeLayout(false);
this.flpSettlement.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TextBox txtAmount;
private System.Windows.Forms.FlowLayoutPanel flpSettlement;
}
}

View File

@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Contracts;
using System.Linq;
using Tanshu.Common.KeyboardControl;
namespace Tanshu.Accounts.PointOfSale
{
public partial class SettleChoicesForm : Form
{
private readonly IDictionary<Button, int> _list;
private decimal _amount;
public SettleChoicesForm(Voucher voucher)
{
InitializeComponent();
_amount = voucher.Settlements.Single(x => x.Settled == SettleOption.Amount).Amount +
voucher.Settlements.Single(x => x.Settled == SettleOption.RoundOff).Amount;
_amount *= -1;
OptionsChosen = new Dictionary<SettleOption, decimal>();
_list = new Dictionary<Button, int>();
}
private void ButtonClick(object sender, EventArgs e)
{
var button = sender as Button;
if (button == null || button.Tag == null)
return;
if (button.Tag is SettleOption)
{
var settleOption = (SettleOption)button.Tag;
using (var frm = new FrmSettleAmounts(new NumpadControl(), settleOption, _amount))
{
frm.ShowDialog();
UpdateChoice(settleOption, frm.AmountSettled, _list[button]);
}
}
else
{
if ((string)button.Tag == "Cancel")
_optionsChosen.Clear();
this.Close();
}
}
private void UpdateChoice(SettleOption settleOption, decimal amount, int group)
{
var oldAmount = _optionsChosen.ContainsKey(settleOption) ? _optionsChosen[settleOption] : 0;
if (amount == 0 && _optionsChosen.ContainsKey(settleOption))
_optionsChosen.Remove(settleOption);
else if (_optionsChosen.ContainsKey(settleOption))
_optionsChosen[settleOption] = amount;
else if (amount != 0)
_optionsChosen.Add(settleOption, amount);
_amount += oldAmount - amount;
txtAmount.Text = string.Format("Pending Amount: Rs. {0}", _amount);
if (_optionsChosen.Count == 0)
foreach (var item in _list.Where(item => item.Value != 0))
item.Key.Enabled = true;
else
foreach (var item in _list.Where(item => item.Value != group && item.Value != 0))
item.Key.Enabled = false;
}
private IDictionary<SettleOption, decimal> _optionsChosen;
public IDictionary<SettleOption, decimal> OptionsChosen
{
get
{
return _amount == 0 ? _optionsChosen : new Dictionary<SettleOption, decimal>();
}
private set { _optionsChosen = value; }
}
private void SettleChoicesFormLoad(object sender, EventArgs e)
{
txtAmount.Text = string.Format("Pending Amount: Rs. {0}", _amount);
var count = 0;
foreach (SettleOption item in Enum.GetValues(typeof(SettleOption)))
{
var attribute = (DisplayAttribute)item.GetType().GetField(item.ToString()).GetCustomAttributes(typeof(DisplayAttribute), false)[0];
if (!attribute.ShowInChoices)
continue;
var button = new Button
{
Name = item.ToString(),
Text = attribute.Name,
Size = new System.Drawing.Size(75, 75),
TabIndex = count,
UseVisualStyleBackColor = true,
Tag = item
};
button.Click += new EventHandler(ButtonClick);
flpSettlement.Controls.Add(button);
_list.Add(button, attribute.Group);
count++;
}
var controlButton = new Button
{
Name = "btnOK",
Text = "OK",
Size = new System.Drawing.Size(75, 75),
TabIndex = count,
UseVisualStyleBackColor = true,
Tag = "OK"
};
controlButton.Click += new EventHandler(ButtonClick);
flpSettlement.Controls.Add(controlButton);
_list.Add(controlButton, 0);
count++;
controlButton = new Button
{
Name = "btnCancel",
Text = "Cancel",
Size = new System.Drawing.Size(75, 75),
TabIndex = count,
UseVisualStyleBackColor = true,
Tag = "Cancel"
};
controlButton.Click += new EventHandler(ButtonClick);
flpSettlement.Controls.Add(controlButton);
_list.Add(controlButton, 0);
count++;
txtAmount.TabIndex = count;
this.Size = this.SizeFromClientSize(new Size(_list.Count * (75 + 6), 3 + txtAmount.Height + 6 + 75 + 3));
txtAmount.Width = flpSettlement.Width - 6;
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>