DataObjects/Location.php
[Pman.Xtuple] / Pman.Tab.XtupleReconcile.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.XtupleReconcile = new Roo.XComponent({
8     part     :  ["Xtuple", "Reconcile" ],
9     order    : '200-Pman.Tab.XtupleReconcile',
10     region   : 'center',
11     parent   : 'Pman.Tab.XtupleAccountsTab',
12     name     : "Pman.Tab.XtupleReconcile",
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                     xtype : 'LayoutRegion',
24                     xns : Roo
25                 },
26                 west : {
27                     '|xns' : 'Roo',
28                     xtype : 'LayoutRegion',
29                     width : 400,
30                     xns : Roo,
31                     split : true
32                 },
33                 '|xns' : 'Roo',
34                 xtype : 'BorderLayout',
35                 xns : Roo,
36                 items : [
37                         {
38                         grid : {
39                             dataSource : {
40                                 proxy : {
41                                     '|xns' : 'Roo.data',
42                                     url : baseURL + '/Roo/metasql.php',
43                                     xtype : 'HttpProxy',
44                                     method : 'GET',
45                                     xns : Roo.data
46                                 },
47                                 reader : {
48                                     '|xns' : 'Roo.data',
49                                     id : 'idx',
50                                     root : 'data',
51                                     xtype : 'JsonReader',
52                                     fields : [
53                                         {
54                                             'name': 'metasql_id',
55                                             'type': 'int'
56                                         },
57                                         {
58                                             'name': 'metasql_group',
59                                             'type': 'string'
60                                         },
61                                         {
62                                             'name': 'metasql_name',
63                                             'type': 'string'
64                                         },
65                                         {
66                                             'name': 'metasql_notes',
67                                             'type': 'string'
68                                         },
69                                         {
70                                             'name': 'metasql_query',
71                                             'type': 'string'
72                                         },
73                                         {
74                                             'name': 'metasql_lastuser',
75                                             'type': 'string'
76                                         },
77                                         {
78                                             'name': 'metasql_lastupdate',
79                                             'type': 'date',
80                                             'dateFormat': 'Y-m-d'
81                                         },
82                                         {
83                                             'name': 'metasql_grade',
84                                             'type': 'int'
85                                         }
86                                     ],
87                                     xns : Roo.data,
88                                     totalProperty : 'total'
89                                 },
90                                 '|xns' : 'Roo.data',
91                                 xtype : 'Store',
92                                 remoteSort : true,
93                                 sortInfo : { field : 'metasql_group', direction: 'ASC' },
94                                 xns : Roo.data,
95                                 updateBalance : function() {
96                                      var bal = _this.bf;
97                                     this.each( function(rec) {
98                                         if (rec.data.doc_type != 'BF') {
99                                             bal += rec.data.amount *1;
100                                             rec.set('balance', bal);   
101                                         } else {
102                                             rec.set('balance', _this.bf);
103                                         }
104                                         
105                                         
106                                     });
107                                 },
108                                 listeners : {
109                                         beforeloadadd : function (_self, records, options, res)
110                                            {
111                                             //  _this.total = 0.0;
112                                            
113                                              
114                                            
115                                            
116                                                  _this.total = 1 * res.raw.amount;
117                                                    _this.bf = 1 * res.raw.amount;
118                                                Roo.log("TOTAL:" + _this.total);
119                                            },
120                                         beforeload : function (_self, o)
121                                            {
122                                                var s = _this.wgrid.getSelectionModel().getSelected();
123                                                
124                                                if (!s) {
125                                                    return false;
126                                                }
127                                                o.params._group = 'bankrec';
128                                                o.params._name = 'all';
129                                                o.params['sortdate:text'] = s.data.sortdate;
130                                                o.params['bankaccntid:number'] =     _this.bankacct.getValue();
131                                            
132                                                o.params['_cals'] = 'amount'
133                                            },
134                                         load : function (_self, records, options)
135                                            {
136                                                
137                                                var bal = _this.bf;
138                                                  var cleared = true;
139                                                  var posted = true;
140                                                Roo.each(records, function(rec) {
141                                                    if (!rec.data.cleared) {
142                                                        cleared = false;
143                                            
144                                                    }
145                                                    if (!rec.data.bankrec_posted) {
146                                                        posted = false;
147                                                    }
148                                                    if (rec.data.doc_type != 'BF') {
149                                                        bal += rec.data.amount *1;
150                                                        rec.set('balance', bal);   
151                                                    } else {
152                                                        rec.set('balance', _this.bf);
153                                                    }
154                                                    
155                                                    
156                                                });
157                                                
158                                                var rec = this.reader.newRow({
159                                                    notes : 'Brought Forward',
160                                                    balance : _this.bf,
161                                                    doc_type : 'BF',
162                                                    cleared : cleared,
163                                                    bankrec_posted : posted
164                                                });
165                                                this.insert(0, [rec]);
166                                            }
167                                 },
168                                 items : [
169
170                                 ]
171
172                             },
173                             footer : {
174                                 '|xns' : 'Roo',
175                                 pageSize : 50,
176                                 xtype : 'PagingToolbar',
177                                 emptyMsg : "Nothing found",
178                                 xns : Roo,
179                                 displayMsg : "Displaying records {0} - {1} of {2}",
180                                 displayInfo : true
181                             },
182                             toolbar : {
183                                 '|xns' : 'Roo',
184                                 xtype : 'Toolbar',
185                                 xns : Roo,
186                                 items : [
187                                         {
188                                         store : {
189                                             proxy : {
190                                                 '|xns' : 'Roo.data',
191                                                 url : baseURL + '/Roo/bankaccnt.php',
192                                                 method : 'GET',
193                                                 xtype : 'HttpProxy',
194                                                 xns : Roo.data
195                                             },
196                                             reader : {
197                                                 '|xns' : 'Roo.data',
198                                                 id : 'id',
199                                                 root : 'data',
200                                                 xtype : 'JsonReader',
201                                                 xns : Roo.data,
202                                                 fields : [{"name":"id","type":"int"},{"name":"bankaccnt_name","type":"string"}],
203                                                 totalProperty : 'total'
204                                             },
205                                             '|xns' : 'Roo.data',
206                                             xtype : 'Store',
207                                             remoteSort : true,
208                                             sortInfo : { direction : 'ASC', field: 'bankaccnt_bankname' },
209                                             xns : Roo.data,
210                                             listeners : {
211                                                 beforeload : function (_self, o){
212                                                        o.params = o.params || {};
213                                                        // set more here
214                                                    }
215                                             },
216                                             items : [
217
218                                             ]
219
220                                         },
221                                         '|xns' : 'Roo.form',
222                                         listWidth : 400,
223                                         triggerAction : 'all',
224                                         fieldLabel : 'bankaccnt',
225                                         forceSelection : true,
226                                         selectOnFocus : true,
227                                         pageSize : 50,
228                                         displayField : 'bankaccnt_bankname',
229                                         emptyText : "Select bankaccnt",
230                                         hiddenName : 'bankaccnt_id',
231                                         minChars : 2,
232                                         valueField : 'bankaccnt_id',
233                                         xtype : 'ComboBox',
234                                         allowBlank : false,
235                                         typeAhead : true,
236                                         editable : false,
237                                         width : 300,
238                                         xns : Roo.form,
239                                         name : 'bankaccnt_bankname',
240                                         qtip : "Select bankaccnt",
241                                         queryParam : '',
242                                         tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{bankaccnt_bankname}</b> </div>',
243                                         loadingText : "Searching...",
244                                         listeners : {
245                                                 render : function (_self)
246                                                    {
247                                                        _this.bankacct = _self;
248                                                    },
249                                                 select : function (combo, record, index)
250                                                    { 
251                                                        var curr = record.data.bankaccnt_curr_id_curr_abbr;
252                                                        var col = _this.grid.colModel.config.length -1;
253                                                        
254                                                        _this.grid.colModel.setColumnHeader(col, 'Balance (' + curr +')');
255                                                        
256                                                        _this.grid.ds.removeAll();
257                                                        
258                                                        _this.wgrid.footer.onClick('first');
259                                                    }
260                                         },
261                                         items : [
262
263                                         ]
264
265                                     },
266                                         {
267                                         '|xns' : 'Roo.Toolbar',
268                                         text : "Download",
269                                         xtype : 'Button',
270                                         xns : Roo.Toolbar,
271                                         listeners : {
272                                                 click : function (_self, e)
273                                                    {
274                                                        var o = {params : {}}; 
275                                                        if (!_this.bankacct.getValue()) {
276                                                            return false;
277                                                        }
278                                                        o.params._group = 'bankrec';
279                                                        o.params._name = 'all';
280                                                        o.params['bankaccntid:number'] =     _this.bankacct.getValue();
281                                                        o.params['_sum_prev'] = 'amount';
282                                                         o.url = baseURL + '/Roo/Metasql';
283                                                         o.method = 'GET';
284                                                         
285                                                         var cols = {
286                                                            'cleared' : 'Cleared',
287                                                            'sortdate' : 'Date',
288                                                            'doc_type' : 'Doctype',
289                                                            'doc_number' : 'Doc number',
290                                                            'notes' : 'Notes',
291                                                            'doc_curr' : 'Currency',
292                                                            'base_amount' : 'Base Amount',
293                                                            'doc_exchrate' : 'Exchange Rate',
294                                                            'amount' : 'Amount (Bank Currency)'
295                                                        };
296                                                         var n =0;
297                                                         for (var i in cols) {
298                                                            
299                                                         
300                                                            o.params['csvCols['+n+']'] =  i
301                                                            o.params['csvTitles['+n+']'] =  cols[i];
302                                                            n++;
303                                                        }
304                                                    
305                                                         
306                                                         new Pman.Download(o);
307                                                        Roo.MessageBox.alert("Notice", "Should be downloading now");
308                                                    }
309                                         }
310                                     },
311                                         {
312                                         '|xns' : 'Roo.Toolbar',
313                                         xtype : 'Fill',
314                                         xns : Roo.Toolbar
315                                     }
316                                 ]
317
318                             },
319                             '|xns' : 'Roo.grid',
320                             autoExpandColumn : 'notes',
321                             xtype : 'EditorGrid',
322                             loadMask : true,
323                             clicksToEdit : 1,
324                             xns : Roo.grid,
325                             colModel : [
326                                  {
327                                         '|xns' : 'Roo.grid',
328                                         xtype : 'ColumnModel',
329                                         header : 'Cleared',
330                                         width : 50,
331                                         renderer : function(v,x,r) { 
332                                             if (r.data.bankrec_posted) {
333                                                 return 'POSTED';
334                                             }
335                                         
336                                             var state = v   ?  '-checked' : '';
337                                                                             
338                                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
339                                          },
340                                         xns : Roo.grid,
341                                         dataIndex : 'cleared'
342                                     },
343 {
344                                         '|xns' : 'Roo.grid',
345                                         xtype : 'ColumnModel',
346                                         header : 'Date',
347                                         width : 75,
348                                         renderer : function(v) {   
349                                         
350                                             return v ? Date.parseDate(v,'Y-m-d').format('d/M/Y') : '';
351                                          },
352                                         xns : Roo.grid,
353                                         dataIndex : 'sortdate'
354                                     },
355 {
356                                         '|xns' : 'Roo.grid',
357                                         xtype : 'ColumnModel',
358                                         header : 'Doctype',
359                                         width : 50,
360                                         renderer : function(v) { return String.format('{0}', v); },
361                                         xns : Roo.grid,
362                                         dataIndex : 'doc_type'
363                                     },
364 {
365                                         '|xns' : 'Roo.grid',
366                                         xtype : 'ColumnModel',
367                                         header : 'Doc Number',
368                                         width : 120,
369                                         renderer : function(v) { return String.format('{0}', v); },
370                                         xns : Roo.grid,
371                                         dataIndex : 'doc_number'
372                                     },
373 {
374                                         '|xns' : 'Roo.grid',
375                                         xtype : 'ColumnModel',
376                                         header : 'Notes',
377                                         width : 200,
378                                         renderer : function(v) { return String.format('{0}', v); },
379                                         xns : Roo.grid,
380                                         dataIndex : 'notes'
381                                     },
382 {
383                                         '|xns' : 'Roo.grid',
384                                         xtype : 'ColumnModel',
385                                         header : 'Currency',
386                                         width : 75,
387                                         renderer : function(v) { return String.format('{0}', v); },
388                                         xns : Roo.grid,
389                                         dataIndex : 'doc_curr'
390                                     },
391 {
392                                         '|xns' : 'Roo.grid',
393                                         align : 'right',
394                                         xtype : 'ColumnModel',
395                                         header : 'Exchange Rate',
396                                         width : 75,
397                                         renderer : function(v) { return String.format('{0}', v ? (v*1).toFixed(3) : ''); },
398                                         xns : Roo.grid,
399                                         dataIndex : 'doc_exchrate'
400                                     },
401 {
402                                         '|xns' : 'Roo.grid',
403                                         align : 'right',
404                                         xtype : 'ColumnModel',
405                                         header : 'Base Amount',
406                                         width : 120,
407                                         renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v*1,2)); },
408                                         xns : Roo.grid,
409                                         dataIndex : 'base_amount'
410                                     },
411 {
412                                         editor : {
413                                             field : {
414                                                 '|xns' : 'Roo.form',
415                                                 xtype : 'NumberField',
416                                                 cls : 'align-right',
417                                                 decimalPrecision : 2,
418                                                 xns : Roo.form
419                                             },
420                                             '|xns' : 'Roo.grid',
421                                             xtype : 'GridEditor',
422                                             xns : Roo.grid,
423                                             items : [
424
425                                             ]
426
427                                         },
428                                         '|xns' : 'Roo.grid',
429                                         align : 'right',
430                                         xtype : 'ColumnModel',
431                                         header : 'Credit',
432                                         width : 120,
433                                         renderer : function(v,x,r) { 
434                                             if (r.data.doc_type == 'BF') {
435                                                 return '';
436                                             }
437                                             return String.format('{0}', v > 0 ? Roo.util.Format.number(v*1,2)   : ''); },
438                                         xns : Roo.grid,
439                                         dataIndex : 'amount',
440                                         items : [
441
442                                         ]
443
444                                     },
445 {
446                                         editor : {
447                                             field : {
448                                                 '|xns' : 'Roo.form',
449                                                 xtype : 'NumberField',
450                                                 cls : 'align-right',
451                                                 decimalPrecision : 2,
452                                                 xns : Roo.form
453                                             },
454                                             '|xns' : 'Roo.grid',
455                                             xtype : 'GridEditor',
456                                             xns : Roo.grid,
457                                             items : [
458
459                                             ]
460
461                                         },
462                                         '|xns' : 'Roo.grid',
463                                         align : 'right',
464                                         xtype : 'ColumnModel',
465                                         header : 'Debit',
466                                         width : 120,
467                                         renderer : function(v,x,r) { 
468                                             if (r.data.doc_type == 'BF') {
469                                                 return '';
470                                             }
471                                             return String.format('{0}', v < 0 ? Roo.util.Format.number(v*1,2): ''); },
472                                         xns : Roo.grid,
473                                         dataIndex : 'amount',
474                                         items : [
475
476                                         ]
477
478                                     },
479 {
480                                         '|xns' : 'Roo.grid',
481                                         align : 'right',
482                                         xtype : 'ColumnModel',
483                                         header : 'Balance',
484                                         width : 120,
485                                         renderer : function(v,x,r) { 
486                                             if (r.data.doc_type == 'BF') {
487                                                 return String.format('{0}', Roo.util.Format.number(v*1,2)); 
488                                             }
489                                         
490                                         
491                                             //_this.total += (v*1)
492                                              return String.format('{0}', Roo.util.Format.number(v*1,2)); 
493                                         },
494                                         xns : Roo.grid,
495                                         dataIndex : 'balance'
496                                     }
497                             ],
498                             listeners : {
499                                 beforeedit : function (e)
500                                    {
501                                        //    Roo.log(e);
502                                           var ch =  _this.grid.colModel.config[e.column].header;
503                                           var val = e.value *1;
504                                      // Roo.log(ch);
505                                      // Roo.log(val);
506                                    
507                                           if (val > 0.0 && ch == 'Debit') {
508                                                e.cancel = true;
509                                                return;
510                                            }
511                                           if (val < 0.0 && ch == 'Credit') {
512                                                e.cancel = true;
513                                                return;
514                                            }
515                                            if (e.record.data.cleared || e.record.data.bankrec_posted) {
516                                                e.cancel = true;
517                                                return;
518                                            }
519                                            
520                                            // allow start editing..
521                                    },
522                                 render : function() 
523                                    {
524                                        _this.grid = this; 
525                                        //_this.dialog = Pman.Dialog.FILL_IN
526                                        if (_this.panel.active) {
527                                           this.footer.onClick('first');
528                                        }
529                                    },
530                                 cellclick : function (_self, rowIndex, columnIndex, e)
531                                    {
532                                        var clear = function(ar) 
533                                        {
534                                            var ar_in = ar;
535                                            if (ar === true) {
536                                                ar = [];
537                                                
538                                                _this.grid.ds.each(function(rec) {
539                                                    if (rec.data.doc_type == 'BF') {
540                                                        return;
541                                                    }
542                                                    ar.push(rec);
543                                                });
544                                            }
545                                            var sortdate = false;
546                                            var data = [];
547                                            Roo.each(ar, function(rec) {
548                                                if (rec.data.cleared || rec.data.bankrec_posted) {
549                                                    return;
550                                                }
551                                                if(!sortdate){
552                                                    sortdate = rec.data.sortdate;
553                                                }
554                                                data.push({
555                                                     id : rec.data.id,
556                                                    altid : rec.data.altid,
557                                                    curr_rate : rec.data.doc_exchrate,
558                                                    amount : rec.data.amount
559                                                    
560                                                });
561                                            });
562                                           new Pman.Request({
563                                            url : baseURL + '/Roo/bankrecitem',
564                                                method : 'POST',
565                                                mask : 'Clearing',
566                                                params : {
567                                                    bankaccnt_id : _this.bankacct.getValue(),
568                                                    sortdate : sortdate,
569                                                    set_clear : Roo.encode(data)
570                                                },
571                                                success : function() {
572                                                    Roo.each(ar, function(rec) {
573                                                        rec.set('cleared', true);
574                                                    });
575                                                    if (ar_in === true) {
576                                                        _this.grid.ds.getAt(0).set('cleared', true);
577                                                    }
578                                                    _this.wgrid.footer.onClick('refresh');
579                                                }
580                                            });
581                                        }
582                                        
583                                        
584                                        var unclear = function(ar)
585                                        {
586                                            var ar_in = ar;
587                                            if (ar === true) {
588                                                ar = [];
589                                                
590                                                _this.grid.ds.each(function(rec) {
591                                                    if (rec.data.doc_type == 'BF') {
592                                                        return;
593                                                    }
594                                                    ar.push(rec);
595                                                });
596                                            }
597                                            var sortdate = false;
598                                            var data = [];
599                                            Roo.each(ar, function(rec) {
600                                                if (!rec.data.cleared  || rec.data.bankrec_posted) {
601                                                    return;
602                                                }
603                                                if(!sortdate){
604                                                    sortdate = rec.data.sortdate;
605                                                }
606                                                data.push({
607                                                    id : rec.data.id,
608                                                    altid : rec.data.altid                
609                                                });
610                                            });
611                                    
612                                            new Pman.Request({
613                                                url : baseURL + '/Roo/bankrecitem',
614                                                method : 'POST',
615                                                mask : 'Clearing',
616                                                params : {
617                                                    bankaccnt_id : _this.bankacct.getValue(),
618                                                    sortdate : sortdate,
619                                                    remove_clear :Roo.encode(data)
620                                                    
621                                                },
622                                                success : function() {
623                                                    Roo.each(ar, function(rec) {
624                                                        rec.set('cleared', false);
625                                                    });
626                                                   if (ar_in === true) {
627                                                        _this.grid.ds.getAt(0).set('cleared', false);
628                                                    }  
629                                                    _this.wgrid.footer.onClick('refresh');
630                                                }
631                                            });
632                                         
633                                          
634                                        };
635                                        
636                                        
637                                        
638                                        var di = this.colModel.config[columnIndex].dataIndex;
639                                        if (di != 'cleared') {
640                                            return;
641                                        }
642                                        var  rec = this.ds.getAt(rowIndex);
643                                        if (rec.data.doc_type == 'BF') {
644                                        
645                                            if (rec.data.cleared) {
646                                                unclear(true);
647                                            
648                                            } else {
649                                                clear(true);
650                                            }
651                                        
652                                            return;
653                                        }
654                                        
655                                            
656                                            
657                                        if (rec.data.cleared) {
658                                        
659                                            unclear([rec]);
660                                            return;
661                                            
662                                        }
663                                        
664                                        clear([rec]);
665                                        
666                                        
667                                         
668                                             
669                                      
670                                    },
671                                 afteredit : function (e)
672                                    {
673                                    
674                                        if (e.cancel) {
675                                            return;
676                                        }
677                                           var ch =  _this.grid.colModel.config[e.column].header;
678                                               var val = e.originalValue *1;
679                                          // Roo.log(ch);
680                                          // Roo.log(val);
681                                    
682                                           if (val > 0.0 && ch == 'Debit') {
683                                                e.cancel = true;
684                                                return;
685                                            }
686                                           if (val < 0.0 && ch == 'Credit') {
687                                                e.cancel = true;
688                                                return;
689                                            }
690                                            if (e.record.data.cleared || e.record.data.bankrec_posted) {
691                                                e.cancel = true;
692                                                return;
693                                            }
694                                            if (val > 0.0 && e.value < 0.0) {
695                                            Roo.log("CANCEL");  
696                                                e.record.set('amount', e.originalValue);
697                                                e.cancel = true;
698                                                return;
699                                            }
700                                            if (val < 0.0 && e.value > 0.0) {
701                                            Roo.log("CANCEL");
702                                                e.record.set('amount', e.originalValue);
703                                                e.cancel = true;
704                                                return;
705                                            } 
706                                            if (e.originalValue*1 == e.value*1) {
707                                                return;
708                                            }
709                                              
710                                            e.record.set('doc_exchrate', Math.abs(e.value  * 1)  / Math.abs(e.record.data.base_amount * 1));
711                                            Roo.log(e.record);
712                                            
713                                            _this.grid.ds.updateBalance();
714                                            // send it down the line...
715                                            new Pman.Request({
716                                                method : 'POST',
717                                                url : baseURL + '/Roo/bankrecitem',
718                                                mask : 'Saving',
719                                                params : {
720                                                    bankaccnt_id : _this.bankacct.getValue(),
721                                                    set_amount : Math.abs(e.value),
722                                                    sortdate : e.record.data.sortdate,
723                                                    source_id : e.record.data.id,
724                                                    altid : e.record.data.altid
725                                                }
726                                            
727                                            });
728                                            
729                                             
730                                            
731                                            
732                                    }
733                             },
734                             items : [
735
736                             ]
737
738                         },
739                         '|xns' : 'Roo',
740                         fitToframe : true,
741                         background : true,
742                         region : 'center',
743                         title : "Bank Reconcile",
744                         xtype : 'GridPanel',
745                         fitContainer : true,
746                         xns : Roo,
747                         tableName : 'metasql',
748                         listeners : {
749                                 activate : function() {
750                                        _this.panel = this;
751                                        if (_this.grid) {
752                                            _this.grid.footer.onClick('first');
753                                        }
754                                    }
755                         },
756                         items : [
757
758                         ]
759
760                     },
761                         {
762                         grid : {
763                             toolbar : {
764                                 '|xns' : 'Roo',
765                                 xtype : 'Toolbar',
766                                 xns : Roo,
767                                 items : [
768                                         {
769                                         '|xns' : 'Roo.form',
770                                         format : 'M Y',
771                                         useIso : true,
772                                         xtype : 'MonthField',
773                                         allowBlank : true,
774                                         width : 150,
775                                         xns : Roo.form,
776                                         listeners : {
777                                                 render : function (_self)
778                                                    {
779                                                        _this.monthSel = _self;
780                                                    },
781                                                 select : function (combo, date)
782                                                    {
783                                                        _this.grid.ds.removeAll();
784                                                        _this.wgrid.footer.onClick('first');
785                                                    }
786                                         }
787                                     },
788                                         {
789                                         '|xns' : 'Roo.Toolbar',
790                                         xtype : 'Button',
791                                         cls : 'x-btn-icon',
792                                         icon : rootURL + '/Pman/templates/images/edit-clear.gif',
793                                         xns : Roo.Toolbar,
794                                         listeners : {
795                                                 click : function (_self, e)
796                                                    {
797                                                        _this.monthSel.setValue('');
798                                                        _this.grid.ds.removeAll();\r
799                                                        _this.wgrid.footer.onClick('first');\r
800                                                    }
801                                         }
802                                     },
803                                         {
804                                         '|xns' : 'Roo.Toolbar',
805                                         xtype : 'Fill',
806                                         xns : Roo.Toolbar
807                                     },
808                                         {
809                                         menu : {
810                                             '|xns' : 'Roo.menu',
811                                             xtype : 'Menu',
812                                             xns : Roo.menu,
813                                             items : [
814                                                 {
815                                                     '|xns' : 'Roo.menu',
816                                                     text : "Fix historical data",
817                                                     xtype : 'Item',
818                                                     cls : 'x-btn-text-icon',
819                                                     icon : Roo.rootURL + 'images/default/tree/leaf.gif',
820                                                     xns : Roo.menu,
821                                                     listeners : {
822                                                         click : function (_self, e)
823                                                            {
824                                                            
825                                                                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",
826                                                                    function (res) {
827                                                                        if(res!='yes') {
828                                                                            return;
829                                                                        
830                                                                        }
831                                                                        new Pman.Request({
832                                                                            url : baseURL + '/Roo/Bankrec.php',
833                                                                            method :'POST',
834                                                                            params : {
835                                                                                _fix : 1
836                                                                            },
837                                                                            success : function() {
838                                                                                if(_this.wgrid){
839                                                                                    _this.wgrid.footer.onClick('refresh');
840                                                                                }
841                                                                                Roo.MessageBox.alert('Notice', 'FIXED');
842                                                                            }
843                                                                        });
844                                                                });
845                                                            
846                                                            }
847                                                     }
848                                                 },
849                                                 {
850                                                     '|xns' : 'Roo.menu',
851                                                     text : "Fix Closed Periods",
852                                                     xtype : 'Item',
853                                                     cls : 'x-btn-text-icon',
854                                                     icon : Roo.rootURL + 'images/default/tree/leaf.gif',
855                                                     xns : Roo.menu,
856                                                     listeners : {
857                                                         click : function (_self, e)
858                                                            {
859                                                            
860                                                                Roo.MessageBox.confirm("Confirm", "Are you sure you want?",
861                                                                    function (res) {
862                                                                        if(res!='yes') {
863                                                                            return;
864                                                                        
865                                                                        }
866                                                                        new Pman.Request({
867                                                                            url : baseURL + '/Roo/Bankrec.php',
868                                                                            method :'POST',
869                                                                            params : {
870                                                                                _closedPeriod : 1
871                                                                            },
872                                                                            success : function() {
873                                                                                if(_this.wgrid){
874                                                                                    _this.wgrid.footer.onClick('refresh');
875                                                                                }
876                                                                                Roo.MessageBox.alert('Notice', 'DONE');
877                                                                            }
878                                                                        });
879                                                                });
880                                                            
881                                                            }
882                                                     }
883                                                 }
884                                             ]
885
886                                         },
887                                         '|xns' : 'Roo.Toolbar',
888                                         text : "Fix Data",
889                                         xtype : 'Button',
890                                         cls : 'x-btn-text-icon',
891                                         icon : Roo.rootURL + 'images/default/tree/leaf.gif',
892                                         xns : Roo.Toolbar,
893                                         items : [
894
895                                         ]
896
897                                     }
898                                 ]
899
900                             },
901                             sm : {
902                                 '|xns' : 'Roo.grid',
903                                 xtype : 'RowSelectionModel',
904                                 singleSelect : true,
905                                 xns : Roo.grid,
906                                 listeners : {
907                                         selectionchange : function (_self)
908                                            {
909                                                _this.grid.footer.onClick('first');
910                                            }
911                                 }
912                             },
913                             dataSource : {
914                                 proxy : {
915                                     '|xns' : 'Roo.data',
916                                     url : baseURL + '/Roo/metasql.php',
917                                     method : 'GET',
918                                     xtype : 'HttpProxy',
919                                     timeout : 900000,
920                                     xns : Roo.data
921                                 },
922                                 reader : {
923                                     '|xns' : 'Roo.data',
924                                     id : 'id',
925                                     root : 'data',
926                                     xtype : 'JsonReader',
927                                     fields : [
928                                         {
929                                             'name': 'sortdate',
930                                             'type': 'string'
931                                         }
932                                     ],
933                                     xns : Roo.data,
934                                     totalProperty : 'total'
935                                 },
936                                 '|xns' : 'Roo.data',
937                                 xtype : 'Store',
938                                 remoteSort : true,
939                                 sortInfo : { field : 'sotrdate', direction: 'ASC' },
940                                 xns : Roo.data,
941                                 listeners : {
942                                         beforeload : function (_self, o)
943                                            {
944                                            
945                                                if (!_this.bankacct.getValue()) {
946                                                    return false;
947                                                }
948                                                var dt = _this.monthSel.getValue();
949                                                
950                                                if(dt.length){
951                                                    o.params['sortdate:text'] = typeof(dt) == 'string' ? dt : dt.format('Y-m-d');
952                                                }
953                                                o.params._group = 'bankrec';
954                                                o.params._name = 'bydate';
955                                                o.params['bankaccntid:number'] =  _this.bankacct.getValue();
956                                                
957                                            
958                                                
959                                            },
960                                         load : function (_self, records, options, res)
961                                            {   
962                                                var sm = _this.wgrid.getSelectionModel();
963                                                
964                                                if(_this.wgrid.lastSelectedRow * 1 >0){
965                                                    sm.selectRow(_this.wgrid.lastSelectedRow);
966                                                    return;
967                                                }
968                                                
969                                                if (!sm.getSelections().length) {
970                                                    sm.selectFirstRow();
971                                                }
972                                            
973                                            }
974                                 },
975                                 items : [
976
977                                 ]
978
979                             },
980                             footer : {
981                                 '|xns' : 'Roo',
982                                 pageSize : 25,
983                                 xtype : 'PagingToolbar',
984                                 emptyMsg : "No Date found",
985                                 xns : Roo,
986                                 displayMsg : "Displaying Date{0} - {1} of {2}",
987                                 displayInfo : false
988                             },
989                             '|xns' : 'Roo.grid',
990                             autoExpandColumn : 'sortdate',
991                             xtype : 'Grid',
992                             loadMask : true,
993                             xns : Roo.grid,
994                             colModel : [
995                                  {
996                                         '|xns' : 'Roo.grid',
997                                         xtype : 'ColumnModel',
998                                         header : 'Date',
999                                         width : 100,
1000                                         renderer : function(v) {   
1001                                         
1002                                             return v ? Date.parseDate(v,'Y-m-d').format('d/M/Y') : '';
1003                                          },
1004                                         xns : Roo.grid,
1005                                         dataIndex : 'sortdate'
1006                                     },
1007 {
1008                                         '|xns' : 'Roo.grid',
1009                                         align : 'right',
1010                                         xtype : 'ColumnModel',
1011                                         header : 'Closing Balance',
1012                                         width : 120,
1013                                         renderer : function(v,x,r) { 
1014                                             
1015                                             var color = 'red'; // has some not 'ticked'
1016                                             
1017                                             if(r.data.no_records - r.data.no_posted == 0){ // all posted on that date
1018                                                 color = 'black';
1019                                             }
1020                                             if(r.data.no_records - r.data.no_cleared == 0 && r.data.no_posted != r.data.no_cleared){ // has 'ticked' or posted
1021                                                 color = 'blue';
1022                                             }
1023                                             
1024                                             return String.format('<span style="color:{0}">{1}</span>', color, Roo.util.Format.number(v*1,2)); 
1025                                         },
1026                                         xns : Roo.grid,
1027                                         dataIndex : 'balance'
1028                                     },
1029 {
1030                                         '|xns' : 'Roo.grid',
1031                                         align : 'right',
1032                                         xtype : 'ColumnModel',
1033                                         header : 'Reconciled',
1034                                         width : 100,
1035                                         renderer : function(v,x,r) { 
1036                                             
1037                                             if(!v){
1038                                                 return '';
1039                                             }
1040                                             
1041                                             if((r.data.no_records * 1 != r.data.no_posted * 1) || r.data.balance * 1 != v * 1){ // not match
1042                                                 
1043                                                 return '<span style="color:red;font-weight:bold">' + Roo.util.Format.number(v*1,2); 
1044                                             }
1045                                             
1046                                             return String.format('<span style="color:black">{0}</span>', Roo.util.Format.number(v*1,2)); 
1047                                                 
1048                                          },
1049                                         xns : Roo.grid,
1050                                         dataIndex : 'reconciled'
1051                                     },
1052 {
1053                                         '|xns' : 'Roo.grid',
1054                                         align : 'right',
1055                                         xtype : 'ColumnModel',
1056                                         header : 'Post?',
1057                                         width : 50,
1058                                         renderer : function(v,x,r) { 
1059                                             var state = v  ?  '-checked' : '';
1060                                         
1061                                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
1062                                          },
1063                                         xns : Roo.grid,
1064                                         dataIndex : 'is_reconciled'
1065                                     }
1066                             ],
1067                             listeners : {
1068                                 render : function() 
1069                                    {
1070                                        _this.wgrid = this; 
1071                                        //_this.dialog = Pman.Dialog.FILL_IN
1072                                        //if (_this.wpanel.active) {
1073                                        //   this.footer.onClick('first');
1074                                        //}
1075                                    },
1076                                 cellclick : function (_self, rowIndex, columnIndex, e)
1077                                    {
1078                                        var di = this.colModel.getDataIndex(columnIndex);
1079                                    
1080                                        if (di != 'is_reconciled') {
1081                                            return;
1082                                        }
1083                                         
1084                                        var rec = this.ds.getAt(rowIndex);
1085                                        
1086                                        var voidit = function(){
1087                                            new Pman.Request({
1088                                                url : baseURL + '/Roo/Bankrec.php',
1089                                                method :'POST',
1090                                                params : {
1091                                                    _void : 1,
1092                                                    bankaccnt_id : _this.bankacct.getValue(),
1093                                                    sotrdate : rec.data.sortdate
1094                                                    
1095                                                },
1096                                                success : function() {
1097                                                    _this.wgrid.footer.onClick('refresh');
1098                                                }
1099                                            });
1100                                        }
1101                                        
1102                                        var postit = function(){
1103                                            new Pman.Request({
1104                                                url : baseURL + '/Roo/Bankrec.php',
1105                                                method :'POST',
1106                                                params : {
1107                                                    _post : 1,
1108                                                    bankaccnt_id : _this.bankacct.getValue(),
1109                                                    sotrdate : rec.data.sortdate
1110                                                    
1111                                                },
1112                                                success : function() {
1113                                                    _this.wgrid.footer.onClick('refresh');
1114                                                }
1115                                            });
1116                                        
1117                                        }
1118                                        
1119                                        if(rec.data.is_reconciled == 1){
1120                                            voidit();
1121                                            return;
1122                                        }
1123                                        
1124                                        postit();
1125                                        return;
1126                                        
1127                                        
1128                                        
1129                                    },
1130                                 rowclick : function (_self, rowIndex, e)
1131                                    {
1132                                        
1133                                         _this.wgrid.lastSelectedRow = rowIndex;
1134                                        
1135                                    }
1136                             },
1137                             items : [
1138
1139                             ]
1140
1141                         },
1142                         '|xns' : 'Roo',
1143                         fitToframe : true,
1144                         background : true,
1145                         region : 'west',
1146                         title : "Pick a Date",
1147                         xtype : 'GridPanel',
1148                         fitContainer : true,
1149                         xns : Roo,
1150                         tableName : 'Groups',
1151                         listeners : {
1152                                 activate : function() {
1153                                        _this.wpanel = this;
1154                                        //if (_this.wgrid) {
1155                                        //    _this.wgrid.footer.onClick('first');
1156                                        //}
1157                                    }
1158                         },
1159                         items : [
1160
1161                         ]
1162
1163                     }
1164                 ]
1165
1166             },
1167             '|xns' : 'Roo',
1168             background : true,
1169             xtype : 'NestedLayoutPanel',
1170             title : "Bank Reconcile",
1171             xns : Roo,
1172             items : [
1173
1174             ]
1175
1176         };    }
1177 });