From 51d518d2a02c96f496d96e1d0da2c16557bb19a0 Mon Sep 17 00:00:00 2001 From: tanshu Date: Thu, 31 Mar 2016 12:27:39 +0530 Subject: [PATCH] Major refactor of the Sales Form and Bill controller to make code more readable and less error prone. The functions now only do one thing. --- .../Data Contracts/VoucherBO.cs | 6 +- Tanshu.Accounts.Helpers/SelectCustomer.cs | 102 -------- .../Tanshu.Accounts.Helpers.csproj | 3 - .../Controllers/BillController.cs | 242 ++++++------------ .../Controllers/BillDict.cs | 3 +- .../Controllers/ISaleForm.cs | 6 - Tanshu.Accounts.PointOfSale/MainForm.cs | 2 +- ...m.Designer.cs => CustomerForm.Designer.cs} | 10 +- .../{CustomersForm.cs => CustomerForm.cs} | 11 +- .../{CustomersForm.resx => CustomerForm.resx} | 0 .../Sales/CustomerListForm.Designer.cs | 167 ++++++++++++ .../Sales/CustomerListForm.cs | 74 ++++++ .../Sales/CustomerListForm.resx | 129 ++++++++++ .../Sales/ModifierForm.Designer.cs | 4 +- .../Sales/SalesForm.cs | 221 +++++++++------- .../Tanshu.Accounts.PointOfSale.csproj | 20 +- Tanshu.Accounts.Repository/CustomerBI.cs | 11 +- 17 files changed, 615 insertions(+), 396 deletions(-) delete mode 100644 Tanshu.Accounts.Helpers/SelectCustomer.cs rename Tanshu.Accounts.PointOfSale/Sales/{CustomersForm.Designer.cs => CustomerForm.Designer.cs} (97%) rename Tanshu.Accounts.PointOfSale/Sales/{CustomersForm.cs => CustomerForm.cs} (90%) rename Tanshu.Accounts.PointOfSale/Sales/{CustomersForm.resx => CustomerForm.resx} (100%) create mode 100644 Tanshu.Accounts.PointOfSale/Sales/CustomerListForm.Designer.cs create mode 100644 Tanshu.Accounts.PointOfSale/Sales/CustomerListForm.cs create mode 100644 Tanshu.Accounts.PointOfSale/Sales/CustomerListForm.resx diff --git a/Tanshu.Accounts.Contracts/Data Contracts/VoucherBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/VoucherBO.cs index 147490f..6cb3507 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/VoucherBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/VoucherBO.cs @@ -15,17 +15,17 @@ namespace Tanshu.Accounts.Entities Settlements = new List(); } - public Voucher(User user) + public Voucher(User user, Customer customer) : this() { this.User = user; VoucherType = VoucherType.Regular; + Customer = customer; } public Voucher(User user, Customer customer, FoodTable table, bool printed, bool isVoid, string narration) - : this(user) + : this(user, customer) { - Customer = customer; Table = table; Printed = printed; Void = isVoid; diff --git a/Tanshu.Accounts.Helpers/SelectCustomer.cs b/Tanshu.Accounts.Helpers/SelectCustomer.cs deleted file mode 100644 index 1963408..0000000 --- a/Tanshu.Accounts.Helpers/SelectCustomer.cs +++ /dev/null @@ -1,102 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Windows.Forms; -using Tanshu.Data; -using Tanshu.Accounts.Entities; - -namespace Tanshu.Accounts.Helpers -{ - public class SelectCustomer : Tanshu.Data.BaseSelector - { - public event CustomerEventHandler CustomerEvent; - public SelectCustomer(GetData getData, bool autoClose) : base(getData, true, "List of Products") - { - var filters = new List {"Universal"}; - SetFilterColumns(filters); - grid.Columns["CustomerID"].Visible = false; - } - - protected override void FilterChanged(Dictionary filter) - { - //data = new CustomerBI().GetFilteredCustomers(filter["Universal"].Split(' ')).ToList(); - data = getData(filter); - bindingSource.DataSource = data; - } - protected override void UpdateDisplay(Customer item) - { - DisplayLabel = item == null ? "" : string.Format("Chosen Customer is {0} with phone number {1}", item.Name, item.Phone); - } - - protected override Customer HandleKeydown(object sender, ExtendedKeyEventArgs e) - { - var customer = bindingSource.Current as Customer; - - if (CustomerEvent == null) - { - e.Handled = false; - return customer; - } - Guid? id = null; - if ((customer != null) && (e.KeyCode == Keys.F2)) - id = customer.CustomerID; - - if ((e.KeyCode == Keys.F1) || (e.KeyCode == Keys.F2)) - { - customer = CustomerEvent(sender, new CustomerEventArgs(id, base.filterColumns["Universal"])); - e.Handled = customer != null; - } - return customer; - } - #region Designer Code - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - } - - #endregion - #endregion - } - public delegate Customer CustomerEventHandler(object sender, CustomerEventArgs e); - public class CustomerEventArgs : EventArgs - { - public CustomerEventArgs(Guid? customerID, string phone) - { - CustomerID = customerID; - Phone = phone; - } - public Guid? CustomerID - { - get; - private set; - } - public string Phone - { - get; - private set; - } - } -} diff --git a/Tanshu.Accounts.Helpers/Tanshu.Accounts.Helpers.csproj b/Tanshu.Accounts.Helpers/Tanshu.Accounts.Helpers.csproj index 9c35837..7fb1e4e 100644 --- a/Tanshu.Accounts.Helpers/Tanshu.Accounts.Helpers.csproj +++ b/Tanshu.Accounts.Helpers/Tanshu.Accounts.Helpers.csproj @@ -70,9 +70,6 @@ Form - - Form - diff --git a/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs b/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs index 191bb6a..be11b61 100644 --- a/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs +++ b/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs @@ -13,8 +13,8 @@ namespace Tanshu.Accounts.PointOfSale { public class BillController { - private readonly BillDict _bill; - private Voucher _voucher; + public readonly BillDict _bill; + public Voucher _voucher; private Guid? _editVoucherID; private ISaleForm _saleForm; @@ -22,45 +22,13 @@ namespace Tanshu.Accounts.PointOfSale { this._editVoucherID = editVoucherID; _bill = new BillDict(); - _voucher = new Voucher(Session.User); using (var bi = new CustomerBI()) - _voucher.Customer = bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER); - } - public BillItemValue CurrentProduct - { - get - { - if (_saleForm.BindingSource.Position == -1) - return null; - var item = _bill.ElementAt(_saleForm.BindingSource.Position); - return item.Key.BillItemType != BillItemType.Kot ? item.Value : null; - } - } - public BillItemKey CurrentKey - { - get - { - if (_saleForm.BindingSource.Position == -1) - return null; - var item = _bill.ElementAt(_saleForm.BindingSource.Position); - return item.Key; - } - } - public BillItemKey CurrentKot - { - get - { - if (_saleForm.BindingSource.Position == -1) - return null; - var item = _bill.ElementAt(_saleForm.BindingSource.Position); - return item.Key.BillItemType == BillItemType.Kot ? item.Key : null; - } + _voucher = new Voucher(Session.User, bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER)); } public void InitGui(ISaleForm saleForm) { this._saleForm = saleForm; - this._saleForm.SetCustomerDisplay(_voucher.Customer.Name); this._saleForm.SetUserName(Session.User.Name); } public void AddProduct(Product product) @@ -69,7 +37,6 @@ namespace Tanshu.Accounts.PointOfSale if (_bill.ContainsKey(newKey)) { - _saleForm.BindingSource.CurrencyManager.Position = _bill.IndexOfKey(newKey); _bill[newKey].inventory.Quantity += 1; } else @@ -82,32 +49,20 @@ namespace Tanshu.Accounts.PointOfSale billItemValue.inventory.Price = old.Value.inventory.Price; } _bill.Add(newKey, billItemValue); - _saleForm.BindingSource.DataSource = _bill.ToList(); - _saleForm.BindingSource.CurrencyManager.Position = _saleForm.BindingSource.CurrencyManager.Count - 1; - - using (var bi = new ProductGroupModifierBI()) - if (bi.HasCompulsoryModifier(product.ProductGroup.ProductGroupID)) - { - ShowModifiers(); - } } - ShowAmount(); } - public void ShowModifiers() + + public void ShowModifiers(BillItemValue item) { - var item = CurrentProduct; - if (item == null || CurrentKey.KotID != Guid.Empty) - return; // No Product or Old Product using (var frm = new ModifierForm(Cache.ProductGroupModifiers(item.inventory.Product.ProductGroup.ProductGroupID), item.inventory.InventoryModifier)) { frm.ShowDialog(); } - ShowAmount(); } public void SetDiscount() { if (!Session.IsAllowed("Discount")) - return; // throw new PermissionException("Not Allowed to give Discount"); + return; using (var bi = new ProductGroupBI()) { @@ -119,7 +74,7 @@ namespace Tanshu.Accounts.PointOfSale var discount = frm.Selection(out outList); discount = discount / 100; if (discount > 1 || discount < 0) - return; // throw new ValidationException("Invalid Discount Amount"); + return; foreach (var item in _bill.Where(x => x.Key.BillItemType == BillItemType.Product && outList.Contains(x.Value.inventory.Product.ProductGroup.GroupType))) { @@ -133,12 +88,9 @@ namespace Tanshu.Accounts.PointOfSale } } } - ShowAmount(); } - public void SetQuantity(decimal quantity, bool prompt) + public void SetQuantity(BillItemKey key, BillItemValue item, decimal quantity, bool prompt) { - var item = CurrentProduct; - var key = CurrentKey; if (item == null || key.KotID != Guid.Empty) return; // No Product or Old Product if (prompt && !GetInput("Quantity", ref quantity)) @@ -147,21 +99,14 @@ namespace Tanshu.Accounts.PointOfSale quantity += item.inventory.Quantity; if (quantity < 0 && !Session.IsAllowed("Edit Printed Product")) return; - //TODO: check if he kotid of the item is not null - //var total = quantity + _bill.Where(x => x.Key.ProductID == item.ProductID && x.Key.BillItemType == BillItemType.Product && x.Value.Printed).Sum(x => x.Value.Quantity); - var total = quantity + _bill.Where(x => x.Key.ProductID == key.ProductID && x.Key.BillItemType == key.BillItemType).Sum(x => x.Value.inventory.Quantity); - if (total < 0) - quantity -= total; + var total = quantity + _bill.Where(x => x.Key.ProductID == key.ProductID && x.Key.KotID != Guid.Empty && x.Key.BillItemType == key.BillItemType).Sum(x => x.Value.inventory.Quantity); + quantity = Math.Max(quantity, 0); item.inventory.Quantity = quantity; - ShowAmount(); } - public void SetPrice() + public void SetPrice(BillItemValue item) { - var item = CurrentProduct; - if (item == null) - throw new ValidationException("No Product Selected"); if (!Session.IsAllowed("Change Rate")) - throw new PermissionException("Price Change not Allowed"); + return; var price = item.inventory.Price; if (!GetInput("Price", ref price)) return; @@ -169,46 +114,14 @@ namespace Tanshu.Accounts.PointOfSale throw new PermissionException("NC of Product is not Allowed"); foreach (var sub in _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.ProductID == item.inventory.Product.ProductID)) sub.Value.inventory.Price = price; - - ShowAmount(); } - public void ShowCustomers(bool reset) + public void ShowCustomers() { - if (!reset && ((_voucher.Customer == null) || _voucher.Customer.CustomerID == Constants.CASH_CUSTOMER)) + using (var frm = new CustomerListForm()) { - using (var selectCustomer = new SelectCustomer(CustomerBI.StaticList, true)) - { - selectCustomer.CustomerEvent += selectCustomer_customerEvent; - selectCustomer.ShowDialog(); - if (selectCustomer.SelectedItem != null) - { - _voucher.Customer = selectCustomer.SelectedItem; - } - else - { - using (var bi = new CustomerBI()) - _voucher.Customer = bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER); - } - } + frm.ShowDialog(); + _voucher.Customer = frm.SelectedItem; } - else - { - using (var bi = new CustomerBI()) - _voucher.Customer = bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER); - } - _saleForm.SetCustomerDisplay(_voucher.Customer.Name); - } - private Customer selectCustomer_customerEvent(object sender, CustomerEventArgs e) - { - using (var form = new CustomersForm(e.CustomerID, e.Phone)) - { - form.ShowDialog(); - return form.Customer; - } - } - private void ShowAmount() - { - _saleForm.ShowAmount(_bill.Discount, _bill.NetAmount, _bill.ServiceCharge, _bill.Tax, _bill.Amount, _bill); } private static bool IsPrintedOrVoid(Voucher voucher) { @@ -236,13 +149,10 @@ namespace Tanshu.Accounts.PointOfSale { _voucher = bi.Get(x => x.VoucherID == voucherID); _bill.Clear(); - _saleForm.ShowInfo(_voucher); _bill.Load(_voucher); var newKotKey = new BillItemKey(Guid.Empty); var newKotItem = new BillItemValue(); _bill.Add(newKotKey, newKotItem); - ShowAmount(); - _saleForm.FormState = SaleFormState.Billing; } } public void LoadBill(string tableName) @@ -261,37 +171,37 @@ namespace Tanshu.Accounts.PointOfSale frm.ShowDialog(); _voucher.Table = table; _voucher.Pax = frm.Pax; - _saleForm.ShowInfo(_voucher); } } } - public void CancelBillChanges() + public bool CancelBillChanges() { if (_bill.Any(x => x.Key.BillItemType != BillItemType.Kot) && MessageBox.Show("Abandon Changes?", "Abandon Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No) - return; + return false; ClearBill(); + return true; } public void ClearBill() { - _voucher = new Voucher(Session.User); - ShowCustomers(true); + using (var bi = new CustomerBI()) + _voucher = new Voucher(Session.User, bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER)); _bill.Clear(); var newKotKey = new BillItemKey(Guid.Empty); var newKotItem = new BillItemValue(); _bill.Add(newKotKey, newKotItem); - _saleForm.ClearBill(_bill); } public SaleFormState FormLoad() { - ClearBill(); if (_editVoucherID.HasValue) { FoodTable ft = new FoodTableBI().Get(x => x.VoucherID == _editVoucherID.Value); if (ft == null) + { LoadBill(_editVoucherID.Value); + } else { _editVoucherID = null; @@ -301,10 +211,10 @@ namespace Tanshu.Accounts.PointOfSale } return SaleFormState.Waiting; } - internal void SettleBill() + internal bool SettleBill() { if (_voucher.VoucherID == Guid.Empty || !_voucher.Printed || !Session.IsAllowed("Settle Bill")) - return; + return false; IDictionary options; var amount = -1 * _voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount)); using (var frm = new SettleChoicesForm(Math.Round(amount) * -1, _voucher.VoucherType)) @@ -313,7 +223,7 @@ namespace Tanshu.Accounts.PointOfSale options = frm.OptionsChosen; } if (options.Count == 0) - return; + return false; using (var bi = new VoucherBI()) { bi.SettleVoucher(Session.User, _voucher.VoucherID, options); @@ -322,6 +232,7 @@ namespace Tanshu.Accounts.PointOfSale bi.SaveChanges(); } ClearBill(); + return true; } #region Move Table(s) / Kot(s) @@ -338,11 +249,11 @@ namespace Tanshu.Accounts.PointOfSale return null; } } - internal void MoveKot() + internal void MoveKot(BillItemKey currentKot) { if (_voucher.VoucherID == Guid.Empty || IsPrintedOrVoid(_voucher)) return; - var kot = CurrentKot; + var kot = currentKot; if (kot == null) return; var table = GetTableForMove(true); @@ -368,7 +279,9 @@ namespace Tanshu.Accounts.PointOfSale //Merge Table voucherID = MergeTable(table); if (voucherID != Guid.Empty) + { LoadBill(voucherID); + } } internal void MoveTable() { @@ -439,15 +352,31 @@ namespace Tanshu.Accounts.PointOfSale #endregion #region Save - public void SaveKot() + public bool SaveAndPrintKot() { #region Check if Allowed - if (!Session.IsAllowed("Print Kot")) - return; + if (!Session.IsAllowed("Print Kot") || _bill.Count(x => x.Key.BillItemType == BillItemType.Product) == 0) + return false; + bool isPrinted = false, isVoid = false; + if (_voucher.VoucherID != Guid.Empty) + using (var bi = new VoucherBI()) + { + var dbVoucher = bi.Get(x => x.VoucherID == _voucher.VoucherID); + isPrinted = dbVoucher.Printed; + isVoid = dbVoucher.Void; + } + if (isVoid) + { + MessageBox.Show(string.Format("This Bill is already void.\nReason: {0}", _voucher.VoidReason), "Bill already Voided", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + if (isPrinted) + { + MessageBox.Show(string.Format("This Bill is already printed and a kot cannot be added", _voucher.VoidReason), "Bill already Printed", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } if (_voucher.VoucherID != Guid.Empty && IsPrintedOrVoid(_voucher)) - return; - if (_bill.Count == 1) //new kot only - return; + return false; #endregion //Save @@ -461,15 +390,16 @@ namespace Tanshu.Accounts.PointOfSale if (_editVoucherID.HasValue) _saleForm.CloseWindow(); else + { ClearBill(); + } + return true; } - public void SaveBill() + public bool SaveAndPrintBill() { #region Check if Allowed - if (!Session.IsAllowed("Print Bill")) - return; - if (_bill.Count == 1) //new kot only - return; + if (!Session.IsAllowed("Print Bill") || _bill.Count(x => x.Key.BillItemType == BillItemType.Product) == 0) + return false; bool isPrinted = false, isVoid = false; if (_voucher.VoucherID != Guid.Empty) using (var bi = new VoucherBI()) @@ -481,10 +411,10 @@ namespace Tanshu.Accounts.PointOfSale if (isVoid) { MessageBox.Show(string.Format("This Bill is already void.\nReason: {0}", _voucher.VoidReason), "Bill already Voided", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; + return false; } if (isPrinted && !Session.IsAllowed("Edit Printed Bill")) - return; + return false; #endregion var amount = _bill.NetAmount; @@ -501,15 +431,19 @@ namespace Tanshu.Accounts.PointOfSale { frm.ShowDialog(); if (!frm.Selection.HasValue) - return; + return false; _voucher.VoucherType = frm.Selection.Value; } - var saved = _voucher.VoucherID == Guid.Empty ? InsertVoucher(true, !_editVoucherID.HasValue) : UpdateVoucher(true, !_editVoucherID.HasValue); + if (_voucher.VoucherID == Guid.Empty) + InsertVoucher(true, !_editVoucherID.HasValue); + else + UpdateVoucher(true, !_editVoucherID.HasValue); } Thermal.PrintBill(_voucher.VoucherID); if (_editVoucherID.HasValue) _saleForm.CloseWindow(); ClearBill(); + return true; } public void SplitBill() { @@ -559,9 +493,8 @@ namespace Tanshu.Accounts.PointOfSale return; #region new voucherFirst - var voucherFirst = new Voucher(Session.User) + var voucherFirst = new Voucher(Session.User, _voucher.Customer) { - Customer = _voucher.Customer, Table = table, Printed = isPrinted, Void = false, @@ -575,9 +508,8 @@ namespace Tanshu.Accounts.PointOfSale #endregion #region new voucherSecond - var voucherSecond = new Voucher(Session.User) + var voucherSecond = new Voucher(Session.User, _voucher.Customer) { - Customer = _voucher.Customer, Table = _voucher.Table, Printed = isPrinted, Void = false, @@ -604,36 +536,31 @@ namespace Tanshu.Accounts.PointOfSale } LoadBill(voucherFirst.VoucherID); } - public void VoidBill() + public bool VoidBill() { #region Check conditions and Permissions - if (_voucher.VoucherID == Guid.Empty) - return; - if (_voucher.Void) - return; - if (!Session.IsAllowed("Void Bill")) - return; + if (_voucher.VoucherID == Guid.Empty || _voucher.Void || !Session.IsAllowed("Void Bill")) + return false; if (MessageBox.Show("Are you sure you want to void this bill?", "Void Bill", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes) - return; + return false; #endregion var voidReason = new SelectVoidReason(GetVoidReason, true); voidReason.ShowDialog(); if (voidReason.SelectedItem != null) - { - using (var bi = new VoucherBI()) - { - 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(); - } - else { MessageBox.Show("Please Select a reason if you want to void the bill", "Bill NOT Voided", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); + return false; } + using (var bi = new VoucherBI()) + { + 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(); + return true; } private static List GetVoidReason(Dictionary filter) { @@ -658,9 +585,8 @@ namespace Tanshu.Accounts.PointOfSale if (amountChanged || itemsChanged) // Discount or Products changed { #region new voucherFirst - var newVoucher = new Voucher(Session.User) + var newVoucher = new Voucher(Session.User, _voucher.Customer) { - Customer = _voucher.Customer, Table = _voucher.Table, Printed = true, Void = false, diff --git a/Tanshu.Accounts.PointOfSale/Controllers/BillDict.cs b/Tanshu.Accounts.PointOfSale/Controllers/BillDict.cs index 57da96a..98041b4 100644 --- a/Tanshu.Accounts.PointOfSale/Controllers/BillDict.cs +++ b/Tanshu.Accounts.PointOfSale/Controllers/BillDict.cs @@ -2,6 +2,7 @@ using Tanshu.Accounts.Contracts; using Tanshu.Common; using Tanshu.Accounts.Entities; +using System; namespace Tanshu.Accounts.PointOfSale { @@ -55,7 +56,7 @@ namespace Tanshu.Accounts.PointOfSale { get { - return this.Where(x => x.Key.BillItemType != BillItemType.Kot).Sum(i => i.Value.inventory.Amount); + return Math.Round(this.Where(x => x.Key.BillItemType != BillItemType.Kot).Sum(i => i.Value.inventory.Amount)); } } } diff --git a/Tanshu.Accounts.PointOfSale/Controllers/ISaleForm.cs b/Tanshu.Accounts.PointOfSale/Controllers/ISaleForm.cs index 9a470dd..fa09bbb 100644 --- a/Tanshu.Accounts.PointOfSale/Controllers/ISaleForm.cs +++ b/Tanshu.Accounts.PointOfSale/Controllers/ISaleForm.cs @@ -11,13 +11,7 @@ namespace Tanshu.Accounts.PointOfSale { public interface ISaleForm { - void ClearBill(BillDict bill); - void SetCustomerDisplay(string name); void CloseWindow(); - void ShowAmount(decimal discountAmount, decimal grossAmount, decimal serviceChargeAmount, decimal taxAmount, decimal valueAmount, BillDict bill); - void ShowInfo(Voucher voucher); void SetUserName(string name); - BindingSource BindingSource { get; } - SaleFormState FormState { set; } } } diff --git a/Tanshu.Accounts.PointOfSale/MainForm.cs b/Tanshu.Accounts.PointOfSale/MainForm.cs index 95b566f..d13faf9 100644 --- a/Tanshu.Accounts.PointOfSale/MainForm.cs +++ b/Tanshu.Accounts.PointOfSale/MainForm.cs @@ -55,7 +55,7 @@ namespace Tanshu.Accounts.PointOfSale private void btnCustomer_Click(object sender, EventArgs e) { - using (var frm = new CustomersForm(null, "")) + using (var frm = new CustomerListForm()) frm.ShowDialog(); } diff --git a/Tanshu.Accounts.PointOfSale/Sales/CustomersForm.Designer.cs b/Tanshu.Accounts.PointOfSale/Sales/CustomerForm.Designer.cs similarity index 97% rename from Tanshu.Accounts.PointOfSale/Sales/CustomersForm.Designer.cs rename to Tanshu.Accounts.PointOfSale/Sales/CustomerForm.Designer.cs index b22533f..9d4126c 100644 --- a/Tanshu.Accounts.PointOfSale/Sales/CustomersForm.Designer.cs +++ b/Tanshu.Accounts.PointOfSale/Sales/CustomerForm.Designer.cs @@ -1,6 +1,6 @@  namespace Tanshu.Accounts.PointOfSale { - partial class CustomersForm + partial class CustomerForm { /// /// Required designer variable. @@ -180,7 +180,7 @@ this.txtUniqueID.Text = "UniqueID"; this.txtUniqueID.WordWrap = false; // - // CustomersForm + // CustomerForm // this.AcceptButton = this.btnSave; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -204,10 +204,10 @@ this.Controls.Add(this.txtName); this.MaximizeBox = false; this.MinimizeBox = false; - this.Name = "CustomersForm"; + this.Name = "CustomerForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; - this.Text = "Customers"; - this.Load += new System.EventHandler(this.CustomersForm_Load); + this.Text = "Customer"; + this.Load += new System.EventHandler(this.CustomerForm_Load); this.ResumeLayout(false); this.PerformLayout(); diff --git a/Tanshu.Accounts.PointOfSale/Sales/CustomersForm.cs b/Tanshu.Accounts.PointOfSale/Sales/CustomerForm.cs similarity index 90% rename from Tanshu.Accounts.PointOfSale/Sales/CustomersForm.cs rename to Tanshu.Accounts.PointOfSale/Sales/CustomerForm.cs index 83b3f92..9e243a1 100644 --- a/Tanshu.Accounts.PointOfSale/Sales/CustomersForm.cs +++ b/Tanshu.Accounts.PointOfSale/Sales/CustomerForm.cs @@ -7,19 +7,24 @@ using Tanshu.Accounts.Entities.Auth; namespace Tanshu.Accounts.PointOfSale { - public partial class CustomersForm : Form + public partial class CustomerForm : Form { private Guid? _customerID; private Customer _customer; private readonly string phone; #region Form Load - public CustomersForm(Guid? customerID, string phone) + public CustomerForm(Guid? customerID) + { + InitializeComponent(); + this._customerID = customerID; + } + public CustomerForm(Guid? customerID, string phone) { InitializeComponent(); this._customerID = customerID; this.phone = phone; } - private void CustomersForm_Load(object sender, EventArgs e) + private void CustomerForm_Load(object sender, EventArgs e) { if (_customerID.HasValue) { diff --git a/Tanshu.Accounts.PointOfSale/Sales/CustomersForm.resx b/Tanshu.Accounts.PointOfSale/Sales/CustomerForm.resx similarity index 100% rename from Tanshu.Accounts.PointOfSale/Sales/CustomersForm.resx rename to Tanshu.Accounts.PointOfSale/Sales/CustomerForm.resx diff --git a/Tanshu.Accounts.PointOfSale/Sales/CustomerListForm.Designer.cs b/Tanshu.Accounts.PointOfSale/Sales/CustomerListForm.Designer.cs new file mode 100644 index 0000000..92a0e19 --- /dev/null +++ b/Tanshu.Accounts.PointOfSale/Sales/CustomerListForm.Designer.cs @@ -0,0 +1,167 @@ +namespace Tanshu.Accounts.PointOfSale +{ + partial class CustomerListForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.btnAdd = new System.Windows.Forms.Button(); + this.btnEdit = new System.Windows.Forms.Button(); + this.btnExit = new System.Windows.Forms.Button(); + this.dgvCustomers = new System.Windows.Forms.DataGridView(); + this.nameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.phone = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.address = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.bsList = new System.Windows.Forms.BindingSource(this.components); + ((System.ComponentModel.ISupportInitialize)(this.dgvCustomers)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.bsList)).BeginInit(); + this.SuspendLayout(); + // + // btnAdd + // + this.btnAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnAdd.Location = new System.Drawing.Point(12, 255); + this.btnAdd.Name = "btnAdd"; + this.btnAdd.Size = new System.Drawing.Size(75, 75); + this.btnAdd.TabIndex = 68; + this.btnAdd.Text = "&Add"; + this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click); + // + // btnEdit + // + this.btnEdit.AccessibleName = "Done"; + this.btnEdit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnEdit.Location = new System.Drawing.Point(93, 255); + this.btnEdit.Name = "btnEdit"; + this.btnEdit.Size = new System.Drawing.Size(75, 75); + this.btnEdit.TabIndex = 62; + this.btnEdit.Text = "&Edit"; + this.btnEdit.Click += new System.EventHandler(this.btnEdit_Click); + // + // btnExit + // + this.btnExit.AccessibleName = "Done"; + this.btnExit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnExit.Location = new System.Drawing.Point(575, 255); + this.btnExit.Name = "btnExit"; + this.btnExit.Size = new System.Drawing.Size(75, 75); + this.btnExit.TabIndex = 61; + this.btnExit.Text = "E&xit"; + this.btnExit.Click += new System.EventHandler(this.btnExit_Click); + // + // dgvCustomers + // + this.dgvCustomers.AllowUserToAddRows = false; + this.dgvCustomers.AllowUserToDeleteRows = false; + this.dgvCustomers.AllowUserToResizeRows = false; + this.dgvCustomers.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dgvCustomers.AutoGenerateColumns = false; + this.dgvCustomers.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells; + this.dgvCustomers.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dgvCustomers.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.nameDataGridViewTextBoxColumn, + this.phone, + this.address}); + this.dgvCustomers.DataSource = this.bsList; + this.dgvCustomers.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically; + this.dgvCustomers.Location = new System.Drawing.Point(12, 12); + this.dgvCustomers.MultiSelect = false; + this.dgvCustomers.Name = "dgvCustomers"; + this.dgvCustomers.ReadOnly = true; + this.dgvCustomers.RowHeadersVisible = false; + this.dgvCustomers.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; + this.dgvCustomers.RowTemplate.Height = 24; + this.dgvCustomers.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dgvCustomers.Size = new System.Drawing.Size(638, 237); + this.dgvCustomers.TabIndex = 74; + this.dgvCustomers.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvCustomers_CellDoubleClick); + // + // nameDataGridViewTextBoxColumn + // + this.nameDataGridViewTextBoxColumn.DataPropertyName = "Name"; + this.nameDataGridViewTextBoxColumn.HeaderText = "Name"; + this.nameDataGridViewTextBoxColumn.Name = "nameDataGridViewTextBoxColumn"; + this.nameDataGridViewTextBoxColumn.ReadOnly = true; + this.nameDataGridViewTextBoxColumn.Width = 60; + // + // phone + // + this.phone.DataPropertyName = "Phone"; + this.phone.HeaderText = "Phone"; + this.phone.Name = "phone"; + this.phone.ReadOnly = true; + this.phone.Width = 63; + // + // address + // + this.address.DataPropertyName = "Address"; + this.address.HeaderText = "Address"; + this.address.Name = "address"; + this.address.ReadOnly = true; + this.address.Width = 70; + // + // bsList + // + this.bsList.DataSource = typeof(Tanshu.Accounts.Entities.Customer); + // + // CustomerListForm + // + 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.dgvCustomers); + this.Controls.Add(this.btnAdd); + this.Controls.Add(this.btnEdit); + this.Controls.Add(this.btnExit); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "CustomerListForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Customers"; + this.Load += new System.EventHandler(this.CustomerListForm_Load); + ((System.ComponentModel.ISupportInitialize)(this.dgvCustomers)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.bsList)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + internal System.Windows.Forms.Button btnAdd; + internal System.Windows.Forms.Button btnEdit; + internal System.Windows.Forms.Button btnExit; + private System.Windows.Forms.DataGridView dgvCustomers; + private System.Windows.Forms.BindingSource bsList; + private System.Windows.Forms.DataGridViewTextBoxColumn Password; + private System.Windows.Forms.DataGridViewTextBoxColumn CustomerGroups; + private System.Windows.Forms.DataGridViewTextBoxColumn nameDataGridViewTextBoxColumn; + private System.Windows.Forms.DataGridViewTextBoxColumn phone; + private System.Windows.Forms.DataGridViewTextBoxColumn address; + } +} \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Sales/CustomerListForm.cs b/Tanshu.Accounts.PointOfSale/Sales/CustomerListForm.cs new file mode 100644 index 0000000..2658b6d --- /dev/null +++ b/Tanshu.Accounts.PointOfSale/Sales/CustomerListForm.cs @@ -0,0 +1,74 @@ +using System; +using System.Linq; +using System.Windows.Forms; +using Tanshu.Accounts.Entities; +using Tanshu.Accounts.Repository; +using System.Collections.Generic; +using Tanshu.Accounts.Entities.Auth; +using Tanshu.Accounts.Contracts; + +namespace Tanshu.Accounts.PointOfSale +{ + public partial class CustomerListForm : Form + { + private IList _list; + public CustomerListForm() + { + InitializeComponent(); + } + + private void btnAdd_Click(object sender, EventArgs e) + { + using (var frm = new CustomerForm(null)) + frm.ShowDialog(); + using (var bi = new CustomerBI()) + _list = bi.List(); + bsList.DataSource = _list; + } + + private void CustomerListForm_Load(object sender, EventArgs e) + { + ShowGrid(); + } + private void ShowGrid() + { + using (var bi = new CustomerBI()) + _list = bi.List(); + bsList.DataSource = _list; + } + + private void btnEdit_Click(object sender, EventArgs e) + { + var id = ((Customer)bsList.Current).CustomerID; + using (var frm = new CustomerForm(id)) + frm.ShowDialog(); + using (var bi = new CustomerBI()) + _list = bi.List(); + bsList.DataSource = _list; + } + + private void btnExit_Click(object sender, EventArgs e) + { + this.Close(); + } + + public Customer SelectedItem + { + get + { + if (bsList.Position >= 0) + { + var item = _list[bsList.Position]; + if (item != null) + return item; + } + return _list.First(x => x.CustomerID == Constants.CASH_CUSTOMER); + } + } + + private void dgvCustomers_CellDoubleClick(object sender, DataGridViewCellEventArgs e) + { + this.Close(); + } + } +} diff --git a/Tanshu.Accounts.PointOfSale/Sales/CustomerListForm.resx b/Tanshu.Accounts.PointOfSale/Sales/CustomerListForm.resx new file mode 100644 index 0000000..fb167e2 --- /dev/null +++ b/Tanshu.Accounts.PointOfSale/Sales/CustomerListForm.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + 17, 17 + + \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Sales/ModifierForm.Designer.cs b/Tanshu.Accounts.PointOfSale/Sales/ModifierForm.Designer.cs index be5964e..acb57ff 100644 --- a/Tanshu.Accounts.PointOfSale/Sales/ModifierForm.Designer.cs +++ b/Tanshu.Accounts.PointOfSale/Sales/ModifierForm.Designer.cs @@ -44,7 +44,8 @@ // btnClose // this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); this.btnClose.Location = new System.Drawing.Point(3, 3); + | System.Windows.Forms.AnchorStyles.Right))); + this.btnClose.Location = new System.Drawing.Point(3, 3); this.btnClose.Name = "btnClose"; this.btnClose.Size = new System.Drawing.Size(480, 75); this.btnClose.TabIndex = 7; @@ -66,6 +67,7 @@ this.Text = "Modifier"; this.Load += new System.EventHandler(this.ModifierForm_Load); this.ResumeLayout(false); + } #endregion diff --git a/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs b/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs index 184aa2e..df20d88 100644 --- a/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs +++ b/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs @@ -27,17 +27,15 @@ namespace Tanshu.Accounts.PointOfSale.Sales Text = name; } - public void SetCustomerDisplay(string name) - { - btnCustomer.Text = name; - } - - public void ShowInfo(Voucher voucher) + private void ShowInfo(Voucher voucher, BillDict bill) { if (voucher.VoucherID == Guid.Empty) { - txtTableID.Text = voucher.Table.Name; - txtPax.Text = voucher.Pax.ToString(); + txtBillID.Text = ""; + txtKotID.Text = ""; + txtCreationDate.Text = ""; + txtDate.Text = ""; + txtLastEditDate.Text = ""; } else { @@ -46,15 +44,52 @@ namespace Tanshu.Accounts.PointOfSale.Sales txtCreationDate.Text = voucher.CreationDate.ToString("HH:mm dd-MMM-yyyy"); txtDate.Text = voucher.Date.ToString("HH:mm dd-MMM-yyyy"); txtLastEditDate.Text = voucher.LastEditDate.ToString("HH:mm dd-MMM-yyyy"); - btnCustomer.Text = voucher.Customer.Name; - txtTableID.Text = voucher.Table.Name; - txtPax.Text = voucher.Pax.ToString(); + } + btnCustomer.Text = voucher.Customer.Name; + txtTableID.Text = voucher.Table == null ? "" : voucher.Table.Name; + txtPax.Text = voucher.Pax.ToString(); + bindingSource.CurrencyManager.Position = Math.Min(bindingSource.CurrencyManager.Position, bill.Count - 1); + txtGrossTax.Text = string.Format("{0:#0.00}", bill.Tax); + txtDiscount.Text = string.Format("{0:#0.00}", bill.Discount); + txtServiceCharge.Text = string.Format("{0:#0.00}", bill.ServiceCharge); + txtGrossAmount.Text = string.Format("{0:#0.00}", bill.NetAmount); + txtAmount.Text = string.Format("{0:#0.00}", bill.Amount); + bindingSource.DataSource = bill.ToList(); + dgvProducts.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells); + MoreButton(false); + } + + public BillItemValue CurrentProduct + { + get + { + if (bindingSource.Position == -1) + return null; + var item = _billController._bill.ElementAt(bindingSource.Position); + return item.Key.BillItemType != BillItemType.Kot ? item.Value : null; } } - public BindingSource BindingSource + public BillItemKey CurrentKey { - get { return bindingSource; } + get + { + if (bindingSource.Position == -1) + return null; + var item = _billController._bill.ElementAt(bindingSource.Position); + return item.Key; + } + } + + public BillItemKey CurrentKot + { + get + { + if (bindingSource.Position == -1) + return null; + var item = _billController._bill.ElementAt(bindingSource.Position); + return item.Key.BillItemType == BillItemType.Kot ? item.Key : null; + } } public void CloseWindow() @@ -81,22 +116,17 @@ namespace Tanshu.Accounts.PointOfSale.Sales case Keys.F4: { if (!e.Alt) - _billController.ShowCustomers(false); - break; - } - case Keys.F7: - { - //using (var selectProduct = new SelectProduct(ProductBI.GetFilteredProducts, true)) - //{ - // selectProduct.ShowDialog(); - // if (selectProduct.SelectedItem != null) - // _billController.AddProduct(selectProduct.SelectedItem.ProductID); - //} + { + _billController.ShowCustomers(); + ShowInfo(_billController._voucher, _billController._bill); + } break; } case Keys.F8: { _billController.LoadBill(null); + ShowInfo(_billController._voucher, _billController._bill); + FormState = SaleFormState.Billing; break; } case Keys.F11: @@ -111,18 +141,20 @@ namespace Tanshu.Accounts.PointOfSale.Sales } case Keys.Delete: { - _billController.SetQuantity(-1, false); - //_billController.ProductRemove(); + _billController.SetQuantity(CurrentKey, CurrentProduct, -1, false); + ShowInfo(_billController._voucher, _billController._bill); break; } case Keys.Add: { - _billController.SetQuantity(1, false); + _billController.SetQuantity(CurrentKey, CurrentProduct, 1, false); + ShowInfo(_billController._voucher, _billController._bill); break; } case Keys.Subtract: { - _billController.SetQuantity(-1, false); + _billController.SetQuantity(CurrentKey, CurrentProduct, -1, false); + ShowInfo(_billController._voucher, _billController._bill); break; } case Keys.Up: @@ -139,7 +171,10 @@ namespace Tanshu.Accounts.PointOfSale.Sales } case Keys.Escape: { - _billController.CancelBillChanges(); + var canceled = _billController.CancelBillChanges(); + ShowInfo(_billController._voucher, _billController._bill); + if (canceled) + FormState = SaleFormState.Waiting; break; } } @@ -153,43 +188,41 @@ namespace Tanshu.Accounts.PointOfSale.Sales txtServiceCharge.Visible = showSC; lblServiceCharge.Visible = showSC; } - _billController.FormLoad(); - FormState = SaleFormState.Waiting; + _billController.ClearBill(); + var state = _billController.FormLoad(); + ShowInfo(_billController._voucher, _billController._bill); + FormState = state; } private void btnCustomer_Click(object sender, EventArgs e) { - _billController.ShowCustomers(false); + _billController.ShowCustomers(); + ShowInfo(_billController._voucher, _billController._bill); } private void btnVoid_Click(object sender, EventArgs e) { - try - { - _billController.VoidBill(); - } - catch (PermissionException ex) - { - MessageBox.Show(ex.Message); - } + var voided = _billController.VoidBill(); + ShowInfo(_billController._voucher, _billController._bill); + if (voided) + FormState = SaleFormState.Waiting; } private void btnPrice_Click(object sender, EventArgs e) { - try - { - _billController.SetPrice(); - } - catch (Exception ex) - { - if (!(ex is ValidationException) && !(ex is PermissionException)) - throw; - } + var item = CurrentProduct; + if (item == null) + return; + _billController.SetPrice(CurrentProduct); + ShowInfo(_billController._voucher, _billController._bill); } private void btnClear_Click(object sender, EventArgs e) { - _billController.CancelBillChanges(); + var canceled = _billController.CancelBillChanges(); + ShowInfo(_billController._voucher, _billController._bill); + if (canceled) + FormState = SaleFormState.Waiting; } private void dgvProducts_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) @@ -225,22 +258,32 @@ namespace Tanshu.Accounts.PointOfSale.Sales private void btnSettle_Click(object sender, EventArgs e) { - _billController.SettleBill(); + var settled = _billController.SettleBill(); + ShowInfo(_billController._voucher, _billController._bill); + if (settled) + FormState = SaleFormState.Waiting; } private void btnModifier_Click(object sender, EventArgs e) { - _billController.ShowModifiers(); + var item = CurrentProduct; + if (item == null || CurrentKey.KotID != Guid.Empty) + return; // No Product or Old Product + + _billController.ShowModifiers(item); + ShowInfo(_billController._voucher, _billController._bill); } private void btnDelete_Click(object sender, EventArgs e) { - _billController.SetQuantity(-1, false); + _billController.SetQuantity(CurrentKey, CurrentProduct, -1, false); + ShowInfo(_billController._voucher, _billController._bill); } private void btnMoveTable_Click(object sender, EventArgs e) { _billController.MoveTable(); + ShowInfo(_billController._voucher, _billController._bill); } private void btnMore_Click(object sender, EventArgs e) @@ -272,44 +315,13 @@ namespace Tanshu.Accounts.PointOfSale.Sales private void btnMoveKot_Click(object sender, EventArgs e) { - _billController.MoveKot(); + _billController.MoveKot(CurrentKot); + ShowInfo(_billController._voucher, _billController._bill); } #region Helper Functions - public void ClearBill(BillDict bill) - { - txtBillID.Text = ""; - txtKotID.Text = ""; - txtCreationDate.Text = ""; - txtDate.Text = ""; - txtLastEditDate.Text = ""; - txtTableID.Text = ""; - txtPax.Text = ""; - txtGrossTax.Text = "0.00"; - txtDiscount.Text = "0.00"; - txtServiceCharge.Text = "0.00"; - txtGrossAmount.Text = "0.00"; - txtAmount.Text = "0.00"; - bindingSource.CurrencyManager.Position = 0; //Hack for Mono - bindingSource.DataSource = bill; - MoreButton(false); - FormState = SaleFormState.Waiting; - } - - public void ShowAmount(decimal discountAmount, decimal grossAmount, decimal serviceChargeAmount, - decimal taxAmount, decimal valueAmount, BillDict bill) - { - txtGrossTax.Text = string.Format("{0:#0.00}", taxAmount); - txtDiscount.Text = string.Format("{0:#0.00}", discountAmount); - txtServiceCharge.Text = string.Format("{0:#0.00}", serviceChargeAmount); - txtGrossAmount.Text = string.Format("{0:#0.00}", grossAmount); - txtAmount.Text = string.Format("{0:#0.00}", Math.Round(valueAmount)); - bindingSource.DataSource = bill.ToList(); - dgvProducts.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells); - } - - public SaleFormState FormState + private SaleFormState FormState { set { @@ -356,6 +368,15 @@ namespace Tanshu.Accounts.PointOfSale.Sales if (item.IsNotAvailable) return; _billController.AddProduct(item); + bindingSource.DataSource = _billController._bill.ToList(); + bindingSource.CurrencyManager.Position = _billController._bill.IndexOfKey(new BillItemKey(item.ProductID, Guid.Empty)); + + var showModifier = false; + using (var bi = new ProductGroupModifierBI()) + showModifier = bi.HasCompulsoryModifier(CurrentProduct.inventory.Product.ProductGroup.ProductGroupID); + if (showModifier) + _billController.ShowModifiers(CurrentProduct); + ShowInfo(_billController._voucher, _billController._bill); } private void productPage_Click(object sender, EventArgs e) @@ -378,6 +399,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales var item = button.Tag as FoodTable; var tableName = item.Name; _billController.LoadBill(tableName); + ShowInfo(_billController._voucher, _billController._bill); FormState = SaleFormState.Billing; } @@ -394,30 +416,30 @@ namespace Tanshu.Accounts.PointOfSale.Sales } private void btnPrintBill_Click(object sender, EventArgs e) { - _billController.SaveBill(); + var printed = _billController.SaveAndPrintBill(); + ShowInfo(_billController._voucher, _billController._bill); + if (printed) + FormState = SaleFormState.Waiting; } private void btnPrintKot_Click(object sender, EventArgs e) { - _billController.SaveKot(); + var printed = _billController.SaveAndPrintKot(); + ShowInfo(_billController._voucher, _billController._bill); + if (printed) + FormState = SaleFormState.Waiting; } private void btnQuantity_Click(object sender, EventArgs e) { - _billController.SetQuantity(0, true); + _billController.SetQuantity(CurrentKey, CurrentProduct, 0, true); + ShowInfo(_billController._voucher, _billController._bill); } private void btnDiscount_Click(object sender, EventArgs e) { - try - { - _billController.SetDiscount(); - } - catch (Exception ex) - { - if (!(ex is ValidationException) && !(ex is PermissionException)) - throw; - } + _billController.SetDiscount(); + ShowInfo(_billController._voucher, _billController._bill); } #endregion @@ -425,6 +447,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales private void btnSplitBill_Click(object sender, EventArgs e) { _billController.SplitBill(); + ShowInfo(_billController._voucher, _billController._bill); } } } \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj b/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj index 83513b6..1bf9403 100644 --- a/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj +++ b/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj @@ -195,6 +195,12 @@ ReorderTableForm.cs + + Form + + + CustomerListForm.cs + Form @@ -256,11 +262,11 @@ CheckoutForm.cs - + Form - - CustomersForm.cs + + CustomerForm.cs Form @@ -372,6 +378,10 @@ ReorderTableForm.cs + + CustomerListForm.cs + Designer + VoucherTypeForm.cs @@ -405,8 +415,8 @@ CheckoutForm.cs Designer - - CustomersForm.cs + + CustomerForm.cs Designer diff --git a/Tanshu.Accounts.Repository/CustomerBI.cs b/Tanshu.Accounts.Repository/CustomerBI.cs index 6c961fc..53dedbf 100644 --- a/Tanshu.Accounts.Repository/CustomerBI.cs +++ b/Tanshu.Accounts.Repository/CustomerBI.cs @@ -7,18 +7,11 @@ namespace Tanshu.Accounts.Repository { public class CustomerBI : UnitOfWork { - public IList List(Dictionary filter) + public new IList List() { return _session.QueryOver() - .WhereRestrictionOn(x => x.Name).IsLike(string.Format("%{0}%", filter["Universal"])) + .OrderBy(x => x.Name).Asc .List(); } - public static IList StaticList(Dictionary filter) - { - using (var bi = new CustomerBI()) - { - return bi.List(filter); - } - } } }