Reputation: 18342
I'm adding my transactions to a dictionary, using a UUID as the key and the transaction object as the value - this is what I call my ledger
:
Example (entriesForPosting is a Set
of Array
s, each containing a credit entry and a debit entry):
postToGL
entriesForPosting do: [ :ea | GeneralLedger ledger at: (ea at: 1) mUID put: (ea at: 1). "credit"
GeneralLedger ledger at:(ea at: 2) mUID put: (ea at: 2) ]. "debit"
We then report this ledger like this:
renderReport
GLReport := WATableReport new
rows: GeneralLedger getGLPostings asOrderedCollection ;
columns: (OrderedCollection new
add: (WAReportColumn
renderBlock: [ :each :html | html emphasis: each ]
title: 'ID');
add: (WAReportColumn
renderBlock: [ :each :html | html emphasis: (GeneralLedger getTransactionByID: each) mDate ]
title: 'Transaction Date');
add: (WAReportColumn
renderBlock: [ :each :html | html emphasis: (GeneralLedger getTransactionByID: each) mAmount ]
title: 'Amount');
add: (WAReportColumn
renderBlock: [ :each :html | html emphasis: ((GeneralLedger getTransactionByID: each) mGLAC mAccountCode)]
title: 'GLAC');
add: (WAReportColumn
renderBlock: [ :each :html | html emphasis: ((GeneralLedger getTransactionByID: each) mFund mFundCode)]
title: 'Fund');
yourself);
rowColors: #(lightblue lightyellow);
rowPeriod: 1;
yourself.
The problem I'm having is, this report isn't ordered. I.e., the transactions display out of order - and I don't see any rhyme or reason to why they're reported how they are:
For example,
spndMgr buildTransactionFor: 100 against: someGLAC.
spndMgr buildTransactionFor: 110 against: someGLAC.
spndMgr buildTransactionFor: 120 against: someGLAC.
spndMgr buildTransactionFor: 130 against: someGLAC.
spndMgr buildTransactionFor: 140 against: someGLAC.
spndMgr buildTransactionFor: 150 against: someGLAC.
spndMgr buildTransactionFor: 160 against: someGLAC.
spndMgr buildTransactionFor: 170 against: someGLAC.
spndMgr buildTransactionFor: 180 against: someGLAC.
spndMgr buildTransactionFor: 190 against: someGLAC.
spndMgr buildTransactionFor: 200 against: someGLAC.
spndMgr postTransactions.
Gives me the following:
I've tried the following:
renderReport
|columnToSortBy|
GLReport := WATableReport new
rows: GeneralLedger getGLPostings asOrderedCollection ;
columns: (OrderedCollection new
add: (WAReportColumn
renderBlock: [ :each :html | html emphasis: (GeneralLedger getTransactionByID: each) mIdentity ]
title: 'Identity');
add: (columnToSortBy := (WAReportColumn
renderBlock: [ :each :html | html emphasis: (GeneralLedger getTransactionByID: each) mDate ]
title: 'Transaction Date') );
add: (WAReportColumn
renderBlock: [ :each :html | html emphasis: (GeneralLedger getTransactionByID: each) mAmount ]
title: 'Amount');
add: (WAReportColumn
renderBlock: [ :each :html | html emphasis: ((GeneralLedger getTransactionByID: each) mGLAC mAccountCode)]
title: 'GLAC');
add: (WAReportColumn
renderBlock: [ :each :html | html emphasis: ((GeneralLedger getTransactionByID: each) mFund mFundCode)]
title: 'Fund');
yourself);
rowColors: #(lightblue lightyellow);
rowPeriod: 1;
sortColumn: columnToSortBy;
yourself.
But this throws an error on rendering:
Upvotes: 2
Views: 212
Reputation: 15917
If you add something like the following to your ledger,
GeneralLedger>>columnDescriptions
^#('Transaction Date' #(mDate)
'Amount' #(mAmount)
'GLAC' #(mGlac mAccountCode)
'Fund' #(mFund mFundCode))
you can build up your report columns like this
ledger columnDescriptions pairsDo: [ :title :accessorCollection | |column|
column := WAReportColumn new
title: title;
renderBlock: [:each :html | |temp|
temp := GeneralLedger getTransactionById: each.
accessorCollection do: [ :accessor |
temp := temp perform: accessor ].
html emphasis: temp];
yourself.
report columns add: column].
If you need different kinds of reports, it makes sense to start using Magritte (or Deltawerken). There you define the fields with separate objects, and just tell the report which fields to render.
Upvotes: 1
Reputation: 5125
WAReportColumn
understands #sortBlock:
. This block is initialized to [ :a :b | a <= b ]
where a and b would be some glPosting
objects I assume. If this sort behavior doesn't suit you, simply pass a different sort block to the column.
WAReportTable
understands #sortColumn:
. Pass the column you want to have sorted by default like so:
...
add: (columnToSortBy := (WAReportColumn
renderBlock: [ :each :html | html emphasis: (GeneralLedger getTransactionByID: each) mAmount ]
title: 'Amount';
yourself));
...
rowColors: #(lightblue lightyellow);
rowPeriod: 1;
sortColumn: columnToSortBy;
yourself.
Upvotes: 5