Fix #7123 - getting abra ready to test
[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      xns : Roo,
30      width : 400,
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          method : 'GET',
44          xtype : 'HttpProxy',
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             xtype : 'HttpProxy',
193             method : 'GET',
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_name',
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_name',
240           qtip : "Select bankaccnt",
241           queryParam : '',
242           tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{bankaccnt_bankname}</b> {bankaccnt_name} - {bankaccnt_descrip}  {bankaccnt_accntnumber}</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           width : 50,
330           header : 'Cleared',
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           width : 75,
347           header : 'Date',
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           width : 50,
359           header : 'Doctype',
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           width : 120,
368           header : 'Doc Number',
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           width : 200,
377           header : 'Notes',
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           width : 75,
386           header : 'Currency',
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         cellclick : function (_self, rowIndex, columnIndex, e)
523          {
524              var clear = function(ar) 
525              {
526                  var ar_in = ar;
527                  if (ar === true) {
528                      ar = [];
529                      
530                      _this.grid.ds.each(function(rec) {
531                          if (rec.data.doc_type == 'BF') {
532                              return;
533                          }
534                          ar.push(rec);
535                      });
536                  }
537                  var sortdate = false;
538                  var data = [];
539                  Roo.each(ar, function(rec) {
540                      if (rec.data.cleared || rec.data.bankrec_posted) {
541                          return;
542                      }
543                      if(!sortdate){
544                          sortdate = rec.data.sortdate;
545                      }
546                      data.push({
547                           id : rec.data.id,
548                          altid : rec.data.altid,
549                          curr_rate : rec.data.doc_exchrate,
550                          amount : rec.data.amount
551                          
552                      });
553                  });
554                 new Pman.Request({
555                  url : baseURL + '/Roo/bankrecitem',
556                      method : 'POST',
557                      mask : 'Clearing',
558                      params : {
559                          bankaccnt_id : _this.bankacct.getValue(),
560                          sortdate : sortdate,
561                          set_clear : Roo.encode(data)
562                      },
563                      success : function() {
564                          Roo.each(ar, function(rec) {
565                              rec.set('cleared', true);
566                          });
567                          if (ar_in === true) {
568                              _this.grid.ds.getAt(0).set('cleared', true);
569                          }
570                          _this.wgrid.footer.onClick('refresh');
571                      }
572                  });
573              }
574              
575              
576              var unclear = function(ar)
577              {
578                  var ar_in = ar;
579                  if (ar === true) {
580                      ar = [];
581                      
582                      _this.grid.ds.each(function(rec) {
583                          if (rec.data.doc_type == 'BF') {
584                              return;
585                          }
586                          ar.push(rec);
587                      });
588                  }
589                  var sortdate = false;
590                  var data = [];
591                  Roo.each(ar, function(rec) {
592                      if (!rec.data.cleared  || rec.data.bankrec_posted) {
593                          return;
594                      }
595                      if(!sortdate){
596                          sortdate = rec.data.sortdate;
597                      }
598                      data.push({
599                          id : rec.data.id,
600                          altid : rec.data.altid                
601                      });
602                  });
603          
604                  new Pman.Request({
605                      url : baseURL + '/Roo/bankrecitem',
606                      method : 'POST',
607                      mask : 'Clearing',
608                      params : {
609                          bankaccnt_id : _this.bankacct.getValue(),
610                          sortdate : sortdate,
611                          remove_clear :Roo.encode(data)
612                          
613                      },
614                      success : function() {
615                          Roo.each(ar, function(rec) {
616                              rec.set('cleared', false);
617                          });
618                         if (ar_in === true) {
619                              _this.grid.ds.getAt(0).set('cleared', false);
620                          }  
621                          _this.wgrid.footer.onClick('refresh');
622                      }
623                  });
624               
625                
626              };
627              
628              
629              
630              var di = this.colModel.config[columnIndex].dataIndex;
631              if (di != 'cleared') {
632                  return;
633              }
634              var  rec = this.ds.getAt(rowIndex);
635              if (rec.data.doc_type == 'BF') {
636              
637                  if (rec.data.cleared) {
638                      unclear(true);
639                  
640                  } else {
641                      clear(true);
642                  }
643              
644                  return;
645              }
646              
647                  
648                  
649              if (rec.data.cleared) {
650              
651                  unclear([rec]);
652                  return;
653                  
654              }
655              
656              clear([rec]);
657              
658              
659               
660                   
661            
662          },
663         render : function() 
664          {
665              _this.grid = this; 
666              //_this.dialog = Pman.Dialog.FILL_IN
667              if (_this.panel.active) {
668                 this.footer.onClick('first');
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       region : 'center',
741       fitToframe : true,
742       background : true,
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           xtype : 'MonthField',
772           useIso : true,
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          xtype : 'HttpProxy',
918          method : 'GET',
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           width : 100,
999           header : 'Date',
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       region : 'west',
1144       fitToframe : true,
1145       background : true,
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    title : "Bank Reconcile",
1170    xtype : 'NestedLayoutPanel',
1171    xns : Roo,
1172    items : [
1173
1174    ]
1175
1176   };  }
1177 });