Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Pman.Tab.XtuplePeriods.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Roo.namespace('Pman.Tab');
6
7 Pman.Tab.XtuplePeriods = new Roo.XComponent({
8     part     :  ["Xtuple", "Periods" ],
9     order    : '300-Pman.Tab.XtuplePeriods',
10     region   : 'center',
11     parent   : 'Pman.Tab.XtupleAccountsTab',
12     name     : "unnamed module",
13     disabled : false, 
14     permname : '', 
15     _tree : function()
16     {
17         var _this = this;
18         var MODULE = this;
19         return {
20             layout : {
21                 center : {
22                     '|xns' : 'Roo',
23                     title : "Periods",
24                     xtype : 'LayoutRegion',
25                     tabPosition : 'top',
26                     xns : Roo,
27                     titlebar : false
28                 },
29                 west : {
30                     '|xns' : 'Roo',
31                     title : "Year Periods",
32                     xtype : 'LayoutRegion',
33                     tabPosition : 'top',
34                     width : 400,
35                     xns : Roo,
36                     split : true,
37                     titlebar : false
38                 },
39                 '|xns' : 'Roo',
40                 xtype : 'BorderLayout',
41                 xns : Roo,
42                 items : [
43                         {
44                         grid : {
45                             sm : {
46                                 '|xns' : 'Roo.grid',
47                                 xtype : 'RowSelectionModel',
48                                 singleSelect : true,
49                                 xns : Roo.grid
50                             },
51                             dataSource : {
52                                 proxy : {
53                                     '|xns' : 'Roo.data',
54                                     url : baseURL + '/Roo/Yearperiod.php',
55                                     xtype : 'HttpProxy',
56                                     method : 'GET',
57                                     xns : Roo.data
58                                 },
59                                 reader : {
60                                     '|xns' : 'Roo.data',
61                                     id : 'id',
62                                     root : 'data',
63                                     xtype : 'JsonReader',
64                                     fields : [
65                                         {
66                                             'name': 'yearperiod_id',
67                                             'type': 'int'
68                                         },
69                                         {
70                                             'name': 'yearperiod_name',
71                                             'type': 'string'
72                                         }
73                                     ],
74                                     xns : Roo.data,
75                                     totalProperty : 'total'
76                                 },
77                                 '|xns' : 'Roo.data',
78                                 xtype : 'Store',
79                                 remoteSort : true,
80                                 sortInfo : { field : 'yearperiod_start', direction: 'ASC' },
81                                 xns : Roo.data,
82                                 items : [
83
84                                 ]
85
86                             },
87                             '|xns' : 'Roo.grid',
88                             autoExpandColumn : 'yearperiod_start',
89                             xtype : 'Grid',
90                             loadMask : true,
91                             xns : Roo.grid,
92                             colModel : [
93                                  {
94                                         '|xns' : 'Roo.grid',
95                                         xtype : 'ColumnModel',
96                                         header : 'Name',
97                                         width : 100,
98                                         renderer : function(v,x,r) 
99                                         { 
100                                             v = r.data.yearperiod_start.getFullYear() + '-' + r.data.yearperiod_end.getFullYear();
101                                             
102                                             return String.format('{0}', v ? v : ''); 
103                                         },
104                                         xns : Roo.grid,
105                                         dataIndex : 'yearperiod_name'
106                                     },
107 {
108                                         '|xns' : 'Roo.grid',
109                                         xtype : 'ColumnModel',
110                                         sortable : true,
111                                         header : 'Start',
112                                         width : 100,
113                                         renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); },
114                                         xns : Roo.grid,
115                                         dataIndex : 'yearperiod_start'
116                                     },
117 {
118                                         '|xns' : 'Roo.grid',
119                                         xtype : 'ColumnModel',
120                                         sortable : true,
121                                         header : 'End',
122                                         width : 100,
123                                         renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); },
124                                         xns : Roo.grid,
125                                         dataIndex : 'yearperiod_end'
126                                     },
127 {
128                                         '|xns' : 'Roo.grid',
129                                         xtype : 'ColumnModel',
130                                         sortable : true,
131                                         header : 'Closed',
132                                         width : 75,
133                                         renderer : function(v) {  
134                                             var state = v  ?  '-checked' : '';
135                                         
136                                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
137                                                         
138                                          },
139                                         xns : Roo.grid,
140                                         dataIndex : 'yearperiod_closed'
141                                     }
142                             ],
143                             listeners : {
144                                 cellclick : function (_self, rowIndex, columnIndex, e)
145                                    {
146                                    
147                                        var di = this.colModel.getDataIndex(columnIndex);
148                                    
149                                        if (di != 'yearperiod_closed') {
150                                            return;
151                                        }
152                                    
153                                        var rec = this.ds.getAt(rowIndex);
154                                    
155                                    
156                                      var open = function(){
157                                            new Pman.Request({
158                                                url : baseURL + '/Roo/Yearperiod.php',
159                                                timeout: 600000,
160                                                mask : 'Processing',
161                                                method : 'POST',
162                                                params : {
163                                                    yearperiod_id : rec.data.yearperiod_id,
164                                                    _open : 1
165                                                    
166                                                }, 
167                                                success : function() {
168                                                    _this.wgrid.ds.load({});
169                                                }
170                                            });    
171                                        };
172                                        
173                                        var close = function(){
174                                            new Pman.Request({
175                                                url : baseURL + '/Roo/Yearperiod.php',
176                                                timeout: 600000,
177                                                mask : 'Processing',
178                                                method : 'POST',
179                                                params : {
180                                                    yearperiod_id : rec.data.yearperiod_id,
181                                                    _close : 1
182                                                    
183                                                }, 
184                                                success : function() {
185                                                    _this.wgrid.ds.load({});
186                                                }
187                                            });    
188                                        };
189                                        
190                                        if(rec.data.yearperiod_id * 1 < 1){
191                                            Roo.MessageBox.alert('Error', 'Please select a period?');
192                                            return;
193                                        }
194                                    
195                                        //Roo.log(rec.data);
196                                        if(rec.data.yearperiod_closed *1){
197                                             Roo.MessageBox.confirm("Confirm", "Are you sure want to open this year period?" , function(r) {
198                                                if (r !='yes') {
199                                                    return;
200                                                }
201                                                open();
202                                             
203                                              });
204                                             return;
205                                       }
206                                            
207                                        
208                                    
209                                      
210                                         Roo.MessageBox.confirm("Confirm", "Are you sure want to close this year period?" , function(r) {
211                                            if (r !='yes') {
212                                                return;
213                                            }
214                                            close();
215                                            
216                                       })
217                                       
218                                        
219                                        
220                                        
221                                    },
222                                 render : function() 
223                                    {
224                                        _this.wgrid = this; 
225                                        //_this.dialog = Pman.Dialog.FILL_IN
226                                        if (_this.wpanel.active) {
227                                           this.ds.load({});
228                                        }
229                                    },
230                                 rowclick : function (_self, rowIndex, e)
231                                    {
232                                        _this.grid.ds.load({});
233                                    }
234                             },
235                             items : [
236
237                             ]
238
239                         },
240                         '|xns' : 'Roo',
241                         fitToframe : true,
242                         background : true,
243                         region : 'west',
244                         title : "Year Periods",
245                         xtype : 'GridPanel',
246                         fitContainer : true,
247                         xns : Roo,
248                         tableName : 'yearperiod',
249                         listeners : {
250                                 activate : function() {
251                                        _this.wpanel = this;
252                                        if (_this.wgrid) {
253                                            _this.wgrid.ds.load({});
254                                        }
255                                    }
256                         },
257                         items : [
258
259                         ]
260
261                     },
262                         {
263                         grid : {
264                             toolbar : {
265                                 '|xns' : 'Roo',
266                                 xtype : 'Toolbar',
267                                 xns : Roo,
268                                 items : [
269                                         {
270                                         store : {
271                                             '|xns' : 'Roo.data',
272                                             xtype : 'SimpleStore',
273                                             data : [ 
274                                                 [ 'O', "Open"],
275                                                 [ 'C' , "Closed"],
276                                                 [ 'A', "All"] 
277                                             ],
278                                             fields : [  'ftype', 'fname'],
279                                             xns : Roo.data
280                                         },
281                                         '|xns' : 'Roo.form',
282                                         listWidth : 200,
283                                         triggerAction : 'all',
284                                         fieldLabel : 'Status',
285                                         displayField : 'fname',
286                                         hiddenName : 'status',
287                                         value : "A",
288                                         valueField : 'ftype',
289                                         xtype : 'ComboBox',
290                                         allowBlank : false,
291                                         editable : false,
292                                         width : 150,
293                                         xns : Roo.form,
294                                         mode : 'local',
295                                         name : 'status',
296                                         listeners : {
297                                                 render : function (_self)
298                                                    {
299                                                      _this.status = _self;
300                                                    },
301                                                 select : function (combo, record, index)
302                                                    {
303                                                        _this.grid.ds.load({});
304                                                    }
305                                         },
306                                         items : [
307
308                                         ]
309
310                                     },
311                                         {
312                                         '|xns' : 'Roo.Toolbar',
313                                         xtype : 'Fill',
314                                         xns : Roo.Toolbar
315                                     },
316                                         {
317                                         '|xns' : 'Roo.Toolbar',
318                                         text : "Add Extra Year",
319                                         xtype : 'Button',
320                                         cls : 'x-btn-text-icon',
321                                         icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
322                                         xns : Roo.Toolbar,
323                                         listeners : {
324                                                 click : function()
325                                                    {
326                                                        var addPeriod = function(){
327                                                            new Pman.Request({
328                                                                url : baseURL + '/Roo/Period.php',
329                                                                timeout: 600000,
330                                                                mask : 'Processing',
331                                                                method : 'POST',
332                                                                params : {
333                                                                    _addExtraYear : 1
334                                                                }, 
335                                                                success : function() {
336                                                                    _this.wgrid.ds.load({});
337                                                                }
338                                                            });
339                                                        }
340                                                         
341                                                        Roo.MessageBox.confirm("Confirm", "Are you sure want to add extra year" , function(r) {
342                                                            if (r !='yes') {
343                                                                return;
344                                                            }
345                                                            addPeriod();
346                                                       })
347                                                       
348                                                    }
349                                         }
350                                     },
351                                         {
352                                         '|xns' : 'Roo.Toolbar',
353                                         xtype : 'Separator',
354                                         xns : Roo.Toolbar
355                                     },
356                                         {
357                                         '|xns' : 'Roo.Toolbar',
358                                         text : "Close all empty months",
359                                         xtype : 'Button',
360                                         cls : 'x-btn-text-icon',
361                                         icon : Roo.rootURL + 'images/default/tree/leaf.gif',
362                                         xns : Roo.Toolbar,
363                                         listeners : {
364                                                 click : function()
365                                                    {
366                                                        var list = []; 
367                                                        
368                                                        
369                                                        
370                                                        _this.grid.ds.each(function (r) {
371                                                            if (r.data.period_closed) {
372                                                                return;
373                                                            }
374                                                        
375                                                            if(r.data.transactions > 0 ){
376                                                                return false;
377                                                            }
378                                                            list.push(r.data);
379                                                    
380                                                        });
381                                                        
382                                                        if (!list.length) {
383                                                           Roo.MessageBox.alert("Notice", "Nothing to close");
384                                                           return;
385                                                        }
386                                                        
387                                                        var tl = list.length;
388                                                        
389                                                        var closeNext = function(){
390                                                        
391                                                            if (!list.length) {
392                                                                Roo.MessageBox.hide();
393                                                                 _this.grid.ds.load({});
394                                                                 return;
395                                                            }
396                                                        
397                                                            var item = list.shift();
398                                                            
399                                                            Roo.MessageBox.updateProgress(
400                                                                (tl-list.length) / tl,
401                                                                "Closing " + item.period_name
402                                                                  
403                                                            );
404                                                        
405                                                            new Pman.Request({
406                                                                url : baseURL + '/Roo/Period.php',
407                                                                timeout: 900000,
408                                                                //mask : 'Processing',
409                                                                method : 'POST',
410                                                                params : {
411                                                                    period_id : item.period_id,
412                                                                    _action:  'close' ,
413                                                                    _second_action : 'freeze'
414                                                                }, 
415                                                                success : function() {
416                                                                    closeNext();
417                                                    //                _this.grid.ds.load({});
418                                                                }
419                                                            });
420                                                        };
421                                                         
422                                                        
423                                                         
424                                                      
425                                                        Roo.MessageBox.confirm("Confirm", "Are you sure want to close the period where there are no transactions?" , function(r) {
426                                                            if (r !='yes') {
427                                                                return;
428                                                            }
429                                                            Roo.MessageBox.progress( "Closing periods", "Closing periods");
430                                                            closeNext();
431                                                            
432                                                       })
433                                                       
434                                                        
435                                                         
436                                                         
437                                                        
438                                                    }
439                                         }
440                                     }
441                                 ]
442
443                             },
444                             dataSource : {
445                                 proxy : {
446                                     '|xns' : 'Roo.data',
447                                     url : baseURL + '/Roo/Period.php',
448                                     xtype : 'HttpProxy',
449                                     method : 'GET',
450                                     xns : Roo.data
451                                 },
452                                 reader : {
453                                     '|xns' : 'Roo.data',
454                                     id : 'id',
455                                     root : 'data',
456                                     xtype : 'JsonReader',
457                                     fields : [
458                                         {
459                                             'name': 'period_id',
460                                             'type': 'int'
461                                         },
462                                         {
463                                             'name': 'period_name',
464                                             'type': 'string'
465                                         }
466                                     ],
467                                     xns : Roo.data,
468                                     totalProperty : 'total'
469                                 },
470                                 '|xns' : 'Roo.data',
471                                 xtype : 'Store',
472                                 remoteSort : true,
473                                 sortInfo : { field : 'period_start', direction: 'ASC' },
474                                 xns : Roo.data,
475                                 listeners : {
476                                         beforeload : function (_self, options)
477                                            {
478                                                options.params = options.params || {};
479                                                
480                                                var s = _this.wgrid.getSelectionModel().getSelected();
481                                                
482                                                if(!s || !s.data.yearperiod_id * 1 > 0){
483                                                    Roo.MessageBox.alert('Error','Please select a year period');
484                                                    this.removeAll();
485                                                    return false;
486                                                }
487                                                
488                                                options.params._status = _this.status.getValue();
489                                                options.params.period_yearperiod_id = s.data.yearperiod_id;
490                                                options.params._with_transactions = 1;
491                                                
492                                            
493                                            }
494                                 },
495                                 items : [
496
497                                 ]
498
499                             },
500                             '|xns' : 'Roo.grid',
501                             autoExpandColumn : 'period_name',
502                             xtype : 'EditorGrid',
503                             loadMask : true,
504                             clicksToEdit : 2,
505                             xns : Roo.grid,
506                             colModel : [
507                                  {
508                                         editor : {
509                                             field : {
510                                                 '|xns' : 'Roo.form',
511                                                 xtype : 'TextField',
512                                                 allowBlank : false,
513                                                 xns : Roo.form
514                                             },
515                                             '|xns' : 'Roo.grid',
516                                             xtype : 'GridEditor',
517                                             xns : Roo.grid,
518                                             items : [
519
520                                             ]
521
522                                         },
523                                         '|xns' : 'Roo.grid',
524                                         xtype : 'ColumnModel',
525                                         header : 'Name',
526                                         width : 100,
527                                         renderer : function(v) 
528                                         { 
529                                             return String.format('{0}', v ? v : ''); 
530                                         },
531                                         xns : Roo.grid,
532                                         dataIndex : 'period_name',
533                                         items : [
534
535                                         ]
536
537                                     },
538 {
539                                         '|xns' : 'Roo.grid',
540                                         xtype : 'ColumnModel',
541                                         header : 'Start',
542                                         width : 100,
543                                         renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); },
544                                         xns : Roo.grid,
545                                         dataIndex : 'period_start'
546                                     },
547 {
548                                         '|xns' : 'Roo.grid',
549                                         xtype : 'ColumnModel',
550                                         header : 'End',
551                                         width : 100,
552                                         renderer : function(v) { return String.format('{0}', v ? v.format('Y-m-d') : ''); },
553                                         xns : Roo.grid,
554                                         dataIndex : 'period_end'
555                                     },
556 {
557                                         '|xns' : 'Roo.grid',
558                                         xtype : 'ColumnModel',
559                                         header : 'Closed',
560                                         width : 75,
561                                         renderer : function(v) {  
562                                             var state = v  ?  '-checked' : '';
563                                         
564                                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
565                                                         
566                                          },
567                                         xns : Roo.grid,
568                                         dataIndex : 'period_closed'
569                                     },
570 {
571                                         '|xns' : 'Roo.grid',
572                                         xtype : 'ColumnModel',
573                                         header : 'Frozen',
574                                         width : 75,
575                                         renderer : function(v) {  
576                                             var state = v  ?  '-checked' : '';
577                                         
578                                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
579                                                         
580                                          },
581                                         xns : Roo.grid,
582                                         dataIndex : 'period_freeze'
583                                     },
584 {
585                                         '|xns' : 'Roo.grid',
586                                         align : 'right',
587                                         xtype : 'ColumnModel',
588                                         header : 'Transactions',
589                                         width : 100,
590                                         renderer : function(v) 
591                                         { 
592                                             return String.format('{0}', v ? v : ''); 
593                                         },
594                                         xns : Roo.grid,
595                                         dataIndex : 'transactions'
596                                     }
597                             ],
598                             listeners : {
599                                 beforeedit : function (e)
600                                    {
601                                        if(e.field != 'period_name'){
602                                            return false;
603                                        }
604                                    },
605                                 render : function() 
606                                    {
607                                        _this.grid = this; 
608                                    },
609                                 cellclick : function (_self, rowIndex, columnIndex, e)
610                                    {
611                                    
612                                        var di = this.colModel.getDataIndex(columnIndex);
613                                    
614                                        if (di != 'period_closed' && di != 'period_freeze') {
615                                            return;
616                                        }
617                                    
618                                        var rec = _this.grid.ds.getAt(rowIndex);
619                                        
620                                        if(rec.data.period_id * 1 < 1){
621                                            Roo.MessageBox.alert('Error', 'Error occur on getting the period id');
622                                            return;
623                                        }
624                                        
625                                        var action = rec.data[di] ? 'thaw' : 'freeze';
626                                        
627                                        if(di == 'period_closed'){
628                                            action = rec.data[di] ? 'open' : 'close';
629                                        }
630                                        
631                                        new Pman.Request({
632                                            url : baseURL + '/Roo/Period.php',
633                                            timeout: 600000,
634                                            mask : 'Processing',
635                                            method : 'POST',
636                                            params : {
637                                                period_id : rec.data.period_id,
638                                                _action : action
639                                                
640                                            }, 
641                                            success : function() {
642                                                _this.grid.ds.load({});
643                                            }
644                                        });    
645                                        
646                                    },
647                                 afteredit : function (e)
648                                    {
649                                        if(e.field != 'period_name' || e.originalValue == e.value){
650                                            return;
651                                        }
652                                        
653                                        if(e.record.data.period_id * 1 < 1){
654                                            Roo.MessageBox.alert('Error', 'Error occur on getting the period id');
655                                            return;
656                                        }
657                                        
658                                        new Pman.Request({
659                                            url : baseURL + '/Roo/Period.php',
660                                            method : 'POST',
661                                            params : {
662                                                period_id : e.record.data.period_id,
663                                                period_name : e.record.data.period_name
664                                                
665                                            }, 
666                                            success : function() {
667                                                _this.grid.ds.load({});
668                                            }
669                                        });
670                                    }
671                             },
672                             items : [
673
674                             ]
675
676                         },
677                         '|xns' : 'Roo',
678                         fitToframe : true,
679                         background : true,
680                         region : 'center',
681                         title : "Periods",
682                         xtype : 'GridPanel',
683                         fitContainer : true,
684                         xns : Roo,
685                         tableName : 'period',
686                         listeners : {
687                                 activate : function() {
688                                        _this.panel = this;
689                                    }
690                         },
691                         items : [
692
693                         ]
694
695                     }
696                 ]
697
698             },
699             '|xns' : 'Roo',
700             fitToFrame : true,
701             background : true,
702             region : 'center',
703             title : "Periods",
704             xtype : 'NestedLayoutPanel',
705             fitContainer : true,
706             xns : Roo,
707             items : [
708
709             ]
710
711         };    }
712 });