commit
[Pman.Xtuple] / Pman.Tab.XtupleReconcile.js
index eadc596..c5e9122 100644 (file)
@@ -2,9 +2,11 @@
 
 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
 
+Roo.namespace('Pman.Tab');
+
 Pman.Tab.XtupleReconcile = new Roo.XComponent({
-    part     :  ["Xtuple","Reconcile"],
-    order    : '105-Pman.Tab.XtupleReconcile',
+    part     :  ["Xtuple", "Reconcile" ],
+    order    : '200-Pman.Tab.XtupleReconcile',
     region   : 'center',
     parent   : 'Pman.Tab.XtupleAccountsTab',
     name     : "Pman.Tab.XtupleReconcile",
@@ -15,363 +17,38 @@ Pman.Tab.XtupleReconcile = new Roo.XComponent({
         var _this = this;
         var MODULE = this;
         return {
-            xtype: 'NestedLayoutPanel',
-            xns: Roo,
-            background : true,
-            title : "Bank Reconcile",
             layout : {
-                xtype: 'BorderLayout',
-                xns: Roo,
+                center : {
+                    '|xns' : 'Roo',
+                    xtype : 'LayoutRegion',
+                    xns : Roo
+                },
+                west : {
+                    '|xns' : 'Roo',
+                    xtype : 'LayoutRegion',
+                    width : 400,
+                    xns : Roo,
+                    split : true
+                },
+                '|xns' : 'Roo',
+                xtype : 'BorderLayout',
+                xns : Roo,
                 items : [
-                    {
-                        xtype: 'GridPanel',
-                        xns: Roo,
-                        listeners : {
-                            activate : function() {
-                                _this.panel = this;
-                                if (_this.grid) {
-                                    _this.grid.footer.onClick('first');
-                                }
-                            }
-                        },
-                        background : true,
-                        fitContainer : true,
-                        fitToframe : true,
-                        region : 'center',
-                        tableName : 'metasql',
-                        title : "Bank Reconcile",
+                       {
                         grid : {
-                            xtype: 'EditorGrid',
-                            xns: Roo.grid,
-                            listeners : {
-                                render : function() 
-                                {
-                                    _this.grid = this; 
-                                    //_this.dialog = Pman.Dialog.FILL_IN
-                                    if (_this.panel.active) {
-                                       this.footer.onClick('first');
-                                    }
-                                },
-                                cellclick : function (_self, rowIndex, columnIndex, e)
-                                {
-                                    var clear = function(ar) 
-                                    {
-                                        var ar_in = ar;
-                                        if (ar === true) {
-                                            ar = [];
-                                            
-                                            _this.grid.ds.each(function(rec) {
-                                                if (rec.data.doc_type == 'BF') {
-                                                    return;
-                                                }
-                                                ar.push(rec);
-                                            });
-                                        }
-                                        var sortdate = false;
-                                        var data = [];
-                                        Roo.each(ar, function(rec) {
-                                            if (rec.data.cleared || rec.data.bankrec_posted) {
-                                                return;
-                                            }
-                                            if(!sortdate){
-                                                sortdate = rec.data.sortdate;
-                                            }
-                                            data.push({
-                                                 id : rec.data.id,
-                                                altid : rec.data.altid,
-                                                curr_rate : rec.data.doc_exchrate,
-                                                amount : rec.data.amount
-                                                
-                                            });
-                                        });
-                                       new Pman.Request({
-                                        url : baseURL + '/Roo/bankrecitem',
-                                            method : 'POST',
-                                            mask : 'Clearing',
-                                            params : {
-                                                bankaccnt_id : _this.bankacct.getValue(),
-                                                sortdate : sortdate,
-                                                set_clear : Roo.encode(data)
-                                            },
-                                            success : function() {
-                                                Roo.each(ar, function(rec) {
-                                                    rec.set('cleared', true);
-                                                });
-                                                if (ar_in === true) {
-                                                    _this.grid.ds.getAt(0).set('cleared', true);
-                                                }
-                                                _this.wgrid.footer.onClick('refresh');
-                                            }
-                                        });
-                                    }
-                                    
-                                    
-                                    var unclear = function(ar)
-                                    {
-                                        var ar_in = ar;
-                                        if (ar === true) {
-                                            ar = [];
-                                            
-                                            _this.grid.ds.each(function(rec) {
-                                                if (rec.data.doc_type == 'BF') {
-                                                    return;
-                                                }
-                                                ar.push(rec);
-                                            });
-                                        }
-                                        var sortdate = false;
-                                        var data = [];
-                                        Roo.each(ar, function(rec) {
-                                            if (!rec.data.cleared  || rec.data.bankrec_posted) {
-                                                return;
-                                            }
-                                            if(!sortdate){
-                                                sortdate = rec.data.sortdate;
-                                            }
-                                            data.push({
-                                                id : rec.data.id,
-                                                altid : rec.data.altid                
-                                            });
-                                        });
-                                
-                                        new Pman.Request({
-                                            url : baseURL + '/Roo/bankrecitem',
-                                            method : 'POST',
-                                            mask : 'Clearing',
-                                            params : {
-                                                bankaccnt_id : _this.bankacct.getValue(),
-                                                sortdate : sortdate,
-                                                remove_clear :Roo.encode(data)
-                                                
-                                            },
-                                            success : function() {
-                                                Roo.each(ar, function(rec) {
-                                                    rec.set('cleared', false);
-                                                });
-                                               if (ar_in === true) {
-                                                    _this.grid.ds.getAt(0).set('cleared', false);
-                                                }  
-                                                _this.wgrid.footer.onClick('refresh');
-                                            }
-                                        });
-                                     
-                                      
-                                    };
-                                    
-                                    
-                                    
-                                    var di = this.colModel.config[columnIndex].dataIndex;
-                                    if (di != 'cleared') {
-                                        return;
-                                    }
-                                    var  rec = this.ds.getAt(rowIndex);
-                                    if (rec.data.doc_type == 'BF') {
-                                    
-                                        if (rec.data.cleared) {
-                                            unclear(true);
-                                        
-                                        } else {
-                                            clear(true);
-                                        }
-                                    
-                                        return;
-                                    }
-                                    
-                                        
-                                        
-                                    if (rec.data.cleared) {
-                                    
-                                        unclear([rec]);
-                                        return;
-                                        
-                                    }
-                                    
-                                    clear([rec]);
-                                    
-                                    
-                                     
-                                         
-                                  
-                                },
-                                beforeedit : function (e)
-                                {
-                                    //    Roo.log(e);
-                                       var ch =  _this.grid.colModel.config[e.column].header;
-                                       var val = e.value *1;
-                                  // Roo.log(ch);
-                                  // Roo.log(val);
-                                
-                                       if (val > 0.0 && ch == 'Debit') {
-                                            e.cancel = true;
-                                            return;
-                                        }
-                                       if (val < 0.0 && ch == 'Credit') {
-                                            e.cancel = true;
-                                            return;
-                                        }
-                                        if (e.record.data.cleared || e.record.data.bankrec_posted) {
-                                            e.cancel = true;
-                                            return;
-                                        }
-                                        
-                                        // allow start editing..
-                                },
-                                afteredit : function (e)
-                                {
-                                
-                                    if (e.cancel) {
-                                        return;
-                                    }
-                                       var ch =  _this.grid.colModel.config[e.column].header;
-                                           var val = e.originalValue *1;
-                                      // Roo.log(ch);
-                                      // Roo.log(val);
-                                
-                                       if (val > 0.0 && ch == 'Debit') {
-                                            e.cancel = true;
-                                            return;
-                                        }
-                                       if (val < 0.0 && ch == 'Credit') {
-                                            e.cancel = true;
-                                            return;
-                                        }
-                                        if (e.record.data.cleared || e.record.data.bankrec_posted) {
-                                            e.cancel = true;
-                                            return;
-                                        }
-                                        if (val > 0.0 && e.value < 0.0) {
-                                        Roo.log("CANCEL");  
-                                            e.record.set('amount', e.originalValue);
-                                            e.cancel = true;
-                                            return;
-                                        }
-                                        if (val < 0.0 && e.value > 0.0) {
-                                        Roo.log("CANCEL");
-                                            e.record.set('amount', e.originalValue);
-                                            e.cancel = true;
-                                            return;
-                                        } 
-                                        if (e.originalValue*1 == e.value*1) {
-                                            return;
-                                        }
-                                          
-                                        e.record.set('doc_exchrate', Math.abs(e.value  * 1)  / Math.abs(e.record.data.base_amount * 1));
-                                        Roo.log(e.record);
-                                        
-                                        _this.grid.ds.updateBalance();
-                                        // send it down the line...
-                                        new Pman.Request({
-                                            method : 'POST',
-                                            url : baseURL + '/Roo/bankrecitem',
-                                            mask : 'Saving',
-                                            params : {
-                                                bankaccnt_id : _this.bankacct.getValue(),
-                                                set_amount : Math.abs(e.value),
-                                                sortdate : e.record.data.sortdate,
-                                                source_id : e.record.data.id,
-                                                altid : e.record.data.altid
-                                            }
-                                        
-                                        });
-                                        
-                                         
-                                        
-                                        
-                                }
-                            },
-                            autoExpandColumn : 'notes',
-                            clicksToEdit : 1,
-                            loadMask : true,
                             dataSource : {
-                                xtype: 'Store',
-                                xns: Roo.data,
-                                listeners : {
-                                    beforeloadadd : function (_self, records, options, res)
-                                    {
-                                     //  _this.total = 0.0;
-                                    
-                                      
-                                    
-                                    
-                                          _this.total = 1 * res.raw.amount;
-                                            _this.bf = 1 * res.raw.amount;
-                                        Roo.log("TOTAL:" + _this.total);
-                                    },
-                                    load : function (_self, records, options)
-                                    {
-                                        
-                                        var bal = _this.bf;
-                                          var cleared = true;
-                                          var posted = true;
-                                        Roo.each(records, function(rec) {
-                                            if (!rec.data.cleared) {
-                                                cleared = false;
-                                    
-                                            }
-                                            if (!rec.data.bankrec_posted) {
-                                                posted = false;
-                                            }
-                                            if (rec.data.doc_type != 'BF') {
-                                                bal += rec.data.amount *1;
-                                                rec.set('balance', bal);   
-                                            } else {
-                                                rec.set('balance', _this.bf);
-                                            }
-                                            
-                                            
-                                        });
-                                        
-                                        var rec = this.reader.newRow({
-                                            notes : 'Brought Forward',
-                                            balance : _this.bf,
-                                            doc_type : 'BF',
-                                            cleared : cleared,
-                                            bankrec_posted : posted
-                                        });
-                                        this.insert(0, [rec]);
-                                    },
-                                    beforeload : function (_self, o)
-                                    {
-                                        var s = _this.wgrid.getSelectionModel().getSelected();
-                                        
-                                        if (!s) {
-                                            return false;
-                                        }
-                                        o.params._group = 'bankrec';
-                                        o.params._name = 'all';
-                                        o.params['sortdate:text'] = s.data.sortdate;
-                                        o.params['bankaccntid:number'] =     _this.bankacct.getValue();
-                                    
-                                        o.params['_cals'] = 'amount'
-                                    }
-                                },
-                                remoteSort : true,
-                                sortInfo : { field : 'metasql_group', direction: 'ASC' },
-                                updateBalance : function() {
-                                     var bal = _this.bf;
-                                    this.each( function(rec) {
-                                        if (rec.data.doc_type != 'BF') {
-                                            bal += rec.data.amount *1;
-                                            rec.set('balance', bal);   
-                                        } else {
-                                            rec.set('balance', _this.bf);
-                                        }
-                                        
-                                        
-                                    });
-                                },
                                 proxy : {
-                                    xtype: 'HttpProxy',
-                                    xns: Roo.data,
+                                    '|xns' : 'Roo.data',
+                                    url : baseURL + '/Roo/metasql.php',
+                                    xtype : 'HttpProxy',
                                     method : 'GET',
-                                    url : baseURL + '/Roo/metasql.php'
+                                    xns : Roo.data
                                 },
                                 reader : {
-                                    xtype: 'JsonReader',
-                                    xns: Roo.data,
+                                    '|xns' : 'Roo.data',
                                     id : 'idx',
                                     root : 'data',
-                                    totalProperty : 'total',
+                                    xtype : 'JsonReader',
                                     fields : [
                                         {
                                             'name': 'metasql_id',
@@ -406,660 +83,1095 @@ Pman.Tab.XtupleReconcile = new Roo.XComponent({
                                             'name': 'metasql_grade',
                                             'type': 'int'
                                         }
-                                    ]
-                                }
+                                    ],
+                                    xns : Roo.data,
+                                    totalProperty : 'total'
+                                },
+                                '|xns' : 'Roo.data',
+                                xtype : 'Store',
+                                remoteSort : true,
+                                sortInfo : { field : 'metasql_group', direction: 'ASC' },
+                                xns : Roo.data,
+                                updateBalance : function() {
+                                     var bal = _this.bf;
+                                    this.each( function(rec) {
+                                        if (rec.data.doc_type != 'BF') {
+                                            bal += rec.data.amount *1;
+                                            rec.set('balance', bal);   
+                                        } else {
+                                            rec.set('balance', _this.bf);
+                                        }
+                                        
+                                        
+                                    });
+                                },
+                                listeners : {
+                                       beforeloadadd : function (_self, records, options, res)
+                                          {
+                                           //  _this.total = 0.0;
+                                          
+                                            
+                                          
+                                          
+                                                _this.total = 1 * res.raw.amount;
+                                                  _this.bf = 1 * res.raw.amount;
+                                              Roo.log("TOTAL:" + _this.total);
+                                          },
+                                       beforeload : function (_self, o)
+                                          {
+                                              var s = _this.wgrid.getSelectionModel().getSelected();
+                                              
+                                              if (!s) {
+                                                  return false;
+                                              }
+                                              o.params._group = 'bankrec';
+                                              o.params._name = 'all';
+                                              o.params['sortdate:text'] = s.data.sortdate;
+                                              o.params['bankaccntid:number'] =     _this.bankacct.getValue();
+                                          
+                                              o.params['_cals'] = 'amount'
+                                          },
+                                       load : function (_self, records, options)
+                                          {
+                                              
+                                              var bal = _this.bf;
+                                                var cleared = true;
+                                                var posted = true;
+                                              Roo.each(records, function(rec) {
+                                                  if (!rec.data.cleared) {
+                                                      cleared = false;
+                                          
+                                                  }
+                                                  if (!rec.data.bankrec_posted) {
+                                                      posted = false;
+                                                  }
+                                                  if (rec.data.doc_type != 'BF') {
+                                                      bal += rec.data.amount *1;
+                                                      rec.set('balance', bal);   
+                                                  } else {
+                                                      rec.set('balance', _this.bf);
+                                                  }
+                                                  
+                                                  
+                                              });
+                                              
+                                              var rec = this.reader.newRow({
+                                                  notes : 'Brought Forward',
+                                                  balance : _this.bf,
+                                                  doc_type : 'BF',
+                                                  cleared : cleared,
+                                                  bankrec_posted : posted
+                                              });
+                                              this.insert(0, [rec]);
+                                          }
+                                },
+                                items : [
+
+                                ]
+
                             },
                             footer : {
-                                xtype: 'PagingToolbar',
-                                xns: Roo,
-                                displayInfo : true,
-                                displayMsg : "Displaying records {0} - {1} of {2}",
+                                '|xns' : 'Roo',
+                                pageSize : 50,
+                                xtype : 'PagingToolbar',
                                 emptyMsg : "Nothing found",
-                                pageSize : 50
+                                xns : Roo,
+                                displayMsg : "Displaying records {0} - {1} of {2}",
+                                displayInfo : true
                             },
                             toolbar : {
-                                xtype: 'Toolbar',
-                                xns: Roo,
+                                '|xns' : 'Roo',
+                                xtype : 'Toolbar',
+                                xns : Roo,
                                 items : [
-                                    {
-                                        xtype: 'ComboBox',
-                                        xns: Roo.form,
-                                        listeners : {
-                                            render : function (_self)
-                                            {
-                                                _this.bankacct = _self;
+                                       {
+                                        store : {
+                                            proxy : {
+                                                '|xns' : 'Roo.data',
+                                                url : baseURL + '/Roo/bankaccnt.php',
+                                                method : 'GET',
+                                                xtype : 'HttpProxy',
+                                                xns : Roo.data
                                             },
-                                            select : function (combo, record, index)
-                                            { 
-                                                var curr = record.data.bankaccnt_curr_id_curr_abbr;
-                                                var col = _this.grid.colModel.config.length -1;
-                                                
-                                                _this.grid.colModel.setColumnHeader(col, 'Balance (' + curr +')');
-                                                
-                                                _this.grid.ds.removeAll();
-                                                
-                                                _this.wgrid.footer.onClick('first');
-                                            }
+                                            reader : {
+                                                '|xns' : 'Roo.data',
+                                                id : 'id',
+                                                root : 'data',
+                                                xtype : 'JsonReader',
+                                                xns : Roo.data,
+                                                fields : [{"name":"id","type":"int"},{"name":"bankaccnt_name","type":"string"}],
+                                                totalProperty : 'total'
+                                            },
+                                            '|xns' : 'Roo.data',
+                                            xtype : 'Store',
+                                            remoteSort : true,
+                                            sortInfo : { direction : 'ASC', field: 'bankaccnt_bankname' },
+                                            xns : Roo.data,
+                                            listeners : {
+                                               beforeload : function (_self, o){
+                                                      o.params = o.params || {};
+                                                      // set more here
+                                                  }
+                                            },
+                                            items : [
+
+                                            ]
+
                                         },
-                                        allowBlank : false,
-                                        displayField : 'bankaccnt_bankname',
-                                        editable : false,
-                                        emptyText : "Select bankaccnt",
+                                        '|xns' : 'Roo.form',
+                                        listWidth : 400,
+                                        triggerAction : 'all',
                                         fieldLabel : 'bankaccnt',
                                         forceSelection : true,
+                                        selectOnFocus : true,
+                                        pageSize : 50,
+                                        displayField : 'bankaccnt_bankname',
+                                        emptyText : "Select bankaccnt",
                                         hiddenName : 'bankaccnt_id',
-                                        listWidth : 400,
-                                        loadingText : "Searching...",
                                         minChars : 2,
+                                        valueField : 'bankaccnt_id',
+                                        xtype : 'ComboBox',
+                                        allowBlank : false,
+                                        typeAhead : true,
+                                        editable : false,
+                                        width : 300,
+                                        xns : Roo.form,
                                         name : 'bankaccnt_bankname',
-                                        pageSize : 50,
                                         qtip : "Select bankaccnt",
                                         queryParam : '',
-                                        selectOnFocus : true,
-                                        tpl : '<div class="x-grid-cell-text x-btn button"><b>{bankaccnt_bankname}</b> </div>',
-                                        triggerAction : 'all',
-                                        typeAhead : true,
-                                        valueField : 'bankaccnt_id',
-                                        width : 300,
-                                        store : {
-                                            xtype: 'Store',
-                                            xns: Roo.data,
-                                            listeners : {
-                                                beforeload : function (_self, o){
-                                                    o.params = o.params || {};
-                                                    // set more here
-                                                }
-                                            },
-                                            remoteSort : true,
-                                            sortInfo : { direction : 'ASC', field: 'bankaccnt_bankname' },
-                                            proxy : {
-                                                xtype: 'HttpProxy',
-                                                xns: Roo.data,
-                                                method : 'GET',
-                                                url : baseURL + '/Roo/bankaccnt.php'
-                                            },
-                                            reader : {
-                                                xtype: 'JsonReader',
-                                                xns: Roo.data,
-                                                id : 'id',
-                                                root : 'data',
-                                                totalProperty : 'total',
-                                                fields : [{"name":"id","type":"int"},{"name":"bankaccnt_name","type":"string"}]
-                                            }
-                                        }
-                                    },
-                                    {
-                                        xtype: 'Button',
-                                        xns: Roo.Toolbar,
+                                        tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{bankaccnt_bankname}</b> </div>',
+                                        loadingText : "Searching...",
                                         listeners : {
-                                            click : function (_self, e)
-                                            {
-                                                var o = {params : {}}; 
-                                                if (!_this.bankacct.getValue()) {
-                                                    return false;
-                                                }
-                                                o.params._group = 'bankrec';
-                                                o.params._name = 'all';
-                                                o.params['bankaccntid:number'] =     _this.bankacct.getValue();
-                                                o.params['_sum_prev'] = 'amount';
-                                                 o.url = baseURL + '/Roo/Metasql';
-                                                 o.method = 'GET';
-                                                 
-                                                 var cols = {
-                                                    'cleared' : 'Cleared',
-                                                    'sortdate' : 'Date',
-                                                    'doc_type' : 'Doctype',
-                                                    'doc_number' : 'Doc number',
-                                                    'notes' : 'Notes',
-                                                    'doc_curr' : 'Currency',
-                                                    'base_amount' : 'Base Amount',
-                                                    'doc_exchrate' : 'Exchange Rate',
-                                                    'amount' : 'Amount (Bank Currency)'
-                                                };
-                                                 var n =0;
-                                                 for (var i in cols) {
-                                                    
-                                                 
-                                                    o.params['csvCols['+n+']'] =  i
-                                                    o.params['csvTitles['+n+']'] =  cols[i];
-                                                    n++;
-                                                }
-                                            
-                                                 
-                                                 new Pman.Download(o);
-                                                Roo.MessageBox.alert("Notice", "Should be downloading now");
-                                            }
+                                               render : function (_self)
+                                                  {
+                                                      _this.bankacct = _self;
+                                                  },
+                                               select : function (combo, record, index)
+                                                  { 
+                                                      var curr = record.data.bankaccnt_curr_id_curr_abbr;
+                                                      var col = _this.grid.colModel.config.length -1;
+                                                      
+                                                      _this.grid.colModel.setColumnHeader(col, 'Balance (' + curr +')');
+                                                      
+                                                      _this.grid.ds.removeAll();
+                                                      
+                                                      _this.wgrid.footer.onClick('first');
+                                                  }
                                         },
-                                        text : "Download"
+                                        items : [
+
+                                        ]
+
                                     },
-                                    {
-                                        xtype: 'Fill',
-                                        xns: Roo.Toolbar
+                                       {
+                                        '|xns' : 'Roo.Toolbar',
+                                        text : "Download",
+                                        xtype : 'Button',
+                                        xns : Roo.Toolbar,
+                                        listeners : {
+                                               click : function (_self, e)
+                                                  {
+                                                      var o = {params : {}}; 
+                                                      if (!_this.bankacct.getValue()) {
+                                                          return false;
+                                                      }
+                                                      o.params._group = 'bankrec';
+                                                      o.params._name = 'all';
+                                                      o.params['bankaccntid:number'] =     _this.bankacct.getValue();
+                                                      o.params['_sum_prev'] = 'amount';
+                                                       o.url = baseURL + '/Roo/Metasql';
+                                                       o.method = 'GET';
+                                                       
+                                                       var cols = {
+                                                          'cleared' : 'Cleared',
+                                                          'sortdate' : 'Date',
+                                                          'doc_type' : 'Doctype',
+                                                          'doc_number' : 'Doc number',
+                                                          'notes' : 'Notes',
+                                                          'doc_curr' : 'Currency',
+                                                          'base_amount' : 'Base Amount',
+                                                          'doc_exchrate' : 'Exchange Rate',
+                                                          'amount' : 'Amount (Bank Currency)'
+                                                      };
+                                                       var n =0;
+                                                       for (var i in cols) {
+                                                          
+                                                       
+                                                          o.params['csvCols['+n+']'] =  i
+                                                          o.params['csvTitles['+n+']'] =  cols[i];
+                                                          n++;
+                                                      }
+                                                  
+                                                       
+                                                       new Pman.Download(o);
+                                                      Roo.MessageBox.alert("Notice", "Should be downloading now");
+                                                  }
+                                        }
+                                    },
+                                       {
+                                        '|xns' : 'Roo.Toolbar',
+                                        xtype : 'Fill',
+                                        xns : Roo.Toolbar
                                     }
                                 ]
+
                             },
+                            '|xns' : 'Roo.grid',
+                            autoExpandColumn : 'notes',
+                            xtype : 'EditorGrid',
+                            loadMask : true,
+                            clicksToEdit : 1,
+                            xns : Roo.grid,
                             colModel : [
-                                {
-                                    xtype: 'ColumnModel',
-                                    xns: Roo.grid,
-                                    dataIndex : 'cleared',
-                                    header : 'Cleared',
-                                    width : 50,
-                                    renderer : function(v,x,r) { 
-                                        if (r.data.bankrec_posted) {
-                                            return 'POSTED';
-                                        }
-                                    
-                                        var state = v   ?  '-checked' : '';
-                                                                        
-                                        return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
-                                     }
-                                },
-                                {
-                                    xtype: 'ColumnModel',
-                                    xns: Roo.grid,
-                                    dataIndex : 'sortdate',
-                                    header : 'Date',
-                                    width : 75,
-                                    renderer : function(v) {   
-                                    
-                                        return v ? Date.parseDate(v,'Y-m-d').format('d/M/Y') : '';
-                                     }
-                                },
-                                {
-                                    xtype: 'ColumnModel',
-                                    xns: Roo.grid,
-                                    dataIndex : 'doc_type',
-                                    header : 'Doctype',
-                                    width : 50,
-                                    renderer : function(v) { return String.format('{0}', v); }
-                                },
-                                {
-                                    xtype: 'ColumnModel',
-                                    xns: Roo.grid,
-                                    dataIndex : 'doc_number',
-                                    header : 'Doc Number',
-                                    width : 120,
-                                    renderer : function(v) { return String.format('{0}', v); }
-                                },
-                                {
-                                    xtype: 'ColumnModel',
-                                    xns: Roo.grid,
-                                    dataIndex : 'notes',
-                                    header : 'Notes',
-                                    width : 200,
-                                    renderer : function(v) { return String.format('{0}', v); }
-                                },
-                                {
-                                    xtype: 'ColumnModel',
-                                    xns: Roo.grid,
-                                    dataIndex : 'doc_curr',
-                                    header : 'Currency',
-                                    width : 75,
-                                    renderer : function(v) { return String.format('{0}', v); }
-                                },
-                                {
-                                    xtype: 'ColumnModel',
-                                    xns: Roo.grid,
-                                    align : 'right',
-                                    dataIndex : 'doc_exchrate',
-                                    header : 'Exchange Rate',
-                                    width : 75,
-                                    renderer : function(v) { return String.format('{0}', v ? (v*1).toFixed(3) : ''); }
-                                },
-                                {
-                                    xtype: 'ColumnModel',
-                                    xns: Roo.grid,
-                                    align : 'right',
-                                    dataIndex : 'base_amount',
-                                    header : 'Base Amount',
-                                    width : 120,
-                                    renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v*1,2)); }
-                                },
-                                {
-                                    xtype: 'ColumnModel',
-                                    xns: Roo.grid,
-                                    align : 'right',
-                                    dataIndex : 'amount',
-                                    header : 'Credit',
-                                    width : 120,
-                                    renderer : function(v,x,r) { 
-                                        if (r.data.doc_type == 'BF') {
-                                            return '';
-                                        }
-                                        return String.format('{0}', v > 0 ? Roo.util.Format.number(v*1,2)   : ''); },
-                                    editor : {
-                                        xtype: 'GridEditor',
-                                        xns: Roo.grid,
-                                        field : {
-                                            xtype: 'NumberField',
-                                            xns: Roo.form,
-                                            cls : 'align-right',
-                                            decimalPrecision : 2
-                                        }
-                                    }
-                                },
-                                {
-                                    xtype: 'ColumnModel',
-                                    xns: Roo.grid,
-                                    align : 'right',
-                                    dataIndex : 'amount',
-                                    header : 'Debit',
-                                    width : 120,
-                                    renderer : function(v,x,r) { 
-                                        if (r.data.doc_type == 'BF') {
-                                            return '';
-                                        }
-                                        return String.format('{0}', v < 0 ? Roo.util.Format.number(v*1,2): ''); },
-                                    editor : {
-                                        xtype: 'GridEditor',
-                                        xns: Roo.grid,
-                                        field : {
-                                            xtype: 'NumberField',
-                                            xns: Roo.form,
-                                            cls : 'align-right',
-                                            decimalPrecision : 2
-                                        }
-                                    }
-                                },
-                                {
-                                    xtype: 'ColumnModel',
-                                    xns: Roo.grid,
-                                    align : 'right',
-                                    dataIndex : 'balance',
-                                    header : 'Balance',
-                                    width : 120,
-                                    renderer : function(v,x,r) { 
-                                        if (r.data.doc_type == 'BF') {
-                                            return String.format('{0}', Roo.util.Format.number(v*1,2)); 
-                                        }
-                                    
-                                    
-                                        //_this.total += (v*1)
-                                         return String.format('{0}', Roo.util.Format.number(v*1,2)); 
-                                    }
-                                }
+                                {
+                                       '|xns' : 'Roo.grid',
+                                       xtype : 'ColumnModel',
+                                       header : 'Cleared',
+                                       width : 50,
+                                       renderer : function(v,x,r) { 
+                                           if (r.data.bankrec_posted) {
+                                               return 'POSTED';
+                                           }
+                                       
+                                           var state = v   ?  '-checked' : '';
+                                                                           
+                                           return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
+                                        },
+                                       xns : Roo.grid,
+                                       dataIndex : 'cleared'
+                                   },
+{
+                                       '|xns' : 'Roo.grid',
+                                       xtype : 'ColumnModel',
+                                       header : 'Date',
+                                       width : 75,
+                                       renderer : function(v) {   
+                                       
+                                           return v ? Date.parseDate(v,'Y-m-d').format('d/M/Y') : '';
+                                        },
+                                       xns : Roo.grid,
+                                       dataIndex : 'sortdate'
+                                   },
+{
+                                       '|xns' : 'Roo.grid',
+                                       xtype : 'ColumnModel',
+                                       header : 'Doctype',
+                                       width : 50,
+                                       renderer : function(v) { return String.format('{0}', v); },
+                                       xns : Roo.grid,
+                                       dataIndex : 'doc_type'
+                                   },
+{
+                                       '|xns' : 'Roo.grid',
+                                       xtype : 'ColumnModel',
+                                       header : 'Doc Number',
+                                       width : 120,
+                                       renderer : function(v) { return String.format('{0}', v); },
+                                       xns : Roo.grid,
+                                       dataIndex : 'doc_number'
+                                   },
+{
+                                       '|xns' : 'Roo.grid',
+                                       xtype : 'ColumnModel',
+                                       header : 'Notes',
+                                       width : 200,
+                                       renderer : function(v) { return String.format('{0}', v); },
+                                       xns : Roo.grid,
+                                       dataIndex : 'notes'
+                                   },
+{
+                                       '|xns' : 'Roo.grid',
+                                       xtype : 'ColumnModel',
+                                       header : 'Currency',
+                                       width : 75,
+                                       renderer : function(v) { return String.format('{0}', v); },
+                                       xns : Roo.grid,
+                                       dataIndex : 'doc_curr'
+                                   },
+{
+                                       '|xns' : 'Roo.grid',
+                                       align : 'right',
+                                       xtype : 'ColumnModel',
+                                       header : 'Exchange Rate',
+                                       width : 75,
+                                       renderer : function(v) { return String.format('{0}', v ? (v*1).toFixed(3) : ''); },
+                                       xns : Roo.grid,
+                                       dataIndex : 'doc_exchrate'
+                                   },
+{
+                                       '|xns' : 'Roo.grid',
+                                       align : 'right',
+                                       xtype : 'ColumnModel',
+                                       header : 'Base Amount',
+                                       width : 120,
+                                       renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v*1,2)); },
+                                       xns : Roo.grid,
+                                       dataIndex : 'base_amount'
+                                   },
+{
+                                       editor : {
+                                           field : {
+                                               '|xns' : 'Roo.form',
+                                               xtype : 'NumberField',
+                                               cls : 'align-right',
+                                               decimalPrecision : 2,
+                                               xns : Roo.form
+                                           },
+                                           '|xns' : 'Roo.grid',
+                                           xtype : 'GridEditor',
+                                           xns : Roo.grid,
+                                           items : [
+
+                                           ]
+
+                                       },
+                                       '|xns' : 'Roo.grid',
+                                       align : 'right',
+                                       xtype : 'ColumnModel',
+                                       header : 'Credit',
+                                       width : 120,
+                                       renderer : function(v,x,r) { 
+                                           if (r.data.doc_type == 'BF') {
+                                               return '';
+                                           }
+                                           return String.format('{0}', v > 0 ? Roo.util.Format.number(v*1,2)   : ''); },
+                                       xns : Roo.grid,
+                                       dataIndex : 'amount',
+                                       items : [
+
+                                       ]
+
+                                   },
+{
+                                       editor : {
+                                           field : {
+                                               '|xns' : 'Roo.form',
+                                               xtype : 'NumberField',
+                                               cls : 'align-right',
+                                               decimalPrecision : 2,
+                                               xns : Roo.form
+                                           },
+                                           '|xns' : 'Roo.grid',
+                                           xtype : 'GridEditor',
+                                           xns : Roo.grid,
+                                           items : [
+
+                                           ]
+
+                                       },
+                                       '|xns' : 'Roo.grid',
+                                       align : 'right',
+                                       xtype : 'ColumnModel',
+                                       header : 'Debit',
+                                       width : 120,
+                                       renderer : function(v,x,r) { 
+                                           if (r.data.doc_type == 'BF') {
+                                               return '';
+                                           }
+                                           return String.format('{0}', v < 0 ? Roo.util.Format.number(v*1,2): ''); },
+                                       xns : Roo.grid,
+                                       dataIndex : 'amount',
+                                       items : [
+
+                                       ]
+
+                                   },
+{
+                                       '|xns' : 'Roo.grid',
+                                       align : 'right',
+                                       xtype : 'ColumnModel',
+                                       header : 'Balance',
+                                       width : 120,
+                                       renderer : function(v,x,r) { 
+                                           if (r.data.doc_type == 'BF') {
+                                               return String.format('{0}', Roo.util.Format.number(v*1,2)); 
+                                           }
+                                       
+                                       
+                                           //_this.total += (v*1)
+                                            return String.format('{0}', Roo.util.Format.number(v*1,2)); 
+                                       },
+                                       xns : Roo.grid,
+                                       dataIndex : 'balance'
+                                   }
+                            ],
+                            listeners : {
+                               beforeedit : function (e)
+                                  {
+                                      //    Roo.log(e);
+                                         var ch =  _this.grid.colModel.config[e.column].header;
+                                         var val = e.value *1;
+                                    // Roo.log(ch);
+                                    // Roo.log(val);
+                                  
+                                         if (val > 0.0 && ch == 'Debit') {
+                                              e.cancel = true;
+                                              return;
+                                          }
+                                         if (val < 0.0 && ch == 'Credit') {
+                                              e.cancel = true;
+                                              return;
+                                          }
+                                          if (e.record.data.cleared || e.record.data.bankrec_posted) {
+                                              e.cancel = true;
+                                              return;
+                                          }
+                                          
+                                          // allow start editing..
+                                  },
+                               render : function() 
+                                  {
+                                      _this.grid = this; 
+                                      //_this.dialog = Pman.Dialog.FILL_IN
+                                      if (_this.panel.active) {
+                                         this.footer.onClick('first');
+                                      }
+                                  },
+                               cellclick : function (_self, rowIndex, columnIndex, e)
+                                  {
+                                      var clear = function(ar) 
+                                      {
+                                          var ar_in = ar;
+                                          if (ar === true) {
+                                              ar = [];
+                                              
+                                              _this.grid.ds.each(function(rec) {
+                                                  if (rec.data.doc_type == 'BF') {
+                                                      return;
+                                                  }
+                                                  ar.push(rec);
+                                              });
+                                          }
+                                          var sortdate = false;
+                                          var data = [];
+                                          Roo.each(ar, function(rec) {
+                                              if (rec.data.cleared || rec.data.bankrec_posted) {
+                                                  return;
+                                              }
+                                              if(!sortdate){
+                                                  sortdate = rec.data.sortdate;
+                                              }
+                                              data.push({
+                                                   id : rec.data.id,
+                                                  altid : rec.data.altid,
+                                                  curr_rate : rec.data.doc_exchrate,
+                                                  amount : rec.data.amount
+                                                  
+                                              });
+                                          });
+                                         new Pman.Request({
+                                          url : baseURL + '/Roo/bankrecitem',
+                                              method : 'POST',
+                                              mask : 'Clearing',
+                                              params : {
+                                                  bankaccnt_id : _this.bankacct.getValue(),
+                                                  sortdate : sortdate,
+                                                  set_clear : Roo.encode(data)
+                                              },
+                                              success : function() {
+                                                  Roo.each(ar, function(rec) {
+                                                      rec.set('cleared', true);
+                                                  });
+                                                  if (ar_in === true) {
+                                                      _this.grid.ds.getAt(0).set('cleared', true);
+                                                  }
+                                                  _this.wgrid.footer.onClick('refresh');
+                                              }
+                                          });
+                                      }
+                                      
+                                      
+                                      var unclear = function(ar)
+                                      {
+                                          var ar_in = ar;
+                                          if (ar === true) {
+                                              ar = [];
+                                              
+                                              _this.grid.ds.each(function(rec) {
+                                                  if (rec.data.doc_type == 'BF') {
+                                                      return;
+                                                  }
+                                                  ar.push(rec);
+                                              });
+                                          }
+                                          var sortdate = false;
+                                          var data = [];
+                                          Roo.each(ar, function(rec) {
+                                              if (!rec.data.cleared  || rec.data.bankrec_posted) {
+                                                  return;
+                                              }
+                                              if(!sortdate){
+                                                  sortdate = rec.data.sortdate;
+                                              }
+                                              data.push({
+                                                  id : rec.data.id,
+                                                  altid : rec.data.altid                
+                                              });
+                                          });
+                                  
+                                          new Pman.Request({
+                                              url : baseURL + '/Roo/bankrecitem',
+                                              method : 'POST',
+                                              mask : 'Clearing',
+                                              params : {
+                                                  bankaccnt_id : _this.bankacct.getValue(),
+                                                  sortdate : sortdate,
+                                                  remove_clear :Roo.encode(data)
+                                                  
+                                              },
+                                              success : function() {
+                                                  Roo.each(ar, function(rec) {
+                                                      rec.set('cleared', false);
+                                                  });
+                                                 if (ar_in === true) {
+                                                      _this.grid.ds.getAt(0).set('cleared', false);
+                                                  }  
+                                                  _this.wgrid.footer.onClick('refresh');
+                                              }
+                                          });
+                                       
+                                        
+                                      };
+                                      
+                                      
+                                      
+                                      var di = this.colModel.config[columnIndex].dataIndex;
+                                      if (di != 'cleared') {
+                                          return;
+                                      }
+                                      var  rec = this.ds.getAt(rowIndex);
+                                      if (rec.data.doc_type == 'BF') {
+                                      
+                                          if (rec.data.cleared) {
+                                              unclear(true);
+                                          
+                                          } else {
+                                              clear(true);
+                                          }
+                                      
+                                          return;
+                                      }
+                                      
+                                          
+                                          
+                                      if (rec.data.cleared) {
+                                      
+                                          unclear([rec]);
+                                          return;
+                                          
+                                      }
+                                      
+                                      clear([rec]);
+                                      
+                                      
+                                       
+                                           
+                                    
+                                  },
+                               afteredit : function (e)
+                                  {
+                                  
+                                      if (e.cancel) {
+                                          return;
+                                      }
+                                         var ch =  _this.grid.colModel.config[e.column].header;
+                                             var val = e.originalValue *1;
+                                        // Roo.log(ch);
+                                        // Roo.log(val);
+                                  
+                                         if (val > 0.0 && ch == 'Debit') {
+                                              e.cancel = true;
+                                              return;
+                                          }
+                                         if (val < 0.0 && ch == 'Credit') {
+                                              e.cancel = true;
+                                              return;
+                                          }
+                                          if (e.record.data.cleared || e.record.data.bankrec_posted) {
+                                              e.cancel = true;
+                                              return;
+                                          }
+                                          if (val > 0.0 && e.value < 0.0) {
+                                          Roo.log("CANCEL");  
+                                              e.record.set('amount', e.originalValue);
+                                              e.cancel = true;
+                                              return;
+                                          }
+                                          if (val < 0.0 && e.value > 0.0) {
+                                          Roo.log("CANCEL");
+                                              e.record.set('amount', e.originalValue);
+                                              e.cancel = true;
+                                              return;
+                                          } 
+                                          if (e.originalValue*1 == e.value*1) {
+                                              return;
+                                          }
+                                            
+                                          e.record.set('doc_exchrate', Math.abs(e.value  * 1)  / Math.abs(e.record.data.base_amount * 1));
+                                          Roo.log(e.record);
+                                          
+                                          _this.grid.ds.updateBalance();
+                                          // send it down the line...
+                                          new Pman.Request({
+                                              method : 'POST',
+                                              url : baseURL + '/Roo/bankrecitem',
+                                              mask : 'Saving',
+                                              params : {
+                                                  bankaccnt_id : _this.bankacct.getValue(),
+                                                  set_amount : Math.abs(e.value),
+                                                  sortdate : e.record.data.sortdate,
+                                                  source_id : e.record.data.id,
+                                                  altid : e.record.data.altid
+                                              }
+                                          
+                                          });
+                                          
+                                           
+                                          
+                                          
+                                  }
+                            },
+                            items : [
+
                             ]
-                        }
-                    },
-                    {
-                        xtype: 'GridPanel',
-                        xns: Roo,
-                        listeners : {
-                            activate : function() {
-                                _this.wpanel = this;
-                                //if (_this.wgrid) {
-                                //    _this.wgrid.footer.onClick('first');
-                                //}
-                            }
+
                         },
+                        '|xns' : 'Roo',
+                        fitToframe : true,
                         background : true,
+                        region : 'center',
+                        title : "Bank Reconcile",
+                        xtype : 'GridPanel',
                         fitContainer : true,
-                        fitToframe : true,
-                        region : 'west',
-                        tableName : 'Groups',
-                        title : "Pick a Date",
+                        xns : Roo,
+                        tableName : 'metasql',
+                        listeners : {
+                               activate : function() {
+                                      _this.panel = this;
+                                      if (_this.grid) {
+                                          _this.grid.footer.onClick('first');
+                                      }
+                                  }
+                        },
+                        items : [
+
+                        ]
+
+                    },
+                       {
                         grid : {
-                            xtype: 'Grid',
-                            xns: Roo.grid,
-                            listeners : {
-                                render : function() 
-                                {
-                                    _this.wgrid = this; 
-                                    //_this.dialog = Pman.Dialog.FILL_IN
-                                    //if (_this.wpanel.active) {
-                                    //   this.footer.onClick('first');
-                                    //}
-                                },
-                                cellclick : function (_self, rowIndex, columnIndex, e)
-                                {
-                                    var di = this.colModel.getDataIndex(columnIndex);
-                                
-                                    if (di != 'is_reconciled') {
-                                        return;
-                                    }
-                                     
-                                    var rec = this.ds.getAt(rowIndex);
-                                    
-                                    var voidit = function(){
-                                        new Pman.Request({
-                                            url : baseURL + '/Roo/Bankrec.php',
-                                            method :'POST',
-                                            params : {
-                                                _void : 1,
-                                                bankaccnt_id : _this.bankacct.getValue(),
-                                                sotrdate : rec.data.sortdate
-                                                
-                                            },
-                                            success : function() {
-                                                _this.wgrid.footer.onClick('refresh');
-                                            }
-                                        });
-                                    }
-                                    
-                                    var postit = function(){
-                                        new Pman.Request({
-                                            url : baseURL + '/Roo/Bankrec.php',
-                                            method :'POST',
-                                            params : {
-                                                _post : 1,
-                                                bankaccnt_id : _this.bankacct.getValue(),
-                                                sotrdate : rec.data.sortdate
-                                                
-                                            },
-                                            success : function() {
-                                                _this.wgrid.footer.onClick('refresh');
-                                            }
-                                        });
-                                    
-                                    }
-                                    
-                                    if(rec.data.is_reconciled == 1){
-                                        voidit();
-                                        return;
-                                    }
-                                    
-                                    postit();
-                                    return;
-                                    
-                                    
-                                    
-                                },
-                                rowclick : function (_self, rowIndex, e)
-                                {
-                                    
-                                     _this.wgrid.lastSelectedRow = rowIndex;
-                                    
-                                }
-                            },
-                            autoExpandColumn : 'sortdate',
-                            loadMask : true,
                             toolbar : {
-                                xtype: 'Toolbar',
-                                xns: Roo,
+                                '|xns' : 'Roo',
+                                xtype : 'Toolbar',
+                                xns : Roo,
                                 items : [
-                                    {
-                                        xtype: 'MonthField',
-                                        xns: Roo.form,
-                                        listeners : {
-                                            render : function (_self)
-                                            {
-                                                _this.monthSel = _self;
-                                            },
-                                            select : function (combo, date)
-                                            {
-                                                _this.grid.ds.removeAll();
-                                                _this.wgrid.footer.onClick('first');
-                                            }
-                                        },
-                                        allowBlank : true,
+                                       {
+                                        '|xns' : 'Roo.form',
                                         format : 'M Y',
                                         useIso : true,
-                                        width : 150
-                                    },
-                                    {
-                                        xtype: 'Button',
-                                        xns: Roo.Toolbar,
+                                        xtype : 'MonthField',
+                                        allowBlank : true,
+                                        width : 150,
+                                        xns : Roo.form,
                                         listeners : {
-                                            click : function (_self, e)
-                                            {
-                                                _this.monthSel.setValue('');
-                                                _this.grid.ds.removeAll();\r
-                                                _this.wgrid.footer.onClick('first');\r
-                                            }
-                                        },
+                                               render : function (_self)
+                                                  {
+                                                      _this.monthSel = _self;
+                                                  },
+                                               select : function (combo, date)
+                                                  {
+                                                      _this.grid.ds.removeAll();
+                                                      _this.wgrid.footer.onClick('first');
+                                                  }
+                                        }
+                                    },
+                                       {
+                                        '|xns' : 'Roo.Toolbar',
+                                        xtype : 'Button',
                                         cls : 'x-btn-icon',
-                                        icon : rootURL + '/Pman/templates/images/edit-clear.gif'
+                                        icon : rootURL + '/Pman/templates/images/edit-clear.gif',
+                                        xns : Roo.Toolbar,
+                                        listeners : {
+                                               click : function (_self, e)
+                                                  {
+                                                      _this.monthSel.setValue('');
+                                                      _this.grid.ds.removeAll();\r
+                                                      _this.wgrid.footer.onClick('first');\r
+                                                  }
+                                        }
                                     },
-                                    {
-                                        xtype: 'Fill',
-                                        xns: Roo.Toolbar
+                                       {
+                                        '|xns' : 'Roo.Toolbar',
+                                        xtype : 'Fill',
+                                        xns : Roo.Toolbar
                                     },
-                                    {
-                                        xtype: 'Button',
-                                        xns: Roo.Toolbar,
-                                        cls : 'x-btn-text-icon',
-                                        text : "Fix Data",
-                                        icon : Roo.rootURL + 'images/default/tree/leaf.gif',
+                                       {
                                         menu : {
-                                            xtype: 'Menu',
-                                            xns: Roo.menu,
+                                            '|xns' : 'Roo.menu',
+                                            xtype : 'Menu',
+                                            xns : Roo.menu,
                                             items : [
-                                                {
-                                                    xtype: 'Item',
-                                                    xns: Roo.menu,
-                                                    listeners : {
-                                                        click : function (_self, e)
-                                                        {
-                                                        
-                                                            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",
-                                                                function (res) {
-                                                                    if(res!='yes') {
-                                                                        return;
-                                                                    
-                                                                    }
-                                                                    new Pman.Request({
-                                                                        url : baseURL + '/Roo/Bankrec.php',
-                                                                        method :'POST',
-                                                                        params : {
-                                                                            _fix : 1
-                                                                        },
-                                                                        success : function() {
-                                                                            if(_this.wgrid){
-                                                                                _this.wgrid.footer.onClick('refresh');
-                                                                            }
-                                                                            Roo.MessageBox.alert('Notice', 'FIXED');
-                                                                        }
-                                                                    });
-                                                            });
-                                                        
-                                                        }
-                                                    },
-                                                    cls : 'x-btn-text-icon',
+                                               {
+                                                    '|xns' : 'Roo.menu',
                                                     text : "Fix historical data",
-                                                    icon : Roo.rootURL + 'images/default/tree/leaf.gif'
-                                                },
-                                                {
-                                                    xtype: 'Item',
-                                                    xns: Roo.menu,
-                                                    listeners : {
-                                                        click : function (_self, e)
-                                                        {
-                                                        
-                                                            Roo.MessageBox.confirm("Confirm", "Are you sure you want?",
-                                                                function (res) {
-                                                                    if(res!='yes') {
-                                                                        return;
-                                                                    
-                                                                    }
-                                                                    new Pman.Request({
-                                                                        url : baseURL + '/Roo/Bankrec.php',
-                                                                        method :'POST',
-                                                                        params : {
-                                                                            _closedPeriod : 1
-                                                                        },
-                                                                        success : function() {
-                                                                            if(_this.wgrid){
-                                                                                _this.wgrid.footer.onClick('refresh');
-                                                                            }
-                                                                            Roo.MessageBox.alert('Notice', 'DONE');
-                                                                        }
-                                                                    });
-                                                            });
-                                                        
-                                                        }
-                                                    },
+                                                    xtype : 'Item',
                                                     cls : 'x-btn-text-icon',
+                                                    icon : Roo.rootURL + 'images/default/tree/leaf.gif',
+                                                    xns : Roo.menu,
+                                                    listeners : {
+                                                       click : function (_self, e)
+                                                          {
+                                                          
+                                                              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",
+                                                                  function (res) {
+                                                                      if(res!='yes') {
+                                                                          return;
+                                                                      
+                                                                      }
+                                                                      new Pman.Request({
+                                                                          url : baseURL + '/Roo/Bankrec.php',
+                                                                          method :'POST',
+                                                                          params : {
+                                                                              _fix : 1
+                                                                          },
+                                                                          success : function() {
+                                                                              if(_this.wgrid){
+                                                                                  _this.wgrid.footer.onClick('refresh');
+                                                                              }
+                                                                              Roo.MessageBox.alert('Notice', 'FIXED');
+                                                                          }
+                                                                      });
+                                                              });
+                                                          
+                                                          }
+                                                    }
+                                                },
+                                               {
+                                                    '|xns' : 'Roo.menu',
                                                     text : "Fix Closed Periods",
-                                                    icon : Roo.rootURL + 'images/default/tree/leaf.gif'
+                                                    xtype : 'Item',
+                                                    cls : 'x-btn-text-icon',
+                                                    icon : Roo.rootURL + 'images/default/tree/leaf.gif',
+                                                    xns : Roo.menu,
+                                                    listeners : {
+                                                       click : function (_self, e)
+                                                          {
+                                                          
+                                                              Roo.MessageBox.confirm("Confirm", "Are you sure you want?",
+                                                                  function (res) {
+                                                                      if(res!='yes') {
+                                                                          return;
+                                                                      
+                                                                      }
+                                                                      new Pman.Request({
+                                                                          url : baseURL + '/Roo/Bankrec.php',
+                                                                          method :'POST',
+                                                                          params : {
+                                                                              _closedPeriod : 1
+                                                                          },
+                                                                          success : function() {
+                                                                              if(_this.wgrid){
+                                                                                  _this.wgrid.footer.onClick('refresh');
+                                                                              }
+                                                                              Roo.MessageBox.alert('Notice', 'DONE');
+                                                                          }
+                                                                      });
+                                                              });
+                                                          
+                                                          }
+                                                    }
                                                 }
                                             ]
-                                        }
+
+                                        },
+                                        '|xns' : 'Roo.Toolbar',
+                                        text : "Fix Data",
+                                        xtype : 'Button',
+                                        cls : 'x-btn-text-icon',
+                                        icon : Roo.rootURL + 'images/default/tree/leaf.gif',
+                                        xns : Roo.Toolbar,
+                                        items : [
+
+                                        ]
+
                                     }
                                 ]
+
                             },
                             sm : {
-                                xtype: 'RowSelectionModel',
-                                xns: Roo.grid,
+                                '|xns' : 'Roo.grid',
+                                xtype : 'RowSelectionModel',
+                                singleSelect : true,
+                                xns : Roo.grid,
                                 listeners : {
-                                    selectionchange : function (_self)
-                                    {
-                                        _this.grid.footer.onClick('first');
-                                    }
-                                },
-                                singleSelect : true
+                                       selectionchange : function (_self)
+                                          {
+                                              _this.grid.footer.onClick('first');
+                                          }
+                                }
                             },
                             dataSource : {
-                                xtype: 'Store',
-                                xns: Roo.data,
-                                listeners : {
-                                    beforeload : function (_self, o)
-                                    {
-                                    
-                                        if (!_this.bankacct.getValue()) {
-                                            return false;
-                                        }
-                                        var dt = _this.monthSel.getValue();
-                                        
-                                        if(dt.length){
-                                            o.params['sortdate:text'] = typeof(dt) == 'string' ? dt : dt.format('Y-m-d');
-                                        }
-                                        o.params._group = 'bankrec';
-                                        o.params._name = 'bydate';
-                                        o.params['bankaccntid:number'] =  _this.bankacct.getValue();
-                                        
-                                    
-                                        
-                                    },
-                                    load : function (_self, records, options, res)
-                                    {   
-                                        var sm = _this.wgrid.getSelectionModel();
-                                        
-                                        if(_this.wgrid.lastSelectedRow * 1 >0){
-                                            sm.selectRow(_this.wgrid.lastSelectedRow);
-                                            return;
-                                        }
-                                        
-                                        if (!sm.getSelections().length) {
-                                            sm.selectFirstRow();
-                                        }
-                                    
-                                    }
-                                },
-                                remoteSort : true,
-                                sortInfo : { field : 'sotrdate', direction: 'ASC' },
                                 proxy : {
-                                    xtype: 'HttpProxy',
-                                    xns: Roo.data,
+                                    '|xns' : 'Roo.data',
+                                    url : baseURL + '/Roo/metasql.php',
                                     method : 'GET',
+                                    xtype : 'HttpProxy',
                                     timeout : 900000,
-                                    url : baseURL + '/Roo/metasql.php'
+                                    xns : Roo.data
                                 },
                                 reader : {
-                                    xtype: 'JsonReader',
-                                    xns: Roo.data,
+                                    '|xns' : 'Roo.data',
                                     id : 'id',
                                     root : 'data',
-                                    totalProperty : 'total',
+                                    xtype : 'JsonReader',
                                     fields : [
                                         {
                                             'name': 'sortdate',
                                             'type': 'string'
                                         }
-                                    ]
-                                }
+                                    ],
+                                    xns : Roo.data,
+                                    totalProperty : 'total'
+                                },
+                                '|xns' : 'Roo.data',
+                                xtype : 'Store',
+                                remoteSort : true,
+                                sortInfo : { field : 'sotrdate', direction: 'ASC' },
+                                xns : Roo.data,
+                                listeners : {
+                                       beforeload : function (_self, o)
+                                          {
+                                          
+                                              if (!_this.bankacct.getValue()) {
+                                                  return false;
+                                              }
+                                              var dt = _this.monthSel.getValue();
+                                              
+                                              if(dt.length){
+                                                  o.params['sortdate:text'] = typeof(dt) == 'string' ? dt : dt.format('Y-m-d');
+                                              }
+                                              o.params._group = 'bankrec';
+                                              o.params._name = 'bydate';
+                                              o.params['bankaccntid:number'] =  _this.bankacct.getValue();
+                                              
+                                          
+                                              
+                                          },
+                                       load : function (_self, records, options, res)
+                                          {   
+                                              var sm = _this.wgrid.getSelectionModel();
+                                              
+                                              if(_this.wgrid.lastSelectedRow * 1 >0){
+                                                  sm.selectRow(_this.wgrid.lastSelectedRow);
+                                                  return;
+                                              }
+                                              
+                                              if (!sm.getSelections().length) {
+                                                  sm.selectFirstRow();
+                                              }
+                                          
+                                          }
+                                },
+                                items : [
+
+                                ]
+
                             },
                             footer : {
-                                xtype: 'PagingToolbar',
-                                xns: Roo,
-                                displayInfo : false,
-                                displayMsg : "Displaying Date{0} - {1} of {2}",
+                                '|xns' : 'Roo',
+                                pageSize : 25,
+                                xtype : 'PagingToolbar',
                                 emptyMsg : "No Date found",
-                                pageSize : 25
+                                xns : Roo,
+                                displayMsg : "Displaying Date{0} - {1} of {2}",
+                                displayInfo : false
                             },
+                            '|xns' : 'Roo.grid',
+                            autoExpandColumn : 'sortdate',
+                            xtype : 'Grid',
+                            loadMask : true,
+                            xns : Roo.grid,
                             colModel : [
-                                {
-                                    xtype: 'ColumnModel',
-                                    xns: Roo.grid,
-                                    dataIndex : 'sortdate',
-                                    header : 'Date',
-                                    width : 100,
-                                    renderer : function(v) {   
-                                    
-                                        return v ? Date.parseDate(v,'Y-m-d').format('d/M/Y') : '';
-                                     }
-                                },
-                                {
-                                    xtype: 'ColumnModel',
-                                    xns: Roo.grid,
-                                    align : 'right',
-                                    dataIndex : 'balance',
-                                    header : 'Closing Balance',
-                                    width : 120,
-                                    renderer : function(v,x,r) { 
-                                        
-                                        var color = 'red'; // has some not 'ticked'
-                                        
-                                        if(r.data.no_records - r.data.no_posted == 0){ // all posted on that date
-                                            color = 'black';
-                                        }
-                                        if(r.data.no_records - r.data.no_cleared == 0 && r.data.no_posted != r.data.no_cleared){ // has 'ticked' or posted
-                                            color = 'blue';
-                                        }
-                                        
-                                        return String.format('<span style="color:{0}">{1}</span>', color, Roo.util.Format.number(v*1,2)); 
-                                    }
-                                },
-                                {
-                                    xtype: 'ColumnModel',
-                                    xns: Roo.grid,
-                                    align : 'right',
-                                    dataIndex : 'reconciled',
-                                    header : 'Reconciled',
-                                    width : 100,
-                                    renderer : function(v,x,r) { 
-                                        
-                                        if(!v){
-                                            return '';
-                                        }
-                                        
-                                        if((r.data.no_records * 1 != r.data.no_posted * 1) || r.data.balance * 1 != v * 1){ // not match
-                                            
-                                            return '<span style="color:red;font-weight:bold">' + Roo.util.Format.number(v*1,2); 
-                                        }
-                                        
-                                        return String.format('<span style="color:black">{0}</span>', Roo.util.Format.number(v*1,2)); 
-                                            
-                                     }
-                                },
-                                {
-                                    xtype: 'ColumnModel',
-                                    xns: Roo.grid,
-                                    align : 'right',
-                                    dataIndex : 'is_reconciled',
-                                    header : 'Post?',
-                                    width : 50,
-                                    renderer : function(v,x,r) { 
-                                        var state = v  ?  '-checked' : '';
-                                    
-                                        return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
-                                     }
-                                }
+                                {
+                                       '|xns' : 'Roo.grid',
+                                       xtype : 'ColumnModel',
+                                       header : 'Date',
+                                       width : 100,
+                                       renderer : function(v) {   
+                                       
+                                           return v ? Date.parseDate(v,'Y-m-d').format('d/M/Y') : '';
+                                        },
+                                       xns : Roo.grid,
+                                       dataIndex : 'sortdate'
+                                   },
+{
+                                       '|xns' : 'Roo.grid',
+                                       align : 'right',
+                                       xtype : 'ColumnModel',
+                                       header : 'Closing Balance',
+                                       width : 120,
+                                       renderer : function(v,x,r) { 
+                                           
+                                           var color = 'red'; // has some not 'ticked'
+                                           
+                                           if(r.data.no_records - r.data.no_posted == 0){ // all posted on that date
+                                               color = 'black';
+                                           }
+                                           if(r.data.no_records - r.data.no_cleared == 0 && r.data.no_posted != r.data.no_cleared){ // has 'ticked' or posted
+                                               color = 'blue';
+                                           }
+                                           
+                                           return String.format('<span style="color:{0}">{1}</span>', color, Roo.util.Format.number(v*1,2)); 
+                                       },
+                                       xns : Roo.grid,
+                                       dataIndex : 'balance'
+                                   },
+{
+                                       '|xns' : 'Roo.grid',
+                                       align : 'right',
+                                       xtype : 'ColumnModel',
+                                       header : 'Reconciled',
+                                       width : 100,
+                                       renderer : function(v,x,r) { 
+                                           
+                                           if(!v){
+                                               return '';
+                                           }
+                                           
+                                           if((r.data.no_records * 1 != r.data.no_posted * 1) || r.data.balance * 1 != v * 1){ // not match
+                                               
+                                               return '<span style="color:red;font-weight:bold">' + Roo.util.Format.number(v*1,2); 
+                                           }
+                                           
+                                           return String.format('<span style="color:black">{0}</span>', Roo.util.Format.number(v*1,2)); 
+                                               
+                                        },
+                                       xns : Roo.grid,
+                                       dataIndex : 'reconciled'
+                                   },
+{
+                                       '|xns' : 'Roo.grid',
+                                       align : 'right',
+                                       xtype : 'ColumnModel',
+                                       header : 'Post?',
+                                       width : 50,
+                                       renderer : function(v,x,r) { 
+                                           var state = v  ?  '-checked' : '';
+                                       
+                                           return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
+                                        },
+                                       xns : Roo.grid,
+                                       dataIndex : 'is_reconciled'
+                                   }
+                            ],
+                            listeners : {
+                               render : function() 
+                                  {
+                                      _this.wgrid = this; 
+                                      //_this.dialog = Pman.Dialog.FILL_IN
+                                      //if (_this.wpanel.active) {
+                                      //   this.footer.onClick('first');
+                                      //}
+                                  },
+                               cellclick : function (_self, rowIndex, columnIndex, e)
+                                  {
+                                      var di = this.colModel.getDataIndex(columnIndex);
+                                  
+                                      if (di != 'is_reconciled') {
+                                          return;
+                                      }
+                                       
+                                      var rec = this.ds.getAt(rowIndex);
+                                      
+                                      var voidit = function(){
+                                          new Pman.Request({
+                                              url : baseURL + '/Roo/Bankrec.php',
+                                              method :'POST',
+                                              params : {
+                                                  _void : 1,
+                                                  bankaccnt_id : _this.bankacct.getValue(),
+                                                  sotrdate : rec.data.sortdate
+                                                  
+                                              },
+                                              success : function() {
+                                                  _this.wgrid.footer.onClick('refresh');
+                                              }
+                                          });
+                                      }
+                                      
+                                      var postit = function(){
+                                          new Pman.Request({
+                                              url : baseURL + '/Roo/Bankrec.php',
+                                              method :'POST',
+                                              params : {
+                                                  _post : 1,
+                                                  bankaccnt_id : _this.bankacct.getValue(),
+                                                  sotrdate : rec.data.sortdate
+                                                  
+                                              },
+                                              success : function() {
+                                                  _this.wgrid.footer.onClick('refresh');
+                                              }
+                                          });
+                                      
+                                      }
+                                      
+                                      if(rec.data.is_reconciled == 1){
+                                          voidit();
+                                          return;
+                                      }
+                                      
+                                      postit();
+                                      return;
+                                      
+                                      
+                                      
+                                  },
+                               rowclick : function (_self, rowIndex, e)
+                                  {
+                                      
+                                       _this.wgrid.lastSelectedRow = rowIndex;
+                                      
+                                  }
+                            },
+                            items : [
+
                             ]
-                        }
+
+                        },
+                        '|xns' : 'Roo',
+                        fitToframe : true,
+                        background : true,
+                        region : 'west',
+                        title : "Pick a Date",
+                        xtype : 'GridPanel',
+                        fitContainer : true,
+                        xns : Roo,
+                        tableName : 'Groups',
+                        listeners : {
+                               activate : function() {
+                                      _this.wpanel = this;
+                                      //if (_this.wgrid) {
+                                      //    _this.wgrid.footer.onClick('first');
+                                      //}
+                                  }
+                        },
+                        items : [
+
+                        ]
+
                     }
-                ],
-                center : {
-                    xtype: 'LayoutRegion',
-                    xns: Roo
-                },
-                west : {
-                    xtype: 'LayoutRegion',
-                    xns: Roo,
-                    split : true,
-                    width : 400
-                }
-            }
-        };
-    }
+                ]
+
+            },
+            '|xns' : 'Roo',
+            background : true,
+            xtype : 'NestedLayoutPanel',
+            title : "Bank Reconcile",
+            xns : Roo,
+            items : [
+
+            ]
+
+        };    }
 });