Initial Json commit from 2 years ago
This commit is contained in:
@ -21,8 +21,7 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
{
|
||||
this._editVoucherID = editVoucherID;
|
||||
_bill = new BillDict();
|
||||
using (var bi = new CustomerBI())
|
||||
_voucher = new Voucher(Session.User, bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER));
|
||||
_voucher = new Voucher(Session.User, CustomerBI.Get(Constants.CASH_CUSTOMER));
|
||||
}
|
||||
|
||||
public void AddProduct(Product product)
|
||||
@ -58,27 +57,24 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
if (!Session.IsAllowed("Discount"))
|
||||
return;
|
||||
|
||||
using (var bi = new ProductGroupBI())
|
||||
using (var frm = new DiscountForm(ProductGroupBI.GetProductGroupTypes()))
|
||||
{
|
||||
using (var frm = new DiscountForm(bi.GetProductGroupTypes()))
|
||||
if (frm.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (frm.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
HashSet<string> outList;
|
||||
var discount = frm.Selection(out outList);
|
||||
discount = discount / 100;
|
||||
if (discount > 1 || discount < 0)
|
||||
return;
|
||||
HashSet<string> outList;
|
||||
var discount = frm.Selection(out outList);
|
||||
discount = discount / 100;
|
||||
if (discount > 1 || discount < 0)
|
||||
return;
|
||||
|
||||
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;
|
||||
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.inventory.Discount = discount;
|
||||
}
|
||||
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;
|
||||
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.inventory.Discount = discount;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -121,39 +117,28 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
}
|
||||
private static bool IsPrintedOrVoid(Voucher voucher)
|
||||
{
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
var dbVoucher = bi.Get(x => x.VoucherID == voucher.VoucherID);
|
||||
return dbVoucher.Printed || dbVoucher.Void;
|
||||
}
|
||||
var dbVoucher = VoucherBI.Get(voucher.VoucherID);
|
||||
return dbVoucher.Printed || dbVoucher.Void;
|
||||
}
|
||||
private static bool IsPrintedOrVoid(Guid voucherID)
|
||||
{
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
var dbVoucher = bi.Get(x => x.VoucherID == voucherID);
|
||||
return dbVoucher.Printed || dbVoucher.Void;
|
||||
}
|
||||
var dbVoucher = VoucherBI.Get(voucherID);
|
||||
return dbVoucher.Printed || dbVoucher.Void;
|
||||
}
|
||||
private void InputBox_Validating(object sender, InputBoxValidatingArgs e)
|
||||
{
|
||||
}
|
||||
private void LoadBill(Guid voucherID)
|
||||
{
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
_voucher = bi.Get(x => x.VoucherID == voucherID);
|
||||
_bill.Load(_voucher);
|
||||
var newKotKey = new BillItemKey(Guid.Empty);
|
||||
var newKotItem = new BillItemValue();
|
||||
_bill.Add(newKotKey, newKotItem);
|
||||
}
|
||||
_voucher = VoucherBI.Get(voucherID);
|
||||
_bill.Load(_voucher);
|
||||
var newKotKey = new BillItemKey(Guid.Empty);
|
||||
var newKotItem = new BillItemValue();
|
||||
_bill.Add(newKotKey, newKotItem);
|
||||
}
|
||||
public void LoadBill(string tableName)
|
||||
{
|
||||
FoodTable table;
|
||||
using (var bi = new FoodTableBI())
|
||||
table = bi.Get(x => x.Name == tableName);
|
||||
FoodTable table = FoodTableBI.GetFromName(tableName);
|
||||
if (table != null && table.VoucherID.HasValue)
|
||||
{
|
||||
LoadBill(table.VoucherID.Value);
|
||||
@ -178,10 +163,9 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
ClearBill();
|
||||
return true;
|
||||
}
|
||||
private void ClearBill()
|
||||
public void ClearBill()
|
||||
{
|
||||
using (var bi = new CustomerBI())
|
||||
_voucher = new Voucher(Session.User, bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER));
|
||||
_voucher = new Voucher(Session.User, CustomerBI.Get(Constants.CASH_CUSTOMER));
|
||||
_bill.Clear();
|
||||
var newKotKey = new BillItemKey(Guid.Empty);
|
||||
var newKotItem = new BillItemValue();
|
||||
@ -193,8 +177,7 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
if (_editVoucherID.HasValue)
|
||||
{
|
||||
FoodTable ft;
|
||||
using (var bi = new FoodTableBI())
|
||||
ft = bi.Get(x => x.VoucherID == _editVoucherID.Value);
|
||||
ft = FoodTableBI.GetFromVoucher(_editVoucherID.Value);
|
||||
LoadBill(_editVoucherID.Value);
|
||||
if (ft != null)
|
||||
_editVoucherID = null;
|
||||
@ -215,13 +198,7 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
}
|
||||
if (options.Count == 0)
|
||||
return false;
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
bi.SettleVoucher(Session.User, _voucher.VoucherID, options);
|
||||
if (!_editVoucherID.HasValue)
|
||||
bi.UpdateTable(x => x.FoodTableID == _voucher.Table.FoodTableID && x.VoucherID == _voucher.VoucherID, null, null);
|
||||
bi.SaveChanges();
|
||||
}
|
||||
VoucherBI.SettleVoucher(Session.User, _voucher.VoucherID, options, !_editVoucherID.HasValue);
|
||||
ClearBill();
|
||||
return true;
|
||||
}
|
||||
@ -229,16 +206,13 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
#region Move Table(s) / Kot(s)
|
||||
private static FoodTable GetTableForMove(bool allowMerge)
|
||||
{
|
||||
using (var bi = new FoodTableBI())
|
||||
using (var frm = new MoveTableForm(FoodTableBI.List(true), allowMerge))
|
||||
{
|
||||
using (var frm = new MoveTableForm(bi.List(x => x.IsActive), allowMerge))
|
||||
{
|
||||
frm.ShowDialog();
|
||||
if (frm.Selection != null)
|
||||
return frm.Selection;
|
||||
}
|
||||
return null;
|
||||
frm.ShowDialog();
|
||||
if (frm.Selection != null)
|
||||
return frm.Selection;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
internal void MoveKot(BillItemKey currentKot)
|
||||
{
|
||||
@ -258,17 +232,32 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
var kotCount = _bill.Keys.Count(x => x.BillItemType == BillItemType.Kot && x.KotID != Guid.Empty);
|
||||
var voucherID = Guid.Empty;
|
||||
if (table.VoucherID == null && kotCount > 1)
|
||||
{
|
||||
//Move Kot
|
||||
voucherID = MoveKot(kot, table);
|
||||
else if (table.VoucherID != null && kotCount > 1)
|
||||
if (Session.IsAllowed("Move Kot"))
|
||||
voucherID = VoucherBI.MoveKot(kot.KotID, table.FoodTableID);
|
||||
}
|
||||
else if (table.VoucherID.HasValue && kotCount > 1)
|
||||
{
|
||||
//Merge Kot
|
||||
voucherID = MergeKot(kot, table);
|
||||
if (Session.IsAllowed("Merge Kots"))
|
||||
voucherID = VoucherBI.MergeKot(kot.KotID, table.VoucherID.Value);
|
||||
}
|
||||
else if (table.VoucherID == null && kotCount == 1)
|
||||
{
|
||||
//Move Table
|
||||
voucherID = MoveTable(table.FoodTableID);
|
||||
else if (table.VoucherID != null && kotCount == 1)
|
||||
if (Session.IsAllowed("Move Table"))
|
||||
{
|
||||
VoucherBI.MoveTable(_voucher.VoucherID, table.FoodTableID);
|
||||
voucherID = _voucher.VoucherID;
|
||||
}
|
||||
}
|
||||
else if (table.VoucherID.HasValue && kotCount == 1)
|
||||
{
|
||||
//Merge Table
|
||||
voucherID = MergeTable(table);
|
||||
if (Session.IsAllowed("Merge Tables"))
|
||||
voucherID = VoucherBI.MergeTables(_voucher.VoucherID, table.VoucherID.Value);
|
||||
}
|
||||
if (voucherID != Guid.Empty)
|
||||
{
|
||||
LoadBill(voucherID);
|
||||
@ -289,60 +278,135 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
if (table.VoucherID.HasValue)
|
||||
if (IsPrintedOrVoid(table.VoucherID.Value))
|
||||
return;
|
||||
|
||||
LoadBill(table.VoucherID.HasValue ? MergeTable(table) : MoveTable(table.FoodTableID));
|
||||
}
|
||||
private Guid MoveKot(BillItemKey kot, FoodTable table)
|
||||
{
|
||||
if (!Session.IsAllowed("Move Kot to New Table"))
|
||||
return Guid.Empty;
|
||||
using (var bi = new VoucherBI())
|
||||
if (table.VoucherID.HasValue)
|
||||
{
|
||||
var newVoucherID = bi.MoveKot(kot.KotID, table.FoodTableID);
|
||||
bi.UpdateTable(x => x.FoodTableID == table.FoodTableID && x.VoucherID == null, newVoucherID, "running");
|
||||
bi.SaveChanges();
|
||||
return newVoucherID;
|
||||
if (Session.IsAllowed("Merge Tables"))
|
||||
{
|
||||
LoadBill(VoucherBI.MergeTables(_voucher.VoucherID, table.VoucherID.Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
private static Guid MergeKot(BillItemKey kot, FoodTable table)
|
||||
{
|
||||
if (!Session.IsAllowed("Merge Kots"))
|
||||
return Guid.Empty;
|
||||
using (var bi = new VoucherBI())
|
||||
else
|
||||
{
|
||||
var newVoucherID = bi.MergeKot(kot.KotID, table.Name);
|
||||
bi.SaveChanges();
|
||||
return newVoucherID;
|
||||
}
|
||||
}
|
||||
private Guid MoveTable(Guid tableID)
|
||||
{
|
||||
if (!Session.IsAllowed("Move Table"))
|
||||
return Guid.Empty;
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
bi.MoveTable(_voucher.VoucherID, tableID);
|
||||
bi.UpdateTable(x => x.FoodTableID == tableID && x.VoucherID == null, _voucher.VoucherID, _voucher.Table.Status);
|
||||
bi.UpdateTable(x => x.FoodTableID == _voucher.Table.FoodTableID && x.VoucherID == _voucher.VoucherID, null, null);
|
||||
bi.SaveChanges();
|
||||
return _voucher.VoucherID;
|
||||
}
|
||||
}
|
||||
private Guid MergeTable(FoodTable table)
|
||||
{
|
||||
if (!Session.IsAllowed("Merge Tables"))
|
||||
return Guid.Empty;
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
var newVoucherID = bi.MergeTables(_voucher.VoucherID, table.Name);
|
||||
bi.UpdateTable(x => x.FoodTableID == _voucher.Table.FoodTableID && x.VoucherID == _voucher.VoucherID, null, null);
|
||||
bi.SaveChanges();
|
||||
return newVoucherID;
|
||||
if (Session.IsAllowed("Move Table"))
|
||||
{
|
||||
LoadBill(VoucherBI.MoveTable(_voucher.VoucherID, table.FoodTableID));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Save
|
||||
public void SplitBill()
|
||||
{
|
||||
bool isPrinted = false;
|
||||
#region Permissions
|
||||
if (!Session.IsAllowed("Split Bill"))
|
||||
return;
|
||||
if (_voucher.VoucherID == Guid.Empty)
|
||||
return; // must be existing non void bill
|
||||
var dbVoucher = VoucherBI.Get(_voucher.VoucherID);
|
||||
if (dbVoucher.Void)
|
||||
{
|
||||
MessageBox.Show(string.Format("This Bill is already void.\nReason: {0}", _voucher.VoidReason), "Bill already Voided", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;// must be a non void bill
|
||||
}
|
||||
if (dbVoucher.Printed && !Session.IsAllowed("Edit Printed Bill"))
|
||||
{
|
||||
MessageBox.Show("This Bill is already Printed.\nYou do not have the authority to alter it", "Bill already Printed", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;// not allowed to edit printed bill
|
||||
}
|
||||
isPrinted = dbVoucher.Printed;
|
||||
#endregion
|
||||
|
||||
#region Get Move List
|
||||
HashSet<string> splitList = null;
|
||||
using (var frm = new DiscountForm(ProductGroupBI.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.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
|
||||
#endregion
|
||||
|
||||
var table = GetTableForMove(false);
|
||||
if (table == null)
|
||||
return;
|
||||
|
||||
#region new voucherFirst
|
||||
var voucherFirst = new Voucher(Session.User, _voucher.Customer)
|
||||
{
|
||||
Table = table,
|
||||
Printed = isPrinted,
|
||||
Void = false,
|
||||
Narration = "",
|
||||
VoucherType = _voucher.VoucherType
|
||||
};
|
||||
|
||||
var kotFirst = GetKot(listFirst);
|
||||
if (kotFirst != null)
|
||||
voucherFirst.Kots.Add(kotFirst);
|
||||
#endregion
|
||||
|
||||
#region new voucherSecond
|
||||
var voucherSecond = new Voucher(Session.User, _voucher.Customer)
|
||||
{
|
||||
Table = _voucher.Table,
|
||||
Printed = isPrinted,
|
||||
Void = false,
|
||||
Narration = "",
|
||||
VoucherType = _voucher.VoucherType
|
||||
};
|
||||
|
||||
var kotSecond = GetKot(listSecond);
|
||||
if (kotSecond != null)
|
||||
voucherSecond.Kots.Add(kotSecond);
|
||||
#endregion
|
||||
VoucherBI.SplitBill(_voucher.VoucherID, voucherFirst, voucherSecond);
|
||||
if (isPrinted)
|
||||
{
|
||||
Thermal.PrintBill(voucherFirst.VoucherID);
|
||||
Thermal.PrintBill(voucherSecond.VoucherID);
|
||||
}
|
||||
LoadBill(voucherFirst.VoucherID);
|
||||
}
|
||||
public bool VoidBill()
|
||||
{
|
||||
#region Check conditions and Permissions
|
||||
if (_voucher.VoucherID == Guid.Empty || _voucher.Void || !Session.IsAllowed("Void Bill"))
|
||||
return false;
|
||||
if (MessageBox.Show("Are you sure you want to void this bill?", "Void Bill", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
|
||||
return false;
|
||||
#endregion
|
||||
var reasons = new string[] {
|
||||
"Discount",
|
||||
"Printing Fault",
|
||||
"Item Changed",
|
||||
"Quantity Reduced",
|
||||
"Costing Bill for Party",
|
||||
"Cashier Mistake",
|
||||
"Management Freesale",
|
||||
"Other"
|
||||
};
|
||||
|
||||
|
||||
using (var voidReason = new VoidReasonListForm(reasons))
|
||||
{
|
||||
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;
|
||||
}
|
||||
VoucherBI.VoidBill(_voucher.VoucherID, voidReason.SelectedItem, !_editVoucherID.HasValue);
|
||||
}
|
||||
ClearBill();
|
||||
return true;
|
||||
}
|
||||
public bool SaveAndPrintKot()
|
||||
{
|
||||
#region Check if Allowed
|
||||
@ -350,12 +414,11 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
return false;
|
||||
bool isPrinted = false, isVoid = false;
|
||||
if (_voucher.VoucherID != Guid.Empty)
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
var dbVoucher = bi.Get(x => x.VoucherID == _voucher.VoucherID);
|
||||
isPrinted = dbVoucher.Printed;
|
||||
isVoid = dbVoucher.Void;
|
||||
}
|
||||
{
|
||||
var dbVoucher = VoucherBI.Get(_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);
|
||||
@ -419,136 +482,6 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
ClearBill();
|
||||
return true;
|
||||
}
|
||||
public void SplitBill()
|
||||
{
|
||||
bool isPrinted = false;
|
||||
#region Permissions
|
||||
if (!Session.IsAllowed("Split Bill"))
|
||||
return;
|
||||
if (_voucher.VoucherID == Guid.Empty)
|
||||
return; // must be existing non void bill
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
var dbVoucher = bi.Get(x => x.VoucherID == _voucher.VoucherID);
|
||||
if (dbVoucher.Void)
|
||||
{
|
||||
MessageBox.Show(string.Format("This Bill is already void.\nReason: {0}", _voucher.VoidReason), "Bill already Voided", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;// must be a non void bill
|
||||
}
|
||||
if (dbVoucher.Printed && !Session.IsAllowed("Edit Printed Bill"))
|
||||
{
|
||||
MessageBox.Show("This Bill is already Printed.\nYou do not have the authority to alter it", "Bill already Printed", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;// not allowed to edit printed bill
|
||||
}
|
||||
isPrinted = dbVoucher.Printed;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Get Move List
|
||||
HashSet<string> 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.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
|
||||
#endregion
|
||||
|
||||
var table = GetTableForMove(false);
|
||||
if (table == null)
|
||||
return;
|
||||
|
||||
#region new voucherFirst
|
||||
var voucherFirst = new Voucher(Session.User, _voucher.Customer)
|
||||
{
|
||||
Table = table,
|
||||
Printed = isPrinted,
|
||||
Void = false,
|
||||
Narration = "",
|
||||
VoucherType = _voucher.VoucherType
|
||||
};
|
||||
|
||||
var kotFirst = GetKot(listFirst);
|
||||
if (kotFirst != null)
|
||||
voucherFirst.Kots.Add(kotFirst);
|
||||
#endregion
|
||||
|
||||
#region new voucherSecond
|
||||
var voucherSecond = new Voucher(Session.User, _voucher.Customer)
|
||||
{
|
||||
Table = _voucher.Table,
|
||||
Printed = isPrinted,
|
||||
Void = false,
|
||||
Narration = "",
|
||||
VoucherType = _voucher.VoucherType
|
||||
};
|
||||
|
||||
var kotSecond = GetKot(listSecond);
|
||||
if (kotSecond != null)
|
||||
voucherSecond.Kots.Add(kotSecond);
|
||||
#endregion
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
bi.SplitBill(_voucher.VoucherID, voucherFirst, voucherSecond);
|
||||
var status = _voucher.Printed ? "printed" : "running";
|
||||
bi.UpdateTable(x => x.FoodTableID == voucherFirst.Table.FoodTableID && x.VoucherID == null, voucherFirst.VoucherID, status);
|
||||
bi.UpdateTable(x => x.FoodTableID == voucherSecond.Table.FoodTableID && x.VoucherID == _voucher.VoucherID, voucherSecond.VoucherID, status);
|
||||
bi.SaveChanges();
|
||||
}
|
||||
if (isPrinted)
|
||||
{
|
||||
Thermal.PrintBill(voucherFirst.VoucherID);
|
||||
Thermal.PrintBill(voucherSecond.VoucherID);
|
||||
}
|
||||
LoadBill(voucherFirst.VoucherID);
|
||||
}
|
||||
public bool VoidBill()
|
||||
{
|
||||
#region Check conditions and Permissions
|
||||
if (_voucher.VoucherID == Guid.Empty || _voucher.Void || !Session.IsAllowed("Void Bill"))
|
||||
return false;
|
||||
if (MessageBox.Show("Are you sure you want to void this bill?", "Void Bill", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes)
|
||||
return false;
|
||||
#endregion
|
||||
var reasons = new string[] {
|
||||
"Discount",
|
||||
"Printing Fault",
|
||||
"Item Changed",
|
||||
"Quantity Reduced",
|
||||
"Costing Bill for Party",
|
||||
"Cashier Mistake",
|
||||
"Management Freesale",
|
||||
"Other"
|
||||
};
|
||||
|
||||
|
||||
using (var voidReason = new VoidReasonListForm(reasons))
|
||||
{
|
||||
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 void SaveReprintOrDiscountBill(decimal oldAmount)
|
||||
{
|
||||
var amountChanged = oldAmount != _bill.Where(x => x.Key.BillItemType != BillItemType.Kot && x.Key.KotID != Guid.Empty).Sum(x => x.Value.inventory.Net);
|
||||
@ -571,22 +504,13 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
newVoucher.Kots.Add(kotNew);
|
||||
#endregion
|
||||
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
bi.DiscountPrintedBill(_voucher.VoucherID, newVoucher);
|
||||
bi.UpdateTable(x => x.FoodTableID == _voucher.Table.FoodTableID && (x.VoucherID == _voucher.VoucherID || x.VoucherID == null), newVoucher.VoucherID, "printed");
|
||||
bi.SaveChanges();
|
||||
}
|
||||
newVoucher = VoucherBI.DiscountPrintedBill(_voucher.VoucherID, newVoucher);
|
||||
_editVoucherID = null;
|
||||
LoadBill(newVoucher.VoucherID);
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var bi = new ReprintBI())
|
||||
{
|
||||
bi.Insert(new Reprint() { User = Session.User, Voucher = _voucher });
|
||||
bi.SaveChanges();
|
||||
}
|
||||
ReprintBI.Insert(new Reprint() { User = Session.User, Voucher = _voucher });
|
||||
}
|
||||
}
|
||||
private Guid? InsertVoucher(bool finalBill, bool updateTable)
|
||||
@ -598,49 +522,38 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
if (kot == null)
|
||||
return null;
|
||||
_voucher.Kots.Add(kot);
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
var kotID = bi.Insert(_voucher);
|
||||
if (updateTable)
|
||||
{
|
||||
var status = !_voucher.Printed ? "running" : "printed";
|
||||
bi.UpdateTable(x => x.FoodTableID == _voucher.Table.FoodTableID && x.VoucherID == null, _voucher.VoucherID, status);
|
||||
}
|
||||
bi.SaveChanges();
|
||||
return kotID;
|
||||
}
|
||||
_voucher = VoucherBI.Insert(_voucher, updateTable);
|
||||
return _voucher.Kots[0].KotID;
|
||||
}
|
||||
private Guid? UpdateVoucher(bool finalBill, bool updateTable)
|
||||
{
|
||||
using (var bi = new VoucherBI())
|
||||
var voucher = VoucherBI.Get(_voucher.VoucherID);
|
||||
voucher.User = Session.User;
|
||||
voucher.Customer = _voucher.Customer;
|
||||
voucher.Printed = finalBill;
|
||||
voucher.VoucherType = _voucher.VoucherType;
|
||||
foreach (var item in _bill.Where(x => x.Key.BillItemType != BillItemType.Kot && x.Key.KotID != Guid.Empty))
|
||||
{
|
||||
var voucher = bi.Get(x => x.VoucherID == _voucher.VoucherID);
|
||||
voucher.User = Session.User;
|
||||
voucher.Customer = _voucher.Customer;
|
||||
voucher.Printed = finalBill;
|
||||
voucher.VoucherType = _voucher.VoucherType;
|
||||
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 && 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.KotID == Guid.Empty));
|
||||
if (kot != null)
|
||||
voucher.Kots.Add(kot);
|
||||
}
|
||||
var kotID = bi.Update(voucher);
|
||||
if (updateTable)
|
||||
{
|
||||
var status = !voucher.Printed ? "running" : "printed";
|
||||
bi.UpdateTable(x => x.FoodTableID == _voucher.Table.FoodTableID && x.VoucherID == _voucher.VoucherID, _voucher.VoucherID, status);
|
||||
}
|
||||
|
||||
bi.SaveChanges();
|
||||
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.KotID == Guid.Empty));
|
||||
if (kot != null)
|
||||
voucher.Kots.Add(kot);
|
||||
}
|
||||
try
|
||||
{
|
||||
var kotID = VoucherBI.Update(voucher, updateTable);
|
||||
return kotID;
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private static Kot GetKot(IEnumerable<KeyValuePair<BillItemKey, BillItemValue>> list)
|
||||
{
|
||||
@ -663,19 +576,19 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
else
|
||||
{
|
||||
var inv = new Inventory
|
||||
{
|
||||
Product = item.Value.inventory.Product,
|
||||
Quantity = item.Value.inventory.Quantity,
|
||||
Price = item.Value.inventory.Price,
|
||||
IsHappyHour = item.Value.inventory.IsHappyHour,
|
||||
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
|
||||
};
|
||||
{
|
||||
Product = item.Value.inventory.Product,
|
||||
Quantity = item.Value.inventory.Quantity,
|
||||
Price = item.Value.inventory.Price,
|
||||
IsHappyHour = item.Value.inventory.IsHappyHour,
|
||||
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.inventory.InventoryModifier)
|
||||
inv.InventoryModifier.Add(new InventoryModifier { Modifier = mod.Modifier });
|
||||
kot.Inventories.Add(inv);
|
||||
|
||||
Reference in New Issue
Block a user