【问题标题】:Smalltalk - Seaside ReportingSmalltalk - 海边报道
【发布时间】:2013-07-06 11:50:31
【问题描述】:

我正在将我的事务添加到字典中,使用 UUID 作为键,事务对象作为值 - 这就是我所说的 ledger

示例(entriesForPosting 是Arrays 中的Set,每个都包含一个贷记分录和一个借记分录):

   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"

然后我们像这样报告这个分类帐:

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. 

我遇到的问题是,此报告没有排序。即,交易显示无序 - 我看不出有任何押韵或理由来说明它们为何被报告:

例如,

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.

给了我以下信息:


我尝试了以下方法:

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. 

但这会在渲染时引发错误:

【问题讨论】:

    标签: smalltalk seaside


    【解决方案1】:

    如果您将以下内容添加到分类帐中,

    GeneralLedger>>columnDescriptions
        ^#('Transaction Date' #(mDate)
           'Amount' #(mAmount)
           'GLAC' #(mGlac mAccountCode)
           'Fund' #(mFund mFundCode))
    

    您可以像这样构建您的报告列

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

    如果您需要不同类型的报告,开始使用 Magritte 是有意义的 (或 Deltawerken)。在那里你用单独的对象定义字段,然后告诉 报告要呈现的字段。

    【讨论】:

      【解决方案2】:
      1. WAReportColumn 理解#sortBlock:。该块被初始化为[ :a :b | a <= b ],其中a 和b 将是我假设的一些glPosting 对象。如果这种排序行为不适合您,只需将不同的排序块传递给列。

      2. WAReportTable 理解#sortColumn:。传递您想要默认排序的列,如下所示:

        ...
        add: (columnToSortBy := (WAReportColumn
            renderBlock: [ :each :html | html emphasis: (GeneralLedger getTransactionByID: each) mAmount ]
            title: 'Amount';
            yourself));
        ...
        rowColors: #(lightblue lightyellow);
        rowPeriod: 1;
        sortColumn: columnToSortBy;
        yourself. 
        

      【讨论】:

      • 你发现了一个非常丑陋的错误。您传递给#renderBlock:title: 的块有两个参数(正如您从示例中正确收集的那样)。但是WAReportColumn 将使用 只有一个 参数调用该块。这里没有快速的解决方案。我的建议是引入一个名为renderBlock 的新实例变量并使用不同的valueBlock。您可以将valueBlock 初始化为[ :row | row ] 并将renderBlock 初始化为[ :row :html | html render: (self valueForRow: row) asString ]
      • 感谢您的帮助!有什么地方可以举报吗?
      • 不客气。讨论和支持的地方是 Seaside 邮件列表 (seaside.st/community/mailinglist)。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多