Refactor: Instead of a concept of Price/FullPrice, happy hour is now a checkbox in the product.

This needed major refactor in all parts dealing with product or inventory.
This commit is contained in:
tanshu
2016-04-11 12:31:52 +05:30
parent 69cb7d8bce
commit 20eac3c216
35 changed files with 861 additions and 435 deletions

View File

@ -27,7 +27,7 @@ namespace Tanshu.Accounts.PointOfSale
public void AddProduct(Product product)
{
var newKey = new BillItemKey(product.ProductID, Guid.Empty);
var newKey = new BillItemKey(product.ProductID, Guid.Empty, product.HasHappyHour);
if (_bill.ContainsKey(newKey))
{
@ -35,8 +35,8 @@ namespace Tanshu.Accounts.PointOfSale
}
else
{
var billItemValue = new BillItemValue(product);
var old = _bill.FirstOrDefault(x => x.Key.BillItemType == BillItemType.Product && x.Key.ProductID == newKey.ProductID);
var billItemValue = new BillItemValue(product, product.HasHappyHour);
var old = _bill.FirstOrDefault(x => x.Key.BillItemType == (product.HasHappyHour ? BillItemType.HappyHourProduct : BillItemType.RegularProduct) && x.Key.ProductID == newKey.ProductID);
if (old.Key != null)
{
billItemValue.inventory.Discount = old.Value.inventory.Discount;
@ -70,7 +70,7 @@ namespace Tanshu.Accounts.PointOfSale
if (discount > 1 || discount < 0)
return;
foreach (var item in _bill.Where(x => x.Key.BillItemType == BillItemType.Product && outList.Contains(x.Value.inventory.Product.ProductGroup.GroupType)))
foreach (var item in _bill.Where(x => x.Key.BillItemType != BillItemType.Kot && outList.Contains(x.Value.inventory.Product.ProductGroup.GroupType)))
{
var product = item.Value.inventory.Product;
var maxDiscount = product.ProductGroup.DiscountLimit;
@ -99,6 +99,8 @@ namespace Tanshu.Accounts.PointOfSale
}
public void SetPrice(BillItemValue item)
{
if (item.inventory.IsHappyHour)
return;
if (!Session.IsAllowed("Change Rate"))
return;
var price = item.inventory.Price;
@ -106,7 +108,7 @@ namespace Tanshu.Accounts.PointOfSale
return;
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.inventory.Product.ProductID))
foreach (var sub in _bill.Where(x => x.Key.BillItemType != BillItemType.Kot && x.Key.ProductID == item.inventory.Product.ProductID))
sub.Value.inventory.Price = price;
}
public void ShowCustomers()
@ -138,7 +140,6 @@ namespace Tanshu.Accounts.PointOfSale
}
private void LoadBill(Guid voucherID)
{
ClearBill();
using (var bi = new VoucherBI())
{
_voucher = bi.Get(x => x.VoucherID == voucherID);
@ -345,7 +346,7 @@ namespace Tanshu.Accounts.PointOfSale
public bool SaveAndPrintKot()
{
#region Check if Allowed
if (!Session.IsAllowed("Print Kot") || _bill.Count(x => x.Key.BillItemType == BillItemType.Product) == 0)
if (!Session.IsAllowed("Print Kot") || _bill.Count(x => x.Key.BillItemType != BillItemType.Kot) == 0)
return false;
bool isPrinted = false, isVoid = false;
if (_voucher.VoucherID != Guid.Empty)
@ -383,7 +384,7 @@ namespace Tanshu.Accounts.PointOfSale
public bool SaveAndPrintBill()
{
#region Check if Allowed
if (!Session.IsAllowed("Print Bill") || _bill.Count(x => x.Key.BillItemType == BillItemType.Product) == 0)
if (!Session.IsAllowed("Print Bill") || _bill.Count(x => x.Key.BillItemType != BillItemType.Kot) == 0)
return false;
bool isPrinted = false, isVoid = false;
if (_voucher.VoucherID != Guid.Empty)
@ -464,8 +465,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.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));
var listFirst = _bill.Where(x => x.Key.BillItemType != BillItemType.Kot && x.Key.KotID != Guid.Empty && splitList.Contains(x.Value.inventory.Product.ProductGroup.GroupType));
var listSecond = _bill.Where(x => x.Key.BillItemType != BillItemType.Kot && 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
@ -527,43 +528,41 @@ namespace Tanshu.Accounts.PointOfSale
if (MessageBox.Show("Are you sure you want to void this bill?", "Void Bill", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
return false;
#endregion
var reasons = new string[] {
"Discount",
"Printing Fault",
"Item Changed",
"Quantity Reduced",
"Costing Bill for Party",
"Cashier Mistake",
"Management Freesale",
"Other"
};
var voidReason = new SelectVoidReason(GetVoidReason, true);
voidReason.ShowDialog();
if (voidReason.SelectedItem != null)
using (var voidReason = new VoidReasonListForm(reasons))
{
MessageBox.Show("Please Select a reason if you want to void the bill", "Bill NOT Voided", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return false;
}
using (var bi = new VoucherBI())
{
bi.VoidBill(_voucher.VoucherID, voidReason.SelectedItem.Description);
if (!_editVoucherID.HasValue)
bi.UpdateTable(x => x.FoodTableID == _voucher.Table.FoodTableID && x.VoucherID == _voucher.VoucherID, null, null);
bi.SaveChanges();
voidReason.ShowDialog();
if (voidReason.SelectedItem == null)
{
MessageBox.Show("Please Select a reason if you want to void the bill", "Bill NOT Voided", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
return false;
}
using (var bi = new VoucherBI())
{
bi.VoidBill(_voucher.VoucherID, voidReason.SelectedItem);
if (!_editVoucherID.HasValue)
bi.UpdateTable(x => x.FoodTableID == _voucher.Table.FoodTableID && x.VoucherID == _voucher.VoucherID, null, null);
bi.SaveChanges();
}
}
ClearBill();
return true;
}
private static List<StringType> GetVoidReason(Dictionary<string, string> filter)
{
var list = new List<StringType>
{
new StringType("Discount"),
new StringType("Printing Fault"),
new StringType("Item Changed"),
new StringType("Quantity Reduced"),
new StringType("Costing Bill for Party"),
new StringType("Cashier Mistake"),
new StringType("Management Freesale"),
new StringType("Other")
};
return list.Where(i => i.Description.ToLower().Contains(filter["Name"].ToLower().Trim())).ToList();
}
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.inventory.Net);
var itemsChanged = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID == Guid.Empty).Count() != 0;
var amountChanged = oldAmount != _bill.Where(x => x.Key.BillItemType != BillItemType.Kot && x.Key.KotID != Guid.Empty).Sum(x => x.Value.inventory.Net);
var itemsChanged = _bill.Where(x => x.Key.BillItemType != BillItemType.Kot && x.Key.KotID == Guid.Empty).Count() != 0;
if (amountChanged || itemsChanged) // Discount or Products changed
{
@ -577,7 +576,7 @@ namespace Tanshu.Accounts.PointOfSale
VoucherType = _voucher.VoucherType
};
var kotNew = GetKot(_bill.Where(x => x.Key.BillItemType == BillItemType.Product));
var kotNew = GetKot(_bill.Where(x => x.Key.BillItemType != BillItemType.Kot));
if (kotNew != null)
newVoucher.Kots.Add(kotNew);
#endregion
@ -605,7 +604,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.inventory.Quantity != 0));
var kot = GetKot(_bill.Where(x => x.Key.KotID == Guid.Empty));
if (kot == null)
return null;
_voucher.Kots.Add(kot);
@ -630,15 +629,15 @@ namespace Tanshu.Accounts.PointOfSale
voucher.Customer = _voucher.Customer;
voucher.Printed = finalBill;
voucher.VoucherType = _voucher.VoucherType;
foreach (var item in _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != Guid.Empty))
foreach (var item in _bill.Where(x => x.Key.BillItemType != BillItemType.Kot && 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);
var i = voucher.Kots.Single(x => x.KotID == item.Key.KotID).Inventories.Single(x => x.Product.ProductID == item.Key.ProductID && x.IsHappyHour == item.Value.inventory.IsHappyHour);
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.inventory.Quantity != 0));
var kot = GetKot(_bill.Where(x => x.Key.KotID == Guid.Empty));
if (kot != null)
voucher.Kots.Add(kot);
}
@ -658,7 +657,13 @@ namespace Tanshu.Accounts.PointOfSale
var kot = new Kot();
foreach (var item in list)
{
var oldInv = kot.Inventories.SingleOrDefault(x => x.Product.ProductID == item.Key.ProductID);
if (item.Key.BillItemType == BillItemType.Kot)
continue;
if (item.Value.inventory.Quantity == 0)
continue;
var happyHour = item.Key.BillItemType == BillItemType.HappyHourProduct;
var productID = item.Key.ProductID;
var oldInv = kot.Inventories.SingleOrDefault(x => x.Product.ProductID == productID && x.IsHappyHour == happyHour);
if (oldInv != null)
{
oldInv.Quantity += item.Value.inventory.Quantity;
@ -672,7 +677,7 @@ namespace Tanshu.Accounts.PointOfSale
Product = item.Value.inventory.Product,
Quantity = item.Value.inventory.Quantity,
Price = item.Value.inventory.Price,
FullPrice = item.Value.inventory.FullPrice,
IsHappyHour = item.Value.inventory.IsHappyHour,
Discount = item.Value.inventory.Discount,
ServiceCharge = item.Value.inventory.ServiceCharge,
IsScTaxable = item.Value.inventory.IsScTaxable,

View File

@ -11,6 +11,7 @@ namespace Tanshu.Accounts.PointOfSale
public delegate void ItemChangedHandler();
public void Load(Voucher voucher)
{
this.Clear();
foreach (var kot in voucher.Kots)
{
var kotKey = new BillItemKey(kot.KotID);
@ -18,12 +19,13 @@ namespace Tanshu.Accounts.PointOfSale
this.Add(kotKey, kotItem);
foreach (var inv in kot.Inventories)
{
var key = new BillItemKey(inv.Product.ProductID, kot.KotID);
var key = new BillItemKey(inv.Product.ProductID, kot.KotID, inv.IsHappyHour);
var item = new BillItemValue(inv);
this.Add(key, item);
}
}
}
public decimal Tax
{
get
@ -35,7 +37,7 @@ namespace Tanshu.Accounts.PointOfSale
{
get
{
return this.Where(x => x.Key.BillItemType != BillItemType.Kot).Sum(i => i.Value.inventory.DiscountAmount);
return this.Where(x=>x.Key.BillItemType != BillItemType.Kot).Sum(i => i.Value.inventory.DiscountAmount);
}
}
public decimal ServiceCharge