Lot of changes. Now table must be explicitly updated and not from inside various functions. This makes for better understanding and lesser mistakes.
Product form now has an IsActive checkbox to show only active products.
This commit is contained in:
parent
e3f92da5ad
commit
b1a9d2daae
Tanshu.Accounts.Contracts/Data Contracts
Tanshu.Accounts.PointOfSale
Tanshu.Accounts.Repository
@ -76,7 +76,6 @@ namespace Tanshu.Accounts.Entities
|
||||
case VoucherType.Regular:
|
||||
default:
|
||||
return (BillID.Value / 10000).ToString() + "-" + (BillID.Value % 10000).ToString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -14,26 +14,24 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
public class BillController
|
||||
{
|
||||
private readonly BillDict _bill;
|
||||
private Voucher _billInfo;
|
||||
private Voucher _voucher;
|
||||
private Guid? _editVoucherID;
|
||||
private readonly bool _print;
|
||||
private ISaleForm _saleForm;
|
||||
|
||||
public Waiter Waiter
|
||||
{
|
||||
get { return _billInfo.Waiter; }
|
||||
set { _billInfo.Waiter = value; }
|
||||
get { return _voucher.Waiter; }
|
||||
set { _voucher.Waiter = value; }
|
||||
}
|
||||
public BillController(Guid? editVoucherID, bool print)
|
||||
public BillController(Guid? editVoucherID)
|
||||
{
|
||||
this._editVoucherID = editVoucherID;
|
||||
_print = print;
|
||||
_bill = new BillDict();
|
||||
_billInfo = new Voucher(Session.User);
|
||||
_voucher = new Voucher(Session.User);
|
||||
using (var bi = new CustomerBI())
|
||||
_billInfo.Customer = bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER);
|
||||
_voucher.Customer = bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER);
|
||||
using (var bi = new WaiterBI())
|
||||
_billInfo.Waiter = bi.Get(x => x.WaiterID == Constants.WAITER);
|
||||
_voucher.Waiter = bi.Get(x => x.WaiterID == Constants.WAITER);
|
||||
}
|
||||
public BillItemValue CurrentProduct
|
||||
{
|
||||
@ -59,7 +57,7 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
public void InitGui(ISaleForm saleForm)
|
||||
{
|
||||
this._saleForm = saleForm;
|
||||
this._saleForm.SetCustomerDisplay(_billInfo.Customer.Name);
|
||||
this._saleForm.SetCustomerDisplay(_voucher.Customer.Name);
|
||||
this._saleForm.SetUserName(Session.User.Name);
|
||||
}
|
||||
public void AddProduct(Product product)
|
||||
@ -107,7 +105,7 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
public void SetDiscount()
|
||||
{
|
||||
if (!Session.IsAllowed("Discount"))
|
||||
throw new PermissionException("Not Allowed to give Discount");
|
||||
return; // throw new PermissionException("Not Allowed to give Discount");
|
||||
|
||||
using (var bi = new ProductGroupBI())
|
||||
{
|
||||
@ -119,7 +117,7 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
var discount = frm.Selection(out outList);
|
||||
discount = discount / 100;
|
||||
if (discount > 1 || discount < 0)
|
||||
throw new ValidationException("Invalid Discount Amount");
|
||||
return; // throw new ValidationException("Invalid Discount Amount");
|
||||
|
||||
foreach (var item in _bill.Where(x => x.Key.BillItemType == BillItemType.Product && outList.Contains(x.Value.Product.ProductGroup.GroupType)))
|
||||
{
|
||||
@ -173,7 +171,7 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
}
|
||||
public void ShowCustomers(bool reset)
|
||||
{
|
||||
if (!reset && ((_billInfo.Customer == null) || _billInfo.Customer.CustomerID == Constants.CASH_CUSTOMER))
|
||||
if (!reset && ((_voucher.Customer == null) || _voucher.Customer.CustomerID == Constants.CASH_CUSTOMER))
|
||||
{
|
||||
using (var selectCustomer = new SelectCustomer(CustomerBI.StaticList, true))
|
||||
{
|
||||
@ -181,21 +179,21 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
selectCustomer.ShowDialog();
|
||||
if (selectCustomer.SelectedItem != null)
|
||||
{
|
||||
_billInfo.Customer = selectCustomer.SelectedItem;
|
||||
_voucher.Customer = selectCustomer.SelectedItem;
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var bi = new CustomerBI())
|
||||
_billInfo.Customer = bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER);
|
||||
_voucher.Customer = bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var bi = new CustomerBI())
|
||||
_billInfo.Customer = bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER);
|
||||
_voucher.Customer = bi.Get(x => x.CustomerID == Constants.CASH_CUSTOMER);
|
||||
}
|
||||
_saleForm.SetCustomerDisplay(_billInfo.Customer.Name);
|
||||
_saleForm.SetCustomerDisplay(_voucher.Customer.Name);
|
||||
}
|
||||
private Customer selectCustomer_customerEvent(object sender, CustomerEventArgs e)
|
||||
{
|
||||
@ -210,7 +208,7 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
if (reset)
|
||||
{
|
||||
using (var bi = new WaiterBI())
|
||||
_billInfo.Waiter = bi.Get(x => x.WaiterID == Constants.WAITER);
|
||||
_voucher.Waiter = bi.Get(x => x.WaiterID == Constants.WAITER);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -220,16 +218,16 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
selectWaiter.ShowDialog();
|
||||
if (selectWaiter.SelectedItem != null)
|
||||
{
|
||||
_billInfo.Waiter = selectWaiter.SelectedItem;
|
||||
_voucher.Waiter = selectWaiter.SelectedItem;
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var bi = new WaiterBI())
|
||||
_billInfo.Waiter = bi.Get(x => x.WaiterID == Constants.WAITER);
|
||||
_voucher.Waiter = bi.Get(x => x.WaiterID == Constants.WAITER);
|
||||
}
|
||||
}
|
||||
}
|
||||
_saleForm.SetWaiterDisplay(_billInfo.Waiter.Name);
|
||||
_saleForm.SetWaiterDisplay(_voucher.Waiter.Name);
|
||||
}
|
||||
private Waiter selectWaiter_waiterEvent(object sender, SelectorEventArgs<Waiter> e)
|
||||
{
|
||||
@ -301,27 +299,6 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
return dbVoucher.Printed || dbVoucher.Void;
|
||||
}
|
||||
}
|
||||
private bool? IsReprint(out decimal amount)
|
||||
{
|
||||
amount = 0;
|
||||
if (_billInfo.VoucherID == Guid.Empty)
|
||||
return false;
|
||||
|
||||
bool isPrinted, isVoid;
|
||||
IsPrintedOrVoid(_billInfo, out isPrinted, out isVoid);
|
||||
|
||||
if (isVoid)
|
||||
{
|
||||
MessageBox.Show(string.Format("This Bill is already void.\nReason: {0}", _billInfo.VoidReason), "Bill already Voided", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isPrinted && (!Session.IsAllowed("Edit Printed Bill")))
|
||||
return null;
|
||||
amount = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != Guid.Empty).Sum(x => x.Value.GrossAmount);
|
||||
|
||||
return isPrinted;
|
||||
}
|
||||
private void InputBox_Validating(object sender, InputBoxValidatingArgs e)
|
||||
{
|
||||
}
|
||||
@ -330,10 +307,10 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
ClearBill();
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
_billInfo = bi.Get(x => x.VoucherID == voucherID);
|
||||
_voucher = bi.Get(x => x.VoucherID == voucherID);
|
||||
_bill.Clear();
|
||||
_saleForm.ShowInfo(_billInfo);
|
||||
_bill.Load(_billInfo);
|
||||
_saleForm.ShowInfo(_voucher);
|
||||
_bill.Load(_voucher);
|
||||
var newKotKey = new BillItemKey(Guid.Empty);
|
||||
var newKotItem = new BillItemValue();
|
||||
_bill.Add(newKotKey, newKotItem);
|
||||
@ -355,9 +332,9 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
using (var frm = new PaxForm())
|
||||
{
|
||||
frm.ShowDialog();
|
||||
_billInfo.Table = table;
|
||||
_billInfo.Pax = frm.Pax;
|
||||
_saleForm.ShowInfo(_billInfo);
|
||||
_voucher.Table = table;
|
||||
_voucher.Pax = frm.Pax;
|
||||
_saleForm.ShowInfo(_voucher);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -372,7 +349,7 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
}
|
||||
public void ClearBill()
|
||||
{
|
||||
_billInfo = new Voucher(Session.User);
|
||||
_voucher = new Voucher(Session.User);
|
||||
ShowCustomers(true);
|
||||
ShowWaiters(true);
|
||||
_bill.Clear();
|
||||
@ -386,31 +363,40 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
ClearBill();
|
||||
if (_editVoucherID.HasValue)
|
||||
{
|
||||
LoadBill(_editVoucherID.Value);
|
||||
FoodTable ft = new FoodTableBI().Get(x => x.VoucherID == _editVoucherID.Value);
|
||||
if (ft == null)
|
||||
LoadBill(_editVoucherID.Value);
|
||||
else
|
||||
{
|
||||
_editVoucherID = null;
|
||||
LoadBill(ft.Name);
|
||||
}
|
||||
return SaleFormState.Billing;
|
||||
}
|
||||
return SaleFormState.Waiting;
|
||||
}
|
||||
internal void SettleBill()
|
||||
{
|
||||
if (_billInfo.VoucherID == Guid.Empty)
|
||||
if (_voucher.VoucherID == Guid.Empty)
|
||||
return;
|
||||
if (!_billInfo.Printed)
|
||||
if (!_voucher.Printed)
|
||||
return;
|
||||
if (!Session.IsAllowed("Settle Bill"))
|
||||
return;
|
||||
IDictionary<SettleOption, decimal> options;
|
||||
var amount = -1 * _billInfo.Kots.Sum(x => x.Inventories.Sum(y => y.Amount));
|
||||
using (var frm = new SettleChoicesForm(Math.Round(amount) * -1, _billInfo.VoucherType))
|
||||
var amount = -1 * _voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount));
|
||||
using (var frm = new SettleChoicesForm(Math.Round(amount) * -1, _voucher.VoucherType))
|
||||
{
|
||||
frm.ShowDialog();
|
||||
options = frm.OptionsChosen;
|
||||
}
|
||||
if (options.Count == 0)
|
||||
return;
|
||||
using (var bi = new VoucherSettlementBI())
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
bi.SettleVoucher(Session.User, _billInfo.VoucherID, options);
|
||||
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();
|
||||
}
|
||||
ClearBill();
|
||||
@ -432,9 +418,9 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
}
|
||||
internal void MoveKot()
|
||||
{
|
||||
if (_billInfo.VoucherID == Guid.Empty)
|
||||
if (_voucher.VoucherID == Guid.Empty)
|
||||
return;
|
||||
if (IsPrintedOrVoid(_billInfo))
|
||||
if (IsPrintedOrVoid(_voucher))
|
||||
return;
|
||||
var kot = CurrentKot;
|
||||
if (kot == null)
|
||||
@ -442,7 +428,7 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
var table = GetTableForMove(true);
|
||||
if (table == null)
|
||||
return;
|
||||
if (table.FoodTableID == _billInfo.Table.FoodTableID)
|
||||
if (table.FoodTableID == _voucher.Table.FoodTableID)
|
||||
return;
|
||||
if (table.VoucherID != null)
|
||||
if (IsPrintedOrVoid(table.VoucherID.Value))
|
||||
@ -466,15 +452,15 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
}
|
||||
internal void MoveTable()
|
||||
{
|
||||
if (_billInfo.VoucherID == Guid.Empty)
|
||||
if (_voucher.VoucherID == Guid.Empty)
|
||||
return;
|
||||
|
||||
var allowMerge = !IsPrintedOrVoid(_billInfo);
|
||||
var allowMerge = !IsPrintedOrVoid(_voucher);
|
||||
|
||||
var table = GetTableForMove(allowMerge);
|
||||
if (table == null)
|
||||
return;
|
||||
if (table.FoodTableID == _billInfo.Table.FoodTableID)
|
||||
if (table.FoodTableID == _voucher.Table.FoodTableID)
|
||||
return;
|
||||
if (table.VoucherID.HasValue)
|
||||
if (IsPrintedOrVoid(table.VoucherID.Value))
|
||||
@ -489,6 +475,7 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
var newVoucherID = bi.MoveKot(kot.KotID, table.FoodTableID);
|
||||
bi.UpdateTable(x => x.FoodTableID == table.FoodTableID && x.VoucherID == null, newVoucherID, "running");
|
||||
bi.SaveChanges();
|
||||
return newVoucherID;
|
||||
}
|
||||
@ -510,9 +497,11 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
return Guid.Empty;
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
var newVoucherID = bi.Move(_billInfo.Table.FoodTableID, tableID);
|
||||
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 newVoucherID;
|
||||
return _voucher.VoucherID;
|
||||
}
|
||||
}
|
||||
private Guid MergeTable(FoodTable table)
|
||||
@ -521,7 +510,8 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
return Guid.Empty;
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
var newVoucherID = bi.MergeTables(_billInfo.VoucherID, table.Name);
|
||||
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;
|
||||
}
|
||||
@ -534,18 +524,18 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
#region Check if Allowed
|
||||
if (!Session.IsAllowed("Print Kot"))
|
||||
return;
|
||||
if (_billInfo.VoucherID != Guid.Empty && IsPrintedOrVoid(_billInfo))
|
||||
if (_voucher.VoucherID != Guid.Empty && IsPrintedOrVoid(_voucher))
|
||||
return;
|
||||
if (_bill.Count == 1) //new kot only
|
||||
return;
|
||||
#endregion
|
||||
|
||||
//Save
|
||||
var saved = _billInfo.VoucherID == Guid.Empty ? InsertVoucher(false, !_editVoucherID.HasValue) : UpdateVoucher(false, !_editVoucherID.HasValue);
|
||||
var saved = _voucher.VoucherID == Guid.Empty ? InsertVoucher(false, !_editVoucherID.HasValue) : UpdateVoucher(false, !_editVoucherID.HasValue);
|
||||
|
||||
//Print
|
||||
if ((!_editVoucherID.HasValue || _print) && saved.HasValue)
|
||||
Thermal.PrintKot(_billInfo.VoucherID, saved.Value);
|
||||
if (!_editVoucherID.HasValue && saved.HasValue)
|
||||
Thermal.PrintKot(_voucher.VoucherID, saved.Value);
|
||||
|
||||
//Cleanup
|
||||
if (_editVoucherID.HasValue)
|
||||
@ -557,54 +547,40 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
{
|
||||
#region Check if Allowed
|
||||
if (!Session.IsAllowed("Print Bill"))
|
||||
throw new PermissionException("Printing not allowed");
|
||||
return; // throw new PermissionException("Printing not allowed");
|
||||
if (_bill.Count == 1) //new kot only
|
||||
return;
|
||||
bool isPrinted = false, isVoid = false;
|
||||
if (_voucher.VoucherID != Guid.Empty)
|
||||
IsPrintedOrVoid(_voucher, out isPrinted, out isVoid);
|
||||
if (isVoid)
|
||||
{
|
||||
MessageBox.Show(string.Format("This Bill is already void.\nReason: {0}", _voucher.VoidReason), "Bill already Voided", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (isPrinted && !Session.IsAllowed("Edit Printed Bill"))
|
||||
return;
|
||||
#endregion
|
||||
|
||||
decimal amount;
|
||||
|
||||
var isReprint = IsReprint(out amount);
|
||||
if (!isReprint.HasValue)
|
||||
return;
|
||||
else if (isReprint.Value)
|
||||
var amount = _bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID != Guid.Empty).Sum(x => x.Value.GrossAmount);
|
||||
SetDiscount();
|
||||
if (isPrinted)
|
||||
{
|
||||
try
|
||||
{
|
||||
SetDiscount();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (!(ex is ValidationException) && !(ex is PermissionException))
|
||||
throw;
|
||||
}
|
||||
SaveReprintOrDiscountBill(amount);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
SetDiscount();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (!(ex is ValidationException) && !(ex is PermissionException))
|
||||
throw;
|
||||
}
|
||||
// Ask for VoucherType only for new bill, if none, then cancel
|
||||
VoucherType? voucherType;
|
||||
using (var frm = new VoucherTypeForm())
|
||||
{
|
||||
frm.ShowDialog();
|
||||
voucherType = frm.Selection;
|
||||
if (!frm.Selection.HasValue)
|
||||
return;
|
||||
_voucher.VoucherType = frm.Selection.Value;
|
||||
}
|
||||
if (!voucherType.HasValue)
|
||||
return;
|
||||
_billInfo.VoucherType = voucherType.Value;
|
||||
var saved = _billInfo.VoucherID == Guid.Empty ? InsertVoucher(true, !_editVoucherID.HasValue) : UpdateVoucher(true, !_editVoucherID.HasValue);
|
||||
var saved = _voucher.VoucherID == Guid.Empty ? InsertVoucher(true, !_editVoucherID.HasValue) : UpdateVoucher(true, !_editVoucherID.HasValue);
|
||||
}
|
||||
if (!_editVoucherID.HasValue || _print)
|
||||
Thermal.PrintBill(_billInfo.VoucherID);
|
||||
Thermal.PrintBill(_voucher.VoucherID);
|
||||
if (_editVoucherID.HasValue)
|
||||
_saleForm.CloseWindow();
|
||||
ClearBill();
|
||||
@ -614,8 +590,8 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
#region Permissions
|
||||
|
||||
bool isPrinted, isVoid;
|
||||
IsPrintedOrVoid(_billInfo, out isPrinted, out isVoid);
|
||||
if (_billInfo.VoucherID == Guid.Empty || isVoid)
|
||||
IsPrintedOrVoid(_voucher, out isPrinted, out isVoid);
|
||||
if (_voucher.VoucherID == Guid.Empty || isVoid)
|
||||
return; // must be existing non void bill
|
||||
|
||||
if (!Session.IsAllowed("Split Bill"))
|
||||
@ -647,13 +623,13 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
#region new voucherFirst
|
||||
var voucherFirst = new Voucher(Session.User)
|
||||
{
|
||||
Customer = _billInfo.Customer,
|
||||
Customer = _voucher.Customer,
|
||||
Table = table,
|
||||
Waiter = _billInfo.Waiter,
|
||||
Waiter = _voucher.Waiter,
|
||||
Printed = isPrinted,
|
||||
Void = false,
|
||||
Narration = "",
|
||||
VoucherType = _billInfo.VoucherType
|
||||
VoucherType = _voucher.VoucherType
|
||||
};
|
||||
|
||||
var kotFirst = GetKot(listFirst);
|
||||
@ -664,13 +640,13 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
#region new voucherSecond
|
||||
var voucherSecond = new Voucher(Session.User)
|
||||
{
|
||||
Customer = _billInfo.Customer,
|
||||
Table = _billInfo.Table,
|
||||
Waiter = _billInfo.Waiter,
|
||||
Customer = _voucher.Customer,
|
||||
Table = _voucher.Table,
|
||||
Waiter = _voucher.Waiter,
|
||||
Printed = isPrinted,
|
||||
Void = false,
|
||||
Narration = "",
|
||||
VoucherType = _billInfo.VoucherType
|
||||
VoucherType = _voucher.VoucherType
|
||||
};
|
||||
|
||||
var kotSecond = GetKot(listSecond);
|
||||
@ -679,7 +655,10 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
#endregion
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
bi.SplitBill(_billInfo.VoucherID, voucherFirst, voucherSecond);
|
||||
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)
|
||||
@ -692,11 +671,9 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
public void VoidBill()
|
||||
{
|
||||
#region Check conditions and Permissions
|
||||
if (_billInfo.VoucherID == Guid.Empty)
|
||||
if (_voucher.VoucherID == Guid.Empty)
|
||||
return;
|
||||
//if (!_billInfo.Printed)
|
||||
// return;
|
||||
if (_billInfo.Void)
|
||||
if (_voucher.Void)
|
||||
return;
|
||||
if (!Session.IsAllowed("Void Bill"))
|
||||
return;
|
||||
@ -710,7 +687,9 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
{
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
bi.VoidBill(_billInfo.VoucherID, voidReason.SelectedItem.Description, !_editVoucherID.HasValue);
|
||||
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();
|
||||
}
|
||||
ClearBill();
|
||||
@ -744,13 +723,13 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
#region new voucherFirst
|
||||
var newVoucher = new Voucher(Session.User)
|
||||
{
|
||||
Customer = _billInfo.Customer,
|
||||
Table = _billInfo.Table,
|
||||
Waiter = _billInfo.Waiter,
|
||||
Customer = _voucher.Customer,
|
||||
Table = _voucher.Table,
|
||||
Waiter = _voucher.Waiter,
|
||||
Printed = true,
|
||||
Void = false,
|
||||
Narration = "",
|
||||
VoucherType = _billInfo.VoucherType
|
||||
VoucherType = _voucher.VoucherType
|
||||
};
|
||||
|
||||
var kotNew = GetKot(_bill.Where(x => x.Key.BillItemType == BillItemType.Product));
|
||||
@ -760,32 +739,39 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
bi.DiscountPrintedBill(_billInfo.VoucherID, newVoucher);
|
||||
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();
|
||||
}
|
||||
_editVoucherID = null;
|
||||
LoadBill(newVoucher.VoucherID);
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var bi = new ReprintBI())
|
||||
{
|
||||
bi.Insert(new Reprint() { User = Session.User, Voucher = _billInfo });
|
||||
bi.Insert(new Reprint() { User = Session.User, Voucher = _voucher });
|
||||
bi.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
private Guid? InsertVoucher(bool finalBill, bool updateTable)
|
||||
{
|
||||
_billInfo.Printed = finalBill;
|
||||
_billInfo.Void = false;
|
||||
_billInfo.Narration = "";
|
||||
_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.Quantity != 0));
|
||||
if (kot == null)
|
||||
return null;
|
||||
_billInfo.Kots.Add(kot);
|
||||
_voucher.Kots.Add(kot);
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
var kotID = bi.Insert(_billInfo, updateTable);
|
||||
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;
|
||||
}
|
||||
@ -794,25 +780,31 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
{
|
||||
using (var bi = new VoucherBI())
|
||||
{
|
||||
var voucher = bi.Get(x => x.VoucherID == _billInfo.VoucherID);
|
||||
var voucher = bi.Get(x => x.VoucherID == _voucher.VoucherID);
|
||||
voucher.User = Session.User;
|
||||
voucher.Customer = _billInfo.Customer;
|
||||
voucher.Waiter = _billInfo.Waiter;
|
||||
voucher.Customer = _voucher.Customer;
|
||||
voucher.Waiter = _voucher.Waiter;
|
||||
voucher.Printed = finalBill;
|
||||
voucher.VoucherType = _billInfo.VoucherType;
|
||||
voucher.VoucherType = _voucher.VoucherType;
|
||||
foreach (var item in _bill.Where(x => x.Key.BillItemType == BillItemType.Product && 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);
|
||||
i.Discount = item.Value.Discount;
|
||||
i.Price = item.Value.Price;
|
||||
}
|
||||
if (!_billInfo.Printed)
|
||||
if (!_voucher.Printed)
|
||||
{
|
||||
var kot = GetKot(_bill.Where(x => x.Key.BillItemType == BillItemType.Product && x.Key.KotID == Guid.Empty && x.Value.Quantity != 0));
|
||||
if (kot != null)
|
||||
voucher.Kots.Add(kot);
|
||||
}
|
||||
var kotID = bi.Update(voucher, updateTable);
|
||||
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();
|
||||
return kotID;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
private void btnSale_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (Session.IsAllowed("Sales"))
|
||||
using (var frmSale = new SalesForm(new BillController(null, true)))
|
||||
using (var frmSale = new SalesForm(new BillController(null)))
|
||||
{
|
||||
frmSale.ShowDialog();
|
||||
Cache.Invalidate();
|
||||
@ -240,7 +240,7 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
if (voucher == null)
|
||||
return;
|
||||
if (Session.IsAllowed("Sales"))
|
||||
using (var frmSale = new SalesForm(new BillController(voucher.VoucherID, true)))
|
||||
using (var frmSale = new SalesForm(new BillController(voucher.VoucherID)))
|
||||
frmSale.ShowDialog();
|
||||
}
|
||||
|
||||
|
@ -29,14 +29,12 @@
|
||||
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 dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle();
|
||||
this.btnAdd = new System.Windows.Forms.Button();
|
||||
this.btnEdit = new System.Windows.Forms.Button();
|
||||
this.btnExit = new System.Windows.Forms.Button();
|
||||
this.dgvProducts = new System.Windows.Forms.DataGridView();
|
||||
this.bsList = new System.Windows.Forms.BindingSource(this.components);
|
||||
this.btnSave = new System.Windows.Forms.Button();
|
||||
this.nameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.unitsDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.moveUp = new System.Windows.Forms.DataGridViewButtonColumn();
|
||||
@ -47,6 +45,9 @@
|
||||
this.serviceChargeDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.salePriceDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.isActiveDataGridViewCheckBoxColumn = new System.Windows.Forms.DataGridViewCheckBoxColumn();
|
||||
this.bsList = new System.Windows.Forms.BindingSource(this.components);
|
||||
this.btnSave = new System.Windows.Forms.Button();
|
||||
this.chkIsActive = new System.Windows.Forms.CheckBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dgvProducts)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.bsList)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -119,21 +120,6 @@
|
||||
this.dgvProducts.TabIndex = 74;
|
||||
this.dgvProducts.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.dgvProductTypes_CellFormatting);
|
||||
//
|
||||
// bsList
|
||||
//
|
||||
this.bsList.DataSource = typeof(Tanshu.Accounts.Entities.Product);
|
||||
//
|
||||
// btnSave
|
||||
//
|
||||
this.btnSave.AccessibleName = "Done";
|
||||
this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.btnSave.Location = new System.Drawing.Point(174, 255);
|
||||
this.btnSave.Name = "btnSave";
|
||||
this.btnSave.Size = new System.Drawing.Size(75, 75);
|
||||
this.btnSave.TabIndex = 75;
|
||||
this.btnSave.Text = "&Save";
|
||||
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
|
||||
//
|
||||
// nameDataGridViewTextBoxColumn
|
||||
//
|
||||
this.nameDataGridViewTextBoxColumn.DataPropertyName = "Name";
|
||||
@ -195,8 +181,8 @@
|
||||
// serviceChargeDataGridViewTextBoxColumn
|
||||
//
|
||||
this.serviceChargeDataGridViewTextBoxColumn.DataPropertyName = "ServiceCharge";
|
||||
dataGridViewCellStyle1.Format = "P0";
|
||||
this.serviceChargeDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle1;
|
||||
dataGridViewCellStyle7.Format = "P0";
|
||||
this.serviceChargeDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle7;
|
||||
this.serviceChargeDataGridViewTextBoxColumn.HeaderText = "SC";
|
||||
this.serviceChargeDataGridViewTextBoxColumn.Name = "serviceChargeDataGridViewTextBoxColumn";
|
||||
this.serviceChargeDataGridViewTextBoxColumn.ReadOnly = true;
|
||||
@ -205,8 +191,8 @@
|
||||
// salePriceDataGridViewTextBoxColumn
|
||||
//
|
||||
this.salePriceDataGridViewTextBoxColumn.DataPropertyName = "Price";
|
||||
dataGridViewCellStyle2.Format = "N0";
|
||||
this.salePriceDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle2;
|
||||
dataGridViewCellStyle8.Format = "N0";
|
||||
this.salePriceDataGridViewTextBoxColumn.DefaultCellStyle = dataGridViewCellStyle8;
|
||||
this.salePriceDataGridViewTextBoxColumn.HeaderText = "Price";
|
||||
this.salePriceDataGridViewTextBoxColumn.Name = "salePriceDataGridViewTextBoxColumn";
|
||||
this.salePriceDataGridViewTextBoxColumn.ReadOnly = true;
|
||||
@ -218,13 +204,44 @@
|
||||
this.isActiveDataGridViewCheckBoxColumn.HeaderText = "Is Active";
|
||||
this.isActiveDataGridViewCheckBoxColumn.Name = "isActiveDataGridViewCheckBoxColumn";
|
||||
this.isActiveDataGridViewCheckBoxColumn.ReadOnly = true;
|
||||
this.isActiveDataGridViewCheckBoxColumn.Width = 75;
|
||||
this.isActiveDataGridViewCheckBoxColumn.Width = 54;
|
||||
//
|
||||
// bsList
|
||||
//
|
||||
this.bsList.DataSource = typeof(Tanshu.Accounts.Entities.Product);
|
||||
//
|
||||
// btnSave
|
||||
//
|
||||
this.btnSave.AccessibleName = "Done";
|
||||
this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.btnSave.Location = new System.Drawing.Point(174, 255);
|
||||
this.btnSave.Name = "btnSave";
|
||||
this.btnSave.Size = new System.Drawing.Size(75, 75);
|
||||
this.btnSave.TabIndex = 75;
|
||||
this.btnSave.Text = "&Save";
|
||||
this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
|
||||
//
|
||||
// chkIsActive
|
||||
//
|
||||
this.chkIsActive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.chkIsActive.AutoSize = true;
|
||||
this.chkIsActive.Checked = true;
|
||||
this.chkIsActive.CheckState = System.Windows.Forms.CheckState.Checked;
|
||||
this.chkIsActive.Location = new System.Drawing.Point(255, 285);
|
||||
this.chkIsActive.Name = "chkIsActive";
|
||||
this.chkIsActive.Size = new System.Drawing.Size(116, 17);
|
||||
this.chkIsActive.TabIndex = 76;
|
||||
this.chkIsActive.Text = "Show Active Only?";
|
||||
this.chkIsActive.ThreeState = true;
|
||||
this.chkIsActive.UseVisualStyleBackColor = true;
|
||||
this.chkIsActive.CheckStateChanged += new System.EventHandler(this.chkIsActive_CheckStateChanged);
|
||||
//
|
||||
// ProductListForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(662, 342);
|
||||
this.Controls.Add(this.chkIsActive);
|
||||
this.Controls.Add(this.btnSave);
|
||||
this.Controls.Add(this.dgvProducts);
|
||||
this.Controls.Add(this.btnAdd);
|
||||
@ -239,6 +256,7 @@
|
||||
((System.ComponentModel.ISupportInitialize)(this.dgvProducts)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.bsList)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
@ -260,6 +278,7 @@
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn serviceChargeDataGridViewTextBoxColumn;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn salePriceDataGridViewTextBoxColumn;
|
||||
private System.Windows.Forms.DataGridViewCheckBoxColumn isActiveDataGridViewCheckBoxColumn;
|
||||
private System.Windows.Forms.CheckBox chkIsActive;
|
||||
//private System.Windows.Forms.DataGridViewTextBoxColumn discountLimitDataGridViewTextBoxColumn;
|
||||
//private System.Windows.Forms.DataGridViewTextBoxColumn groupTypeDataGridViewTextBoxColumn;
|
||||
//private System.Windows.Forms.DataGridViewTextBoxColumn productGroupDataGridViewTextBoxColumn;
|
||||
|
@ -25,9 +25,24 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
}
|
||||
|
||||
private void ProductGroupListForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
ShowGrid();
|
||||
}
|
||||
private void ShowGrid()
|
||||
{
|
||||
using (var bi = new ProductBI())
|
||||
_list = bi.List();
|
||||
switch (chkIsActive.CheckState)
|
||||
{
|
||||
case CheckState.Checked:
|
||||
_list = bi.List(x => x.IsActive == true);
|
||||
break;
|
||||
case CheckState.Unchecked:
|
||||
_list = bi.List(x => x.IsActive == false);
|
||||
break;
|
||||
default:
|
||||
_list = bi.List();
|
||||
break;
|
||||
}
|
||||
bsList.DataSource = _list;
|
||||
}
|
||||
|
||||
@ -108,9 +123,25 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
{
|
||||
bi.UpdateSortOrder(_list);
|
||||
bi.SaveChanges();
|
||||
_list = bi.List();
|
||||
switch (chkIsActive.CheckState)
|
||||
{
|
||||
case CheckState.Checked:
|
||||
_list = bi.List(x => x.IsActive == true);
|
||||
break;
|
||||
case CheckState.Unchecked:
|
||||
_list = bi.List(x => x.IsActive == false);
|
||||
break;
|
||||
default:
|
||||
_list = bi.List();
|
||||
break;
|
||||
}
|
||||
bsList.DataSource = _list;
|
||||
}
|
||||
}
|
||||
|
||||
private void chkIsActive_CheckStateChanged(object sender, EventArgs e)
|
||||
{
|
||||
ShowGrid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -135,4 +135,22 @@
|
||||
<metadata name="bsList.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="moveUp.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="moveDown.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Vat.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="ServiceTax.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="Group.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<metadata name="bsList.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
@ -17,6 +17,7 @@ namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
var list = _session.QueryOver<Product>()
|
||||
.Where(query)
|
||||
.OrderBy(x => x.ProductGroup).Asc
|
||||
.OrderBy(x => x.SortOrder).Asc
|
||||
.ThenBy(x => x.Name).Asc
|
||||
.List();
|
||||
|
@ -9,7 +9,7 @@ using Tanshu.Accounts.Contracts;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class VoucherBI : UnitOfWork<Voucher>
|
||||
public partial class VoucherBI : UnitOfWork<Voucher>
|
||||
{
|
||||
public new Guid Insert(Voucher voucher)
|
||||
{
|
||||
@ -38,30 +38,10 @@ namespace Tanshu.Accounts.Repository
|
||||
}
|
||||
}
|
||||
}
|
||||
var amount = -1 * voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount));
|
||||
VoucherSettlementBI.UpdateSettlements(voucher.Settlements, amount);
|
||||
foreach (var settlement in voucher.Settlements.Where(x => x.Amount != 0 || x.Settled == SettleOption.Amount))
|
||||
{
|
||||
settlement.Voucher = voucher;
|
||||
_session.Save(settlement);
|
||||
}
|
||||
var options = GetSettlementOptions(voucher);
|
||||
UpdateSettlements(voucher, options);
|
||||
return addedKot == null ? Guid.Empty : addedKot.KotID;
|
||||
}
|
||||
public Guid Insert(Voucher voucher, bool updateTable)
|
||||
{
|
||||
var kotID = Insert(voucher);
|
||||
if (updateTable)
|
||||
{
|
||||
var table = _session.QueryOver<FoodTable>().Where(x => x.FoodTableID == voucher.Table.FoodTableID).SingleOrDefault();
|
||||
if (table.VoucherID.HasValue)
|
||||
throw new ValidationException("A bill exists on this table, cannot overwrite");
|
||||
var status = !voucher.Printed ? "running" : "printed";
|
||||
table.VoucherID = voucher.VoucherID;
|
||||
table.Status = status;
|
||||
_session.Update(table);
|
||||
}
|
||||
return kotID;
|
||||
}
|
||||
public new Guid? Update(Voucher voucher)
|
||||
{
|
||||
_session.Update(voucher);
|
||||
@ -90,36 +70,10 @@ namespace Tanshu.Accounts.Repository
|
||||
}
|
||||
}
|
||||
UpdateBillType(voucher);
|
||||
var amount = -1 * voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount));
|
||||
VoucherSettlementBI.UpdateSettlements(voucher.Settlements, amount);
|
||||
foreach (var settlement in voucher.Settlements)
|
||||
{
|
||||
settlement.Voucher = voucher;
|
||||
if (settlement.Amount == 0)
|
||||
{
|
||||
if (settlement.VoucherSettlementID != Guid.Empty)
|
||||
_session.Delete(settlement);
|
||||
}
|
||||
else if (settlement.VoucherSettlementID == Guid.Empty)
|
||||
_session.Save(settlement);
|
||||
else
|
||||
_session.Update(settlement);
|
||||
}
|
||||
var options = GetSettlementOptions(voucher);
|
||||
UpdateSettlements(voucher, options);
|
||||
return addedKot == null ? (Guid?)null : addedKot.KotID;
|
||||
}
|
||||
public Guid? Update(Voucher voucher, bool updateTable)
|
||||
{
|
||||
var kotID = Update(voucher);
|
||||
if (updateTable)
|
||||
{
|
||||
var table = _session.QueryOver<FoodTable>().Where(x => x.FoodTableID == voucher.Table.FoodTableID).SingleOrDefault();
|
||||
var status = !voucher.Printed ? "running" : "printed";
|
||||
table.VoucherID = voucher.VoucherID;
|
||||
table.Status = status;
|
||||
_session.Update(table);
|
||||
}
|
||||
return kotID;
|
||||
}
|
||||
public new Voucher Get(Expression<Func<Voucher, bool>> query)
|
||||
{
|
||||
var voucher = _session.QueryOver<Voucher>()
|
||||
@ -148,20 +102,22 @@ namespace Tanshu.Accounts.Repository
|
||||
NHibernateUtil.Initialize(item);
|
||||
return voucher;
|
||||
}
|
||||
public void VoidBill(Guid voucherID, string reason, bool updateTable)
|
||||
public void VoidBill(Guid voucherID, string reason)
|
||||
{
|
||||
var voucher = _session.Get<Voucher>(voucherID);
|
||||
voucher.Void = true;
|
||||
voucher.VoidReason = reason;
|
||||
_session.Update(voucher);
|
||||
}
|
||||
|
||||
if (updateTable)
|
||||
{
|
||||
var table = _session.QueryOver<FoodTable>().Where(x => x.FoodTableID == voucher.Table.FoodTableID).SingleOrDefault();
|
||||
table.VoucherID = null;
|
||||
table.Status = null;
|
||||
_session.Update(table);
|
||||
}
|
||||
public void UpdateTable(Expression<Func<FoodTable, bool>> query, Guid? newVoucherID, string status)
|
||||
{
|
||||
var table = _session.QueryOver<FoodTable>().Where(query).SingleOrDefault();
|
||||
if (table == null)
|
||||
throw new ValidationException("Old Voucher on the table does not match");
|
||||
table.Status = status;
|
||||
table.VoucherID = newVoucherID;
|
||||
_session.Update(table);
|
||||
}
|
||||
|
||||
public Guid MergeKot(Guid kotID, string tableName)
|
||||
@ -197,15 +153,11 @@ namespace Tanshu.Accounts.Repository
|
||||
_session.Update(newVoucher);
|
||||
|
||||
|
||||
var oldTable = _session.QueryOver<FoodTable>().Where(x => x.FoodTableID == oldVoucher.Table.FoodTableID).SingleOrDefault();
|
||||
foreach (var item in oldVoucher.Settlements)
|
||||
{
|
||||
_session.Delete(item);
|
||||
}
|
||||
_session.Delete(oldVoucher);
|
||||
oldTable.VoucherID = null;
|
||||
oldTable.Status = null;
|
||||
_session.Update(oldTable);
|
||||
return newVoucher.VoucherID;
|
||||
}
|
||||
private void UpdateBillType(Voucher voucher)
|
||||
@ -253,10 +205,6 @@ namespace Tanshu.Accounts.Repository
|
||||
var table = _session.QueryOver<FoodTable>().Where(x => x.FoodTableID == tableID).SingleOrDefault();
|
||||
var newVoucher = new Voucher(Session.User, oldVoucher.Customer, table, oldVoucher.Waiter, false, false, "");
|
||||
Insert(newVoucher);
|
||||
table.VoucherID = newVoucher.VoucherID;
|
||||
table.Status = "running";
|
||||
_session.Update(table);
|
||||
|
||||
|
||||
oldVoucher.Kots.Remove(kot);
|
||||
kot.Voucher = newVoucher;
|
||||
@ -279,20 +227,6 @@ namespace Tanshu.Accounts.Repository
|
||||
Insert(first);
|
||||
Insert(second);
|
||||
Update(oldVoucher);
|
||||
|
||||
var status = oldVoucher.Printed ? "printed" : "running";
|
||||
|
||||
var tableFirst = _session.QueryOver<FoodTable>().Where(x => x.FoodTableID == first.Table.FoodTableID).SingleOrDefault();
|
||||
if (tableFirst.VoucherID.HasValue)
|
||||
throw new ValidationException("A bill exists on this table, cannot overwrite");
|
||||
tableFirst.VoucherID = first.VoucherID;
|
||||
tableFirst.Status = status;
|
||||
_session.Update(tableFirst);
|
||||
|
||||
var tableSecond = _session.QueryOver<FoodTable>().Where(x => x.FoodTableID == second.Table.FoodTableID).SingleOrDefault();
|
||||
tableSecond.VoucherID = second.VoucherID;
|
||||
tableSecond.Status = status;
|
||||
_session.Update(tableFirst);
|
||||
}
|
||||
|
||||
public void DiscountPrintedBill(Guid oldVoucherID, Voucher newVoucher)
|
||||
@ -304,30 +238,13 @@ namespace Tanshu.Accounts.Repository
|
||||
|
||||
Insert(newVoucher);
|
||||
Update(oldVoucher);
|
||||
|
||||
var table = _session.QueryOver<FoodTable>().Where(x => x.FoodTableID == oldVoucher.Table.FoodTableID).SingleOrDefault();
|
||||
table.VoucherID = newVoucher.VoucherID;
|
||||
table.Status = "printed";
|
||||
_session.Update(table);
|
||||
}
|
||||
public Guid Move(Guid oldTableID, Guid newTableID)
|
||||
public void MoveTable(Guid voucherID, Guid tableID)
|
||||
{
|
||||
var oldTable = _session.QueryOver<FoodTable>().Where(x => x.FoodTableID == oldTableID).SingleOrDefault();
|
||||
var newTable = _session.QueryOver<FoodTable>().Where(x => x.FoodTableID == newTableID).SingleOrDefault();
|
||||
var voucher = _session.Get<Voucher>(oldTable.VoucherID);
|
||||
|
||||
newTable.Status = oldTable.Status;
|
||||
newTable.VoucherID = oldTable.VoucherID;
|
||||
|
||||
oldTable.Status = null;
|
||||
oldTable.VoucherID = null;
|
||||
|
||||
var voucher = _session.Get<Voucher>(voucherID);
|
||||
var newTable = _session.QueryOver<FoodTable>().Where(x => x.FoodTableID == tableID).SingleOrDefault();
|
||||
voucher.Table = newTable;
|
||||
|
||||
_session.Update(newTable);
|
||||
_session.Update(oldTable);
|
||||
_session.Update(voucher);
|
||||
return voucher.VoucherID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,35 +8,25 @@ using Tanshu.Common.Helpers;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public class VoucherSettlementBI : UnitOfWork<VoucherSettlement>
|
||||
public partial class VoucherBI : UnitOfWork<Voucher>
|
||||
{
|
||||
public static void UpdateSettlements(IList<VoucherSettlement> list, decimal amount)
|
||||
private IDictionary<SettleOption, decimal> GetSettlementOptions(Voucher voucher)
|
||||
{
|
||||
amount = Math.Round(amount, 5);
|
||||
if (list.Count(x => x.Settled == SettleOption.Amount) == 0)
|
||||
list.Add(new VoucherSettlement() { Amount = amount, Settled = SettleOption.Amount });
|
||||
else
|
||||
list.Single(x => x.Settled == SettleOption.Amount).Amount = amount;
|
||||
|
||||
var roundoff = Math.Round(amount) - amount;
|
||||
if (list.Count(x => x.Settled == SettleOption.RoundOff) == 0)
|
||||
list.Add(new VoucherSettlement() { Amount = roundoff, Settled = SettleOption.RoundOff });
|
||||
else
|
||||
list.Single(x => x.Settled == SettleOption.RoundOff).Amount = roundoff;
|
||||
|
||||
var balance = list.Where(x => x.Settled != SettleOption.Unsettled).Sum(x => x.Amount) * -1;
|
||||
if (list.Count(x => x.Settled == SettleOption.Unsettled) == 0)
|
||||
IDictionary<SettleOption, decimal> options = new Dictionary<SettleOption, decimal>();
|
||||
foreach (var item in voucher.Settlements)
|
||||
{
|
||||
if (balance != 0)
|
||||
list.Add(new VoucherSettlement() { Amount = balance, Settled = SettleOption.Unsettled });
|
||||
if (item.Settled == SettleOption.Amount || item.Settled == SettleOption.RoundOff || item.Settled == SettleOption.Unsettled)
|
||||
continue;
|
||||
if (options.ContainsKey(item.Settled))
|
||||
options[item.Settled] += item.Amount;
|
||||
else
|
||||
options.Add(item.Settled, item.Amount);
|
||||
}
|
||||
else
|
||||
list.Single(x => x.Settled == SettleOption.Unsettled).Amount = balance;
|
||||
return options;
|
||||
}
|
||||
|
||||
public void SettleVoucher(User user, Guid voucherID, IDictionary<SettleOption, decimal> values)
|
||||
public void UpdateSettlements(Voucher voucher, IDictionary<SettleOption, decimal> values)
|
||||
{
|
||||
var voucher = _session.Get<Voucher>(voucherID);
|
||||
var amount = Math.Round(-1 * voucher.Kots.Sum(x => x.Inventories.Sum(y => y.Amount)), 5);
|
||||
values.Add(SettleOption.Amount, Math.Round(amount, 5));
|
||||
var roundoff = Math.Round(amount) - amount;
|
||||
@ -46,21 +36,6 @@ namespace Tanshu.Accounts.Repository
|
||||
if (unsettled != 0)
|
||||
values.Add(SettleOption.Unsettled, unsettled);
|
||||
|
||||
UpdateOld(voucher, values);
|
||||
AddNew(voucher, values);
|
||||
|
||||
voucher.User = user;
|
||||
_session.Update(voucher);
|
||||
|
||||
var table = _session.QueryOver<FoodTable>()
|
||||
.Where(x => x.FoodTableID == voucher.Table.FoodTableID && x.VoucherID == voucher.VoucherID)
|
||||
.SingleOrDefault();
|
||||
table.VoucherID = null;
|
||||
table.Status = null;
|
||||
_session.Update(table);
|
||||
}
|
||||
private void UpdateOld(Voucher voucher, IDictionary<SettleOption, decimal> values)
|
||||
{
|
||||
for (var i = voucher.Settlements.Count - 1; i >= 0; i--)
|
||||
{
|
||||
var item = voucher.Settlements[i];
|
||||
@ -76,15 +51,21 @@ namespace Tanshu.Accounts.Repository
|
||||
values.Remove(item.Settled);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void AddNew(Voucher voucher, IDictionary<SettleOption, decimal> values)
|
||||
{
|
||||
foreach (var item in values)
|
||||
{
|
||||
var set = new VoucherSettlement { Settled = item.Key, Amount = item.Value, Voucher = voucher };
|
||||
voucher.Settlements.Add(set);
|
||||
_session.Save(set);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void SettleVoucher(User user, Guid voucherID, IDictionary<SettleOption, decimal> values)
|
||||
{
|
||||
var voucher = _session.Get<Voucher>(voucherID);
|
||||
UpdateSettlements(voucher, values);
|
||||
voucher.User = user;
|
||||
_session.Update(voucher);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user