Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Pman.Tab.XtuplePeriods.bjs
1 {
2     "name" : "Pman.Tab.XtuplePeriods",
3     "parent" : "Pman.Tab.XtupleAccountsTab",
4     "title" : "",
5     "path" : "/home/edward/gitlive/web.xtuple/Pman/Xtuple/Pman.Tab.XtuplePeriods.bjs",
6     "permname" : "",
7     "modOrder" : "300",
8     "items" : [
9         {
10             "fitToFrame" : true,
11             "background" : true,
12             "region" : "center",
13             "title" : "Periods",
14             "xtype" : "NestedLayoutPanel",
15             "fitContainer" : true,
16             "$ xns" : "Roo",
17             "items" : [
18                 {
19                     "xtype" : "BorderLayout",
20                     "$ xns" : "Roo",
21                     "* prop" : "layout",
22                     "items" : [
23                         {
24                             "title" : "Periods",
25                             "xtype" : "LayoutRegion",
26                             "tabPosition" : "top",
27                             "$ xns" : "Roo",
28                             "* prop" : "center",
29                             "titlebar" : false
30                         },
31                         {
32                             "title" : "Year Periods",
33                             "xtype" : "LayoutRegion",
34                             "tabPosition" : "top",
35                             "width" : 400,
36                             "$ xns" : "Roo",
37                             "split" : true,
38                             "* prop" : "west",
39                             "titlebar" : false
40                         },
41                         {
42                             "listeners" : {
43                                 "|activate" : "function() {\n    _this.wpanel = this;\n    if (_this.wgrid) {\n        _this.wgrid.ds.load({});\n    }\n}"
44                             },
45                             "fitToframe" : true,
46                             "background" : true,
47                             "region" : "west",
48                             "title" : "Year Periods",
49                             "xtype" : "GridPanel",
50                             "fitContainer" : true,
51                             "$ xns" : "Roo",
52                             "tableName" : "yearperiod",
53                             "items" : [
54                                 {
55                                     "listeners" : {
56                                         "cellclick" : "function (_self, rowIndex, columnIndex, e)\n{\n\n    var di = this.colModel.getDataIndex(columnIndex);\n\n    if (di != 'yearperiod_closed') {\n        return;\n    }\n\n    var rec = this.ds.getAt(rowIndex);\n\n\n  var open = function(){\n        new Pman.Request({\n            url : baseURL + '/Roo/Yearperiod.php',\n            timeout: 600000,\n            mask : 'Processing',\n            method : 'POST',\n            params : {\n                yearperiod_id : rec.data.yearperiod_id,\n                _open : 1\n                \n            }, \n            success : function() {\n                _this.wgrid.ds.load({});\n            }\n        });    \n    };\n    \n    var close = function(){\n        new Pman.Request({\n            url : baseURL + '/Roo/Yearperiod.php',\n            timeout: 600000,\n            mask : 'Processing',\n            method : 'POST',\n            params : {\n                yearperiod_id : rec.data.yearperiod_id,\n                _close : 1\n                \n            }, \n            success : function() {\n                _this.wgrid.ds.load({});\n            }\n        });    \n    };\n    \n    if(rec.data.yearperiod_id * 1 < 1){\n        Roo.MessageBox.alert('Error', 'Please select a period?');\n        return;\n    }\n\n    //Roo.log(rec.data);\n    if(rec.data.yearperiod_closed *1){\n         Roo.MessageBox.confirm(\"Confirm\", \"Are you sure want to open this year period?\" , function(r) {\n            if (r !='yes') {\n                return;\n            }\n            open();\n         \n          });\n         return;\n   }\n        \n    \n\n  \n     Roo.MessageBox.confirm(\"Confirm\", \"Are you sure want to close this year period?\" , function(r) {\n        if (r !='yes') {\n            return;\n        }\n        close();\n        \n   })\n   \n    \n    \n    \n}",
57                                         "|render" : "function() \n{\n    _this.wgrid = this; \n    //_this.dialog = Pman.Dialog.FILL_IN\n    if (_this.wpanel.active) {\n       this.ds.load({});\n    }\n}",
58                                         "rowclick" : "function (_self, rowIndex, e)\n{\n    _this.grid.ds.load({});\n}"
59                                     },
60                                     "autoExpandColumn" : "yearperiod_start",
61                                     "xtype" : "Grid",
62                                     "loadMask" : true,
63                                     "$ xns" : "Roo.grid",
64                                     "* prop" : "grid",
65                                     "items" : [
66                                         {
67                                             "xtype" : "RowSelectionModel",
68                                             "singleSelect" : true,
69                                             "$ xns" : "Roo.grid",
70                                             "* prop" : "sm"
71                                         },
72                                         {
73                                             "xtype" : "Store",
74                                             "remoteSort" : true,
75                                             "$ sortInfo" : "{ field : 'yearperiod_start', direction: 'ASC' }",
76                                             "$ xns" : "Roo.data",
77                                             "* prop" : "dataSource",
78                                             "items" : [
79                                                 {
80                                                     "$ url" : "baseURL + '/Roo/Yearperiod.php'",
81                                                     "xtype" : "HttpProxy",
82                                                     "method" : "GET",
83                                                     "$ xns" : "Roo.data",
84                                                     "* prop" : "proxy"
85                                                 },
86                                                 {
87                                                     "id" : "id",
88                                                     "root" : "data",
89                                                     "xtype" : "JsonReader",
90                                                     "$ fields" : "[\n    {\n        'name': 'yearperiod_id',\n        'type': 'int'\n    },\n    {\n        'name': 'yearperiod_name',\n        'type': 'string'\n    }\n]",
91                                                     "$ xns" : "Roo.data",
92                                                     "* prop" : "reader",
93                                                     "totalProperty" : "total"
94                                                 }
95                                             ]
96                                         },
97                                         {
98                                             "xtype" : "ColumnModel",
99                                             "header" : "Name",
100                                             "width" : 100,
101                                             "$ renderer" : "function(v,x,r) \n{ \n    v = r.data.yearperiod_start.getFullYear() + '-' + r.data.yearperiod_end.getFullYear();\n    \n    return String.format('{0}', v ? v : ''); \n}",
102                                             "$ xns" : "Roo.grid",
103                                             "* prop" : "colModel[]",
104                                             "dataIndex" : "yearperiod_name"
105                                         },
106                                         {
107                                             "xtype" : "ColumnModel",
108                                             "sortable" : true,
109                                             "header" : "Start",
110                                             "width" : 100,
111                                             "$ renderer" : "function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); }",
112                                             "$ xns" : "Roo.grid",
113                                             "* prop" : "colModel[]",
114                                             "dataIndex" : "yearperiod_start"
115                                         },
116                                         {
117                                             "xtype" : "ColumnModel",
118                                             "sortable" : true,
119                                             "header" : "End",
120                                             "width" : 100,
121                                             "$ renderer" : "function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); }",
122                                             "$ xns" : "Roo.grid",
123                                             "* prop" : "colModel[]",
124                                             "dataIndex" : "yearperiod_end"
125                                         },
126                                         {
127                                             "xtype" : "ColumnModel",
128                                             "sortable" : true,
129                                             "header" : "Closed",
130                                             "width" : 75,
131                                             "$ renderer" : "function(v) {  \n    var state = v  ?  '-checked' : '';\n\n    return '<img class=\"x-grid-check-icon' + state + '\" src=\"' + Roo.BLANK_IMAGE_URL + '\"/>';\n                \n }",
132                                             "$ xns" : "Roo.grid",
133                                             "* prop" : "colModel[]",
134                                             "dataIndex" : "yearperiod_closed"
135                                         }
136                                     ]
137                                 }
138                             ]
139                         },
140                         {
141                             "listeners" : {
142                                 "|activate" : "function() {\n    _this.panel = this;\n}"
143                             },
144                             "fitToframe" : true,
145                             "background" : true,
146                             "region" : "center",
147                             "title" : "Periods",
148                             "xtype" : "GridPanel",
149                             "fitContainer" : true,
150                             "$ xns" : "Roo",
151                             "tableName" : "period",
152                             "items" : [
153                                 {
154                                     "listeners" : {
155                                         "beforeedit" : "function (e)\n{\n    if(e.field != 'period_name'){\n        return false;\n    }\n}",
156                                         "|render" : "function() \n{\n    _this.grid = this; \n}",
157                                         "cellclick" : "function (_self, rowIndex, columnIndex, e)\n{\n\n    var di = this.colModel.getDataIndex(columnIndex);\n\n    if (di != 'period_closed' && di != 'period_freeze') {\n        return;\n    }\n\n    var rec = _this.grid.ds.getAt(rowIndex);\n    \n    if(rec.data.period_id * 1 < 1){\n        Roo.MessageBox.alert('Error', 'Error occur on getting the period id');\n        return;\n    }\n    \n    var action = rec.data[di] ? 'thaw' : 'freeze';\n    \n    if(di == 'period_closed'){\n        action = rec.data[di] ? 'open' : 'close';\n    }\n    \n    new Pman.Request({\n        url : baseURL + '/Roo/Period.php',\n        timeout: 600000,\n        mask : 'Processing',\n        method : 'POST',\n        params : {\n            period_id : rec.data.period_id,\n            _action : action\n            \n        }, \n        success : function() {\n            _this.grid.ds.load({});\n        }\n    });    \n    \n}",
158                                         "afteredit" : "function (e)\n{\n    if(e.field != 'period_name' || e.originalValue == e.value){\n        return;\n    }\n    \n    if(e.record.data.period_id * 1 < 1){\n        Roo.MessageBox.alert('Error', 'Error occur on getting the period id');\n        return;\n    }\n    \n    new Pman.Request({\n        url : baseURL + '/Roo/Period.php',\n        method : 'POST',\n        params : {\n            period_id : e.record.data.period_id,\n            period_name : e.record.data.period_name\n            \n        }, \n        success : function() {\n            _this.grid.ds.load({});\n        }\n    });\n}"
159                                     },
160                                     "autoExpandColumn" : "period_name",
161                                     "xtype" : "EditorGrid",
162                                     "loadMask" : true,
163                                     "clicksToEdit" : 2,
164                                     "$ xns" : "Roo.grid",
165                                     "* prop" : "grid",
166                                     "items" : [
167                                         {
168                                             "xtype" : "Toolbar",
169                                             "$ xns" : "Roo",
170                                             "* prop" : "toolbar",
171                                             "items" : [
172                                                 {
173                                                     "listeners" : {
174                                                         "render" : "function (_self)\n{\n  _this.status = _self;\n}",
175                                                         "select" : "function (combo, record, index)\n{\n    _this.grid.ds.load({});\n}"
176                                                     },
177                                                     "listWidth" : 200,
178                                                     "triggerAction" : "all",
179                                                     "fieldLabel" : "Status",
180                                                     "displayField" : "fname",
181                                                     "hiddenName" : "status",
182                                                     "value" : "A",
183                                                     "valueField" : "ftype",
184                                                     "xtype" : "ComboBox",
185                                                     "allowBlank" : false,
186                                                     "editable" : false,
187                                                     "width" : 150,
188                                                     "$ xns" : "Roo.form",
189                                                     "mode" : "local",
190                                                     "name" : "status",
191                                                     "items" : [
192                                                         {
193                                                             "xtype" : "SimpleStore",
194                                                             "$ data" : "[ \n    [ 'O', \"Open\"],\n    [ 'C' , \"Closed\"],\n    [ 'A', \"All\"] \n]\n",
195                                                             "$ fields" : "[  'ftype', 'fname']",
196                                                             "$ xns" : "Roo.data",
197                                                             "* prop" : "store"
198                                                         }
199                                                     ]
200                                                 },
201                                                 {
202                                                     "xtype" : "Fill",
203                                                     "$ xns" : "Roo.Toolbar"
204                                                 },
205                                                 {
206                                                     "listeners" : {
207                                                         "|click" : "function()\n{\n    var addPeriod = function(){\n        new Pman.Request({\n            url : baseURL + '/Roo/Period.php',\n            timeout: 600000,\n            mask : 'Processing',\n            method : 'POST',\n            params : {\n                _addExtraYear : 1\n            }, \n            success : function() {\n                _this.wgrid.ds.load({});\n            }\n        });\n    }\n     \n    Roo.MessageBox.confirm(\"Confirm\", \"Are you sure want to add extra year\" , function(r) {\n        if (r !='yes') {\n            return;\n        }\n        addPeriod();\n   })\n   \n}\n"
208                                                     },
209                                                     "text" : "Add Extra Year",
210                                                     "xtype" : "Button",
211                                                     "cls" : "x-btn-text-icon",
212                                                     "$ icon" : "Roo.rootURL + 'images/default/dd/drop-add.gif'",
213                                                     "$ xns" : "Roo.Toolbar"
214                                                 },
215                                                 {
216                                                     "xtype" : "Separator",
217                                                     "$ xns" : "Roo.Toolbar"
218                                                 },
219                                                 {
220                                                     "listeners" : {
221                                                         "|click" : "function()\n{\n    var list = []; \n    \n    \n    \n    _this.grid.ds.each(function (r) {\n        if (r.data.period_closed) {\n            return;\n        }\n    \n        if(r.data.transactions > 0 ){\n            return false;\n        }\n        list.push(r.data);\n\n    });\n    \n    if (!list.length) {\n       Roo.MessageBox.alert(\"Notice\", \"Nothing to close\");\n       return;\n    }\n    \n    var tl = list.length;\n    \n    var closeNext = function(){\n    \n        if (!list.length) {\n            Roo.MessageBox.hide();\n             _this.grid.ds.load({});\n             return;\n        }\n    \n        var item = list.shift();\n        \n        Roo.MessageBox.updateProgress(\n            (tl-list.length) / tl,\n            \"Closing \" + item.period_name\n              \n        );\n    \n        new Pman.Request({\n            url : baseURL + '/Roo/Period.php',\n            timeout: 900000,\n            //mask : 'Processing',\n            method : 'POST',\n            params : {\n                period_id : item.period_id,\n                _action:  'close' ,\n                _second_action : 'freeze'\n            }, \n            success : function() {\n                closeNext();\n//                _this.grid.ds.load({});\n            }\n        });\n    };\n     \n    \n     \n  \n    Roo.MessageBox.confirm(\"Confirm\", \"Are you sure want to close the period where there are no transactions?\" , function(r) {\n        if (r !='yes') {\n            return;\n        }\n        Roo.MessageBox.progress( \"Closing periods\", \"Closing periods\");\n        closeNext();\n        \n   })\n   \n    \n     \n     \n    \n}\n"
222                                                     },
223                                                     "text" : "Close all empty months",
224                                                     "xtype" : "Button",
225                                                     "cls" : "x-btn-text-icon",
226                                                     "$ icon" : "Roo.rootURL + 'images/default/tree/leaf.gif'",
227                                                     "$ xns" : "Roo.Toolbar"
228                                                 }
229                                             ]
230                                         },
231                                         {
232                                             "listeners" : {
233                                                 "beforeload" : "function (_self, options)\n{\n    options.params = options.params || {};\n    \n    var s = _this.wgrid.getSelectionModel().getSelected();\n    \n    if(!s || !s.data.yearperiod_id * 1 > 0){\n        Roo.MessageBox.alert('Error','Please select a year period');\n        this.removeAll();\n        return false;\n    }\n    \n    options.params._status = _this.status.getValue();\n    options.params.period_yearperiod_id = s.data.yearperiod_id;\n    options.params._with_transactions = 1;\n    \n\n}"
234                                             },
235                                             "xtype" : "Store",
236                                             "remoteSort" : true,
237                                             "$ sortInfo" : "{ field : 'period_start', direction: 'ASC' }",
238                                             "$ xns" : "Roo.data",
239                                             "* prop" : "dataSource",
240                                             "items" : [
241                                                 {
242                                                     "$ url" : "baseURL + '/Roo/Period.php'",
243                                                     "xtype" : "HttpProxy",
244                                                     "method" : "GET",
245                                                     "$ xns" : "Roo.data",
246                                                     "* prop" : "proxy"
247                                                 },
248                                                 {
249                                                     "id" : "id",
250                                                     "root" : "data",
251                                                     "xtype" : "JsonReader",
252                                                     "$ fields" : "[\n    {\n        'name': 'period_id',\n        'type': 'int'\n    },\n    {\n        'name': 'period_name',\n        'type': 'string'\n    }\n]",
253                                                     "$ xns" : "Roo.data",
254                                                     "* prop" : "reader",
255                                                     "totalProperty" : "total"
256                                                 }
257                                             ]
258                                         },
259                                         {
260                                             "xtype" : "ColumnModel",
261                                             "header" : "Name",
262                                             "width" : 100,
263                                             "$ renderer" : "function(v) \n{ \n    return String.format('{0}', v ? v : ''); \n}",
264                                             "$ xns" : "Roo.grid",
265                                             "* prop" : "colModel[]",
266                                             "dataIndex" : "period_name",
267                                             "items" : [
268                                                 {
269                                                     "xtype" : "GridEditor",
270                                                     "$ xns" : "Roo.grid",
271                                                     "* prop" : "editor",
272                                                     "items" : [
273                                                         {
274                                                             "xtype" : "TextField",
275                                                             "allowBlank" : false,
276                                                             "$ xns" : "Roo.form",
277                                                             "* prop" : "field"
278                                                         }
279                                                     ]
280                                                 }
281                                             ]
282                                         },
283                                         {
284                                             "xtype" : "ColumnModel",
285                                             "header" : "Start",
286                                             "width" : 100,
287                                             "$ renderer" : "function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); }",
288                                             "$ xns" : "Roo.grid",
289                                             "* prop" : "colModel[]",
290                                             "dataIndex" : "period_start"
291                                         },
292                                         {
293                                             "xtype" : "ColumnModel",
294                                             "header" : "End",
295                                             "width" : 100,
296                                             "$ renderer" : "function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); }",
297                                             "$ xns" : "Roo.grid",
298                                             "* prop" : "colModel[]",
299                                             "dataIndex" : "period_end"
300                                         },
301                                         {
302                                             "xtype" : "ColumnModel",
303                                             "header" : "Closed",
304                                             "width" : 75,
305                                             "$ renderer" : "function(v) {  \n    var state = v  ?  '-checked' : '';\n\n    return '<img class=\"x-grid-check-icon' + state + '\" src=\"' + Roo.BLANK_IMAGE_URL + '\"/>';\n                \n }",
306                                             "$ xns" : "Roo.grid",
307                                             "* prop" : "colModel[]",
308                                             "dataIndex" : "period_closed"
309                                         },
310                                         {
311                                             "xtype" : "ColumnModel",
312                                             "header" : "Frozen",
313                                             "width" : 75,
314                                             "$ renderer" : "function(v) {  \n    var state = v  ?  '-checked' : '';\n\n    return '<img class=\"x-grid-check-icon' + state + '\" src=\"' + Roo.BLANK_IMAGE_URL + '\"/>';\n                \n }",
315                                             "$ xns" : "Roo.grid",
316                                             "* prop" : "colModel[]",
317                                             "dataIndex" : "period_freeze"
318                                         },
319                                         {
320                                             "align" : "right",
321                                             "xtype" : "ColumnModel",
322                                             "header" : "Transactions",
323                                             "width" : 100,
324                                             "$ renderer" : "function(v) \n{ \n    return String.format('{0}', v ? v : ''); \n}",
325                                             "$ xns" : "Roo.grid",
326                                             "* prop" : "colModel[]",
327                                             "dataIndex" : "transactions"
328                                         }
329                                     ]
330                                 }
331                             ]
332                         }
333                     ]
334                 }
335             ]
336         }
337     ]
338 }