Error while executing templating engine. Missing helper: "total"



  • Well, I have done very well getting data creating a new report. I saw in the Invoice example being able to total a column on the table. The report runs fine until I try to total the lines. I actually want to total the 3 columns.

    {{CurrentMinimumBalance}}
    {{CashBalance}}
    {{LastCalculatedBalance}}

    <tr class="total">
                        <td></td>
                        <td>
                            Total: ${{total LastCalculatedBalance}}
                        </td>
                    </tr>
    

    I get error

    Error while executing templating engine. Missing helper: "total"
    Error: Missing helper: "total"
        at Object.<anonymous> (/home/ubuntu/jsreportapp/node_modules/handlebars/dist/cjs/handlebars/helpers/helper-missing.js:19:13)
        at Object.wrapper (/home/ubuntu/jsreportapp/node_modules/handlebars/dist/cjs/handlebars/internal/wrapHelper.js:15:19)
        at Object.eval [as main] (eval at createFunctionContext (/home/ubuntu/jsreportapp/node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js:262:23), <anonymous>:15:100)
        at main (/home/ubuntu/jsreportapp/node_modules/handlebars/dist/cjs/handlebars/runtime.js:208:32)
        at ret (/home/ubuntu/jsreportapp/node_modules/handlebars/dist/cjs/handlebars/runtime.js:212:12)
        at ret (/home/ubuntu/jsreportapp/node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js:519:21)
        at /home/ubuntu/jsreportapp/node_modules/jsreport-handlebars/lib/handlebarsEngine.js:33:20
        at Object.base.apply (/home/ubuntu/jsreportapp/node_modules/vm2/lib/contextify.js:469:32)
        at evaluate-template-engine.js:1:64
        at Script.runInContext (node:vm:141:12)
    

    Here is the full report:

    <html>
        <head>
            <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
            <style>
                {#asset els-styles.css @encoding=utf8}
            </style>
        </head>
        <body>
            <div class="report-box">
                <table cellpadding="2" cellspacing="2">
                    <tr class="top">
                        <td colspan="2">
                            <table>
                                <tr>
                                    <td class="title">
                                        <p>ELS Luckii Daily Account Balance</p>
                                    </td>
                                    <td>
                                        Report Date: {{Date}}
                                        <br> Report for: ORC
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
        <table>
            <tr class="heading">
                        <td align="center">
                            Account Id
                        </td>
                        <td align="center">
                            Account Name
                        </td>
                        <td align="center">
                            Bonus Balance
                        </td>
                        <td align="center">
                            Cash Balance
                        </td>
                        <td align="center">
                            Account Balance
                        </td>
                    </tr>
        {{#each Account}}
        <tr>
            <td>
                {{PunterId}}
                </td>
            <td>
                {{AccountName}}
                </td>
            <td align="right">
               $ {{CurrentMinimumBalance}}
                </td>
            <td align="right">
               $ {{CashBalance}}
                </td>
            <td align="right">
               $ {{LastCalculatedBalance}}
                </td>
        </tr>
        {{/each}}
        <tr class="total">
                        <td></td>
                        <td>
                            Total: ${{total LastCalculatedBalance}}
                        </td>
                    </tr>
           
    
    
        
    </table>
    </div>
    </body>
    </html>
    


  • Added function

    function now () {
      return new Date().toLocaleDateString()
    }
    
    function nowPlus20Days () {
      var date = new Date()
      date.setDate(date.getDate() + 20)
      return date.toLocaleDateString()
    }
    
    function total (items) {
      var sum = 0
      items.forEach(function (i) {
        console.log('Calculating item ' + i.name + '; you should see this message in debug run')
        sum += i.LastCalculatedBalance
      })
      return sum
    }
    


  • So got on total working on totalling each column, and want them to line up under each column



  • Formatted layout first

    <tr class="total">
                        <td>Totals:</td>
                        <td></td>
                        <td>
                            Bonus: ${{total1 Account}}
                        </td>
                        <td>
                            Cash: ${{total2 Account}}
                        </td>
                        <td>
                            Blanace: ${{total3 Account}}
                        </td>
                    </tr>  
    

    Then created 3 functions

    function total1 (items) {
      var sum = 0
      items.forEach(function (i) {
        console.log('Calculating item ' + i.name + '; you should see this message in debug run')
        sum += i.CashBalance
      })
      return sum
    }
    
    function total2 (items) {
      var sum = 0
      items.forEach(function (i) {
        console.log('Calculating item ' + i.name + '; you should see this message in debug run')
        sum += i.CashBalance
      })
      return sum
    }
    
    function total3 (items) {
      var sum = 0
      items.forEach(function (i) {
        console.log('Calculating item ' + i.name + '; you should see this message in debug run')
        sum += i.LastCalculatedBalance
      })
      return sum
    }
    

Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.