diff --git a/Include/Tanshu.Common.dll b/Include/Tanshu.Common.dll index a01a3c4..0ede7ec 100644 Binary files a/Include/Tanshu.Common.dll and b/Include/Tanshu.Common.dll differ diff --git a/Include/Tanshu.Data.dll b/Include/Tanshu.Data.dll index e2e3cdb..e3e285b 100644 Binary files a/Include/Tanshu.Data.dll and b/Include/Tanshu.Data.dll differ diff --git a/Tanshu.Accounts.Contracts/Data Contracts Display/BillInventoryBO.cs b/Tanshu.Accounts.Contracts/Data Contracts Display/BillInventoryBO.cs index 967dca3..934836f 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts Display/BillInventoryBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts Display/BillInventoryBO.cs @@ -77,8 +77,9 @@ namespace Tanshu.Accounts.Contracts var output = string.Format("{0} @ Rs. {1:#.##}", Name, Price); if (_discount != 0) output += string.Format(" - {0:#.##%}", _discount); - foreach (var item in Modifiers) - output += string.Format("\n\r -- {0}", item.Name); + if (Modifiers != null) + foreach (var item in Modifiers) + output += string.Format("\n\r -- {0}", item.Name); return output; //if (Price == 0) @@ -96,10 +97,45 @@ namespace Tanshu.Accounts.Contracts public IList Modifiers { get; set; } public BillItemValue(Product product) { - Quantity = 1; - Printed = false; Modifiers = new List(); - Product = product; + if (product != null) + { + Product = product; + ProductID = product.ProductID; + Name = product.Units == string.Empty ? product.Name : product.Name + " (" + product.Units + ")"; + Quantity = 1; + Price = product.SalePrice; + Tax = product.Tax.Rate; + ServiceCharge = product.ServiceCharge; + Discount = 0; + Printed = false; + } } + public BillItemValue() + { + Product = null; + ProductID = 0; + Discount = 0; + Name = "== New Kot =="; + Price = 0; + Printed = true; + Quantity = 0; + Tax = -1; + ServiceCharge = 0; + } + + public BillItemValue(Kot kot) + { + Product = null; + ProductID = kot.KotID; + Discount = 0; + Name = string.Format("Kot: {0} / {1:dd-MMM HH:mm} ({2})", kot.Code, kot.Date, kot.User.Name); + Price = 0; + Printed = true; + Quantity = 0; + Tax = -1; + ServiceCharge = 0; + } + } -} +} \ No newline at end of file diff --git a/Tanshu.Accounts.Contracts/Data Contracts/ReprintBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/ReprintBO.cs new file mode 100644 index 0000000..da5fe2b --- /dev/null +++ b/Tanshu.Accounts.Contracts/Data Contracts/ReprintBO.cs @@ -0,0 +1,13 @@ +using System; +using Tanshu.Accounts.Entities.Auth; + +namespace Tanshu.Accounts.Entities +{ + public class Reprint + { + public virtual int ReprintID { get; set; } + public virtual User User { get; set; } + public virtual DateTime Date { get; set; } + public virtual Voucher Voucher { get; set; } + } +} diff --git a/Tanshu.Accounts.Contracts/Data Contracts/VoucherBO.cs b/Tanshu.Accounts.Contracts/Data Contracts/VoucherBO.cs index 4a6f704..05a235a 100644 --- a/Tanshu.Accounts.Contracts/Data Contracts/VoucherBO.cs +++ b/Tanshu.Accounts.Contracts/Data Contracts/VoucherBO.cs @@ -8,27 +8,56 @@ namespace Tanshu.Accounts.Entities { public class Voucher { - public Voucher() + protected Voucher() { Kots = new List(); Settlements = new List(); } - public virtual int VoucherID { get; set; } - public virtual DateTime? Date { get; set; } + public Voucher(User user) + : this() + { + this._date = null; + this.User = user; + } + + protected int _voucherID; + public virtual int VoucherID + { + get { return _voucherID; } + } + + protected DateTime? _date; + public virtual DateTime? Date + { + get { return _date; } + } + public virtual string Narration { get; set; } [NotNull] public virtual User User { get; set; } + protected DateTime _creationDate; [NotNull] - public virtual DateTime CreationDate { get; set; } + public virtual DateTime CreationDate + { + get { return _creationDate; } + } + protected DateTime _lastEditDate; [NotNull] - public virtual DateTime LastEditDate { get; set; } + public virtual DateTime LastEditDate + { + get { return _lastEditDate; } + } + protected string _billID; [NotNull] - public virtual string BillID { get; set; } + public virtual string BillID + { + get { return _billID; } + } [NotNull] public virtual string TableID { get; set; } @@ -48,11 +77,33 @@ namespace Tanshu.Accounts.Entities [AllowNull] public virtual string VoidReason { get; set; } - [NotNull] - public virtual bool Printed { get; set; } + protected bool _printed; [NotNull] - public virtual string KotID { get; set; } + public virtual bool Printed + { + get + { return _printed; } + set + { + if (_printed) + return; + if (value == false) + return; + _date = null; + _printed = value; + } + } + +#pragma warning disable 649 + private string _kotID; +#pragma warning restore 649 + + [NotNull] + public virtual string KotID + { + get { return _kotID; } + } [Cascade] public virtual IList Kots { get; set; } diff --git a/Tanshu.Accounts.Contracts/Helper Functions/ReflectionHelper.cs b/Tanshu.Accounts.Contracts/Helper Functions/ReflectionHelper.cs new file mode 100644 index 0000000..9df994d --- /dev/null +++ b/Tanshu.Accounts.Contracts/Helper Functions/ReflectionHelper.cs @@ -0,0 +1,28 @@ +using System.Reflection; +using Tanshu.Accounts.Entities; + +namespace Tanshu.Common.Helpers +{ + public enum VoucherFields + { + CreationDate, + LastEditDate, + Date, + BillID, + KotID + } + public static class ReflectionHelper + { + public static void SetValue(this Voucher voucher, VoucherFields field, object value) + { + var fi = typeof(Voucher).GetField(ConvertToCamelCaseUnderscore(field.ToString()), BindingFlags.NonPublic | BindingFlags.Instance); + if (fi != null) + fi.SetValue(voucher, value); + } + private static string ConvertToCamelCaseUnderscore(string propertyName) + { + return "_" + propertyName[0].ToString().ToLower() + propertyName.Substring(1); + } + + } +} \ No newline at end of file diff --git a/Tanshu.Accounts.Contracts/RolesConstants.cs b/Tanshu.Accounts.Contracts/RolesConstants.cs index 3459bcf..35a274d 100644 --- a/Tanshu.Accounts.Contracts/RolesConstants.cs +++ b/Tanshu.Accounts.Contracts/RolesConstants.cs @@ -39,6 +39,7 @@ namespace Tanshu.Accounts.Contracts public static RoleConstants BILL_DETAILS = new RoleConstants("Sales/BillDetails"); public static RoleConstants SALE_ANALYSIS = new RoleConstants("Sales/SaleAnalysis"); public static RoleConstants SALE_DETAIL = new RoleConstants("Sales/SaleDetail"); + public static RoleConstants SPLIT_BILL = new RoleConstants("Split Bill"); public static RoleConstants VOID_BILL = new RoleConstants("Sales/VoidPrintedBill"); public static RoleConstants ZERO_RATE = new RoleConstants("Sales/ZeroRate"); public static RoleConstants SETTLE_BILL = new RoleConstants("Sales/SettleBill"); diff --git a/Tanshu.Accounts.Contracts/Tanshu.Accounts.Contracts.csproj b/Tanshu.Accounts.Contracts/Tanshu.Accounts.Contracts.csproj index a8f4542..d6fe866 100644 --- a/Tanshu.Accounts.Contracts/Tanshu.Accounts.Contracts.csproj +++ b/Tanshu.Accounts.Contracts/Tanshu.Accounts.Contracts.csproj @@ -93,6 +93,7 @@ + @@ -114,6 +115,7 @@ + diff --git a/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs b/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs index 4aaced5..7e0847a 100644 --- a/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs +++ b/Tanshu.Accounts.PointOfSale/Controllers/BillController.cs @@ -1,11 +1,9 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using Tanshu.Accounts.Contracts; using Tanshu.Accounts.Entities; using Tanshu.Accounts.Helpers; -using Tanshu.Accounts.PointOfSale.Sales; using Tanshu.Accounts.Print; using Tanshu.Accounts.Repository; using Tanshu.Common; @@ -62,35 +60,7 @@ namespace Tanshu.Accounts.PointOfSale this._saleForm.SetUserName(Session.User.Name); } - private void InitComponents() - { - InitModel(); - InitView(); - } - - private void InitView() - { - throw new NotImplementedException(); - } - - private void InitModel() - { - throw new NotImplementedException(); - } - - public void AddProductToGrid(Product product) - { - AddProduct(product); - using (var bi = new ProductGroupModifierBI(false)) - if (bi.HasCompulsoryModifier(product.ProductGroup.ProductGroupID)) - { - var item = CurrentProduct; - ShowModifiers(product.ProductGroup.ProductGroupID, item); - } - ShowAmount(); - } - - private void AddProduct(Product product) + public void AddProduct(Product product) { var newKey = new BillItemKey(product.ProductID, 0); @@ -101,19 +71,10 @@ namespace Tanshu.Accounts.PointOfSale } else { - var billItemValue = new BillItemValue(product) - { - ProductID = product.ProductID, - Name = product.Units == string.Empty ? product.Name : product.Name + " (" + product.Units + ")", - Price = product.SalePrice, - Tax = product.Tax.Rate, - ServiceCharge = product.ServiceCharge, - Discount = 0, - Printed = false, - Quantity = 1, - }; - - var old = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.ProductID == newKey.ProductID).FirstOrDefault(); + var billItemValue = new BillItemValue(product); + var old = + _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.ProductID == newKey.ProductID). + FirstOrDefault(); if (old.Key != null) { billItemValue.Discount = old.Value.Discount; @@ -122,9 +83,16 @@ namespace Tanshu.Accounts.PointOfSale _bill.Add(newKey, billItemValue); _saleForm.BindingSource.DataSource = _bill.Values.ToList(); _saleForm.BindingSource.CurrencyManager.Position = _saleForm.BindingSource.CurrencyManager.Count - 1; - } - } + using (var bi = new ProductGroupModifierBI(false)) + if (bi.HasCompulsoryModifier(product.ProductGroup.ProductGroupID)) + { + var item = CurrentProduct; + ShowModifiers(product.ProductGroup.ProductGroupID, item); + } + } + ShowAmount(); + } public void ShowModifiers(int productGroupID, BillItemValue item) { @@ -172,6 +140,7 @@ namespace Tanshu.Accounts.PointOfSale } ShowAmount(); } + public void ShowCustomerList(bool reset) { if ((_customer.CustomerID == 1) && (!reset)) @@ -200,17 +169,30 @@ namespace Tanshu.Accounts.PointOfSale } } + private Customer selectCustomer_customerEvent(object sender, CustomerEventArgs e) + { + using (var form = new CustomersForm(e.CustomerID, e.Phone)) + { + form.ShowDialog(); + return form.Customer; + } + } + public void VoidBill() { + #region Check conditions and Permissions if (_billInfo == null) return; - if (!_billInfo.Printed) + //if (!_billInfo.Printed) + // return; + if (_billInfo.Void) return; if (!Session.IsAllowed(RoleConstants.VOID_BILL)) return; - if (MessageBox.Show("Are you sure you want to void this bill?", "Void Bill", MessageBoxButtons.YesNo, - MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes) + if (MessageBox.Show("Are you sure you want to void this bill?", "Void Bill", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes) return; + #endregion + var voidReason = new SelectVoidReason(GetVoidReason, true); voidReason.ShowDialog(); if (voidReason.SelectedItem != null) @@ -230,17 +212,7 @@ namespace Tanshu.Accounts.PointOfSale } else { - MessageBox.Show("Please Select a reason if you want to void the bill", "Bill NOT Voided", - MessageBoxButtons.OK, MessageBoxIcon.Asterisk); - } - } - - private Customer selectCustomer_customerEvent(object sender, CustomerEventArgs e) - { - using (var form = new CustomersForm(e.CustomerID, e.Phone)) - { - form.ShowDialog(); - return form.Customer; + MessageBox.Show("Please Select a reason if you want to void the bill", "Bill NOT Voided", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } @@ -262,29 +234,26 @@ namespace Tanshu.Accounts.PointOfSale private void ShowAmount() { - //saleForm.BindingSource.CurrencyManager.Position = 1; - var taxAmount = _bill.Values.Sum(b => b.TaxAmount); 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); - //bill.Values.ToList(); _saleForm.ShowAmount(discountAmount, grossAmount, serviceChargeAmount, taxAmount, valueAmount, _bill.Values.ToList()); } - public void ProductRemove() - { - var item = CurrentProduct; - if (!Allowed(item)) - return; - if (item.Printed) - return; - _bill.Remove(new BillItemKey(item.ProductID, 0)); - _bill.ReCompact(); - ShowAmount(); - } + //public void ProductRemove() + //{ + // var item = CurrentProduct; + // if (!Allowed(item)) + // return; + // if (item.Printed) + // return; + // _bill.Remove(new BillItemKey(item.ProductID, 0)); + // _bill.ReCompact(); + // ShowAmount(); + //} public void SetQuantity(decimal quantity, bool prompt) { @@ -324,9 +293,7 @@ namespace Tanshu.Accounts.PointOfSale private bool Allowed(BillItemValue item, RoleConstants role) { - if (item == null) - return false; - return Session.IsAllowed(role); + return item != null && Session.IsAllowed(role); } private bool Allowed(BillItemValue item) @@ -344,67 +311,50 @@ namespace Tanshu.Accounts.PointOfSale _bill.Clear(); _billInfo = null; using (var bi = new VoucherBI(false)) + { _billInfo = bi.Get(voucherID); - _customer = _billInfo.Customer; - _saleForm.ShowInfo(_billInfo.BillID, _billInfo.KotID, _billInfo.CreationDate, _billInfo.Date.Value, - _billInfo.LastEditDate, _customer.Name, _billInfo.TableID, _billInfo.Waiter.WaiterID, - _billInfo.Waiter.Name); + _customer = _billInfo.Customer; + _saleForm.ShowInfo(_billInfo.BillID, _billInfo.KotID, _billInfo.CreationDate, _billInfo.Date.Value, + _billInfo.LastEditDate, _customer.Name, _billInfo.TableID, _billInfo.Waiter.WaiterID, + _billInfo.Waiter.Name); - foreach (var kot in _billInfo.Kots) - { - var kotKey = new BillItemKey(kot.KotID); - var kotItem = new BillItemValue(null) - { - ProductID = kot.KotID, - Discount = 0, - Name = string.Format("Kot: {0} / {1:dd-MMM HH:mm} ({2})", kot.Code, kot.Date, kot.User.Name), - Price = 0, - Printed = true, - Quantity = 0, - Tax = -1, - ServiceCharge = 0, - }; - _bill.Add(kotKey, kotItem); - foreach (var inv in kot.Inventories) + foreach (var kot in _billInfo.Kots) { - 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.Rate, - Printed = true, - Quantity = inv.Quantity, - Tax = inv.Tax, - ServiceCharge = inv.ServiceCharge, - }; - foreach (var mod in inv.InventoryModifier) - item.Modifiers.Add(mod.Modifier); - _bill.Add(key, item); + var kotKey = new BillItemKey(kot.KotID); + var kotItem = new BillItemValue(kot); + _bill.Add(kotKey, kotItem); + 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.Rate, + Printed = true, + Quantity = inv.Quantity, + Tax = inv.Tax, + ServiceCharge = inv.ServiceCharge, + }; + foreach (var mod in inv.InventoryModifier) + item.Modifiers.Add(mod.Modifier); + _bill.Add(key, item); + } } + var newKotKey = new BillItemKey(0); + var newKotItem = new BillItemValue(); + _bill.Add(newKotKey, newKotItem); + ShowAmount(); + _saleForm.FormState = SaleFormState.Billing; } - var newKotKey = new BillItemKey(0); - var newKotItem = new BillItemValue(null) - { - ProductID = 0, - Discount = 0, - Name = "== New Kot ==", - Price = 0, - Printed = true, - Quantity = 0, - Tax = -1, - ServiceCharge = 0, - }; - _bill.Add(newKotKey, newKotItem); - ShowAmount(); } - public void LoadBillFromTable(string tableName) + public void LoadBill(string tableName) { if (!string.IsNullOrEmpty(tableName)) { @@ -420,7 +370,7 @@ namespace Tanshu.Accounts.PointOfSale { var result = "0"; if (GetInput("Table Number", ref result)) - LoadBillFromTable(result); + LoadBill(result); else ClearBill(); } @@ -441,19 +391,9 @@ namespace Tanshu.Accounts.PointOfSale ShowCustomerList(true); _bill.Clear(); var newKotKey = new BillItemKey(0); - var newKotItem = new BillItemValue(null) - { - ProductID = 0, - Discount = 0, - Name = "== New Kot ==", - Price = 0, - Printed = true, - Quantity = 0, - Tax = -1, - ServiceCharge = 0, - }; + var newKotItem = new BillItemValue(); _bill.Add(newKotKey, newKotItem); - _saleForm.ClearBill(_bill); + _saleForm.ClearBill(_bill.Values.ToList()); } public SaleFormState FormLoad() @@ -519,6 +459,8 @@ namespace Tanshu.Accounts.PointOfSale var table = GetTableForMove(true); if (table == null) return; + if (_billInfo.TableID == table.Name) + return; var kotCount = _bill.Keys.Count(x => x.BillItemType == BillItemType.Kot && x.KotID != 0); var voucherID = 0; if (table.VoucherID == 0 && kotCount > 1) @@ -553,16 +495,14 @@ namespace Tanshu.Accounts.PointOfSale { if (!Session.IsAllowed(RoleConstants.MOVE_KOT)) return 0; - var voucher = new Voucher + var voucher = new Voucher(Session.User) { Customer = _billInfo.Customer, TableID = table.Name, Waiter = _billInfo.Waiter, - Printed = false, + Printed = _billInfo.Printed, Void = false, - Date = DateTime.Now, Narration = "", - User = Session.User }; using (var session = SessionManager.Session) @@ -600,6 +540,8 @@ namespace Tanshu.Accounts.PointOfSale { if (!Session.IsAllowed(RoleConstants.MERGE_TABLE)) return 0; + if (_billInfo.Printed) + return 0; var kots = _bill.Keys.Where(x => x.BillItemType == BillItemType.Kot && x.KotID != 0); foreach (var item in kots) MergeKot(item, table); @@ -614,13 +556,26 @@ namespace Tanshu.Accounts.PointOfSale { if (!Session.IsAllowed(RoleConstants.PRINT_BILL)) return; - using (var bi = new VoucherBI(false)) - if ((_billInfo != null) && (bi.IsVoucherPrinted(_billInfo.VoucherID)) && (!Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL))) - return; if (_bill.Count == 1) //new kot only return; + if (_billInfo.Void) //voided bills not allowed + { + MessageBox.Show(string.Format("This Bill is already void.\nReason: {0}", _billInfo.VoidReason), "Bill already Voided", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + var printed = false; + if (_billInfo != null) + using (var bi = new VoucherBI(false)) + printed = bi.IsVoucherPrinted(_billInfo.VoucherID); + if (printed && (!Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL))) + return; + var amount = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != 0).Sum(x => x.Value.GrossAmount); ShowDiscount(); - var saved = _billInfo == null ? InsertVoucher(true, waiterID, tableID, !_editVoucherID.HasValue) : UpdateVoucher(true, waiterID, tableID, !_editVoucherID.HasValue); + if (printed) + SaveReprintOrDiscountBill(waiterID, tableID, amount); + else + SaveNewBill(waiterID, tableID); if (!_editVoucherID.HasValue || _print) Thermal.PrintBill(_billInfo.VoucherID); @@ -628,13 +583,72 @@ namespace Tanshu.Accounts.PointOfSale _saleForm.CloseWindow(); ClearBill(); } + public void SaveNewBill(int waiterID, string tableID) + { + var saved = _billInfo == null + ? InsertVoucher(true, waiterID, tableID, !_editVoucherID.HasValue) + : UpdateVoucher(true, waiterID, tableID, !_editVoucherID.HasValue); + + + } + public void SaveReprintOrDiscountBill(int waiterID, string tableID, decimal oldAmount) + { + var amountChanged = oldAmount != _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != 0).Sum(x => x.Value.GrossAmount); + var itemsChanged = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID == 0).Count() != 0; + if (amountChanged || itemsChanged) // Discount or Products changed + { + #region new voucherFirst + var voucherNew = new Voucher(Session.User) + { + Customer = _billInfo.Customer, + TableID = _billInfo.TableID, + Waiter = _billInfo.Waiter, + Printed = true, + Void = false, + Narration = "" + }; + + var kotNew = GetKot(_bill.Where(x => x.Key.BillItemType == BillItemType.Product)); + if (kotNew != null) + voucherNew.Kots.Add(kotNew); + #endregion + + #region Old Voucher + _billInfo.User = Session.User; + _billInfo.Void = true; + + #endregion + using (var session = SessionManager.Session) + { + using (var trans = session.BeginTransaction()) + { + using (var bi = new VoucherBI(session, false)) + { + bi.Insert(voucherNew); + _billInfo.VoidReason = string.Format("Bill Discounted / Changed. New Bill ID is {0}", voucherNew.BillID); + bi.Update(_billInfo); + } + using (var ft = new FoodTableBI(session, false)) + ft.UpdateStatus(voucherNew); + + trans.Commit(); + } + } + LoadBill(voucherNew.VoucherID); + } + else + { + using (var bi = new ReprintBI()) + bi.Insert(new Reprint() { Date = DbValues.Date, User = Session.User, Voucher = _billInfo }); + } + } public void SaveKot(int waiterID, string tableID) { if (!Session.IsAllowed(RoleConstants.PRINT_KOT)) return; - using (var bi = new VoucherBI(false)) - if ((_billInfo != null) && (bi.IsVoucherPrinted(_billInfo.VoucherID)) && (!Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL))) + using (var bi = new VoucherBI(false)) // Kot on printed bill not allowed + if ((_billInfo != null) && (bi.IsVoucherPrinted(_billInfo.VoucherID))) return; if (_bill.Count == 1) //new kot only return; @@ -655,7 +669,7 @@ namespace Tanshu.Accounts.PointOfSale MessageBox.Show("Error in InsertVoucher, there is a previous sale in memory", "Error"); return null; } - _billInfo = new Voucher + _billInfo = new Voucher(Session.User) { Customer = _customer, //Paid = finalBill, @@ -663,12 +677,10 @@ namespace Tanshu.Accounts.PointOfSale Waiter = WaiterBI.GetWaiter(waiterID), Printed = finalBill, Void = false, - Date = DateTime.Now, Narration = "", - User = Session.User }; UpdateKots(); - var kot = GetKotForBill(); + var kot = GetKot(_bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID == 0 && x.Value.Quantity != 0)); if (kot != null) _billInfo.Kots.Add(kot); using (var session = SessionManager.Session) @@ -691,15 +703,20 @@ namespace Tanshu.Accounts.PointOfSale { _billInfo.User = Session.User; _billInfo.Customer = _customer; - if (!_billInfo.Printed && finalBill) - _billInfo.Date = null; - _billInfo.Printed = _billInfo.Printed || finalBill; + _billInfo.TableID = tableID; _billInfo.Waiter = WaiterBI.GetWaiter(waiterID); + UpdateKots(); - var kot = GetKotForBill(); - if (kot != null) - _billInfo.Kots.Add(kot); + if (!_billInfo.Printed) + { + var kot = GetKot(_bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID == 0 && x.Value.Quantity != 0)); + if (kot != null) + _billInfo.Kots.Add(kot); + } + + _billInfo.Printed = finalBill; + using (var session = SessionManager.Session) { using (var trans = session.BeginTransaction()) @@ -725,24 +742,35 @@ namespace Tanshu.Accounts.PointOfSale i.Rate = item.Value.Price; } } - private Kot GetKotForBill() + private static Kot GetKot(IEnumerable> list) { var kot = new Kot(); - foreach (var item in _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID == 0 && x.Value.Quantity != 0)) + foreach (var item in list) { - var inv = new Inventory - { - Product = item.Value.Product, - Quantity = item.Value.Quantity, - Rate = item.Value.Price, - Discount = item.Value.Discount, - ServiceCharge = item.Value.ServiceCharge, - Tax = item.Value.Tax - }; - foreach (var mod in item.Value.Modifiers) - inv.InventoryModifier.Add(new InventoryModifier { Modifier = mod }); - kot.Inventories.Add(inv); + var oldInv = kot.Inventories.SingleOrDefault(x => x.Product.ProductID == item.Key.ProductID); + if (oldInv != null) + { + oldInv.Quantity += item.Value.Quantity; + if (oldInv.Quantity == 0) + kot.Inventories.Remove(oldInv); + } + else + { + var inv = new Inventory + { + Product = item.Value.Product, + Quantity = item.Value.Quantity, + Rate = item.Value.Price, + Discount = item.Value.Discount, + ServiceCharge = item.Value.ServiceCharge, + Tax = item.Value.Tax + }; + foreach (var mod in item.Value.Modifiers) + inv.InventoryModifier.Add(new InventoryModifier { Modifier = mod }); + kot.Inventories.Add(inv); + } } + return kot.Inventories.Count == 0 ? null : kot; } @@ -769,5 +797,108 @@ namespace Tanshu.Accounts.PointOfSale } #endregion + + public void SplitBill() + { + #region Permissions + if (_billInfo == null || _billInfo.VoucherID == 0 || _billInfo.Void == true) + return; // must be existing non void bill + + if (!Session.IsAllowed(RoleConstants.SPLIT_BILL)) + return; + #endregion + + bool printed; + using (var bi = new VoucherBI(false)) + printed = bi.IsVoucherPrinted(_billInfo.VoucherID); + + #region Get Move List + HashSet splitList = null; + using (var bi = new ProductGroupBI()) + { + using (var frm = new DiscountForm(bi.GetProductGroupTypes())) + if (frm.ShowDialog() == DialogResult.OK) + frm.Selection(out splitList); + } + if (splitList == null || splitList.Count == 0) + return; + + var listFirst = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != 0 && splitList.Contains(x.Value.Product.ProductGroup.GroupType)); + var listSecond = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != 0 && !splitList.Contains(x.Value.Product.ProductGroup.GroupType)); + + if (listFirst.Count() == 0 || listSecond.Count() == 0) + return; // all or none items selected to be moved + #endregion + + var table = GetTableForMove(false); + if (table == null) + return; + + #region new voucherFirst + var voucherFirst = new Voucher(Session.User) + { + Customer = _billInfo.Customer, + TableID = table.Name, + Waiter = _billInfo.Waiter, + Printed = printed, + Void = false, + Narration = "" + }; + + var kotFirst = GetKot(listFirst); + if (kotFirst != null) + voucherFirst.Kots.Add(kotFirst); + #endregion + + #region new voucherFirst + var voucherSecond = new Voucher(Session.User) + { + Customer = _billInfo.Customer, + TableID = _billInfo.TableID, + Waiter = _billInfo.Waiter, + Printed = printed, + Void = false, + Narration = "" + }; + + var kotSecond = GetKot(listSecond); + if (kotSecond != null) + voucherSecond.Kots.Add(kotSecond); + #endregion + + #region Old Voucher + _billInfo.User = Session.User; + _billInfo.Void = true; + _billInfo.VoidReason = "Printed bill Split"; + #endregion + using (var session = SessionManager.Session) + { + var trans = session.BeginTransaction(); + using (var bi = new VoucherBI(session, false)) + bi.Insert(voucherFirst); + trans.Commit(); + trans = session.BeginTransaction(); + using (var bi = new VoucherBI(session, false)) + bi.Insert(voucherSecond); + trans.Commit(); + trans = session.BeginTransaction(); + using (var bi = new VoucherBI(session, false)) + bi.Update(_billInfo); + trans.Commit(); + trans = session.BeginTransaction(); + using (var ft = new FoodTableBI(session, false)) + ft.UpdateStatus(voucherFirst); + using (var ft = new FoodTableBI(session, false)) + ft.UpdateStatus(voucherSecond); + trans.Commit(); + trans.Dispose(); + } + if (printed) + { + Thermal.PrintBill(voucherFirst.VoucherID); + Thermal.PrintBill(voucherSecond.VoucherID); + } + LoadBill(voucherFirst.VoucherID); + } } } \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Controllers/ISaleForm.cs b/Tanshu.Accounts.PointOfSale/Controllers/ISaleForm.cs index 9975e52..d1a2d1b 100644 --- a/Tanshu.Accounts.PointOfSale/Controllers/ISaleForm.cs +++ b/Tanshu.Accounts.PointOfSale/Controllers/ISaleForm.cs @@ -10,12 +10,13 @@ namespace Tanshu.Accounts.PointOfSale { public interface ISaleForm { - void ClearBill(OrderedDictionary bill); + void ClearBill(List bill); void SetCustomerDisplay(string name); void CloseWindow(); void ShowAmount(decimal discountAmount, decimal grossAmount, decimal serviceChargeAmount, decimal taxAmount, decimal valueAmount, List bill); void ShowInfo(string billID, string kotID, DateTime creationDate, DateTime date, DateTime lastEditDate, string customer, string tableID, int waiterID, string waiter); void SetUserName(string name); BindingSource BindingSource { get; } + SaleFormState FormState { set; } } } diff --git a/Tanshu.Accounts.PointOfSale/Products/ProductListForm.Designer.cs b/Tanshu.Accounts.PointOfSale/Products/ProductListForm.Designer.cs index e1ea39e..40de627 100644 --- a/Tanshu.Accounts.PointOfSale/Products/ProductListForm.Designer.cs +++ b/Tanshu.Accounts.PointOfSale/Products/ProductListForm.Designer.cs @@ -213,10 +213,10 @@ internal System.Windows.Forms.Button btnExit; private System.Windows.Forms.DataGridView dgvProductTypes; private System.Windows.Forms.BindingSource bsList; - private System.Windows.Forms.DataGridViewTextBoxColumn discountLimitDataGridViewTextBoxColumn; - private System.Windows.Forms.DataGridViewTextBoxColumn groupTypeDataGridViewTextBoxColumn; - private System.Windows.Forms.DataGridViewTextBoxColumn productGroupDataGridViewTextBoxColumn; - private System.Windows.Forms.DataGridViewTextBoxColumn taxDataGridViewTextBoxColumn; + //private System.Windows.Forms.DataGridViewTextBoxColumn discountLimitDataGridViewTextBoxColumn; + //private System.Windows.Forms.DataGridViewTextBoxColumn groupTypeDataGridViewTextBoxColumn; + //private System.Windows.Forms.DataGridViewTextBoxColumn productGroupDataGridViewTextBoxColumn; + //private System.Windows.Forms.DataGridViewTextBoxColumn taxDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewTextBoxColumn nameDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewTextBoxColumn unitsDataGridViewTextBoxColumn; private System.Windows.Forms.DataGridViewTextBoxColumn Tax; diff --git a/Tanshu.Accounts.PointOfSale/Sales/SalesForm.Designer.cs b/Tanshu.Accounts.PointOfSale/Sales/SalesForm.Designer.cs index 0617d4b..4b94528 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 dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = 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(); @@ -81,6 +81,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales this.btnCustomer = new System.Windows.Forms.Button(); this.bsWaiter = new System.Windows.Forms.BindingSource(this.components); this.bsPending = new System.Windows.Forms.BindingSource(this.components); + this.btnSplitBill = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dgvProducts)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.bindingSource)).BeginInit(); this.pnlBilling.SuspendLayout(); @@ -204,15 +205,14 @@ namespace Tanshu.Accounts.PointOfSale.Sales this.dgvProducts.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dgvProducts.Size = new System.Drawing.Size(372, 412); this.dgvProducts.TabIndex = 0; - this.dgvProducts.VirtualMode = true; this.dgvProducts.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.dgvProducts_CellFormatting); // // Display // this.Display.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells; this.Display.DataPropertyName = "Display"; - dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.Display.DefaultCellStyle = dataGridViewCellStyle1; + dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.Display.DefaultCellStyle = dataGridViewCellStyle3; this.Display.HeaderText = "Display"; this.Display.MinimumWidth = 250; this.Display.Name = "Display"; @@ -223,9 +223,9 @@ namespace Tanshu.Accounts.PointOfSale.Sales // 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; + dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight; + dataGridViewCellStyle4.Format = "N2"; + this.printedDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle4; this.printedDataGridViewTextBoxColumn.HeaderText = "Printed"; this.printedDataGridViewTextBoxColumn.Name = "printedDataGridViewTextBoxColumn"; this.printedDataGridViewTextBoxColumn.ReadOnly = true; @@ -306,6 +306,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales this.flpActions.Controls.Add(this.btnSettle); this.flpActions.Controls.Add(this.btnMore); this.flpActions.Controls.Add(this.btnMoveKot); + this.flpActions.Controls.Add(this.btnSplitBill); this.flpActions.Dock = System.Windows.Forms.DockStyle.Bottom; this.flpActions.Location = new System.Drawing.Point(0, 607); this.flpActions.Name = "flpActions"; @@ -594,6 +595,16 @@ namespace Tanshu.Accounts.PointOfSale.Sales // this.bsPending.DataSource = typeof(Tanshu.Accounts.Contracts.PendingBills); // + // btnSplitBill + // + this.btnSplitBill.Location = new System.Drawing.Point(165, 84); + this.btnSplitBill.Name = "btnSplitBill"; + this.btnSplitBill.Size = new System.Drawing.Size(75, 75); + this.btnSplitBill.TabIndex = 161; + this.btnSplitBill.Text = "Split Bill"; + this.btnSplitBill.UseVisualStyleBackColor = true; + this.btnSplitBill.Click += new System.EventHandler(this.btnSplitBill_Click); + // // SalesForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -670,6 +681,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales private System.Windows.Forms.Button btnMore; private System.Windows.Forms.Button btnMoveKot; private readonly BillController _billController; + private System.Windows.Forms.Button btnSplitBill; } } diff --git a/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs b/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs index ce20aad..737d7a9 100644 --- a/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs +++ b/Tanshu.Accounts.PointOfSale/Sales/SalesForm.cs @@ -99,13 +99,13 @@ namespace Tanshu.Accounts.PointOfSale.Sales //{ // selectProduct.ShowDialog(); // if (selectProduct.SelectedItem != null) - // _billController.AddProductToGrid(selectProduct.SelectedItem.ProductID); + // _billController.AddProduct(selectProduct.SelectedItem.ProductID); //} break; } case Keys.F8: { - _billController.LoadBillFromTable(null); + _billController.LoadBill(null); break; } case Keys.F11: @@ -120,7 +120,8 @@ namespace Tanshu.Accounts.PointOfSale.Sales } case Keys.Delete: { - _billController.ProductRemove(); + _billController.SetQuantity(-1, false); + //_billController.ProductRemove(); break; } case Keys.Add: @@ -156,7 +157,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales private void SalesForm_Load(object sender, EventArgs e) { _billController.FormLoad(); - ChangeFormState(SaleFormState.Waiting); + FormState = SaleFormState.Waiting; } private void btnCustomer_Click(object sender, EventArgs e) @@ -276,6 +277,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales private void btnMoveTable_Click(object sender, EventArgs e) { _billController.MoveTable(); + } private void btnMore_Click(object sender, EventArgs e) @@ -300,6 +302,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales btnMoveTable.Visible = more; btnMoveKot.Visible = more; btnVoid.Visible = more; + btnSplitBill.Visible = more; } private void btnMoveKot_Click(object sender, EventArgs e) @@ -309,7 +312,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales #region Helper Functions - public void ClearBill(OrderedDictionary bill) + public void ClearBill(List bill) { txtBillID.Text = ""; txtKotID.Text = ""; @@ -324,9 +327,10 @@ namespace Tanshu.Accounts.PointOfSale.Sales txtServiceCharge.Text = "0.00"; txtGrossAmount.Text = "0.00"; txtAmount.Text = "0.00"; - bindingSource.DataSource = bill.Values; + bindingSource.CurrencyManager.Position = 0; //Hack for Mono + bindingSource.DataSource = bill; MoreButton(false); - ChangeFormState(SaleFormState.Waiting); + FormState = SaleFormState.Waiting; } public void ShowAmount(decimal discountAmount, decimal grossAmount, decimal serviceChargeAmount, @@ -341,15 +345,19 @@ namespace Tanshu.Accounts.PointOfSale.Sales dgvProducts.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells); } - private void ChangeFormState(SaleFormState state) + public SaleFormState FormState { - flpGroup.Controls.Clear(); - flpMain.Controls.Clear(); - if (state == SaleFormState.Billing) - ControlFactory.GenerateGroups(ref flpGroup, new Point(75, 75), 0, _productGroupList, productTypeButton_Click); - else - using (var bi = new FoodTableBI()) - ControlFactory.GenerateTables(ref flpMain, new Point(75, 75), 0, bi.List(), tableButton_Click); + set + { + flpGroup.Controls.Clear(); + flpMain.Controls.Clear(); + if (value == SaleFormState.Billing) + ControlFactory.GenerateGroups(ref flpGroup, new Point(75, 75), 0, _productGroupList, productTypeButton_Click); + else + using (var bi = new FoodTableBI()) + ControlFactory.GenerateTables(ref flpMain, new Point(75, 75), 0, bi.List(), tableButton_Click); + + } } private void productTypeButton_Click(object sender, EventArgs e) @@ -388,7 +396,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales } else { - _billController.AddProductToGrid(item); + _billController.AddProduct(item); } } @@ -409,10 +417,10 @@ namespace Tanshu.Accounts.PointOfSale.Sales } else { - string tableName = item.Name; - _billController.LoadBillFromTable(tableName); + var tableName = item.Name; + _billController.LoadBill(tableName); txtTableID.Text = tableName; - ChangeFormState(SaleFormState.Billing); + FormState = SaleFormState.Billing; } } @@ -431,11 +439,6 @@ namespace Tanshu.Accounts.PointOfSale.Sales _billController.SaveKot((int)btnWaiter.Tag, txtTableID.Text); } - private void btnCancel_Click(object sender, EventArgs e) - { - _billController.CancelBillChanges(); - } - private void btnQuantity_Click(object sender, EventArgs e) { _billController.SetQuantity(0, true); @@ -444,11 +447,13 @@ namespace Tanshu.Accounts.PointOfSale.Sales private void btnDiscount_Click(object sender, EventArgs e) { _billController.ShowDiscount(); - - //if (dgvProducts.Rows.Count > 0) - // billController.SetDiscount(billController.CurrentProduct, -1); } #endregion + + private void btnSplitBill_Click(object sender, EventArgs e) + { + _billController.SplitBill(); + } } } \ No newline at end of file diff --git a/Tanshu.Accounts.PointOfSale/Sales/SalesForm.resx b/Tanshu.Accounts.PointOfSale/Sales/SalesForm.resx index c41ea0d..53e72f3 100644 --- a/Tanshu.Accounts.PointOfSale/Sales/SalesForm.resx +++ b/Tanshu.Accounts.PointOfSale/Sales/SalesForm.resx @@ -123,6 +123,12 @@ 17, 17 + + True + + + 17, 17 + 148, 17 diff --git a/Tanshu.Accounts.PointOfSale/Sales/FrmSettleAmounts.Designer.cs b/Tanshu.Accounts.PointOfSale/Sales/SettleAmountsForm.Designer.cs similarity index 96% rename from Tanshu.Accounts.PointOfSale/Sales/FrmSettleAmounts.Designer.cs rename to Tanshu.Accounts.PointOfSale/Sales/SettleAmountsForm.Designer.cs index 97844bd..003372b 100644 --- a/Tanshu.Accounts.PointOfSale/Sales/FrmSettleAmounts.Designer.cs +++ b/Tanshu.Accounts.PointOfSale/Sales/SettleAmountsForm.Designer.cs @@ -1,6 +1,6 @@ namespace Tanshu.Accounts.PointOfSale { - partial class FrmSettleAmounts + partial class SettleAmountsForm { /// /// Required designer variable. @@ -52,7 +52,7 @@ this.txtCurrentAmount.TabIndex = 0; this.txtCurrentAmount.KeyDown += new System.Windows.Forms.KeyEventHandler(this.TxtCurrentAmountKeyDown); // - // FrmSettleAmounts + // SettleAmountsForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; @@ -62,7 +62,7 @@ this.Controls.Add(this.txtAmount); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; this.MaximizeBox = false; - this.Name = "FrmSettleAmounts"; + this.Name = "SettleAmountsForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Settle Bill"; this.Load += new System.EventHandler(this.SettleChoicesFormLoad); diff --git a/Tanshu.Accounts.PointOfSale/Sales/FrmSettleAmounts.cs b/Tanshu.Accounts.PointOfSale/Sales/SettleAmountsForm.cs similarity index 92% rename from Tanshu.Accounts.PointOfSale/Sales/FrmSettleAmounts.cs rename to Tanshu.Accounts.PointOfSale/Sales/SettleAmountsForm.cs index 33c1bab..646ee02 100644 --- a/Tanshu.Accounts.PointOfSale/Sales/FrmSettleAmounts.cs +++ b/Tanshu.Accounts.PointOfSale/Sales/SettleAmountsForm.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using Tanshu.Accounts.Entities; @@ -8,13 +7,13 @@ using Tanshu.Common.KeyboardControl; namespace Tanshu.Accounts.PointOfSale { - public partial class FrmSettleAmounts : Form + public partial class SettleAmountsForm : Form { private IKeyboardControl _keyboardControl; private readonly decimal _amount; private readonly SettleOption _settleOption; private decimal _settleAmount; - public FrmSettleAmounts(IKeyboardControl keyboardControl, SettleOption settleOption, decimal amount) + public SettleAmountsForm(IKeyboardControl keyboardControl, SettleOption settleOption, decimal amount) { InitializeComponent(); diff --git a/Tanshu.Accounts.PointOfSale/Sales/FrmSettleAmounts.resx b/Tanshu.Accounts.PointOfSale/Sales/SettleAmountsForm.resx similarity index 100% rename from Tanshu.Accounts.PointOfSale/Sales/FrmSettleAmounts.resx rename to Tanshu.Accounts.PointOfSale/Sales/SettleAmountsForm.resx diff --git a/Tanshu.Accounts.PointOfSale/Sales/SettleChoicesForm.cs b/Tanshu.Accounts.PointOfSale/Sales/SettleChoicesForm.cs index 72c6a14..aa5d6bf 100644 --- a/Tanshu.Accounts.PointOfSale/Sales/SettleChoicesForm.cs +++ b/Tanshu.Accounts.PointOfSale/Sales/SettleChoicesForm.cs @@ -30,7 +30,7 @@ namespace Tanshu.Accounts.PointOfSale if (button.Tag is SettleOption) { var settleOption = (SettleOption)button.Tag; - using (var frm = new FrmSettleAmounts(new NumpadControl(), settleOption, _amount)) + using (var frm = new SettleAmountsForm(new NumpadControl(), settleOption, _amount)) { frm.ShowDialog(); UpdateChoice(settleOption, frm.AmountSettled, _list[button]); diff --git a/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj b/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj index db9680d..ea76f5f 100644 --- a/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj +++ b/Tanshu.Accounts.PointOfSale/Tanshu.Accounts.PointOfSale.csproj @@ -155,11 +155,11 @@ SaleDetail.cs - + Form - - frmSettleAmounts.cs + + SettleAmountsForm.cs Form @@ -282,8 +282,8 @@ SaleDetail.cs Designer - - frmSettleAmounts.cs + + SettleAmountsForm.cs SettleChoicesForm.cs diff --git a/Tanshu.Accounts.Print/Thermal.cs b/Tanshu.Accounts.Print/Thermal.cs index 0d30a27..eecae69 100644 --- a/Tanshu.Accounts.Print/Thermal.cs +++ b/Tanshu.Accounts.Print/Thermal.cs @@ -23,14 +23,13 @@ namespace Tanshu.Accounts.Print private const string DrawLine = "\n\r------------------------------------------"; private const string DrawEqual = "\n\r=========================================="; - private static string DesignKot(Voucher trans, string kotCode, IEnumerable billItems, int copyNumber) + private static string DesignKot(Voucher trans, Kot kot, IEnumerable billItems, int copyNumber) { var waiter = trans.Waiter; var billText = "\n\r" + FormatText("KOT / BOT", 42, false, Align.Centre); billText += "\n\r" + FormatText(string.Format("Copy No. {0}", copyNumber), 42, false, Align.Centre); billText += DrawLine; - billText += string.Format("\n\rKOT ID : {0,-7}/{1,-7} {2:dd-MMM-yyyy HH:mm}", trans.KotID, kotCode, - trans.Date); + billText += string.Format("\n\rKOT ID : {0,-7}/{1,-7} {2:dd-MMM-yyyy HH:mm}", trans.KotID, kot.Code, kot.Date); billText += string.Format("\n\rTable No.: {0} / {1}", trans.TableID, waiter.Name); billText += DrawLine; billText += "\n\r Qty. x Name "; @@ -355,18 +354,17 @@ namespace Tanshu.Accounts.Print using (var bi = new VoucherBI(false)) voucher = bi.Get(voucherID); var dict = new Dictionary>(); - foreach (var item in voucher.Kots.Where(x => x.KotID == kotID)) + var kot = voucher.Kots.SingleOrDefault(x => x.KotID == kotID); + if (kot == null) + return; + + foreach (var inventory in kot.Inventories) { - foreach (var inventory in item.Inventories) - { - var type = inventory.Product.ProductGroup.ProductGroupID; - var printer = PrintLocationBI.KotPrinter(type); - if (!dict.ContainsKey(printer)) - { - dict.Add(printer, new List()); - } - dict[printer].Add(inventory); - } + var type = inventory.Product.ProductGroup.ProductGroupID; + var printer = PrintLocationBI.KotPrinter(type); + if (!dict.ContainsKey(printer)) + dict.Add(printer, new List()); + dict[printer].Add(inventory); } stopwatch.Stop(); Trace.TraceWarning("kot and printers built in {0} ms", stopwatch.ElapsedMilliseconds); @@ -376,9 +374,7 @@ namespace Tanshu.Accounts.Print for (var i = 0; i < item.Key.Copies; i++) { stopwatch.Start(); - PrintRaw(item.Key, - DesignKot(voucher, voucher.Kots.Where(x => x.KotID == kotID).Single().Code, item.Value, i), - "KOT"); + PrintRaw(item.Key, DesignKot(voucher, kot, item.Value, i), "KOT"); stopwatch.Stop(); Trace.TraceWarning("kot designed and printed in {0} ms", stopwatch.ElapsedMilliseconds); stopwatch.Reset(); diff --git a/Tanshu.Accounts.Print/ThermalPrinter.cs b/Tanshu.Accounts.Print/ThermalPrinter.cs index fe6d6cf..929b5cc 100644 --- a/Tanshu.Accounts.Print/ThermalPrinter.cs +++ b/Tanshu.Accounts.Print/ThermalPrinter.cs @@ -4,12 +4,10 @@ namespace Tanshu.Accounts.Print { internal class ThermalPrinter { - private static readonly bool _runningOnLinux; internal static PlatformPrinter Printer; static ThermalPrinter() { - _runningOnLinux = RunningOnLinux(); - Printer = _runningOnLinux ? (PlatformPrinter)new PrinterLinux() : new PrinterWindows(); + Printer = RunningOnLinux() ? (PlatformPrinter)new PrinterLinux() : new PrinterWindows(); } internal static bool RunningOnLinux() diff --git a/Tanshu.Accounts.Repository/BusinessLayer/ReprintBI.cs b/Tanshu.Accounts.Repository/BusinessLayer/ReprintBI.cs new file mode 100644 index 0000000..15e5d39 --- /dev/null +++ b/Tanshu.Accounts.Repository/BusinessLayer/ReprintBI.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; +using NHibernate; +using Tanshu.Accounts.Entities; + + +namespace Tanshu.Accounts.Repository +{ + public class ReprintBI : FluentGenericBase + { + public ReprintBI() + : base() + { } + public ReprintBI(bool beginTransaction) + : base(beginTransaction) + { } + public ReprintBI(ISession session) + : base(session) + { } + public ReprintBI(ISession session, bool beginTransaction) + : base(session, beginTransaction) + { } + } +} diff --git a/Tanshu.Accounts.Repository/BusinessLayer/SalesAnalysisBI.cs b/Tanshu.Accounts.Repository/BusinessLayer/SalesAnalysisBI.cs index c3d14f2..d12a130 100644 --- a/Tanshu.Accounts.Repository/BusinessLayer/SalesAnalysisBI.cs +++ b/Tanshu.Accounts.Repository/BusinessLayer/SalesAnalysisBI.cs @@ -120,7 +120,7 @@ order by g.GroupType using (var session = SessionManager.Session) { const string query = @" -select v.Date, v.BillID, s.Settled, s.Amount +select v.Date, v.BillID, s.Settled, s.Amount, v.Void, v.VoidReason from Voucher v inner join v.Settlements s where v.Date >= :startDate and v.Date <= :finishDate @@ -134,11 +134,14 @@ order by v.BillID, s.Settled var outList = new List(); foreach (var item in list) { + var settlement = ((SettleOption)item[2]).Display(); + if ((bool)item[4]) + settlement = string.Format("Void: {0}", (string)item[5]); outList.Add(new BillDetail() { Date = (DateTime)item[0], BillID = (string)item[1], - Settlement = ((SettleOption)item[2]).Display(), + Settlement = settlement, Amount = (decimal)item[3] }); } diff --git a/Tanshu.Accounts.Repository/BusinessLayer/VoucherBI.cs b/Tanshu.Accounts.Repository/BusinessLayer/VoucherBI.cs index 0f82afd..2c21056 100644 --- a/Tanshu.Accounts.Repository/BusinessLayer/VoucherBI.cs +++ b/Tanshu.Accounts.Repository/BusinessLayer/VoucherBI.cs @@ -1,5 +1,6 @@ using NHibernate.Criterion; using Tanshu.Accounts.Entities; +using Tanshu.Common.Helpers; using NHibernate; using System.Linq; @@ -27,11 +28,11 @@ namespace Tanshu.Accounts.Repository public int? Insert(Voucher voucher) { var dt = DbValues.Date; - voucher.CreationDate = dt; - voucher.LastEditDate = dt; - voucher.Date = dt; - voucher.KotID = DbValues.KotID; - voucher.BillID = voucher.Printed ? DbValues.BillID : voucher.KotID; + voucher.SetValue(VoucherFields.CreationDate, dt); + voucher.SetValue(VoucherFields.LastEditDate, dt); + voucher.SetValue(VoucherFields.Date, dt); + voucher.SetValue(VoucherFields.KotID, DbValues.KotID); + voucher.SetValue(VoucherFields.BillID, voucher.Printed ? DbValues.BillID : voucher.KotID); Kot addedKot = null; foreach (var item in voucher.Kots.Where(item => item.KotID == 0)) { @@ -47,7 +48,6 @@ namespace Tanshu.Accounts.Repository Session.Save(voucher); return addedKot == null ? (int?)null : addedKot.KotID; } - public void Delete(int voucherID) { var voucher = Session.Get(voucherID); @@ -55,18 +55,16 @@ namespace Tanshu.Accounts.Repository using (var ft = new FoodTableBI(Session, false)) ft.UpdateStatus(voucher.TableID, voucherID, null); } - public int? Update(Voucher voucher) { var dt = DbValues.Date; - voucher.LastEditDate = dt; + voucher.SetValue(VoucherFields.LastEditDate, dt); if (voucher.Date == null) { - voucher.Date = dt; - voucher.BillID = DbValues.BillID; + voucher.SetValue(VoucherFields.Date, dt); + voucher.SetValue(VoucherFields.BillID, DbValues.BillID ); } - if (!voucher.Printed) - voucher.Date = dt; + Kot addedKot = null; foreach (var item in voucher.Kots.Where(item => item.KotID == 0)) { @@ -80,10 +78,7 @@ namespace Tanshu.Accounts.Repository var amount = -1 * voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount)); VoucherSettlementBI.UpdateSettlements(voucher.Settlements, amount); Session.Update(voucher); - if (addedKot == null) - return null; - else - return addedKot.KotID; + return addedKot == null ? (int?) null : addedKot.KotID; } public Voucher Get(int voucherID) @@ -109,7 +104,6 @@ namespace Tanshu.Accounts.Repository NHibernateUtil.Initialize(item); return voucher; } - public Voucher Get(string billID) { var voucher = Session.CreateCriteria() @@ -141,5 +135,6 @@ namespace Tanshu.Accounts.Repository Session.Update(voucher); return voucher.VoucherID; } + } } diff --git a/Tanshu.Accounts.Repository/BusinessLayer/VoucherSettlementBI.cs b/Tanshu.Accounts.Repository/BusinessLayer/VoucherSettlementBI.cs index c1e1b38..a8a632c 100644 --- a/Tanshu.Accounts.Repository/BusinessLayer/VoucherSettlementBI.cs +++ b/Tanshu.Accounts.Repository/BusinessLayer/VoucherSettlementBI.cs @@ -4,6 +4,7 @@ using Tanshu.Accounts.Entities; using Tanshu.Accounts.Entities.Auth; using NHibernate; using System.Linq; +using Tanshu.Common.Helpers; namespace Tanshu.Accounts.Repository { @@ -71,7 +72,7 @@ namespace Tanshu.Accounts.Repository var amount = -1 * voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount)); UpdateSettlements(voucher.Settlements, amount); voucher.User = user; - voucher.LastEditDate = DbValues.Date; + voucher.SetValue(VoucherFields.LastEditDate, DbValues.Date); Session.Update(voucher); using (var ft = new FoodTableBI(Session, false)) ft.TableSettled(voucher); diff --git a/Tanshu.Accounts.Repository/Fluent/PropertyAccessConvention.cs b/Tanshu.Accounts.Repository/Fluent/PropertyAccessConvention.cs new file mode 100644 index 0000000..9a4d621 --- /dev/null +++ b/Tanshu.Accounts.Repository/Fluent/PropertyAccessConvention.cs @@ -0,0 +1,36 @@ +using System; +using System.Reflection; +using FluentNHibernate.Conventions; +using FluentNHibernate.Conventions.Inspections; +using FluentNHibernate.Conventions.Instances; + +namespace Tanshu.Accounts.Conventions +{ + public class PropertyAccessConvention : IPropertyConvention + { + public void Apply(IPropertyInstance instance) + { + var entityType = instance.EntityType; + var camelCaseUnderscoreName = ConvertToCamelCaseUnderscore(instance.Name); + + // Default is to use property setter, so only modify mapping + // if there is a backing field + + if (HasField(entityType, camelCaseUnderscoreName)) + instance.Access.CamelCaseField(CamelCasePrefix.Underscore); + } + + private static string ConvertToCamelCaseUnderscore(string propertyName) + { + return "_" + propertyName[0].ToString().ToLower() + propertyName.Substring(1); + } + + private static bool HasField(Type type, string fieldName) + { + var backingField = type.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance); + return backingField != null; + } + } +} + + diff --git a/Tanshu.Accounts.Repository/Fluent/SetupStore.cs b/Tanshu.Accounts.Repository/Fluent/SetupStore.cs index 81d4b6f..45b3b6e 100644 --- a/Tanshu.Accounts.Repository/Fluent/SetupStore.cs +++ b/Tanshu.Accounts.Repository/Fluent/SetupStore.cs @@ -59,7 +59,7 @@ namespace Tanshu.Accounts.Repository c.Add(); c.Add(); c.Add(); - //c.Add(); + c.Add(); c.Add(); }); diff --git a/Tanshu.Accounts.Repository/Tanshu.Accounts.Repository.csproj b/Tanshu.Accounts.Repository/Tanshu.Accounts.Repository.csproj index a4b7b86..cb78baf 100644 --- a/Tanshu.Accounts.Repository/Tanshu.Accounts.Repository.csproj +++ b/Tanshu.Accounts.Repository/Tanshu.Accounts.Repository.csproj @@ -84,6 +84,7 @@ + @@ -95,6 +96,7 @@ +