Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Pman.Tab.XtupleReconcile.bjs
1 {
2  "name" : "Pman.Tab.XtupleReconcile",
3  "parent" : "Pman.Tab.XtupleAccountsTab",
4  "title" : "Pman.Tab.XtupleReconcile",
5  "path" : "/home/alan/gitlive/Pman.Xtuple/Pman.Tab.XtupleReconcile.bjs",
6  "permname" : "",
7  "modOrder" : "200",
8  "items" : [
9   {
10    "background" : true,
11    "title" : "Bank Reconcile",
12    "xtype" : "NestedLayoutPanel",
13    "$ xns" : "Roo",
14    "items" : [
15     {
16      "xtype" : "BorderLayout",
17      "$ xns" : "Roo",
18      "* prop" : "layout",
19      "items" : [
20       {
21        "xtype" : "LayoutRegion",
22        "$ xns" : "Roo",
23        "* prop" : "center"
24       },
25       {
26        "xtype" : "LayoutRegion",
27        "$ xns" : "Roo",
28        "width" : 400,
29        "split" : true,
30        "* prop" : "west"
31       },
32       {
33        "listeners" : {
34         "|activate" : "function() {\n    _this.panel = this;\n    if (_this.grid) {\n        _this.grid.footer.onClick('first');\n    }\n}"
35        },
36        "region" : "center",
37        "fitToframe" : true,
38        "background" : true,
39        "title" : "Bank Reconcile",
40        "xtype" : "GridPanel",
41        "fitContainer" : true,
42        "$ xns" : "Roo",
43        "tableName" : "metasql",
44        "items" : [
45         {
46          "listeners" : {
47           "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}",
48           "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}",
49           "|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}",
50           "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}"
51          },
52          "autoExpandColumn" : "notes",
53          "xtype" : "EditorGrid",
54          "loadMask" : true,
55          "clicksToEdit" : 1,
56          "$ xns" : "Roo.grid",
57          "* prop" : "grid",
58          "items" : [
59           {
60            "listeners" : {
61             "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",
62             "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}",
63             "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}"
64            },
65            "xtype" : "Store",
66            "remoteSort" : true,
67            "$ sortInfo" : "{ field : 'metasql_group', direction: 'ASC' }",
68            "$ xns" : "Roo.data",
69            "$ 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",
70            "* prop" : "dataSource",
71            "items" : [
72             {
73              "$ url" : "baseURL + '/Roo/metasql.php'",
74              "method" : "GET",
75              "xtype" : "HttpProxy",
76              "$ xns" : "Roo.data",
77              "* prop" : "proxy"
78             },
79             {
80              "id" : "idx",
81              "root" : "data",
82              "xtype" : "JsonReader",
83              "$ 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]",
84              "$ xns" : "Roo.data",
85              "* prop" : "reader",
86              "totalProperty" : "total"
87             }
88            ]
89           },
90           {
91            "pageSize" : 50,
92            "xtype" : "PagingToolbar",
93            "emptyMsg" : "Nothing found",
94            "$ xns" : "Roo",
95            "displayMsg" : "Displaying records {0} - {1} of {2}",
96            "displayInfo" : true,
97            "* prop" : "footer"
98           },
99           {
100            "xtype" : "Toolbar",
101            "$ xns" : "Roo",
102            "* prop" : "toolbar",
103            "items" : [
104             {
105              "listeners" : {
106               "render" : "function (_self)\n{\n    _this.bankacct = _self;\n}",
107               "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}"
108              },
109              "listWidth" : 400,
110              "triggerAction" : "all",
111              "fieldLabel" : "bankaccnt",
112              "forceSelection" : true,
113              "selectOnFocus" : true,
114              "pageSize" : 50,
115              "displayField" : "bankaccnt_name",
116              "emptyText" : "Select bankaccnt",
117              "hiddenName" : "bankaccnt_id",
118              "minChars" : 2,
119              "valueField" : "bankaccnt_id",
120              "xtype" : "ComboBox",
121              "allowBlank" : false,
122              "typeAhead" : true,
123              "editable" : false,
124              "width" : 300,
125              "$ xns" : "Roo.form",
126              "name" : "bankaccnt_name",
127              "qtip" : "Select bankaccnt",
128              "queryParam" : "",
129              "tpl" : "<div class=\"x-grid-cell-text x-btn button\"><b>{bankaccnt_bankname}</b> {bankaccnt_name} - {bankaccnt_descrip}  {bankaccnt_accntnumber}</div>",
130              "loadingText" : "Searching...",
131              "items" : [
132               {
133                "listeners" : {
134                 "|beforeload" : "function (_self, o){\n    o.params = o.params || {};\n    // set more here\n}\n"
135                },
136                "xtype" : "Store",
137                "remoteSort" : true,
138                "$ sortInfo" : "{ direction : 'ASC', field: 'bankaccnt_bankname' }",
139                "$ xns" : "Roo.data",
140                "* prop" : "store",
141                "items" : [
142                 {
143                  "$ url" : "baseURL + '/Roo/bankaccnt.php'",
144                  "xtype" : "HttpProxy",
145                  "method" : "GET",
146                  "$ xns" : "Roo.data",
147                  "* prop" : "proxy"
148                 },
149                 {
150                  "id" : "id",
151                  "root" : "data",
152                  "xtype" : "JsonReader",
153                  "$ xns" : "Roo.data",
154                  "$ fields" : "[{\"name\":\"id\",\"type\":\"int\"},{\"name\":\"bankaccnt_name\",\"type\":\"string\"}]",
155                  "* prop" : "reader",
156                  "totalProperty" : "total"
157                 }
158                ]
159               }
160              ]
161             },
162             {
163              "listeners" : {
164               "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}"
165              },
166              "text" : "Download",
167              "xtype" : "Button",
168              "$ xns" : "Roo.Toolbar"
169             },
170             {
171              "xtype" : "Fill",
172              "$ xns" : "Roo.Toolbar"
173             }
174            ]
175           },
176           {
177            "xtype" : "ColumnModel",
178            "width" : 50,
179            "header" : "Cleared",
180            "$ 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 }",
181            "$ xns" : "Roo.grid",
182            "* prop" : "colModel[]",
183            "dataIndex" : "cleared"
184           },
185           {
186            "xtype" : "ColumnModel",
187            "width" : 75,
188            "header" : "Date",
189            "$ renderer" : "function(v) {   \n\n    return v ? Date.parseDate(v,'Y-m-d').format('d/M/Y') : '';\n }",
190            "$ xns" : "Roo.grid",
191            "* prop" : "colModel[]",
192            "dataIndex" : "sortdate"
193           },
194           {
195            "xtype" : "ColumnModel",
196            "width" : 50,
197            "header" : "Doctype",
198            "$ renderer" : "function(v) { return String.format('{0}', v); }",
199            "$ xns" : "Roo.grid",
200            "* prop" : "colModel[]",
201            "dataIndex" : "doc_type"
202           },
203           {
204            "xtype" : "ColumnModel",
205            "width" : 120,
206            "header" : "Doc Number",
207            "$ renderer" : "function(v) { return String.format('{0}', v); }",
208            "$ xns" : "Roo.grid",
209            "* prop" : "colModel[]",
210            "dataIndex" : "doc_number"
211           },
212           {
213            "xtype" : "ColumnModel",
214            "width" : 200,
215            "header" : "Notes",
216            "$ renderer" : "function(v) { return String.format('{0}', v); }",
217            "$ xns" : "Roo.grid",
218            "* prop" : "colModel[]",
219            "dataIndex" : "notes"
220           },
221           {
222            "xtype" : "ColumnModel",
223            "width" : 75,
224            "header" : "Currency",
225            "$ renderer" : "function(v) { return String.format('{0}', v); }",
226            "$ xns" : "Roo.grid",
227            "* prop" : "colModel[]",
228            "dataIndex" : "doc_curr"
229           },
230           {
231            "align" : "right",
232            "xtype" : "ColumnModel",
233            "header" : "Exchange Rate",
234            "width" : 75,
235            "$ renderer" : "function(v) { return String.format('{0}', v ? (v*1).toFixed(3) : ''); }",
236            "$ xns" : "Roo.grid",
237            "* prop" : "colModel[]",
238            "dataIndex" : "doc_exchrate"
239           },
240           {
241            "align" : "right",
242            "xtype" : "ColumnModel",
243            "header" : "Base Amount",
244            "width" : 120,
245            "$ renderer" : "function(v) { return String.format('{0}', Roo.util.Format.number(v*1,2)); }",
246            "$ xns" : "Roo.grid",
247            "* prop" : "colModel[]",
248            "dataIndex" : "base_amount"
249           },
250           {
251            "align" : "right",
252            "xtype" : "ColumnModel",
253            "header" : "Credit",
254            "width" : 120,
255            "$ 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)   : ''); }",
256            "$ xns" : "Roo.grid",
257            "* prop" : "colModel[]",
258            "dataIndex" : "amount",
259            "items" : [
260             {
261              "xtype" : "GridEditor",
262              "$ xns" : "Roo.grid",
263              "* prop" : "editor",
264              "items" : [
265               {
266                "xtype" : "NumberField",
267                "cls" : "align-right",
268                "decimalPrecision" : 2,
269                "$ xns" : "Roo.form",
270                "* prop" : "field"
271               }
272              ]
273             }
274            ]
275           },
276           {
277            "align" : "right",
278            "xtype" : "ColumnModel",
279            "header" : "Debit",
280            "width" : 120,
281            "$ 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): ''); }",
282            "$ xns" : "Roo.grid",
283            "* prop" : "colModel[]",
284            "dataIndex" : "amount",
285            "items" : [
286             {
287              "xtype" : "GridEditor",
288              "$ xns" : "Roo.grid",
289              "* prop" : "editor",
290              "items" : [
291               {
292                "xtype" : "NumberField",
293                "cls" : "align-right",
294                "decimalPrecision" : 2,
295                "$ xns" : "Roo.form",
296                "* prop" : "field"
297               }
298              ]
299             }
300            ]
301           },
302           {
303            "align" : "right",
304            "xtype" : "ColumnModel",
305            "header" : "Balance",
306            "width" : 120,
307            "$ 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}",
308            "$ xns" : "Roo.grid",
309            "* prop" : "colModel[]",
310            "dataIndex" : "balance"
311           }
312          ]
313         }
314        ]
315       },
316       {
317        "listeners" : {
318         "|activate" : "function() {\n    _this.wpanel = this;\n    //if (_this.wgrid) {\n    //    _this.wgrid.footer.onClick('first');\n    //}\n}"
319        },
320        "region" : "west",
321        "fitToframe" : true,
322        "background" : true,
323        "title" : "Pick a Date",
324        "xtype" : "GridPanel",
325        "fitContainer" : true,
326        "$ xns" : "Roo",
327        "tableName" : "Groups",
328        "items" : [
329         {
330          "listeners" : {
331           "|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}",
332           "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}",
333           "rowclick" : "function (_self, rowIndex, e)\n{\n    \n     _this.wgrid.lastSelectedRow = rowIndex;\n    \n}"
334          },
335          "autoExpandColumn" : "sortdate",
336          "xtype" : "Grid",
337          "loadMask" : true,
338          "$ xns" : "Roo.grid",
339          "* prop" : "grid",
340          "items" : [
341           {
342            "xtype" : "Toolbar",
343            "$ xns" : "Roo",
344            "* prop" : "toolbar",
345            "items" : [
346             {
347              "listeners" : {
348               "render" : "function (_self)\n{\n    _this.monthSel = _self;\n}",
349               "select" : "function (combo, date)\n{\n    _this.grid.ds.removeAll();\n    _this.wgrid.footer.onClick('first');\n}"
350              },
351              "format" : "M Y",
352              "xtype" : "MonthField",
353              "useIso" : true,
354              "allowBlank" : true,
355              "width" : 150,
356              "$ xns" : "Roo.form"
357             },
358             {
359              "listeners" : {
360               "click" : "function (_self, e)\n{\n    _this.monthSel.setValue('');\n    _this.grid.ds.removeAll();\r\n    _this.wgrid.footer.onClick('first');\r\n}"
361              },
362              "xtype" : "Button",
363              "cls" : "x-btn-icon",
364              "$ icon" : "rootURL + '/Pman/templates/images/edit-clear.gif'",
365              "$ xns" : "Roo.Toolbar"
366             },
367             {
368              "xtype" : "Fill",
369              "$ xns" : "Roo.Toolbar"
370             },
371             {
372              "text" : "Fix Data",
373              "xtype" : "Button",
374              "cls" : "x-btn-text-icon",
375              "$ icon" : "Roo.rootURL + 'images/default/tree/leaf.gif'",
376              "$ xns" : "Roo.Toolbar",
377              "items" : [
378               {
379                "xtype" : "Menu",
380                "$ xns" : "Roo.menu",
381                "* prop" : "menu",
382                "items" : [
383                 {
384                  "listeners" : {
385                   "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}"
386                  },
387                  "text" : "Fix historical data",
388                  "xtype" : "Item",
389                  "cls" : "x-btn-text-icon",
390                  "$ icon" : "Roo.rootURL + 'images/default/tree/leaf.gif'",
391                  "$ xns" : "Roo.menu"
392                 },
393                 {
394                  "listeners" : {
395                   "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}"
396                  },
397                  "text" : "Fix Closed Periods",
398                  "xtype" : "Item",
399                  "cls" : "x-btn-text-icon",
400                  "$ icon" : "Roo.rootURL + 'images/default/tree/leaf.gif'",
401                  "$ xns" : "Roo.menu"
402                 }
403                ]
404               }
405              ]
406             }
407            ]
408           },
409           {
410            "listeners" : {
411             "selectionchange" : "function (_self)\n{\n    _this.grid.footer.onClick('first');\n}"
412            },
413            "xtype" : "RowSelectionModel",
414            "singleSelect" : true,
415            "$ xns" : "Roo.grid",
416            "* prop" : "sm"
417           },
418           {
419            "listeners" : {
420             "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}",
421             "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}"
422            },
423            "xtype" : "Store",
424            "remoteSort" : true,
425            "$ sortInfo" : "{ field : 'sotrdate', direction: 'ASC' }",
426            "$ xns" : "Roo.data",
427            "* prop" : "dataSource",
428            "items" : [
429             {
430              "$ url" : "baseURL + '/Roo/metasql.php'",
431              "xtype" : "HttpProxy",
432              "method" : "GET",
433              "timeout" : 900000,
434              "$ xns" : "Roo.data",
435              "* prop" : "proxy"
436             },
437             {
438              "id" : "id",
439              "root" : "data",
440              "xtype" : "JsonReader",
441              "$ fields" : "[\n    {\n        'name': 'sortdate',\n        'type': 'string'\n    }\n]",
442              "$ xns" : "Roo.data",
443              "* prop" : "reader",
444              "totalProperty" : "total"
445             }
446            ]
447           },
448           {
449            "pageSize" : 25,
450            "xtype" : "PagingToolbar",
451            "emptyMsg" : "No Date found",
452            "$ xns" : "Roo",
453            "displayMsg" : "Displaying Date{0} - {1} of {2}",
454            "displayInfo" : false,
455            "* prop" : "footer"
456           },
457           {
458            "xtype" : "ColumnModel",
459            "width" : 100,
460            "header" : "Date",
461            "$ renderer" : "function(v) {   \n\n    return v ? Date.parseDate(v,'Y-m-d').format('d/M/Y') : '';\n }",
462            "$ xns" : "Roo.grid",
463            "* prop" : "colModel[]",
464            "dataIndex" : "sortdate"
465           },
466           {
467            "align" : "right",
468            "xtype" : "ColumnModel",
469            "header" : "Closing Balance",
470            "width" : 120,
471            "$ 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}",
472            "$ xns" : "Roo.grid",
473            "* prop" : "colModel[]",
474            "dataIndex" : "balance"
475           },
476           {
477            "align" : "right",
478            "xtype" : "ColumnModel",
479            "header" : "Reconciled",
480            "width" : 100,
481            "$ 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 }",
482            "$ xns" : "Roo.grid",
483            "* prop" : "colModel[]",
484            "dataIndex" : "reconciled"
485           },
486           {
487            "align" : "right",
488            "xtype" : "ColumnModel",
489            "header" : "Post?",
490            "width" : 50,
491            "$ 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",
492            "$ xns" : "Roo.grid",
493            "* prop" : "colModel[]",
494            "dataIndex" : "is_reconciled"
495           }
496          ]
497         }
498        ]
499       }
500      ]
501     }
502    ]
503   }
504  ]
505 }