right-justify cash report; format all numeric fields; provide summary row
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 7 Jan 2009 21:39:24 +0000 (21:39 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 7 Jan 2009 21:39:24 +0000 (21:39 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@11760 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/opac/common/js/fm_table.js
Open-ILS/web/opac/common/js/fm_table_conf.js
Open-ILS/xul/staff_client/server/admin/cash_reports.js

index 1e6891d..95c5bc9 100644 (file)
@@ -30,6 +30,7 @@ function FMObjectBuilder( obj, args ) {
        this.subtables = [];
        this.display = args.display;
        this.selectCol = args.selectCol;
+       this.moneySummaryRow = args.moneySummaryRow;
        this.selectColName = args.selectColName;
        this.selectAllName = args.selectAllName;
        this.selectNoneName = args.selectNoneName;
@@ -81,6 +82,28 @@ FMObjectBuilder.prototype.build = function() {
                        td.appendChild(none);
                        this.thead_tr.appendChild(td);
                }
+
+               if (this.moneySummaryRow) {
+                       this.moneySummaryRow = elem('tr');
+
+                       if( this.selectCol )
+                               this.moneySummaryRow.appendChild(elem('td'));
+
+                       for( var i = 0; i < this.keys.length; i++ ) {
+                               var key = this.keys[i];
+
+                               var td = elem('td');
+                               td.setAttribute('name', this.table.id + key);
+
+                               if (this.money && grep(this.money,function(i){return (i==key)}) )
+                                       td.appendChild(text('0.00'));
+
+                               this.moneySummaryRow.appendChild(td);
+                       }
+
+                       this.tbody.appendChild(this.moneySummaryRow);
+               }
+
                for( var i = 0; i < this.keys.length; i++ ) 
                        this.thead_tr.appendChild(elem('td',null,this.keys[i]));
        
@@ -113,6 +136,7 @@ FMObjectBuilder.prototype.setKeys = function(o) {
        if( this.display[o.classname] ) {
                this.keys = this.display[o.classname].fields;
                this.bold = this.display[o.classname].bold;
+               this.money = this.display[o.classname].money;
        }
 
        if(!this.keys && FM_TABLE_DISPLAY[o.classname])
@@ -121,6 +145,9 @@ FMObjectBuilder.prototype.setKeys = function(o) {
        if(!this.bold && FM_TABLE_DISPLAY[o.classname])
                this.bold = FM_TABLE_DISPLAY[o.classname].bold;
 
+       if(!this.money && FM_TABLE_DISPLAY[o.classname])
+               this.money = FM_TABLE_DISPLAY[o.classname].money;
+
        if(!this.keys) {
                this.keys = fmclasses[o.classname];
                sortme = true;
@@ -155,6 +182,7 @@ FMObjectBuilder.prototype.buildObjectRow = function(obj) {
                row.appendChild(td);
        }
        this.tbody.appendChild(row);
+       if (this.moneySummaryRow) this.tbody.appendChild(this.moneySummaryRow);
 }
 
 FMObjectBuilder.prototype.munge = function(data) {
@@ -165,6 +193,7 @@ FMObjectBuilder.prototype.munge = function(data) {
                        data = data.replace(/:\d{2}-.*/,'');
                }
        }
+
        return data;
 }
 
@@ -217,6 +246,18 @@ FMObjectBuilder.prototype.fleshData = function(td, data, key) {
                }
 
        } else {
+               if (this.money && grep(this.money,function(i){return (i==key)}) ) {
+                       td.setAttribute('align', 'right');
+                       data = parseFloat(data).toFixed(2);
+
+                       if (isNaN(data)) data = '0.00';
+
+                       if (this.moneySummaryRow) {
+                               var summary_td = $n(this.moneySummaryRow, this.table.id + key);
+                               summary_td.innerHTML = parseFloat(parseFloat(summary_td.innerHTML) + parseFloat(data)).toFixed(2);
+                       }
+               }
+
                if( this.bold && grep(this.bold,function(i){return (i==key)}) ) {
                        var span = elem('span',{'class':'fm_table_bold'}, data);
                        td.appendChild(span);
index 964c3a0..9153b5a 100644 (file)
@@ -65,6 +65,11 @@ var FM_TABLE_DISPLAY = {
                        'cash_payment',
                        'check_payment',        
                        'credit_card_payment'
+               ],
+               money : [
+                       'cash_payment',
+                       'check_payment',        
+                       'credit_card_payment'
                ]
        },
 
@@ -75,6 +80,12 @@ var FM_TABLE_DISPLAY = {
                        'forgive_payment',
                        'work_payment',
                        'goods_payment'
+               ],
+               money : [
+                       'credit_payment',
+                       'forgive_payment',
+                       'work_payment',
+                       'goods_payment'
                ]
        },
        'rr' : {
index d72bf53..32e4e1d 100644 (file)
@@ -97,7 +97,7 @@ function crDrawRange() {
                org, $('cr_start').value, $('cr_end').value );
        req.callback(
                function(r) {
-                       drawFMObjectTable( { dest : 'cr_desk_payments', obj : r.getResultObject() });
+                       drawFMObjectTable( { dest : 'cr_desk_payments', obj : r.getResultObject(), moneySummaryRow : true });
                        sortables_init();
                }
        );
@@ -107,7 +107,7 @@ function crDrawRange() {
                org, $('cr_start').value, $('cr_end').value );
        req.callback(
                function(r) {
-                       drawFMObjectTable( { dest : 'cr_user_payments', obj : r.getResultObject() });
+                       drawFMObjectTable( { dest : 'cr_user_payments', obj : r.getResultObject(), moneySummaryRow : true });
                        sortables_init();
                }
        );