Added Basecode to Product

Added Voucher Type During Printing
Added Discount Report
Fixed Void bill table not getting cleared error
Added PAX to table
Removed Itital Setup button in MainForm as it was not doing anything
This commit is contained in:
unknown
2011-12-05 15:11:02 +05:30
parent 719dbd49d2
commit 964d0a78bf
54 changed files with 2285 additions and 1028 deletions

View File

@ -15,20 +15,28 @@ namespace Tanshu.Accounts.PointOfSale
private readonly OrderedDictionary<BillItemKey, BillItemValue> _bill;
private Voucher _billInfo;
private Customer _customer;
private int? _editVoucherID;
private readonly bool _print;
private ISaleForm _saleForm;
public Waiter Waiter
{
get { return _billInfo.Waiter; }
set { _billInfo.Waiter = value; }
}
public BillController(int? editVoucherID, bool print)
{
this._editVoucherID = editVoucherID;
_print = print;
_bill = new OrderedDictionary<BillItemKey, BillItemValue>();
_billInfo = new Voucher(Session.User);
using (var bi = new CustomerBI(false))
_customer = bi.Get(x => x.CustomerID == 1);
_billInfo.Customer = bi.Get(x => x.CustomerID == 1);
using (var bi = new WaiterBI(false))
_billInfo.Waiter = bi.Get(x => x.WaiterID == 1);
}
public BillItemValue CurrentProduct
@ -56,7 +64,7 @@ namespace Tanshu.Accounts.PointOfSale
public void InitGui(ISaleForm saleForm)
{
this._saleForm = saleForm;
this._saleForm.SetCustomerDisplay(_customer.Name);
this._saleForm.SetCustomerDisplay(_billInfo.Customer.Name);
this._saleForm.SetUserName(Session.User.Name);
}
@ -109,7 +117,7 @@ namespace Tanshu.Accounts.PointOfSale
ShowAmount();
}
public void ShowDiscount()
public void SetDiscount()
{
if (!Session.IsAllowed(RoleConstants.DISCOUNT))
return;
@ -141,32 +149,67 @@ namespace Tanshu.Accounts.PointOfSale
ShowAmount();
}
public void ShowCustomerList(bool reset)
public void SetQuantity(decimal quantity, bool prompt)
{
if ((_customer.CustomerID == 1) && (!reset))
var item = CurrentProduct;
if (!Allowed(item))
return;
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 && x.Value.Printed).Sum(x => x.Value.Quantity);
if (total < 0)
quantity -= total;
item.Quantity = quantity;
ShowAmount();
}
public void SetRate()
{
var item = CurrentProduct;
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))
return;
foreach (var sub in _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.ProductID == item.ProductID))
sub.Value.Price = rate;
ShowAmount();
}
public void ShowCustomers(bool reset)
{
if (!reset && ((_billInfo.Customer == null) || _billInfo.Customer.CustomerID == 1))
{
using (var selectCustomer = new SelectCustomer(CustomerBI.List, true))
{
selectCustomer.customerEvent += selectCustomer_customerEvent;
selectCustomer.CustomerEvent += selectCustomer_customerEvent;
selectCustomer.ShowDialog();
if (selectCustomer.SelectedItem != null)
{
_customer = selectCustomer.SelectedItem;
_saleForm.SetCustomerDisplay(_customer.Name);
_billInfo.Customer = selectCustomer.SelectedItem;
}
else
{
using (var bi = new CustomerBI(false))
_customer = bi.Get(x => x.CustomerID == 1);
_billInfo.Customer = bi.Get(x => x.CustomerID == 1);
}
}
}
else
{
using (var bi = new CustomerBI(false))
_customer = bi.Get(x => x.CustomerID == 1);
_saleForm.SetCustomerDisplay(_customer.Name);
_billInfo.Customer = bi.Get(x => x.CustomerID == 1);
}
_saleForm.SetCustomerDisplay(_billInfo.Customer.Name);
}
private Customer selectCustomer_customerEvent(object sender, CustomerEventArgs e)
@ -178,58 +221,61 @@ namespace Tanshu.Accounts.PointOfSale
}
}
public void VoidBill()
public void ShowWaiters(bool reset)
{
#region Check conditions and Permissions
if (_billInfo == null)
return;
//if (!_billInfo.Printed)
// return;
if (_billInfo.Void)
return;
if (!Session.IsAllowed(RoleConstants.VOID_BILL))
return;
if (MessageBox.Show("Are you sure you want to void this bill?", "Void Bill", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
return;
#endregion
var voidReason = new SelectVoidReason(GetVoidReason, true);
voidReason.ShowDialog();
if (voidReason.SelectedItem != null)
if (reset)
{
using (var session = SessionManager.Session)
{
using (var trans = session.BeginTransaction())
{
using (var bi = new VoucherBI(session, false))
bi.VoidBill(_billInfo.VoucherID, voidReason.SelectedItem.Description);
using (var ft = new FoodTableBI(session, false))
ft.UpdateStatus(_billInfo);
trans.Commit();
}
}
ClearBill();
using (var bi = new WaiterBI(false))
_billInfo.Waiter = bi.Get(x => x.WaiterID == 1);
}
else
{
MessageBox.Show("Please Select a reason if you want to void the bill", "Bill NOT Voided", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
using (var selectWaiter = new SelectWaiter(WaiterBI.List, true))
{
selectWaiter.WaiterEvent += selectWaiter_waiterEvent;
selectWaiter.ShowDialog();
if (selectWaiter.SelectedItem != null)
{
_billInfo.Waiter = selectWaiter.SelectedItem;
}
else
{
using (var bi = new WaiterBI(false))
_billInfo.Waiter = bi.Get(x => x.WaiterID == 1);
}
}
}
_saleForm.SetWaiterDisplay(_billInfo.Waiter.Name);
}
private static List<StringType> GetVoidReason(Dictionary<string, string> filter)
private Waiter selectWaiter_waiterEvent(object sender, SelectorEventArgs<Waiter> e)
{
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")
};
return list.Where(i => i.Description.ToLower().Contains(filter["Name"].ToLower().Trim())).ToList();
var waiter = e.Item;
//if (!Thread.CurrentPrincipal.IsInRole("Waiter/Master"))
// return waiter;
using (var bi = new WaiterBI())
{
switch (e.Action)
{
case SelectorAction.Insert: // Add
bi.Insert(waiter);
e.Handled = true;
return waiter;
case SelectorAction.Update: // Edit
bi.Update(waiter);
e.Handled = true;
return waiter;
case SelectorAction.Delete: // Delete
bi.Delete(x => x.WaiterID == waiter.WaiterID);
e.Handled = true;
return bi.Get(x => x.WaiterID == 1);
default:
e.Handled = true;
return bi.Get(x => x.WaiterID == 1);
}
}
}
private void ShowAmount()
@ -255,52 +301,67 @@ namespace Tanshu.Accounts.PointOfSale
// ShowAmount();
//}
public void SetQuantity(decimal quantity, bool prompt)
{
var item = CurrentProduct;
if (!Allowed(item))
return;
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;
ShowAmount();
}
public void ChangeRate()
{
var item = CurrentProduct;
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))
return;
foreach (var sub in _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.ProductID == item.ProductID))
sub.Value.Price = rate;
ShowAmount();
}
private bool Allowed(BillItemValue item, RoleConstants role)
private static bool Allowed(BillItemValue item, RoleConstants role)
{
return item != null && Session.IsAllowed(role);
}
private bool Allowed(BillItemValue item)
private static bool Allowed(BillItemValue item)
{
return item != null;
}
private static void IsPrintedOrVoid(Voucher voucher, out bool isPrinted, out bool isVoid)
{
using (var bi = new VoucherBI(false))
{
var dbVoucher = bi.Get(x => x.VoucherID == voucher.VoucherID);
isPrinted = dbVoucher.Printed;
isVoid = dbVoucher.Void;
}
}
private static bool IsPrintedOrVoid(Voucher voucher)
{
using (var bi = new VoucherBI(false))
{
var dbVoucher = bi.Get(x => x.VoucherID == voucher.VoucherID);
return dbVoucher.Printed || dbVoucher.Void;
}
}
private static bool IsPrintedOrVoid(int voucherID)
{
using (var bi = new VoucherBI(false))
{
var dbVoucher = bi.Get(x => x.VoucherID == voucherID);
return dbVoucher.Printed || dbVoucher.Void;
}
}
private bool? IsReprint(out decimal amount)
{
amount = 0;
if (_billInfo.VoucherID == 0)
return false;
bool isPrinted, isVoid;
IsPrintedOrVoid(_billInfo, out isPrinted, out isVoid);
if (isVoid)
{
MessageBox.Show(string.Format("This Bill is already void.\nReason: {0}", _billInfo.VoidReason), "Bill already Voided", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
if (isPrinted && (!Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL)))
return null;
amount = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != 0).Sum(x => x.Value.GrossAmount);
return isPrinted;
}
private void InputBox_Validating(object sender, InputBoxValidatingArgs e)
{
}
@ -308,16 +369,11 @@ namespace Tanshu.Accounts.PointOfSale
private void LoadBill(int voucherID)
{
ClearBill();
_bill.Clear();
_billInfo = null;
using (var bi = new VoucherBI(false))
{
_billInfo = bi.Get(voucherID);
_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);
_billInfo = bi.Get(x => x.VoucherID == voucherID);
_bill.Clear();
_saleForm.ShowInfo(_billInfo);
foreach (var kot in _billInfo.Kots)
{
@ -365,6 +421,16 @@ namespace Tanshu.Accounts.PointOfSale
{
LoadBill(table.VoucherID);
}
else
{
using (var frm = new PaxForm())
{
frm.ShowDialog();
_billInfo.TableID = tableName;
_billInfo.Pax = frm.Pax;
_saleForm.ShowInfo(_billInfo);
}
}
}
else
{
@ -387,8 +453,9 @@ namespace Tanshu.Accounts.PointOfSale
public void ClearBill()
{
_billInfo = null;
ShowCustomerList(true);
_billInfo = new Voucher(Session.User);
ShowCustomers(true);
ShowWaiters(true);
_bill.Clear();
var newKotKey = new BillItemKey(0);
var newKotItem = new BillItemValue();
@ -409,7 +476,7 @@ namespace Tanshu.Accounts.PointOfSale
internal void SettleBill()
{
if (_billInfo == null)
if (_billInfo.VoucherID == 0)
return;
if (!_billInfo.Printed)
return;
@ -419,7 +486,7 @@ namespace Tanshu.Accounts.PointOfSale
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))
using (var frm = new SettleChoicesForm(amount, _billInfo.VoucherType))
{
frm.ShowDialog();
options = frm.OptionsChosen;
@ -446,32 +513,34 @@ namespace Tanshu.Accounts.PointOfSale
}
}
internal void MergeKot()
internal void MoveKot()
{
if (_billInfo == null)
if (_billInfo.VoucherID == 0)
return;
if (IsPrintedOrVoid(_billInfo))
return;
using (var bi = new VoucherBI(false))
if (bi.IsVoucherPrinted(_billInfo.VoucherID) && !Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL))
return;
var kot = CurrentKot;
if (kot == null)
return;
var table = GetTableForMove(true);
if (table == null)
return;
if (_billInfo.TableID == table.Name)
if (table.Name == _billInfo.TableID)
return;
if (table.VoucherID != 0)
if (IsPrintedOrVoid(table.VoucherID))
return;
var kotCount = _bill.Keys.Count(x => x.BillItemType == BillItemType.Kot && x.KotID != 0);
var voucherID = 0;
if (table.VoucherID == 0 && kotCount > 1)
//Move Kot
voucherID = MoveKot(kot, table);
else if (table.VoucherID == 0 && kotCount == 1)
//Move Table
voucherID = MoveTable(table);
else if (table.VoucherID != 0 && kotCount > 1)
//Merge Kot
voucherID = MergeKot(kot, table);
else if (table.VoucherID == 0 && kotCount == 1)
//Move Table
voucherID = MoveTable(table);
else if (table.VoucherID != 0 && kotCount == 1)
//Merge Table
voucherID = MergeTable(table);
@ -480,14 +549,20 @@ namespace Tanshu.Accounts.PointOfSale
}
internal void MoveTable()
{
if (_billInfo == null)
if (_billInfo.VoucherID == 0)
return;
using (var bi = new VoucherBI(false))
if (bi.IsVoucherPrinted(_billInfo.VoucherID) && !Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL))
return;
var table = GetTableForMove(true);
var allowMerge = !IsPrintedOrVoid(_billInfo);
var table = GetTableForMove(allowMerge);
if (table == null)
return;
if (table.Name == _billInfo.TableID)
return;
if (table.VoucherID != 0)
if (IsPrintedOrVoid(table.VoucherID))
return;
LoadBill(table.VoucherID == 0 ? MoveTable(table) : MergeTable(table));
}
@ -495,15 +570,7 @@ namespace Tanshu.Accounts.PointOfSale
{
if (!Session.IsAllowed(RoleConstants.MOVE_KOT))
return 0;
var voucher = new Voucher(Session.User)
{
Customer = _billInfo.Customer,
TableID = table.Name,
Waiter = _billInfo.Waiter,
Printed = _billInfo.Printed,
Void = false,
Narration = "",
};
var voucher = new Voucher(Session.User, _billInfo.Customer, table.Name, _billInfo.Waiter, _billInfo.Printed, false, "");
using (var session = SessionManager.Session)
{
@ -540,60 +607,239 @@ namespace Tanshu.Accounts.PointOfSale
{
if (!Session.IsAllowed(RoleConstants.MERGE_TABLE))
return 0;
if (_billInfo.Printed)
return 0;
var kots = _bill.Keys.Where(x => x.BillItemType == BillItemType.Kot && x.KotID != 0);
foreach (var item in kots)
MergeKot(item, table);
int voucherID;
using (var bi = new VoucherBI())
voucherID = bi.MergeTables(_billInfo.VoucherID, table);
using (var bi = new VoucherBI())
bi.Delete(_billInfo.VoucherID);
return table.VoucherID;
return voucherID;
}
#endregion
#region Save
public void SaveBill(int waiterID, string tableID)
public void SaveKot()
{
#region Check if Allowed
if (!Session.IsAllowed(RoleConstants.PRINT_KOT))
return;
if (_billInfo.VoucherID != 0 && IsPrintedOrVoid(_billInfo))
return;
if (_bill.Count == 1) //new kot only
return;
#endregion
//Save
var saved = _billInfo.VoucherID == 0 ? InsertVoucher(false, !_editVoucherID.HasValue) : UpdateVoucher(false, !_editVoucherID.HasValue);
//Print
if ((!_editVoucherID.HasValue || _print) && saved.HasValue)
Thermal.PrintKot(_billInfo.VoucherID, saved.Value);
//Cleanup
if (_editVoucherID.HasValue)
_saleForm.CloseWindow();
else
ClearBill();
}
public void SaveBill()
{
#region Check if Allowed
if (!Session.IsAllowed(RoleConstants.PRINT_BILL))
return;
if (_bill.Count == 1) //new kot only
return;
var printed = false;
if (_billInfo != null)
using (var bi = new VoucherBI(false))
{
var voucher = bi.Get(_billInfo.VoucherID);
if (voucher.Void)
{
MessageBox.Show(string.Format("This Bill is already void.\nReason: {0}", _billInfo.VoidReason), "Bill already Voided", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
printed = voucher.Printed;
}
if (printed && (!Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL)))
return;
var amount = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != 0).Sum(x => x.Value.GrossAmount);
ShowDiscount();
if (printed)
SaveReprintOrDiscountBill(waiterID, tableID, amount);
else
SaveNewBill(waiterID, tableID);
#endregion
decimal amount;
var isReprint = IsReprint(out amount);
if (!isReprint.HasValue)
return;
else if (isReprint.Value)
{
SetDiscount();
SaveReprintOrDiscountBill(amount);
}
else
{
SetDiscount();
// Ask for VoucherType only for new bill, if none, then cancel
VoucherType? voucherType;
using (var frm = new VoucherTypeForm())
{
frm.ShowDialog();
voucherType = frm.Selection;
}
if (!voucherType.HasValue)
return;
_billInfo.VoucherType = voucherType.Value;
var saved = _billInfo.VoucherID == 0 ? InsertVoucher(true, !_editVoucherID.HasValue) : UpdateVoucher(true, !_editVoucherID.HasValue);
}
if (!_editVoucherID.HasValue || _print)
Thermal.PrintBill(_billInfo.VoucherID);
if (_editVoucherID.HasValue)
_saleForm.CloseWindow();
ClearBill();
}
public void SaveNewBill(int waiterID, string tableID)
public void SplitBill()
{
var saved = _billInfo == null
? InsertVoucher(true, waiterID, tableID, !_editVoucherID.HasValue)
: UpdateVoucher(true, waiterID, tableID, !_editVoucherID.HasValue);
#region Permissions
bool isPrinted, isVoid;
IsPrintedOrVoid(_billInfo, out isPrinted, out isVoid);
if (_billInfo.VoucherID == 0 || isVoid)
return; // must be existing non void bill
if (!Session.IsAllowed(RoleConstants.SPLIT_BILL))
return;
#endregion
#region Get Move List
HashSet<string> splitList = null;
using (var bi = new ProductGroupBI())
{
using (var frm = new DiscountForm(bi.GetProductGroupTypes()))
if (frm.ShowDialog() == DialogResult.OK)
frm.Selection(out splitList);
}
if (splitList == null || splitList.Count == 0)
return;
var listFirst = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != 0 && splitList.Contains(x.Value.Product.ProductGroup.GroupType));
var listSecond = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != 0 && !splitList.Contains(x.Value.Product.ProductGroup.GroupType));
if (listFirst.Count() == 0 || listSecond.Count() == 0)
return; // all or none items selected to be moved
#endregion
var table = GetTableForMove(false);
if (table == null)
return;
#region new voucherFirst
var voucherFirst = new Voucher(Session.User)
{
Customer = _billInfo.Customer,
TableID = table.Name,
Waiter = _billInfo.Waiter,
Printed = isPrinted,
Void = false,
Narration = "",
VoucherType = _billInfo.VoucherType
};
var kotFirst = GetKot(listFirst);
if (kotFirst != null)
voucherFirst.Kots.Add(kotFirst);
#endregion
#region new voucherFirst
var voucherSecond = new Voucher(Session.User)
{
Customer = _billInfo.Customer,
TableID = _billInfo.TableID,
Waiter = _billInfo.Waiter,
Printed = isPrinted,
Void = false,
Narration = "",
VoucherType = _billInfo.VoucherType
};
var kotSecond = GetKot(listSecond);
if (kotSecond != null)
voucherSecond.Kots.Add(kotSecond);
#endregion
#region Old Voucher
_billInfo.User = Session.User;
_billInfo.Void = true;
_billInfo.VoidReason = "Bill Split";
#endregion
using (var session = SessionManager.Session)
{
var trans = session.BeginTransaction();
using (var bi = new VoucherBI(session, false))
bi.Insert(voucherFirst);
trans.Commit();
trans = session.BeginTransaction();
using (var bi = new VoucherBI(session, false))
bi.Insert(voucherSecond);
trans.Commit();
trans = session.BeginTransaction();
using (var bi = new VoucherBI(session, false))
bi.Update(_billInfo);
trans.Commit();
trans = session.BeginTransaction();
using (var ft = new FoodTableBI(session, false))
ft.UpdateStatus(voucherFirst);
using (var ft = new FoodTableBI(session, false))
ft.UpdateStatus(voucherSecond);
trans.Commit();
trans.Dispose();
}
if (isPrinted)
{
Thermal.PrintBill(voucherFirst.VoucherID);
Thermal.PrintBill(voucherSecond.VoucherID);
}
LoadBill(voucherFirst.VoucherID);
}
public void SaveReprintOrDiscountBill(int waiterID, string tableID, decimal oldAmount)
public void VoidBill()
{
#region Check conditions and Permissions
if (_billInfo.VoucherID == 0)
return;
//if (!_billInfo.Printed)
// return;
if (_billInfo.Void)
return;
if (!Session.IsAllowed(RoleConstants.VOID_BILL))
return;
if (MessageBox.Show("Are you sure you want to void this bill?", "Void Bill", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
return;
#endregion
var voidReason = new SelectVoidReason(GetVoidReason, true);
voidReason.ShowDialog();
if (voidReason.SelectedItem != null)
{
using (var session = SessionManager.Session)
{
using (var trans = session.BeginTransaction())
{
using (var bi = new VoucherBI(session, false))
bi.VoidBill(_billInfo.VoucherID, voidReason.SelectedItem.Description);
_billInfo.Void = true;
_billInfo.VoidReason = voidReason.SelectedItem.Description;
using (var ft = new FoodTableBI(session, false))
ft.UpdateStatus(_billInfo);
trans.Commit();
}
}
ClearBill();
}
else
{
MessageBox.Show("Please Select a reason if you want to void the bill", "Bill NOT Voided", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
}
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")
};
return list.Where(i => i.Description.ToLower().Contains(filter["Name"].ToLower().Trim())).ToList();
}
private void SaveReprintOrDiscountBill(decimal oldAmount)
{
var amountChanged = oldAmount != _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != 0).Sum(x => x.Value.GrossAmount);
var itemsChanged = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID == 0).Count() != 0;
@ -607,7 +853,8 @@ namespace Tanshu.Accounts.PointOfSale
Waiter = _billInfo.Waiter,
Printed = true,
Void = false,
Narration = ""
Narration = "",
VoucherType = _billInfo.VoucherType
};
var kotNew = GetKot(_bill.Where(x => x.Key.BillItemType == BillItemType.Product));
@ -644,47 +891,16 @@ namespace Tanshu.Accounts.PointOfSale
bi.Insert(new Reprint() { Date = DbValues.Date, User = Session.User, Voucher = _billInfo });
}
}
public void SaveKot(int waiterID, string tableID)
private int? InsertVoucher(bool finalBill, bool updateTable)
{
if (!Session.IsAllowed(RoleConstants.PRINT_KOT))
return;
using (var bi = new VoucherBI(false)) // Kot on printed bill not allowed
if ((_billInfo != null) && (bi.IsVoucherPrinted(_billInfo.VoucherID)))
return;
if (_bill.Count == 1) //new kot only
return;
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);
if (_editVoucherID.HasValue)
_saleForm.CloseWindow();
ClearBill();
}
private int? InsertVoucher(bool finalBill, int waiterID, string tableID, bool updateTable)
{
if (_billInfo != null)
{
MessageBox.Show("Error in InsertVoucher, there is a previous sale in memory", "Error");
return null;
}
_billInfo = new Voucher(Session.User)
{
Customer = _customer,
//Paid = finalBill,
TableID = tableID,
Waiter = WaiterBI.GetWaiter(waiterID),
Printed = finalBill,
Void = false,
Narration = "",
};
UpdateKots();
_billInfo.Printed = finalBill;
_billInfo.Void = false;
_billInfo.Narration = "";
//UpdateKots();
var kot = GetKot(_bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID == 0 && x.Value.Quantity != 0));
if (kot != null)
_billInfo.Kots.Add(kot);
if (kot == null)
return null;
_billInfo.Kots.Add(kot);
using (var session = SessionManager.Session)
{
using (var trans = session.BeginTransaction())
@ -700,14 +916,9 @@ namespace Tanshu.Accounts.PointOfSale
}
}
}
private int? UpdateVoucher(bool finalBill, int waiterID, string tableID, bool updateTable)
private int? UpdateVoucher(bool finalBill, bool updateTable)
{
_billInfo.User = Session.User;
_billInfo.Customer = _customer;
_billInfo.TableID = tableID;
_billInfo.Waiter = WaiterBI.GetWaiter(waiterID);
UpdateKots();
if (!_billInfo.Printed)
@ -734,7 +945,6 @@ namespace Tanshu.Accounts.PointOfSale
}
}
}
private void UpdateKots()
{
foreach (var item in _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != 0))
@ -776,17 +986,15 @@ namespace Tanshu.Accounts.PointOfSale
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;
return decimal.TryParse(result.Text, out amount);
}
private bool GetInput(string prompt, ref string info)
{
@ -794,114 +1002,8 @@ namespace Tanshu.Accounts.PointOfSale
if (!result.OK)
return false;
info = result.Text.Trim();
if (string.IsNullOrEmpty(info))
return false;
return true;
return !string.IsNullOrEmpty(info);
}
#endregion
public void SplitBill()
{
#region Permissions
if (_billInfo == null || _billInfo.VoucherID == 0 || _billInfo.Void == true)
return; // must be existing non void bill
if (!Session.IsAllowed(RoleConstants.SPLIT_BILL))
return;
#endregion
bool printed;
using (var bi = new VoucherBI(false))
printed = bi.IsVoucherPrinted(_billInfo.VoucherID);
#region Get Move List
HashSet<string> splitList = null;
using (var bi = new ProductGroupBI())
{
using (var frm = new DiscountForm(bi.GetProductGroupTypes()))
if (frm.ShowDialog() == DialogResult.OK)
frm.Selection(out splitList);
}
if (splitList == null || splitList.Count == 0)
return;
var listFirst = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != 0 && splitList.Contains(x.Value.Product.ProductGroup.GroupType));
var listSecond = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != 0 && !splitList.Contains(x.Value.Product.ProductGroup.GroupType));
if (listFirst.Count() == 0 || listSecond.Count() == 0)
return; // all or none items selected to be moved
#endregion
var table = GetTableForMove(false);
if (table == null)
return;
#region new voucherFirst
var voucherFirst = new Voucher(Session.User)
{
Customer = _billInfo.Customer,
TableID = table.Name,
Waiter = _billInfo.Waiter,
Printed = printed,
Void = false,
Narration = ""
};
var kotFirst = GetKot(listFirst);
if (kotFirst != null)
voucherFirst.Kots.Add(kotFirst);
#endregion
#region new voucherFirst
var voucherSecond = new Voucher(Session.User)
{
Customer = _billInfo.Customer,
TableID = _billInfo.TableID,
Waiter = _billInfo.Waiter,
Printed = printed,
Void = false,
Narration = ""
};
var kotSecond = GetKot(listSecond);
if (kotSecond != null)
voucherSecond.Kots.Add(kotSecond);
#endregion
#region Old Voucher
_billInfo.User = Session.User;
_billInfo.Void = true;
_billInfo.VoidReason = "Printed bill Split";
#endregion
using (var session = SessionManager.Session)
{
var trans = session.BeginTransaction();
using (var bi = new VoucherBI(session, false))
bi.Insert(voucherFirst);
trans.Commit();
trans = session.BeginTransaction();
using (var bi = new VoucherBI(session, false))
bi.Insert(voucherSecond);
trans.Commit();
trans = session.BeginTransaction();
using (var bi = new VoucherBI(session, false))
bi.Update(_billInfo);
trans.Commit();
trans = session.BeginTransaction();
using (var ft = new FoodTableBI(session, false))
ft.UpdateStatus(voucherFirst);
using (var ft = new FoodTableBI(session, false))
ft.UpdateStatus(voucherSecond);
trans.Commit();
trans.Dispose();
}
if (printed)
{
Thermal.PrintBill(voucherFirst.VoucherID);
Thermal.PrintBill(voucherSecond.VoucherID);
}
LoadBill(voucherFirst.VoucherID);
}
}
}

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using Tanshu.Accounts.Contracts;
using System.Windows.Forms;
using Tanshu.Accounts.Entities;
using Tanshu.Common;
namespace Tanshu.Accounts.PointOfSale
@ -12,9 +13,10 @@ namespace Tanshu.Accounts.PointOfSale
{
void ClearBill(List<BillItemValue> bill);
void SetCustomerDisplay(string name);
void SetWaiterDisplay(string p);
void CloseWindow();
void ShowAmount(decimal discountAmount, decimal grossAmount, decimal serviceChargeAmount, decimal taxAmount, decimal valueAmount, List<BillItemValue> bill);
void ShowInfo(string billID, string kotID, DateTime creationDate, DateTime date, DateTime lastEditDate, string customer, string tableID, int waiterID, string waiter);
void ShowInfo(Voucher voucher);
void SetUserName(string name);
BindingSource BindingSource { get; }
SaleFormState FormState { set; }