Field to sum up selected rows in Reconciliation window
John O'Brien
Hi all,I would like to be able to sum up the amount column in selected rows in the reconciliation window.
I have successfully created the items on the form, but now I need the logic that will loop through each matrix row and if its selected, then sum the amount.
Has anyone previously done a similar rule?
This would help my client reconciling a lot of bank data against SAP bank gl.
here is my code so far:
// this rule sums up total of selected rows
try
{
Item refItem = Item.GetFromUID(pVal.Form, "7");
Label l1 = Label.CreateNew("L1");
l1.SetSizeAndPosition(refItem);
l1.Left = l1.Left + 220;
l1.Value = "Total: ";
Label l2 = Label.CreateNew("L2");
l2.SetSizeAndPosition(refItem);
l2.Left = l2.Left + 280;
l2.Value = "";
pVal.Form.AddItem(l1);
pVal.Form.AddItem(l2);
pVal.Form.Update();
SwissAddonFramework.UI.EventHandling.ItemEvents.ItemPressedEventHandler ev = null;
ev = delegate (SwissAddonFramework.UI.EventHandling.ItemEvents.ItemPressed e)
{
try
{
Matrix m = Matrix.GetFromUID(pVal.Form, "3");
double mAmount;
for (int index = 0; index < m.Rows.Count; index++)
{
// if row is selected, add amount to variable
}
}
catch (Exception ex)
{
StatusBar.WriteError(ex.Message);
}
};
// b.AddHandler_ItemPressed(SwissAddonFramework.UI.Components.ModeComponent.FormModes.ALL, null, ev);
// t.AddHandler_KeyDown(SwissAddonFramework.UI.Components.ModeComponent.FormModes.ALL, null, ev);
}
catch (Exception ex)
{
StatusBar.WriteError(ex.Message);
}
return true;
Many thanks,
John
Lorenz Stierlin
Hello JohnHere is an example which sums the amount of the selected rows and shows it in a message box. You can use it for example as a Function Button on the reconciliation form.
[CODE]
try
{
Matrix m = Matrix.GetFromUID(pVal.Form, "3");
decimal mAmount = 0;
for (int i = 1; i < m.Rows.Count; i++)
{
if (m.SelectedRows.IsRowSelected(i) == true){
mAmount = mAmount + m.GetValueAsMoney("7", i-1).Amount;
}
}
MessageBox.Show("" + mAmount, "OK");
}
catch (Exception ex)
{
StatusBar.WriteError(ex.Message);
}
[/CODE]
I hope this will help you.
Kind Regards,
Lorenz Stierlin
John O'Brien
Hi Lorenz,That's excellent, thanks very much!
Regards,
John
John O'Brien
Hi Lorenz,I notice that if I select the very last line in the matrix, it doesn't include this amount.
Somehow the matrix row count is incorrect, or it doesn't recognise the last row as selected.
Any ideas?!
Thanks,
John
Lorenz Stierlin
Hi JohnJust try rowCount+1 in the for loop because the Row.Count and the real row indexes for getting the selected items in the matrix are a bit tricky to handle.
[CODE]
for (int i = 1; i < rowCount+1; i++)
[/CODE]
Please let me know if this solves your problem.
Kind Regards,
Lorenz
John O'Brien
Hi Lorenz,Yes that did it, this is now resolved.
Many thanks,
John
0
Please sign in to leave a comment.
Comments
0 comments