From 843d644154639a19ee60c784cef0eac901dfa0be Mon Sep 17 00:00:00 2001 From: Tanshu Date: Sat, 1 Dec 2012 15:19:33 +0530 Subject: [PATCH] Added ST Number to bill. Fixed error were unprinted bill was not removed from table when voided. --- .../Data Contracts Display/BillItemKey.cs | 4 +- .../Data Contracts/FoodTableBO.cs | 6 +-- Tanshu.Accounts.Helpers/ControlFactory.cs | 52 +++++++++---------- .../Controllers/BillController.cs | 27 +++++++--- .../Controllers/BillDict.cs | 12 +++++ .../Reports/SaleAnalysisForm.cs | 5 +- Tanshu.Accounts.Print/ThermalBill.cs | 1 + .../BusinessLayer/FoodTableBI.cs | 4 +- 8 files changed, 68 insertions(+), 43 deletions(-) create mode 100644 Tanshu.Accounts.PointOfSale/Controllers/BillDict.cs diff --git a/Tanshu.Accounts.Contracts/Data Contracts Display/BillItemKey.cs b/Tanshu.Accounts.Contracts/Data Contracts Display/BillItemKey.cs index 03545a7..d96d74d 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts Display/BillItemKey.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts Display/BillItemKey.cs @@ -5,7 +5,9 @@ namespace Tanshu.Accounts.Contracts public enum BillItemType { Product, - Kot + Kot, + Information, + Total } public class BillItemKey { diff --git a/Tanshu.Accounts.Contracts/Data Contracts/FoodTableBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/FoodTableBO.cs index f09d165..80eda89 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/FoodTableBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/FoodTableBO.cs @@ -1,8 +1,4 @@ -using System; -using System.Runtime.Serialization; -using FluentNHibernate.Mapping; - -namespace Tanshu.Accounts.Entities +namespace Tanshu.Accounts.Entities { public class FoodTable { diff --git a/Tanshu.Accounts.Helpers/ControlFactory.cs b/Tanshu.Accounts.Helpers/ControlFactory.cs index deaba9e..b776880 100644 --- a/Tanshu.Accounts.Helpers/ControlFactory.cs +++ b/Tanshu.Accounts.Helpers/ControlFactory.cs @@ -1,13 +1,9 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Windows.Forms; using System.Drawing; -using Tanshu.Accounts.Contracts; using Tanshu.Accounts.Entities; using System.Collections; -using Tanshu.Accounts.Repository; using Tanshu.Common.KeyboardControl; namespace Tanshu.Accounts.Helpers @@ -20,7 +16,7 @@ namespace Tanshu.Accounts.Helpers { IList list = new List(); int pageLength, stop; - PageSetup(ref panel, start, inList as IList, out pageLength, out stop); + PageSetup(panel, start, inList as IList, size, out pageLength, out stop); if (start != 0) list.Add(new FoodTable() { FoodTableID = start - pageLength, Name = "Previous" }); for (int i = start; i < stop; i++) @@ -34,7 +30,7 @@ namespace Tanshu.Accounts.Helpers { var item = list[i]; var status = item.Status; - var control = GetButton(string.Format("g{0}", i), item.Name, size.X, size.Y, item, bcDelegate); + var control = GetButton(string.Format("g{0}", i), item.Name, size, item, bcDelegate); if (status == "printed") control.BackColor = Color.Green; else if (status == "running") @@ -46,7 +42,7 @@ namespace Tanshu.Accounts.Helpers { IList list = new List(); int pageLength, stop; - PageSetup(ref panel, start, inList as IList, out pageLength, out stop); + PageSetup(panel, start, inList as IList, size, out pageLength, out stop); if (start != 0) list.Add(new Product() { ProductID = start - pageLength, Name = "Previous" }); for (int i = start; i < stop; i++) @@ -59,7 +55,7 @@ namespace Tanshu.Accounts.Helpers for (var i = 0; i < list.Count; i++) { var item = list[i]; - var control = GetButton(string.Format("p{0}", i), item.Units == string.Empty ? item.Name : string.Format("{0} ({1})", item.Name, item.Units), size.X, size.Y, item, bcDelegate); + var control = GetButton(string.Format("p{0}", i), item.Units == string.Empty ? item.Name : string.Format("{0} ({1})", item.Name, item.Units), size, item, bcDelegate); if (item.Price == 0) control.BackColor = Color.Yellow; panel.Controls.Add(control); @@ -72,7 +68,7 @@ namespace Tanshu.Accounts.Helpers for (int i = 0; i < list.Count; i++) { var item = list[i]; - var control = GetUnselectableCheckbox(i.ToString(), item, size.X, size.Y, item, bcDelegate); + var control = GetUnselectableCheckbox(i.ToString(), item, size, item, bcDelegate); panel.Controls.Add(control); } } @@ -81,7 +77,7 @@ namespace Tanshu.Accounts.Helpers { IList list = new List(); int pageLength, stop; - PageSetup(ref panel, start, inList as IList, out pageLength, out stop); + PageSetup(panel, start, inList as IList, size, out pageLength, out stop); if (start != 0) list.Add(new ProductGroup() { ProductGroupID = start - pageLength, Name = "Previous" }); for (int i = start; i < stop; i++) @@ -94,7 +90,7 @@ namespace Tanshu.Accounts.Helpers for (int i = 0; i < list.Count; i++) { var item = list[i]; - var control = GetButton(string.Format("g{0}", i), item.Name, size.X, size.Y, item, bcDelegate); + var control = GetButton(string.Format("g{0}", i), item.Name, size, item, bcDelegate); panel.Controls.Add(control); } } @@ -113,18 +109,20 @@ namespace Tanshu.Accounts.Helpers for (int i = 0; i < count; i++) { var item = list[i]; - var control = GetCheckbox(i.ToString(), item.Name, size.X, size.Y, item, bcDelegate); + var control = GetCheckbox(i.ToString(), item.Name, size, item, bcDelegate); control.Checked = selection.Contains(item); panel.Controls.Add(control); controlList.Add(control); } } - private static void PageSetup(ref FlowLayoutPanel panel, int start, IList inList, out int pageLength, out int stop) + private static void PageSetup(FlowLayoutPanel panel, int start, ICollection inList, Point size, out int pageLength, out int stop) { panel.Controls.Clear(); - pageLength = (panel.Height / (3 + 75 + 3)); - pageLength *= (panel.Width / (3 + 75 + 3)); + var marginWidth = panel.Margin.Right + panel.Margin.Left; + var marginHeight = panel.Margin.Top + panel.Margin.Bottom; + pageLength = (panel.ClientSize.Height / (marginHeight + size.Y)); + pageLength *= (panel.ClientSize.Width / (marginWidth + size.X)); pageLength -= 2; if (inList.Count <= pageLength) start = 0; @@ -135,28 +133,28 @@ namespace Tanshu.Accounts.Helpers stop = inList.Count; } - private static Button GetButton(string name, string text, int width, int height, object tag, ButtonClickDelegate bcDelegate) + private static Button GetButton(string name, string text, Point size, object tag, ButtonClickDelegate bcDelegate) { - Button control = new Button() + var control = new Button() { Name = name, Text = text, - Width = width, - Height = height, + Width = size.X, + Height = size.Y, Tag = tag, }; if (bcDelegate != null) control.Click += new EventHandler(bcDelegate); return control; } - private static UnselectableCheckbox GetUnselectableCheckbox(string name, string text, int width, int height, object tag, ButtonClickDelegate bcDelegate) + private static UnselectableCheckbox GetUnselectableCheckbox(string name, string text, Point size, object tag, ButtonClickDelegate bcDelegate) { - UnselectableCheckbox control = new UnselectableCheckbox() + var control = new UnselectableCheckbox() { Name = name, Text = text, - Width = width, - Height = height, + Width = size.X, + Height = size.Y, Tag = tag, Appearance = Appearance.Button, @@ -165,14 +163,14 @@ namespace Tanshu.Accounts.Helpers control.Click += new EventHandler(bcDelegate); return control; } - private static CheckBox GetCheckbox(string name, string text, int width, int height, object tag, ButtonClickDelegate bcDelegate) + private static CheckBox GetCheckbox(string name, string text, Point size, object tag, ButtonClickDelegate bcDelegate) { - CheckBox control = new CheckBox() + var control = new CheckBox() { Name = name, Text = text, - Width = width, - Height = height, + Width = size.X, + Height = size.Y, Tag = tag, Appearance = Appearance.Button, diff --git a/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs b/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs index 1c9c299..80a763c 100644 --- a/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs +++ b/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs @@ -12,7 +12,7 @@ namespace Tanshu.Accounts.PointOfSale { public class BillController { - private readonly OrderedDictionary _bill; + private readonly BillDict _bill; private Voucher _billInfo; @@ -31,7 +31,7 @@ namespace Tanshu.Accounts.PointOfSale { this._editVoucherID = editVoucherID; _print = print; - _bill = new OrderedDictionary(); + _bill = new BillDict(); _billInfo = new Voucher(Session.User); using (var bi = new CustomerBI(false)) _billInfo.Customer = bi.Get(x => x.CustomerID == 1); @@ -80,9 +80,7 @@ namespace Tanshu.Accounts.PointOfSale else { var billItemValue = new BillItemValue(product); - var old = - _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.ProductID == newKey.ProductID). - FirstOrDefault(); + var old = _bill.FirstOrDefault(x => x.Key.BillItemType == BillItemType.Product && x.Key.ProductID == newKey.ProductID); if (old.Key != null) { billItemValue.Discount = old.Value.Discount; @@ -908,13 +906,28 @@ namespace Tanshu.Accounts.PointOfSale using (var trans = session.BeginTransaction()) { int? kotID; + bool tableExists = false; using (var bi = new VoucherBI(session, false)) kotID = bi.Insert(_billInfo); if (updateTable) using (var ft = new FoodTableBI(session, false)) + { + tableExists = ft.Get(x => x.Name == _billInfo.TableID).VoucherID == 0; ft.UpdateStatus(_billInfo); - trans.Commit(); - return kotID; + + } + if (tableExists) + { + MessageBox.Show("A bill exists on this table, cannot overrite", "Bill Open", + MessageBoxButtons.OK, MessageBoxIcon.Error); + trans.Rollback(); + return null; + } + else + { + trans.Commit(); + return kotID; + } } } } diff --git a/Tanshu.Accounts.PointOfSale/Controllers/BillDict.cs b/Tanshu.Accounts.PointOfSale/Controllers/BillDict.cs new file mode 100644 index 0000000..ad25e6d --- /dev/null +++ b/Tanshu.Accounts.PointOfSale/Controllers/BillDict.cs @@ -0,0 +1,12 @@ +using Tanshu.Accounts.Contracts; +using Tanshu.Common; + +namespace Tanshu.Accounts.PointOfSale +{ + public class BillDict : OrderedDictionary + { + public delegate void ItemChangedHandler(); + public event ItemChangedHandler ItemChanged; + + } +} \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Reports/SaleAnalysisForm.cs b/Tanshu.Accounts.PointOfSale/Reports/SaleAnalysisForm.cs index b5c6b7d..1c3773b 100644 --- a/Tanshu.Accounts.PointOfSale/Reports/SaleAnalysisForm.cs +++ b/Tanshu.Accounts.PointOfSale/Reports/SaleAnalysisForm.cs @@ -21,9 +21,12 @@ namespace Tanshu.Accounts.PointOfSale private void ShowStatement() { - if (DateTime.Today.Subtract(dtpStart.Value.Date).Days > 5 && !Session.IsAllowed(RoleConstants.ACCOUNTS_AUDIT)) + if (DateTime.Today.Subtract(dtpStart.Value.Date).Days > 5 && + !Session.IsAllowed(RoleConstants.ACCOUNTS_AUDIT)) return; + _list = new SalesAnalysisBI().GetSale(dtpStart.Value, dtpFinish.Value); + dgvSale.AutoGenerateColumns = true; dgvSale.DataSource = _list; dgvSale.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; diff --git a/Tanshu.Accounts.Print/ThermalBill.cs b/Tanshu.Accounts.Print/ThermalBill.cs index 7e55cde..014e325 100644 --- a/Tanshu.Accounts.Print/ThermalBill.cs +++ b/Tanshu.Accounts.Print/ThermalBill.cs @@ -103,6 +103,7 @@ namespace Tanshu.Accounts.Print billText += "\n\r" + "SCO 358, Sector 9, Panchkula".Center42(); billText += "\n\r" + "A Unit of Peitho Foods Pvt. Ltd.".Center42(); billText += "\n\r" + "TIN: 06592507323".Center42(); + billText += "\n\r" + "Service Tax: AAFCP5097GSD001".Center42(); switch (voucher.VoucherType) { case VoucherType.Regular: diff --git a/Tanshu.Accounts.Repository/BusinessLayer/FoodTableBI.cs b/Tanshu.Accounts.Repository/BusinessLayer/FoodTableBI.cs index af54f43..c8ffb32 100644 --- a/Tanshu.Accounts.Repository/BusinessLayer/FoodTableBI.cs +++ b/Tanshu.Accounts.Repository/BusinessLayer/FoodTableBI.cs @@ -49,9 +49,9 @@ namespace Tanshu.Accounts.Repository public void UpdateStatus(Voucher voucher) { string status; - if (!voucher.Printed) + if (!voucher.Printed && !voucher.Void) status = "running"; - else if (voucher.Settlements.Count(x => x.Settled == SettleOption.Unsettled) != 0 && voucher.Void == false) + else if (voucher.Settlements.Count(x => x.Settled == SettleOption.Unsettled) != 0 && !voucher.Void) status = "printed"; else status = null;