Search code examples
smalltalkseaside

Smalltalk - Seaside Reporting


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 Arrays, 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: enter image description here


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: enter image description here


Solution

    1. 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.

    2. 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.