Sannyasin,

The simple answer to the situation you describe is to loop through the
records and build the arrays.

I seem to recall you're working with v15+, so with that in mind here's how
I'm handling these sorts of situations these days.

1) make an object array of each record.
Depending on your structure you may just put each record into the array
(think SELECTION TO JSON) or you may want to loop through the selection and
pull the relevant bits from the invoice line arrays as well as any linked
tables. The idea is to get all the data you may need to perform
calculations in the object. In your example, if I understand it correctly,
a give item may have more than one sales record of some sort associated
with it. Using my scheme you could include the list of those items as
arrays in the JSON object.

2) Populate your listbox.
I tend to put these object arrays as the first column and hide it (you
can't display an object column without using 4D Write and in this case you
probably don't want to). The remainder of the list box a) can use all
dynamic vars for the columns and b) can easily be inserted from user prefs.
Or you can put them in yourself. The point is you can load each row from
the data in the object array.

Why is this helpful?
For one thing you've got all the data you need encapsulated in the listbox.
That's pretty cool. You may need to have a bunch of fields, some from
different tables, in the data object and only need to have arrays for the
data you actually need to display. Calculations are easy to write, debug
and fast because they are all working on a c-obj in memory.

Finally, it's quick and easy to look through the data array to create
whatever sums and other totals you need.

If you need to do something like make the listbox hierarchical you can opt
to make the data col the last col. This just makes managing the user prefs
a little more complicated but really not too much.

In previous incarnations I've gone from included output forms (long time
ago) and having the use Subtotal to array based listboxes with dozens of
columns when only 5 or 6 would be displayed and this is by far the most
effective approach I've found.

And a big upside for me is this is a way to cache all the changes to the
invoice in memory so the user could decide to cancel. Since all the data is
being calculated and written to the c-obj for each row you can wait until
the user gives it the OkeyDokey before writing to disk. This is an
attractive option to starting a transaction, for example, when the record
is opened. I don't do that sort of thing because it can cascade through the
system as you touch more and more records plus it's a problem is someone
gets halfway through an entry and goes to lunch.

Hope this helps.

On Tue, Jun 20, 2017 at 2:25 PM, Sannyasin Siddhanathaswami via 4D_Tech <
4d_tech@lists.4d.com> wrote:

> Aloha,
>
> Does anyone have a utility method for summarizing (and summing) a set of
> arrays?
>
> For example with Invoice Line Items:
>
> Arrays:
> aItemNumbers
> aItemDescription
> aQuantitySold
> aExtendedSoldAmount
>
> Of course, with invoice line items there are multiple records with item
> numbers. I want a summary array where there is only 1 element with an item
> number, and the aQuantitySold, and aExtendedSoldAmount gets summed.
>
> I know there’s lots of ways to do this, but didn’t want to reinvent the
> wheel if possible.
>
> Thanks!
>
> Sannyasin Siddhanathaswami
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **********************************************************************




-- 
Kirk Brooks
San Francisco, CA
=======================

*The only thing necessary for the triumph of evil is for good men to do
nothing.*

*- Edmund Burke*
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**********************************************************************

Reply via email to