2011-01-10 19:49:11 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
using Tanshu.Accounts.Contracts;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
using Tanshu.Accounts.Entities;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
using Tanshu.Accounts.Helpers;
|
|
|
|
|
using Tanshu.Accounts.PointOfSale.Sales;
|
|
|
|
|
using Tanshu.Accounts.Print;
|
|
|
|
|
using Tanshu.Accounts.Repository;
|
|
|
|
|
using Tanshu.Common;
|
2011-01-10 19:49:11 +00:00
|
|
|
|
|
|
|
|
|
namespace Tanshu.Accounts.PointOfSale
|
|
|
|
|
{
|
|
|
|
|
public class BillController
|
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
private readonly OrderedDictionary<BillItemKey, BillItemValue> _bill;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
|
|
|
|
private Voucher _billInfo;
|
|
|
|
|
private Customer _customer = new CustomerBI().GetCustomer(1);
|
|
|
|
|
|
|
|
|
|
private int? _editVoucherID;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
private readonly bool _print;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
|
|
|
|
private ISaleForm _saleForm;
|
2011-01-10 19:49:11 +00:00
|
|
|
|
|
2011-06-23 12:47:48 +00:00
|
|
|
|
public BillController(int? editVoucherID, bool print)
|
2011-02-09 12:03:22 +00:00
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
this._editVoucherID = editVoucherID;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
_print = print;
|
|
|
|
|
_bill = new OrderedDictionary<BillItemKey, BillItemValue>();
|
2011-02-09 12:03:22 +00:00
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
2011-06-23 12:47:48 +00:00
|
|
|
|
public BillItemValue CurrentProduct
|
2011-03-11 18:49:48 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_saleForm.BindingSource.Position == -1)
|
|
|
|
|
return null;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
var item = _bill.ElementAt(_saleForm.BindingSource.Position);
|
|
|
|
|
return item.Key.BillItemType == BillItemType.Product ? item.Value : null;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-23 12:47:48 +00:00
|
|
|
|
public BillItemKey CurrentKot
|
2011-01-10 19:49:11 +00:00
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (_saleForm.BindingSource.Position == -1)
|
|
|
|
|
return null;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
var item = _bill.ElementAt(_saleForm.BindingSource.Position);
|
|
|
|
|
return item.Key.BillItemType == BillItemType.Kot ? item.Key : null;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-01-10 19:49:11 +00:00
|
|
|
|
|
2011-03-11 18:49:48 +00:00
|
|
|
|
public void InitGui(ISaleForm saleForm)
|
|
|
|
|
{
|
|
|
|
|
this._saleForm = saleForm;
|
|
|
|
|
this._saleForm.SetCustomerDisplay(_customer.Name);
|
|
|
|
|
this._saleForm.SetUserName(Session.User.Name);
|
2011-01-10 19:49:11 +00:00
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
2011-01-10 19:49:11 +00:00
|
|
|
|
private void InitComponents()
|
|
|
|
|
{
|
|
|
|
|
InitModel();
|
|
|
|
|
InitView();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitView()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitModel()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
2011-06-23 12:47:48 +00:00
|
|
|
|
public void AddProductToGrid(Product product)
|
2011-01-10 19:49:11 +00:00
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
AddProduct(product);
|
2011-01-30 07:14:05 +00:00
|
|
|
|
if (ProductGroupModifierBI.HasCompulsoryModifier(product.ProductGroup.ProductGroupID))
|
|
|
|
|
{
|
|
|
|
|
var item = CurrentProduct;
|
|
|
|
|
ShowModifiers(product.ProductGroup.ProductGroupID, item);
|
|
|
|
|
}
|
2011-01-10 19:49:11 +00:00
|
|
|
|
ShowAmount();
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
2011-01-22 12:38:30 +00:00
|
|
|
|
|
2011-06-23 12:47:48 +00:00
|
|
|
|
private void AddProduct(Product product)
|
|
|
|
|
{
|
|
|
|
|
var newKey = new BillItemKey(product.ProductID, 0);
|
|
|
|
|
|
|
|
|
|
if (_bill.ContainsKey(newKey))
|
|
|
|
|
{
|
|
|
|
|
_saleForm.BindingSource.CurrencyManager.Position = _bill.IndexOfKey(newKey);
|
|
|
|
|
_bill[newKey].Quantity += 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var billItemValue = new BillItemValue(product)
|
|
|
|
|
{
|
|
|
|
|
ProductID = product.ProductID,
|
|
|
|
|
Name = product.Units == string.Empty ? product.Name : product.Name + " (" + product.Units + ")",
|
|
|
|
|
Price = product.SalePrice,
|
|
|
|
|
Tax = product.Tax.Rate,
|
|
|
|
|
ServiceCharge = product.ServiceCharge,
|
|
|
|
|
Discount = 0,
|
|
|
|
|
Printed = false,
|
|
|
|
|
Quantity = 1,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var old = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.ProductID == newKey.ProductID).SingleOrDefault();
|
|
|
|
|
if (old.Key != null)
|
|
|
|
|
{
|
|
|
|
|
billItemValue.Discount = old.Value.Discount;
|
|
|
|
|
billItemValue.Price = old.Value.Price;
|
|
|
|
|
}
|
|
|
|
|
_bill.Add(newKey, billItemValue);
|
|
|
|
|
_saleForm.BindingSource.DataSource = _bill.Values.ToList();
|
|
|
|
|
_saleForm.BindingSource.CurrencyManager.Position = _saleForm.BindingSource.CurrencyManager.Count - 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void ShowModifiers(int productGroupID, BillItemValue item)
|
2011-01-30 07:14:05 +00:00
|
|
|
|
{
|
2011-02-18 16:54:48 +00:00
|
|
|
|
if (item.Printed)
|
2011-01-31 20:33:22 +00:00
|
|
|
|
return;
|
2011-01-30 07:14:05 +00:00
|
|
|
|
var list = ProductGroupModifierBI.GetProductGroupModifiers(productGroupID);
|
|
|
|
|
using (var frm = new ModifierForm(list, item.Modifiers))
|
|
|
|
|
{
|
|
|
|
|
frm.ShowDialog();
|
|
|
|
|
item.Modifiers = frm.Selection;
|
|
|
|
|
}
|
2011-01-31 20:33:22 +00:00
|
|
|
|
ShowAmount();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ShowDiscount()
|
|
|
|
|
{
|
2011-02-09 12:03:22 +00:00
|
|
|
|
if (!Session.IsAllowed(RoleConstants.DISCOUNT))
|
|
|
|
|
return;
|
|
|
|
|
|
2011-06-23 12:47:48 +00:00
|
|
|
|
using (var bi = new ProductGroupBI())
|
2011-01-31 20:33:22 +00:00
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
using (var frm = new DiscountForm(bi.GetProductGroupTypes()))
|
2011-01-31 20:33:22 +00:00
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
if (frm.ShowDialog() == DialogResult.OK)
|
2011-01-31 20:33:22 +00:00
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
HashSet<string> outList;
|
|
|
|
|
var discount = frm.Selection(out outList);
|
|
|
|
|
discount = discount / 100;
|
|
|
|
|
if (discount > 1 || discount < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
foreach (var item in _bill.Where(x => x.Key.BillItemType == BillItemType.Product && outList.Contains(x.Value.Product.ProductGroup.GroupType)))
|
|
|
|
|
{
|
|
|
|
|
var product = item.Value.Product;
|
|
|
|
|
var maxDiscount = product.ProductGroup.DiscountLimit;
|
|
|
|
|
if (discount > item.Value.Product.ProductGroup.DiscountLimit)
|
|
|
|
|
MessageBox.Show(string.Format("Maximum discount for {0} is {1:P}", product.Name, maxDiscount),
|
|
|
|
|
"Excessive Discount", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
|
|
item.Value.Discount = discount;
|
|
|
|
|
}
|
2011-01-31 20:33:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ShowAmount();
|
2011-01-10 19:49:11 +00:00
|
|
|
|
}
|
|
|
|
|
public void ShowCustomerList(bool reset)
|
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
if ((_customer.CustomerID == 1) && (!reset))
|
2011-01-10 19:49:11 +00:00
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
using (var selectCustomer = new SelectCustomer(new CustomerBI().GetFilteredCustomers, true))
|
2011-01-10 19:49:11 +00:00
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
selectCustomer.customerEvent += selectCustomer_customerEvent;
|
2011-01-10 19:49:11 +00:00
|
|
|
|
selectCustomer.ShowDialog();
|
|
|
|
|
if (selectCustomer.SelectedItem != null)
|
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
_customer = selectCustomer.SelectedItem;
|
|
|
|
|
_saleForm.SetCustomerDisplay(_customer.Name);
|
2011-01-10 19:49:11 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
_customer = new CustomerBI().GetCustomer(1);
|
2011-01-10 19:49:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
_customer = new CustomerBI().GetCustomer(1);
|
|
|
|
|
_saleForm.SetCustomerDisplay(_customer.Name);
|
2011-01-10 19:49:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-11 18:49:48 +00:00
|
|
|
|
public void VoidBill()
|
2011-01-10 19:49:11 +00:00
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
if (_billInfo == null)
|
2011-02-09 12:03:22 +00:00
|
|
|
|
return;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
if (!_billInfo.Printed)
|
2011-02-09 12:03:22 +00:00
|
|
|
|
return;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
if (!Session.IsAllowed(RoleConstants.VOID_BILL))
|
2011-02-09 12:03:22 +00:00
|
|
|
|
return;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
if (MessageBox.Show("Are you sure you want to void this bill?", "Void Bill", MessageBoxButtons.YesNo,
|
|
|
|
|
MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
|
2011-02-09 12:03:22 +00:00
|
|
|
|
return;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
var voidReason = new SelectVoidReason(GetVoidReason, true);
|
|
|
|
|
voidReason.ShowDialog();
|
|
|
|
|
if (voidReason.SelectedItem != null)
|
2011-01-10 19:49:11 +00:00
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
VoucherBI.VoidBill(_billInfo.VoucherID, voidReason.SelectedItem.Description);
|
|
|
|
|
ClearBill();
|
2011-01-30 07:14:05 +00:00
|
|
|
|
}
|
2011-02-18 16:54:48 +00:00
|
|
|
|
else
|
2011-01-10 19:49:11 +00:00
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
MessageBox.Show("Please Select a reason if you want to void the bill", "Bill NOT Voided",
|
|
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
|
2011-01-10 19:49:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
|
|
|
|
private Customer selectCustomer_customerEvent(object sender, CustomerEventArgs e)
|
2011-01-10 19:49:11 +00:00
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
using (var form = new CustomersForm(e.CustomerID, e.Phone))
|
2011-01-10 19:49:11 +00:00
|
|
|
|
{
|
|
|
|
|
form.ShowDialog();
|
|
|
|
|
return form.Customer;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
|
|
|
|
private static List<StringType> GetVoidReason(Dictionary<string, string> filter)
|
|
|
|
|
{
|
|
|
|
|
var list = new List<StringType>
|
|
|
|
|
{
|
|
|
|
|
new StringType("Discount"),
|
|
|
|
|
new StringType("Printing Fault"),
|
|
|
|
|
new StringType("Item Changed"),
|
|
|
|
|
new StringType("Quantity Reduced"),
|
|
|
|
|
new StringType("Costing Bill for Party"),
|
|
|
|
|
new StringType("Cashier Mistake"),
|
|
|
|
|
new StringType("Management Freesale"),
|
|
|
|
|
new StringType("Other")
|
|
|
|
|
};
|
2011-01-10 19:49:11 +00:00
|
|
|
|
return list.Where(i => i.Description.ToLower().Contains(filter["Name"].ToLower().Trim())).ToList();
|
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
2011-01-10 19:49:11 +00:00
|
|
|
|
private void ShowAmount()
|
|
|
|
|
{
|
2011-01-30 07:14:05 +00:00
|
|
|
|
//saleForm.BindingSource.CurrencyManager.Position = 1;
|
|
|
|
|
|
2011-06-23 12:47:48 +00:00
|
|
|
|
var taxAmount = _bill.Values.Sum(b => b.TaxAmount);
|
|
|
|
|
var discountAmount = _bill.Values.Sum(b => b.DiscountAmount);
|
|
|
|
|
var grossAmount = _bill.Values.Sum(b => b.GrossAmount);
|
|
|
|
|
var valueAmount = _bill.Values.Sum(b => b.Value);
|
|
|
|
|
var serviceChargeAmount = _bill.Values.Sum(b => b.ServiceChargeAmount);
|
2011-01-10 19:49:11 +00:00
|
|
|
|
//bill.Values.ToList();
|
2011-03-11 18:49:48 +00:00
|
|
|
|
_saleForm.ShowAmount(discountAmount, grossAmount, serviceChargeAmount, taxAmount, valueAmount,
|
2011-06-23 12:47:48 +00:00
|
|
|
|
_bill.Values.ToList());
|
2011-01-10 19:49:11 +00:00
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
2011-02-09 12:03:22 +00:00
|
|
|
|
public void ProductRemove()
|
2011-01-10 19:49:11 +00:00
|
|
|
|
{
|
2011-02-09 12:03:22 +00:00
|
|
|
|
var item = CurrentProduct;
|
|
|
|
|
if (!Allowed(item))
|
2011-01-30 07:14:05 +00:00
|
|
|
|
return;
|
2011-02-18 16:54:48 +00:00
|
|
|
|
if (item.Printed)
|
|
|
|
|
return;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
_bill.Remove(new BillItemKey(item.ProductID, 0));
|
|
|
|
|
_bill.ReCompact();
|
2011-01-30 07:14:05 +00:00
|
|
|
|
ShowAmount();
|
2011-01-10 19:49:11 +00:00
|
|
|
|
}
|
2011-01-30 07:14:05 +00:00
|
|
|
|
|
2011-02-09 12:03:22 +00:00
|
|
|
|
public void SetQuantity(decimal quantity, bool prompt)
|
2011-01-10 19:49:11 +00:00
|
|
|
|
{
|
2011-02-09 12:03:22 +00:00
|
|
|
|
var item = CurrentProduct;
|
|
|
|
|
if (!Allowed(item))
|
2011-01-10 19:49:11 +00:00
|
|
|
|
return;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
if (item.Printed)
|
|
|
|
|
return;
|
|
|
|
|
if (prompt && !GetInput("Quantity", ref quantity))
|
|
|
|
|
return;
|
|
|
|
|
if (!prompt)
|
|
|
|
|
quantity += item.Quantity;
|
|
|
|
|
if (quantity < 0 && !Session.IsAllowed(RoleConstants.EDIT_PRINTED_PRODUCT))
|
|
|
|
|
return;
|
|
|
|
|
var total = quantity + _bill.Where(x => x.Key.ProductID == item.ProductID && x.Key.BillItemType == BillItemType.Product).Sum(x => x.Value.Quantity);
|
|
|
|
|
if (total < 0)
|
|
|
|
|
quantity -= total;
|
|
|
|
|
item.Quantity = quantity;
|
2011-01-10 19:49:11 +00:00
|
|
|
|
ShowAmount();
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-30 07:14:05 +00:00
|
|
|
|
public void ChangeRate()
|
2011-01-10 19:49:11 +00:00
|
|
|
|
{
|
2011-02-18 16:54:48 +00:00
|
|
|
|
var item = CurrentProduct;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
if (!Allowed(item, RoleConstants.CHANGE_RATE))
|
|
|
|
|
return;
|
|
|
|
|
var rate = item.Price;
|
|
|
|
|
if (!GetInput("Price", ref rate))
|
|
|
|
|
return;
|
|
|
|
|
if (rate == 0 && !Session.IsAllowed(RoleConstants.ZERO_RATE))
|
2011-02-18 16:54:48 +00:00
|
|
|
|
return;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
foreach (var sub in _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.ProductID == item.ProductID))
|
|
|
|
|
sub.Value.Price = rate;
|
|
|
|
|
|
2011-02-09 12:03:22 +00:00
|
|
|
|
ShowAmount();
|
2011-01-10 19:49:11 +00:00
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
2011-06-23 12:47:48 +00:00
|
|
|
|
private bool Allowed(BillItemValue item, RoleConstants role)
|
2011-02-09 12:03:22 +00:00
|
|
|
|
{
|
|
|
|
|
if (item == null)
|
|
|
|
|
return false;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
return Session.IsAllowed(role);
|
2011-02-09 12:03:22 +00:00
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
2011-06-23 12:47:48 +00:00
|
|
|
|
private bool Allowed(BillItemValue item)
|
2011-03-11 18:49:48 +00:00
|
|
|
|
{
|
|
|
|
|
return item != null;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-10 19:49:11 +00:00
|
|
|
|
private void InputBox_Validating(object sender, InputBoxValidatingArgs e)
|
|
|
|
|
{
|
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
2011-01-30 07:14:05 +00:00
|
|
|
|
private void LoadBill(int voucherID)
|
2011-01-10 19:49:11 +00:00
|
|
|
|
{
|
|
|
|
|
ClearBill();
|
2011-06-23 12:47:48 +00:00
|
|
|
|
_bill.Clear();
|
2011-03-11 18:49:48 +00:00
|
|
|
|
_billInfo = null;
|
2011-04-11 12:55:45 +00:00
|
|
|
|
_billInfo = VoucherBI.Get(voucherID);
|
2011-01-10 19:49:11 +00:00
|
|
|
|
|
2011-03-11 18:49:48 +00:00
|
|
|
|
_customer = _billInfo.Customer;
|
|
|
|
|
_saleForm.ShowInfo(_billInfo.BillID, _billInfo.KotID, _billInfo.CreationDate, _billInfo.Date.Value,
|
|
|
|
|
_billInfo.LastEditDate, _customer.Name, _billInfo.TableID, _billInfo.Waiter.WaiterID,
|
|
|
|
|
_billInfo.Waiter.Name);
|
2011-01-10 19:49:11 +00:00
|
|
|
|
|
2011-03-11 18:49:48 +00:00
|
|
|
|
foreach (var kot in _billInfo.Kots)
|
2011-01-10 19:49:11 +00:00
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
var kotKey = new BillItemKey(kot.KotID);
|
|
|
|
|
var kotItem = new BillItemValue(null)
|
2011-03-11 18:49:48 +00:00
|
|
|
|
{
|
|
|
|
|
ProductID = kot.KotID,
|
|
|
|
|
Discount = 0,
|
2011-06-23 12:47:48 +00:00
|
|
|
|
Name = string.Format("Kot: {0} / {1:dd-MMM HH:mm} ({2})", kot.Code, kot.Date, kot.User.Name),
|
2011-03-11 18:49:48 +00:00
|
|
|
|
Price = 0,
|
|
|
|
|
Printed = true,
|
|
|
|
|
Quantity = 0,
|
|
|
|
|
Tax = -1,
|
|
|
|
|
ServiceCharge = 0,
|
|
|
|
|
};
|
2011-06-23 12:47:48 +00:00
|
|
|
|
_bill.Add(kotKey, kotItem);
|
2011-02-18 16:54:48 +00:00
|
|
|
|
foreach (var inv in kot.Inventories)
|
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
var key = new BillItemKey(inv.Product.ProductID, kot.KotID);
|
2011-06-23 12:47:48 +00:00
|
|
|
|
var item = new BillItemValue(inv.Product)
|
2011-03-11 18:49:48 +00:00
|
|
|
|
{
|
|
|
|
|
ProductID = inv.Product.ProductID,
|
|
|
|
|
Discount = inv.Discount,
|
|
|
|
|
Name =
|
|
|
|
|
inv.Product.Units == string.Empty
|
|
|
|
|
? inv.Product.Name
|
|
|
|
|
: inv.Product.Name + " (" + inv.Product.Units + ")",
|
|
|
|
|
Price = inv.Rate,
|
|
|
|
|
Printed = true,
|
|
|
|
|
Quantity = inv.Quantity,
|
|
|
|
|
Tax = inv.Tax,
|
|
|
|
|
ServiceCharge = inv.ServiceCharge,
|
|
|
|
|
};
|
2011-02-18 16:54:48 +00:00
|
|
|
|
foreach (var mod in inv.InventoryModifier)
|
|
|
|
|
item.Modifiers.Add(mod.Modifier);
|
2011-06-23 12:47:48 +00:00
|
|
|
|
_bill.Add(key, item);
|
2011-02-18 16:54:48 +00:00
|
|
|
|
}
|
2011-01-10 19:49:11 +00:00
|
|
|
|
}
|
2011-06-23 12:47:48 +00:00
|
|
|
|
var newKotKey = new BillItemKey(0);
|
|
|
|
|
var newKotItem = new BillItemValue(null)
|
2011-03-11 18:49:48 +00:00
|
|
|
|
{
|
|
|
|
|
ProductID = 0,
|
|
|
|
|
Discount = 0,
|
|
|
|
|
Name = "== New Kot ==",
|
|
|
|
|
Price = 0,
|
|
|
|
|
Printed = true,
|
|
|
|
|
Quantity = 0,
|
|
|
|
|
Tax = -1,
|
|
|
|
|
ServiceCharge = 0,
|
|
|
|
|
};
|
2011-06-23 12:47:48 +00:00
|
|
|
|
_bill.Add(newKotKey, newKotItem);
|
2011-01-10 19:49:11 +00:00
|
|
|
|
ShowAmount();
|
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
2011-01-13 20:21:02 +00:00
|
|
|
|
public void LoadBillFromTable(string tableName)
|
2011-01-10 19:49:11 +00:00
|
|
|
|
{
|
2011-01-13 20:21:02 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(tableName))
|
2011-01-10 19:49:11 +00:00
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
FoodTable table;
|
|
|
|
|
using (var bi = new FoodTableBI())
|
|
|
|
|
table = bi.Get(x => x.Name == tableName);
|
2011-02-18 16:54:48 +00:00
|
|
|
|
if (table != null && table.VoucherID != 0)
|
2011-01-10 19:49:11 +00:00
|
|
|
|
{
|
2011-02-18 16:54:48 +00:00
|
|
|
|
LoadBill(table.VoucherID);
|
2011-01-13 20:21:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
var result = "0";
|
|
|
|
|
if (GetInput("Table Number", ref result))
|
|
|
|
|
LoadBillFromTable(result);
|
|
|
|
|
else
|
|
|
|
|
ClearBill();
|
2011-01-10 19:49:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CancelBillChanges()
|
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
if (_bill.Values.Any(i => i.Printed == false) &&
|
|
|
|
|
MessageBox.Show("Abandon Changes?", "Abandon Changes", MessageBoxButtons.YesNo,
|
|
|
|
|
MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
|
|
|
|
|
return;
|
2011-01-10 19:49:11 +00:00
|
|
|
|
ClearBill();
|
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
2011-01-10 19:49:11 +00:00
|
|
|
|
public void ClearBill()
|
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
_billInfo = null;
|
2011-01-10 19:49:11 +00:00
|
|
|
|
ShowCustomerList(true);
|
2011-06-23 12:47:48 +00:00
|
|
|
|
_bill.Clear();
|
|
|
|
|
var newKotKey = new BillItemKey(0);
|
|
|
|
|
var newKotItem = new BillItemValue(null)
|
2011-03-11 18:49:48 +00:00
|
|
|
|
{
|
|
|
|
|
ProductID = 0,
|
|
|
|
|
Discount = 0,
|
|
|
|
|
Name = "== New Kot ==",
|
|
|
|
|
Price = 0,
|
|
|
|
|
Printed = true,
|
|
|
|
|
Quantity = 0,
|
|
|
|
|
Tax = -1,
|
|
|
|
|
ServiceCharge = 0,
|
|
|
|
|
};
|
2011-06-23 12:47:48 +00:00
|
|
|
|
_bill.Add(newKotKey, newKotItem);
|
|
|
|
|
_saleForm.ClearBill(_bill);
|
2011-01-10 19:49:11 +00:00
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
2011-01-10 19:49:11 +00:00
|
|
|
|
public void FormLoad()
|
|
|
|
|
{
|
2011-02-18 16:54:48 +00:00
|
|
|
|
ClearBill();
|
2011-03-11 18:49:48 +00:00
|
|
|
|
if (_editVoucherID.HasValue)
|
2011-01-10 19:49:11 +00:00
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
LoadBill(_editVoucherID.Value);
|
2011-01-10 19:49:11 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
2011-01-17 14:55:43 +00:00
|
|
|
|
internal void SettleBill()
|
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
if (_billInfo == null)
|
2011-01-17 14:55:43 +00:00
|
|
|
|
return;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
if (!_billInfo.Printed)
|
2011-01-31 20:33:22 +00:00
|
|
|
|
return;
|
2011-02-09 12:03:22 +00:00
|
|
|
|
if (!Session.IsAllowed(RoleConstants.SETTLE_BILL))
|
|
|
|
|
return;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
IDictionary<SettleOption, decimal> options;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
var amount = (_billInfo.Settlements.Single(x => x.Settled == SettleOption.Amount).Amount +
|
|
|
|
|
_billInfo.Settlements.Single(x => x.Settled == SettleOption.RoundOff).Amount) * -1;
|
|
|
|
|
|
|
|
|
|
using (var frm = new SettleChoicesForm(amount))
|
2011-01-17 14:55:43 +00:00
|
|
|
|
{
|
|
|
|
|
frm.ShowDialog();
|
2011-03-11 18:49:48 +00:00
|
|
|
|
options = frm.OptionsChosen;
|
2011-01-17 14:55:43 +00:00
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
if (options.Count == 0)
|
|
|
|
|
return;
|
|
|
|
|
VoucherBI.SettleVoucher(Session.User, _billInfo.VoucherID, options);
|
|
|
|
|
ClearBill();
|
2011-01-17 14:55:43 +00:00
|
|
|
|
}
|
2011-02-18 16:54:48 +00:00
|
|
|
|
|
2011-06-23 12:47:48 +00:00
|
|
|
|
#region Move Table(s) / Kot(s)
|
2011-03-11 18:49:48 +00:00
|
|
|
|
private static FoodTable GetTableForMove(bool allowMerge)
|
2011-02-18 16:54:48 +00:00
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
using (var bi = new FoodTableBI())
|
2011-02-18 16:54:48 +00:00
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
using (var frm = new MoveTableForm(bi.List(), allowMerge))
|
|
|
|
|
{
|
|
|
|
|
frm.ShowDialog();
|
|
|
|
|
if (frm.Selection != null)
|
|
|
|
|
return frm.Selection;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
2011-02-18 16:54:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void MergeKot()
|
|
|
|
|
{
|
2011-03-11 18:49:48 +00:00
|
|
|
|
if (_billInfo == null)
|
2011-02-18 16:54:48 +00:00
|
|
|
|
return;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
if (VoucherBI.IsBillPrinted(_billInfo.VoucherID) && !Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL))
|
2011-02-18 16:54:48 +00:00
|
|
|
|
return;
|
|
|
|
|
var kot = CurrentKot;
|
|
|
|
|
if (kot == null)
|
|
|
|
|
return;
|
|
|
|
|
var table = GetTableForMove(true);
|
|
|
|
|
if (table == null)
|
|
|
|
|
return;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
var kotCount = _bill.Keys.Count(x => x.BillItemType == BillItemType.Kot && x.KotID != 0);
|
2011-03-11 18:49:48 +00:00
|
|
|
|
var voucherID = 0;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
if (table.VoucherID == 0 && kotCount > 1)
|
2011-02-18 16:54:48 +00:00
|
|
|
|
//Move Kot
|
|
|
|
|
voucherID = MoveKot(kot, table);
|
2011-06-23 12:47:48 +00:00
|
|
|
|
else if (table.VoucherID == 0 && kotCount == 1)
|
2011-02-18 16:54:48 +00:00
|
|
|
|
//Move Table
|
|
|
|
|
voucherID = MoveTable(table);
|
2011-06-23 12:47:48 +00:00
|
|
|
|
else if (table.VoucherID != 0 && kotCount > 1)
|
2011-02-18 16:54:48 +00:00
|
|
|
|
//Merge Kot
|
|
|
|
|
voucherID = MergeKot(kot, table);
|
2011-06-23 12:47:48 +00:00
|
|
|
|
else if (table.VoucherID != 0 && kotCount == 1)
|
2011-02-18 16:54:48 +00:00
|
|
|
|
//Merge Table
|
|
|
|
|
voucherID = MergeTable(table);
|
|
|
|
|
if (voucherID != 0)
|
|
|
|
|
LoadBill(voucherID);
|
|
|
|
|
}
|
2011-06-23 12:47:48 +00:00
|
|
|
|
internal void MoveTable()
|
|
|
|
|
{
|
|
|
|
|
if (_billInfo == null)
|
|
|
|
|
return;
|
|
|
|
|
if (VoucherBI.IsBillPrinted(_billInfo.VoucherID) && !Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL))
|
|
|
|
|
return;
|
|
|
|
|
var table = GetTableForMove(true);
|
|
|
|
|
if (table == null)
|
|
|
|
|
return;
|
|
|
|
|
LoadBill(table.VoucherID == 0 ? MoveTable(table) : MergeTable(table));
|
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
|
2011-06-23 12:47:48 +00:00
|
|
|
|
private int MoveKot(BillItemKey kot, FoodTable table)
|
|
|
|
|
{
|
|
|
|
|
if (!Session.IsAllowed(RoleConstants.MOVE_KOT))
|
|
|
|
|
return 0;
|
|
|
|
|
var voucher = new Voucher
|
|
|
|
|
{
|
|
|
|
|
Customer = _billInfo.Customer,
|
|
|
|
|
TableID = table.Name,
|
|
|
|
|
Waiter = _billInfo.Waiter,
|
|
|
|
|
Printed = false,
|
|
|
|
|
Void = false,
|
|
|
|
|
Date = DateTime.Now,
|
|
|
|
|
Narration = "",
|
|
|
|
|
User = Session.User
|
|
|
|
|
};
|
|
|
|
|
VoucherBI.Insert(voucher, true);
|
|
|
|
|
return VoucherBI.MergeKot(kot.KotID, voucher);
|
|
|
|
|
}
|
|
|
|
|
private static int MergeKot(BillItemKey kot, FoodTable table)
|
|
|
|
|
{
|
|
|
|
|
if (!Session.IsAllowed(RoleConstants.MERGE_KOT))
|
|
|
|
|
return 0;
|
|
|
|
|
return VoucherBI.MergeKot(kot.KotID, table);
|
|
|
|
|
}
|
|
|
|
|
private int MoveTable(FoodTable table)
|
|
|
|
|
{
|
|
|
|
|
if (!Session.IsAllowed(RoleConstants.MOVE_TABLE))
|
|
|
|
|
return 0;
|
|
|
|
|
using (var ft = new FoodTableBI())
|
|
|
|
|
return ft.Move(_billInfo.TableID, table);
|
|
|
|
|
}
|
|
|
|
|
private int MergeTable(FoodTable table)
|
|
|
|
|
{
|
|
|
|
|
if (!Session.IsAllowed(RoleConstants.MERGE_TABLE))
|
|
|
|
|
return 0;
|
|
|
|
|
var kots = _bill.Keys.Where(x => x.BillItemType == BillItemType.Kot && x.KotID != 0);
|
|
|
|
|
foreach (var item in kots)
|
|
|
|
|
MergeKot(item, table);
|
|
|
|
|
VoucherBI.Delete(_billInfo.VoucherID);
|
|
|
|
|
return table.VoucherID;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
2011-03-11 18:49:48 +00:00
|
|
|
|
#region Save
|
|
|
|
|
|
2011-06-23 12:47:48 +00:00
|
|
|
|
public void SaveBill(int waiterID, string tableID)
|
2011-03-11 18:49:48 +00:00
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
if (!Session.IsAllowed(RoleConstants.PRINT_BILL))
|
|
|
|
|
return;
|
|
|
|
|
if ((_billInfo != null) && (VoucherBI.IsBillPrinted(_billInfo.VoucherID)) &&
|
|
|
|
|
(!Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL)))
|
2011-03-11 18:49:48 +00:00
|
|
|
|
return;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
if (_bill.Count == 1) //new kot only
|
|
|
|
|
return;
|
|
|
|
|
ShowDiscount();
|
|
|
|
|
var saved = _billInfo == null ? InsertVoucher(true, waiterID, tableID, !_editVoucherID.HasValue) : UpdateVoucher(true, waiterID, tableID, !_editVoucherID.HasValue);
|
|
|
|
|
|
|
|
|
|
if (!_editVoucherID.HasValue || _print)
|
|
|
|
|
Thermal.PrintBill(_billInfo.VoucherID);
|
|
|
|
|
if (_editVoucherID.HasValue)
|
|
|
|
|
_saleForm.CloseWindow();
|
|
|
|
|
ClearBill();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveKot(int waiterID, string tableID)
|
|
|
|
|
{
|
|
|
|
|
if (!Session.IsAllowed(RoleConstants.PRINT_KOT))
|
2011-03-11 18:49:48 +00:00
|
|
|
|
return;
|
|
|
|
|
if ((_billInfo != null) && (VoucherBI.IsBillPrinted(_billInfo.VoucherID)) &&
|
|
|
|
|
(!Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL)))
|
|
|
|
|
return;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
if (_bill.Count == 1) //new kot only
|
2011-03-11 18:49:48 +00:00
|
|
|
|
return;
|
2011-06-23 12:47:48 +00:00
|
|
|
|
var saved = _billInfo == null ? InsertVoucher(false, waiterID, tableID, !_editVoucherID.HasValue) : UpdateVoucher(false, waiterID, tableID, !_editVoucherID.HasValue);
|
|
|
|
|
|
|
|
|
|
if ((!_editVoucherID.HasValue || _print) && saved.HasValue)
|
|
|
|
|
Thermal.PrintKot(_billInfo.VoucherID, saved.Value);
|
|
|
|
|
|
2011-03-11 18:49:48 +00:00
|
|
|
|
if (_editVoucherID.HasValue)
|
|
|
|
|
_saleForm.CloseWindow();
|
|
|
|
|
ClearBill();
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-23 12:47:48 +00:00
|
|
|
|
private int? InsertVoucher(bool finalBill, int waiterID, string tableID, bool updateTable)
|
2011-03-11 18:49:48 +00:00
|
|
|
|
{
|
|
|
|
|
if (_billInfo != null)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("Error in InsertVoucher, there is a previous sale in memory", "Error");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
_billInfo = new Voucher
|
|
|
|
|
{
|
|
|
|
|
Customer = _customer,
|
|
|
|
|
//Paid = finalBill,
|
|
|
|
|
TableID = tableID,
|
|
|
|
|
Waiter = WaiterBI.GetWaiter(waiterID),
|
|
|
|
|
Printed = finalBill,
|
|
|
|
|
Void = false,
|
|
|
|
|
Date = DateTime.Now,
|
|
|
|
|
Narration = "",
|
|
|
|
|
User = Session.User
|
|
|
|
|
};
|
2011-06-23 12:47:48 +00:00
|
|
|
|
UpdateKots();
|
|
|
|
|
var kot = GetKotForBill();
|
2011-03-11 18:49:48 +00:00
|
|
|
|
if (kot != null)
|
|
|
|
|
_billInfo.Kots.Add(kot);
|
2011-06-23 12:47:48 +00:00
|
|
|
|
return VoucherBI.Insert(_billInfo, updateTable);
|
2011-03-11 18:49:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-23 12:47:48 +00:00
|
|
|
|
private int? UpdateVoucher(bool finalBill, int waiterID, string tableID, bool updateTable)
|
2011-03-11 18:49:48 +00:00
|
|
|
|
{
|
|
|
|
|
_billInfo.User = Session.User;
|
|
|
|
|
_billInfo.Customer = _customer;
|
|
|
|
|
if (!_billInfo.Printed && finalBill)
|
|
|
|
|
_billInfo.Date = null;
|
|
|
|
|
_billInfo.Printed = _billInfo.Printed || finalBill;
|
|
|
|
|
_billInfo.TableID = tableID;
|
|
|
|
|
_billInfo.Waiter = WaiterBI.GetWaiter(waiterID);
|
2011-06-23 12:47:48 +00:00
|
|
|
|
UpdateKots();
|
|
|
|
|
var kot = GetKotForBill();
|
2011-03-11 18:49:48 +00:00
|
|
|
|
if (kot != null)
|
|
|
|
|
_billInfo.Kots.Add(kot);
|
2011-06-23 12:47:48 +00:00
|
|
|
|
return VoucherBI.Update(_billInfo, updateTable);
|
|
|
|
|
}
|
|
|
|
|
private void UpdateKots()
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != 0))
|
|
|
|
|
{
|
|
|
|
|
var i = _billInfo.Kots.Single(x => x.KotID == item.Key.KotID).Inventories.Single(x => x.Product.ProductID == item.Key.ProductID);
|
|
|
|
|
i.Discount = item.Value.Discount;
|
|
|
|
|
i.Rate = item.Value.Price;
|
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
}
|
|
|
|
|
private Kot GetKotForBill()
|
|
|
|
|
{
|
|
|
|
|
var kot = new Kot();
|
2011-06-23 12:47:48 +00:00
|
|
|
|
foreach (var item in _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID == 0 && x.Value.Quantity != 0))
|
2011-03-11 18:49:48 +00:00
|
|
|
|
{
|
2011-06-23 12:47:48 +00:00
|
|
|
|
var inv = new Inventory
|
|
|
|
|
{
|
|
|
|
|
Product = item.Value.Product,
|
|
|
|
|
Quantity = item.Value.Quantity,
|
|
|
|
|
Rate = item.Value.Price,
|
|
|
|
|
Discount = item.Value.Discount,
|
|
|
|
|
ServiceCharge = item.Value.ServiceCharge,
|
|
|
|
|
Tax = item.Value.Tax
|
|
|
|
|
};
|
|
|
|
|
foreach (var mod in item.Value.Modifiers)
|
|
|
|
|
inv.InventoryModifier.Add(new InventoryModifier { Modifier = mod });
|
|
|
|
|
kot.Inventories.Add(inv);
|
2011-03-11 18:49:48 +00:00
|
|
|
|
}
|
2011-06-23 12:47:48 +00:00
|
|
|
|
return kot.Inventories.Count == 0 ? null : kot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
#region InputBox
|
|
|
|
|
private bool GetInput(string prompt, ref decimal amount)
|
|
|
|
|
{
|
|
|
|
|
var result = InputBox.Show(prompt, amount.ToString(), InputBox_Validating);
|
|
|
|
|
if (!result.OK)
|
|
|
|
|
return false;
|
|
|
|
|
if (!decimal.TryParse(result.Text, out amount))
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
private bool GetInput(string prompt, ref string info)
|
|
|
|
|
{
|
|
|
|
|
var result = InputBox.Show(prompt, info, InputBox_Validating);
|
|
|
|
|
if (!result.OK)
|
|
|
|
|
return false;
|
|
|
|
|
info = result.Text.Trim();
|
|
|
|
|
if (string.IsNullOrEmpty(info))
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
2011-03-11 18:49:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2011-01-10 19:49:11 +00:00
|
|
|
|
}
|
2011-03-11 18:49:48 +00:00
|
|
|
|
}
|