User management fixed. Reports working now. Deployed

This commit is contained in:
unknown
2011-02-09 17:33:22 +05:30
parent 1400f42989
commit d4cfa92848
51 changed files with 1990 additions and 1358 deletions

View File

@ -18,13 +18,15 @@ namespace Tanshu.Accounts.PointOfSale
public class BillController
{
private SaleVoucher billInfo;
// private KeyedCollection<BillItemKey, BillInventory> b1 = new KeyedCollection<BillItemKey, BillInventory>();
private OrderedDictionary<BillItemKey, BillInventory> bill = new OrderedDictionary<BillItemKey, BillInventory>();
int? newBillID;
int? editVoucherID;
ISaleForm saleForm;
private Customer customer = new CustomerBI().GetCustomer(1);
public BillController(int? editVoucherID)
{
this.editVoucherID = editVoucherID;
}
public void InitGui(ISaleForm saleForm)
{
this.saleForm = saleForm;
@ -49,7 +51,7 @@ namespace Tanshu.Accounts.PointOfSale
}
public void AddProductToGrid(int productID)
{
BillHelperFunctions.AddProductToGrid(productID, saleForm.BindingSource, bill);
new BillHelperFunctions(saleForm.BindingSource, bill, productID).AddProduct();
Product product = ProductBI.GetProduct(productID);
if (ProductGroupModifierBI.HasCompulsoryModifier(product.ProductGroup.ProductGroupID))
{
@ -74,6 +76,9 @@ namespace Tanshu.Accounts.PointOfSale
public void ShowDiscount()
{
if (!Session.IsAllowed(RoleConstants.DISCOUNT))
return;
var list = new ProductGroupBI().GetProductGroups();
using (var frm = new DiscountForm(list))
{
@ -86,7 +91,8 @@ namespace Tanshu.Accounts.PointOfSale
{
var pg = new ProductGroupBI().GetProductGroupOfProduct(item.Value.ProductID);
if (outList.Contains(pg.ProductGroupID))
item.Value.Discount = discount;
new BillHelperFunctions(saleForm.BindingSource, bill, item.Value.ProductID).SetDiscount(item.Value.Name, discount);
}
}
}
@ -125,35 +131,34 @@ namespace Tanshu.Accounts.PointOfSale
public void Save(bool print, int waiterID, string tableID)
{
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(RolesConstants.SALES_EDIT_BILL))
if (print && !Session.IsAllowed(RoleConstants.PRINT_BILL))
return;
if (!print && !Session.IsAllowed(RoleConstants.PRINT_KOT))
return;
if ((billInfo != null) && (SaleVoucherBI.IsBillPrinted(billInfo.VoucherID)) && (!Session.IsAllowed(RoleConstants.EDIT_PRINTED_BILL)))
return;
if (bill.Count == 0)
return;
int? saved;
if (billInfo == null)
saved = InsertVoucher(print, waiterID, tableID);
else
saved = UpdateSale(print, waiterID, tableID);
if (saved.HasValue)
{
if ((billInfo != null) && (SaleVoucherBI.IsBillPrinted(billInfo.VoucherID)) && (!roleBI.IsAllowed))
{
throw new PermissionException("You do not have the permission to reprint a bill.");
}
}
if (bill.Count != 0)
{
int? saved;
if (billInfo == null)
saved = AddNewSale(print, waiterID, tableID);
if (editVoucherID.HasValue)
saleForm.CloseWindow();
else
saved = UpdateSale(print, waiterID, tableID);
if (saved.HasValue)
{
if (newBillID.HasValue)
saleForm.CloseWindow();
else
PrintBill(print, saved.Value);
}
ClearBill();
PrintBill(print, saved.Value);
}
ClearBill();
}
private int? AddNewSale(bool finalBill, int waiterID, string tableID)
private int? InsertVoucher(bool finalBill, int waiterID, string tableID)
{
if (billInfo != null)
{
MessageBox.Show("Error in AddNewSale, there is a previous sale in memory", "Error");
MessageBox.Show("Error in InsertVoucher, there is a previous sale in memory", "Error");
return null;
}
@ -205,41 +210,46 @@ namespace Tanshu.Accounts.PointOfSale
private IList<Inventory> GetInventoryForBill(ICollection<BillInventory> list)
{
Dictionary<int, Inventory> localList = new Dictionary<int, Inventory>();
HashSet<int> keys = new HashSet<int>();
foreach (BillInventory item in list)
{
Inventory temp = new Inventory();
if (localList.ContainsKey(item.ProductID))
{
if (temp.Quantity <= 0)
keys.Remove(item.ProductID);
temp = localList[item.ProductID];
temp.Quantity += item.Quantity;
temp.Amount += item.Value;
foreach (var mod in item.Modifiers)
temp.InventoryModifier.Add(new InventoryModifier() { Modifier = mod });
if (temp.Quantity <= 0)
keys.Add(item.ProductID);
}
else
{
temp.Discount = item.Discount;
temp.Product = ProductBI.GetProduct(item.ProductID);
temp.Quantity = item.Quantity;
temp.Rate = item.Price;
temp.Discount = item.Discount;
temp.ServiceCharge = item.ServiceCharge;
temp.Tax = item.Tax;
temp.Amount = item.Value;
foreach (var mod in item.Modifiers)
temp.InventoryModifier.Add(new InventoryModifier() { Modifier = mod });
localList.Add(item.ProductID, temp);
if (item.Quantity <= 0)
keys.Add(item.ProductID);
}
}
return localList.Values.ToList();
}
public decimal GetInput(string type, decimal basic)
{
decimal value;
InputBoxResult result = InputBox.Show(type, basic.ToString(), InputBox_Validating);
if (result.OK)
foreach (var item in keys)
{
if (!decimal.TryParse(result.Text, out value))
return 0;
return value;
localList.Remove(item);
}
return 0;
return localList.Values.ToList();
}
#endregion
public void VoidBill()
@ -248,27 +258,22 @@ namespace Tanshu.Accounts.PointOfSale
return;
if (!billInfo.Printed)
return;
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(RolesConstants.SALES_VOID_BILL))
if (Session.IsAllowed(RoleConstants.VOID_BILL))
{
if (roleBI.IsAllowed)
if (MessageBox.Show("Are you sure you want to void this bill?", "Void Bill", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
{
if (MessageBox.Show("Are you sure you want to void this bill?", "Void Bill", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
SelectVoidReason voidReason = new SelectVoidReason(GetVoidReason, true);
voidReason.ShowDialog();
if (voidReason.SelectedItem != null)
{
SelectVoidReason voidReason = new SelectVoidReason(GetVoidReason, true);
voidReason.ShowDialog();
if (voidReason.SelectedItem != null)
{
SaleVoucherBI.VoidBill(billInfo.VoucherID, voidReason.SelectedItem.Description);
ClearBill();
}
else
{
MessageBox.Show("Please Select a reason if you want to void the bill", "Bill NOT Voided", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
SaleVoucherBI.VoidBill(billInfo.VoucherID, voidReason.SelectedItem.Description);
ClearBill();
}
else
{
MessageBox.Show("Please Select a reason if you want to void the bill", "Bill NOT Voided", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
}
else
throw new PermissionException("You do not have the permission to void a bill.");
}
}
Customer selectCustomer_customerEvent(object sender, CustomerEventArgs e)
@ -281,25 +286,10 @@ namespace Tanshu.Accounts.PointOfSale
}
private void PrintBill(bool finalBill, int voucherID)
{
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(RolesConstants.SALES_PRINT_KOT))
if (!roleBI.IsAllowed)
throw new PermissionException("You are not allowed to print KOT");
if (!finalBill)
Accounts.Print.Thermal.PrintKot(voucherID, bill.Values.ToList());
else
{
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(RolesConstants.SALES_PRINT_BILL))
{
if (roleBI.IsAllowed)
{
Accounts.Print.Thermal.PrintBill(true, voucherID, bill.Values.ToList());
}
else
throw new PermissionException("You are not allowed to print KOT");
}
}
Accounts.Print.Thermal.PrintBill(voucherID, bill.Values.ToList());
}
private List<StringType> GetVoidReason(Dictionary<string, string> filter)
@ -315,15 +305,14 @@ namespace Tanshu.Accounts.PointOfSale
list.Add(new StringType("Other"));
return list.Where(i => i.Description.ToLower().Contains(filter["Name"].ToLower().Trim())).ToList();
}
public void SetNewBillID(int voucherID)
{
this.newBillID = voucherID;
}
public BillInventory CurrentProduct
{
get
{
return bill.ElementAt(saleForm.BindingSource.Position).Value;
if (saleForm.BindingSource.Position == -1)
return null;
else
return bill.ElementAt(saleForm.BindingSource.Position).Value;
}
}
private void ShowAmount()
@ -338,64 +327,48 @@ namespace Tanshu.Accounts.PointOfSale
//bill.Values.ToList();
saleForm.ShowAmount(discountAmount, grossAmount, serviceChargeAmount, taxAmount, valueAmount, bill.Values.ToList());
}
public void SetDiscount(BillInventory billInventory, decimal discount)
public void ProductRemove()
{
if (billInventory == null)
var item = CurrentProduct;
if (!Allowed(item))
return;
BillHelperFunctions.SetDiscount(billInventory.ProductID, discount, customer, bill);
ShowAmount();
}
public void SetAmount(BillInventory billInventory, decimal amount)
{
if (billInventory == null)
return;
BillHelperFunctions.SetAmount(billInventory, amount, saleForm.BindingSource, bill);
ShowAmount();
}
public void ProductRemove(BillInventory billInventory)
{
if (billInventory == null)
return;
if (billInventory.Printed > 0)
if (item.Printed > 0)
{
using (RoleBI roleBI = RoleFactoryBI.GetRoleBI(RolesConstants.SALES_EDIT_PRINTED_PRODUCT))
{
if (roleBI.IsAllowed)
{
if (MessageBox.Show(string.Format("Already {0} items have been printed.\n\rAre you sure you want to delete this item?", billInventory.Printed), "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
return;
}
}
if (!Session.IsAllowed(RoleConstants.EDIT_PRINTED_PRODUCT))
return;
else if (MessageBox.Show(string.Format("Already {0} items have been printed.\n\rAre you sure you want to delete this item?", item.Printed), "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
return;
}
bill.Remove(new BillItemKey(billInventory.ProductID, billInventory.Printed == 0));
bill.Remove(new BillItemKey(item.ProductID, item.Printed == 0));
bill.ReCompact();
ShowAmount();
}
public void SetQuantity(BillInventory billInventory, decimal quantity, bool absolute, bool prompt)
public void SetQuantity(decimal quantity, bool prompt)
{
if (billInventory == null)
var item = CurrentProduct;
if (!Allowed(item))
return;
BillHelperFunctions.SetQuantity(billInventory, quantity, absolute, prompt, saleForm.BindingSource, bill);
new BillHelperFunctions(saleForm.BindingSource, bill, CurrentProduct.ProductID).SetQuantity(item, quantity, prompt);
ShowAmount();
}
public void ChangeRate()
{
var item = CurrentProduct;
if (item != null)
{
decimal rate = 0;
InputBoxResult result = InputBox.Show("Rate", item.Price.ToString(), InputBox_Validating);
if (result.OK)
rate = Convert.ToDecimal(result.Text);
if (rate != 0)
{
BillHelperFunctions.SetRate(item.ProductID, rate, bill);
ShowAmount();
}
}
new BillHelperFunctions(saleForm.BindingSource, bill, CurrentProduct.ProductID).SetPrice(CurrentProduct);
ShowAmount();
}
private bool Allowed(BillInventory item, RoleConstants role)
{
if (item == null)
return false;
if (!Session.IsAllowed(role))
return false;
return true;
}
private bool Allowed(BillInventory item)
{ return item != null; }
private void InputBox_Validating(object sender, InputBoxValidatingArgs e)
{
}
@ -463,11 +436,10 @@ namespace Tanshu.Accounts.PointOfSale
public void CancelBillChanges()
{
if (bill.Count != 0)
if (MessageBox.Show("Cancel current bill?", "Cancel bill", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
if (bill.Count != 0 && bill.Values.Any(i => i.Printed != i.Quantity))
if (MessageBox.Show("Abandon Changes?", "Abandon Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
return;
ClearBill();
}
public void ClearBill()
{
@ -478,11 +450,10 @@ namespace Tanshu.Accounts.PointOfSale
}
public void FormLoad()
{
if (newBillID.HasValue)
if (editVoucherID.HasValue)
{
LoadBill(newBillID.Value);
LoadBill(editVoucherID.Value);
}
}
internal void SettleBill()
{
@ -490,6 +461,8 @@ namespace Tanshu.Accounts.PointOfSale
return;
if (!billInfo.Printed)
return;
if (!Session.IsAllowed(RoleConstants.SETTLE_BILL))
return;
int option = SettleOptionFactory.Unsettled;
using (BillSettleForm frm = new BillSettleForm())
{
@ -505,5 +478,5 @@ namespace Tanshu.Accounts.PointOfSale
}
}
// How to load a bill
//LoadBill(((PendingBills)bsPending.Current).voucherID);
//LoadBill(((PendingBills)bsPending.Current).editVoucherID);
// ChangeFormState(SaleFormState.Billing);