Reprint and Printed bill editing logged.
Printed bill can no longer be changed, any changes voids the bill and prints a new one. Added option to Split Bill. Kot printed with right time. Numerous bug fixes.
This commit is contained in:
@ -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<KeyValuePair<BillItemKey, BillItemValue>> 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<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.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -10,12 +10,13 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
{
|
||||
public interface ISaleForm
|
||||
{
|
||||
void ClearBill(OrderedDictionary<BillItemKey, BillItemValue> bill);
|
||||
void ClearBill(List<BillItemValue> bill);
|
||||
void SetCustomerDisplay(string name);
|
||||
void CloseWindow();
|
||||
void ShowAmount(decimal discountAmount, decimal grossAmount, decimal serviceChargeAmount, decimal taxAmount, decimal valueAmount, List<BillItemValue> 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; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user