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