User management fixed. Reports working now. Deployed
This commit is contained in:
@ -11,227 +11,148 @@ using Tanshu.Accounts.Entities;
|
||||
|
||||
namespace Tanshu.Accounts.PointOfSale
|
||||
{
|
||||
public static class BillHelperFunctions
|
||||
public class BillHelperFunctions
|
||||
{
|
||||
#region Discount
|
||||
public static void SetDiscount(int productID, decimal discount, Customer customer, OrderedDictionary<BillItemKey, BillInventory> bill)
|
||||
BindingSource bindingSource;
|
||||
OrderedDictionary<BillItemKey, BillInventory> bill;
|
||||
BillItemKey oldKey;
|
||||
BillItemKey newKey;
|
||||
public BillHelperFunctions(BindingSource bindingSource, OrderedDictionary<BillItemKey, BillInventory> bill, int productID)
|
||||
{
|
||||
#region InputBox
|
||||
if (discount == -1)
|
||||
{
|
||||
InputBoxResult result = InputBox.Show("Discount", "0", InputBox_Validating);
|
||||
if (result.OK)
|
||||
{
|
||||
if (!decimal.TryParse(result.Text, out discount))
|
||||
return;
|
||||
discount /= 100;
|
||||
}
|
||||
}
|
||||
if (discount == -1)
|
||||
this.bindingSource = bindingSource;
|
||||
this.bill = bill;
|
||||
this.oldKey = new BillItemKey(productID, false);
|
||||
this.newKey = new BillItemKey(productID, true);
|
||||
}
|
||||
public void SetDiscount(string name, decimal discount)
|
||||
{
|
||||
if (discount > 1 || discount < 0)
|
||||
return;
|
||||
#endregion
|
||||
|
||||
#region Max Discount
|
||||
decimal maxDiscount = SaleVoucherBI.GetProductDiscountLimit(productID);
|
||||
if ((discount > maxDiscount) && customer.CustomerID != 1)
|
||||
{
|
||||
MessageBox.Show(string.Format("Maximum discount for this product is {0:P}", maxDiscount), "Excessive Discount", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
}
|
||||
else if ((discount > maxDiscount) && customer.CustomerID == 1)
|
||||
{
|
||||
MessageBox.Show(string.Format("Maximum discount for this product is {0:P} Discount Disallowed", maxDiscount), "Excessive Discount", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
#endregion
|
||||
|
||||
if (bill.ContainsKey(new BillItemKey(productID, true)))
|
||||
SetDiscount(bill[new BillItemKey(productID, true)], discount);
|
||||
if (bill.ContainsKey(new BillItemKey(productID, false)))
|
||||
SetDiscount(bill[new BillItemKey(productID, false)], discount);
|
||||
decimal maxDiscount = SaleVoucherBI.GetProductDiscountLimit(newKey.ProductID);
|
||||
if (discount > maxDiscount)
|
||||
MessageBox.Show(string.Format("Maximum discount for {0} is {1:P}", name, maxDiscount), "Excessive Discount", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
if (bill.ContainsKey(oldKey))
|
||||
bill[oldKey].Discount = discount;
|
||||
if (bill.ContainsKey(newKey))
|
||||
bill[newKey].Discount = discount;
|
||||
return;
|
||||
}
|
||||
private static void SetDiscount(BillInventory product, decimal discount)
|
||||
{
|
||||
product.Discount = discount;
|
||||
}
|
||||
#endregion
|
||||
#region Add Product
|
||||
public static BillInventory AddProductToGrid(int productID, BindingSource bindingSource, OrderedDictionary<BillItemKey, BillInventory> bill)
|
||||
public BillInventory AddProduct()
|
||||
{
|
||||
BillInventory product;
|
||||
if ((!bill.ContainsKey(new BillItemKey(productID, false))) && (!bill.ContainsKey(new BillItemKey(productID, true))))
|
||||
if ((!bill.ContainsKey(oldKey)) && (!bill.ContainsKey(newKey)))
|
||||
{
|
||||
//No new or old
|
||||
product = AddNewProduct(productID, bindingSource, bill);
|
||||
product = SaleVoucherBI.GetDefaultSaleBillItem(newKey.ProductID);
|
||||
product = AddProduct(product);
|
||||
}
|
||||
else if (bill.ContainsKey(new BillItemKey(productID, true)))
|
||||
else if (bill.ContainsKey(newKey))
|
||||
{
|
||||
//Has new or both
|
||||
BillItemKey key = new BillItemKey(productID, true);
|
||||
bindingSource.CurrencyManager.Position = ProductPosition(key, bill);
|
||||
product = bill[key];
|
||||
SetQuantity(product, 1, false);
|
||||
bindingSource.CurrencyManager.Position = bill.IndexOfKey(newKey);
|
||||
product = bill[newKey];
|
||||
product.Quantity += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Has only old
|
||||
product = bill[new BillItemKey(productID, false)];
|
||||
if (product.Additional <= -1)
|
||||
SetQuantity(product, 1, false);
|
||||
else if (product.Additional < 0)
|
||||
{
|
||||
decimal quantity = 1 + product.Additional;
|
||||
SetQuantity(product, 1, false);
|
||||
|
||||
decimal rate = bill[new BillItemKey(productID, false)].Discount;
|
||||
decimal discount = bill[new BillItemKey(productID, false)].Price;
|
||||
product = AddNewProduct(productID, bindingSource, bill);
|
||||
SetDiscount(product, discount);
|
||||
SetRate(productID, rate, bill);
|
||||
|
||||
SetQuantity(product, quantity, true);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
decimal discount = bill[new BillItemKey(productID, false)].Discount;
|
||||
decimal rate = bill[new BillItemKey(productID, false)].Price;
|
||||
product = AddNewProduct(productID, bindingSource, bill);
|
||||
SetDiscount(product, discount);
|
||||
SetRate(productID, rate, bill);
|
||||
}
|
||||
product = SaleVoucherBI.GetDefaultSaleBillItem(oldKey.ProductID);
|
||||
product.Discount = bill[oldKey].Discount;
|
||||
product.Price = bill[oldKey].Price;
|
||||
product = AddProduct(product);
|
||||
}
|
||||
return product;
|
||||
}
|
||||
private static BillInventory AddNewProduct(int productID, BindingSource bindingSource, OrderedDictionary<BillItemKey, BillInventory> bill)
|
||||
private BillInventory AddProduct(BillInventory product)
|
||||
{
|
||||
BillItemKey key = new BillItemKey(productID, true);
|
||||
BillInventory product = SaleVoucherBI.GetDefaultSaleBillItem(productID);
|
||||
product.Quantity = 1;
|
||||
bill.Add(key, product);
|
||||
bill.Add(new BillItemKey(product.ProductID, true), product);
|
||||
bindingSource.DataSource = bill.Values;
|
||||
bindingSource.CurrencyManager.Position = bindingSource.CurrencyManager.Count + 1;
|
||||
return product;
|
||||
|
||||
}
|
||||
private static int ProductPosition(BillItemKey key, OrderedDictionary<BillItemKey, BillInventory> bill)
|
||||
{
|
||||
for (int i = 0; i < bill.Count; i++)
|
||||
{
|
||||
if (bill.Keys.ElementAt(i) == key)
|
||||
return i;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region Quantity
|
||||
public static void SetQuantity(BillInventory product, decimal quantity, bool absolute, bool prompt, BindingSource bindingSource, OrderedDictionary<BillItemKey, BillInventory> bill)
|
||||
public void SetQuantity(BillInventory product, decimal quantity, bool prompt)
|
||||
{
|
||||
#region Prompt
|
||||
if (prompt)
|
||||
{
|
||||
InputBoxResult result = InputBox.Show("Quantity", (product.Quantity + 1).ToString(), InputBox_Validating);
|
||||
if (result.OK)
|
||||
{
|
||||
if (!decimal.TryParse(result.Text, out quantity))
|
||||
return;
|
||||
absolute = true;
|
||||
}
|
||||
}
|
||||
if (quantity == 0)
|
||||
if (prompt && !GetInput("Price", ref quantity))
|
||||
return;
|
||||
#endregion
|
||||
|
||||
CheckQuantity(product, quantity, absolute);
|
||||
|
||||
if (product.Printed == 0)
|
||||
{
|
||||
SetQuantity(product, quantity, absolute);
|
||||
{ // new
|
||||
if (!prompt)
|
||||
quantity += product.Quantity;
|
||||
SetQuantity(product, quantity);
|
||||
}
|
||||
else if (bill.ContainsKey(new BillItemKey(product.ProductID, true)))
|
||||
else if (bill.ContainsKey(newKey))
|
||||
{
|
||||
BillInventory otherProduct = bill[new BillItemKey(product.ProductID, true)];
|
||||
if (absolute)
|
||||
SetQuantity(otherProduct, quantity - product.Printed, absolute);
|
||||
BillInventory newProduct = bill[newKey];
|
||||
if (prompt)
|
||||
SetQuantity(newProduct, quantity - product.Printed);
|
||||
else
|
||||
SetQuantity(otherProduct, quantity, absolute);
|
||||
SetQuantity(newProduct, newProduct.Quantity + quantity);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (product.Additional < 0)
|
||||
////Has only old
|
||||
if (prompt)
|
||||
quantity -= product.Printed;
|
||||
if (quantity > 0 || Session.IsAllowed(RoleConstants.EDIT_PRINTED_PRODUCT))
|
||||
{
|
||||
if (!absolute)
|
||||
quantity += product.Additional;
|
||||
product.Quantity = product.Printed;
|
||||
}
|
||||
if (absolute)
|
||||
quantity -= product.Quantity;
|
||||
if (quantity > 0)
|
||||
{
|
||||
BillInventory otherProduct = AddProductToGrid(product.ProductID, bindingSource, bill);
|
||||
SetQuantity(otherProduct, quantity, true);
|
||||
}
|
||||
else if ((quantity < 0) && (Thread.CurrentPrincipal.IsInRole("Sales/EditPrintedProduct")))
|
||||
{
|
||||
SetQuantity(product, quantity, false);
|
||||
var newProduct = SaleVoucherBI.GetDefaultSaleBillItem(product.ProductID);
|
||||
newProduct.Price = product.Price;
|
||||
newProduct.Discount = product.Discount;
|
||||
newProduct = AddProduct(newProduct);
|
||||
SetQuantity(newProduct, quantity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private static bool CheckQuantity(BillInventory product, decimal quantity, bool absolute)
|
||||
private void SetQuantity(BillInventory product, decimal quantity)
|
||||
{
|
||||
if (!absolute)
|
||||
quantity = product.Quantity + quantity;
|
||||
if (quantity < 0)
|
||||
return false;
|
||||
else if ((quantity < product.Printed) && (!Thread.CurrentPrincipal.IsInRole("Sales/EditPrintedProduct")))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
private static void SetQuantity(BillInventory product, decimal quantity, bool absolute)
|
||||
{
|
||||
if (!absolute)
|
||||
{
|
||||
quantity = product.Quantity + quantity;
|
||||
}
|
||||
if (quantity <= 0)
|
||||
if (quantity < 0 && !Session.IsAllowed(RoleConstants.EDIT_PRINTED_PRODUCT))
|
||||
return;
|
||||
if (bill.ContainsKey(oldKey))
|
||||
{
|
||||
var totalQuantity = bill[oldKey].Quantity + quantity;
|
||||
if (totalQuantity < 0)
|
||||
quantity += 0 - totalQuantity;
|
||||
}
|
||||
product.Quantity = quantity;
|
||||
}
|
||||
#endregion
|
||||
#region Amount
|
||||
public static void SetAmount(BillInventory product, decimal amount, BindingSource bindingSource, OrderedDictionary<BillItemKey, BillInventory> bill)
|
||||
public void SetPrice(BillInventory product)
|
||||
{
|
||||
if (amount == -1)
|
||||
{
|
||||
InputBoxResult result = InputBox.Show("Amount", (product.Value).ToString(), InputBox_Validating);
|
||||
if (result.OK)
|
||||
{
|
||||
amount = Convert.ToDecimal(result.Text);
|
||||
}
|
||||
}
|
||||
if (amount == -1)
|
||||
if (!Allowed(product, RoleConstants.CHANGE_RATE))
|
||||
return;
|
||||
else
|
||||
{
|
||||
SetQuantity(product, amount / (product.Price * (1 + product.Tax) * (1 - product.Discount)), true, false, bindingSource, bill);
|
||||
}
|
||||
decimal rate = product.Price;
|
||||
if (!GetInput("Price", ref rate))
|
||||
return;
|
||||
if (rate == 0 && !Session.IsAllowed(RoleConstants.ZERO_RATE))
|
||||
return;
|
||||
if (bill.ContainsKey(new BillItemKey(product.ProductID, true)))
|
||||
bill[new BillItemKey(product.ProductID, true)].Price = rate;
|
||||
if (bill.ContainsKey(new BillItemKey(product.ProductID, false)))
|
||||
bill[new BillItemKey(product.ProductID, false)].Price = rate;
|
||||
}
|
||||
#endregion
|
||||
#region Rate
|
||||
public static void SetRate(int productID, decimal rate, OrderedDictionary<BillItemKey, BillInventory> bill)
|
||||
{
|
||||
if (bill.ContainsKey(new BillItemKey(productID, true)))
|
||||
bill[new BillItemKey(productID, true)].Price = rate;
|
||||
if (bill.ContainsKey(new BillItemKey(productID, false)))
|
||||
bill[new BillItemKey(productID, false)].Price = rate;
|
||||
}
|
||||
#endregion
|
||||
private static void InputBox_Validating(object sender, InputBoxValidatingArgs e)
|
||||
private void InputBox_Validating(object sender, InputBoxValidatingArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
private bool Allowed(BillInventory item, RoleConstants role)
|
||||
{
|
||||
if (item == null)
|
||||
return false;
|
||||
if (!Session.IsAllowed(role))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
private bool GetInput(string prompt, ref decimal amount)
|
||||
{
|
||||
InputBoxResult result = InputBox.Show(prompt, amount.ToString(), InputBox_Validating);
|
||||
if (!result.OK)
|
||||
return false;
|
||||
if (!decimal.TryParse(result.Text, out amount))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,8 +51,8 @@
|
||||
// splitContainer1.Panel2
|
||||
//
|
||||
this.splitContainer1.Panel2.Controls.Add(this.flpModifier);
|
||||
this.splitContainer1.Size = new System.Drawing.Size(619, 492);
|
||||
this.splitContainer1.SplitterDistance = 230;
|
||||
this.splitContainer1.Size = new System.Drawing.Size(847, 492);
|
||||
this.splitContainer1.SplitterDistance = 232;
|
||||
this.splitContainer1.TabIndex = 2;
|
||||
//
|
||||
// numpadControl1
|
||||
@ -76,14 +76,14 @@
|
||||
this.flpModifier.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.flpModifier.Location = new System.Drawing.Point(0, 0);
|
||||
this.flpModifier.Name = "flpModifier";
|
||||
this.flpModifier.Size = new System.Drawing.Size(385, 492);
|
||||
this.flpModifier.Size = new System.Drawing.Size(611, 492);
|
||||
this.flpModifier.TabIndex = 6;
|
||||
//
|
||||
// DiscountForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(619, 492);
|
||||
this.ClientSize = new System.Drawing.Size(847, 492);
|
||||
this.ControlBox = false;
|
||||
this.Controls.Add(this.splitContainer1);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
|
||||
|
||||
@ -27,12 +27,6 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
billController.InitGui(this);
|
||||
}
|
||||
|
||||
public SalesForm(int voucherID, BillController billController)
|
||||
: this(billController)
|
||||
{
|
||||
billController.SetNewBillID(voucherID);
|
||||
}
|
||||
|
||||
public void SetUserName(string name)
|
||||
{
|
||||
this.Text = name;
|
||||
@ -43,10 +37,7 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
{
|
||||
case Keys.F2:
|
||||
{
|
||||
if (dgvProducts.Rows.Count > 0)
|
||||
{
|
||||
billController.SetQuantity(billController.CurrentProduct, 0, false, true);
|
||||
}
|
||||
btnQuantity_Click(sender, new EventArgs());
|
||||
break;
|
||||
}
|
||||
case Keys.F3:
|
||||
@ -80,14 +71,6 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
billController.LoadBillFromTable(null);
|
||||
break;
|
||||
}
|
||||
case Keys.F9:
|
||||
{
|
||||
if (dgvProducts.Rows.Count > 0)
|
||||
{
|
||||
billController.SetAmount(billController.CurrentProduct, -1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Keys.F11:
|
||||
{
|
||||
btnPrintBill_Click(sender, e);
|
||||
@ -100,20 +83,17 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
}
|
||||
case Keys.Delete:
|
||||
{
|
||||
if (dgvProducts.Rows.Count > 0)
|
||||
billController.ProductRemove(billController.CurrentProduct);
|
||||
billController.ProductRemove();
|
||||
break;
|
||||
}
|
||||
case Keys.Add:
|
||||
{
|
||||
if (dgvProducts.Rows.Count > 0)
|
||||
billController.SetQuantity(billController.CurrentProduct, 1, false, false);
|
||||
billController.SetQuantity(1, false);
|
||||
break;
|
||||
}
|
||||
case Keys.Subtract:
|
||||
{
|
||||
if (dgvProducts.Rows.Count > 0)
|
||||
billController.SetQuantity(billController.CurrentProduct, -1, false, false);
|
||||
billController.SetQuantity(-1, false);
|
||||
break;
|
||||
}
|
||||
case Keys.Up:
|
||||
@ -257,13 +237,6 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
btnWaiter.Tag = WaiterBI.GetWaiters()[0].WaiterID;
|
||||
billController.Save(false, (int)btnWaiter.Tag, txtTableID.Text);
|
||||
}
|
||||
private void btnMultiPrint_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (btnWaiter.Tag == null)
|
||||
btnWaiter.Tag = WaiterBI.GetWaiters()[0].WaiterID;
|
||||
billController.Save(true, (int)btnWaiter.Tag, txtTableID.Text);
|
||||
|
||||
}
|
||||
private void btnCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
billController.CancelBillChanges();
|
||||
@ -271,10 +244,7 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
|
||||
private void btnQuantity_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dgvProducts.Rows.Count > 0)
|
||||
{
|
||||
billController.SetQuantity(billController.CurrentProduct, 0, false, true);
|
||||
}
|
||||
billController.SetQuantity(0, true);
|
||||
}
|
||||
private void btnDiscount_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -333,14 +303,11 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
}
|
||||
private void btnRate_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dgvProducts.Rows.Count > 0)
|
||||
{
|
||||
billController.ChangeRate();
|
||||
}
|
||||
billController.ChangeRate();
|
||||
}
|
||||
private void btnClear_Click(object sender, EventArgs e)
|
||||
{
|
||||
billController.ClearBill();
|
||||
billController.CancelBillChanges();
|
||||
}
|
||||
|
||||
private void dgvProducts_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
|
||||
@ -414,14 +381,21 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
private void btnModifier_Click(object sender, EventArgs e)
|
||||
{
|
||||
var item = billController.CurrentProduct;
|
||||
if (item == null)
|
||||
return;
|
||||
var id = new ProductGroupBI().GetProductGroupOfProduct(item.ProductID).ProductGroupID;
|
||||
billController.ShowModifiers(id, item);
|
||||
}
|
||||
|
||||
private void btnDelete_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dgvProducts.Rows.Count > 0)
|
||||
billController.ProductRemove(billController.CurrentProduct);
|
||||
if (dgvProducts.Rows.Count <= 0)
|
||||
return;
|
||||
var p = billController.CurrentProduct;
|
||||
if (p.Quantity > 1)
|
||||
billController.SetQuantity(-1, false);
|
||||
else
|
||||
billController.ProductRemove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user