Moved SaleForm code to Controller, have to put Exception handlers for PermissionException
This commit is contained in:
@ -9,10 +9,19 @@ namespace Tanshu.Accounts.Contracts
|
|||||||
{
|
{
|
||||||
public const string SALES_CHECKOUT = "Sales/Checkout";
|
public const string SALES_CHECKOUT = "Sales/Checkout";
|
||||||
public const string SALES_SALES_BILL = "Sales/SalesBill";
|
public const string SALES_SALES_BILL = "Sales/SalesBill";
|
||||||
public const string SECURITY_MANAGE_ROLES = "Security/ManageRoles";
|
|
||||||
public const string SALES_SALE_DETAIL = "Sales/SaleDetail";
|
public const string SALES_SALE_DETAIL = "Sales/SaleDetail";
|
||||||
|
public const string SALES_VOID_BILL = "Sales/VoidPrintedBill";
|
||||||
|
public const string SALES_EDIT_BILL = "Sales/EditBill";
|
||||||
|
public const string SALES_PRINT_KOT = "Sales/PrintKOT";
|
||||||
|
public const string SALES_PRINT_BILL = "Sales/PrintBill";
|
||||||
|
public const string SALES_CHANGE_RATE = "Sales/ChangeRate";
|
||||||
|
public const string SALES_EDIT_PRINTED_PRODUCT = "Sales/EditPrintedProduct";
|
||||||
|
|
||||||
public const string MASTER_PRODUCTS = "Master/Products";
|
public const string MASTER_PRODUCTS = "Master/Products";
|
||||||
|
|
||||||
|
public const string SECURITY_MANAGE_ROLES = "Security/ManageRoles";
|
||||||
public const string LOG_VIEW = "Log/View";
|
public const string LOG_VIEW = "Log/View";
|
||||||
public const string MASTER_OWNER = "Master/Owner";
|
public const string MASTER_OWNER = "Master/Owner";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Tanshu.Accounts.PointOfSale
|
||||||
|
{
|
||||||
|
public class PermissionException : Exception
|
||||||
|
{
|
||||||
|
public PermissionException(string message)
|
||||||
|
: base(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
443
Tanshu.Accounts.PointOfSale/Controllers/BillController.cs
Normal file
443
Tanshu.Accounts.PointOfSale/Controllers/BillController.cs
Normal file
@ -0,0 +1,443 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Tanshu.Accounts.BI;
|
||||||
|
using Tanshu.Accounts.Helpers;
|
||||||
|
using Tanshu.Accounts.Contracts;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Tanshu.Common;
|
||||||
|
|
||||||
|
namespace Tanshu.Accounts.PointOfSale
|
||||||
|
{
|
||||||
|
public class BillController
|
||||||
|
{
|
||||||
|
private SaleVoucherBO billInfo;
|
||||||
|
private Dictionary<BillItemKey, SalesBillItemBO> bill = new Dictionary<BillItemKey, SalesBillItemBO>();
|
||||||
|
Guid? newBillID;
|
||||||
|
|
||||||
|
ISaleForm saleForm;
|
||||||
|
private CustomerBO customer = new CustomerBI().GetCustomer(new Guid("F016CBAD-206C-42C0-BB1D-6006CE57BAB5"));
|
||||||
|
public void InitGui(ISaleForm saleForm)
|
||||||
|
{
|
||||||
|
this.saleForm = saleForm;
|
||||||
|
this.saleForm.SetCustomerDisplay(customer.Name);
|
||||||
|
this.saleForm.SetUserName(Session.User.Name);
|
||||||
|
|
||||||
|
}
|
||||||
|
private void InitComponents()
|
||||||
|
{
|
||||||
|
InitModel();
|
||||||
|
InitView();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitView()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitModel()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
public void AddProductToGrid(Guid productID, BindingSource bindingSource)
|
||||||
|
{
|
||||||
|
BillHelperFunctions.AddProductToGrid(productID, bindingSource, bill);
|
||||||
|
ShowAmount();
|
||||||
|
}
|
||||||
|
public 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;
|
||||||
|
saleForm.SetCustomerDisplay(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"));
|
||||||
|
saleForm.SetCustomerDisplay(customer.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Save
|
||||||
|
// if (btnWaiter.Tag == null)
|
||||||
|
//btnWaiter.Tag = new WaiterBI().GetWaiters()[0].WaiterID;
|
||||||
|
|
||||||
|
public void Save(bool print, Guid waiterID, string tableID)
|
||||||
|
{
|
||||||
|
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(Roles.SALES_EDIT_BILL))
|
||||||
|
{
|
||||||
|
if ((billInfo != null) && (new SaleVoucherBI().IsBillPrinted(billInfo.VoucherID)) && (!roleBI.IsAllowed))
|
||||||
|
{
|
||||||
|
throw new PermissionException("You do not have the permission to reprint a bill.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bill.Count != 0)
|
||||||
|
{
|
||||||
|
Guid? saved;
|
||||||
|
if (billInfo == null)
|
||||||
|
saved = AddNewSale(print, waiterID, tableID);
|
||||||
|
else
|
||||||
|
saved = UpdateSale(print, waiterID, tableID);
|
||||||
|
if (saved.HasValue)
|
||||||
|
{
|
||||||
|
if (newBillID.HasValue)
|
||||||
|
saleForm.CloseWindow();
|
||||||
|
else
|
||||||
|
PrintBill(print, saved.Value);
|
||||||
|
}
|
||||||
|
ClearBill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private Guid? AddNewSale(bool finalBill, Guid waiterID, string tableID)
|
||||||
|
{
|
||||||
|
if (billInfo != null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Error in AddNewSale, there is a previous sale in memory", "Error");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#region SaleVoucher
|
||||||
|
UserBO user = Session.User;
|
||||||
|
SaleVoucherBO saleVoucher = new SaleVoucherBO
|
||||||
|
{
|
||||||
|
CustomerID = customer.CustomerID,
|
||||||
|
Paid = false,
|
||||||
|
//Paid = finalBill,
|
||||||
|
TableID = tableID,
|
||||||
|
WaiterID = waiterID,
|
||||||
|
Printed = finalBill,
|
||||||
|
Void = false,
|
||||||
|
Date = DateTime.Now,
|
||||||
|
Narration = "",
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
private Guid? UpdateSale(bool finalBill, Guid waiterID, string tableID)
|
||||||
|
{
|
||||||
|
UserBO user = Session.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 = tableID,
|
||||||
|
Void = billInfo.Void,
|
||||||
|
VoidReason = billInfo.VoidReason,
|
||||||
|
WaiterID = waiterID,
|
||||||
|
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
|
||||||
|
public void VoidBill()
|
||||||
|
{
|
||||||
|
if (billInfo != null)
|
||||||
|
{
|
||||||
|
if (billInfo.Printed)
|
||||||
|
{
|
||||||
|
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(Roles.SALES_VOID_BILL))
|
||||||
|
{
|
||||||
|
if (roleBI.IsAllowed)
|
||||||
|
{
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new PermissionException("You do not have the permission to void a bill.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CustomerBO selectCustomer_customerEvent(object sender, CustomerEventArgs e)
|
||||||
|
{
|
||||||
|
using (CustomersForm form = new CustomersForm(e.CustomerID, e.Phone))
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
return form.Customer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void PrintBill(bool finalBill, Guid voucherID)
|
||||||
|
{
|
||||||
|
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(Roles.SALES_PRINT_KOT))
|
||||||
|
if (!roleBI.IsAllowed)
|
||||||
|
throw new PermissionException("You are not allowed to print KOT");
|
||||||
|
|
||||||
|
if (!finalBill)
|
||||||
|
Accounts.Print.Thermal.PrintWaiterKot("KOT", voucherID, bill.Values.ToList());
|
||||||
|
else
|
||||||
|
{
|
||||||
|
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(Roles.SALES_PRINT_BILL))
|
||||||
|
{
|
||||||
|
if (roleBI.IsAllowed)
|
||||||
|
{
|
||||||
|
Accounts.Print.Thermal.PrintBill(Session.printer(), true, voucherID, bill.Values.ToList());
|
||||||
|
Accounts.Print.Thermal.PrintCustomerKot("KOT", voucherID, bill.Values.ToList());
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new PermissionException("You are not allowed to print KOT");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
public void SetNewBillID(Guid voucherID)
|
||||||
|
{
|
||||||
|
this.newBillID = voucherID;
|
||||||
|
}
|
||||||
|
public SalesBillItemBO CurrentProduct(int index)
|
||||||
|
{
|
||||||
|
if ((index != -1) && (index < bill.Count))
|
||||||
|
return bill.ElementAt(index).Value;
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
|
||||||
|
//if (dgvProducts.Rows.Count == 0)
|
||||||
|
// return null;
|
||||||
|
//SalesBillItemBO product = bill.ElementAt(dgvProducts.CurrentRow.Index).Value;
|
||||||
|
//return product;
|
||||||
|
}
|
||||||
|
private void ShowAmount()
|
||||||
|
{
|
||||||
|
decimal grossTax = bill.Values.Sum(b => b.TaxAmount);
|
||||||
|
decimal discount = bill.Values.Sum(b => b.DiscountAmount);
|
||||||
|
decimal grossAmount = bill.Values.Sum(b => b.GrossAmount);
|
||||||
|
decimal amount = bill.Values.Sum(b => b.Value);
|
||||||
|
//bill.Values.ToList();
|
||||||
|
saleForm.ShowAmount(grossTax, discount, grossAmount, amount, bill.Values.ToList());
|
||||||
|
}
|
||||||
|
public void SetDiscount(SalesBillItemBO product, decimal discount)
|
||||||
|
{
|
||||||
|
if (product == null)
|
||||||
|
return;
|
||||||
|
BillHelperFunctions.SetDiscount(product.productID, discount, customer, bill);
|
||||||
|
ShowAmount();
|
||||||
|
}
|
||||||
|
public void SetAmount(SalesBillItemBO product, BindingSource bindingSource, decimal amount)
|
||||||
|
{
|
||||||
|
if (product == null)
|
||||||
|
return;
|
||||||
|
BillHelperFunctions.SetAmount(product, amount, bindingSource, bill);
|
||||||
|
ShowAmount();
|
||||||
|
}
|
||||||
|
public bool ProductRemove(SalesBillItemBO product)
|
||||||
|
{
|
||||||
|
if (product == null)
|
||||||
|
return false;
|
||||||
|
if (product.Printed > 0)
|
||||||
|
{
|
||||||
|
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(Roles.SALES_EDIT_PRINTED_PRODUCT))
|
||||||
|
{
|
||||||
|
if (roleBI.IsAllowed)
|
||||||
|
{
|
||||||
|
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));
|
||||||
|
ShowAmount();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new PermissionException("You are not allowed to delete already printed products");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public void SetQuantity(SalesBillItemBO product, BindingSource bindingSource, decimal quantity, bool absolute, bool prompt)
|
||||||
|
{
|
||||||
|
if (product == null)
|
||||||
|
return;
|
||||||
|
BillHelperFunctions.SetQuantity(product, quantity, absolute, prompt, bindingSource, bill);
|
||||||
|
ShowAmount();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ChangeRate(int index)
|
||||||
|
{
|
||||||
|
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(Roles.SALES_CHANGE_RATE))
|
||||||
|
{
|
||||||
|
if (roleBI.IsAllowed)
|
||||||
|
{
|
||||||
|
SalesBillItemBO product = bill.ElementAt(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);
|
||||||
|
ShowAmount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw new PermissionException("You do not have permission to Change the Rate");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void InputBox_Validating(object sender, InputBoxValidatingArgs e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
private void LoadBill(Guid voucherID)
|
||||||
|
{
|
||||||
|
ClearBill();
|
||||||
|
List<InventoryDisplayBO> iList = new List<InventoryDisplayBO>();
|
||||||
|
new SaleVoucherBI().GetSaleVoucher(voucherID, ref billInfo, ref iList);
|
||||||
|
|
||||||
|
this.customer = new CustomerBI().GetCustomer(billInfo.CustomerID);
|
||||||
|
saleForm.ShowInfo(billInfo.BillID, billInfo.KotID, billInfo.CreationDate, billInfo.Date.Value, billInfo.LastEditDate, customer.Name, billInfo.TableID, billInfo.WaiterID, 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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ShowAmount();
|
||||||
|
|
||||||
|
}
|
||||||
|
public void LoadBillFromTable()
|
||||||
|
{
|
||||||
|
InputBoxResult result = InputBox.Show("Enter Table Number", "Table", "0", InputBox_Validating);
|
||||||
|
if (result.OK)
|
||||||
|
{
|
||||||
|
string tableID = result.Text.Trim();
|
||||||
|
if ((tableID != "C") && (tableID != "") && (!tableID.Contains(".")))
|
||||||
|
{
|
||||||
|
Guid? tID = new SaleVoucherBI().GetPendingVoucherID(tableID);
|
||||||
|
if (tID.HasValue)
|
||||||
|
{
|
||||||
|
LoadBill(tID.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ClearBill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CancelBillChanges()
|
||||||
|
{
|
||||||
|
if (bill.Count != 0)
|
||||||
|
if (MessageBox.Show("Cancel current bill?", "Cancel bill", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
|
||||||
|
return;
|
||||||
|
ClearBill();
|
||||||
|
|
||||||
|
}
|
||||||
|
public void ClearBill()
|
||||||
|
{
|
||||||
|
billInfo = null;
|
||||||
|
ShowCustomerList(true);
|
||||||
|
bill.Clear();
|
||||||
|
saleForm.ClearBill(bill);
|
||||||
|
}
|
||||||
|
public void FormLoad()
|
||||||
|
{
|
||||||
|
if (newBillID.HasValue)
|
||||||
|
{
|
||||||
|
LoadBill(newBillID.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// How to load a bill
|
||||||
|
//LoadBill(((PendingBillsBO)bsPending.Current).voucherID);
|
||||||
|
// ChangeFormState(SaleFormState.Billing);
|
||||||
31
Tanshu.Accounts.PointOfSale/Controllers/DisplayController.cs
Normal file
31
Tanshu.Accounts.PointOfSale/Controllers/DisplayController.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Tanshu.Accounts.PointOfSale
|
||||||
|
{
|
||||||
|
public class DisplayController
|
||||||
|
{
|
||||||
|
ISaleForm saleForm;
|
||||||
|
public void InitGui(ISaleForm saleForm)
|
||||||
|
{
|
||||||
|
this.saleForm = saleForm;
|
||||||
|
}
|
||||||
|
private void InitComponents()
|
||||||
|
{
|
||||||
|
InitModel();
|
||||||
|
InitView();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitView()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitModel()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
18
Tanshu.Accounts.PointOfSale/Controllers/ISaleForm.cs
Normal file
18
Tanshu.Accounts.PointOfSale/Controllers/ISaleForm.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Tanshu.Accounts.Contracts;
|
||||||
|
|
||||||
|
namespace Tanshu.Accounts.PointOfSale
|
||||||
|
{
|
||||||
|
public interface ISaleForm
|
||||||
|
{
|
||||||
|
void ClearBill(Dictionary<BillItemKey, SalesBillItemBO> bill);
|
||||||
|
void SetCustomerDisplay(string name);
|
||||||
|
void CloseWindow();
|
||||||
|
void ShowAmount(decimal grossTax, decimal discount, decimal grossAmount, decimal amount, List<SalesBillItemBO> bill);
|
||||||
|
void ShowInfo(string billID, string kotID, DateTime creationDate, DateTime date, DateTime lastEditDate, string customer, string tableID, Guid waiterID, string waiter);
|
||||||
|
void SetUserName(string name);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -227,7 +227,7 @@ namespace Tanshu.Accounts.PointOfSale
|
|||||||
if (roleBI.IsAllowed)
|
if (roleBI.IsAllowed)
|
||||||
{
|
{
|
||||||
new ProductBI().UpdateShortName();
|
new ProductBI().UpdateShortName();
|
||||||
using (SalesForm frmSale = new SalesForm())
|
using (SalesForm frmSale = new SalesForm(new BillController()))
|
||||||
frmSale.ShowDialog();
|
frmSale.ShowDialog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,33 +13,31 @@ using Tanshu.Common;
|
|||||||
|
|
||||||
namespace Tanshu.Accounts.PointOfSale
|
namespace Tanshu.Accounts.PointOfSale
|
||||||
{
|
{
|
||||||
public partial class SalesForm : Form
|
public partial class SalesForm : Form, ISaleForm
|
||||||
{
|
{
|
||||||
|
BillController billController;
|
||||||
List<Button> buttonList = new List<Button>();
|
List<Button> buttonList = new List<Button>();
|
||||||
List<Button> buttonHeads = new List<Button>();
|
List<Button> buttonHeads = new List<Button>();
|
||||||
int page = 0;
|
int page = 0;
|
||||||
int pageSize = 6;
|
int pageSize = 6;
|
||||||
#region Billing
|
|
||||||
private Dictionary<BillItemKey, SalesBillItemBO> bill = new Dictionary<BillItemKey, SalesBillItemBO>();
|
public SalesForm(BillController billController)
|
||||||
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();
|
InitializeComponent();
|
||||||
btnCustomer.Text = customer.Name;
|
this.billController = billController;
|
||||||
this.Text = Session.User.Name;
|
billController.InitGui(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SalesForm(Guid voucherID)
|
public SalesForm(Guid voucherID, BillController billController)
|
||||||
: this()
|
: this(billController)
|
||||||
{
|
{
|
||||||
newBillID = voucherID;
|
billController.SetNewBillID(voucherID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetUserName(string name)
|
||||||
|
{
|
||||||
|
this.Text = name;
|
||||||
|
}
|
||||||
private void SalesForm_KeyDown(object sender, KeyEventArgs e)
|
private void SalesForm_KeyDown(object sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
switch (e.KeyCode)
|
switch (e.KeyCode)
|
||||||
@ -47,7 +45,7 @@ namespace Tanshu.Accounts.PointOfSale
|
|||||||
case Keys.F2:
|
case Keys.F2:
|
||||||
{
|
{
|
||||||
if (dgvProducts.Rows.Count > 0)
|
if (dgvProducts.Rows.Count > 0)
|
||||||
SetQuantity(CurrentProduct, 0, false, true);
|
billController.SetQuantity(billController.CurrentProduct(dgvProducts.CurrentRow.Index), bindingSource, 0, false, true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Keys.F3:
|
case Keys.F3:
|
||||||
@ -58,7 +56,7 @@ namespace Tanshu.Accounts.PointOfSale
|
|||||||
case Keys.F4:
|
case Keys.F4:
|
||||||
{
|
{
|
||||||
if (!e.Alt)
|
if (!e.Alt)
|
||||||
ShowCustomerList(false);
|
billController.ShowCustomerList(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Keys.F5:
|
case Keys.F5:
|
||||||
@ -72,19 +70,19 @@ namespace Tanshu.Accounts.PointOfSale
|
|||||||
{
|
{
|
||||||
selectProduct.ShowDialog();
|
selectProduct.ShowDialog();
|
||||||
if (selectProduct.SelectedItem != null)
|
if (selectProduct.SelectedItem != null)
|
||||||
AddProductToGrid(selectProduct.SelectedItem.ProductID);
|
billController.AddProductToGrid(selectProduct.SelectedItem.ProductID, bindingSource);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Keys.F8:
|
case Keys.F8:
|
||||||
{
|
{
|
||||||
LoadBillFromTable();
|
billController.LoadBillFromTable();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Keys.F9:
|
case Keys.F9:
|
||||||
{
|
{
|
||||||
if (dgvProducts.Rows.Count > 0)
|
if (dgvProducts.Rows.Count > 0)
|
||||||
SetAmount(CurrentProduct, -1);
|
billController.SetAmount(billController.CurrentProduct(dgvProducts.CurrentRow.Index), bindingSource, -1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Keys.F11:
|
case Keys.F11:
|
||||||
@ -100,19 +98,19 @@ namespace Tanshu.Accounts.PointOfSale
|
|||||||
case Keys.Delete:
|
case Keys.Delete:
|
||||||
{
|
{
|
||||||
if (dgvProducts.Rows.Count > 0)
|
if (dgvProducts.Rows.Count > 0)
|
||||||
ProductRemove(CurrentProduct);
|
billController.ProductRemove(billController.CurrentProduct(dgvProducts.CurrentRow.Index));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Keys.Add:
|
case Keys.Add:
|
||||||
{
|
{
|
||||||
if (dgvProducts.Rows.Count > 0)
|
if (dgvProducts.Rows.Count > 0)
|
||||||
SetQuantity(CurrentProduct, 1, false, false);
|
billController.SetQuantity(billController.CurrentProduct(dgvProducts.CurrentRow.Index), bindingSource, 1, false, false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Keys.Subtract:
|
case Keys.Subtract:
|
||||||
{
|
{
|
||||||
if (dgvProducts.Rows.Count > 0)
|
if (dgvProducts.Rows.Count > 0)
|
||||||
SetQuantity(CurrentProduct, -1, false, false);
|
billController.SetQuantity(billController.CurrentProduct(dgvProducts.CurrentRow.Index), bindingSource, -1, false, false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Keys.Up:
|
case Keys.Up:
|
||||||
@ -129,20 +127,15 @@ namespace Tanshu.Accounts.PointOfSale
|
|||||||
}
|
}
|
||||||
case Keys.Escape:
|
case Keys.Escape:
|
||||||
{
|
{
|
||||||
if (bill.Count != 0)
|
billController.CancelBillChanges();
|
||||||
if (MessageBox.Show("Cancel current bill?", "Cancel bill", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
|
|
||||||
return;
|
|
||||||
ClearBill();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Helper Functions
|
#region Helper Functions
|
||||||
private void ClearBill()
|
public void ClearBill(Dictionary<BillItemKey, SalesBillItemBO> bill)
|
||||||
{
|
{
|
||||||
ShowCustomerList(true);
|
|
||||||
this.billInfo = null;
|
|
||||||
this.txtBillID.Text = "";
|
this.txtBillID.Text = "";
|
||||||
this.txtKotID.Text = "";
|
this.txtKotID.Text = "";
|
||||||
this.txtCreationDate.Text = "";
|
this.txtCreationDate.Text = "";
|
||||||
@ -155,59 +148,7 @@ namespace Tanshu.Accounts.PointOfSale
|
|||||||
txtDiscount.Text = "0.00";
|
txtDiscount.Text = "0.00";
|
||||||
txtGrossAmount.Text = "0.00";
|
txtGrossAmount.Text = "0.00";
|
||||||
txtAmount.Text = "0.00";
|
txtAmount.Text = "0.00";
|
||||||
bill.Clear();
|
|
||||||
bindingSource.DataSource = bill.Values;
|
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 productTypeButton_Click(object sender, EventArgs e)
|
private void productTypeButton_Click(object sender, EventArgs e)
|
||||||
@ -224,7 +165,7 @@ namespace Tanshu.Accounts.PointOfSale
|
|||||||
if (button == null)
|
if (button == null)
|
||||||
return;
|
return;
|
||||||
Guid tag = (Guid)button.Tag;
|
Guid tag = (Guid)button.Tag;
|
||||||
AddProductToGrid(tag);
|
billController.AddProductToGrid(tag, bindingSource);
|
||||||
}
|
}
|
||||||
private void tableButton_Click(object sender, EventArgs e)
|
private void tableButton_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@ -233,458 +174,106 @@ namespace Tanshu.Accounts.PointOfSale
|
|||||||
return;
|
return;
|
||||||
int tag = (int)button.Tag;
|
int tag = (int)button.Tag;
|
||||||
MessageBox.Show("Table No " + tag.ToString());
|
MessageBox.Show("Table No " + tag.ToString());
|
||||||
ChangeFormState(SaleFormState.Billing);
|
|
||||||
//AddProductToGrid(tag);
|
//AddProductToGrid(tag);
|
||||||
}
|
}
|
||||||
private void calculateAmount()
|
public void ShowAmount(decimal grossTax, decimal discount, decimal grossAmount, decimal amount, List<SalesBillItemBO> bill)
|
||||||
{
|
{
|
||||||
txtGrossTax.Text = string.Format("{0:#0.00}", bill.Values.Sum(b => b.TaxAmount));
|
txtGrossTax.Text = string.Format("{0:#0.00}", grossTax);
|
||||||
txtDiscount.Text = string.Format("{0:#0.00}", bill.Values.Sum(b => b.DiscountAmount));
|
txtDiscount.Text = string.Format("{0:#0.00}", discount);
|
||||||
txtGrossAmount.Text = string.Format("{0:#0.00}", bill.Values.Sum(b => b.GrossAmount));
|
txtGrossAmount.Text = string.Format("{0:#0.00}", grossAmount);
|
||||||
txtAmount.Text = string.Format("{0:#0.00}", Math.Round(bill.Values.Sum(b => b.Value)));
|
txtAmount.Text = string.Format("{0:#0.00}", Math.Round(amount));
|
||||||
bindingSource.DataSource = bill.Values.ToList();
|
bindingSource.DataSource = bill;
|
||||||
dgvProducts.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
|
dgvProducts.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnPrintBill_Click(object sender, EventArgs e)
|
private void btnPrintBill_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Save(true);
|
if (btnWaiter.Tag == null)
|
||||||
|
btnWaiter.Tag = new WaiterBI().GetWaiters()[0].WaiterID;
|
||||||
|
billController.Save(true, (Guid)btnWaiter.Tag, txtTableID.Text);
|
||||||
}
|
}
|
||||||
private void btnPrintKot_Click(object sender, EventArgs e)
|
private void btnPrintKot_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Save(false);
|
if (btnWaiter.Tag == null)
|
||||||
|
btnWaiter.Tag = new WaiterBI().GetWaiters()[0].WaiterID;
|
||||||
|
billController.Save(false, (Guid)btnWaiter.Tag, txtTableID.Text);
|
||||||
}
|
}
|
||||||
private void btnMultiPrint_Click(object sender, EventArgs e)
|
private void btnMultiPrint_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Save(true);
|
if (btnWaiter.Tag == null)
|
||||||
|
btnWaiter.Tag = new WaiterBI().GetWaiters()[0].WaiterID;
|
||||||
|
billController.Save(true, (Guid)btnWaiter.Tag, txtTableID.Text);
|
||||||
|
|
||||||
}
|
}
|
||||||
private void btnCancel_Click(object sender, EventArgs e)
|
private void btnCancel_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (bill.Count != 0)
|
billController.CancelBillChanges();
|
||||||
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)
|
private void btnQuantity_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (dgvProducts.Rows.Count > 0)
|
if (dgvProducts.Rows.Count > 0)
|
||||||
SetQuantity(CurrentProduct, 0, false, true);
|
billController.SetQuantity(billController.CurrentProduct(dgvProducts.CurrentRow.Index), bindingSource, 0, false, true);
|
||||||
}
|
}
|
||||||
private void btnDiscount_Click(object sender, EventArgs e)
|
private void btnDiscount_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (dgvProducts.Rows.Count > 0)
|
if (dgvProducts.Rows.Count > 0)
|
||||||
SetDiscount(CurrentProduct, -1);
|
billController.SetDiscount(billController.CurrentProduct(dgvProducts.CurrentRow.Index), -1);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private void SalesForm_Load(object sender, EventArgs e)
|
private void SalesForm_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
ChangeFormState(SaleFormState.Waiting);
|
billController.FormLoad();
|
||||||
if (newBillID.HasValue)
|
|
||||||
{
|
|
||||||
LoadBill(newBillID.Value);
|
|
||||||
ChangeFormState(SaleFormState.Billing);
|
|
||||||
}
|
|
||||||
//ControlFactory.GenerateButtons(ref pnlBilling, new Rectangle(489, 94, 400, 385), 5, 6, 2, new ProductBI().GetUnFilteredProducts(), new ButtonClickDelegate(productButton_Click));
|
//ControlFactory.GenerateButtons(ref pnlBilling, new Rectangle(489, 94, 400, 385), 5, 6, 2, new ProductBI().GetUnFilteredProducts(), new ButtonClickDelegate(productButton_Click));
|
||||||
//ControlFactory.GenerateButtons(ref pnlBilling, ref buttonHeads, new Rectangle(889, 0, 80, 688), 1, pageSize, 2, page, new ProductTypeBI().GetProductTypes(), new ButtonClickDelegate(productTypeButton_Click));
|
//ControlFactory.GenerateButtons(ref pnlBilling, ref buttonHeads, new Rectangle(889, 0, 80, 688), 1, pageSize, 2, page, new ProductTypeBI().GetProductTypes(), new ButtonClickDelegate(productTypeButton_Click));
|
||||||
//ControlFactory.GenerateButtons(ref pnlBilling, ref buttonHeads, new Rectangle(889, 90, 85, 498), 1, pageSize, 2, page, new ProductTypeBI().GetProductTypes(), new ButtonClickDelegate(productTypeButton_Click));
|
//ControlFactory.GenerateButtons(ref pnlBilling, ref buttonHeads, new Rectangle(889, 90, 85, 498), 1, pageSize, 2, page, new ProductTypeBI().GetProductTypes(), new ButtonClickDelegate(productTypeButton_Click));
|
||||||
ControlFactory.GenerateButtons(ref pnlBilling, ref buttonHeads, new Rectangle(390, 94, 499, 385), 6, 10, 2, new FoodTableBI().GetFoodTables(), new ButtonClickDelegate(tableButton_Click));
|
ControlFactory.GenerateButtons(ref pnlBilling, ref buttonHeads, new Rectangle(390, 94, 499, 385), 6, 10, 2, new FoodTableBI().GetFoodTables(), new ButtonClickDelegate(tableButton_Click));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ChangeFormState(SaleFormState state)
|
private void btnCustomer_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
pnlBilling.Visible = true;
|
billController.ShowCustomerList(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Save Bill
|
public void SetCustomerDisplay(string name)
|
||||||
private void Save(bool print)
|
|
||||||
{
|
{
|
||||||
if ((billInfo != null) && (new SaleVoucherBI().IsBillPrinted(billInfo.VoucherID)) && (!Thread.CurrentPrincipal.IsInRole("Sales/EditBill")))
|
btnCustomer.Text = name;
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
public void ShowInfo(string billID, string kotID, DateTime creationDate, DateTime date, DateTime lastEditDate, string customer, string tableID, Guid waiterID, string waiter)
|
||||||
private void PrintBill(bool finalBill, Guid voucherID)
|
|
||||||
{
|
{
|
||||||
if (!Thread.CurrentPrincipal.IsInRole("Sales/PrintKOT"))
|
this.txtBillID.Text = billID;
|
||||||
{
|
this.txtKotID.Text = kotID;
|
||||||
MessageBox.Show("You are not authorized to access");
|
this.txtCreationDate.Text = creationDate.ToString("HH:mm dd-MMM-yyyy");
|
||||||
return;
|
this.txtDate.Text = date.ToString("HH:mm dd-MMM-yyyy");
|
||||||
}
|
this.txtLastEditDate.Text = lastEditDate.ToString("HH:mm dd-MMM-yyyy");
|
||||||
if (!finalBill)
|
this.btnCustomer.Text = customer;
|
||||||
Accounts.Print.Thermal.PrintWaiterKot("KOT", voucherID, bill.Values.ToList());
|
this.txtTableID.Text = tableID;
|
||||||
else
|
this.btnWaiter.Tag = waiterID;
|
||||||
{
|
this.btnWaiter.Text = string.Format("{0} - F5", waiter);
|
||||||
if (!Thread.CurrentPrincipal.IsInRole("Sales/PrintBill"))
|
|
||||||
{
|
|
||||||
MessageBox.Show("You are not authorized to access");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Accounts.Print.Thermal.PrintBill(Session.printer(), 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 = Session.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 = "",
|
|
||||||
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 void btnVoid_Click(object sender, EventArgs e)
|
||||||
private Guid? UpdateSale(bool finalBill)
|
|
||||||
{
|
|
||||||
if (btnWaiter.Tag == null)
|
|
||||||
btnWaiter.Tag = new WaiterBI().GetWaiters()[0].WaiterID;
|
|
||||||
|
|
||||||
UserBO user = Session.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.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 dgvPending_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DataGridView dgv = sender as DataGridView;
|
billController.VoidBill();
|
||||||
PendingBillsBO data = dgv.Rows[e.RowIndex].DataBoundItem as PendingBillsBO;
|
|
||||||
if (data.Printed)
|
|
||||||
e.CellStyle.BackColor = Color.LightSlateGray;
|
|
||||||
}
|
}
|
||||||
catch
|
catch (PermissionException ex)
|
||||||
{
|
{
|
||||||
// Catch and swallow exception when DataGridView attemps to get values for removed rows.
|
MessageBox.Show(ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#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 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)
|
private void btnRate_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (!Thread.CurrentPrincipal.IsInRole("Sales/ChangeRate"))
|
if (dgvProducts.Rows.Count > 0)
|
||||||
MessageBox.Show("You are not authorized to access");
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (dgvProducts.Rows.Count > 0)
|
billController.ChangeRate(dgvProducts.CurrentRow.Index);
|
||||||
{
|
|
||||||
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)
|
private void btnClear_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
ClearBill();
|
billController.ClearBill();
|
||||||
}
|
|
||||||
|
|
||||||
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 dgvProducts_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
|
private void dgvProducts_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
|
||||||
@ -745,6 +334,10 @@ namespace Tanshu.Accounts.PointOfSale
|
|||||||
throw new ArgumentException();
|
throw new ArgumentException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void CloseWindow()
|
||||||
|
{
|
||||||
|
this.Close();
|
||||||
|
}
|
||||||
#region Dynamic Buttons
|
#region Dynamic Buttons
|
||||||
private void btnPrevious_Click(object sender, EventArgs e)
|
private void btnPrevious_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@ -755,7 +348,6 @@ namespace Tanshu.Accounts.PointOfSale
|
|||||||
|
|
||||||
ControlFactory.GenerateButtons(ref pnlBilling, ref buttonHeads, new Rectangle(889, 90, 85, 498), 1, pageSize, 2, page, list, new ButtonClickDelegate(productTypeButton_Click));
|
ControlFactory.GenerateButtons(ref pnlBilling, ref buttonHeads, new Rectangle(889, 90, 85, 498), 1, pageSize, 2, page, list, new ButtonClickDelegate(productTypeButton_Click));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnNext_Click(object sender, EventArgs e)
|
private void btnNext_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
page++;
|
page++;
|
||||||
|
|||||||
@ -83,9 +83,12 @@
|
|||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Authentication\PermissionException.cs" />
|
||||||
<Compile Include="Authentication\Session.cs" />
|
<Compile Include="Authentication\Session.cs" />
|
||||||
<Compile Include="Authentication\KeyboardLogin.cs" />
|
<Compile Include="Authentication\KeyboardLogin.cs" />
|
||||||
<Compile Include="Authentication\ILogin.cs" />
|
<Compile Include="Authentication\ILogin.cs" />
|
||||||
|
<Compile Include="Controllers\BillController.cs" />
|
||||||
|
<Compile Include="Controllers\ISaleForm.cs" />
|
||||||
<Compile Include="CurrencyCounter.cs">
|
<Compile Include="CurrencyCounter.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
@ -44,7 +44,7 @@ namespace Tanshu.Accounts.PointOfSale.Updates
|
|||||||
{
|
{
|
||||||
//Guid gd = new Guid(dgvPending.Rows[e.RowIndex].Cells[2].Value.ToString());
|
//Guid gd = new Guid(dgvPending.Rows[e.RowIndex].Cells[2].Value.ToString());
|
||||||
PendingBillsBO current = (PendingBillsBO)bsPending.Current;
|
PendingBillsBO current = (PendingBillsBO)bsPending.Current;
|
||||||
using (SalesForm frmSale = new SalesForm(current.voucherID))
|
using (SalesForm frmSale = new SalesForm(current.voucherID, new BillController()))
|
||||||
frmSale.ShowDialog();
|
frmSale.ShowDialog();
|
||||||
btnShowBill_Click(this, null);
|
btnShowBill_Click(this, null);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user