Feature: Added SortOrder to Inventory.
Chore: Settle Choices form greatly simplified. Feature: Modifiers are now cached.
This commit is contained in:
@ -234,10 +234,7 @@ namespace Tanshu.Accounts.PointOfSale.Sales
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
Guid id;
|
||||
using (var bi = new ProductGroupBI())
|
||||
id = bi.GetProductGroupOfProduct(item.ProductID).ProductGroupID;
|
||||
_billController.ShowModifiers(id, item);
|
||||
_billController.ShowModifiers(item);
|
||||
}
|
||||
|
||||
private void btnDelete_Click(object sender, EventArgs e)
|
||||
|
||||
@ -35,7 +35,8 @@
|
||||
//
|
||||
// txtAmount
|
||||
//
|
||||
this.txtAmount.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.txtAmount.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.txtAmount.Location = new System.Drawing.Point(3, 3);
|
||||
this.txtAmount.Name = "txtAmount";
|
||||
this.txtAmount.ReadOnly = true;
|
||||
|
||||
@ -11,74 +11,20 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
{
|
||||
public partial class SettleChoicesForm : Form
|
||||
{
|
||||
private readonly IDictionary<Button, int> _list;
|
||||
private decimal _amount;
|
||||
private decimal _totalAmount;
|
||||
private readonly VoucherType _voucherType;
|
||||
public SettleChoicesForm(decimal amount, VoucherType voucherType)
|
||||
private IDictionary<SettleOption, decimal> _optionsChosen;
|
||||
public SettleChoicesForm(decimal totalAmount, VoucherType voucherType)
|
||||
{
|
||||
InitializeComponent();
|
||||
_amount = amount;
|
||||
_totalAmount = totalAmount;
|
||||
_voucherType = voucherType;
|
||||
OptionsChosen = new Dictionary<SettleOption, decimal>();
|
||||
_list = new Dictionary<Button, int>();
|
||||
}
|
||||
|
||||
private void ButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
var button = sender as Button;
|
||||
if (button == null || button.Tag == null)
|
||||
return;
|
||||
if (button.Tag is SettleOption)
|
||||
{
|
||||
var settleOption = (SettleOption)button.Tag;
|
||||
using (var frm = new SettleAmountsForm(new NumpadControl(), settleOption, _amount))
|
||||
{
|
||||
frm.ShowDialog();
|
||||
UpdateChoice(settleOption, frm.AmountSettled, _list[button]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((string)button.Tag == "Cancel")
|
||||
_optionsChosen.Clear();
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateChoice(SettleOption settleOption, decimal amount, int group)
|
||||
{
|
||||
var oldAmount = _optionsChosen.ContainsKey(settleOption) ? _optionsChosen[settleOption] : 0;
|
||||
if (amount == 0 && _optionsChosen.ContainsKey(settleOption))
|
||||
_optionsChosen.Remove(settleOption);
|
||||
else if (_optionsChosen.ContainsKey(settleOption))
|
||||
_optionsChosen[settleOption] = amount;
|
||||
else if (amount != 0)
|
||||
_optionsChosen.Add(settleOption, amount);
|
||||
_amount += oldAmount - amount;
|
||||
txtAmount.Text = string.Format("Pending Amount: Rs. {0}", _amount);
|
||||
|
||||
if (_optionsChosen.Count == 0)
|
||||
foreach (var item in _list)
|
||||
item.Key.Enabled = true;
|
||||
else
|
||||
foreach (var item in _list.Where(item => item.Value != group))
|
||||
item.Key.Enabled = false;
|
||||
|
||||
}
|
||||
|
||||
private IDictionary<SettleOption, decimal> _optionsChosen;
|
||||
public IDictionary<SettleOption, decimal> OptionsChosen
|
||||
{
|
||||
get
|
||||
{
|
||||
return _amount == 0 ? _optionsChosen : new Dictionary<SettleOption, decimal>();
|
||||
}
|
||||
private set { _optionsChosen = value; }
|
||||
_optionsChosen = new Dictionary<SettleOption, decimal>();
|
||||
}
|
||||
|
||||
private void SettleChoicesFormLoad(object sender, EventArgs e)
|
||||
{
|
||||
txtAmount.Text = string.Format("Pending Amount: Rs. {0}", _amount);
|
||||
txtAmount.Text = string.Format("Pending Amount: Rs. {0}", PendingAmount);
|
||||
var count = 0;
|
||||
foreach (SettleOption item in Enum.GetValues(typeof(SettleOption)))
|
||||
{
|
||||
@ -86,17 +32,16 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
if (!attribute.ShowInChoices || attribute.Group != _voucherType.Attribute().Group)
|
||||
continue;
|
||||
var button = new Button
|
||||
{
|
||||
Name = item.ToString(),
|
||||
Text = attribute.Name,
|
||||
Size = new Size(75, 75),
|
||||
TabIndex = count,
|
||||
UseVisualStyleBackColor = true,
|
||||
Tag = item
|
||||
};
|
||||
{
|
||||
Name = item.ToString(),
|
||||
Text = attribute.Name,
|
||||
Size = new Size(75, 75),
|
||||
TabIndex = count,
|
||||
UseVisualStyleBackColor = true,
|
||||
Tag = item,
|
||||
};
|
||||
button.Click += new EventHandler(ButtonClick);
|
||||
flpSettlement.Controls.Add(button);
|
||||
_list.Add(button, attribute.Group);
|
||||
count++;
|
||||
}
|
||||
var controlButton = new Button
|
||||
@ -108,9 +53,8 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
UseVisualStyleBackColor = true,
|
||||
Tag = "OK"
|
||||
};
|
||||
controlButton.Click += new EventHandler(ButtonClick);
|
||||
controlButton.Click += new EventHandler(OkClick);
|
||||
flpSettlement.Controls.Add(controlButton);
|
||||
// _list.Add(controlButton); --- Do not add to list
|
||||
count++;
|
||||
controlButton = new Button
|
||||
{
|
||||
@ -121,9 +65,8 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
UseVisualStyleBackColor = true,
|
||||
Tag = "Cancel"
|
||||
};
|
||||
controlButton.Click += new EventHandler(ButtonClick);
|
||||
controlButton.Click += new EventHandler(CancelClick);
|
||||
flpSettlement.Controls.Add(controlButton);
|
||||
// _list.Add(controlButton); --- Do not add to list
|
||||
count++;
|
||||
txtAmount.TabIndex = count;
|
||||
|
||||
@ -131,5 +74,55 @@ namespace Tanshu.Accounts.PointOfSale
|
||||
txtAmount.Width = flpSettlement.Width - 6;
|
||||
}
|
||||
|
||||
private void ButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
var settleOption = (SettleOption)((sender as Button).Tag);
|
||||
using (var frm = new SettleAmountsForm(new NumpadControl(), settleOption, PendingAmount))
|
||||
{
|
||||
frm.ShowDialog();
|
||||
UpdateChoice(settleOption, frm.AmountSettled);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateChoice(SettleOption settleOption, decimal amount)
|
||||
{
|
||||
if (amount == 0 && _optionsChosen.ContainsKey(settleOption))
|
||||
_optionsChosen.Remove(settleOption);
|
||||
else if (amount != 0 && _optionsChosen.ContainsKey(settleOption))
|
||||
_optionsChosen[settleOption] = amount;
|
||||
else if (amount != 0 && !_optionsChosen.ContainsKey(settleOption))
|
||||
_optionsChosen.Add(settleOption, amount);
|
||||
else if (_totalAmount == 0 && amount == 0 && !_optionsChosen.ContainsKey(settleOption))
|
||||
_optionsChosen.Add(settleOption, amount);
|
||||
txtAmount.Text = string.Format("Pending Amount: Rs. {0}", PendingAmount);
|
||||
}
|
||||
private decimal PendingAmount
|
||||
{
|
||||
get
|
||||
{
|
||||
decimal amount = _totalAmount;
|
||||
foreach (var item in _optionsChosen)
|
||||
{
|
||||
amount -= item.Value;
|
||||
}
|
||||
return amount;
|
||||
}
|
||||
}
|
||||
public IDictionary<SettleOption, decimal> OptionsChosen
|
||||
{
|
||||
get
|
||||
{
|
||||
return PendingAmount == 0 ? _optionsChosen : new Dictionary<SettleOption, decimal>();
|
||||
}
|
||||
}
|
||||
private void OkClick(object sender, EventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
private void CancelClick(object sender, EventArgs e)
|
||||
{
|
||||
_optionsChosen.Clear();
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user