narsil/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs
unknown 0172fc4e01 Added Service Tax and CIN Information to the bill printout
Added Nc Option in settlement
Merged Vouchers and SaleVoucher table. Need to update the Sql Schema
2014-08-08 17:35:38 +05:30

972 lines
37 KiB
C#

using System;
using System.Collections;
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
{
private static readonly Logging.SqlLogger Log = new Logging.SqlLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#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"));
private Guid? _advanceID;
#endregion
private VoucherBO _billInfo;
object lockObject = new object();
Guid? _newBillID;
readonly int _floor;
public SalesForm()
{
InitializeComponent();
btnCustomer.Text = customer.Name;
lblUser.Text = CurrentUser.user.Name;
var floorString = System.Configuration.ConfigurationManager.AppSettings["floor"];
_floor = !string.IsNullOrEmpty(floorString) ? Convert.ToInt32(floorString.Trim()) : 0;
}
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 FiltersBI().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.F10:
{
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();
_advanceID = null;
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)
{
var button = sender as Button;
if (button == null)
return;
var tag = (Guid)button.Tag;
AddProductToGrid(tag);
}
private void CalculateAmount()
{
txtGrossTax.Text = string.Format("{0:#0.00}", bill.Values.Sum(b => b.TotalTax));
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)
{
var val = Save(true);
if (val == null)
return;
PrintBill(val.VoucherID);
ClearBill();
}
private void btnPrintKot_Click(object sender, EventArgs e)
{
var val = Save(false);
if (val == null)
return;
PrintKOT(val.VoucherID);
ClearBill();
}
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);
}
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var dao = new SqlDAO.ProductDAO(connection))
{
Dictionary<string, string> filter = new Dictionary<string, string>();
filter.Add("Name", "");
filter.Add("ProductGroup", "");
var buttons = dao.GetFilteredProducts(filter);
ControlFactory.GenerateButtons(ref pnlBilling, new Rectangle(489, 94, 481, 385), 6, 6, 2, buttons, 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 VoucherBO Save(bool finalBill)
{
decimal? amount = null;
VoucherBO oldVoucher = null;
if (_billInfo != null)
oldVoucher = new VoucherBI().GetVoucher(_billInfo.VoucherID);
if (oldVoucher != null && oldVoucher.Printed)
{
if (!Thread.CurrentPrincipal.IsInRole("Sales/EditBill"))
{
MessageBox.Show("You are not authorized to access");
return null;
}
amount = oldVoucher.Amount;
}
if (bill.Count == 0)
return null;
//
if (_advanceID.HasValue)
{
var billAmount = Math.Round(bill.Values.Sum(b => b.Value));
decimal advanceAmount = 0;
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var dao = new SqlDAO.AdvanceDAO(connection))
{
advanceAmount = dao.Get(_advanceID.Value).Amount;
}
}
if (advanceAmount > billAmount)
{
if (MessageBox.Show("Advance adjusted amount more than bill amount, advance will not be adjusted.\n\rContinue will bill print?", "Advace adjustment error",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
return null;
else
_advanceID = null;
}
}
var saved = _billInfo == null ? AddNewSale(finalBill) : UpdateSale(finalBill);
if (amount != null)
Log.Warn(string.Format("{4} modified bill no {0}/{1} from (Rs. {2:#,00}) to (Rs. {3:#,00})", _billInfo.BillID, _billInfo.TableID, amount.Value, saved.Amount, Thread.CurrentPrincipal.Identity.Name));
if (_newBillID.HasValue)
this.Close();
return saved;
}
private void PrintBill(Guid voucherID)
{
if (!Thread.CurrentPrincipal.IsInRole("Sales/PrintBill"))
MessageBox.Show("You are not authorized to access");
else
{
Print.Thermal.PrintBill(voucherID);
Print.Thermal.PrintCustomerKot("KOT", voucherID, bill.Values.ToList());
}
}
private void PrintKOT(Guid voucherID)
{
if (!Thread.CurrentPrincipal.IsInRole("Sales/PrintKOT"))
MessageBox.Show("You are not authorized to access");
else
Print.Thermal.PrintWaiterKot("KOT", voucherID, bill.Values.ToList());
}
private VoucherBO 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;
var user = CurrentUser.user;
var voucher = new VoucherBO
{
CustomerID = customer.CustomerID,
PaidStatus = PaidStatus.Pending,
TableID = txtTableID.Text,
WaiterID = (Guid)btnWaiter.Tag,
Printed = finalBill,
Date = DateTime.Now,
Narration = txtNarration.Text,
UserID = user.UserID,
Floor = _floor,
AdvanceID = _advanceID
};
voucher.Inventories = new VoucherBI().SaleInventory(bill.Values, null);
return new VoucherBI().Insert(voucher);
}
private VoucherBO UpdateSale(bool finalBill)
{
if (btnWaiter.Tag == null)
btnWaiter.Tag = new WaiterBI().GetWaiters()[0].WaiterID;
var user = CurrentUser.user;
var voucher = new VoucherBO
{
VoucherID = _billInfo.VoucherID,
UserID = _billInfo.UserID,
Date = _billInfo.Date,
Narration = _billInfo.Narration,
Alarm = _billInfo.Alarm,
CustomerID = customer.CustomerID,
PaidStatus = _billInfo.PaidStatus,
Printed = _billInfo.Printed || finalBill,
TableID = txtTableID.Text,
VoidReason = _billInfo.VoidReason,
WaiterID = (Guid)btnWaiter.Tag,
Floor = _floor,
AdvanceID = _advanceID
};
if ((!_billInfo.Printed) && finalBill)
voucher.Date = null;
voucher.Inventories = new VoucherBI().SaleInventory(bill.Values, _billInfo.VoucherID);
return new VoucherBI().Update(voucher);
}
#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 VoucherBI().GetPendingVoucherID(txtTableID.Text, _floor);
if (tID.HasValue)
{
LoadBill(tID.Value);
ChangeFormState(SaleFormState.Billing);
}
}
else
ClearBill();
}
}
private void LoadBill(Guid voucherID)
{
ClearBill();
_billInfo = new VoucherBI().GetVoucher(voucherID);
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 = _billInfo.User.Name;
this.customer = _billInfo.Customer;
this.btnCustomer.Text = this.customer.Name;
this.txtTableID.Text = _billInfo.TableID;
this.btnWaiter.Tag = _billInfo.WaiterID;
this._advanceID = _billInfo.AdvanceID;
this.btnWaiter.Text = string.Format("{0} - F5", _billInfo.Waiter.Name);
foreach (var inventory in _billInfo.Inventories)
{
var 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,
Vat = inventory.Vat,
ServiceTax = inventory.ServiceTax
});
}
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 VoucherBI().GetPendingBills(pendingList, _floor);
bsPending.DataSource = pendingBills;
var alarmBills = new VoucherBI().GetPendingBills(PendingType.Alarms, _floor).OrderBy(b => b.AlarmTime).ToList();
if (alarmBills.Count > 0)
{
var al = alarmBills.First();
var seconds = al.AlarmTime.Value.Subtract(DateTime.Now).TotalSeconds;
lblUser.Text = seconds <= 0 ? string.Format("Alarm {0:hh:MM}", al.AlarmTime) : 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 "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 FiltersBI().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 if (!reset)
{
using (CustomersForm form = new CustomersForm(customer.CustomerID, customer.Phone))
{
form.ShowDialog();
}
}
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 VoucherBI().VoidBill(_billInfo.VoucherID, voidReason.SelectedItem.Description, CurrentUser.user.UserID);
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)
{
var user = CurrentUser.user;
new VoucherBI().DeclareBillsPaid(user.UserID, selectedBills, PaidStatus.Cash);
ListUnpaidBills();
}
private void btnPaidCC_Click(object sender, EventArgs e)
{
var user = CurrentUser.user;
new VoucherBI().DeclareBillsPaid(user.UserID, selectedBills, PaidStatus.CreditCard);
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 VoucherBI().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 VoucherBI().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;
var result = InputBox.Show("Bill No", "Bill No", "", InputBox_Validating);
if (result.OK)
{
var voucher = new VoucherBI().GetVoucher(result.Text);
if (voucher == null)
return;
LoadBill(voucher.VoucherID);
ChangeFormState(SaleFormState.Billing);
}
//#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 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 btnResetCustomer_Click(object sender, EventArgs e)
{
ShowCustomerList(true);
}
private void btnPaidStaff_Click(object sender, EventArgs e)
{
var user = CurrentUser.user;
new VoucherBI().DeclareBillsPaid(user.UserID, selectedBills, PaidStatus.Staff);
ListUnpaidBills();
}
private void btnPaidCredit_Click(object sender, EventArgs e)
{
var user = CurrentUser.user;
new VoucherBI().DeclareBillsPaid(user.UserID, selectedBills, PaidStatus.Credit);
ListUnpaidBills();
}
private void btnAdvance_Click(object sender, EventArgs e)
{
if (_billInfo != null && _billInfo.AdvanceID.HasValue)
return;
using (var frm = new AdjustAdvanceForm(true))
{
frm.ShowDialog();
_advanceID = frm.AdvanceID;
}
}
private void btnPaidNc_Click(object sender, EventArgs e)
{
var user = CurrentUser.user;
new VoucherBI().DeclareBillsPaid(user.UserID, selectedBills, PaidStatus.Nc);
ListUnpaidBills();
}
}
}