From b1a9d2daaedf82459900823ec0327735c8828f6b Mon Sep 17 00:00:00 2001 From: tanshu Date: Thu, 20 Nov 2014 13:42:20 +0530 Subject: [PATCH] Lot of changes. Now table must be explicitly updated and not from inside various functions. This makes for better understanding and lesser mistakes. Product form now has an IsActive checkbox to show only active products. --- .../Data Contracts/VoucherBO.cs | 1 - .../Controllers/BillController.cs | 260 +++++++++--------- Tanshu.Accounts.PointOfSale/MainForm.cs | 4 +- .../Products/ProductListForm.Designer.cs | 67 +++-- .../Products/ProductListForm.cs | 35 ++- .../Products/ProductListForm.resx | 18 ++ Tanshu.Accounts.Repository/ProductBI.cs | 1 + Tanshu.Accounts.Repository/VoucherBI.cs | 119 ++------ .../VoucherSettlementBI.cs | 61 ++-- 9 files changed, 262 insertions(+), 304 deletions(-) diff --git a/Tanshu.Accounts.Contracts/Data Contracts/VoucherBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/VoucherBO.cs index 96ff654..18b009a 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/VoucherBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/VoucherBO.cs @@ -76,7 +76,6 @@ namespace Tanshu.Accounts.Entities case VoucherType.Regular: default: return (BillID.Value / 10000).ToString() + "-" + (BillID.Value % 10000).ToString(); - break; } } else diff --git a/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs b/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs index 9b3db58..8ede911 100644 --- a/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs +++ b/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs @@ -14,26 +14,24 @@ namespace Tanshu.Accounts.PointOfSale public class BillController { private readonly BillDict _bill; - private Voucher _billInfo; + private Voucher _voucher; private Guid? _editVoucherID; - private readonly bool _print; private ISaleForm _saleForm; public Waiter Waiter { - get { return _billInfo.Waiter; } - set { _billInfo.Waiter = value; } + get { return _voucher.Waiter; } + set { _voucher.Waiter = value; } } - public BillController(Guid? editVoucherID, bool print) + public BillController(Guid? editVoucherID) { this._editVoucherID = editVoucherID; - _print = print; _bill = new BillDict(); - _billInfo = new Voucher(Session.User); + _voucher = new Voucher(Session.User); using (var bi = new CustomerBI()) - _billInfo.Customer = bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER); + _voucher.Customer = bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER); using (var bi = new WaiterBI()) - _billInfo.Waiter = bi.Get(x => x.WaiterID == Constants.WAITER); + _voucher.Waiter = bi.Get(x => x.WaiterID == Constants.WAITER); } public BillItemValue CurrentProduct { @@ -59,7 +57,7 @@ namespace Tanshu.Accounts.PointOfSale public void InitGui(ISaleForm saleForm) { this._saleForm = saleForm; - this._saleForm.SetCustomerDisplay(_billInfo.Customer.Name); + this._saleForm.SetCustomerDisplay(_voucher.Customer.Name); this._saleForm.SetUserName(Session.User.Name); } public void AddProduct(Product product) @@ -107,7 +105,7 @@ namespace Tanshu.Accounts.PointOfSale public void SetDiscount() { if (!Session.IsAllowed("Discount")) - throw new PermissionException("Not Allowed to give Discount"); + return; // throw new PermissionException("Not Allowed to give Discount"); using (var bi = new ProductGroupBI()) { @@ -119,7 +117,7 @@ namespace Tanshu.Accounts.PointOfSale var discount = frm.Selection(out outList); discount = discount / 100; if (discount > 1 || discount < 0) - throw new ValidationException("Invalid Discount Amount"); + return; // throw new ValidationException("Invalid Discount Amount"); foreach (var item in _bill.Where(x => x.Key.BillItemType == BillItemType.Product && outList.Contains(x.Value.Product.ProductGroup.GroupType))) { @@ -173,7 +171,7 @@ namespace Tanshu.Accounts.PointOfSale } public void ShowCustomers(bool reset) { - if (!reset && ((_billInfo.Customer == null) || _billInfo.Customer.CustomerID == Constants.CASH_CUSTOMER)) + if (!reset && ((_voucher.Customer == null) || _voucher.Customer.CustomerID == Constants.CASH_CUSTOMER)) { using (var selectCustomer = new SelectCustomer(CustomerBI.StaticList, true)) { @@ -181,21 +179,21 @@ namespace Tanshu.Accounts.PointOfSale selectCustomer.ShowDialog(); if (selectCustomer.SelectedItem != null) { - _billInfo.Customer = selectCustomer.SelectedItem; + _voucher.Customer = selectCustomer.SelectedItem; } else { using (var bi = new CustomerBI()) - _billInfo.Customer = bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER); + _voucher.Customer = bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER); } } } else { using (var bi = new CustomerBI()) - _billInfo.Customer = bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER); + _voucher.Customer = bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER); } - _saleForm.SetCustomerDisplay(_billInfo.Customer.Name); + _saleForm.SetCustomerDisplay(_voucher.Customer.Name); } private Customer selectCustomer_customerEvent(object sender, CustomerEventArgs e) { @@ -210,7 +208,7 @@ namespace Tanshu.Accounts.PointOfSale if (reset) { using (var bi = new WaiterBI()) - _billInfo.Waiter = bi.Get(x => x.WaiterID == Constants.WAITER); + _voucher.Waiter = bi.Get(x => x.WaiterID == Constants.WAITER); } else { @@ -220,16 +218,16 @@ namespace Tanshu.Accounts.PointOfSale selectWaiter.ShowDialog(); if (selectWaiter.SelectedItem != null) { - _billInfo.Waiter = selectWaiter.SelectedItem; + _voucher.Waiter = selectWaiter.SelectedItem; } else { using (var bi = new WaiterBI()) - _billInfo.Waiter = bi.Get(x => x.WaiterID == Constants.WAITER); + _voucher.Waiter = bi.Get(x => x.WaiterID == Constants.WAITER); } } } - _saleForm.SetWaiterDisplay(_billInfo.Waiter.Name); + _saleForm.SetWaiterDisplay(_voucher.Waiter.Name); } private Waiter selectWaiter_waiterEvent(object sender, SelectorEventArgs e) { @@ -301,27 +299,6 @@ namespace Tanshu.Accounts.PointOfSale return dbVoucher.Printed || dbVoucher.Void; } } - private bool? IsReprint(out decimal amount) - { - amount = 0; - if (_billInfo.VoucherID == Guid.Empty) - 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("Edit Printed Bill"))) - return null; - amount = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != Guid.Empty).Sum(x => x.Value.GrossAmount); - - return isPrinted; - } private void InputBox_Validating(object sender, InputBoxValidatingArgs e) { } @@ -330,10 +307,10 @@ namespace Tanshu.Accounts.PointOfSale ClearBill(); using (var bi = new VoucherBI()) { - _billInfo = bi.Get(x => x.VoucherID == voucherID); + _voucher = bi.Get(x => x.VoucherID == voucherID); _bill.Clear(); - _saleForm.ShowInfo(_billInfo); - _bill.Load(_billInfo); + _saleForm.ShowInfo(_voucher); + _bill.Load(_voucher); var newKotKey = new BillItemKey(Guid.Empty); var newKotItem = new BillItemValue(); _bill.Add(newKotKey, newKotItem); @@ -355,9 +332,9 @@ namespace Tanshu.Accounts.PointOfSale using (var frm = new PaxForm()) { frm.ShowDialog(); - _billInfo.Table = table; - _billInfo.Pax = frm.Pax; - _saleForm.ShowInfo(_billInfo); + _voucher.Table = table; + _voucher.Pax = frm.Pax; + _saleForm.ShowInfo(_voucher); } } } @@ -372,7 +349,7 @@ namespace Tanshu.Accounts.PointOfSale } public void ClearBill() { - _billInfo = new Voucher(Session.User); + _voucher = new Voucher(Session.User); ShowCustomers(true); ShowWaiters(true); _bill.Clear(); @@ -386,31 +363,40 @@ namespace Tanshu.Accounts.PointOfSale ClearBill(); if (_editVoucherID.HasValue) { - LoadBill(_editVoucherID.Value); + FoodTable ft = new FoodTableBI().Get(x => x.VoucherID == _editVoucherID.Value); + if (ft == null) + LoadBill(_editVoucherID.Value); + else + { + _editVoucherID = null; + LoadBill(ft.Name); + } return SaleFormState.Billing; } return SaleFormState.Waiting; } internal void SettleBill() { - if (_billInfo.VoucherID == Guid.Empty) + if (_voucher.VoucherID == Guid.Empty) return; - if (!_billInfo.Printed) + if (!_voucher.Printed) return; if (!Session.IsAllowed("Settle Bill")) return; IDictionary options; - var amount = -1 * _billInfo.Kots.Sum(x => x.Inventories.Sum(y => y.Amount)); - using (var frm = new SettleChoicesForm(Math.Round(amount) * -1, _billInfo.VoucherType)) + var amount = -1 * _voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount)); + using (var frm = new SettleChoicesForm(Math.Round(amount) * -1, _voucher.VoucherType)) { frm.ShowDialog(); options = frm.OptionsChosen; } if (options.Count == 0) return; - using (var bi = new VoucherSettlementBI()) + using (var bi = new VoucherBI()) { - bi.SettleVoucher(Session.User, _billInfo.VoucherID, options); + bi.SettleVoucher(Session.User, _voucher.VoucherID, options); + if (!_editVoucherID.HasValue) + bi.UpdateTable(x => x.FoodTableID == _voucher.Table.FoodTableID && x.VoucherID == _voucher.VoucherID, null, null); bi.SaveChanges(); } ClearBill(); @@ -432,9 +418,9 @@ namespace Tanshu.Accounts.PointOfSale } internal void MoveKot() { - if (_billInfo.VoucherID == Guid.Empty) + if (_voucher.VoucherID == Guid.Empty) return; - if (IsPrintedOrVoid(_billInfo)) + if (IsPrintedOrVoid(_voucher)) return; var kot = CurrentKot; if (kot == null) @@ -442,7 +428,7 @@ namespace Tanshu.Accounts.PointOfSale var table = GetTableForMove(true); if (table == null) return; - if (table.FoodTableID == _billInfo.Table.FoodTableID) + if (table.FoodTableID == _voucher.Table.FoodTableID) return; if (table.VoucherID != null) if (IsPrintedOrVoid(table.VoucherID.Value)) @@ -466,15 +452,15 @@ namespace Tanshu.Accounts.PointOfSale } internal void MoveTable() { - if (_billInfo.VoucherID == Guid.Empty) + if (_voucher.VoucherID == Guid.Empty) return; - var allowMerge = !IsPrintedOrVoid(_billInfo); + var allowMerge = !IsPrintedOrVoid(_voucher); var table = GetTableForMove(allowMerge); if (table == null) return; - if (table.FoodTableID == _billInfo.Table.FoodTableID) + if (table.FoodTableID == _voucher.Table.FoodTableID) return; if (table.VoucherID.HasValue) if (IsPrintedOrVoid(table.VoucherID.Value)) @@ -489,6 +475,7 @@ namespace Tanshu.Accounts.PointOfSale using (var bi = new VoucherBI()) { var newVoucherID = bi.MoveKot(kot.KotID, table.FoodTableID); + bi.UpdateTable(x => x.FoodTableID == table.FoodTableID && x.VoucherID == null, newVoucherID, "running"); bi.SaveChanges(); return newVoucherID; } @@ -510,9 +497,11 @@ namespace Tanshu.Accounts.PointOfSale return Guid.Empty; using (var bi = new VoucherBI()) { - var newVoucherID = bi.Move(_billInfo.Table.FoodTableID, tableID); + bi.MoveTable(_voucher.VoucherID, tableID); + bi.UpdateTable(x => x.FoodTableID == tableID && x.VoucherID == null, _voucher.VoucherID, _voucher.Table.Status); + bi.UpdateTable(x => x.FoodTableID == _voucher.Table.FoodTableID && x.VoucherID == _voucher.VoucherID, null, null); bi.SaveChanges(); - return newVoucherID; + return _voucher.VoucherID; } } private Guid MergeTable(FoodTable table) @@ -521,7 +510,8 @@ namespace Tanshu.Accounts.PointOfSale return Guid.Empty; using (var bi = new VoucherBI()) { - var newVoucherID = bi.MergeTables(_billInfo.VoucherID, table.Name); + var newVoucherID = bi.MergeTables(_voucher.VoucherID, table.Name); + bi.UpdateTable(x => x.FoodTableID == _voucher.Table.FoodTableID && x.VoucherID == _voucher.VoucherID, null, null); bi.SaveChanges(); return newVoucherID; } @@ -534,18 +524,18 @@ namespace Tanshu.Accounts.PointOfSale #region Check if Allowed if (!Session.IsAllowed("Print Kot")) return; - if (_billInfo.VoucherID != Guid.Empty && IsPrintedOrVoid(_billInfo)) + if (_voucher.VoucherID != Guid.Empty && IsPrintedOrVoid(_voucher)) return; if (_bill.Count == 1) //new kot only return; #endregion //Save - var saved = _billInfo.VoucherID == Guid.Empty ? InsertVoucher(false, !_editVoucherID.HasValue) : UpdateVoucher(false, !_editVoucherID.HasValue); + var saved = _voucher.VoucherID == Guid.Empty ? InsertVoucher(false, !_editVoucherID.HasValue) : UpdateVoucher(false, !_editVoucherID.HasValue); //Print - if ((!_editVoucherID.HasValue || _print) && saved.HasValue) - Thermal.PrintKot(_billInfo.VoucherID, saved.Value); + if (!_editVoucherID.HasValue && saved.HasValue) + Thermal.PrintKot(_voucher.VoucherID, saved.Value); //Cleanup if (_editVoucherID.HasValue) @@ -557,54 +547,40 @@ namespace Tanshu.Accounts.PointOfSale { #region Check if Allowed if (!Session.IsAllowed("Print Bill")) - throw new PermissionException("Printing not allowed"); + return; // throw new PermissionException("Printing not allowed"); if (_bill.Count == 1) //new kot only return; + bool isPrinted = false, isVoid = false; + if (_voucher.VoucherID != Guid.Empty) + IsPrintedOrVoid(_voucher, out isPrinted, out isVoid); + if (isVoid) + { + MessageBox.Show(string.Format("This Bill is already void.\nReason: {0}", _voucher.VoidReason), "Bill already Voided", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (isPrinted && !Session.IsAllowed("Edit Printed Bill")) + return; #endregion - decimal amount; - - var isReprint = IsReprint(out amount); - if (!isReprint.HasValue) - return; - else if (isReprint.Value) + var amount = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != Guid.Empty).Sum(x => x.Value.GrossAmount); + SetDiscount(); + if (isPrinted) { - try - { - SetDiscount(); - } - catch (Exception ex) - { - if (!(ex is ValidationException) && !(ex is PermissionException)) - throw; - } SaveReprintOrDiscountBill(amount); } else { - try - { - SetDiscount(); - } - catch (Exception ex) - { - if (!(ex is ValidationException) && !(ex is PermissionException)) - throw; - } // Ask for VoucherType only for new bill, if none, then cancel - VoucherType? voucherType; using (var frm = new VoucherTypeForm()) { frm.ShowDialog(); - voucherType = frm.Selection; + if (!frm.Selection.HasValue) + return; + _voucher.VoucherType = frm.Selection.Value; } - if (!voucherType.HasValue) - return; - _billInfo.VoucherType = voucherType.Value; - var saved = _billInfo.VoucherID == Guid.Empty ? InsertVoucher(true, !_editVoucherID.HasValue) : UpdateVoucher(true, !_editVoucherID.HasValue); + var saved = _voucher.VoucherID == Guid.Empty ? InsertVoucher(true, !_editVoucherID.HasValue) : UpdateVoucher(true, !_editVoucherID.HasValue); } - if (!_editVoucherID.HasValue || _print) - Thermal.PrintBill(_billInfo.VoucherID); + Thermal.PrintBill(_voucher.VoucherID); if (_editVoucherID.HasValue) _saleForm.CloseWindow(); ClearBill(); @@ -614,8 +590,8 @@ namespace Tanshu.Accounts.PointOfSale #region Permissions bool isPrinted, isVoid; - IsPrintedOrVoid(_billInfo, out isPrinted, out isVoid); - if (_billInfo.VoucherID == Guid.Empty || isVoid) + IsPrintedOrVoid(_voucher, out isPrinted, out isVoid); + if (_voucher.VoucherID == Guid.Empty || isVoid) return; // must be existing non void bill if (!Session.IsAllowed("Split Bill")) @@ -647,13 +623,13 @@ namespace Tanshu.Accounts.PointOfSale #region new voucherFirst var voucherFirst = new Voucher(Session.User) { - Customer = _billInfo.Customer, + Customer = _voucher.Customer, Table = table, - Waiter = _billInfo.Waiter, + Waiter = _voucher.Waiter, Printed = isPrinted, Void = false, Narration = "", - VoucherType = _billInfo.VoucherType + VoucherType = _voucher.VoucherType }; var kotFirst = GetKot(listFirst); @@ -664,13 +640,13 @@ namespace Tanshu.Accounts.PointOfSale #region new voucherSecond var voucherSecond = new Voucher(Session.User) { - Customer = _billInfo.Customer, - Table = _billInfo.Table, - Waiter = _billInfo.Waiter, + Customer = _voucher.Customer, + Table = _voucher.Table, + Waiter = _voucher.Waiter, Printed = isPrinted, Void = false, Narration = "", - VoucherType = _billInfo.VoucherType + VoucherType = _voucher.VoucherType }; var kotSecond = GetKot(listSecond); @@ -679,7 +655,10 @@ namespace Tanshu.Accounts.PointOfSale #endregion using (var bi = new VoucherBI()) { - bi.SplitBill(_billInfo.VoucherID, voucherFirst, voucherSecond); + bi.SplitBill(_voucher.VoucherID, voucherFirst, voucherSecond); + var status = _voucher.Printed ? "printed" : "running"; + bi.UpdateTable(x => x.FoodTableID == voucherFirst.Table.FoodTableID && x.VoucherID == null, voucherFirst.VoucherID, status); + bi.UpdateTable(x => x.FoodTableID == voucherSecond.Table.FoodTableID && x.VoucherID == _voucher.VoucherID, voucherSecond.VoucherID, status); bi.SaveChanges(); } if (isPrinted) @@ -692,11 +671,9 @@ namespace Tanshu.Accounts.PointOfSale public void VoidBill() { #region Check conditions and Permissions - if (_billInfo.VoucherID == Guid.Empty) + if (_voucher.VoucherID == Guid.Empty) return; - //if (!_billInfo.Printed) - // return; - if (_billInfo.Void) + if (_voucher.Void) return; if (!Session.IsAllowed("Void Bill")) return; @@ -710,7 +687,9 @@ namespace Tanshu.Accounts.PointOfSale { using (var bi = new VoucherBI()) { - bi.VoidBill(_billInfo.VoucherID, voidReason.SelectedItem.Description, !_editVoucherID.HasValue); + bi.VoidBill(_voucher.VoucherID, voidReason.SelectedItem.Description); + if (!_editVoucherID.HasValue) + bi.UpdateTable(x => x.FoodTableID == _voucher.Table.FoodTableID && x.VoucherID == _voucher.VoucherID, null, null); bi.SaveChanges(); } ClearBill(); @@ -744,13 +723,13 @@ namespace Tanshu.Accounts.PointOfSale #region new voucherFirst var newVoucher = new Voucher(Session.User) { - Customer = _billInfo.Customer, - Table = _billInfo.Table, - Waiter = _billInfo.Waiter, + Customer = _voucher.Customer, + Table = _voucher.Table, + Waiter = _voucher.Waiter, Printed = true, Void = false, Narration = "", - VoucherType = _billInfo.VoucherType + VoucherType = _voucher.VoucherType }; var kotNew = GetKot(_bill.Where(x => x.Key.BillItemType == BillItemType.Product)); @@ -760,32 +739,39 @@ namespace Tanshu.Accounts.PointOfSale using (var bi = new VoucherBI()) { - bi.DiscountPrintedBill(_billInfo.VoucherID, newVoucher); + bi.DiscountPrintedBill(_voucher.VoucherID, newVoucher); + bi.UpdateTable(x => x.FoodTableID == _voucher.Table.FoodTableID && (x.VoucherID == _voucher.VoucherID || x.VoucherID == null), newVoucher.VoucherID, "printed"); bi.SaveChanges(); } + _editVoucherID = null; LoadBill(newVoucher.VoucherID); } else { using (var bi = new ReprintBI()) { - bi.Insert(new Reprint() { User = Session.User, Voucher = _billInfo }); + bi.Insert(new Reprint() { User = Session.User, Voucher = _voucher }); bi.SaveChanges(); } } } private Guid? InsertVoucher(bool finalBill, bool updateTable) { - _billInfo.Printed = finalBill; - _billInfo.Void = false; - _billInfo.Narration = ""; + _voucher.Printed = finalBill; + _voucher.Void = false; + _voucher.Narration = ""; var kot = GetKot(_bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID == Guid.Empty && x.Value.Quantity != 0)); if (kot == null) return null; - _billInfo.Kots.Add(kot); + _voucher.Kots.Add(kot); using (var bi = new VoucherBI()) { - var kotID = bi.Insert(_billInfo, updateTable); + var kotID = bi.Insert(_voucher); + if (updateTable) + { + var status = !_voucher.Printed ? "running" : "printed"; + bi.UpdateTable(x => x.FoodTableID == _voucher.Table.FoodTableID && x.VoucherID == null, _voucher.VoucherID, status); + } bi.SaveChanges(); return kotID; } @@ -794,25 +780,31 @@ namespace Tanshu.Accounts.PointOfSale { using (var bi = new VoucherBI()) { - var voucher = bi.Get(x => x.VoucherID == _billInfo.VoucherID); + var voucher = bi.Get(x => x.VoucherID == _voucher.VoucherID); voucher.User = Session.User; - voucher.Customer = _billInfo.Customer; - voucher.Waiter = _billInfo.Waiter; + voucher.Customer = _voucher.Customer; + voucher.Waiter = _voucher.Waiter; voucher.Printed = finalBill; - voucher.VoucherType = _billInfo.VoucherType; + voucher.VoucherType = _voucher.VoucherType; foreach (var item in _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != Guid.Empty)) { var i = voucher.Kots.Single(x => x.KotID == item.Key.KotID).Inventories.Single(x => x.Product.ProductID == item.Key.ProductID); i.Discount = item.Value.Discount; i.Price = item.Value.Price; } - if (!_billInfo.Printed) + if (!_voucher.Printed) { var kot = GetKot(_bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID == Guid.Empty && x.Value.Quantity != 0)); if (kot != null) voucher.Kots.Add(kot); } - var kotID = bi.Update(voucher, updateTable); + var kotID = bi.Update(voucher); + if (updateTable) + { + var status = !voucher.Printed ? "running" : "printed"; + bi.UpdateTable(x => x.FoodTableID == _voucher.Table.FoodTableID && x.VoucherID == _voucher.VoucherID, _voucher.VoucherID, status); + } + bi.SaveChanges(); return kotID; } diff --git a/Tanshu.Accounts.PointOfSale/MainForm.cs b/Tanshu.Accounts.PointOfSale/MainForm.cs index 2c39585..f8fd1e1 100644 --- a/Tanshu.Accounts.PointOfSale/MainForm.cs +++ b/Tanshu.Accounts.PointOfSale/MainForm.cs @@ -51,7 +51,7 @@ namespace Tanshu.Accounts.PointOfSale private void btnSale_Click(object sender, EventArgs e) { if (Session.IsAllowed("Sales")) - using (var frmSale = new SalesForm(new BillController(null, true))) + using (var frmSale = new SalesForm(new BillController(null))) { frmSale.ShowDialog(); Cache.Invalidate(); @@ -240,7 +240,7 @@ namespace Tanshu.Accounts.PointOfSale if (voucher == null) return; if (Session.IsAllowed("Sales")) - using (var frmSale = new SalesForm(new BillController(voucher.VoucherID, true))) + using (var frmSale = new SalesForm(new BillController(voucher.VoucherID))) frmSale.ShowDialog(); } diff --git a/Tanshu.Accounts.PointOfSale/Products/ProductListForm.Designer.cs b/Tanshu.Accounts.PointOfSale/Products/ProductListForm.Designer.cs index a2fa386..a8ecdd6 100644 --- a/Tanshu.Accounts.PointOfSale/Products/ProductListForm.Designer.cs +++ b/Tanshu.Accounts.PointOfSale/Products/ProductListForm.Designer.cs @@ -29,14 +29,12 @@ private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle(); this.btnAdd = new System.Windows.Forms.Button(); this.btnEdit = new System.Windows.Forms.Button(); this.btnExit = new System.Windows.Forms.Button(); this.dgvProducts = new System.Windows.Forms.DataGridView(); - this.bsList = new System.Windows.Forms.BindingSource(this.components); - this.btnSave = new System.Windows.Forms.Button(); this.nameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.unitsDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.moveUp = new System.Windows.Forms.DataGridViewButtonColumn(); @@ -47,6 +45,9 @@ this.serviceChargeDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.salePriceDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.isActiveDataGridViewCheckBoxColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn(); + this.bsList = new System.Windows.Forms.BindingSource(this.components); + this.btnSave = new System.Windows.Forms.Button(); + this.chkIsActive = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.dgvProducts)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.bsList)).BeginInit(); this.SuspendLayout(); @@ -119,21 +120,6 @@ this.dgvProducts.TabIndex = 74; this.dgvProducts.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.dgvProductTypes_CellFormatting); // - // bsList - // - this.bsList.DataSource = typeof(Tanshu.Accounts.Entities.Product); - // - // btnSave - // - this.btnSave.AccessibleName = "Done"; - this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.btnSave.Location = new System.Drawing.Point(174, 255); - this.btnSave.Name = "btnSave"; - this.btnSave.Size = new System.Drawing.Size(75, 75); - this.btnSave.TabIndex = 75; - this.btnSave.Text = "&Save"; - this.btnSave.Click += new System.EventHandler(this.btnSave_Click); - // // nameDataGridViewTextBoxColumn // this.nameDataGridViewTextBoxColumn.DataPropertyName = "Name"; @@ -195,8 +181,8 @@ // serviceChargeDataGridViewTextBoxColumn // this.serviceChargeDataGridViewTextBoxColumn.DataPropertyName = "ServiceCharge"; - dataGridViewCellStyle1.Format = "P0"; - this.serviceChargeDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle1; + dataGridViewCellStyle7.Format = "P0"; + this.serviceChargeDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle7; this.serviceChargeDataGridViewTextBoxColumn.HeaderText = "SC"; this.serviceChargeDataGridViewTextBoxColumn.Name = "serviceChargeDataGridViewTextBoxColumn"; this.serviceChargeDataGridViewTextBoxColumn.ReadOnly = true; @@ -205,8 +191,8 @@ // salePriceDataGridViewTextBoxColumn // this.salePriceDataGridViewTextBoxColumn.DataPropertyName = "Price"; - dataGridViewCellStyle2.Format = "N0"; - this.salePriceDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle2; + dataGridViewCellStyle8.Format = "N0"; + this.salePriceDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle8; this.salePriceDataGridViewTextBoxColumn.HeaderText = "Price"; this.salePriceDataGridViewTextBoxColumn.Name = "salePriceDataGridViewTextBoxColumn"; this.salePriceDataGridViewTextBoxColumn.ReadOnly = true; @@ -218,13 +204,44 @@ this.isActiveDataGridViewCheckBoxColumn.HeaderText = "Is Active"; this.isActiveDataGridViewCheckBoxColumn.Name = "isActiveDataGridViewCheckBoxColumn"; this.isActiveDataGridViewCheckBoxColumn.ReadOnly = true; - this.isActiveDataGridViewCheckBoxColumn.Width = 75; + this.isActiveDataGridViewCheckBoxColumn.Width = 54; + // + // bsList + // + this.bsList.DataSource = typeof(Tanshu.Accounts.Entities.Product); + // + // btnSave + // + this.btnSave.AccessibleName = "Done"; + this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnSave.Location = new System.Drawing.Point(174, 255); + this.btnSave.Name = "btnSave"; + this.btnSave.Size = new System.Drawing.Size(75, 75); + this.btnSave.TabIndex = 75; + this.btnSave.Text = "&Save"; + this.btnSave.Click += new System.EventHandler(this.btnSave_Click); + // + // chkIsActive + // + this.chkIsActive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.chkIsActive.AutoSize = true; + this.chkIsActive.Checked = true; + this.chkIsActive.CheckState = System.Windows.Forms.CheckState.Checked; + this.chkIsActive.Location = new System.Drawing.Point(255, 285); + this.chkIsActive.Name = "chkIsActive"; + this.chkIsActive.Size = new System.Drawing.Size(116, 17); + this.chkIsActive.TabIndex = 76; + this.chkIsActive.Text = "Show Active Only?"; + this.chkIsActive.ThreeState = true; + this.chkIsActive.UseVisualStyleBackColor = true; + this.chkIsActive.CheckStateChanged += new System.EventHandler(this.chkIsActive_CheckStateChanged); // // ProductListForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(662, 342); + this.Controls.Add(this.chkIsActive); this.Controls.Add(this.btnSave); this.Controls.Add(this.dgvProducts); this.Controls.Add(this.btnAdd); @@ -239,6 +256,7 @@ ((System.ComponentModel.ISupportInitialize)(this.dgvProducts)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.bsList)).EndInit(); this.ResumeLayout(false); + this.PerformLayout(); } @@ -260,6 +278,7 @@ private System.Windows.Forms.DataGridViewTextBoxColumn serviceChargeDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewTextBoxColumn salePriceDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewCheckBoxColumn isActiveDataGridViewCheckBoxColumn; + private System.Windows.Forms.CheckBox chkIsActive; //private System.Windows.Forms.DataGridViewTextBoxColumn discountLimitDataGridViewTextBoxColumn; //private System.Windows.Forms.DataGridViewTextBoxColumn groupTypeDataGridViewTextBoxColumn; //private System.Windows.Forms.DataGridViewTextBoxColumn productGroupDataGridViewTextBoxColumn; diff --git a/Tanshu.Accounts.PointOfSale/Products/ProductListForm.cs b/Tanshu.Accounts.PointOfSale/Products/ProductListForm.cs index 675c5ee..9d9c8fd 100644 --- a/Tanshu.Accounts.PointOfSale/Products/ProductListForm.cs +++ b/Tanshu.Accounts.PointOfSale/Products/ProductListForm.cs @@ -25,9 +25,24 @@ namespace Tanshu.Accounts.PointOfSale } private void ProductGroupListForm_Load(object sender, EventArgs e) + { + ShowGrid(); + } + private void ShowGrid() { using (var bi = new ProductBI()) - _list = bi.List(); + switch (chkIsActive.CheckState) + { + case CheckState.Checked: + _list = bi.List(x => x.IsActive == true); + break; + case CheckState.Unchecked: + _list = bi.List(x => x.IsActive == false); + break; + default: + _list = bi.List(); + break; + } bsList.DataSource = _list; } @@ -108,9 +123,25 @@ namespace Tanshu.Accounts.PointOfSale { bi.UpdateSortOrder(_list); bi.SaveChanges(); - _list = bi.List(); + switch (chkIsActive.CheckState) + { + case CheckState.Checked: + _list = bi.List(x => x.IsActive == true); + break; + case CheckState.Unchecked: + _list = bi.List(x => x.IsActive == false); + break; + default: + _list = bi.List(); + break; + } bsList.DataSource = _list; } } + + private void chkIsActive_CheckStateChanged(object sender, EventArgs e) + { + ShowGrid(); + } } } diff --git a/Tanshu.Accounts.PointOfSale/Products/ProductListForm.resx b/Tanshu.Accounts.PointOfSale/Products/ProductListForm.resx index 4537dcc..c97991e 100644 --- a/Tanshu.Accounts.PointOfSale/Products/ProductListForm.resx +++ b/Tanshu.Accounts.PointOfSale/Products/ProductListForm.resx @@ -135,4 +135,22 @@ 17, 17 + + True + + + True + + + True + + + True + + + True + + + 17, 17 + \ No newline at end of file diff --git a/Tanshu.Accounts.Repository/ProductBI.cs b/Tanshu.Accounts.Repository/ProductBI.cs index 0258a23..f5e24d4 100644 --- a/Tanshu.Accounts.Repository/ProductBI.cs +++ b/Tanshu.Accounts.Repository/ProductBI.cs @@ -17,6 +17,7 @@ namespace Tanshu.Accounts.Repository { var list = _session.QueryOver() .Where(query) + .OrderBy(x => x.ProductGroup).Asc .OrderBy(x => x.SortOrder).Asc .ThenBy(x => x.Name).Asc .List(); diff --git a/Tanshu.Accounts.Repository/VoucherBI.cs b/Tanshu.Accounts.Repository/VoucherBI.cs index 52dd6d1..a8ef557 100644 --- a/Tanshu.Accounts.Repository/VoucherBI.cs +++ b/Tanshu.Accounts.Repository/VoucherBI.cs @@ -9,7 +9,7 @@ using Tanshu.Accounts.Contracts; namespace Tanshu.Accounts.Repository { - public class VoucherBI : UnitOfWork + public partial class VoucherBI : UnitOfWork { public new Guid Insert(Voucher voucher) { @@ -38,30 +38,10 @@ namespace Tanshu.Accounts.Repository } } } - var amount = -1 * voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount)); - VoucherSettlementBI.UpdateSettlements(voucher.Settlements, amount); - foreach (var settlement in voucher.Settlements.Where(x => x.Amount != 0 || x.Settled == SettleOption.Amount)) - { - settlement.Voucher = voucher; - _session.Save(settlement); - } + var options = GetSettlementOptions(voucher); + UpdateSettlements(voucher, options); return addedKot == null ? Guid.Empty : addedKot.KotID; } - public Guid Insert(Voucher voucher, bool updateTable) - { - var kotID = Insert(voucher); - if (updateTable) - { - var table = _session.QueryOver().Where(x => x.FoodTableID == voucher.Table.FoodTableID).SingleOrDefault(); - if (table.VoucherID.HasValue) - throw new ValidationException("A bill exists on this table, cannot overwrite"); - var status = !voucher.Printed ? "running" : "printed"; - table.VoucherID = voucher.VoucherID; - table.Status = status; - _session.Update(table); - } - return kotID; - } public new Guid? Update(Voucher voucher) { _session.Update(voucher); @@ -90,36 +70,10 @@ namespace Tanshu.Accounts.Repository } } UpdateBillType(voucher); - var amount = -1 * voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount)); - VoucherSettlementBI.UpdateSettlements(voucher.Settlements, amount); - foreach (var settlement in voucher.Settlements) - { - settlement.Voucher = voucher; - if (settlement.Amount == 0) - { - if (settlement.VoucherSettlementID != Guid.Empty) - _session.Delete(settlement); - } - else if (settlement.VoucherSettlementID == Guid.Empty) - _session.Save(settlement); - else - _session.Update(settlement); - } + var options = GetSettlementOptions(voucher); + UpdateSettlements(voucher, options); return addedKot == null ? (Guid?)null : addedKot.KotID; } - public Guid? Update(Voucher voucher, bool updateTable) - { - var kotID = Update(voucher); - if (updateTable) - { - var table = _session.QueryOver().Where(x => x.FoodTableID == voucher.Table.FoodTableID).SingleOrDefault(); - var status = !voucher.Printed ? "running" : "printed"; - table.VoucherID = voucher.VoucherID; - table.Status = status; - _session.Update(table); - } - return kotID; - } public new Voucher Get(Expression> query) { var voucher = _session.QueryOver() @@ -148,20 +102,22 @@ namespace Tanshu.Accounts.Repository NHibernateUtil.Initialize(item); return voucher; } - public void VoidBill(Guid voucherID, string reason, bool updateTable) + public void VoidBill(Guid voucherID, string reason) { var voucher = _session.Get(voucherID); voucher.Void = true; voucher.VoidReason = reason; _session.Update(voucher); + } - if (updateTable) - { - var table = _session.QueryOver().Where(x => x.FoodTableID == voucher.Table.FoodTableID).SingleOrDefault(); - table.VoucherID = null; - table.Status = null; - _session.Update(table); - } + public void UpdateTable(Expression> query, Guid? newVoucherID, string status) + { + var table = _session.QueryOver().Where(query).SingleOrDefault(); + if (table == null) + throw new ValidationException("Old Voucher on the table does not match"); + table.Status = status; + table.VoucherID = newVoucherID; + _session.Update(table); } public Guid MergeKot(Guid kotID, string tableName) @@ -197,15 +153,11 @@ namespace Tanshu.Accounts.Repository _session.Update(newVoucher); - var oldTable = _session.QueryOver().Where(x => x.FoodTableID == oldVoucher.Table.FoodTableID).SingleOrDefault(); foreach (var item in oldVoucher.Settlements) { _session.Delete(item); } _session.Delete(oldVoucher); - oldTable.VoucherID = null; - oldTable.Status = null; - _session.Update(oldTable); return newVoucher.VoucherID; } private void UpdateBillType(Voucher voucher) @@ -253,10 +205,6 @@ namespace Tanshu.Accounts.Repository var table = _session.QueryOver().Where(x => x.FoodTableID == tableID).SingleOrDefault(); var newVoucher = new Voucher(Session.User, oldVoucher.Customer, table, oldVoucher.Waiter, false, false, ""); Insert(newVoucher); - table.VoucherID = newVoucher.VoucherID; - table.Status = "running"; - _session.Update(table); - oldVoucher.Kots.Remove(kot); kot.Voucher = newVoucher; @@ -279,20 +227,6 @@ namespace Tanshu.Accounts.Repository Insert(first); Insert(second); Update(oldVoucher); - - var status = oldVoucher.Printed ? "printed" : "running"; - - var tableFirst = _session.QueryOver().Where(x => x.FoodTableID == first.Table.FoodTableID).SingleOrDefault(); - if (tableFirst.VoucherID.HasValue) - throw new ValidationException("A bill exists on this table, cannot overwrite"); - tableFirst.VoucherID = first.VoucherID; - tableFirst.Status = status; - _session.Update(tableFirst); - - var tableSecond = _session.QueryOver().Where(x => x.FoodTableID == second.Table.FoodTableID).SingleOrDefault(); - tableSecond.VoucherID = second.VoucherID; - tableSecond.Status = status; - _session.Update(tableFirst); } public void DiscountPrintedBill(Guid oldVoucherID, Voucher newVoucher) @@ -304,30 +238,13 @@ namespace Tanshu.Accounts.Repository Insert(newVoucher); Update(oldVoucher); - - var table = _session.QueryOver().Where(x => x.FoodTableID == oldVoucher.Table.FoodTableID).SingleOrDefault(); - table.VoucherID = newVoucher.VoucherID; - table.Status = "printed"; - _session.Update(table); } - public Guid Move(Guid oldTableID, Guid newTableID) + public void MoveTable(Guid voucherID, Guid tableID) { - var oldTable = _session.QueryOver().Where(x => x.FoodTableID == oldTableID).SingleOrDefault(); - var newTable = _session.QueryOver().Where(x => x.FoodTableID == newTableID).SingleOrDefault(); - var voucher = _session.Get(oldTable.VoucherID); - - newTable.Status = oldTable.Status; - newTable.VoucherID = oldTable.VoucherID; - - oldTable.Status = null; - oldTable.VoucherID = null; - + var voucher = _session.Get(voucherID); + var newTable = _session.QueryOver().Where(x => x.FoodTableID == tableID).SingleOrDefault(); voucher.Table = newTable; - - _session.Update(newTable); - _session.Update(oldTable); _session.Update(voucher); - return voucher.VoucherID; } } } diff --git a/Tanshu.Accounts.Repository/VoucherSettlementBI.cs b/Tanshu.Accounts.Repository/VoucherSettlementBI.cs index dd8659b..ad66213 100644 --- a/Tanshu.Accounts.Repository/VoucherSettlementBI.cs +++ b/Tanshu.Accounts.Repository/VoucherSettlementBI.cs @@ -8,35 +8,25 @@ using Tanshu.Common.Helpers; namespace Tanshu.Accounts.Repository { - public class VoucherSettlementBI : UnitOfWork + public partial class VoucherBI : UnitOfWork { - public static void UpdateSettlements(IList list, decimal amount) + private IDictionary GetSettlementOptions(Voucher voucher) { - amount = Math.Round(amount, 5); - if (list.Count(x => x.Settled == SettleOption.Amount) == 0) - list.Add(new VoucherSettlement() { Amount = amount, Settled = SettleOption.Amount }); - else - list.Single(x => x.Settled == SettleOption.Amount).Amount = amount; - - var roundoff = Math.Round(amount) - amount; - if (list.Count(x => x.Settled == SettleOption.RoundOff) == 0) - list.Add(new VoucherSettlement() { Amount = roundoff, Settled = SettleOption.RoundOff }); - else - list.Single(x => x.Settled == SettleOption.RoundOff).Amount = roundoff; - - var balance = list.Where(x => x.Settled != SettleOption.Unsettled).Sum(x => x.Amount) * -1; - if (list.Count(x => x.Settled == SettleOption.Unsettled) == 0) + IDictionary options = new Dictionary(); + foreach (var item in voucher.Settlements) { - if (balance != 0) - list.Add(new VoucherSettlement() { Amount = balance, Settled = SettleOption.Unsettled }); + if (item.Settled == SettleOption.Amount || item.Settled == SettleOption.RoundOff || item.Settled == SettleOption.Unsettled) + continue; + if (options.ContainsKey(item.Settled)) + options[item.Settled] += item.Amount; + else + options.Add(item.Settled, item.Amount); } - else - list.Single(x => x.Settled == SettleOption.Unsettled).Amount = balance; + return options; } - public void SettleVoucher(User user, Guid voucherID, IDictionary values) + public void UpdateSettlements(Voucher voucher, IDictionary values) { - var voucher = _session.Get(voucherID); var amount = Math.Round(-1 * voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount)), 5); values.Add(SettleOption.Amount, Math.Round(amount, 5)); var roundoff = Math.Round(amount) - amount; @@ -46,21 +36,6 @@ namespace Tanshu.Accounts.Repository if (unsettled != 0) values.Add(SettleOption.Unsettled, unsettled); - UpdateOld(voucher, values); - AddNew(voucher, values); - - voucher.User = user; - _session.Update(voucher); - - var table = _session.QueryOver() - .Where(x => x.FoodTableID == voucher.Table.FoodTableID && x.VoucherID == voucher.VoucherID) - .SingleOrDefault(); - table.VoucherID = null; - table.Status = null; - _session.Update(table); - } - private void UpdateOld(Voucher voucher, IDictionary values) - { for (var i = voucher.Settlements.Count - 1; i >= 0; i--) { var item = voucher.Settlements[i]; @@ -76,15 +51,21 @@ namespace Tanshu.Accounts.Repository values.Remove(item.Settled); } } - } - private void AddNew(Voucher voucher, IDictionary values) - { foreach (var item in values) { var set = new VoucherSettlement { Settled = item.Key, Amount = item.Value, Voucher = voucher }; voucher.Settlements.Add(set); _session.Save(set); } + + } + + public void SettleVoucher(User user, Guid voucherID, IDictionary values) + { + var voucher = _session.Get(voucherID); + UpdateSettlements(voucher, values); + voucher.User = user; + _session.Update(voucher); } } }