Pman.Tab.XtupleReconcile.bjs
authorAlan Knowles <alan@roojs.com>
Wed, 25 Feb 2015 09:05:40 +0000 (17:05 +0800)
committerAlan Knowles <alan@roojs.com>
Wed, 25 Feb 2015 09:05:40 +0000 (17:05 +0800)
Pman.Tab.XtupleReconcile.js

Pman.Tab.XtupleReconcile.bjs
Pman.Tab.XtupleReconcile.js

index e628f52..81f9bca 100644 (file)
 {
-    "name" : "Pman.Tab.XtupleReconcile",
-    "parent" : "Pman.Tab.XtupleAccountsTab",
-    "title" : "Pman.Tab.XtupleReconcile",
-    "path" : "/home/edward/gitlive/web.xtuple/Pman/Xtuple/Pman.Tab.XtupleReconcile.bjs",
-    "permname" : "",
-    "modOrder" : "200",
-    "items" : [
+ "name" : "Pman.Tab.XtupleReconcile",
+ "parent" : "Pman.Tab.XtupleAccountsTab",
+ "title" : "Pman.Tab.XtupleReconcile",
+ "path" : "/home/alan/gitlive/Pman.Xtuple/Pman.Tab.XtupleReconcile.bjs",
+ "permname" : "",
+ "modOrder" : "200",
+ "items" : [
+  {
+   "background" : true,
+   "title" : "Bank Reconcile",
+   "xtype" : "NestedLayoutPanel",
+   "$ xns" : "Roo",
+   "items" : [
+    {
+     "xtype" : "BorderLayout",
+     "$ xns" : "Roo",
+     "* prop" : "layout",
+     "items" : [
+      {
+       "xtype" : "LayoutRegion",
+       "$ xns" : "Roo",
+       "* prop" : "center"
+      },
+      {
+       "xtype" : "LayoutRegion",
+       "$ xns" : "Roo",
+       "width" : 400,
+       "split" : true,
+       "* prop" : "west"
+      },
+      {
+       "listeners" : {
+        "|activate" : "function() {\n    _this.panel = this;\n    if (_this.grid) {\n        _this.grid.footer.onClick('first');\n    }\n}"
+       },
+       "region" : "center",
+       "fitToframe" : true,
+       "background" : true,
+       "title" : "Bank Reconcile",
+       "xtype" : "GridPanel",
+       "fitContainer" : true,
+       "$ xns" : "Roo",
+       "tableName" : "metasql",
+       "items" : [
         {
-            "background" : true,
-            "xtype" : "NestedLayoutPanel",
-            "title" : "Bank Reconcile",
-            "$ xns" : "Roo",
-            "items" : [
+         "listeners" : {
+          "beforeedit" : "function (e)\n{\n    //    Roo.log(e);\n       var ch =  _this.grid.colModel.config[e.column].header;\n       var val = e.value *1;\n  // Roo.log(ch);\n  // Roo.log(val);\n\n       if (val > 0.0 && ch == 'Debit') {\n            e.cancel = true;\n            return;\n        }\n       if (val < 0.0 && ch == 'Credit') {\n            e.cancel = true;\n            return;\n        }\n        if (e.record.data.cleared || e.record.data.bankrec_posted) {\n            e.cancel = true;\n            return;\n        }\n        \n        // allow start editing..\n}",
+          "cellclick" : "function (_self, rowIndex, columnIndex, e)\n{\n    var clear = function(ar) \n    {\n        var ar_in = ar;\n        if (ar === true) {\n            ar = [];\n            \n            _this.grid.ds.each(function(rec) {\n                if (rec.data.doc_type == 'BF') {\n                    return;\n                }\n                ar.push(rec);\n            });\n        }\n        var sortdate = false;\n        var data = [];\n        Roo.each(ar, function(rec) {\n            if (rec.data.cleared || rec.data.bankrec_posted) {\n                return;\n            }\n            if(!sortdate){\n                sortdate = rec.data.sortdate;\n            }\n            data.push({\n                 id : rec.data.id,\n                altid : rec.data.altid,\n                curr_rate : rec.data.doc_exchrate,\n                amount : rec.data.amount\n                \n            });\n        });\n       new Pman.Request({\n        url : baseURL + '/Roo/bankrecitem',\n            method : 'POST',\n            mask : 'Clearing',\n            params : {\n                bankaccnt_id : _this.bankacct.getValue(),\n                sortdate : sortdate,\n                set_clear : Roo.encode(data)\n            },\n            success : function() {\n                Roo.each(ar, function(rec) {\n                    rec.set('cleared', true);\n                });\n                if (ar_in === true) {\n                    _this.grid.ds.getAt(0).set('cleared', true);\n                }\n                _this.wgrid.footer.onClick('refresh');\n            }\n        });\n    }\n    \n    \n    var unclear = function(ar)\n    {\n        var ar_in = ar;\n        if (ar === true) {\n            ar = [];\n            \n            _this.grid.ds.each(function(rec) {\n                if (rec.data.doc_type == 'BF') {\n                    return;\n                }\n                ar.push(rec);\n            });\n        }\n        var sortdate = false;\n        var data = [];\n        Roo.each(ar, function(rec) {\n            if (!rec.data.cleared  || rec.data.bankrec_posted) {\n                return;\n            }\n            if(!sortdate){\n                sortdate = rec.data.sortdate;\n            }\n            data.push({\n                id : rec.data.id,\n                altid : rec.data.altid                \n            });\n        });\n\n        new Pman.Request({\n            url : baseURL + '/Roo/bankrecitem',\n            method : 'POST',\n            mask : 'Clearing',\n            params : {\n                bankaccnt_id : _this.bankacct.getValue(),\n                sortdate : sortdate,\n                remove_clear :Roo.encode(data)\n                \n            },\n            success : function() {\n                Roo.each(ar, function(rec) {\n                    rec.set('cleared', false);\n                });\n               if (ar_in === true) {\n                    _this.grid.ds.getAt(0).set('cleared', false);\n                }  \n                _this.wgrid.footer.onClick('refresh');\n            }\n        });\n     \n      \n    };\n    \n    \n    \n    var di = this.colModel.config[columnIndex].dataIndex;\n    if (di != 'cleared') {\n        return;\n    }\n    var  rec = this.ds.getAt(rowIndex);\n    if (rec.data.doc_type == 'BF') {\n    \n        if (rec.data.cleared) {\n            unclear(true);\n        \n        } else {\n            clear(true);\n        }\n    \n        return;\n    }\n    \n        \n        \n    if (rec.data.cleared) {\n    \n        unclear([rec]);\n        return;\n        \n    }\n    \n    clear([rec]);\n    \n    \n     \n         \n  \n}",
+          "|render" : "function() \n{\n    _this.grid = this; \n    //_this.dialog = Pman.Dialog.FILL_IN\n    if (_this.panel.active) {\n       this.footer.onClick('first');\n    }\n}",
+          "afteredit" : "function (e)\n{\n\n    if (e.cancel) {\n        return;\n    }\n       var ch =  _this.grid.colModel.config[e.column].header;\n           var val = e.originalValue *1;\n      // Roo.log(ch);\n      // Roo.log(val);\n\n       if (val > 0.0 && ch == 'Debit') {\n            e.cancel = true;\n            return;\n        }\n       if (val < 0.0 && ch == 'Credit') {\n            e.cancel = true;\n            return;\n        }\n        if (e.record.data.cleared || e.record.data.bankrec_posted) {\n            e.cancel = true;\n            return;\n        }\n        if (val > 0.0 && e.value < 0.0) {\n        Roo.log(\"CANCEL\");  \n            e.record.set('amount', e.originalValue);\n            e.cancel = true;\n            return;\n        }\n        if (val < 0.0 && e.value > 0.0) {\n        Roo.log(\"CANCEL\");\n            e.record.set('amount', e.originalValue);\n            e.cancel = true;\n            return;\n        } \n        if (e.originalValue*1 == e.value*1) {\n            return;\n        }\n          \n        e.record.set('doc_exchrate', Math.abs(e.value  * 1)  / Math.abs(e.record.data.base_amount * 1));\n        Roo.log(e.record);\n        \n        _this.grid.ds.updateBalance();\n        // send it down the line...\n        new Pman.Request({\n            method : 'POST',\n            url : baseURL + '/Roo/bankrecitem',\n            mask : 'Saving',\n            params : {\n                bankaccnt_id : _this.bankacct.getValue(),\n                set_amount : Math.abs(e.value),\n                sortdate : e.record.data.sortdate,\n                source_id : e.record.data.id,\n                altid : e.record.data.altid\n            }\n        \n        });\n        \n         \n        \n        \n}"
+         },
+         "autoExpandColumn" : "notes",
+         "xtype" : "EditorGrid",
+         "loadMask" : true,
+         "clicksToEdit" : 1,
+         "$ xns" : "Roo.grid",
+         "* prop" : "grid",
+         "items" : [
+          {
+           "listeners" : {
+            "beforeloadadd" : "function (_self, records, options, res)\n{\n //  _this.total = 0.0;\n\n  \n\n\n      _this.total = 1 * res.raw.amount;\n        _this.bf = 1 * res.raw.amount;\n    Roo.log(\"TOTAL:\" + _this.total);\n}\n",
+            "beforeload" : "function (_self, o)\n{\n    var s = _this.wgrid.getSelectionModel().getSelected();\n    \n    if (!s) {\n        return false;\n    }\n    o.params._group = 'bankrec';\n    o.params._name = 'all';\n    o.params['sortdate:text'] = s.data.sortdate;\n    o.params['bankaccntid:number'] =     _this.bankacct.getValue();\n\n    o.params['_cals'] = 'amount'\n}",
+            "load" : "function (_self, records, options)\n{\n    \n    var bal = _this.bf;\n      var cleared = true;\n      var posted = true;\n    Roo.each(records, function(rec) {\n        if (!rec.data.cleared) {\n            cleared = false;\n\n        }\n        if (!rec.data.bankrec_posted) {\n            posted = false;\n        }\n        if (rec.data.doc_type != 'BF') {\n            bal += rec.data.amount *1;\n            rec.set('balance', bal);   \n        } else {\n            rec.set('balance', _this.bf);\n        }\n        \n        \n    });\n    \n    var rec = this.reader.newRow({\n        notes : 'Brought Forward',\n        balance : _this.bf,\n        doc_type : 'BF',\n        cleared : cleared,\n        bankrec_posted : posted\n    });\n    this.insert(0, [rec]);\n}"
+           },
+           "xtype" : "Store",
+           "remoteSort" : true,
+           "$ sortInfo" : "{ field : 'metasql_group', direction: 'ASC' }",
+           "$ xns" : "Roo.data",
+           "$ updateBalance" : "function() {\n     var bal = _this.bf;\n    this.each( function(rec) {\n        if (rec.data.doc_type != 'BF') {\n            bal += rec.data.amount *1;\n            rec.set('balance', bal);   \n        } else {\n            rec.set('balance', _this.bf);\n        }\n        \n        \n    });\n}\n",
+           "* prop" : "dataSource",
+           "items" : [
+            {
+             "$ url" : "baseURL + '/Roo/metasql.php'",
+             "method" : "GET",
+             "xtype" : "HttpProxy",
+             "$ xns" : "Roo.data",
+             "* prop" : "proxy"
+            },
+            {
+             "id" : "idx",
+             "root" : "data",
+             "xtype" : "JsonReader",
+             "$ fields" : "[\n    {\n        'name': 'metasql_id',\n        'type': 'int'\n    },\n    {\n        'name': 'metasql_group',\n        'type': 'string'\n    },\n    {\n        'name': 'metasql_name',\n        'type': 'string'\n    },\n    {\n        'name': 'metasql_notes',\n        'type': 'string'\n    },\n    {\n        'name': 'metasql_query',\n        'type': 'string'\n    },\n    {\n        'name': 'metasql_lastuser',\n        'type': 'string'\n    },\n    {\n        'name': 'metasql_lastupdate',\n        'type': 'date',\n        'dateFormat': 'Y-m-d'\n    },\n    {\n        'name': 'metasql_grade',\n        'type': 'int'\n    }\n]",
+             "$ xns" : "Roo.data",
+             "* prop" : "reader",
+             "totalProperty" : "total"
+            }
+           ]
+          },
+          {
+           "pageSize" : 50,
+           "xtype" : "PagingToolbar",
+           "emptyMsg" : "Nothing found",
+           "$ xns" : "Roo",
+           "displayMsg" : "Displaying records {0} - {1} of {2}",
+           "displayInfo" : true,
+           "* prop" : "footer"
+          },
+          {
+           "xtype" : "Toolbar",
+           "$ xns" : "Roo",
+           "* prop" : "toolbar",
+           "items" : [
+            {
+             "listeners" : {
+              "render" : "function (_self)\n{\n    _this.bankacct = _self;\n}",
+              "select" : "function (combo, record, index)\n{ \n    var curr = record.data.bankaccnt_curr_id_curr_abbr;\n    var col = _this.grid.colModel.config.length -1;\n    \n    _this.grid.colModel.setColumnHeader(col, 'Balance (' + curr +')');\n    \n    _this.grid.ds.removeAll();\n    \n    _this.wgrid.footer.onClick('first');\n}"
+             },
+             "listWidth" : 400,
+             "triggerAction" : "all",
+             "fieldLabel" : "bankaccnt",
+             "forceSelection" : true,
+             "selectOnFocus" : true,
+             "pageSize" : 50,
+             "displayField" : "bankaccnt_name",
+             "emptyText" : "Select bankaccnt",
+             "hiddenName" : "bankaccnt_id",
+             "minChars" : 2,
+             "valueField" : "bankaccnt_id",
+             "xtype" : "ComboBox",
+             "allowBlank" : false,
+             "typeAhead" : true,
+             "editable" : false,
+             "width" : 300,
+             "$ xns" : "Roo.form",
+             "name" : "bankaccnt_bankname",
+             "qtip" : "Select bankaccnt",
+             "queryParam" : "",
+             "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{bankaccnt_bankname}</b> </div>",
+             "loadingText" : "Searching...",
+             "items" : [
+              {
+               "listeners" : {
+                "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n}\n"
+               },
+               "xtype" : "Store",
+               "remoteSort" : true,
+               "$ sortInfo" : "{ direction : 'ASC', field: 'bankaccnt_bankname' }",
+               "$ xns" : "Roo.data",
+               "* prop" : "store",
+               "items" : [
                 {
-                    "xtype" : "BorderLayout",
-                    "$ xns" : "Roo",
-                    "* prop" : "layout",
-                    "items" : [
-                        {
-                            "xtype" : "LayoutRegion",
-                            "$ xns" : "Roo",
-                            "* prop" : "center"
-                        },
-                        {
-                            "xtype" : "LayoutRegion",
-                            "width" : 400,
-                            "$ xns" : "Roo",
-                            "split" : true,
-                            "* prop" : "west"
-                        },
-                        {
-                            "listeners" : {
-                                "|activate" : "function() {\n    _this.panel = this;\n    if (_this.grid) {\n        _this.grid.footer.onClick('first');\n    }\n}"
-                            },
-                            "fitToframe" : true,
-                            "background" : true,
-                            "region" : "center",
-                            "title" : "Bank Reconcile",
-                            "xtype" : "GridPanel",
-                            "fitContainer" : true,
-                            "$ xns" : "Roo",
-                            "tableName" : "metasql",
-                            "items" : [
-                                {
-                                    "listeners" : {
-                                        "beforeedit" : "function (e)\n{\n    //    Roo.log(e);\n       var ch =  _this.grid.colModel.config[e.column].header;\n       var val = e.value *1;\n  // Roo.log(ch);\n  // Roo.log(val);\n\n       if (val > 0.0 && ch == 'Debit') {\n            e.cancel = true;\n            return;\n        }\n       if (val < 0.0 && ch == 'Credit') {\n            e.cancel = true;\n            return;\n        }\n        if (e.record.data.cleared || e.record.data.bankrec_posted) {\n            e.cancel = true;\n            return;\n        }\n        \n        // allow start editing..\n}",
-                                        "|render" : "function() \n{\n    _this.grid = this; \n    //_this.dialog = Pman.Dialog.FILL_IN\n    if (_this.panel.active) {\n       this.footer.onClick('first');\n    }\n}",
-                                        "cellclick" : "function (_self, rowIndex, columnIndex, e)\n{\n    var clear = function(ar) \n    {\n        var ar_in = ar;\n        if (ar === true) {\n            ar = [];\n            \n            _this.grid.ds.each(function(rec) {\n                if (rec.data.doc_type == 'BF') {\n                    return;\n                }\n                ar.push(rec);\n            });\n        }\n        var sortdate = false;\n        var data = [];\n        Roo.each(ar, function(rec) {\n            if (rec.data.cleared || rec.data.bankrec_posted) {\n                return;\n            }\n            if(!sortdate){\n                sortdate = rec.data.sortdate;\n            }\n            data.push({\n                 id : rec.data.id,\n                altid : rec.data.altid,\n                curr_rate : rec.data.doc_exchrate,\n                amount : rec.data.amount\n                \n            });\n        });\n       new Pman.Request({\n        url : baseURL + '/Roo/bankrecitem',\n            method : 'POST',\n            mask : 'Clearing',\n            params : {\n                bankaccnt_id : _this.bankacct.getValue(),\n                sortdate : sortdate,\n                set_clear : Roo.encode(data)\n            },\n            success : function() {\n                Roo.each(ar, function(rec) {\n                    rec.set('cleared', true);\n                });\n                if (ar_in === true) {\n                    _this.grid.ds.getAt(0).set('cleared', true);\n                }\n                _this.wgrid.footer.onClick('refresh');\n            }\n        });\n    }\n    \n    \n    var unclear = function(ar)\n    {\n        var ar_in = ar;\n        if (ar === true) {\n            ar = [];\n            \n            _this.grid.ds.each(function(rec) {\n                if (rec.data.doc_type == 'BF') {\n                    return;\n                }\n                ar.push(rec);\n            });\n        }\n        var sortdate = false;\n        var data = [];\n        Roo.each(ar, function(rec) {\n            if (!rec.data.cleared  || rec.data.bankrec_posted) {\n                return;\n            }\n            if(!sortdate){\n                sortdate = rec.data.sortdate;\n            }\n            data.push({\n                id : rec.data.id,\n                altid : rec.data.altid                \n            });\n        });\n\n        new Pman.Request({\n            url : baseURL + '/Roo/bankrecitem',\n            method : 'POST',\n            mask : 'Clearing',\n            params : {\n                bankaccnt_id : _this.bankacct.getValue(),\n                sortdate : sortdate,\n                remove_clear :Roo.encode(data)\n                \n            },\n            success : function() {\n                Roo.each(ar, function(rec) {\n                    rec.set('cleared', false);\n                });\n               if (ar_in === true) {\n                    _this.grid.ds.getAt(0).set('cleared', false);\n                }  \n                _this.wgrid.footer.onClick('refresh');\n            }\n        });\n     \n      \n    };\n    \n    \n    \n    var di = this.colModel.config[columnIndex].dataIndex;\n    if (di != 'cleared') {\n        return;\n    }\n    var  rec = this.ds.getAt(rowIndex);\n    if (rec.data.doc_type == 'BF') {\n    \n        if (rec.data.cleared) {\n            unclear(true);\n        \n        } else {\n            clear(true);\n        }\n    \n        return;\n    }\n    \n        \n        \n    if (rec.data.cleared) {\n    \n        unclear([rec]);\n        return;\n        \n    }\n    \n    clear([rec]);\n    \n    \n     \n         \n  \n}",
-                                        "afteredit" : "function (e)\n{\n\n    if (e.cancel) {\n        return;\n    }\n       var ch =  _this.grid.colModel.config[e.column].header;\n           var val = e.originalValue *1;\n      // Roo.log(ch);\n      // Roo.log(val);\n\n       if (val > 0.0 && ch == 'Debit') {\n            e.cancel = true;\n            return;\n        }\n       if (val < 0.0 && ch == 'Credit') {\n            e.cancel = true;\n            return;\n        }\n        if (e.record.data.cleared || e.record.data.bankrec_posted) {\n            e.cancel = true;\n            return;\n        }\n        if (val > 0.0 && e.value < 0.0) {\n        Roo.log(\"CANCEL\");  \n            e.record.set('amount', e.originalValue);\n            e.cancel = true;\n            return;\n        }\n        if (val < 0.0 && e.value > 0.0) {\n        Roo.log(\"CANCEL\");\n            e.record.set('amount', e.originalValue);\n            e.cancel = true;\n            return;\n        } \n        if (e.originalValue*1 == e.value*1) {\n            return;\n        }\n          \n        e.record.set('doc_exchrate', Math.abs(e.value  * 1)  / Math.abs(e.record.data.base_amount * 1));\n        Roo.log(e.record);\n        \n        _this.grid.ds.updateBalance();\n        // send it down the line...\n        new Pman.Request({\n            method : 'POST',\n            url : baseURL + '/Roo/bankrecitem',\n            mask : 'Saving',\n            params : {\n                bankaccnt_id : _this.bankacct.getValue(),\n                set_amount : Math.abs(e.value),\n                sortdate : e.record.data.sortdate,\n                source_id : e.record.data.id,\n                altid : e.record.data.altid\n            }\n        \n        });\n        \n         \n        \n        \n}"
-                                    },
-                                    "autoExpandColumn" : "notes",
-                                    "xtype" : "EditorGrid",
-                                    "loadMask" : true,
-                                    "clicksToEdit" : 1,
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "grid",
-                                    "items" : [
-                                        {
-                                            "listeners" : {
-                                                "beforeloadadd" : "function (_self, records, options, res)\n{\n //  _this.total = 0.0;\n\n  \n\n\n      _this.total = 1 * res.raw.amount;\n        _this.bf = 1 * res.raw.amount;\n    Roo.log(\"TOTAL:\" + _this.total);\n}\n",
-                                                "beforeload" : "function (_self, o)\n{\n    var s = _this.wgrid.getSelectionModel().getSelected();\n    \n    if (!s) {\n        return false;\n    }\n    o.params._group = 'bankrec';\n    o.params._name = 'all';\n    o.params['sortdate:text'] = s.data.sortdate;\n    o.params['bankaccntid:number'] =     _this.bankacct.getValue();\n\n    o.params['_cals'] = 'amount'\n}",
-                                                "load" : "function (_self, records, options)\n{\n    \n    var bal = _this.bf;\n      var cleared = true;\n      var posted = true;\n    Roo.each(records, function(rec) {\n        if (!rec.data.cleared) {\n            cleared = false;\n\n        }\n        if (!rec.data.bankrec_posted) {\n            posted = false;\n        }\n        if (rec.data.doc_type != 'BF') {\n            bal += rec.data.amount *1;\n            rec.set('balance', bal);   \n        } else {\n            rec.set('balance', _this.bf);\n        }\n        \n        \n    });\n    \n    var rec = this.reader.newRow({\n        notes : 'Brought Forward',\n        balance : _this.bf,\n        doc_type : 'BF',\n        cleared : cleared,\n        bankrec_posted : posted\n    });\n    this.insert(0, [rec]);\n}"
-                                            },
-                                            "xtype" : "Store",
-                                            "remoteSort" : true,
-                                            "$ sortInfo" : "{ field : 'metasql_group', direction: 'ASC' }",
-                                            "$ xns" : "Roo.data",
-                                            "$ updateBalance" : "function() {\n     var bal = _this.bf;\n    this.each( function(rec) {\n        if (rec.data.doc_type != 'BF') {\n            bal += rec.data.amount *1;\n            rec.set('balance', bal);   \n        } else {\n            rec.set('balance', _this.bf);\n        }\n        \n        \n    });\n}\n",
-                                            "* prop" : "dataSource",
-                                            "items" : [
-                                                {
-                                                    "$ url" : "baseURL + '/Roo/metasql.php'",
-                                                    "xtype" : "HttpProxy",
-                                                    "method" : "GET",
-                                                    "$ xns" : "Roo.data",
-                                                    "* prop" : "proxy"
-                                                },
-                                                {
-                                                    "id" : "idx",
-                                                    "root" : "data",
-                                                    "xtype" : "JsonReader",
-                                                    "$ fields" : "[\n    {\n        'name': 'metasql_id',\n        'type': 'int'\n    },\n    {\n        'name': 'metasql_group',\n        'type': 'string'\n    },\n    {\n        'name': 'metasql_name',\n        'type': 'string'\n    },\n    {\n        'name': 'metasql_notes',\n        'type': 'string'\n    },\n    {\n        'name': 'metasql_query',\n        'type': 'string'\n    },\n    {\n        'name': 'metasql_lastuser',\n        'type': 'string'\n    },\n    {\n        'name': 'metasql_lastupdate',\n        'type': 'date',\n        'dateFormat': 'Y-m-d'\n    },\n    {\n        'name': 'metasql_grade',\n        'type': 'int'\n    }\n]",
-                                                    "$ xns" : "Roo.data",
-                                                    "* prop" : "reader",
-                                                    "totalProperty" : "total"
-                                                }
-                                            ]
-                                        },
-                                        {
-                                            "pageSize" : 50,
-                                            "xtype" : "PagingToolbar",
-                                            "emptyMsg" : "Nothing found",
-                                            "$ xns" : "Roo",
-                                            "displayMsg" : "Displaying records {0} - {1} of {2}",
-                                            "displayInfo" : true,
-                                            "* prop" : "footer"
-                                        },
-                                        {
-                                            "xtype" : "Toolbar",
-                                            "$ xns" : "Roo",
-                                            "* prop" : "toolbar",
-                                            "items" : [
-                                                {
-                                                    "listeners" : {
-                                                        "render" : "function (_self)\n{\n    _this.bankacct = _self;\n}",
-                                                        "select" : "function (combo, record, index)\n{ \n    var curr = record.data.bankaccnt_curr_id_curr_abbr;\n    var col = _this.grid.colModel.config.length -1;\n    \n    _this.grid.colModel.setColumnHeader(col, 'Balance (' + curr +')');\n    \n    _this.grid.ds.removeAll();\n    \n    _this.wgrid.footer.onClick('first');\n}"
-                                                    },
-                                                    "listWidth" : 400,
-                                                    "triggerAction" : "all",
-                                                    "fieldLabel" : "bankaccnt",
-                                                    "forceSelection" : true,
-                                                    "selectOnFocus" : true,
-                                                    "pageSize" : 50,
-                                                    "displayField" : "bankaccnt_bankname",
-                                                    "emptyText" : "Select bankaccnt",
-                                                    "hiddenName" : "bankaccnt_id",
-                                                    "minChars" : 2,
-                                                    "valueField" : "bankaccnt_id",
-                                                    "xtype" : "ComboBox",
-                                                    "allowBlank" : false,
-                                                    "typeAhead" : true,
-                                                    "editable" : false,
-                                                    "width" : 300,
-                                                    "$ xns" : "Roo.form",
-                                                    "name" : "bankaccnt_bankname",
-                                                    "qtip" : "Select bankaccnt",
-                                                    "queryParam" : "",
-                                                    "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{bankaccnt_bankname}</b> </div>",
-                                                    "loadingText" : "Searching...",
-                                                    "items" : [
-                                                        {
-                                                            "listeners" : {
-                                                                "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n}\n"
-                                                            },
-                                                            "xtype" : "Store",
-                                                            "remoteSort" : true,
-                                                            "$ sortInfo" : "{ direction : 'ASC', field: 'bankaccnt_bankname' }",
-                                                            "$ xns" : "Roo.data",
-                                                            "* prop" : "store",
-                                                            "items" : [
-                                                                {
-                                                                    "$ url" : "baseURL + '/Roo/bankaccnt.php'",
-                                                                    "method" : "GET",
-                                                                    "xtype" : "HttpProxy",
-                                                                    "$ xns" : "Roo.data",
-                                                                    "* prop" : "proxy"
-                                                                },
-                                                                {
-                                                                    "id" : "id",
-                                                                    "root" : "data",
-                                                                    "xtype" : "JsonReader",
-                                                                    "$ xns" : "Roo.data",
-                                                                    "$ fields" : "[{\"name\":\"id\",\"type\":\"int\"},{\"name\":\"bankaccnt_name\",\"type\":\"string\"}]",
-                                                                    "* prop" : "reader",
-                                                                    "totalProperty" : "total"
-                                                                }
-                                                            ]
-                                                        }
-                                                    ]
-                                                },
-                                                {
-                                                    "listeners" : {
-                                                        "click" : "function (_self, e)\n{\n    var o = {params : {}}; \n    if (!_this.bankacct.getValue()) {\n        return false;\n    }\n    o.params._group = 'bankrec';\n    o.params._name = 'all';\n    o.params['bankaccntid:number'] =     _this.bankacct.getValue();\n    o.params['_sum_prev'] = 'amount';\n     o.url = baseURL + '/Roo/Metasql';\n     o.method = 'GET';\n     \n     var cols = {\n        'cleared' : 'Cleared',\n        'sortdate' : 'Date',\n        'doc_type' : 'Doctype',\n        'doc_number' : 'Doc number',\n        'notes' : 'Notes',\n        'doc_curr' : 'Currency',\n        'base_amount' : 'Base Amount',\n        'doc_exchrate' : 'Exchange Rate',\n        'amount' : 'Amount (Bank Currency)'\n    };\n     var n =0;\n     for (var i in cols) {\n        \n     \n        o.params['csvCols['+n+']'] =  i\n        o.params['csvTitles['+n+']'] =  cols[i];\n        n++;\n    }\n\n     \n     new Pman.Download(o);\n    Roo.MessageBox.alert(\"Notice\", \"Should be downloading now\");\n}"
-                                                    },
-                                                    "text" : "Download",
-                                                    "xtype" : "Button",
-                                                    "$ xns" : "Roo.Toolbar"
-                                                },
-                                                {
-                                                    "xtype" : "Fill",
-                                                    "$ xns" : "Roo.Toolbar"
-                                                }
-                                            ]
-                                        },
-                                        {
-                                            "xtype" : "ColumnModel",
-                                            "header" : "Cleared",
-                                            "width" : 50,
-                                            "$ renderer" : "function(v,x,r) { \n    if (r.data.bankrec_posted) {\n        return 'POSTED';\n    }\n\n    var state = v   ?  '-checked' : '';\n                                    \n    return '<img class=\"x-grid-check-icon' + state + '\" src=\"' + Roo.BLANK_IMAGE_URL + '\"/>';\n }",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "colModel[]",
-                                            "dataIndex" : "cleared"
-                                        },
-                                        {
-                                            "xtype" : "ColumnModel",
-                                            "header" : "Date",
-                                            "width" : 75,
-                                            "$ renderer" : "function(v) {   \n\n    return v ? Date.parseDate(v,'Y-m-d').format('d/M/Y') : '';\n }",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "colModel[]",
-                                            "dataIndex" : "sortdate"
-                                        },
-                                        {
-                                            "xtype" : "ColumnModel",
-                                            "header" : "Doctype",
-                                            "width" : 50,
-                                            "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "colModel[]",
-                                            "dataIndex" : "doc_type"
-                                        },
-                                        {
-                                            "xtype" : "ColumnModel",
-                                            "header" : "Doc Number",
-                                            "width" : 120,
-                                            "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "colModel[]",
-                                            "dataIndex" : "doc_number"
-                                        },
-                                        {
-                                            "xtype" : "ColumnModel",
-                                            "header" : "Notes",
-                                            "width" : 200,
-                                            "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "colModel[]",
-                                            "dataIndex" : "notes"
-                                        },
-                                        {
-                                            "xtype" : "ColumnModel",
-                                            "header" : "Currency",
-                                            "width" : 75,
-                                            "$ renderer" : "function(v) { return String.format('{0}', v); }",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "colModel[]",
-                                            "dataIndex" : "doc_curr"
-                                        },
-                                        {
-                                            "align" : "right",
-                                            "xtype" : "ColumnModel",
-                                            "header" : "Exchange Rate",
-                                            "width" : 75,
-                                            "$ renderer" : "function(v) { return String.format('{0}', v ? (v*1).toFixed(3) : ''); }",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "colModel[]",
-                                            "dataIndex" : "doc_exchrate"
-                                        },
-                                        {
-                                            "align" : "right",
-                                            "xtype" : "ColumnModel",
-                                            "header" : "Base Amount",
-                                            "width" : 120,
-                                            "$ renderer" : "function(v) { return String.format('{0}', Roo.util.Format.number(v*1,2)); }",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "colModel[]",
-                                            "dataIndex" : "base_amount"
-                                        },
-                                        {
-                                            "align" : "right",
-                                            "xtype" : "ColumnModel",
-                                            "header" : "Credit",
-                                            "width" : 120,
-                                            "$ renderer" : "function(v,x,r) { \n    if (r.data.doc_type == 'BF') {\n        return '';\n    }\n    return String.format('{0}', v > 0 ? Roo.util.Format.number(v*1,2)   : ''); }",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "colModel[]",
-                                            "dataIndex" : "amount",
-                                            "items" : [
-                                                {
-                                                    "xtype" : "GridEditor",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "editor",
-                                                    "items" : [
-                                                        {
-                                                            "xtype" : "NumberField",
-                                                            "cls" : "align-right",
-                                                            "decimalPrecision" : 2,
-                                                            "$ xns" : "Roo.form",
-                                                            "* prop" : "field"
-                                                        }
-                                                    ]
-                                                }
-                                            ]
-                                        },
-                                        {
-                                            "align" : "right",
-                                            "xtype" : "ColumnModel",
-                                            "header" : "Debit",
-                                            "width" : 120,
-                                            "$ renderer" : "function(v,x,r) { \n    if (r.data.doc_type == 'BF') {\n        return '';\n    }\n    return String.format('{0}', v < 0 ? Roo.util.Format.number(v*1,2): ''); }",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "colModel[]",
-                                            "dataIndex" : "amount",
-                                            "items" : [
-                                                {
-                                                    "xtype" : "GridEditor",
-                                                    "$ xns" : "Roo.grid",
-                                                    "* prop" : "editor",
-                                                    "items" : [
-                                                        {
-                                                            "xtype" : "NumberField",
-                                                            "cls" : "align-right",
-                                                            "decimalPrecision" : 2,
-                                                            "$ xns" : "Roo.form",
-                                                            "* prop" : "field"
-                                                        }
-                                                    ]
-                                                }
-                                            ]
-                                        },
-                                        {
-                                            "align" : "right",
-                                            "xtype" : "ColumnModel",
-                                            "header" : "Balance",
-                                            "width" : 120,
-                                            "$ renderer" : "\nfunction(v,x,r) { \n    if (r.data.doc_type == 'BF') {\n        return String.format('{0}', Roo.util.Format.number(v*1,2)); \n    }\n\n\n    //_this.total += (v*1)\n     return String.format('{0}', Roo.util.Format.number(v*1,2)); \n}",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "colModel[]",
-                                            "dataIndex" : "balance"
-                                        }
-                                    ]
-                                }
-                            ]
-                        },
-                        {
-                            "listeners" : {
-                                "|activate" : "function() {\n    _this.wpanel = this;\n    //if (_this.wgrid) {\n    //    _this.wgrid.footer.onClick('first');\n    //}\n}"
-                            },
-                            "fitToframe" : true,
-                            "background" : true,
-                            "region" : "west",
-                            "title" : "Pick a Date",
-                            "xtype" : "GridPanel",
-                            "fitContainer" : true,
-                            "$ xns" : "Roo",
-                            "tableName" : "Groups",
-                            "items" : [
-                                {
-                                    "listeners" : {
-                                        "|render" : "function() \n{\n    _this.wgrid = this; \n    //_this.dialog = Pman.Dialog.FILL_IN\n    //if (_this.wpanel.active) {\n    //   this.footer.onClick('first');\n    //}\n}",
-                                        "cellclick" : "function (_self, rowIndex, columnIndex, e)\n{\n    var di = this.colModel.getDataIndex(columnIndex);\n\n    if (di != 'is_reconciled') {\n        return;\n    }\n     \n    var rec = this.ds.getAt(rowIndex);\n    \n    var voidit = function(){\n        new Pman.Request({\n            url : baseURL + '/Roo/Bankrec.php',\n            method :'POST',\n            params : {\n                _void : 1,\n                bankaccnt_id : _this.bankacct.getValue(),\n                sotrdate : rec.data.sortdate\n                \n            },\n            success : function() {\n                _this.wgrid.footer.onClick('refresh');\n            }\n        });\n    }\n    \n    var postit = function(){\n        new Pman.Request({\n            url : baseURL + '/Roo/Bankrec.php',\n            method :'POST',\n            params : {\n                _post : 1,\n                bankaccnt_id : _this.bankacct.getValue(),\n                sotrdate : rec.data.sortdate\n                \n            },\n            success : function() {\n                _this.wgrid.footer.onClick('refresh');\n            }\n        });\n    \n    }\n    \n    if(rec.data.is_reconciled == 1){\n        voidit();\n        return;\n    }\n    \n    postit();\n    return;\n    \n    \n    \n}",
-                                        "rowclick" : "function (_self, rowIndex, e)\n{\n    \n     _this.wgrid.lastSelectedRow = rowIndex;\n    \n}"
-                                    },
-                                    "autoExpandColumn" : "sortdate",
-                                    "xtype" : "Grid",
-                                    "loadMask" : true,
-                                    "$ xns" : "Roo.grid",
-                                    "* prop" : "grid",
-                                    "items" : [
-                                        {
-                                            "xtype" : "Toolbar",
-                                            "$ xns" : "Roo",
-                                            "* prop" : "toolbar",
-                                            "items" : [
-                                                {
-                                                    "listeners" : {
-                                                        "render" : "function (_self)\n{\n    _this.monthSel = _self;\n}",
-                                                        "select" : "function (combo, date)\n{\n    _this.grid.ds.removeAll();\n    _this.wgrid.footer.onClick('first');\n}"
-                                                    },
-                                                    "format" : "M Y",
-                                                    "useIso" : true,
-                                                    "xtype" : "MonthField",
-                                                    "allowBlank" : true,
-                                                    "width" : 150,
-                                                    "$ xns" : "Roo.form"
-                                                },
-                                                {
-                                                    "listeners" : {
-                                                        "click" : "function (_self, e)\n{\n    _this.monthSel.setValue('');\n    _this.grid.ds.removeAll();\r\n    _this.wgrid.footer.onClick('first');\r\n}"
-                                                    },
-                                                    "xtype" : "Button",
-                                                    "cls" : "x-btn-icon",
-                                                    "$ icon" : "rootURL + '/Pman/templates/images/edit-clear.gif'",
-                                                    "$ xns" : "Roo.Toolbar"
-                                                },
-                                                {
-                                                    "xtype" : "Fill",
-                                                    "$ xns" : "Roo.Toolbar"
-                                                },
-                                                {
-                                                    "text" : "Fix Data",
-                                                    "xtype" : "Button",
-                                                    "cls" : "x-btn-text-icon",
-                                                    "$ icon" : "Roo.rootURL + 'images/default/tree/leaf.gif'",
-                                                    "$ xns" : "Roo.Toolbar",
-                                                    "items" : [
-                                                        {
-                                                            "xtype" : "Menu",
-                                                            "$ xns" : "Roo.menu",
-                                                            "* prop" : "menu",
-                                                            "items" : [
-                                                                {
-                                                                    "listeners" : {
-                                                                        "click" : "function (_self, e)\n{\n\n    Roo.MessageBox.confirm(\"Confirm\", \"Are you sure you want to fix all the historical data? It will recreate all the posted bankrec and delect all the unpost\",\n        function (res) {\n            if(res!='yes') {\n                return;\n            \n            }\n            new Pman.Request({\n                url : baseURL + '/Roo/Bankrec.php',\n                method :'POST',\n                params : {\n                    _fix : 1\n                },\n                success : function() {\n                    if(_this.wgrid){\n                        _this.wgrid.footer.onClick('refresh');\n                    }\n                    Roo.MessageBox.alert('Notice', 'FIXED');\n                }\n            });\n    });\n\n}"
-                                                                    },
-                                                                    "text" : "Fix historical data",
-                                                                    "xtype" : "Item",
-                                                                    "cls" : "x-btn-text-icon",
-                                                                    "$ icon" : "Roo.rootURL + 'images/default/tree/leaf.gif'",
-                                                                    "$ xns" : "Roo.menu"
-                                                                },
-                                                                {
-                                                                    "listeners" : {
-                                                                        "click" : "function (_self, e)\n{\n\n    Roo.MessageBox.confirm(\"Confirm\", \"Are you sure you want?\",\n        function (res) {\n            if(res!='yes') {\n                return;\n            \n            }\n            new Pman.Request({\n                url : baseURL + '/Roo/Bankrec.php',\n                method :'POST',\n                params : {\n                    _closedPeriod : 1\n                },\n                success : function() {\n                    if(_this.wgrid){\n                        _this.wgrid.footer.onClick('refresh');\n                    }\n                    Roo.MessageBox.alert('Notice', 'DONE');\n                }\n            });\n    });\n\n}"
-                                                                    },
-                                                                    "text" : "Fix Closed Periods",
-                                                                    "xtype" : "Item",
-                                                                    "cls" : "x-btn-text-icon",
-                                                                    "$ icon" : "Roo.rootURL + 'images/default/tree/leaf.gif'",
-                                                                    "$ xns" : "Roo.menu"
-                                                                }
-                                                            ]
-                                                        }
-                                                    ]
-                                                }
-                                            ]
-                                        },
-                                        {
-                                            "listeners" : {
-                                                "selectionchange" : "function (_self)\n{\n    _this.grid.footer.onClick('first');\n}"
-                                            },
-                                            "xtype" : "RowSelectionModel",
-                                            "singleSelect" : true,
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "sm"
-                                        },
-                                        {
-                                            "listeners" : {
-                                                "beforeload" : "function (_self, o)\n{\n\n    if (!_this.bankacct.getValue()) {\n        return false;\n    }\n    var dt = _this.monthSel.getValue();\n    \n    if(dt.length){\n        o.params['sortdate:text'] = typeof(dt) == 'string' ? dt : dt.format('Y-m-d');\n    }\n    o.params._group = 'bankrec';\n    o.params._name = 'bydate';\n    o.params['bankaccntid:number'] =  _this.bankacct.getValue();\n    \n\n    \n}",
-                                                "load" : "function (_self, records, options, res)\n{   \n    var sm = _this.wgrid.getSelectionModel();\n    \n    if(_this.wgrid.lastSelectedRow * 1 >0){\n        sm.selectRow(_this.wgrid.lastSelectedRow);\n        return;\n    }\n    \n    if (!sm.getSelections().length) {\n        sm.selectFirstRow();\n    }\n\n}"
-                                            },
-                                            "xtype" : "Store",
-                                            "remoteSort" : true,
-                                            "$ sortInfo" : "{ field : 'sotrdate', direction: 'ASC' }",
-                                            "$ xns" : "Roo.data",
-                                            "* prop" : "dataSource",
-                                            "items" : [
-                                                {
-                                                    "$ url" : "baseURL + '/Roo/metasql.php'",
-                                                    "method" : "GET",
-                                                    "xtype" : "HttpProxy",
-                                                    "timeout" : 900000,
-                                                    "$ xns" : "Roo.data",
-                                                    "* prop" : "proxy"
-                                                },
-                                                {
-                                                    "id" : "id",
-                                                    "root" : "data",
-                                                    "xtype" : "JsonReader",
-                                                    "$ fields" : "[\n    {\n        'name': 'sortdate',\n        'type': 'string'\n    }\n]",
-                                                    "$ xns" : "Roo.data",
-                                                    "* prop" : "reader",
-                                                    "totalProperty" : "total"
-                                                }
-                                            ]
-                                        },
-                                        {
-                                            "pageSize" : 25,
-                                            "xtype" : "PagingToolbar",
-                                            "emptyMsg" : "No Date found",
-                                            "$ xns" : "Roo",
-                                            "displayMsg" : "Displaying Date{0} - {1} of {2}",
-                                            "displayInfo" : false,
-                                            "* prop" : "footer"
-                                        },
-                                        {
-                                            "xtype" : "ColumnModel",
-                                            "header" : "Date",
-                                            "width" : 100,
-                                            "$ renderer" : "function(v) {   \n\n    return v ? Date.parseDate(v,'Y-m-d').format('d/M/Y') : '';\n }",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "colModel[]",
-                                            "dataIndex" : "sortdate"
-                                        },
-                                        {
-                                            "align" : "right",
-                                            "xtype" : "ColumnModel",
-                                            "header" : "Closing Balance",
-                                            "width" : 120,
-                                            "$ renderer" : "function(v,x,r) { \n    \n    var color = 'red'; // has some not 'ticked'\n    \n    if(r.data.no_records - r.data.no_posted == 0){ // all posted on that date\n        color = 'black';\n    }\n    if(r.data.no_records - r.data.no_cleared == 0 && r.data.no_posted != r.data.no_cleared){ // has 'ticked' or posted\n        color = 'blue';\n    }\n    \n    return String.format('<span style=\"color:{0}\">{1}</span>', color, Roo.util.Format.number(v*1,2)); \n}",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "colModel[]",
-                                            "dataIndex" : "balance"
-                                        },
-                                        {
-                                            "align" : "right",
-                                            "xtype" : "ColumnModel",
-                                            "header" : "Reconciled",
-                                            "width" : 100,
-                                            "$ renderer" : "function(v,x,r) { \n    \n    if(!v){\n        return '';\n    }\n    \n    if((r.data.no_records * 1 != r.data.no_posted * 1) || r.data.balance * 1 != v * 1){ // not match\n        \n        return '<span style=\"color:red;font-weight:bold\">' + Roo.util.Format.number(v*1,2); \n    }\n    \n    return String.format('<span style=\"color:black\">{0}</span>', Roo.util.Format.number(v*1,2)); \n        \n }",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "colModel[]",
-                                            "dataIndex" : "reconciled"
-                                        },
-                                        {
-                                            "align" : "right",
-                                            "xtype" : "ColumnModel",
-                                            "header" : "Post?",
-                                            "width" : 50,
-                                            "$ renderer" : "function(v,x,r) { \n    var state = v  ?  '-checked' : '';\n\n    return '<img class=\"x-grid-check-icon' + state + '\" src=\"' + Roo.BLANK_IMAGE_URL + '\"/>';\n }\n \n",
-                                            "$ xns" : "Roo.grid",
-                                            "* prop" : "colModel[]",
-                                            "dataIndex" : "is_reconciled"
-                                        }
-                                    ]
-                                }
-                            ]
-                        }
-                    ]
+                 "$ url" : "baseURL + '/Roo/bankaccnt.php'",
+                 "xtype" : "HttpProxy",
+                 "method" : "GET",
+                 "$ xns" : "Roo.data",
+                 "* prop" : "proxy"
+                },
+                {
+                 "id" : "id",
+                 "root" : "data",
+                 "xtype" : "JsonReader",
+                 "$ xns" : "Roo.data",
+                 "$ fields" : "[{\"name\":\"id\",\"type\":\"int\"},{\"name\":\"bankaccnt_name\",\"type\":\"string\"}]",
+                 "* prop" : "reader",
+                 "totalProperty" : "total"
+                }
+               ]
+              }
+             ]
+            },
+            {
+             "listeners" : {
+              "click" : "function (_self, e)\n{\n    var o = {params : {}}; \n    if (!_this.bankacct.getValue()) {\n        return false;\n    }\n    o.params._group = 'bankrec';\n    o.params._name = 'all';\n    o.params['bankaccntid:number'] =     _this.bankacct.getValue();\n    o.params['_sum_prev'] = 'amount';\n     o.url = baseURL + '/Roo/Metasql';\n     o.method = 'GET';\n     \n     var cols = {\n        'cleared' : 'Cleared',\n        'sortdate' : 'Date',\n        'doc_type' : 'Doctype',\n        'doc_number' : 'Doc number',\n        'notes' : 'Notes',\n        'doc_curr' : 'Currency',\n        'base_amount' : 'Base Amount',\n        'doc_exchrate' : 'Exchange Rate',\n        'amount' : 'Amount (Bank Currency)'\n    };\n     var n =0;\n     for (var i in cols) {\n        \n     \n        o.params['csvCols['+n+']'] =  i\n        o.params['csvTitles['+n+']'] =  cols[i];\n        n++;\n    }\n\n     \n     new Pman.Download(o);\n    Roo.MessageBox.alert(\"Notice\", \"Should be downloading now\");\n}"
+             },
+             "text" : "Download",
+             "xtype" : "Button",
+             "$ xns" : "Roo.Toolbar"
+            },
+            {
+             "xtype" : "Fill",
+             "$ xns" : "Roo.Toolbar"
+            }
+           ]
+          },
+          {
+           "xtype" : "ColumnModel",
+           "width" : 50,
+           "header" : "Cleared",
+           "$ renderer" : "function(v,x,r) { \n    if (r.data.bankrec_posted) {\n        return 'POSTED';\n    }\n\n    var state = v   ?  '-checked' : '';\n                                    \n    return '<img class=\"x-grid-check-icon' + state + '\" src=\"' + Roo.BLANK_IMAGE_URL + '\"/>';\n }",
+           "$ xns" : "Roo.grid",
+           "* prop" : "colModel[]",
+           "dataIndex" : "cleared"
+          },
+          {
+           "xtype" : "ColumnModel",
+           "width" : 75,
+           "header" : "Date",
+           "$ renderer" : "function(v) {   \n\n    return v ? Date.parseDate(v,'Y-m-d').format('d/M/Y') : '';\n }",
+           "$ xns" : "Roo.grid",
+           "* prop" : "colModel[]",
+           "dataIndex" : "sortdate"
+          },
+          {
+           "xtype" : "ColumnModel",
+           "width" : 50,
+           "header" : "Doctype",
+           "$ renderer" : "function(v) { return String.format('{0}', v); }",
+           "$ xns" : "Roo.grid",
+           "* prop" : "colModel[]",
+           "dataIndex" : "doc_type"
+          },
+          {
+           "xtype" : "ColumnModel",
+           "width" : 120,
+           "header" : "Doc Number",
+           "$ renderer" : "function(v) { return String.format('{0}', v); }",
+           "$ xns" : "Roo.grid",
+           "* prop" : "colModel[]",
+           "dataIndex" : "doc_number"
+          },
+          {
+           "xtype" : "ColumnModel",
+           "width" : 200,
+           "header" : "Notes",
+           "$ renderer" : "function(v) { return String.format('{0}', v); }",
+           "$ xns" : "Roo.grid",
+           "* prop" : "colModel[]",
+           "dataIndex" : "notes"
+          },
+          {
+           "xtype" : "ColumnModel",
+           "width" : 75,
+           "header" : "Currency",
+           "$ renderer" : "function(v) { return String.format('{0}', v); }",
+           "$ xns" : "Roo.grid",
+           "* prop" : "colModel[]",
+           "dataIndex" : "doc_curr"
+          },
+          {
+           "align" : "right",
+           "xtype" : "ColumnModel",
+           "header" : "Exchange Rate",
+           "width" : 75,
+           "$ renderer" : "function(v) { return String.format('{0}', v ? (v*1).toFixed(3) : ''); }",
+           "$ xns" : "Roo.grid",
+           "* prop" : "colModel[]",
+           "dataIndex" : "doc_exchrate"
+          },
+          {
+           "align" : "right",
+           "xtype" : "ColumnModel",
+           "header" : "Base Amount",
+           "width" : 120,
+           "$ renderer" : "function(v) { return String.format('{0}', Roo.util.Format.number(v*1,2)); }",
+           "$ xns" : "Roo.grid",
+           "* prop" : "colModel[]",
+           "dataIndex" : "base_amount"
+          },
+          {
+           "align" : "right",
+           "xtype" : "ColumnModel",
+           "header" : "Credit",
+           "width" : 120,
+           "$ renderer" : "function(v,x,r) { \n    if (r.data.doc_type == 'BF') {\n        return '';\n    }\n    return String.format('{0}', v > 0 ? Roo.util.Format.number(v*1,2)   : ''); }",
+           "$ xns" : "Roo.grid",
+           "* prop" : "colModel[]",
+           "dataIndex" : "amount",
+           "items" : [
+            {
+             "xtype" : "GridEditor",
+             "$ xns" : "Roo.grid",
+             "* prop" : "editor",
+             "items" : [
+              {
+               "xtype" : "NumberField",
+               "cls" : "align-right",
+               "decimalPrecision" : 2,
+               "$ xns" : "Roo.form",
+               "* prop" : "field"
+              }
+             ]
+            }
+           ]
+          },
+          {
+           "align" : "right",
+           "xtype" : "ColumnModel",
+           "header" : "Debit",
+           "width" : 120,
+           "$ renderer" : "function(v,x,r) { \n    if (r.data.doc_type == 'BF') {\n        return '';\n    }\n    return String.format('{0}', v < 0 ? Roo.util.Format.number(v*1,2): ''); }",
+           "$ xns" : "Roo.grid",
+           "* prop" : "colModel[]",
+           "dataIndex" : "amount",
+           "items" : [
+            {
+             "xtype" : "GridEditor",
+             "$ xns" : "Roo.grid",
+             "* prop" : "editor",
+             "items" : [
+              {
+               "xtype" : "NumberField",
+               "cls" : "align-right",
+               "decimalPrecision" : 2,
+               "$ xns" : "Roo.form",
+               "* prop" : "field"
+              }
+             ]
+            }
+           ]
+          },
+          {
+           "align" : "right",
+           "xtype" : "ColumnModel",
+           "header" : "Balance",
+           "width" : 120,
+           "$ renderer" : "\nfunction(v,x,r) { \n    if (r.data.doc_type == 'BF') {\n        return String.format('{0}', Roo.util.Format.number(v*1,2)); \n    }\n\n\n    //_this.total += (v*1)\n     return String.format('{0}', Roo.util.Format.number(v*1,2)); \n}",
+           "$ xns" : "Roo.grid",
+           "* prop" : "colModel[]",
+           "dataIndex" : "balance"
+          }
+         ]
+        }
+       ]
+      },
+      {
+       "listeners" : {
+        "|activate" : "function() {\n    _this.wpanel = this;\n    //if (_this.wgrid) {\n    //    _this.wgrid.footer.onClick('first');\n    //}\n}"
+       },
+       "region" : "west",
+       "fitToframe" : true,
+       "background" : true,
+       "title" : "Pick a Date",
+       "xtype" : "GridPanel",
+       "fitContainer" : true,
+       "$ xns" : "Roo",
+       "tableName" : "Groups",
+       "items" : [
+        {
+         "listeners" : {
+          "|render" : "function() \n{\n    _this.wgrid = this; \n    //_this.dialog = Pman.Dialog.FILL_IN\n    //if (_this.wpanel.active) {\n    //   this.footer.onClick('first');\n    //}\n}",
+          "cellclick" : "function (_self, rowIndex, columnIndex, e)\n{\n    var di = this.colModel.getDataIndex(columnIndex);\n\n    if (di != 'is_reconciled') {\n        return;\n    }\n     \n    var rec = this.ds.getAt(rowIndex);\n    \n    var voidit = function(){\n        new Pman.Request({\n            url : baseURL + '/Roo/Bankrec.php',\n            method :'POST',\n            params : {\n                _void : 1,\n                bankaccnt_id : _this.bankacct.getValue(),\n                sotrdate : rec.data.sortdate\n                \n            },\n            success : function() {\n                _this.wgrid.footer.onClick('refresh');\n            }\n        });\n    }\n    \n    var postit = function(){\n        new Pman.Request({\n            url : baseURL + '/Roo/Bankrec.php',\n            method :'POST',\n            params : {\n                _post : 1,\n                bankaccnt_id : _this.bankacct.getValue(),\n                sotrdate : rec.data.sortdate\n                \n            },\n            success : function() {\n                _this.wgrid.footer.onClick('refresh');\n            }\n        });\n    \n    }\n    \n    if(rec.data.is_reconciled == 1){\n        voidit();\n        return;\n    }\n    \n    postit();\n    return;\n    \n    \n    \n}",
+          "rowclick" : "function (_self, rowIndex, e)\n{\n    \n     _this.wgrid.lastSelectedRow = rowIndex;\n    \n}"
+         },
+         "autoExpandColumn" : "sortdate",
+         "xtype" : "Grid",
+         "loadMask" : true,
+         "$ xns" : "Roo.grid",
+         "* prop" : "grid",
+         "items" : [
+          {
+           "xtype" : "Toolbar",
+           "$ xns" : "Roo",
+           "* prop" : "toolbar",
+           "items" : [
+            {
+             "listeners" : {
+              "render" : "function (_self)\n{\n    _this.monthSel = _self;\n}",
+              "select" : "function (combo, date)\n{\n    _this.grid.ds.removeAll();\n    _this.wgrid.footer.onClick('first');\n}"
+             },
+             "format" : "M Y",
+             "xtype" : "MonthField",
+             "useIso" : true,
+             "allowBlank" : true,
+             "width" : 150,
+             "$ xns" : "Roo.form"
+            },
+            {
+             "listeners" : {
+              "click" : "function (_self, e)\n{\n    _this.monthSel.setValue('');\n    _this.grid.ds.removeAll();\r\n    _this.wgrid.footer.onClick('first');\r\n}"
+             },
+             "xtype" : "Button",
+             "cls" : "x-btn-icon",
+             "$ icon" : "rootURL + '/Pman/templates/images/edit-clear.gif'",
+             "$ xns" : "Roo.Toolbar"
+            },
+            {
+             "xtype" : "Fill",
+             "$ xns" : "Roo.Toolbar"
+            },
+            {
+             "text" : "Fix Data",
+             "xtype" : "Button",
+             "cls" : "x-btn-text-icon",
+             "$ icon" : "Roo.rootURL + 'images/default/tree/leaf.gif'",
+             "$ xns" : "Roo.Toolbar",
+             "items" : [
+              {
+               "xtype" : "Menu",
+               "$ xns" : "Roo.menu",
+               "* prop" : "menu",
+               "items" : [
+                {
+                 "listeners" : {
+                  "click" : "function (_self, e)\n{\n\n    Roo.MessageBox.confirm(\"Confirm\", \"Are you sure you want to fix all the historical data? It will recreate all the posted bankrec and delect all the unpost\",\n        function (res) {\n            if(res!='yes') {\n                return;\n            \n            }\n            new Pman.Request({\n                url : baseURL + '/Roo/Bankrec.php',\n                method :'POST',\n                params : {\n                    _fix : 1\n                },\n                success : function() {\n                    if(_this.wgrid){\n                        _this.wgrid.footer.onClick('refresh');\n                    }\n                    Roo.MessageBox.alert('Notice', 'FIXED');\n                }\n            });\n    });\n\n}"
+                 },
+                 "text" : "Fix historical data",
+                 "xtype" : "Item",
+                 "cls" : "x-btn-text-icon",
+                 "$ icon" : "Roo.rootURL + 'images/default/tree/leaf.gif'",
+                 "$ xns" : "Roo.menu"
+                },
+                {
+                 "listeners" : {
+                  "click" : "function (_self, e)\n{\n\n    Roo.MessageBox.confirm(\"Confirm\", \"Are you sure you want?\",\n        function (res) {\n            if(res!='yes') {\n                return;\n            \n            }\n            new Pman.Request({\n                url : baseURL + '/Roo/Bankrec.php',\n                method :'POST',\n                params : {\n                    _closedPeriod : 1\n                },\n                success : function() {\n                    if(_this.wgrid){\n                        _this.wgrid.footer.onClick('refresh');\n                    }\n                    Roo.MessageBox.alert('Notice', 'DONE');\n                }\n            });\n    });\n\n}"
+                 },
+                 "text" : "Fix Closed Periods",
+                 "xtype" : "Item",
+                 "cls" : "x-btn-text-icon",
+                 "$ icon" : "Roo.rootURL + 'images/default/tree/leaf.gif'",
+                 "$ xns" : "Roo.menu"
                 }
-            ]
+               ]
+              }
+             ]
+            }
+           ]
+          },
+          {
+           "listeners" : {
+            "selectionchange" : "function (_self)\n{\n    _this.grid.footer.onClick('first');\n}"
+           },
+           "xtype" : "RowSelectionModel",
+           "singleSelect" : true,
+           "$ xns" : "Roo.grid",
+           "* prop" : "sm"
+          },
+          {
+           "listeners" : {
+            "beforeload" : "function (_self, o)\n{\n\n    if (!_this.bankacct.getValue()) {\n        return false;\n    }\n    var dt = _this.monthSel.getValue();\n    \n    if(dt.length){\n        o.params['sortdate:text'] = typeof(dt) == 'string' ? dt : dt.format('Y-m-d');\n    }\n    o.params._group = 'bankrec';\n    o.params._name = 'bydate';\n    o.params['bankaccntid:number'] =  _this.bankacct.getValue();\n    \n\n    \n}",
+            "load" : "function (_self, records, options, res)\n{   \n    var sm = _this.wgrid.getSelectionModel();\n    \n    if(_this.wgrid.lastSelectedRow * 1 >0){\n        sm.selectRow(_this.wgrid.lastSelectedRow);\n        return;\n    }\n    \n    if (!sm.getSelections().length) {\n        sm.selectFirstRow();\n    }\n\n}"
+           },
+           "xtype" : "Store",
+           "remoteSort" : true,
+           "$ sortInfo" : "{ field : 'sotrdate', direction: 'ASC' }",
+           "$ xns" : "Roo.data",
+           "* prop" : "dataSource",
+           "items" : [
+            {
+             "$ url" : "baseURL + '/Roo/metasql.php'",
+             "xtype" : "HttpProxy",
+             "method" : "GET",
+             "timeout" : 900000,
+             "$ xns" : "Roo.data",
+             "* prop" : "proxy"
+            },
+            {
+             "id" : "id",
+             "root" : "data",
+             "xtype" : "JsonReader",
+             "$ fields" : "[\n    {\n        'name': 'sortdate',\n        'type': 'string'\n    }\n]",
+             "$ xns" : "Roo.data",
+             "* prop" : "reader",
+             "totalProperty" : "total"
+            }
+           ]
+          },
+          {
+           "pageSize" : 25,
+           "xtype" : "PagingToolbar",
+           "emptyMsg" : "No Date found",
+           "$ xns" : "Roo",
+           "displayMsg" : "Displaying Date{0} - {1} of {2}",
+           "displayInfo" : false,
+           "* prop" : "footer"
+          },
+          {
+           "xtype" : "ColumnModel",
+           "width" : 100,
+           "header" : "Date",
+           "$ renderer" : "function(v) {   \n\n    return v ? Date.parseDate(v,'Y-m-d').format('d/M/Y') : '';\n }",
+           "$ xns" : "Roo.grid",
+           "* prop" : "colModel[]",
+           "dataIndex" : "sortdate"
+          },
+          {
+           "align" : "right",
+           "xtype" : "ColumnModel",
+           "header" : "Closing Balance",
+           "width" : 120,
+           "$ renderer" : "function(v,x,r) { \n    \n    var color = 'red'; // has some not 'ticked'\n    \n    if(r.data.no_records - r.data.no_posted == 0){ // all posted on that date\n        color = 'black';\n    }\n    if(r.data.no_records - r.data.no_cleared == 0 && r.data.no_posted != r.data.no_cleared){ // has 'ticked' or posted\n        color = 'blue';\n    }\n    \n    return String.format('<span style=\"color:{0}\">{1}</span>', color, Roo.util.Format.number(v*1,2)); \n}",
+           "$ xns" : "Roo.grid",
+           "* prop" : "colModel[]",
+           "dataIndex" : "balance"
+          },
+          {
+           "align" : "right",
+           "xtype" : "ColumnModel",
+           "header" : "Reconciled",
+           "width" : 100,
+           "$ renderer" : "function(v,x,r) { \n    \n    if(!v){\n        return '';\n    }\n    \n    if((r.data.no_records * 1 != r.data.no_posted * 1) || r.data.balance * 1 != v * 1){ // not match\n        \n        return '<span style=\"color:red;font-weight:bold\">' + Roo.util.Format.number(v*1,2); \n    }\n    \n    return String.format('<span style=\"color:black\">{0}</span>', Roo.util.Format.number(v*1,2)); \n        \n }",
+           "$ xns" : "Roo.grid",
+           "* prop" : "colModel[]",
+           "dataIndex" : "reconciled"
+          },
+          {
+           "align" : "right",
+           "xtype" : "ColumnModel",
+           "header" : "Post?",
+           "width" : 50,
+           "$ renderer" : "function(v,x,r) { \n    var state = v  ?  '-checked' : '';\n\n    return '<img class=\"x-grid-check-icon' + state + '\" src=\"' + Roo.BLANK_IMAGE_URL + '\"/>';\n }\n \n",
+           "$ xns" : "Roo.grid",
+           "* prop" : "colModel[]",
+           "dataIndex" : "is_reconciled"
+          }
+         ]
         }
-    ]
+       ]
+      }
+     ]
+    }
+   ]
+  }
+ ]
 }
\ No newline at end of file
index c5e9122..11071e3 100644 (file)
 Roo.namespace('Pman.Tab');
 
 Pman.Tab.XtupleReconcile = new Roo.XComponent({
-    part     :  ["Xtuple", "Reconcile" ],
-    order    : '200-Pman.Tab.XtupleReconcile',
-    region   : 'center',
-    parent   : 'Pman.Tab.XtupleAccountsTab',
-    name     : "Pman.Tab.XtupleReconcile",
-    disabled : false, 
-    permname : '', 
-    _tree : function()
-    {
-        var _this = this;
-        var MODULE = this;
-        return {
-            layout : {
-                center : {
-                    '|xns' : 'Roo',
-                    xtype : 'LayoutRegion',
-                    xns : Roo
-                },
-                west : {
-                    '|xns' : 'Roo',
-                    xtype : 'LayoutRegion',
-                    width : 400,
-                    xns : Roo,
-                    split : true
-                },
-                '|xns' : 'Roo',
-                xtype : 'BorderLayout',
-                xns : Roo,
-                items : [
-                       {
-                        grid : {
-                            dataSource : {
-                                proxy : {
-                                    '|xns' : 'Roo.data',
-                                    url : baseURL + '/Roo/metasql.php',
-                                    xtype : 'HttpProxy',
-                                    method : 'GET',
-                                    xns : Roo.data
-                                },
-                                reader : {
-                                    '|xns' : 'Roo.data',
-                                    id : 'idx',
-                                    root : 'data',
-                                    xtype : 'JsonReader',
-                                    fields : [
-                                        {
-                                            'name': 'metasql_id',
-                                            'type': 'int'
-                                        },
-                                        {
-                                            'name': 'metasql_group',
-                                            'type': 'string'
-                                        },
-                                        {
-                                            'name': 'metasql_name',
-                                            'type': 'string'
-                                        },
-                                        {
-                                            'name': 'metasql_notes',
-                                            'type': 'string'
-                                        },
-                                        {
-                                            'name': 'metasql_query',
-                                            'type': 'string'
-                                        },
-                                        {
-                                            'name': 'metasql_lastuser',
-                                            'type': 'string'
-                                        },
-                                        {
-                                            'name': 'metasql_lastupdate',
-                                            'type': 'date',
-                                            'dateFormat': 'Y-m-d'
-                                        },
-                                        {
-                                            'name': 'metasql_grade',
-                                            'type': 'int'
-                                        }
-                                    ],
-                                    xns : Roo.data,
-                                    totalProperty : 'total'
-                                },
-                                '|xns' : 'Roo.data',
-                                xtype : 'Store',
-                                remoteSort : true,
-                                sortInfo : { field : 'metasql_group', direction: 'ASC' },
-                                xns : Roo.data,
-                                updateBalance : function() {
-                                     var bal = _this.bf;
-                                    this.each( function(rec) {
-                                        if (rec.data.doc_type != 'BF') {
-                                            bal += rec.data.amount *1;
-                                            rec.set('balance', bal);   
-                                        } else {
-                                            rec.set('balance', _this.bf);
-                                        }
-                                        
-                                        
-                                    });
-                                },
-                                listeners : {
-                                       beforeloadadd : function (_self, records, options, res)
-                                          {
-                                           //  _this.total = 0.0;
-                                          
-                                            
-                                          
-                                          
-                                                _this.total = 1 * res.raw.amount;
-                                                  _this.bf = 1 * res.raw.amount;
-                                              Roo.log("TOTAL:" + _this.total);
-                                          },
-                                       beforeload : function (_self, o)
-                                          {
-                                              var s = _this.wgrid.getSelectionModel().getSelected();
-                                              
-                                              if (!s) {
-                                                  return false;
-                                              }
-                                              o.params._group = 'bankrec';
-                                              o.params._name = 'all';
-                                              o.params['sortdate:text'] = s.data.sortdate;
-                                              o.params['bankaccntid:number'] =     _this.bankacct.getValue();
-                                          
-                                              o.params['_cals'] = 'amount'
-                                          },
-                                       load : function (_self, records, options)
-                                          {
-                                              
-                                              var bal = _this.bf;
-                                                var cleared = true;
-                                                var posted = true;
-                                              Roo.each(records, function(rec) {
-                                                  if (!rec.data.cleared) {
-                                                      cleared = false;
-                                          
-                                                  }
-                                                  if (!rec.data.bankrec_posted) {
-                                                      posted = false;
-                                                  }
-                                                  if (rec.data.doc_type != 'BF') {
-                                                      bal += rec.data.amount *1;
-                                                      rec.set('balance', bal);   
-                                                  } else {
-                                                      rec.set('balance', _this.bf);
-                                                  }
-                                                  
-                                                  
-                                              });
-                                              
-                                              var rec = this.reader.newRow({
-                                                  notes : 'Brought Forward',
-                                                  balance : _this.bf,
-                                                  doc_type : 'BF',
-                                                  cleared : cleared,
-                                                  bankrec_posted : posted
-                                              });
-                                              this.insert(0, [rec]);
-                                          }
-                                },
-                                items : [
+  part     :  ["Xtuple", "Reconcile" ],
+  order    : '200-Pman.Tab.XtupleReconcile',
+  region   : 'center',
+  parent   : 'Pman.Tab.XtupleAccountsTab',
+  name     : "Pman.Tab.XtupleReconcile",
+  disabled : false, 
+  permname : '', 
+  _tree : function()
+  {
+   var _this = this;
+   var MODULE = this;
+   return {
+   layout : {
+    center : {
+     '|xns' : 'Roo',
+     xtype : 'LayoutRegion',
+     xns : Roo
+    },
+    west : {
+     '|xns' : 'Roo',
+     xtype : 'LayoutRegion',
+     xns : Roo,
+     width : 400,
+     split : true
+    },
+    '|xns' : 'Roo',
+    xtype : 'BorderLayout',
+    xns : Roo,
+    items : [
+     {
+      grid : {
+       dataSource : {
+        proxy : {
+         '|xns' : 'Roo.data',
+         url : baseURL + '/Roo/metasql.php',
+         method : 'GET',
+         xtype : 'HttpProxy',
+         xns : Roo.data
+        },
+        reader : {
+         '|xns' : 'Roo.data',
+         id : 'idx',
+         root : 'data',
+         xtype : 'JsonReader',
+         fields : [
+             {
+                 'name': 'metasql_id',
+                 'type': 'int'
+             },
+             {
+                 'name': 'metasql_group',
+                 'type': 'string'
+             },
+             {
+                 'name': 'metasql_name',
+                 'type': 'string'
+             },
+             {
+                 'name': 'metasql_notes',
+                 'type': 'string'
+             },
+             {
+                 'name': 'metasql_query',
+                 'type': 'string'
+             },
+             {
+                 'name': 'metasql_lastuser',
+                 'type': 'string'
+             },
+             {
+                 'name': 'metasql_lastupdate',
+                 'type': 'date',
+                 'dateFormat': 'Y-m-d'
+             },
+             {
+                 'name': 'metasql_grade',
+                 'type': 'int'
+             }
+         ],
+         xns : Roo.data,
+         totalProperty : 'total'
+        },
+        '|xns' : 'Roo.data',
+        xtype : 'Store',
+        remoteSort : true,
+        sortInfo : { field : 'metasql_group', direction: 'ASC' },
+        xns : Roo.data,
+        updateBalance : function() {
+             var bal = _this.bf;
+            this.each( function(rec) {
+                if (rec.data.doc_type != 'BF') {
+                    bal += rec.data.amount *1;
+                    rec.set('balance', bal);   
+                } else {
+                    rec.set('balance', _this.bf);
+                }
+                
+                
+            });
+        },
+        listeners : {
+         beforeloadadd : function (_self, records, options, res)
+          {
+           //  _this.total = 0.0;
+          
+            
+          
+          
+                _this.total = 1 * res.raw.amount;
+                  _this.bf = 1 * res.raw.amount;
+              Roo.log("TOTAL:" + _this.total);
+          },
+         beforeload : function (_self, o)
+          {
+              var s = _this.wgrid.getSelectionModel().getSelected();
+              
+              if (!s) {
+                  return false;
+              }
+              o.params._group = 'bankrec';
+              o.params._name = 'all';
+              o.params['sortdate:text'] = s.data.sortdate;
+              o.params['bankaccntid:number'] =     _this.bankacct.getValue();
+          
+              o.params['_cals'] = 'amount'
+          },
+         load : function (_self, records, options)
+          {
+              
+              var bal = _this.bf;
+                var cleared = true;
+                var posted = true;
+              Roo.each(records, function(rec) {
+                  if (!rec.data.cleared) {
+                      cleared = false;
+          
+                  }
+                  if (!rec.data.bankrec_posted) {
+                      posted = false;
+                  }
+                  if (rec.data.doc_type != 'BF') {
+                      bal += rec.data.amount *1;
+                      rec.set('balance', bal);   
+                  } else {
+                      rec.set('balance', _this.bf);
+                  }
+                  
+                  
+              });
+              
+              var rec = this.reader.newRow({
+                  notes : 'Brought Forward',
+                  balance : _this.bf,
+                  doc_type : 'BF',
+                  cleared : cleared,
+                  bankrec_posted : posted
+              });
+              this.insert(0, [rec]);
+          }
+        },
+        items : [
 
-                                ]
+        ]
 
-                            },
-                            footer : {
-                                '|xns' : 'Roo',
-                                pageSize : 50,
-                                xtype : 'PagingToolbar',
-                                emptyMsg : "Nothing found",
-                                xns : Roo,
-                                displayMsg : "Displaying records {0} - {1} of {2}",
-                                displayInfo : true
-                            },
-                            toolbar : {
-                                '|xns' : 'Roo',
-                                xtype : 'Toolbar',
-                                xns : Roo,
-                                items : [
-                                       {
-                                        store : {
-                                            proxy : {
-                                                '|xns' : 'Roo.data',
-                                                url : baseURL + '/Roo/bankaccnt.php',
-                                                method : 'GET',
-                                                xtype : 'HttpProxy',
-                                                xns : Roo.data
-                                            },
-                                            reader : {
-                                                '|xns' : 'Roo.data',
-                                                id : 'id',
-                                                root : 'data',
-                                                xtype : 'JsonReader',
-                                                xns : Roo.data,
-                                                fields : [{"name":"id","type":"int"},{"name":"bankaccnt_name","type":"string"}],
-                                                totalProperty : 'total'
-                                            },
-                                            '|xns' : 'Roo.data',
-                                            xtype : 'Store',
-                                            remoteSort : true,
-                                            sortInfo : { direction : 'ASC', field: 'bankaccnt_bankname' },
-                                            xns : Roo.data,
-                                            listeners : {
-                                               beforeload : function (_self, o){
-                                                      o.params = o.params || {};
-                                                      // set more here
-                                                  }
-                                            },
-                                            items : [
+       },
+       footer : {
+        '|xns' : 'Roo',
+        pageSize : 50,
+        xtype : 'PagingToolbar',
+        emptyMsg : "Nothing found",
+        xns : Roo,
+        displayMsg : "Displaying records {0} - {1} of {2}",
+        displayInfo : true
+       },
+       toolbar : {
+        '|xns' : 'Roo',
+        xtype : 'Toolbar',
+        xns : Roo,
+        items : [
+         {
+          store : {
+           proxy : {
+            '|xns' : 'Roo.data',
+            url : baseURL + '/Roo/bankaccnt.php',
+            xtype : 'HttpProxy',
+            method : 'GET',
+            xns : Roo.data
+           },
+           reader : {
+            '|xns' : 'Roo.data',
+            id : 'id',
+            root : 'data',
+            xtype : 'JsonReader',
+            xns : Roo.data,
+            fields : [{"name":"id","type":"int"},{"name":"bankaccnt_name","type":"string"}],
+            totalProperty : 'total'
+           },
+           '|xns' : 'Roo.data',
+           xtype : 'Store',
+           remoteSort : true,
+           sortInfo : { direction : 'ASC', field: 'bankaccnt_bankname' },
+           xns : Roo.data,
+           listeners : {
+            beforeload : function (_self, o){
+                 o.params = o.params || {};
+                 // set more here
+             }
+           },
+           items : [
 
-                                            ]
+           ]
 
-                                        },
-                                        '|xns' : 'Roo.form',
-                                        listWidth : 400,
-                                        triggerAction : 'all',
-                                        fieldLabel : 'bankaccnt',
-                                        forceSelection : true,
-                                        selectOnFocus : true,
-                                        pageSize : 50,
-                                        displayField : 'bankaccnt_bankname',
-                                        emptyText : "Select bankaccnt",
-                                        hiddenName : 'bankaccnt_id',
-                                        minChars : 2,
-                                        valueField : 'bankaccnt_id',
-                                        xtype : 'ComboBox',
-                                        allowBlank : false,
-                                        typeAhead : true,
-                                        editable : false,
-                                        width : 300,
-                                        xns : Roo.form,
-                                        name : 'bankaccnt_bankname',
-                                        qtip : "Select bankaccnt",
-                                        queryParam : '',
-                                        tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{bankaccnt_bankname}</b> </div>',
-                                        loadingText : "Searching...",
-                                        listeners : {
-                                               render : function (_self)
-                                                  {
-                                                      _this.bankacct = _self;
-                                                  },
-                                               select : function (combo, record, index)
-                                                  
-                                                      var curr = record.data.bankaccnt_curr_id_curr_abbr;
-                                                      var col = _this.grid.colModel.config.length -1;
-                                                      
-                                                      _this.grid.colModel.setColumnHeader(col, 'Balance (' + curr +')');
-                                                      
-                                                      _this.grid.ds.removeAll();
-                                                      
-                                                      _this.wgrid.footer.onClick('first');
-                                                  }
-                                        },
-                                        items : [
+          },
+          '|xns' : 'Roo.form',
+          listWidth : 400,
+          triggerAction : 'all',
+          fieldLabel : 'bankaccnt',
+          forceSelection : true,
+          selectOnFocus : true,
+          pageSize : 50,
+          displayField : 'bankaccnt_name',
+          emptyText : "Select bankaccnt",
+          hiddenName : 'bankaccnt_id',
+          minChars : 2,
+          valueField : 'bankaccnt_id',
+          xtype : 'ComboBox',
+          allowBlank : false,
+          typeAhead : true,
+          editable : false,
+          width : 300,
+          xns : Roo.form,
+          name : 'bankaccnt_bankname',
+          qtip : "Select bankaccnt",
+          queryParam : '',
+          tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{bankaccnt_bankname}</b> </div>',
+          loadingText : "Searching...",
+          listeners : {
+           render : function (_self)
+            {
+                _this.bankacct = _self;
+            },
+           select : function (combo, record, index)
+            { 
+                var curr = record.data.bankaccnt_curr_id_curr_abbr;
+                var col = _this.grid.colModel.config.length -1;
+                
+                _this.grid.colModel.setColumnHeader(col, 'Balance (' + curr +')');
+                
+                _this.grid.ds.removeAll();
+                
+                _this.wgrid.footer.onClick('first');
+            }
+          },
+          items : [
 
-                                        ]
+          ]
 
-                                    },
-                                       {
-                                        '|xns' : 'Roo.Toolbar',
-                                        text : "Download",
-                                        xtype : 'Button',
-                                        xns : Roo.Toolbar,
-                                        listeners : {
-                                               click : function (_self, e)
-                                                  {
-                                                      var o = {params : {}}; 
-                                                      if (!_this.bankacct.getValue()) {
-                                                          return false;
-                                                      }
-                                                      o.params._group = 'bankrec';
-                                                      o.params._name = 'all';
-                                                      o.params['bankaccntid:number'] =     _this.bankacct.getValue();
-                                                      o.params['_sum_prev'] = 'amount';
-                                                       o.url = baseURL + '/Roo/Metasql';
-                                                       o.method = 'GET';
-                                                       
-                                                       var cols = {
-                                                          'cleared' : 'Cleared',
-                                                          'sortdate' : 'Date',
-                                                          'doc_type' : 'Doctype',
-                                                          'doc_number' : 'Doc number',
-                                                          'notes' : 'Notes',
-                                                          'doc_curr' : 'Currency',
-                                                          'base_amount' : 'Base Amount',
-                                                          'doc_exchrate' : 'Exchange Rate',
-                                                          'amount' : 'Amount (Bank Currency)'
-                                                      };
-                                                       var n =0;
-                                                       for (var i in cols) {
-                                                          
-                                                       
-                                                          o.params['csvCols['+n+']'] =  i
-                                                          o.params['csvTitles['+n+']'] =  cols[i];
-                                                          n++;
-                                                      }
-                                                  
-                                                       
-                                                       new Pman.Download(o);
-                                                      Roo.MessageBox.alert("Notice", "Should be downloading now");
-                                                  }
-                                        }
-                                    },
-                                       {
-                                        '|xns' : 'Roo.Toolbar',
-                                        xtype : 'Fill',
-                                        xns : Roo.Toolbar
-                                    }
-                                ]
+         },
+         {
+          '|xns' : 'Roo.Toolbar',
+          text : "Download",
+          xtype : 'Button',
+          xns : Roo.Toolbar,
+          listeners : {
+           click : function (_self, e)
+            {
+                var o = {params : {}}; 
+                if (!_this.bankacct.getValue()) {
+                    return false;
+                }
+                o.params._group = 'bankrec';
+                o.params._name = 'all';
+                o.params['bankaccntid:number'] =     _this.bankacct.getValue();
+                o.params['_sum_prev'] = 'amount';
+                 o.url = baseURL + '/Roo/Metasql';
+                 o.method = 'GET';
+                 
+                 var cols = {
+                    'cleared' : 'Cleared',
+                    'sortdate' : 'Date',
+                    'doc_type' : 'Doctype',
+                    'doc_number' : 'Doc number',
+                    'notes' : 'Notes',
+                    'doc_curr' : 'Currency',
+                    'base_amount' : 'Base Amount',
+                    'doc_exchrate' : 'Exchange Rate',
+                    'amount' : 'Amount (Bank Currency)'
+                };
+                 var n =0;
+                 for (var i in cols) {
+                    
+                 
+                    o.params['csvCols['+n+']'] =  i
+                    o.params['csvTitles['+n+']'] =  cols[i];
+                    n++;
+                }
+            
+                 
+                 new Pman.Download(o);
+                Roo.MessageBox.alert("Notice", "Should be downloading now");
+            }
+          }
+         },
+         {
+          '|xns' : 'Roo.Toolbar',
+          xtype : 'Fill',
+          xns : Roo.Toolbar
+         }
+        ]
 
-                            },
-                            '|xns' : 'Roo.grid',
-                            autoExpandColumn : 'notes',
-                            xtype : 'EditorGrid',
-                            loadMask : true,
-                            clicksToEdit : 1,
-                            xns : Roo.grid,
-                            colModel : [
-                                {
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'Cleared',
-                                       width : 50,
-                                       renderer : function(v,x,r) { 
-                                           if (r.data.bankrec_posted) {
-                                               return 'POSTED';
-                                           }
-                                       
-                                           var state = v   ?  '-checked' : '';
-                                                                           
-                                           return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
-                                        },
-                                       xns : Roo.grid,
-                                       dataIndex : 'cleared'
-                                   },
+       },
+       '|xns' : 'Roo.grid',
+       autoExpandColumn : 'notes',
+       xtype : 'EditorGrid',
+       loadMask : true,
+       clicksToEdit : 1,
+       xns : Roo.grid,
+       colModel : [
+         {
+          '|xns' : 'Roo.grid',
+          xtype : 'ColumnModel',
+          width : 50,
+          header : 'Cleared',
+          renderer : function(v,x,r) { 
+              if (r.data.bankrec_posted) {
+                  return 'POSTED';
+              }
+          
+              var state = v   ?  '-checked' : '';
+                                              
+              return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
+           },
+          xns : Roo.grid,
+          dataIndex : 'cleared'
+         },
 {
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'Date',
-                                       width : 75,
-                                       renderer : function(v) {   
-                                       
-                                           return v ? Date.parseDate(v,'Y-m-d').format('d/M/Y') : '';
-                                        },
-                                       xns : Roo.grid,
-                                       dataIndex : 'sortdate'
-                                   },
+          '|xns' : 'Roo.grid',
+          xtype : 'ColumnModel',
+          width : 75,
+          header : 'Date',
+          renderer : function(v) {   
+          
+              return v ? Date.parseDate(v,'Y-m-d').format('d/M/Y') : '';
+           },
+          xns : Roo.grid,
+          dataIndex : 'sortdate'
+         },
 {
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'Doctype',
-                                       width : 50,
-                                       renderer : function(v) { return String.format('{0}', v); },
-                                       xns : Roo.grid,
-                                       dataIndex : 'doc_type'
-                                   },
+          '|xns' : 'Roo.grid',
+          xtype : 'ColumnModel',
+          width : 50,
+          header : 'Doctype',
+          renderer : function(v) { return String.format('{0}', v); },
+          xns : Roo.grid,
+          dataIndex : 'doc_type'
+         },
 {
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'Doc Number',
-                                       width : 120,
-                                       renderer : function(v) { return String.format('{0}', v); },
-                                       xns : Roo.grid,
-                                       dataIndex : 'doc_number'
-                                   },
+          '|xns' : 'Roo.grid',
+          xtype : 'ColumnModel',
+          width : 120,
+          header : 'Doc Number',
+          renderer : function(v) { return String.format('{0}', v); },
+          xns : Roo.grid,
+          dataIndex : 'doc_number'
+         },
 {
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'Notes',
-                                       width : 200,
-                                       renderer : function(v) { return String.format('{0}', v); },
-                                       xns : Roo.grid,
-                                       dataIndex : 'notes'
-                                   },
+          '|xns' : 'Roo.grid',
+          xtype : 'ColumnModel',
+          width : 200,
+          header : 'Notes',
+          renderer : function(v) { return String.format('{0}', v); },
+          xns : Roo.grid,
+          dataIndex : 'notes'
+         },
 {
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'Currency',
-                                       width : 75,
-                                       renderer : function(v) { return String.format('{0}', v); },
-                                       xns : Roo.grid,
-                                       dataIndex : 'doc_curr'
-                                   },
+          '|xns' : 'Roo.grid',
+          xtype : 'ColumnModel',
+          width : 75,
+          header : 'Currency',
+          renderer : function(v) { return String.format('{0}', v); },
+          xns : Roo.grid,
+          dataIndex : 'doc_curr'
+         },
 {
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       xtype : 'ColumnModel',
-                                       header : 'Exchange Rate',
-                                       width : 75,
-                                       renderer : function(v) { return String.format('{0}', v ? (v*1).toFixed(3) : ''); },
-                                       xns : Roo.grid,
-                                       dataIndex : 'doc_exchrate'
-                                   },
+          '|xns' : 'Roo.grid',
+          align : 'right',
+          xtype : 'ColumnModel',
+          header : 'Exchange Rate',
+          width : 75,
+          renderer : function(v) { return String.format('{0}', v ? (v*1).toFixed(3) : ''); },
+          xns : Roo.grid,
+          dataIndex : 'doc_exchrate'
+         },
 {
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       xtype : 'ColumnModel',
-                                       header : 'Base Amount',
-                                       width : 120,
-                                       renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v*1,2)); },
-                                       xns : Roo.grid,
-                                       dataIndex : 'base_amount'
-                                   },
+          '|xns' : 'Roo.grid',
+          align : 'right',
+          xtype : 'ColumnModel',
+          header : 'Base Amount',
+          width : 120,
+          renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v*1,2)); },
+          xns : Roo.grid,
+          dataIndex : 'base_amount'
+         },
 {
-                                       editor : {
-                                           field : {
-                                               '|xns' : 'Roo.form',
-                                               xtype : 'NumberField',
-                                               cls : 'align-right',
-                                               decimalPrecision : 2,
-                                               xns : Roo.form
-                                           },
-                                           '|xns' : 'Roo.grid',
-                                           xtype : 'GridEditor',
-                                           xns : Roo.grid,
-                                           items : [
+          editor : {
+           field : {
+            '|xns' : 'Roo.form',
+            xtype : 'NumberField',
+            cls : 'align-right',
+            decimalPrecision : 2,
+            xns : Roo.form
+           },
+           '|xns' : 'Roo.grid',
+           xtype : 'GridEditor',
+           xns : Roo.grid,
+           items : [
 
-                                           ]
+           ]
 
-                                       },
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       xtype : 'ColumnModel',
-                                       header : 'Credit',
-                                       width : 120,
-                                       renderer : function(v,x,r) { 
-                                           if (r.data.doc_type == 'BF') {
-                                               return '';
-                                           }
-                                           return String.format('{0}', v > 0 ? Roo.util.Format.number(v*1,2)   : ''); },
-                                       xns : Roo.grid,
-                                       dataIndex : 'amount',
-                                       items : [
+          },
+          '|xns' : 'Roo.grid',
+          align : 'right',
+          xtype : 'ColumnModel',
+          header : 'Credit',
+          width : 120,
+          renderer : function(v,x,r) { 
+              if (r.data.doc_type == 'BF') {
+                  return '';
+              }
+              return String.format('{0}', v > 0 ? Roo.util.Format.number(v*1,2)   : ''); },
+          xns : Roo.grid,
+          dataIndex : 'amount',
+          items : [
 
-                                       ]
+          ]
 
-                                   },
+         },
 {
-                                       editor : {
-                                           field : {
-                                               '|xns' : 'Roo.form',
-                                               xtype : 'NumberField',
-                                               cls : 'align-right',
-                                               decimalPrecision : 2,
-                                               xns : Roo.form
-                                           },
-                                           '|xns' : 'Roo.grid',
-                                           xtype : 'GridEditor',
-                                           xns : Roo.grid,
-                                           items : [
+          editor : {
+           field : {
+            '|xns' : 'Roo.form',
+            xtype : 'NumberField',
+            cls : 'align-right',
+            decimalPrecision : 2,
+            xns : Roo.form
+           },
+           '|xns' : 'Roo.grid',
+           xtype : 'GridEditor',
+           xns : Roo.grid,
+           items : [
 
-                                           ]
+           ]
 
-                                       },
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       xtype : 'ColumnModel',
-                                       header : 'Debit',
-                                       width : 120,
-                                       renderer : function(v,x,r) { 
-                                           if (r.data.doc_type == 'BF') {
-                                               return '';
-                                           }
-                                           return String.format('{0}', v < 0 ? Roo.util.Format.number(v*1,2): ''); },
-                                       xns : Roo.grid,
-                                       dataIndex : 'amount',
-                                       items : [
+          },
+          '|xns' : 'Roo.grid',
+          align : 'right',
+          xtype : 'ColumnModel',
+          header : 'Debit',
+          width : 120,
+          renderer : function(v,x,r) { 
+              if (r.data.doc_type == 'BF') {
+                  return '';
+              }
+              return String.format('{0}', v < 0 ? Roo.util.Format.number(v*1,2): ''); },
+          xns : Roo.grid,
+          dataIndex : 'amount',
+          items : [
 
-                                       ]
+          ]
 
-                                   },
+         },
 {
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       xtype : 'ColumnModel',
-                                       header : 'Balance',
-                                       width : 120,
-                                       renderer : function(v,x,r) { 
-                                           if (r.data.doc_type == 'BF') {
-                                               return String.format('{0}', Roo.util.Format.number(v*1,2)); 
-                                           }
-                                       
-                                       
-                                           //_this.total += (v*1)
-                                            return String.format('{0}', Roo.util.Format.number(v*1,2)); 
-                                       },
-                                       xns : Roo.grid,
-                                       dataIndex : 'balance'
-                                   }
-                            ],
-                            listeners : {
-                               beforeedit : function (e)
-                                  {
-                                      //    Roo.log(e);
-                                         var ch =  _this.grid.colModel.config[e.column].header;
-                                         var val = e.value *1;
-                                    // Roo.log(ch);
-                                    // Roo.log(val);
-                                  
-                                         if (val > 0.0 && ch == 'Debit') {
-                                              e.cancel = true;
-                                              return;
-                                          }
-                                         if (val < 0.0 && ch == 'Credit') {
-                                              e.cancel = true;
-                                              return;
-                                          }
-                                          if (e.record.data.cleared || e.record.data.bankrec_posted) {
-                                              e.cancel = true;
-                                              return;
-                                          }
-                                          
-                                          // allow start editing..
-                                  },
-                               render : function() 
-                                  {
-                                      _this.grid = this; 
-                                      //_this.dialog = Pman.Dialog.FILL_IN
-                                      if (_this.panel.active) {
-                                         this.footer.onClick('first');
-                                      }
-                                  },
-                               cellclick : function (_self, rowIndex, columnIndex, e)
-                                  {
-                                      var clear = function(ar) 
-                                      {
-                                          var ar_in = ar;
-                                          if (ar === true) {
-                                              ar = [];
-                                              
-                                              _this.grid.ds.each(function(rec) {
-                                                  if (rec.data.doc_type == 'BF') {
-                                                      return;
-                                                  }
-                                                  ar.push(rec);
-                                              });
-                                          }
-                                          var sortdate = false;
-                                          var data = [];
-                                          Roo.each(ar, function(rec) {
-                                              if (rec.data.cleared || rec.data.bankrec_posted) {
-                                                  return;
-                                              }
-                                              if(!sortdate){
-                                                  sortdate = rec.data.sortdate;
-                                              }
-                                              data.push({
-                                                   id : rec.data.id,
-                                                  altid : rec.data.altid,
-                                                  curr_rate : rec.data.doc_exchrate,
-                                                  amount : rec.data.amount
-                                                  
-                                              });
-                                          });
-                                         new Pman.Request({
-                                          url : baseURL + '/Roo/bankrecitem',
-                                              method : 'POST',
-                                              mask : 'Clearing',
-                                              params : {
-                                                  bankaccnt_id : _this.bankacct.getValue(),
-                                                  sortdate : sortdate,
-                                                  set_clear : Roo.encode(data)
-                                              },
-                                              success : function() {
-                                                  Roo.each(ar, function(rec) {
-                                                      rec.set('cleared', true);
-                                                  });
-                                                  if (ar_in === true) {
-                                                      _this.grid.ds.getAt(0).set('cleared', true);
-                                                  }
-                                                  _this.wgrid.footer.onClick('refresh');
-                                              }
-                                          });
-                                      }
-                                      
-                                      
-                                      var unclear = function(ar)
-                                      {
-                                          var ar_in = ar;
-                                          if (ar === true) {
-                                              ar = [];
-                                              
-                                              _this.grid.ds.each(function(rec) {
-                                                  if (rec.data.doc_type == 'BF') {
-                                                      return;
-                                                  }
-                                                  ar.push(rec);
-                                              });
-                                          }
-                                          var sortdate = false;
-                                          var data = [];
-                                          Roo.each(ar, function(rec) {
-                                              if (!rec.data.cleared  || rec.data.bankrec_posted) {
-                                                  return;
-                                              }
-                                              if(!sortdate){
-                                                  sortdate = rec.data.sortdate;
-                                              }
-                                              data.push({
-                                                  id : rec.data.id,
-                                                  altid : rec.data.altid                
-                                              });
-                                          });
-                                  
-                                          new Pman.Request({
-                                              url : baseURL + '/Roo/bankrecitem',
-                                              method : 'POST',
-                                              mask : 'Clearing',
-                                              params : {
-                                                  bankaccnt_id : _this.bankacct.getValue(),
-                                                  sortdate : sortdate,
-                                                  remove_clear :Roo.encode(data)
-                                                  
-                                              },
-                                              success : function() {
-                                                  Roo.each(ar, function(rec) {
-                                                      rec.set('cleared', false);
-                                                  });
-                                                 if (ar_in === true) {
-                                                      _this.grid.ds.getAt(0).set('cleared', false);
-                                                  }  
-                                                  _this.wgrid.footer.onClick('refresh');
-                                              }
-                                          });
-                                       
-                                        
-                                      };
-                                      
-                                      
-                                      
-                                      var di = this.colModel.config[columnIndex].dataIndex;
-                                      if (di != 'cleared') {
-                                          return;
-                                      }
-                                      var  rec = this.ds.getAt(rowIndex);
-                                      if (rec.data.doc_type == 'BF') {
-                                      
-                                          if (rec.data.cleared) {
-                                              unclear(true);
-                                          
-                                          } else {
-                                              clear(true);
-                                          }
-                                      
-                                          return;
-                                      }
-                                      
-                                          
-                                          
-                                      if (rec.data.cleared) {
-                                      
-                                          unclear([rec]);
-                                          return;
-                                          
-                                      }
-                                      
-                                      clear([rec]);
-                                      
-                                      
-                                       
-                                           
-                                    
-                                  },
-                               afteredit : function (e)
-                                  {
-                                  
-                                      if (e.cancel) {
-                                          return;
-                                      }
-                                         var ch =  _this.grid.colModel.config[e.column].header;
-                                             var val = e.originalValue *1;
-                                        // Roo.log(ch);
-                                        // Roo.log(val);
-                                  
-                                         if (val > 0.0 && ch == 'Debit') {
-                                              e.cancel = true;
-                                              return;
-                                          }
-                                         if (val < 0.0 && ch == 'Credit') {
-                                              e.cancel = true;
-                                              return;
-                                          }
-                                          if (e.record.data.cleared || e.record.data.bankrec_posted) {
-                                              e.cancel = true;
-                                              return;
-                                          }
-                                          if (val > 0.0 && e.value < 0.0) {
-                                          Roo.log("CANCEL");  
-                                              e.record.set('amount', e.originalValue);
-                                              e.cancel = true;
-                                              return;
-                                          }
-                                          if (val < 0.0 && e.value > 0.0) {
-                                          Roo.log("CANCEL");
-                                              e.record.set('amount', e.originalValue);
-                                              e.cancel = true;
-                                              return;
-                                          
-                                          if (e.originalValue*1 == e.value*1) {
-                                              return;
-                                          }
-                                            
-                                          e.record.set('doc_exchrate', Math.abs(e.value  * 1)  / Math.abs(e.record.data.base_amount * 1));
-                                          Roo.log(e.record);
-                                          
-                                          _this.grid.ds.updateBalance();
-                                          // send it down the line...
-                                          new Pman.Request({
-                                              method : 'POST',
-                                              url : baseURL + '/Roo/bankrecitem',
-                                              mask : 'Saving',
-                                              params : {
-                                                  bankaccnt_id : _this.bankacct.getValue(),
-                                                  set_amount : Math.abs(e.value),
-                                                  sortdate : e.record.data.sortdate,
-                                                  source_id : e.record.data.id,
-                                                  altid : e.record.data.altid
-                                              }
-                                          
-                                          });
-                                          
-                                           
-                                          
-                                          
-                                  }
-                            },
-                            items : [
+          '|xns' : 'Roo.grid',
+          align : 'right',
+          xtype : 'ColumnModel',
+          header : 'Balance',
+          width : 120,
+          renderer : function(v,x,r) { 
+              if (r.data.doc_type == 'BF') {
+                  return String.format('{0}', Roo.util.Format.number(v*1,2)); 
+              }
+          
+          
+              //_this.total += (v*1)
+               return String.format('{0}', Roo.util.Format.number(v*1,2)); 
+          },
+          xns : Roo.grid,
+          dataIndex : 'balance'
+         }
+       ],
+       listeners : {
+        beforeedit : function (e)
+         {
+             //    Roo.log(e);
+                var ch =  _this.grid.colModel.config[e.column].header;
+                var val = e.value *1;
+           // Roo.log(ch);
+           // Roo.log(val);
+         
+                if (val > 0.0 && ch == 'Debit') {
+                     e.cancel = true;
+                     return;
+                 }
+                if (val < 0.0 && ch == 'Credit') {
+                     e.cancel = true;
+                     return;
+                 }
+                 if (e.record.data.cleared || e.record.data.bankrec_posted) {
+                     e.cancel = true;
+                     return;
+                 }
+                 
+                 // allow start editing..
+         },
+        cellclick : function (_self, rowIndex, columnIndex, e)
+         {
+             var clear = function(ar) 
+             {
+                 var ar_in = ar;
+                 if (ar === true) {
+                     ar = [];
+                     
+                     _this.grid.ds.each(function(rec) {
+                         if (rec.data.doc_type == 'BF') {
+                             return;
+                         }
+                         ar.push(rec);
+                     });
+                 }
+                 var sortdate = false;
+                 var data = [];
+                 Roo.each(ar, function(rec) {
+                     if (rec.data.cleared || rec.data.bankrec_posted) {
+                         return;
+                     }
+                     if(!sortdate){
+                         sortdate = rec.data.sortdate;
+                     }
+                     data.push({
+                          id : rec.data.id,
+                         altid : rec.data.altid,
+                         curr_rate : rec.data.doc_exchrate,
+                         amount : rec.data.amount
+                         
+                     });
+                 });
+                new Pman.Request({
+                 url : baseURL + '/Roo/bankrecitem',
+                     method : 'POST',
+                     mask : 'Clearing',
+                     params : {
+                         bankaccnt_id : _this.bankacct.getValue(),
+                         sortdate : sortdate,
+                         set_clear : Roo.encode(data)
+                     },
+                     success : function() {
+                         Roo.each(ar, function(rec) {
+                             rec.set('cleared', true);
+                         });
+                         if (ar_in === true) {
+                             _this.grid.ds.getAt(0).set('cleared', true);
+                         }
+                         _this.wgrid.footer.onClick('refresh');
+                     }
+                 });
+             }
+             
+             
+             var unclear = function(ar)
+             {
+                 var ar_in = ar;
+                 if (ar === true) {
+                     ar = [];
+                     
+                     _this.grid.ds.each(function(rec) {
+                         if (rec.data.doc_type == 'BF') {
+                             return;
+                         }
+                         ar.push(rec);
+                     });
+                 }
+                 var sortdate = false;
+                 var data = [];
+                 Roo.each(ar, function(rec) {
+                     if (!rec.data.cleared  || rec.data.bankrec_posted) {
+                         return;
+                     }
+                     if(!sortdate){
+                         sortdate = rec.data.sortdate;
+                     }
+                     data.push({
+                         id : rec.data.id,
+                         altid : rec.data.altid                
+                     });
+                 });
+         
+                 new Pman.Request({
+                     url : baseURL + '/Roo/bankrecitem',
+                     method : 'POST',
+                     mask : 'Clearing',
+                     params : {
+                         bankaccnt_id : _this.bankacct.getValue(),
+                         sortdate : sortdate,
+                         remove_clear :Roo.encode(data)
+                         
+                     },
+                     success : function() {
+                         Roo.each(ar, function(rec) {
+                             rec.set('cleared', false);
+                         });
+                        if (ar_in === true) {
+                             _this.grid.ds.getAt(0).set('cleared', false);
+                         }  
+                         _this.wgrid.footer.onClick('refresh');
+                     }
+                 });
+              
+               
+             };
+             
+             
+             
+             var di = this.colModel.config[columnIndex].dataIndex;
+             if (di != 'cleared') {
+                 return;
+             }
+             var  rec = this.ds.getAt(rowIndex);
+             if (rec.data.doc_type == 'BF') {
+             
+                 if (rec.data.cleared) {
+                     unclear(true);
+                 
+                 } else {
+                     clear(true);
+                 }
+             
+                 return;
+             }
+             
+                 
+                 
+             if (rec.data.cleared) {
+             
+                 unclear([rec]);
+                 return;
+                 
+             }
+             
+             clear([rec]);
+             
+             
+              
+                  
+           
+         },
+        render : function() 
+         {
+             _this.grid = this; 
+             //_this.dialog = Pman.Dialog.FILL_IN
+             if (_this.panel.active) {
+                this.footer.onClick('first');
+             }
+         },
+        afteredit : function (e)
+         {
+         
+             if (e.cancel) {
+                 return;
+             }
+                var ch =  _this.grid.colModel.config[e.column].header;
+                    var val = e.originalValue *1;
+               // Roo.log(ch);
+               // Roo.log(val);
+         
+                if (val > 0.0 && ch == 'Debit') {
+                     e.cancel = true;
+                     return;
+                 }
+                if (val < 0.0 && ch == 'Credit') {
+                     e.cancel = true;
+                     return;
+                 }
+                 if (e.record.data.cleared || e.record.data.bankrec_posted) {
+                     e.cancel = true;
+                     return;
+                 }
+                 if (val > 0.0 && e.value < 0.0) {
+                 Roo.log("CANCEL");  
+                     e.record.set('amount', e.originalValue);
+                     e.cancel = true;
+                     return;
+                 }
+                 if (val < 0.0 && e.value > 0.0) {
+                 Roo.log("CANCEL");
+                     e.record.set('amount', e.originalValue);
+                     e.cancel = true;
+                     return;
+                 } 
+                 if (e.originalValue*1 == e.value*1) {
+                     return;
+                 }
+                   
+                 e.record.set('doc_exchrate', Math.abs(e.value  * 1)  / Math.abs(e.record.data.base_amount * 1));
+                 Roo.log(e.record);
+                 
+                 _this.grid.ds.updateBalance();
+                 // send it down the line...
+                 new Pman.Request({
+                     method : 'POST',
+                     url : baseURL + '/Roo/bankrecitem',
+                     mask : 'Saving',
+                     params : {
+                         bankaccnt_id : _this.bankacct.getValue(),
+                         set_amount : Math.abs(e.value),
+                         sortdate : e.record.data.sortdate,
+                         source_id : e.record.data.id,
+                         altid : e.record.data.altid
+                     }
+                 
+                 });
+                 
+                  
+                 
+                 
+         }
+       },
+       items : [
 
-                            ]
+       ]
 
-                        },
-                        '|xns' : 'Roo',
-                        fitToframe : true,
-                        background : true,
-                        region : 'center',
-                        title : "Bank Reconcile",
-                        xtype : 'GridPanel',
-                        fitContainer : true,
-                        xns : Roo,
-                        tableName : 'metasql',
-                        listeners : {
-                               activate : function() {
-                                      _this.panel = this;
-                                      if (_this.grid) {
-                                          _this.grid.footer.onClick('first');
-                                      }
-                                  }
-                        },
-                        items : [
+      },
+      '|xns' : 'Roo',
+      region : 'center',
+      fitToframe : true,
+      background : true,
+      title : "Bank Reconcile",
+      xtype : 'GridPanel',
+      fitContainer : true,
+      xns : Roo,
+      tableName : 'metasql',
+      listeners : {
+       activate : function() {
+            _this.panel = this;
+            if (_this.grid) {
+                _this.grid.footer.onClick('first');
+            }
+        }
+      },
+      items : [
 
-                        ]
+      ]
 
-                    },
-                       {
-                        grid : {
-                            toolbar : {
-                                '|xns' : 'Roo',
-                                xtype : 'Toolbar',
-                                xns : Roo,
-                                items : [
-                                       {
-                                        '|xns' : 'Roo.form',
-                                        format : 'M Y',
-                                        useIso : true,
-                                        xtype : 'MonthField',
-                                        allowBlank : true,
-                                        width : 150,
-                                        xns : Roo.form,
-                                        listeners : {
-                                               render : function (_self)
-                                                  {
-                                                      _this.monthSel = _self;
-                                                  },
-                                               select : function (combo, date)
-                                                  {
-                                                      _this.grid.ds.removeAll();
-                                                      _this.wgrid.footer.onClick('first');
-                                                  }
-                                        }
-                                    },
-                                       {
-                                        '|xns' : 'Roo.Toolbar',
-                                        xtype : 'Button',
-                                        cls : 'x-btn-icon',
-                                        icon : rootURL + '/Pman/templates/images/edit-clear.gif',
-                                        xns : Roo.Toolbar,
-                                        listeners : {
-                                               click : function (_self, e)
-                                                  {
-                                                      _this.monthSel.setValue('');
-                                                      _this.grid.ds.removeAll();\r
-                                                      _this.wgrid.footer.onClick('first');\r
-                                                  }
-                                        }
-                                    },
-                                       {
-                                        '|xns' : 'Roo.Toolbar',
-                                        xtype : 'Fill',
-                                        xns : Roo.Toolbar
-                                    },
-                                       {
-                                        menu : {
-                                            '|xns' : 'Roo.menu',
-                                            xtype : 'Menu',
-                                            xns : Roo.menu,
-                                            items : [
-                                               {
-                                                    '|xns' : 'Roo.menu',
-                                                    text : "Fix historical data",
-                                                    xtype : 'Item',
-                                                    cls : 'x-btn-text-icon',
-                                                    icon : Roo.rootURL + 'images/default/tree/leaf.gif',
-                                                    xns : Roo.menu,
-                                                    listeners : {
-                                                       click : function (_self, e)
-                                                          {
-                                                          
-                                                              Roo.MessageBox.confirm("Confirm", "Are you sure you want to fix all the historical data? It will recreate all the posted bankrec and delect all the unpost",
-                                                                  function (res) {
-                                                                      if(res!='yes') {
-                                                                          return;
-                                                                      
-                                                                      }
-                                                                      new Pman.Request({
-                                                                          url : baseURL + '/Roo/Bankrec.php',
-                                                                          method :'POST',
-                                                                          params : {
-                                                                              _fix : 1
-                                                                          },
-                                                                          success : function() {
-                                                                              if(_this.wgrid){
-                                                                                  _this.wgrid.footer.onClick('refresh');
-                                                                              }
-                                                                              Roo.MessageBox.alert('Notice', 'FIXED');
-                                                                          }
-                                                                      });
-                                                              });
-                                                          
-                                                          }
-                                                    }
-                                                },
-                                               {
-                                                    '|xns' : 'Roo.menu',
-                                                    text : "Fix Closed Periods",
-                                                    xtype : 'Item',
-                                                    cls : 'x-btn-text-icon',
-                                                    icon : Roo.rootURL + 'images/default/tree/leaf.gif',
-                                                    xns : Roo.menu,
-                                                    listeners : {
-                                                       click : function (_self, e)
-                                                          {
-                                                          
-                                                              Roo.MessageBox.confirm("Confirm", "Are you sure you want?",
-                                                                  function (res) {
-                                                                      if(res!='yes') {
-                                                                          return;
-                                                                      
-                                                                      }
-                                                                      new Pman.Request({
-                                                                          url : baseURL + '/Roo/Bankrec.php',
-                                                                          method :'POST',
-                                                                          params : {
-                                                                              _closedPeriod : 1
-                                                                          },
-                                                                          success : function() {
-                                                                              if(_this.wgrid){
-                                                                                  _this.wgrid.footer.onClick('refresh');
-                                                                              }
-                                                                              Roo.MessageBox.alert('Notice', 'DONE');
-                                                                          }
-                                                                      });
-                                                              });
-                                                          
-                                                          }
-                                                    }
-                                                }
-                                            ]
+     },
+     {
+      grid : {
+       toolbar : {
+        '|xns' : 'Roo',
+        xtype : 'Toolbar',
+        xns : Roo,
+        items : [
+         {
+          '|xns' : 'Roo.form',
+          format : 'M Y',
+          xtype : 'MonthField',
+          useIso : true,
+          allowBlank : true,
+          width : 150,
+          xns : Roo.form,
+          listeners : {
+           render : function (_self)
+            {
+                _this.monthSel = _self;
+            },
+           select : function (combo, date)
+            {
+                _this.grid.ds.removeAll();
+                _this.wgrid.footer.onClick('first');
+            }
+          }
+         },
+         {
+          '|xns' : 'Roo.Toolbar',
+          xtype : 'Button',
+          cls : 'x-btn-icon',
+          icon : rootURL + '/Pman/templates/images/edit-clear.gif',
+          xns : Roo.Toolbar,
+          listeners : {
+           click : function (_self, e)
+            {
+                _this.monthSel.setValue('');
+                _this.grid.ds.removeAll();\r
+                _this.wgrid.footer.onClick('first');\r
+            }
+          }
+         },
+         {
+          '|xns' : 'Roo.Toolbar',
+          xtype : 'Fill',
+          xns : Roo.Toolbar
+         },
+         {
+          menu : {
+           '|xns' : 'Roo.menu',
+           xtype : 'Menu',
+           xns : Roo.menu,
+           items : [
+            {
+             '|xns' : 'Roo.menu',
+             text : "Fix historical data",
+             xtype : 'Item',
+             cls : 'x-btn-text-icon',
+             icon : Roo.rootURL + 'images/default/tree/leaf.gif',
+             xns : Roo.menu,
+             listeners : {
+              click : function (_self, e)
+               {
+               
+                   Roo.MessageBox.confirm("Confirm", "Are you sure you want to fix all the historical data? It will recreate all the posted bankrec and delect all the unpost",
+                       function (res) {
+                           if(res!='yes') {
+                               return;
+                           
+                           }
+                           new Pman.Request({
+                               url : baseURL + '/Roo/Bankrec.php',
+                               method :'POST',
+                               params : {
+                                   _fix : 1
+                               },
+                               success : function() {
+                                   if(_this.wgrid){
+                                       _this.wgrid.footer.onClick('refresh');
+                                   }
+                                   Roo.MessageBox.alert('Notice', 'FIXED');
+                               }
+                           });
+                   });
+               
+               }
+             }
+            },
+            {
+             '|xns' : 'Roo.menu',
+             text : "Fix Closed Periods",
+             xtype : 'Item',
+             cls : 'x-btn-text-icon',
+             icon : Roo.rootURL + 'images/default/tree/leaf.gif',
+             xns : Roo.menu,
+             listeners : {
+              click : function (_self, e)
+               {
+               
+                   Roo.MessageBox.confirm("Confirm", "Are you sure you want?",
+                       function (res) {
+                           if(res!='yes') {
+                               return;
+                           
+                           }
+                           new Pman.Request({
+                               url : baseURL + '/Roo/Bankrec.php',
+                               method :'POST',
+                               params : {
+                                   _closedPeriod : 1
+                               },
+                               success : function() {
+                                   if(_this.wgrid){
+                                       _this.wgrid.footer.onClick('refresh');
+                                   }
+                                   Roo.MessageBox.alert('Notice', 'DONE');
+                               }
+                           });
+                   });
+               
+               }
+             }
+            }
+           ]
 
-                                        },
-                                        '|xns' : 'Roo.Toolbar',
-                                        text : "Fix Data",
-                                        xtype : 'Button',
-                                        cls : 'x-btn-text-icon',
-                                        icon : Roo.rootURL + 'images/default/tree/leaf.gif',
-                                        xns : Roo.Toolbar,
-                                        items : [
+          },
+          '|xns' : 'Roo.Toolbar',
+          text : "Fix Data",
+          xtype : 'Button',
+          cls : 'x-btn-text-icon',
+          icon : Roo.rootURL + 'images/default/tree/leaf.gif',
+          xns : Roo.Toolbar,
+          items : [
 
-                                        ]
+          ]
 
-                                    }
-                                ]
+         }
+        ]
 
-                            },
-                            sm : {
-                                '|xns' : 'Roo.grid',
-                                xtype : 'RowSelectionModel',
-                                singleSelect : true,
-                                xns : Roo.grid,
-                                listeners : {
-                                       selectionchange : function (_self)
-                                          {
-                                              _this.grid.footer.onClick('first');
-                                          }
-                                }
-                            },
-                            dataSource : {
-                                proxy : {
-                                    '|xns' : 'Roo.data',
-                                    url : baseURL + '/Roo/metasql.php',
-                                    method : 'GET',
-                                    xtype : 'HttpProxy',
-                                    timeout : 900000,
-                                    xns : Roo.data
-                                },
-                                reader : {
-                                    '|xns' : 'Roo.data',
-                                    id : 'id',
-                                    root : 'data',
-                                    xtype : 'JsonReader',
-                                    fields : [
-                                        {
-                                            'name': 'sortdate',
-                                            'type': 'string'
-                                        }
-                                    ],
-                                    xns : Roo.data,
-                                    totalProperty : 'total'
-                                },
-                                '|xns' : 'Roo.data',
-                                xtype : 'Store',
-                                remoteSort : true,
-                                sortInfo : { field : 'sotrdate', direction: 'ASC' },
-                                xns : Roo.data,
-                                listeners : {
-                                       beforeload : function (_self, o)
-                                          {
-                                          
-                                              if (!_this.bankacct.getValue()) {
-                                                  return false;
-                                              }
-                                              var dt = _this.monthSel.getValue();
-                                              
-                                              if(dt.length){
-                                                  o.params['sortdate:text'] = typeof(dt) == 'string' ? dt : dt.format('Y-m-d');
-                                              }
-                                              o.params._group = 'bankrec';
-                                              o.params._name = 'bydate';
-                                              o.params['bankaccntid:number'] =  _this.bankacct.getValue();
-                                              
-                                          
-                                              
-                                          },
-                                       load : function (_self, records, options, res)
-                                          {   
-                                              var sm = _this.wgrid.getSelectionModel();
-                                              
-                                              if(_this.wgrid.lastSelectedRow * 1 >0){
-                                                  sm.selectRow(_this.wgrid.lastSelectedRow);
-                                                  return;
-                                              }
-                                              
-                                              if (!sm.getSelections().length) {
-                                                  sm.selectFirstRow();
-                                              }
-                                          
-                                          }
-                                },
-                                items : [
+       },
+       sm : {
+        '|xns' : 'Roo.grid',
+        xtype : 'RowSelectionModel',
+        singleSelect : true,
+        xns : Roo.grid,
+        listeners : {
+         selectionchange : function (_self)
+          {
+              _this.grid.footer.onClick('first');
+          }
+        }
+       },
+       dataSource : {
+        proxy : {
+         '|xns' : 'Roo.data',
+         url : baseURL + '/Roo/metasql.php',
+         xtype : 'HttpProxy',
+         method : 'GET',
+         timeout : 900000,
+         xns : Roo.data
+        },
+        reader : {
+         '|xns' : 'Roo.data',
+         id : 'id',
+         root : 'data',
+         xtype : 'JsonReader',
+         fields : [
+             {
+                 'name': 'sortdate',
+                 'type': 'string'
+             }
+         ],
+         xns : Roo.data,
+         totalProperty : 'total'
+        },
+        '|xns' : 'Roo.data',
+        xtype : 'Store',
+        remoteSort : true,
+        sortInfo : { field : 'sotrdate', direction: 'ASC' },
+        xns : Roo.data,
+        listeners : {
+         beforeload : function (_self, o)
+          {
+          
+              if (!_this.bankacct.getValue()) {
+                  return false;
+              }
+              var dt = _this.monthSel.getValue();
+              
+              if(dt.length){
+                  o.params['sortdate:text'] = typeof(dt) == 'string' ? dt : dt.format('Y-m-d');
+              }
+              o.params._group = 'bankrec';
+              o.params._name = 'bydate';
+              o.params['bankaccntid:number'] =  _this.bankacct.getValue();
+              
+          
+              
+          },
+         load : function (_self, records, options, res)
+          {   
+              var sm = _this.wgrid.getSelectionModel();
+              
+              if(_this.wgrid.lastSelectedRow * 1 >0){
+                  sm.selectRow(_this.wgrid.lastSelectedRow);
+                  return;
+              }
+              
+              if (!sm.getSelections().length) {
+                  sm.selectFirstRow();
+              }
+          
+          }
+        },
+        items : [
 
-                                ]
+        ]
 
-                            },
-                            footer : {
-                                '|xns' : 'Roo',
-                                pageSize : 25,
-                                xtype : 'PagingToolbar',
-                                emptyMsg : "No Date found",
-                                xns : Roo,
-                                displayMsg : "Displaying Date{0} - {1} of {2}",
-                                displayInfo : false
-                            },
-                            '|xns' : 'Roo.grid',
-                            autoExpandColumn : 'sortdate',
-                            xtype : 'Grid',
-                            loadMask : true,
-                            xns : Roo.grid,
-                            colModel : [
-                                {
-                                       '|xns' : 'Roo.grid',
-                                       xtype : 'ColumnModel',
-                                       header : 'Date',
-                                       width : 100,
-                                       renderer : function(v) {   
-                                       
-                                           return v ? Date.parseDate(v,'Y-m-d').format('d/M/Y') : '';
-                                        },
-                                       xns : Roo.grid,
-                                       dataIndex : 'sortdate'
-                                   },
+       },
+       footer : {
+        '|xns' : 'Roo',
+        pageSize : 25,
+        xtype : 'PagingToolbar',
+        emptyMsg : "No Date found",
+        xns : Roo,
+        displayMsg : "Displaying Date{0} - {1} of {2}",
+        displayInfo : false
+       },
+       '|xns' : 'Roo.grid',
+       autoExpandColumn : 'sortdate',
+       xtype : 'Grid',
+       loadMask : true,
+       xns : Roo.grid,
+       colModel : [
+         {
+          '|xns' : 'Roo.grid',
+          xtype : 'ColumnModel',
+          width : 100,
+          header : 'Date',
+          renderer : function(v) {   
+          
+              return v ? Date.parseDate(v,'Y-m-d').format('d/M/Y') : '';
+           },
+          xns : Roo.grid,
+          dataIndex : 'sortdate'
+         },
 {
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       xtype : 'ColumnModel',
-                                       header : 'Closing Balance',
-                                       width : 120,
-                                       renderer : function(v,x,r) { 
-                                           
-                                           var color = 'red'; // has some not 'ticked'
-                                           
-                                           if(r.data.no_records - r.data.no_posted == 0){ // all posted on that date
-                                               color = 'black';
-                                           }
-                                           if(r.data.no_records - r.data.no_cleared == 0 && r.data.no_posted != r.data.no_cleared){ // has 'ticked' or posted
-                                               color = 'blue';
-                                           }
-                                           
-                                           return String.format('<span style="color:{0}">{1}</span>', color, Roo.util.Format.number(v*1,2)); 
-                                       },
-                                       xns : Roo.grid,
-                                       dataIndex : 'balance'
-                                   },
+          '|xns' : 'Roo.grid',
+          align : 'right',
+          xtype : 'ColumnModel',
+          header : 'Closing Balance',
+          width : 120,
+          renderer : function(v,x,r) { 
+              
+              var color = 'red'; // has some not 'ticked'
+              
+              if(r.data.no_records - r.data.no_posted == 0){ // all posted on that date
+                  color = 'black';
+              }
+              if(r.data.no_records - r.data.no_cleared == 0 && r.data.no_posted != r.data.no_cleared){ // has 'ticked' or posted
+                  color = 'blue';
+              }
+              
+              return String.format('<span style="color:{0}">{1}</span>', color, Roo.util.Format.number(v*1,2)); 
+          },
+          xns : Roo.grid,
+          dataIndex : 'balance'
+         },
 {
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       xtype : 'ColumnModel',
-                                       header : 'Reconciled',
-                                       width : 100,
-                                       renderer : function(v,x,r) { 
-                                           
-                                           if(!v){
-                                               return '';
-                                           }
-                                           
-                                           if((r.data.no_records * 1 != r.data.no_posted * 1) || r.data.balance * 1 != v * 1){ // not match
-                                               
-                                               return '<span style="color:red;font-weight:bold">' + Roo.util.Format.number(v*1,2); 
-                                           }
-                                           
-                                           return String.format('<span style="color:black">{0}</span>', Roo.util.Format.number(v*1,2)); 
-                                               
-                                        },
-                                       xns : Roo.grid,
-                                       dataIndex : 'reconciled'
-                                   },
+          '|xns' : 'Roo.grid',
+          align : 'right',
+          xtype : 'ColumnModel',
+          header : 'Reconciled',
+          width : 100,
+          renderer : function(v,x,r) { 
+              
+              if(!v){
+                  return '';
+              }
+              
+              if((r.data.no_records * 1 != r.data.no_posted * 1) || r.data.balance * 1 != v * 1){ // not match
+                  
+                  return '<span style="color:red;font-weight:bold">' + Roo.util.Format.number(v*1,2); 
+              }
+              
+              return String.format('<span style="color:black">{0}</span>', Roo.util.Format.number(v*1,2)); 
+                  
+           },
+          xns : Roo.grid,
+          dataIndex : 'reconciled'
+         },
 {
-                                       '|xns' : 'Roo.grid',
-                                       align : 'right',
-                                       xtype : 'ColumnModel',
-                                       header : 'Post?',
-                                       width : 50,
-                                       renderer : function(v,x,r) { 
-                                           var state = v  ?  '-checked' : '';
-                                       
-                                           return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
-                                        },
-                                       xns : Roo.grid,
-                                       dataIndex : 'is_reconciled'
-                                   }
-                            ],
-                            listeners : {
-                               render : function() 
-                                  {
-                                      _this.wgrid = this; 
-                                      //_this.dialog = Pman.Dialog.FILL_IN
-                                      //if (_this.wpanel.active) {
-                                      //   this.footer.onClick('first');
-                                      //}
-                                  },
-                               cellclick : function (_self, rowIndex, columnIndex, e)
-                                  {
-                                      var di = this.colModel.getDataIndex(columnIndex);
-                                  
-                                      if (di != 'is_reconciled') {
-                                          return;
-                                      }
-                                       
-                                      var rec = this.ds.getAt(rowIndex);
-                                      
-                                      var voidit = function(){
-                                          new Pman.Request({
-                                              url : baseURL + '/Roo/Bankrec.php',
-                                              method :'POST',
-                                              params : {
-                                                  _void : 1,
-                                                  bankaccnt_id : _this.bankacct.getValue(),
-                                                  sotrdate : rec.data.sortdate
-                                                  
-                                              },
-                                              success : function() {
-                                                  _this.wgrid.footer.onClick('refresh');
-                                              }
-                                          });
-                                      }
-                                      
-                                      var postit = function(){
-                                          new Pman.Request({
-                                              url : baseURL + '/Roo/Bankrec.php',
-                                              method :'POST',
-                                              params : {
-                                                  _post : 1,
-                                                  bankaccnt_id : _this.bankacct.getValue(),
-                                                  sotrdate : rec.data.sortdate
-                                                  
-                                              },
-                                              success : function() {
-                                                  _this.wgrid.footer.onClick('refresh');
-                                              }
-                                          });
-                                      
-                                      }
-                                      
-                                      if(rec.data.is_reconciled == 1){
-                                          voidit();
-                                          return;
-                                      }
-                                      
-                                      postit();
-                                      return;
-                                      
-                                      
-                                      
-                                  },
-                               rowclick : function (_self, rowIndex, e)
-                                  {
-                                      
-                                       _this.wgrid.lastSelectedRow = rowIndex;
-                                      
-                                  }
-                            },
-                            items : [
+          '|xns' : 'Roo.grid',
+          align : 'right',
+          xtype : 'ColumnModel',
+          header : 'Post?',
+          width : 50,
+          renderer : function(v,x,r) { 
+              var state = v  ?  '-checked' : '';
+          
+              return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
+           },
+          xns : Roo.grid,
+          dataIndex : 'is_reconciled'
+         }
+       ],
+       listeners : {
+        render : function() 
+         {
+             _this.wgrid = this; 
+             //_this.dialog = Pman.Dialog.FILL_IN
+             //if (_this.wpanel.active) {
+             //   this.footer.onClick('first');
+             //}
+         },
+        cellclick : function (_self, rowIndex, columnIndex, e)
+         {
+             var di = this.colModel.getDataIndex(columnIndex);
+         
+             if (di != 'is_reconciled') {
+                 return;
+             }
+              
+             var rec = this.ds.getAt(rowIndex);
+             
+             var voidit = function(){
+                 new Pman.Request({
+                     url : baseURL + '/Roo/Bankrec.php',
+                     method :'POST',
+                     params : {
+                         _void : 1,
+                         bankaccnt_id : _this.bankacct.getValue(),
+                         sotrdate : rec.data.sortdate
+                         
+                     },
+                     success : function() {
+                         _this.wgrid.footer.onClick('refresh');
+                     }
+                 });
+             }
+             
+             var postit = function(){
+                 new Pman.Request({
+                     url : baseURL + '/Roo/Bankrec.php',
+                     method :'POST',
+                     params : {
+                         _post : 1,
+                         bankaccnt_id : _this.bankacct.getValue(),
+                         sotrdate : rec.data.sortdate
+                         
+                     },
+                     success : function() {
+                         _this.wgrid.footer.onClick('refresh');
+                     }
+                 });
+             
+             }
+             
+             if(rec.data.is_reconciled == 1){
+                 voidit();
+                 return;
+             }
+             
+             postit();
+             return;
+             
+             
+             
+         },
+        rowclick : function (_self, rowIndex, e)
+         {
+             
+              _this.wgrid.lastSelectedRow = rowIndex;
+             
+         }
+       },
+       items : [
 
-                            ]
+       ]
 
-                        },
-                        '|xns' : 'Roo',
-                        fitToframe : true,
-                        background : true,
-                        region : 'west',
-                        title : "Pick a Date",
-                        xtype : 'GridPanel',
-                        fitContainer : true,
-                        xns : Roo,
-                        tableName : 'Groups',
-                        listeners : {
-                               activate : function() {
-                                      _this.wpanel = this;
-                                      //if (_this.wgrid) {
-                                      //    _this.wgrid.footer.onClick('first');
-                                      //}
-                                  }
-                        },
-                        items : [
+      },
+      '|xns' : 'Roo',
+      region : 'west',
+      fitToframe : true,
+      background : true,
+      title : "Pick a Date",
+      xtype : 'GridPanel',
+      fitContainer : true,
+      xns : Roo,
+      tableName : 'Groups',
+      listeners : {
+       activate : function() {
+            _this.wpanel = this;
+            //if (_this.wgrid) {
+            //    _this.wgrid.footer.onClick('first');
+            //}
+        }
+      },
+      items : [
 
-                        ]
+      ]
 
-                    }
-                ]
+     }
+    ]
 
-            },
-            '|xns' : 'Roo',
-            background : true,
-            xtype : 'NestedLayoutPanel',
-            title : "Bank Reconcile",
-            xns : Roo,
-            items : [
+   },
+   '|xns' : 'Roo',
+   background : true,
+   title : "Bank Reconcile",
+   xtype : 'NestedLayoutPanel',
+   xns : Roo,
+   items : [
 
-            ]
+   ]
 
-        };    }
+  };  }
 });