935 lines
36 KiB
C#
935 lines
36 KiB
C#
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.BI;
|
|
using Tanshu.Accounts.Contracts;
|
|
using Tanshu.Accounts.Helpers;
|
|
using Tanshu.Common;
|
|
|
|
|
|
namespace Tanshu.Accounts.PointOfSale
|
|
{
|
|
public partial class SalesForm : Form
|
|
{
|
|
#region Waiting
|
|
private List<Guid> selectedBills = new List<Guid>();
|
|
private List<PendingBillsBO> pendingBills = new List<PendingBillsBO>();
|
|
private PendingType pendingList = PendingType.Today;
|
|
#endregion
|
|
private SaleFormState formState = SaleFormState.Waiting;
|
|
#region Billing
|
|
private Dictionary<BillItemKey, SalesBillItemBO> bill = new Dictionary<BillItemKey, SalesBillItemBO>();
|
|
private CustomerBO customer = new CustomerBI().GetCustomer(new Guid("F016CBAD-206C-42C0-BB1D-6006CE57BAB5"));
|
|
#endregion
|
|
private SaleVoucherBO billInfo;
|
|
object lockObject = new object();
|
|
Guid? newBillID;
|
|
|
|
public SalesForm()
|
|
{
|
|
InitializeComponent();
|
|
btnCustomer.Text = customer.Name;
|
|
lblUser.Text = CurrentUser.user.Name;
|
|
}
|
|
|
|
public SalesForm(Guid voucherID)
|
|
: this()
|
|
{
|
|
newBillID = voucherID;
|
|
}
|
|
|
|
private void SalesForm_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (formState == SaleFormState.Billing)
|
|
{
|
|
#region Billing KeyDown
|
|
switch (e.KeyCode)
|
|
{
|
|
case Keys.F2:
|
|
{
|
|
if (dgvProducts.Rows.Count > 0)
|
|
SetQuantity(CurrentProduct, 0, false, true);
|
|
break;
|
|
}
|
|
case Keys.F3:
|
|
{
|
|
btnDiscount_Click(sender, new EventArgs());
|
|
break;
|
|
}
|
|
case Keys.F4:
|
|
{
|
|
if (!e.Alt)
|
|
ShowCustomerList(false);
|
|
break;
|
|
}
|
|
case Keys.F5:
|
|
{
|
|
btnWaiter_Click(sender, new EventArgs());
|
|
break;
|
|
}
|
|
case Keys.F7:
|
|
{
|
|
using (SelectProduct selectProduct = new SelectProduct(new ProductBI().GetFilteredProducts, true))
|
|
{
|
|
selectProduct.ShowDialog();
|
|
if (selectProduct.SelectedItem != null)
|
|
AddProductToGrid(selectProduct.SelectedItem.ProductID);
|
|
}
|
|
break;
|
|
}
|
|
case Keys.F8:
|
|
{
|
|
LoadBillFromTable();
|
|
break;
|
|
}
|
|
case Keys.F9:
|
|
{
|
|
if (dgvProducts.Rows.Count > 0)
|
|
SetAmount(CurrentProduct, -1);
|
|
break;
|
|
}
|
|
case Keys.F11:
|
|
{
|
|
btnPrintBill_Click(sender, e);
|
|
break;
|
|
}
|
|
case Keys.F12:
|
|
{
|
|
btnPrintKot_Click(sender, e);
|
|
break;
|
|
}
|
|
case Keys.Delete:
|
|
{
|
|
if (dgvProducts.Rows.Count > 0)
|
|
ProductRemove(CurrentProduct);
|
|
break;
|
|
}
|
|
case Keys.Add:
|
|
{
|
|
if (dgvProducts.Rows.Count > 0)
|
|
SetQuantity(CurrentProduct, 1, false, false);
|
|
break;
|
|
}
|
|
case Keys.Subtract:
|
|
{
|
|
if (dgvProducts.Rows.Count > 0)
|
|
SetQuantity(CurrentProduct, -1, false, 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:
|
|
{
|
|
if (bill.Count != 0)
|
|
if (MessageBox.Show("Cancel current bill?", "Cancel bill", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
|
|
return;
|
|
ClearBill();
|
|
break;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
else
|
|
{
|
|
#region Waiting KeyDown
|
|
switch (e.KeyCode)
|
|
{
|
|
case Keys.F6:
|
|
{
|
|
ChangeFormState(SaleFormState.Billing);
|
|
break;
|
|
}
|
|
case Keys.F8:
|
|
{
|
|
LoadBillFromTable();
|
|
break;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
#region Helper Functions
|
|
private void ClearBill()
|
|
{
|
|
ShowCustomerList(true);
|
|
this.billInfo = null;
|
|
this.txtBillID.Text = "";
|
|
this.txtKotID.Text = "";
|
|
this.txtCreationDate.Text = "";
|
|
this.txtDate.Text = "";
|
|
this.txtLastEditDate.Text = "";
|
|
this.txtNarration.Text = "";
|
|
this.txtUserID.Text = "";
|
|
this.txtTableID.Text = "";
|
|
this.btnWaiter.Text = "Waiter - F5";
|
|
this.btnWaiter.Tag = null;
|
|
txtGrossTax.Text = "0.00";
|
|
txtDiscount.Text = "0.00";
|
|
txtGrossAmount.Text = "0.00";
|
|
txtAmount.Text = "0.00";
|
|
bill.Clear();
|
|
bindingSource.DataSource = bill.Values;
|
|
ChangeFormState(SaleFormState.Waiting);
|
|
}
|
|
private void AddProductToGrid(Guid productID)
|
|
{
|
|
BillHelperFunctions.AddProductToGrid(productID, bindingSource, bill);
|
|
calculateAmount();
|
|
}
|
|
|
|
private void SetQuantity(SalesBillItemBO product, decimal quantity, bool absolute, bool prompt)
|
|
{
|
|
if (product == null)
|
|
return;
|
|
BillHelperFunctions.SetQuantity(product, quantity, absolute, prompt, bindingSource, bill);
|
|
calculateAmount();
|
|
}
|
|
private void SetAmount(SalesBillItemBO product, decimal amount)
|
|
{
|
|
if (product == null)
|
|
return;
|
|
BillHelperFunctions.SetAmount(product, amount, bindingSource, bill);
|
|
calculateAmount();
|
|
}
|
|
private void SetDiscount(SalesBillItemBO product, decimal discount)
|
|
{
|
|
if (product == null)
|
|
return;
|
|
BillHelperFunctions.SetDiscount(product.productID, discount, customer, bill);
|
|
calculateAmount();
|
|
return;
|
|
}
|
|
private bool ProductRemove(SalesBillItemBO product)
|
|
{
|
|
if (product == null)
|
|
return false;
|
|
if (product.Printed > 0)
|
|
{
|
|
if (!Thread.CurrentPrincipal.IsInRole("Sales/EditPrintedProduct"))
|
|
{
|
|
MessageBox.Show("You are not allowed to delete already printed products");
|
|
return false;
|
|
}
|
|
if (MessageBox.Show(string.Format("Already {0} items have been printed.\n\rAre you sure you want to delete this item?", product.Printed), "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|
return false;
|
|
//If BillList(Location).Printed <> 0 Then ItemsDeleted.Add("Deleted " & BillList(Location).Printed & " " & BillList(Location).Name & " from Bill No " & mBillNo)
|
|
}
|
|
bill.Remove(new BillItemKey(product.productID, product.Printed == 0));
|
|
calculateAmount();
|
|
return true;
|
|
}
|
|
private void InputBox_Validating(object sender, InputBoxValidatingArgs e)
|
|
{
|
|
}
|
|
|
|
private void button_Click(object sender, EventArgs e)
|
|
{
|
|
Button button = sender as Button;
|
|
if (button == null)
|
|
return;
|
|
Guid tag = (Guid)button.Tag;
|
|
AddProductToGrid(tag);
|
|
}
|
|
private void calculateAmount()
|
|
{
|
|
txtGrossTax.Text = string.Format("{0:#0.00}", bill.Values.Sum(b => b.TaxAmount));
|
|
txtDiscount.Text = string.Format("{0:#0.00}", bill.Values.Sum(b => b.DiscountAmount));
|
|
txtGrossAmount.Text = string.Format("{0:#0.00}", bill.Values.Sum(b => b.GrossAmount));
|
|
txtAmount.Text = string.Format("{0:#0.00}", Math.Round(bill.Values.Sum(b => b.Value)));
|
|
bindingSource.DataSource = bill.Values.ToList();
|
|
dgvProducts.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
|
|
}
|
|
|
|
private void btnPrintBill_Click(object sender, EventArgs e)
|
|
{
|
|
Save(true);
|
|
}
|
|
private void btnPrintKot_Click(object sender, EventArgs e)
|
|
{
|
|
Save(false);
|
|
}
|
|
private void btnMultiPrint_Click(object sender, EventArgs e)
|
|
{
|
|
Save(true);
|
|
}
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
if (bill.Count != 0)
|
|
if (MessageBox.Show("Cancel current bill?", "Cancel bill", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
|
|
return;
|
|
ClearBill();
|
|
}
|
|
|
|
private SalesBillItemBO CurrentProduct
|
|
{
|
|
get
|
|
{
|
|
if (dgvProducts.Rows.Count == 0)
|
|
return null;
|
|
SalesBillItemBO product = bill.ElementAt(dgvProducts.CurrentRow.Index).Value;
|
|
return product;
|
|
}
|
|
}
|
|
private void btnQuantity_Click(object sender, EventArgs e)
|
|
{
|
|
if (dgvProducts.Rows.Count > 0)
|
|
SetQuantity(CurrentProduct, 0, false, true);
|
|
}
|
|
private void btnDiscount_Click(object sender, EventArgs e)
|
|
{
|
|
if (dgvProducts.Rows.Count > 0)
|
|
SetDiscount(CurrentProduct, -1);
|
|
}
|
|
#endregion
|
|
|
|
private void SalesForm_Load(object sender, EventArgs e)
|
|
{
|
|
ChangeFormState(SaleFormState.Waiting);
|
|
if (newBillID.HasValue)
|
|
{
|
|
LoadBill(newBillID.Value);
|
|
ChangeFormState(SaleFormState.Billing);
|
|
}
|
|
ControlFactory.GenerateButtons(ref pnlBilling, new Rectangle(489, 94, 481, 385), 6, 6, 2, new ProductBI().GetUnFilteredProducts(), new ButtonClickDelegate(button_Click));
|
|
}
|
|
|
|
private void ChangeFormState(SaleFormState state)
|
|
{
|
|
formState = state;
|
|
if (state == SaleFormState.Billing)
|
|
{
|
|
pnlWaiting.Visible = false;
|
|
pnlBilling.Visible = true;
|
|
}
|
|
else
|
|
{
|
|
pnlWaiting.Visible = true;
|
|
pnlBilling.Visible = false;
|
|
ListUnpaidBills();
|
|
}
|
|
}
|
|
|
|
#region Save Bill
|
|
private void Save(bool print)
|
|
{
|
|
if ((billInfo != null) && (new SaleVoucherBI().IsBillPrinted(billInfo.VoucherID)) && (!Thread.CurrentPrincipal.IsInRole("Sales/EditBill")))
|
|
MessageBox.Show("You are not authorized to access");
|
|
else
|
|
{
|
|
if (bill.Count != 0)
|
|
{
|
|
Guid? saved;
|
|
if (billInfo == null)
|
|
saved = AddNewSale(print);
|
|
else
|
|
saved = UpdateSale(print);
|
|
if (saved.HasValue)
|
|
{
|
|
if (newBillID.HasValue)
|
|
this.Close();
|
|
else
|
|
PrintBill(print, saved.Value);
|
|
}
|
|
ClearBill();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void PrintBill(bool finalBill, Guid voucherID)
|
|
{
|
|
if (!Thread.CurrentPrincipal.IsInRole("Sales/PrintKOT"))
|
|
{
|
|
MessageBox.Show("You are not authorized to access");
|
|
return;
|
|
}
|
|
if (!finalBill)
|
|
Accounts.Print.Thermal.PrintWaiterKot("KOT", voucherID, bill.Values.ToList());
|
|
else
|
|
{
|
|
if (!Thread.CurrentPrincipal.IsInRole("Sales/PrintBill"))
|
|
{
|
|
MessageBox.Show("You are not authorized to access");
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
Accounts.Print.Thermal.PrintBill(true, voucherID, bill.Values.ToList());
|
|
Accounts.Print.Thermal.PrintCustomerKot("KOT", voucherID, bill.Values.ToList());
|
|
}
|
|
}
|
|
}
|
|
private Guid? AddNewSale(bool finalBill)
|
|
{
|
|
if (billInfo != null)
|
|
{
|
|
MessageBox.Show("Error in AddNewSale, there is a previous sale in memory", "Error");
|
|
return null;
|
|
}
|
|
|
|
if (btnWaiter.Tag == null)
|
|
btnWaiter.Tag = new WaiterBI().GetWaiters()[0].WaiterID;
|
|
|
|
#region SaleVoucher
|
|
UserBO user = CurrentUser.user;
|
|
SaleVoucherBO saleVoucher = new SaleVoucherBO
|
|
{
|
|
CustomerID = customer.CustomerID,
|
|
Paid = false,
|
|
//Paid = finalBill,
|
|
TableID = txtTableID.Text,
|
|
WaiterID = (Guid)btnWaiter.Tag,
|
|
Printed = finalBill,
|
|
Void = false,
|
|
Date = DateTime.Now,
|
|
Narration = txtNarration.Text,
|
|
Ref = "",
|
|
Type = 'S',
|
|
UserID = user.UserID
|
|
};
|
|
#endregion
|
|
#region Inventories
|
|
List<InventoryBO> iList = new SaleVoucherBI().SaleInventory(bill.Values, null);
|
|
#endregion
|
|
new SaleVoucherBI().Insert(saleVoucher, iList);
|
|
return saleVoucher.VoucherID;
|
|
|
|
}
|
|
#region TransactionUpdate
|
|
private Guid? UpdateSale(bool finalBill)
|
|
{
|
|
if (btnWaiter.Tag == null)
|
|
btnWaiter.Tag = new WaiterBI().GetWaiters()[0].WaiterID;
|
|
|
|
UserBO user = CurrentUser.user;
|
|
#region Voucher and SaleVoucher
|
|
SaleVoucherBO saleVoucher = new SaleVoucherBO
|
|
{
|
|
VoucherID = billInfo.VoucherID,
|
|
timestamp = (byte[])billInfo.timestamp,
|
|
UserID = billInfo.UserID,
|
|
Date = billInfo.Date,
|
|
CreationDate = DateTime.Now,
|
|
LastEditDate = DateTime.Now,
|
|
Narration = billInfo.Narration,
|
|
Ref = "",
|
|
Type = 'S',
|
|
Alarm = billInfo.Alarm,
|
|
BillID = billInfo.BillID,
|
|
CustomerID = customer.CustomerID,
|
|
KotID = billInfo.KotID,
|
|
Paid = billInfo.Paid,
|
|
Printed = billInfo.Printed || finalBill,
|
|
TableID = txtTableID.Text,
|
|
Void = billInfo.Void,
|
|
VoidReason = billInfo.VoidReason,
|
|
WaiterID = (Guid)btnWaiter.Tag,
|
|
SaleTimestamp = (byte[])billInfo.SaleTimestamp
|
|
};
|
|
if ((!billInfo.Printed) && finalBill)
|
|
saleVoucher.Date = null;
|
|
#endregion
|
|
#region Inventory
|
|
List<InventoryBO> iList = new SaleVoucherBI().SaleInventory(bill.Values, billInfo.VoucherID);
|
|
#endregion
|
|
new SaleVoucherBI().Update(saleVoucher, iList);
|
|
return saleVoucher.VoucherID;
|
|
}
|
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
private void LoadBillFromTable()
|
|
{
|
|
InputBoxResult result = InputBox.Show("Enter Table Number", "Table", "0", InputBox_Validating);
|
|
if (result.OK)
|
|
{
|
|
txtTableID.Text = result.Text.Trim();
|
|
if ((txtTableID.Text != "C") && (txtTableID.Text != "") && (!txtTableID.Text.Contains(".")))
|
|
{
|
|
Guid? tID = new SaleVoucherBI().GetPendingVoucherID(txtTableID.Text);
|
|
if (tID.HasValue)
|
|
{
|
|
LoadBill(tID.Value);
|
|
ChangeFormState(SaleFormState.Billing);
|
|
}
|
|
}
|
|
else
|
|
ClearBill();
|
|
}
|
|
}
|
|
|
|
private void LoadBill(Guid voucherID)
|
|
{
|
|
ClearBill();
|
|
List<InventoryDisplayBO> iList = new List<InventoryDisplayBO>();
|
|
new SaleVoucherBI().GetSaleVoucher(voucherID, ref billInfo, ref iList);
|
|
|
|
this.txtBillID.Text = billInfo.BillID;
|
|
this.txtKotID.Text = billInfo.KotID;
|
|
this.txtCreationDate.Text = billInfo.CreationDate.ToString("HH:mm dd-MMM-yyyy");
|
|
this.txtDate.Text = billInfo.Date.Value.ToString("HH:mm dd-MMM-yyyy");
|
|
this.txtLastEditDate.Text = billInfo.LastEditDate.ToString("HH:mm dd-MMM-yyyy");
|
|
this.txtNarration.Text = billInfo.Narration;
|
|
this.txtUserID.Text = new UserBI().GetUser(billInfo.UserID).Name;
|
|
this.customer = new CustomerBI().GetCustomer(billInfo.CustomerID);
|
|
this.btnCustomer.Text = this.customer.Name;
|
|
this.txtTableID.Text = billInfo.TableID;
|
|
this.btnWaiter.Tag = billInfo.WaiterID;
|
|
this.btnWaiter.Text = string.Format("{0} - F5", new WaiterBI().GetWaiter(billInfo.WaiterID).Name);
|
|
|
|
foreach (InventoryDisplayBO inventory in iList)
|
|
{
|
|
if (inventory.ComplexProductID.HasValue)
|
|
{
|
|
BillItemKey key = new BillItemKey(inventory.ComplexProductID.Value, inventory.Quantity == 0);
|
|
if (!bill.ContainsKey(key))
|
|
{
|
|
decimal rate = 0, quantity = 0;
|
|
string name = "";
|
|
new SaleVoucherBI().GetComplexBillInformation(voucherID, inventory.ComplexProductID.Value, ref rate, ref quantity, ref name);
|
|
bill.Add(key, new SalesBillItemBO
|
|
{
|
|
productID = inventory.ComplexProductID.Value,
|
|
Discount = inventory.Discount,
|
|
Name = name,
|
|
Price = rate,
|
|
Printed = quantity,
|
|
Quantity = quantity,
|
|
Tax = inventory.Tax,
|
|
});
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
BillItemKey key = new BillItemKey(inventory.ProductID, inventory.Quantity == 0);
|
|
bill.Add(key, new SalesBillItemBO
|
|
{
|
|
productID = inventory.ProductID,
|
|
Discount = inventory.Discount,
|
|
Name = inventory.ProductName,
|
|
Price = inventory.Rate,
|
|
Printed = inventory.Quantity,
|
|
Quantity = inventory.Quantity,
|
|
Tax = inventory.Tax,
|
|
});
|
|
}
|
|
}
|
|
calculateAmount();
|
|
|
|
}
|
|
|
|
#region Waiting
|
|
|
|
private void btnStartBill_Click(object sender, EventArgs e)
|
|
{
|
|
ChangeFormState(SaleFormState.Billing);
|
|
}
|
|
|
|
private void btnSelectBill_Click(object sender, EventArgs e)
|
|
{
|
|
if (bsPending.Current != null)
|
|
{
|
|
LoadBill(((PendingBillsBO)bsPending.Current).voucherID);
|
|
ChangeFormState(SaleFormState.Billing);
|
|
}
|
|
}
|
|
|
|
private void tmrPending_Tick(object sender, EventArgs e)
|
|
{
|
|
if (chkRefresh.Checked)
|
|
ListUnpaidBills();
|
|
}
|
|
|
|
private void ListUnpaidBills()
|
|
{
|
|
lock (lockObject)
|
|
{
|
|
pendingBills = new SaleVoucherBI().GetPendingBills(pendingList);
|
|
bsPending.DataSource = pendingBills;
|
|
List<PendingBillsBO> alarmBills = new SaleVoucherBI().GetPendingBills(PendingType.Alarms).OrderBy(b => b.AlarmTime).ToList();
|
|
if (alarmBills.Count > 0)
|
|
{
|
|
PendingBillsBO al = alarmBills.First();
|
|
double seconds = al.AlarmTime.Value.Subtract(DateTime.Now).TotalSeconds;
|
|
if (seconds <= 0)
|
|
lblUser.Text = string.Format("Alarm {0:hh:MM}", al.AlarmTime);
|
|
else
|
|
lblUser.Text = CurrentUser.user.Name;
|
|
}
|
|
else
|
|
{
|
|
lblUser.Text = CurrentUser.user.Name;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void dgvPending_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DataGridView dgv = sender as DataGridView;
|
|
PendingBillsBO data = dgv.Rows[e.RowIndex].DataBoundItem as PendingBillsBO;
|
|
if (data.Printed)
|
|
e.CellStyle.BackColor = Color.LightSlateGray;
|
|
}
|
|
catch
|
|
{
|
|
// Catch and swallow exception when DataGridView attemps to get values for removed rows.
|
|
}
|
|
}
|
|
|
|
private void tcPending_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
switch (tcPending.SelectedTab.Text)
|
|
{
|
|
case "Today":
|
|
pendingList = PendingType.Today;
|
|
break;
|
|
case "Week":
|
|
pendingList = PendingType.Week;
|
|
break;
|
|
case "All":
|
|
pendingList = PendingType.All;
|
|
break;
|
|
case "Important":
|
|
pendingList = PendingType.Important;
|
|
break;
|
|
case "Alarms":
|
|
pendingList = PendingType.Alarms;
|
|
break;
|
|
}
|
|
ListUnpaidBills();
|
|
}
|
|
|
|
private void dgvPending_CellValuePushed(object sender, DataGridViewCellValueEventArgs e)
|
|
{
|
|
if (e.ColumnIndex != 0) return;
|
|
if ((bool)e.Value)
|
|
selectedBills.Add(pendingBills[e.RowIndex].voucherID);
|
|
else
|
|
selectedBills.Remove(pendingBills[e.RowIndex].voucherID);
|
|
}
|
|
|
|
private void dgvPending_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e)
|
|
{
|
|
if (e.ColumnIndex != 0) return;
|
|
if (e.RowIndex > pendingBills.Count - 1) return;
|
|
e.Value = selectedBills.Contains(pendingBills.ElementAt(e.RowIndex).voucherID);
|
|
}
|
|
#endregion
|
|
|
|
#region Billing
|
|
private void btnCustomer_Click(object sender, EventArgs e)
|
|
{
|
|
ShowCustomerList(false);
|
|
}
|
|
|
|
private void ShowCustomerList(bool reset)
|
|
{
|
|
if ((customer.CustomerID == new Guid("F016CBAD-206C-42C0-BB1D-6006CE57BAB5")) && (!reset))
|
|
{
|
|
using (SelectCustomer selectCustomer = new SelectCustomer(new CustomerBI().GetFilteredCustomers, true))
|
|
{
|
|
selectCustomer.customerEvent += new CustomerEventHandler(selectCustomer_customerEvent);
|
|
selectCustomer.ShowDialog();
|
|
if (selectCustomer.SelectedItem != null)
|
|
{
|
|
customer = selectCustomer.SelectedItem;
|
|
btnCustomer.Text = customer.Name;
|
|
}
|
|
else
|
|
{
|
|
customer = new CustomerBI().GetCustomer(new Guid("F016CBAD-206C-42C0-BB1D-6006CE57BAB5"));
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
customer = new CustomerBI().GetCustomer(new Guid("F016CBAD-206C-42C0-BB1D-6006CE57BAB5"));
|
|
btnCustomer.Text = customer.Name;
|
|
}
|
|
}
|
|
|
|
CustomerBO selectCustomer_customerEvent(object sender, CustomerEventArgs e)
|
|
{
|
|
using (CustomersForm form = new CustomersForm(e.CustomerID, e.Phone))
|
|
{
|
|
form.ShowDialog();
|
|
return form.Customer;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
private void dgvPending_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
if ((dgvProducts.Rows.Count > 0) && (dgvPending.CurrentRow != null))
|
|
{
|
|
LoadBill(((PendingBillsBO)bsPending.Current).voucherID);
|
|
ChangeFormState(SaleFormState.Billing);
|
|
}
|
|
}
|
|
|
|
private void btnRefresh_Click(object sender, EventArgs e)
|
|
{
|
|
ListUnpaidBills();
|
|
}
|
|
|
|
private void btnVoid_Click(object sender, EventArgs e)
|
|
{
|
|
if (billInfo != null)
|
|
{
|
|
if ((billInfo.Printed) && (!Thread.CurrentPrincipal.IsInRole("Sales/VoidPrintedBill")))
|
|
MessageBox.Show("Cannot void a paid bill");
|
|
else if (MessageBox.Show("Are you sure you want to void this bill?", "Void Bill", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
|
|
{
|
|
SelectVoidReason voidReason = new SelectVoidReason(GetVoidReason, true);
|
|
voidReason.ShowDialog();
|
|
if (voidReason.SelectedItem != null)
|
|
{
|
|
new SaleVoucherBI().VoidBill(billInfo.VoucherID, voidReason.SelectedItem.Description);
|
|
ClearBill();
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Please Select a reason if you want to void the bill", "Bill NOT Voided", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private List<StringType> GetVoidReason(Dictionary<string, string> filter)
|
|
{
|
|
List<StringType> list = new List<StringType>();
|
|
list.Add(new StringType("Discount"));
|
|
list.Add(new StringType("Printing Fault"));
|
|
list.Add(new StringType("Item Changed"));
|
|
list.Add(new StringType("Quantity Reduced"));
|
|
list.Add(new StringType("Costing Bill for Party"));
|
|
list.Add(new StringType("Cashier Mistake"));
|
|
list.Add(new StringType("Management Freesale"));
|
|
list.Add(new StringType("Other"));
|
|
return list.Where(i => i.Description.ToLower().Contains(filter["Name"].ToLower().Trim())).ToList();
|
|
}
|
|
private void btnRate_Click(object sender, EventArgs e)
|
|
{
|
|
if (!Thread.CurrentPrincipal.IsInRole("Sales/ChangeRate"))
|
|
MessageBox.Show("You are not authorized to access");
|
|
else
|
|
{
|
|
if (dgvProducts.Rows.Count > 0)
|
|
{
|
|
SalesBillItemBO product = bill.ElementAt(dgvProducts.CurrentRow.Index).Value;
|
|
decimal rate = 0;
|
|
InputBoxResult result = InputBox.Show("Enter Rate", "Rate", product.Price.ToString(), InputBox_Validating);
|
|
if (result.OK)
|
|
rate = Convert.ToDecimal(result.Text);
|
|
if (rate != 0)
|
|
{
|
|
BillHelperFunctions.SetRate(product.productID, rate, bill);
|
|
calculateAmount();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnClear_Click(object sender, EventArgs e)
|
|
{
|
|
ClearBill();
|
|
}
|
|
|
|
private void btnPaidCash_Click(object sender, EventArgs e)
|
|
{
|
|
UserBO user = CurrentUser.user;
|
|
new SaleVoucherBI().DeclareBillsPaid(user.UserID, selectedBills, false);
|
|
ListUnpaidBills();
|
|
}
|
|
|
|
private void btnPaidCC_Click(object sender, EventArgs e)
|
|
{
|
|
UserBO user = CurrentUser.user;
|
|
new SaleVoucherBI().DeclareBillsPaid(user.UserID, selectedBills, true);
|
|
ListUnpaidBills();
|
|
}
|
|
|
|
private void btnAlarm_Click(object sender, EventArgs e)
|
|
{
|
|
if (bsPending.Current != null)
|
|
{
|
|
PendingBillsBO billAlarm = (PendingBillsBO)bsPending.Current;
|
|
InputBoxResult result = InputBox.Show(
|
|
string.Format("Alarm for Bill {0} Rs. {1}", billAlarm.BillNo, billAlarm.Amount),
|
|
"Alarm",
|
|
string.Format("{0:dd-MMM-yyy HH:mm}", billAlarm.LastEdited),
|
|
InputBox_Validating);
|
|
if (result.OK)
|
|
{
|
|
DateTime alarmTime;
|
|
if (result.Text == string.Empty)
|
|
{
|
|
new SaleVoucherBI().SetAlarm(billAlarm.voucherID, null);
|
|
MessageBox.Show("Alarm Cleared", "Alarm Cleared", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
else if (DateTime.TryParseExact(result.Text, "dd-MMM-yyyy HH:mm", new CultureInfo("en-US"), DateTimeStyles.None, out alarmTime))
|
|
{
|
|
new SaleVoucherBI().SetAlarm(billAlarm.voucherID, alarmTime);
|
|
MessageBox.Show("Alarm set", "Alarm Set", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Alarm NOT set, please try again", "Alarm NOT Set", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnBillList_Click(object sender, EventArgs e)
|
|
{
|
|
//if (!Thread.CurrentPrincipal.IsInRole("Security/CreateUser"))
|
|
// return;
|
|
//#region Filters
|
|
//decimal? minValue = 0, maxValue = 0;
|
|
//decimal valTemp;
|
|
//DateTime? fromDate = DateTime.Now, toDate = DateTime.Now; // used in filters
|
|
//DateTime dateTemp;
|
|
//bool? showVoided;
|
|
|
|
//InputBoxResult result = InputBox.Show("Start Date", "Start Date", string.Format("{0:dd-MMM-yyy}", fromDate), InputBox_Validating);
|
|
//if ((result.OK) && (DateTime.TryParseExact(result.Text, "dd-MMM-yyyy", new CultureInfo("en-US"), DateTimeStyles.None, out dateTemp)))
|
|
//{
|
|
// fromDate = dateTemp;
|
|
//}
|
|
//result = InputBox.Show("Finish Date", "Finish Date", string.Format("{0:dd-MMM-yyy}", toDate), InputBox_Validating);
|
|
//if ((result.OK) && (DateTime.TryParseExact(result.Text, "dd-MMM-yyyy", new CultureInfo("en-US"), DateTimeStyles.None, out dateTemp)))
|
|
//{
|
|
// toDate = dateTemp;
|
|
//}
|
|
//result = InputBox.Show("Minimum Value", "Minimum Value", "0", InputBox_Validating);
|
|
//if ((result.OK) && (decimal.TryParse(result.Text, out valTemp)))
|
|
//{
|
|
// minValue = valTemp;
|
|
//}
|
|
//result = InputBox.Show("Maximum Value", "Maximum Value", "0", InputBox_Validating);
|
|
//if ((result.OK) && (decimal.TryParse(result.Text, out valTemp)))
|
|
//{
|
|
// maxValue = valTemp;
|
|
//}
|
|
//DialogResult dResult = MessageBox.Show("Show Un-Voided Bills only", "Un-Voided", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
|
|
//if (dResult == DialogResult.Yes)
|
|
// showVoided = false;
|
|
//else if (dResult == DialogResult.No)
|
|
// showVoided = true;
|
|
//else
|
|
// showVoided = null;
|
|
//#endregion
|
|
//List<PendingBillsBO> billList = ManagementBI.GetBillList(fromDate, toDate, minValue, maxValue, showVoided);
|
|
//using (SelectBill selectBill = new SelectBill(billList, true))
|
|
//{
|
|
// selectBill.ShowDialog();
|
|
// if (selectBill.SelectedItem != null)
|
|
// {
|
|
// LoadBill(selectBill.SelectedItem.voucherID);
|
|
// ChangeFormState(SaleFormState.Billing);
|
|
|
|
// }
|
|
//}
|
|
}
|
|
|
|
private void btnImportant_Click(object sender, EventArgs e)
|
|
{
|
|
if (bsPending.Current == null)
|
|
return;
|
|
if (MessageBox.Show("Are you sure?", "Mark / UnMark Important", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
|
return;
|
|
PendingBillsBO billAlarm = (PendingBillsBO)bsPending.Current;
|
|
new SaleVoucherBI().ToggleImportant(billAlarm.voucherID);
|
|
ListUnpaidBills();
|
|
}
|
|
|
|
private void dgvProducts_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
|
|
{
|
|
DataGridView dgv = sender as DataGridView;
|
|
SalesBillItemBO data = dgv.Rows[e.RowIndex].DataBoundItem as SalesBillItemBO;
|
|
|
|
if (data.Printed > 0)
|
|
{
|
|
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)
|
|
{
|
|
using (SelectWaiter selectWaiter = new SelectWaiter(new WaiterBI().GetFilteredWaiters, true))
|
|
{
|
|
selectWaiter.waiterEvent += new WaiterEventHandler(selectWaiter_waiterEvent);
|
|
selectWaiter.ShowDialog();
|
|
if (selectWaiter.SelectedItem != null)
|
|
{
|
|
btnWaiter.Text = string.Format("{0} - F5", selectWaiter.SelectedItem.Name);
|
|
btnWaiter.Tag = selectWaiter.SelectedItem.WaiterID;
|
|
}
|
|
else
|
|
{
|
|
btnWaiter.Text = "Select Waiter - F5";
|
|
btnWaiter.Tag = new WaiterBI().GetWaiters()[0].WaiterID;
|
|
}
|
|
}
|
|
}
|
|
WaiterBO selectWaiter_waiterEvent(object sender, WaiterEventArgs e)
|
|
{
|
|
WaiterBO waiter = e.Waiter;
|
|
if (!Thread.CurrentPrincipal.IsInRole("Waiter/Master"))
|
|
return waiter;
|
|
|
|
switch (e.Action)
|
|
{
|
|
case 1: // Add
|
|
new WaiterBI().Insert(waiter);
|
|
e.Handled = true;
|
|
return waiter;
|
|
case 2: // Edit
|
|
new WaiterBI().Update(waiter);
|
|
e.Handled = true;
|
|
return waiter;
|
|
case 3: // Delete
|
|
e.Handled = new WaiterBI().Delete(waiter.WaiterID);
|
|
return new WaiterBI().GetWaiter(1);
|
|
default:
|
|
throw new ArgumentException();
|
|
}
|
|
}
|
|
|
|
private void pnlWaiting_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|