diff --git a/Tanshu.Accounts.Contracts/Data Contracts Display/BillInventoryBO.cs b/Tanshu.Accounts.Contracts/Data Contracts Display/BillInventoryBO.cs index f39fa2c..b4b328d 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts Display/BillInventoryBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts Display/BillInventoryBO.cs @@ -6,163 +6,61 @@ namespace Tanshu.Accounts.Contracts { public class BillItemValue { - public Guid ProductID { get; set; } - public string Name { get; set; } - public decimal Price { get; set; } - public decimal FullPrice { get; set; } - public decimal Quantity { get; set; } - private decimal _discount; - public Product Product { get; private set; } - public bool IsKot { get; private set; } - public decimal Discount - { - get { return _discount; } - set - { - if (value < 0) - throw new ArgumentException("Discount has to be non-negative greater than or equal to zero."); - if (value > 1) - throw new ArgumentException("Discount has to be less than one."); - _discount = value; - } - } - - public bool IsScTaxable { get; set; } - - public Tax ServiceTax { get; set; } - public decimal ServiceTaxRate { get; set; } - public decimal ServiceTaxAmount - { - get - { - if (IsScTaxable) - return Quantity * Price * (1 - Discount) * (1 + ServiceCharge) * ServiceTaxRate; - return Quantity * Price * (1 - Discount) * ServiceTaxRate; - } - } - - public Tax Vat { get; set; } - public decimal VatRate { get; set; } - public decimal VatAmount - { - get - { - if (IsScTaxable) - return Quantity * Price * (1 - Discount) * (1 + ServiceCharge) * VatRate; - return Quantity * Price * (1 - Discount) * VatRate; - } - } - - public decimal ServiceCharge { get; set; } - public decimal ServiceChargeAmount - { - get - { - return Quantity * Price * (1 - Discount) * ServiceCharge; - } - } - - public decimal DiscountAmount - { - get - { - return Quantity * Price * Discount; - } - } - - public decimal GrossAmount - { - get - { - return Quantity * Price * (1 - Discount); - } - } - - public bool Printed { get; set; } - - public decimal Value - { - get - { - if (IsScTaxable) - return Quantity * Price * (1 - Discount) * (1 + ServiceCharge) * (1 + ServiceTaxRate + VatRate); - return Quantity * Price * (1 - Discount) * (1 + ServiceCharge + ServiceTaxRate + VatRate); - } - } + public Inventory inventory { get; set; } + public Kot kot { get; private set; } public string Display { get { - var output = string.Format("{0} @ Rs. {1:#.##}", Name, Price); - if (_discount != 0) - output += string.Format(" - {0:#.##%}", _discount); - if (Modifiers != null) - foreach (var item in Modifiers) - output += string.Format("\n\r -- {0}", item.Name); - return output; - - //if (Price == 0) - // return string.Format(" -- {0}", Name); - //string output = string.Format("{0} @ Rs. {1:#.##}", Name, Price); - //if (discount != 0) - // output += string.Format(" - {0:#.##%}", discount); - //return output; + if (inventory != null) + { + var output = string.Format("{0} @ Rs. {1:#.##}", inventory.Product.FullName, inventory.Price); + if (inventory.Discount != 0) + output += string.Format(" - {0:#.##%}", inventory.Discount); + foreach (var item in inventory.InventoryModifier) + output += string.Format("\n\r -- {0}", item.Modifier.Name); + return output; + } + else if (kot.KotID != Guid.Empty) + { + return string.Format("Kot: S-{0} / {1:dd-MMM HH:mm} ({2})", kot.Code, kot.Date, kot.User.Name); + } + else + { + return "== New Kot =="; + } } } - public override string ToString() + public BillItemValue(Inventory inv) { - return string.Format("{0} - {1}", ProductID, Name); + inventory = inv; } - public IList Modifiers { get; set; } public BillItemValue(Product product) { - Modifiers = new List(); - if (product != null) + inventory = new Inventory() { - Product = product; - ProductID = product.ProductID; - Name = product.Units == string.Empty ? product.Name : product.Name + " (" + product.Units + ")"; - Quantity = 1; - Price = product.Price; - FullPrice = product.FullPrice; - IsScTaxable = product.IsScTaxable; - ServiceTax = product.ServiceTax; - Vat = product.Vat; - ServiceTaxRate = product.ServiceTax.Rate; - VatRate = product.Vat.Rate; - ServiceCharge = product.ServiceCharge; - Discount = 0; - Printed = false; - IsKot = false; - } + Product = product, + FullPrice = product.FullPrice, + Price = product.Price, + IsScTaxable = product.IsScTaxable, + Quantity = 1, + ServiceCharge = product.ServiceCharge, + ServiceTax = product.ServiceTax, + Vat = product.Vat, + Discount = 0, + ServiceTaxRate = product.ServiceTax.Rate, + VatRate = product.Vat.Rate + }; } public BillItemValue() { - Product = null; - ProductID = Guid.Empty; - Discount = 0; - Name = "== New Kot =="; - Price = 0; - FullPrice = 0; - Printed = true; - Quantity = 0; - ServiceCharge = 0; - IsKot = true; + this.kot = new Kot(); } public BillItemValue(Kot kot) { - Product = null; - ProductID = kot.KotID; - Discount = 0; - Name = string.Format("Kot: S-{0} / {1:dd-MMM HH:mm} ({2})", kot.Code, kot.Date, kot.User.Name); - Price = 0; - FullPrice = 0; - Printed = true; - Quantity = 0; - ServiceCharge = 0; - IsKot = true; + this.kot = kot; } } diff --git a/Tanshu.Accounts.Contracts/Data Contracts/InventoryBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/InventoryBO.cs index dbe28bb..1133e34 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/InventoryBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/InventoryBO.cs @@ -41,6 +41,50 @@ namespace Tanshu.Accounts.Entities } set { } } + + public virtual decimal ServiceTaxAmount + { + get + { + if (IsScTaxable) + return Quantity * Price * (1 - Discount) * (1 + ServiceCharge) * ServiceTaxRate; + return Quantity * Price * (1 - Discount) * ServiceTaxRate; + } + } + + public virtual decimal VatAmount + { + get + { + if (IsScTaxable) + return Quantity * Price * (1 - Discount) * (1 + ServiceCharge) * VatRate; + return Quantity * Price * (1 - Discount) * VatRate; + } + } + + public virtual decimal ServiceChargeAmount + { + get + { + return Quantity * Price * (1 - Discount) * ServiceCharge; + } + } + + public virtual decimal DiscountAmount + { + get + { + return Quantity * Price * Discount; + } + } + + public virtual decimal Net + { + get + { + return Quantity * Price * (1 - Discount); + } + } } public class InventoryMap : ClassMapping { diff --git a/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs b/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs index a14b7b0..191bb6a 100644 --- a/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs +++ b/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs @@ -33,7 +33,17 @@ namespace Tanshu.Accounts.PointOfSale if (_saleForm.BindingSource.Position == -1) return null; var item = _bill.ElementAt(_saleForm.BindingSource.Position); - return item.Key.BillItemType == BillItemType.Product ? item.Value : null; + 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 @@ -60,7 +70,7 @@ namespace Tanshu.Accounts.PointOfSale if (_bill.ContainsKey(newKey)) { _saleForm.BindingSource.CurrencyManager.Position = _bill.IndexOfKey(newKey); - _bill[newKey].Quantity += 1; + _bill[newKey].inventory.Quantity += 1; } else { @@ -68,30 +78,29 @@ namespace Tanshu.Accounts.PointOfSale var old = _bill.FirstOrDefault(x => x.Key.BillItemType == BillItemType.Product && x.Key.ProductID == newKey.ProductID); if (old.Key != null) { - billItemValue.Discount = old.Value.Discount; - billItemValue.Price = old.Value.Price; + billItemValue.inventory.Discount = old.Value.inventory.Discount; + billItemValue.inventory.Price = old.Value.inventory.Price; } _bill.Add(newKey, billItemValue); - _saleForm.BindingSource.DataSource = _bill.Values.ToList(); + _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)) { - var item = CurrentProduct; - ShowModifiers(item); + ShowModifiers(); } } ShowAmount(); } - public void ShowModifiers(BillItemValue item) + public void ShowModifiers() { - if (item.Printed) - return; - using (var frm = new ModifierForm(Cache.ProductGroupModifiers(item.Product.ProductGroup.ProductGroupID), item.Modifiers)) + 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(); - item.Modifiers = frm.Selection; } ShowAmount(); } @@ -112,14 +121,14 @@ namespace Tanshu.Accounts.PointOfSale if (discount > 1 || discount < 0) 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))) + foreach (var item in _bill.Where(x => x.Key.BillItemType == BillItemType.Product && outList.Contains(x.Value.inventory.Product.ProductGroup.GroupType))) { - var product = item.Value.Product; + var product = item.Value.inventory.Product; var maxDiscount = product.ProductGroup.DiscountLimit; - if (discount > item.Value.Product.ProductGroup.DiscountLimit) + if (discount > item.Value.inventory.Product.ProductGroup.DiscountLimit) MessageBox.Show(string.Format("Maximum discount for {0} is {1:P}", product.Name, maxDiscount), "Excessive Discount", MessageBoxButtons.OK, MessageBoxIcon.Warning); - item.Value.Discount = discount; + item.Value.inventory.Discount = discount; } } } @@ -129,36 +138,37 @@ namespace Tanshu.Accounts.PointOfSale public void SetQuantity(decimal quantity, bool prompt) { var item = CurrentProduct; - if (!Allowed(item)) - return; - if (item.Printed) - return; + var key = CurrentKey; + if (item == null || key.KotID != Guid.Empty) + return; // No Product or Old Product if (prompt && !GetInput("Quantity", ref quantity)) return; if (!prompt) - quantity += item.Quantity; + quantity += item.inventory.Quantity; if (quantity < 0 && !Session.IsAllowed("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); + //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; - item.Quantity = quantity; + item.inventory.Quantity = quantity; ShowAmount(); } - public void SetRate() + public void SetPrice() { var item = CurrentProduct; if (item == null) throw new ValidationException("No Product Selected"); if (!Session.IsAllowed("Change Rate")) - throw new PermissionException("Rate Change not Allowed"); - var rate = item.Price; - if (!GetInput("Price", ref rate)) + throw new PermissionException("Price Change not Allowed"); + var price = item.inventory.Price; + if (!GetInput("Price", ref price)) return; - if (rate == 0 && !Session.IsAllowed("NC Product")) + if (price == 0 && !Session.IsAllowed("NC Product")) 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.ProductID)) - sub.Value.Price = rate; + 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(); } @@ -198,26 +208,7 @@ namespace Tanshu.Accounts.PointOfSale } private void ShowAmount() { - var taxAmount = _bill.Values.Sum(b => b.ServiceTaxAmount + b.VatAmount); - var discountAmount = _bill.Values.Sum(b => b.DiscountAmount); - var grossAmount = _bill.Values.Sum(b => b.GrossAmount); - var valueAmount = _bill.Values.Sum(b => b.Value); - var serviceChargeAmount = _bill.Values.Sum(b => b.ServiceChargeAmount); - _saleForm.ShowAmount(discountAmount, grossAmount, serviceChargeAmount, taxAmount, valueAmount, - _bill.Values.ToList()); - } - 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()) - { - var dbVoucher = bi.Get(x => x.VoucherID == voucher.VoucherID); - isPrinted = dbVoucher.Printed; - isVoid = dbVoucher.Void; - } + _saleForm.ShowAmount(_bill.Discount, _bill.NetAmount, _bill.ServiceCharge, _bill.Tax, _bill.Amount, _bill); } private static bool IsPrintedOrVoid(Voucher voucher) { @@ -277,7 +268,7 @@ namespace Tanshu.Accounts.PointOfSale public void CancelBillChanges() { - if (_bill.Values.Any(i => i.Printed == false) && + if (_bill.Any(x => x.Key.BillItemType != BillItemType.Kot) && MessageBox.Show("Abandon Changes?", "Abandon Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No) return; @@ -291,7 +282,7 @@ namespace Tanshu.Accounts.PointOfSale var newKotKey = new BillItemKey(Guid.Empty); var newKotItem = new BillItemValue(); _bill.Add(newKotKey, newKotItem); - _saleForm.ClearBill(_bill.Values.ToList()); + _saleForm.ClearBill(_bill); } public SaleFormState FormLoad() { @@ -312,11 +303,7 @@ namespace Tanshu.Accounts.PointOfSale } internal void SettleBill() { - if (_voucher.VoucherID == Guid.Empty) - return; - if (!_voucher.Printed) - return; - if (!Session.IsAllowed("Settle Bill")) + if (_voucher.VoucherID == Guid.Empty || !_voucher.Printed || !Session.IsAllowed("Settle Bill")) return; IDictionary options; var amount = -1 * _voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount)); @@ -353,9 +340,7 @@ namespace Tanshu.Accounts.PointOfSale } internal void MoveKot() { - if (_voucher.VoucherID == Guid.Empty) - return; - if (IsPrintedOrVoid(_voucher)) + if (_voucher.VoucherID == Guid.Empty || IsPrintedOrVoid(_voucher)) return; var kot = CurrentKot; if (kot == null) @@ -487,7 +472,12 @@ namespace Tanshu.Accounts.PointOfSale return; bool isPrinted = false, isVoid = false; if (_voucher.VoucherID != Guid.Empty) - IsPrintedOrVoid(_voucher, out isPrinted, out isVoid); + 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); @@ -497,7 +487,8 @@ namespace Tanshu.Accounts.PointOfSale return; #endregion - var amount = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != Guid.Empty).Sum(x => x.Value.GrossAmount); + var amount = _bill.NetAmount; + SetDiscount(); if (isPrinted) { @@ -556,8 +547,8 @@ namespace Tanshu.Accounts.PointOfSale if (splitList == null || splitList.Count == 0) return; - var listFirst = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != Guid.Empty && splitList.Contains(x.Value.Product.ProductGroup.GroupType)); - var listSecond = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != Guid.Empty && !splitList.Contains(x.Value.Product.ProductGroup.GroupType)); + var listFirst = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != Guid.Empty && splitList.Contains(x.Value.inventory.Product.ProductGroup.GroupType)); + var listSecond = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != Guid.Empty && !splitList.Contains(x.Value.inventory.Product.ProductGroup.GroupType)); if (listFirst.Count() == 0 || listSecond.Count() == 0) return; // all or none items selected to be moved @@ -661,8 +652,9 @@ namespace Tanshu.Accounts.PointOfSale } private void SaveReprintOrDiscountBill(decimal oldAmount) { - var amountChanged = oldAmount != _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != Guid.Empty).Sum(x => x.Value.GrossAmount); + var amountChanged = oldAmount != _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != Guid.Empty).Sum(x => x.Value.inventory.Net); var itemsChanged = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID == Guid.Empty).Count() != 0; + if (amountChanged || itemsChanged) // Discount or Products changed { #region new voucherFirst @@ -704,7 +696,7 @@ namespace Tanshu.Accounts.PointOfSale _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)); + var kot = GetKot(_bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID == Guid.Empty && x.Value.inventory.Quantity != 0)); if (kot == null) return null; _voucher.Kots.Add(kot); @@ -732,12 +724,12 @@ namespace Tanshu.Accounts.PointOfSale 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; + i.Discount = item.Value.inventory.Discount; + i.Price = item.Value.inventory.Price; } if (!_voucher.Printed) { - var kot = GetKot(_bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID == Guid.Empty && x.Value.Quantity != 0)); + var kot = GetKot(_bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID == Guid.Empty && x.Value.inventory.Quantity != 0)); if (kot != null) voucher.Kots.Add(kot); } @@ -760,7 +752,7 @@ namespace Tanshu.Accounts.PointOfSale var oldInv = kot.Inventories.SingleOrDefault(x => x.Product.ProductID == item.Key.ProductID); if (oldInv != null) { - oldInv.Quantity += item.Value.Quantity; + oldInv.Quantity += item.Value.inventory.Quantity; if (oldInv.Quantity == 0) kot.Inventories.Remove(oldInv); } @@ -768,20 +760,20 @@ namespace Tanshu.Accounts.PointOfSale { var inv = new Inventory { - Product = item.Value.Product, - Quantity = item.Value.Quantity, - Price = item.Value.Price, - FullPrice = item.Value.FullPrice, - Discount = item.Value.Discount, - ServiceCharge = item.Value.ServiceCharge, - IsScTaxable = item.Value.IsScTaxable, - ServiceTaxRate = item.Value.ServiceTaxRate, - VatRate = item.Value.VatRate, - ServiceTax = item.Value.ServiceTax, - Vat = item.Value.Vat + Product = item.Value.inventory.Product, + Quantity = item.Value.inventory.Quantity, + Price = item.Value.inventory.Price, + FullPrice = item.Value.inventory.FullPrice, + Discount = item.Value.inventory.Discount, + ServiceCharge = item.Value.inventory.ServiceCharge, + IsScTaxable = item.Value.inventory.IsScTaxable, + ServiceTaxRate = item.Value.inventory.ServiceTaxRate, + VatRate = item.Value.inventory.VatRate, + ServiceTax = item.Value.inventory.ServiceTax, + Vat = item.Value.inventory.Vat }; - foreach (var mod in item.Value.Modifiers) - inv.InventoryModifier.Add(new InventoryModifier { Modifier = mod }); + foreach (var mod in item.Value.inventory.InventoryModifier) + inv.InventoryModifier.Add(new InventoryModifier { Modifier = mod.Modifier }); kot.Inventories.Add(inv); } } diff --git a/Tanshu.Accounts.PointOfSale/Controllers/BillDict.cs b/Tanshu.Accounts.PointOfSale/Controllers/BillDict.cs index 3e993e3..57da96a 100644 --- a/Tanshu.Accounts.PointOfSale/Controllers/BillDict.cs +++ b/Tanshu.Accounts.PointOfSale/Controllers/BillDict.cs @@ -1,4 +1,5 @@ -using Tanshu.Accounts.Contracts; +using System.Linq; +using Tanshu.Accounts.Contracts; using Tanshu.Common; using Tanshu.Accounts.Entities; @@ -7,7 +8,8 @@ namespace Tanshu.Accounts.PointOfSale public class BillDict : OrderedDictionary { public delegate void ItemChangedHandler(); - public void Load(Voucher voucher) { + public void Load(Voucher voucher) + { foreach (var kot in voucher.Kots) { var kotKey = new BillItemKey(kot.KotID); @@ -16,30 +18,45 @@ namespace Tanshu.Accounts.PointOfSale foreach (var inv in kot.Inventories) { var key = new BillItemKey(inv.Product.ProductID, kot.KotID); - var item = new BillItemValue(inv.Product) - { - ProductID = inv.Product.ProductID, - Discount = inv.Discount, - Name = - inv.Product.Units == string.Empty - ? inv.Product.Name - : inv.Product.Name + " (" + inv.Product.Units + ")", - Price = inv.Price, - Printed = true, - Quantity = inv.Quantity, - IsScTaxable = inv.IsScTaxable, - ServiceTaxRate = inv.ServiceTaxRate, - VatRate = inv.VatRate, - ServiceTax = inv.ServiceTax, - Vat = inv.Vat, - ServiceCharge = inv.ServiceCharge, - }; - foreach (var mod in inv.InventoryModifier) - item.Modifiers.Add(mod.Modifier); + var item = new BillItemValue(inv); this.Add(key, item); } } - + } + public decimal Tax + { + get + { + return this.Where(x => x.Key.BillItemType != BillItemType.Kot).Sum(i => i.Value.inventory.ServiceTaxAmount + i.Value.inventory.VatAmount); + } + } + public decimal Discount + { + get + { + return this.Where(x => x.Key.BillItemType != BillItemType.Kot).Sum(i => i.Value.inventory.DiscountAmount); + } + } + public decimal ServiceCharge + { + get + { + return this.Where(x => x.Key.BillItemType != BillItemType.Kot).Sum(i => i.Value.inventory.ServiceChargeAmount); + } + } + public decimal NetAmount + { + get + { + return this.Where(x => x.Key.BillItemType != BillItemType.Kot).Sum(i => i.Value.inventory.Net); + } + } + public decimal Amount + { + get + { + return this.Where(x => x.Key.BillItemType != BillItemType.Kot).Sum(i => i.Value.inventory.Amount); + } } } } \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Controllers/ISaleForm.cs b/Tanshu.Accounts.PointOfSale/Controllers/ISaleForm.cs index 6e5b04b..9a470dd 100644 --- a/Tanshu.Accounts.PointOfSale/Controllers/ISaleForm.cs +++ b/Tanshu.Accounts.PointOfSale/Controllers/ISaleForm.cs @@ -11,10 +11,10 @@ namespace Tanshu.Accounts.PointOfSale { public interface ISaleForm { - void ClearBill(List bill); + void ClearBill(BillDict bill); void SetCustomerDisplay(string name); void CloseWindow(); - void ShowAmount(decimal discountAmount, decimal grossAmount, decimal serviceChargeAmount, decimal taxAmount, decimal valueAmount, List bill); + 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; } diff --git a/Tanshu.Accounts.PointOfSale/Sales/ModifierForm.Designer.cs b/Tanshu.Accounts.PointOfSale/Sales/ModifierForm.Designer.cs index 89413fb..be5964e 100644 --- a/Tanshu.Accounts.PointOfSale/Sales/ModifierForm.Designer.cs +++ b/Tanshu.Accounts.PointOfSale/Sales/ModifierForm.Designer.cs @@ -30,25 +30,24 @@ { this.flpModifier = new System.Windows.Forms.FlowLayoutPanel(); this.btnClose = new System.Windows.Forms.Button(); - this.flpModifier.SuspendLayout(); this.SuspendLayout(); // // flpModifier // this.flpModifier.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.flpModifier.Controls.Add(this.btnClose); - this.flpModifier.Dock = System.Windows.Forms.DockStyle.Fill; - this.flpModifier.Location = new System.Drawing.Point(0, 0); + this.flpModifier.Dock = System.Windows.Forms.DockStyle.Bottom; + this.flpModifier.Location = new System.Drawing.Point(0, 84); this.flpModifier.Name = "flpModifier"; - this.flpModifier.Size = new System.Drawing.Size(486, 408); + this.flpModifier.Size = new System.Drawing.Size(486, 324); this.flpModifier.TabIndex = 6; // // btnClose // - this.btnClose.Location = new System.Drawing.Point(3, 3); + 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); this.btnClose.Name = "btnClose"; this.btnClose.Size = new System.Drawing.Size(480, 75); - this.btnClose.TabIndex = 6; + this.btnClose.TabIndex = 7; this.btnClose.Text = "Close"; this.btnClose.UseVisualStyleBackColor = true; this.btnClose.Click += new System.EventHandler(this.btnClose_Click); @@ -59,16 +58,14 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(486, 408); this.ControlBox = false; + this.Controls.Add(this.btnClose); this.Controls.Add(this.flpModifier); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; this.MaximizeBox = false; this.Name = "ModifierForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Modifier"; this.Load += new System.EventHandler(this.ModifierForm_Load); - this.flpModifier.ResumeLayout(false); this.ResumeLayout(false); - } #endregion diff --git a/Tanshu.Accounts.PointOfSale/Sales/ModifierForm.cs b/Tanshu.Accounts.PointOfSale/Sales/ModifierForm.cs index 6c1020d..7a7dd8b 100644 --- a/Tanshu.Accounts.PointOfSale/Sales/ModifierForm.cs +++ b/Tanshu.Accounts.PointOfSale/Sales/ModifierForm.cs @@ -14,10 +14,10 @@ namespace Tanshu.Accounts.PointOfSale { public partial class ModifierForm : Form { - private IList selection; + private IList selection; private IList source; private IList list; - public ModifierForm(IList source, IList selection) + public ModifierForm(IList source, IList selection) { InitializeComponent(); this.selection = selection; @@ -28,18 +28,41 @@ namespace Tanshu.Accounts.PointOfSale private void button_Click(object sender, EventArgs e) { CheckBox button = sender as CheckBox; - if (button == null) - return; if (button.CheckState == CheckState.Checked) - selection.Add((Modifier)button.Tag); + selection.Add(new InventoryModifier() { Modifier = (Modifier)button.Tag }); else - selection.Remove((Modifier)button.Tag); + selection.Remove(selection.First(x => x.Modifier.ModifierID == ((Modifier)button.Tag).ModifierID)); } - public IList Selection + private void ModifierForm_Load(object sender, EventArgs e) { - get + var size = new Point(75, 75); + int count = 30; + ButtonClickDelegate bcDelegate = new ButtonClickDelegate(button_Click); + if (list.Count != 0) { - return selection; + for (int i = list.Count - 1; i >= 0; i--) + { + list[i].Dispose(); + } + list = new List(); + } + if (count > source.Count) + count = source.Count; + for (int i = 0; i < count; i++) + { + var control = new CheckBox() + { + Name = i.ToString(), + Text = source[i].Name, + Width = size.X, + Height = size.Y, + Tag = source[i], + Appearance = Appearance.Button, + Checked = selection.Count(x => x.Modifier.ModifierID == source[i].ModifierID) > 0 + }; + control.Click += new EventHandler(bcDelegate); + flpModifier.Controls.Add(control); + list.Add(control); } } @@ -48,10 +71,5 @@ namespace Tanshu.Accounts.PointOfSale this.Close(); } - private void ModifierForm_Load(object sender, EventArgs e) - { - ControlFactory.GenerateModifiers(ref flpModifier, ref list, selection, new Point(75, 75), 30, source, new ButtonClickDelegate(button_Click)); - } - } } diff --git a/Tanshu.Accounts.PointOfSale/Sales/SalesForm.Designer.cs b/Tanshu.Accounts.PointOfSale/Sales/SalesForm.Designer.cs index 6e60771..69c61a6 100644 --- a/Tanshu.Accounts.PointOfSale/Sales/SalesForm.Designer.cs +++ b/Tanshu.Accounts.PointOfSale/Sales/SalesForm.Designer.cs @@ -32,8 +32,8 @@ namespace Tanshu.Accounts.PointOfSale.Sales 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 dgvCellStyleDisplay = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dgvCellStyleQuantity = new System.Windows.Forms.DataGridViewCellStyle(); this.label7 = new System.Windows.Forms.Label(); this.txtDiscount = new System.Windows.Forms.TextBox(); this.Label12 = new System.Windows.Forms.Label(); @@ -43,8 +43,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales this.label5 = new System.Windows.Forms.Label(); this.txtGrossTax = new System.Windows.Forms.TextBox(); this.dgvProducts = new System.Windows.Forms.DataGridView(); - this.Display = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.printedDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.displayColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.bindingSource = new System.Windows.Forms.BindingSource(this.components); this.pnlBilling = new System.Windows.Forms.Panel(); this.label10 = new System.Windows.Forms.Label(); @@ -53,7 +52,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales this.flpGroup = new System.Windows.Forms.FlowLayoutPanel(); this.flpActions = new System.Windows.Forms.FlowLayoutPanel(); this.btnQuantity = new System.Windows.Forms.Button(); - this.btnRate = new System.Windows.Forms.Button(); + this.btnPrice = new System.Windows.Forms.Button(); this.btnDelete = new System.Windows.Forms.Button(); this.btnDiscount = new System.Windows.Forms.Button(); this.btnModifier = new System.Windows.Forms.Button(); @@ -81,6 +80,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales this.txtBillID = new System.Windows.Forms.TextBox(); this.txtKotID = new System.Windows.Forms.TextBox(); this.btnCustomer = new System.Windows.Forms.Button(); + this.quantityColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)(this.dgvProducts)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.bindingSource)).BeginInit(); this.pnlBilling.SuspendLayout(); @@ -190,8 +190,8 @@ namespace Tanshu.Accounts.PointOfSale.Sales this.dgvProducts.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders; this.dgvProducts.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dgvProducts.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.Display, - this.printedDataGridViewTextBoxColumn}); + this.displayColumn, + this.quantityColumn}); this.dgvProducts.DataSource = this.bindingSource; this.dgvProducts.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically; this.dgvProducts.Location = new System.Drawing.Point(12, 90); @@ -206,31 +206,31 @@ namespace Tanshu.Accounts.PointOfSale.Sales // // Display // - this.Display.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells; - this.Display.DataPropertyName = "Display"; - dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.Display.DefaultCellStyle = dataGridViewCellStyle1; - this.Display.HeaderText = "Display"; - this.Display.MinimumWidth = 250; - this.Display.Name = "Display"; - this.Display.ReadOnly = true; - this.Display.Width = 250; + this.displayColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells; + this.displayColumn.DataPropertyName = "Display"; + dgvCellStyleDisplay.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.displayColumn.DefaultCellStyle = dgvCellStyleDisplay; + this.displayColumn.HeaderText = "Display"; + this.displayColumn.MinimumWidth = 250; + this.displayColumn.Name = "DisplayColumn"; + this.displayColumn.ReadOnly = true; + this.displayColumn.Width = 250; // - // printedDataGridViewTextBoxColumn + // quantityColumn // - this.printedDataGridViewTextBoxColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells; - this.printedDataGridViewTextBoxColumn.DataPropertyName = "Quantity"; - dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight; - dataGridViewCellStyle2.Format = "N2"; - this.printedDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle2; - this.printedDataGridViewTextBoxColumn.HeaderText = "Printed"; - this.printedDataGridViewTextBoxColumn.Name = "printedDataGridViewTextBoxColumn"; - this.printedDataGridViewTextBoxColumn.ReadOnly = true; - this.printedDataGridViewTextBoxColumn.Width = 65; + this.quantityColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells; + this.quantityColumn.DataPropertyName = "Quantity"; + dgvCellStyleQuantity.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight; + dgvCellStyleQuantity.Format = "N2"; + this.quantityColumn.DefaultCellStyle = dgvCellStyleQuantity; + this.quantityColumn.HeaderText = "Quantity"; + this.quantityColumn.Name = "QuantityColumn"; + this.quantityColumn.ReadOnly = true; + this.quantityColumn.Width = 65; // // bindingSource // - this.bindingSource.DataSource = typeof(Tanshu.Accounts.Contracts.BillItemValue); + this.bindingSource.DataSource = typeof(System.Collections.Generic.KeyValuePair); // // pnlBilling // @@ -309,7 +309,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales // flpActions // this.flpActions.Controls.Add(this.btnQuantity); - this.flpActions.Controls.Add(this.btnRate); + this.flpActions.Controls.Add(this.btnPrice); this.flpActions.Controls.Add(this.btnDelete); this.flpActions.Controls.Add(this.btnDiscount); this.flpActions.Controls.Add(this.btnModifier); @@ -338,15 +338,15 @@ namespace Tanshu.Accounts.PointOfSale.Sales this.btnQuantity.UseVisualStyleBackColor = true; this.btnQuantity.Click += new System.EventHandler(this.btnQuantity_Click); // - // btnRate + // btnPrice // - this.btnRate.Location = new System.Drawing.Point(84, 3); - this.btnRate.Name = "btnRate"; - this.btnRate.Size = new System.Drawing.Size(75, 75); - this.btnRate.TabIndex = 146; - this.btnRate.Text = "&Rate"; - this.btnRate.UseVisualStyleBackColor = true; - this.btnRate.Click += new System.EventHandler(this.btnRate_Click); + this.btnPrice.Location = new System.Drawing.Point(84, 3); + this.btnPrice.Name = "btnPrice"; + this.btnPrice.Size = new System.Drawing.Size(75, 75); + this.btnPrice.TabIndex = 146; + this.btnPrice.Text = "btnPrice"; + this.btnPrice.UseVisualStyleBackColor = true; + this.btnPrice.Click += new System.EventHandler(this.btnPrice_Click); // // btnDelete // @@ -657,7 +657,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales private System.Windows.Forms.Button btnPrintKot; private System.Windows.Forms.Button btnPrintBill; private System.Windows.Forms.Button btnVoid; - private System.Windows.Forms.Button btnRate; + private System.Windows.Forms.Button btnPrice; private System.Windows.Forms.Button btnClear; internal System.Windows.Forms.Label lblServiceCharge; internal System.Windows.Forms.TextBox txtServiceCharge; @@ -668,8 +668,8 @@ namespace Tanshu.Accounts.PointOfSale.Sales private System.Windows.Forms.FlowLayoutPanel flpMain; private System.Windows.Forms.Button btnDelete; private System.Windows.Forms.Button btnMoveTable; - private System.Windows.Forms.DataGridViewTextBoxColumn Display; - private System.Windows.Forms.DataGridViewTextBoxColumn printedDataGridViewTextBoxColumn; + private System.Windows.Forms.DataGridViewTextBoxColumn displayColumn; + private System.Windows.Forms.DataGridViewTextBoxColumn quantityColumn; private System.Windows.Forms.Button btnMore; private System.Windows.Forms.Button btnMoveKot; private readonly BillController _billController; diff --git a/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs b/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs index 214c251..184aa2e 100644 --- a/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs +++ b/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using System.Linq; using System.Threading; using System.Windows.Forms; using Tanshu.Accounts.Contracts; @@ -173,11 +174,11 @@ namespace Tanshu.Accounts.PointOfSale.Sales } } - private void btnRate_Click(object sender, EventArgs e) + private void btnPrice_Click(object sender, EventArgs e) { try { - _billController.SetRate(); + _billController.SetPrice(); } catch (Exception ex) { @@ -194,14 +195,14 @@ namespace Tanshu.Accounts.PointOfSale.Sales private void dgvProducts_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { var dgv = sender as DataGridView; - var data = dgv.Rows[e.RowIndex].DataBoundItem as BillItemValue; + var data = (KeyValuePair)dgv.Rows[e.RowIndex].DataBoundItem; - if (data.IsKot) + if (data.Key.BillItemType == BillItemType.Kot) { e.CellStyle.SelectionBackColor = Color.Blue; e.CellStyle.BackColor = Color.LightBlue; } - else if (data.Printed) + else if (data.Value.inventory.Kot != null) { e.CellStyle.SelectionBackColor = Color.HotPink; e.CellStyle.BackColor = Color.LightPink; @@ -211,6 +212,15 @@ namespace Tanshu.Accounts.PointOfSale.Sales e.CellStyle.SelectionBackColor = Color.Green; e.CellStyle.BackColor = Color.LightGreen; } + if (dgv.Columns[e.ColumnIndex].Name.Equals("DisplayColumn")) + e.Value = data.Value.Display; + else if (dgv.Columns[e.ColumnIndex].Name.Equals("QuantityColumn")) + { + if (data.Key.BillItemType != BillItemType.Kot) + e.Value = data.Value.inventory.Quantity; + else + e.Value = ""; + } } private void btnSettle_Click(object sender, EventArgs e) @@ -220,11 +230,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales private void btnModifier_Click(object sender, EventArgs e) { - var item = _billController.CurrentProduct; - if (item == null) - return; - - _billController.ShowModifiers(item); + _billController.ShowModifiers(); } private void btnDelete_Click(object sender, EventArgs e) @@ -254,7 +260,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales { btnMore.Text = more ? "Less" : "More"; btnQuantity.Visible = !more; - btnRate.Visible = more; + btnPrice.Visible = more; btnDelete.Visible = !more; btnDiscount.Visible = !more; btnModifier.Visible = !more; @@ -271,7 +277,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales #region Helper Functions - public void ClearBill(List bill) + public void ClearBill(BillDict bill) { txtBillID.Text = ""; txtKotID.Text = ""; @@ -292,14 +298,14 @@ namespace Tanshu.Accounts.PointOfSale.Sales } public void ShowAmount(decimal discountAmount, decimal grossAmount, decimal serviceChargeAmount, - decimal taxAmount, decimal valueAmount, List bill) + 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; + bindingSource.DataSource = bill.ToList(); dgvProducts.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells); }