da929ad036
Breaking Change: Renamed Discontinued to IsActive and added NA field to products. Cleanup: Removed not used attributes Change: RoleConstants changed to simple string Feature: Table Create/Edit/Reorder and Modifier Create/Edit Form Feature: Bills now show the Tax name from the database and not a hack
448 lines
15 KiB
C#
448 lines
15 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
using Tanshu.Accounts.Contracts;
|
|
using Tanshu.Accounts.Entities;
|
|
using Tanshu.Accounts.Helpers;
|
|
using Tanshu.Accounts.Repository;
|
|
|
|
namespace Tanshu.Accounts.PointOfSale.Sales
|
|
{
|
|
public partial class SalesForm : Form, ISaleForm
|
|
{
|
|
private readonly IDictionary<Guid, IList<Product>> _productDictionary;
|
|
private readonly IList<ProductGroup> _productGroupList;
|
|
private ProductGroup _currentProductGroup;
|
|
public SalesForm(BillController billController)
|
|
{
|
|
InitializeComponent();
|
|
_productDictionary = new Dictionary<Guid, IList<Product>>();
|
|
|
|
this._billController = billController;
|
|
billController.InitGui(this);
|
|
using (var bi = new ProductGroupBI())
|
|
_productGroupList = bi.List(x => x.IsActive);
|
|
using (var bi = new ProductBI())
|
|
foreach (var item in _productGroupList)
|
|
_productDictionary.Add(item.ProductGroupID, bi.List(x => x.ProductGroup.ProductGroupID == item.ProductGroupID && x.IsActive));
|
|
}
|
|
|
|
#region ISaleForm Members
|
|
|
|
public void SetUserName(string name)
|
|
{
|
|
Text = name;
|
|
}
|
|
|
|
public void SetCustomerDisplay(string name)
|
|
{
|
|
btnCustomer.Text = name;
|
|
}
|
|
|
|
public void SetWaiterDisplay(string name)
|
|
{
|
|
btnWaiter.Text = string.Format("{0} - F5", name);
|
|
}
|
|
|
|
public void ShowInfo(Voucher voucher)
|
|
{
|
|
if (voucher.VoucherID == Guid.Empty)
|
|
{
|
|
txtTableID.Text = voucher.Table.Name;
|
|
txtPax.Text = voucher.Pax.ToString();
|
|
}
|
|
else
|
|
{
|
|
txtBillID.Text = voucher.BillID;
|
|
txtKotID.Text = voucher.KotID;
|
|
txtCreationDate.Text = voucher.CreationDate.ToString("HH:mm dd-MMM-yyyy");
|
|
txtDate.Text = voucher.Date.Value.ToString("HH:mm dd-MMM-yyyy");
|
|
txtLastEditDate.Text = voucher.LastEditDate.ToString("HH:mm dd-MMM-yyyy");
|
|
btnCustomer.Text = voucher.Customer.Name;
|
|
txtTableID.Text = voucher.Table.Name;
|
|
txtPax.Text = voucher.Pax.ToString();
|
|
btnWaiter.Text = string.Format("{0} - F5", voucher.Waiter.Name);
|
|
}
|
|
}
|
|
|
|
public BindingSource BindingSource
|
|
{
|
|
get { return bindingSource; }
|
|
}
|
|
|
|
public void CloseWindow()
|
|
{
|
|
Close();
|
|
}
|
|
|
|
#endregion
|
|
|
|
private void SalesForm_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
switch (e.KeyCode)
|
|
{
|
|
case Keys.F2:
|
|
{
|
|
btnQuantity_Click(sender, new EventArgs());
|
|
break;
|
|
}
|
|
case Keys.F3:
|
|
{
|
|
btnDiscount_Click(sender, new EventArgs());
|
|
break;
|
|
}
|
|
case Keys.F4:
|
|
{
|
|
if (!e.Alt)
|
|
_billController.ShowCustomers(false);
|
|
break;
|
|
}
|
|
case Keys.F5:
|
|
{
|
|
btnWaiter_Click(sender, new EventArgs());
|
|
break;
|
|
}
|
|
case Keys.F7:
|
|
{
|
|
//using (var selectProduct = new SelectProduct(ProductBI.GetFilteredProducts, true))
|
|
//{
|
|
// selectProduct.ShowDialog();
|
|
// if (selectProduct.SelectedItem != null)
|
|
// _billController.AddProduct(selectProduct.SelectedItem.ProductID);
|
|
//}
|
|
break;
|
|
}
|
|
case Keys.F8:
|
|
{
|
|
_billController.LoadBill(null);
|
|
break;
|
|
}
|
|
case Keys.F11:
|
|
{
|
|
btnPrintBill_Click(sender, e);
|
|
break;
|
|
}
|
|
case Keys.F12:
|
|
{
|
|
btnPrintKot_Click(sender, e);
|
|
break;
|
|
}
|
|
case Keys.Delete:
|
|
{
|
|
_billController.SetQuantity(-1, false);
|
|
//_billController.ProductRemove();
|
|
break;
|
|
}
|
|
case Keys.Add:
|
|
{
|
|
_billController.SetQuantity(1, false);
|
|
break;
|
|
}
|
|
case Keys.Subtract:
|
|
{
|
|
_billController.SetQuantity(-1, false);
|
|
break;
|
|
}
|
|
case Keys.Up:
|
|
{
|
|
if ((bindingSource.Position >= 1) && (!dgvProducts.Focused))
|
|
bindingSource.Position -= 1;
|
|
break;
|
|
}
|
|
case Keys.Down:
|
|
{
|
|
if ((bindingSource.Position < bindingSource.Count - 1) && (!dgvProducts.Focused))
|
|
bindingSource.Position += 1;
|
|
break;
|
|
}
|
|
case Keys.Escape:
|
|
{
|
|
_billController.CancelBillChanges();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void SalesForm_Load(object sender, EventArgs e)
|
|
{
|
|
_billController.FormLoad();
|
|
FormState = SaleFormState.Waiting;
|
|
}
|
|
|
|
private void btnCustomer_Click(object sender, EventArgs e)
|
|
{
|
|
_billController.ShowCustomers(false);
|
|
}
|
|
|
|
private void btnVoid_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
_billController.VoidBill();
|
|
}
|
|
catch (PermissionException ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void btnRate_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
_billController.SetRate();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!(ex is ValidationException) && !(ex is PermissionException))
|
|
throw;
|
|
}
|
|
}
|
|
|
|
private void btnClear_Click(object sender, EventArgs e)
|
|
{
|
|
_billController.CancelBillChanges();
|
|
}
|
|
|
|
private void dgvProducts_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
|
|
{
|
|
var dgv = sender as DataGridView;
|
|
var data = dgv.Rows[e.RowIndex].DataBoundItem as BillItemValue;
|
|
|
|
if (data.IsKot)
|
|
{
|
|
e.CellStyle.SelectionBackColor = Color.Blue;
|
|
e.CellStyle.BackColor = Color.LightBlue;
|
|
}
|
|
else if (data.Printed)
|
|
{
|
|
e.CellStyle.SelectionBackColor = Color.HotPink;
|
|
e.CellStyle.BackColor = Color.LightPink;
|
|
}
|
|
else
|
|
{
|
|
e.CellStyle.SelectionBackColor = Color.Green;
|
|
e.CellStyle.BackColor = Color.LightGreen;
|
|
}
|
|
}
|
|
|
|
private void btnWaiter_Click(object sender, EventArgs e)
|
|
{
|
|
_billController.ShowWaiters(false);
|
|
}
|
|
|
|
private void btnSettle_Click(object sender, EventArgs e)
|
|
{
|
|
_billController.SettleBill();
|
|
}
|
|
|
|
private void btnModifier_Click(object sender, EventArgs e)
|
|
{
|
|
var item = _billController.CurrentProduct;
|
|
if (item == null)
|
|
return;
|
|
|
|
Guid id;
|
|
using (var bi = new ProductGroupBI())
|
|
id = bi.GetProductGroupOfProduct(item.ProductID).ProductGroupID;
|
|
_billController.ShowModifiers(id, item);
|
|
}
|
|
|
|
private void btnDelete_Click(object sender, EventArgs e)
|
|
{
|
|
_billController.SetQuantity(-1, false);
|
|
}
|
|
|
|
private void btnMoveTable_Click(object sender, EventArgs e)
|
|
{
|
|
_billController.MoveTable();
|
|
}
|
|
|
|
private void btnMore_Click(object sender, EventArgs e)
|
|
{
|
|
var button = sender as Button;
|
|
if (button == null)
|
|
return;
|
|
if (button.Text == "More")
|
|
MoreButton(true);
|
|
else if (button.Text == "Less")
|
|
MoreButton(false);
|
|
else
|
|
throw new InvalidOperationException("Button State incorrect");
|
|
}
|
|
|
|
private void MoreButton(bool more)
|
|
{
|
|
btnMore.Text = more ? "Less" : "More";
|
|
btnQuantity.Visible = !more;
|
|
btnRate.Visible = more;
|
|
btnDelete.Visible = !more;
|
|
btnDiscount.Visible = !more;
|
|
btnModifier.Visible = !more;
|
|
btnMoveTable.Visible = more;
|
|
btnMoveKot.Visible = more;
|
|
btnVoid.Visible = more;
|
|
btnSplitBill.Visible = more;
|
|
}
|
|
|
|
private void btnMoveKot_Click(object sender, EventArgs e)
|
|
{
|
|
_billController.MoveKot();
|
|
}
|
|
|
|
#region Helper Functions
|
|
|
|
public void ClearBill(List<BillItemValue> bill)
|
|
{
|
|
txtBillID.Text = "";
|
|
txtKotID.Text = "";
|
|
txtCreationDate.Text = "";
|
|
txtDate.Text = "";
|
|
txtLastEditDate.Text = "";
|
|
txtTableID.Text = "";
|
|
txtPax.Text = "";
|
|
btnWaiter.Text = "Waiter - F5";
|
|
txtGrossTax.Text = "0.00";
|
|
txtDiscount.Text = "0.00";
|
|
txtServiceCharge.Text = "0.00";
|
|
txtGrossAmount.Text = "0.00";
|
|
txtAmount.Text = "0.00";
|
|
bindingSource.CurrencyManager.Position = 0; //Hack for Mono
|
|
bindingSource.DataSource = bill;
|
|
MoreButton(false);
|
|
FormState = SaleFormState.Waiting;
|
|
}
|
|
|
|
public void ShowAmount(decimal discountAmount, decimal grossAmount, decimal serviceChargeAmount,
|
|
decimal taxAmount, decimal valueAmount, List<BillItemValue> 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);
|
|
}
|
|
|
|
public SaleFormState FormState
|
|
{
|
|
set
|
|
{
|
|
flpGroup.Controls.Clear();
|
|
flpMain.Controls.Clear();
|
|
if (value == SaleFormState.Billing)
|
|
ControlFactory.GenerateGroups(ref flpGroup, new Point(75, 75), 0, _productGroupList, productTypeButton_Click, productTypePage_Click);
|
|
else
|
|
using (var bi = new FoodTableBI())
|
|
ControlFactory.GenerateTables(ref flpMain, new Point(75, 75), 0, bi.List(x => x.IsActive), tableButton_Click, tablePage_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 == null)
|
|
return;
|
|
_currentProductGroup = item;
|
|
ControlFactory.GenerateProducts(ref flpMain, new Point(75, 75), 0,
|
|
_productDictionary[item.ProductGroupID], productButton_Click, productPage_Click);
|
|
}
|
|
|
|
private void productTypePage_Click(object sender, EventArgs e)
|
|
{
|
|
var button = sender as Button;
|
|
if (button == null)
|
|
return;
|
|
var start = (int)button.Tag;
|
|
if (start < 0)
|
|
start = 0;
|
|
ControlFactory.GenerateGroups(ref flpGroup, new Point(75, 75), start, _productGroupList, productTypeButton_Click, productTypePage_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.IsNotAvailable)
|
|
return;
|
|
_billController.AddProduct(item);
|
|
}
|
|
|
|
private void productPage_Click(object sender, EventArgs e)
|
|
{
|
|
var button = sender as Button;
|
|
if (button == null)
|
|
return;
|
|
var item = button.Tag as Product;
|
|
var start = (int)button.Tag;
|
|
if (start < 0)
|
|
start = 0;
|
|
ControlFactory.GenerateProducts(ref flpMain, new Point(75, 75), start, _productDictionary[_currentProductGroup.ProductGroupID], productButton_Click, productPage_Click);
|
|
}
|
|
|
|
private void tableButton_Click(object sender, EventArgs e)
|
|
{
|
|
var button = sender as Button;
|
|
if (button == null)
|
|
return;
|
|
var item = button.Tag as FoodTable;
|
|
var tableName = item.Name;
|
|
_billController.LoadBill(tableName);
|
|
FormState = SaleFormState.Billing;
|
|
}
|
|
|
|
private void tablePage_Click(object sender, EventArgs e)
|
|
{
|
|
var button = sender as Button;
|
|
if (button == null)
|
|
return;
|
|
var start = (int)button.Tag;
|
|
if (start < 0)
|
|
start = 0;
|
|
using (var bi = new FoodTableBI())
|
|
ControlFactory.GenerateTables(ref flpMain, new Point(75, 75), start, bi.List(x => x.IsActive), tableButton_Click, tablePage_Click);
|
|
}
|
|
private void btnPrintBill_Click(object sender, EventArgs e)
|
|
{
|
|
_billController.SaveBill();
|
|
}
|
|
|
|
private void btnPrintKot_Click(object sender, EventArgs e)
|
|
{
|
|
_billController.SaveKot();
|
|
}
|
|
|
|
private void btnQuantity_Click(object sender, EventArgs e)
|
|
{
|
|
_billController.SetQuantity(0, true);
|
|
}
|
|
|
|
private void btnDiscount_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
_billController.SetDiscount();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
if (!(ex is ValidationException) && !(ex is PermissionException))
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
private void btnSplitBill_Click(object sender, EventArgs e)
|
|
{
|
|
_billController.SplitBill();
|
|
}
|
|
}
|
|
} |