Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Pman.Tab.XtuplePurchaseRecv.js
index f407940..20399e9 100644 (file)
@@ -42,7 +42,7 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                         tableName : 'pohead',
                         title : "PO Receive Stock",
                         grid : {
-                            xtype: 'EditorGrid',
+                            xtype: 'Grid',
                             xns: Roo.grid,
                             listeners : {
                                 render : function() 
@@ -53,26 +53,77 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                        this.footer.onClick('first');
                                     }
                                 },
+                                cellclick : function (_self, rowIndex, columnIndex, e)
+                                {
+                                
+                                    var applyVoucher = function(){
+                                        Roo.MessageBox.confirm("Confirm", "Are you sure to apply voucher for the selected PO completely?",
+                                            function(v) {
+                                                if (v != 'yes') {
+                                                    return;
+                                                }
+                                                                
+                                                Pman.request({
+                                                    url: baseURL+'/Roo/Pohead.php',
+                                                    method :'POST',
+                                                    mask : 'Processing',
+                                                    params : {
+                                                        'pohead_id' : s.data.pohead_id,
+                                                        '_applyVoucher' : 1
+                                                    },
+                                                    success : function  () {
+                                                        _this.grid.footer.onClick('refresh');
+                                                        return;
+                                                    }
+                                                });
+                                            });
+                                            return;
+                                    }
+                                    
+                                    var di = _this.grid.getColumnModel().getDataIndex(columnIndex);
+                                    var s = _this.grid.ds.getAt(rowIndex);
+                                    
+                                    if(di == 'pohead_vouchered'){
+                                        if(s.data.pohead_status != 'O'){
+                                            Roo.MessageBox.alert('Error', 'Please Open this PO first');
+                                            return;
+                                        }
+                                        if(Math.round(s.data.pohead_vouchered*100) > Math.round(s.data.pohead_val*100)){
+                                            //Roo.MessageBox.alert('Error', 'This PO has been apply completely!');
+                                            return;
+                                        }
+                                        applyVoucher();
+                                        
+                                        return;
+                                    }
+                                    
+                                    if(di == 'pohead_paid'){ // comming soon...
+                                        return;
+                                    }
+                                    
+                                    
+                                    
+                                    _this.rggrid.ds.load({});
+                                },
                                 rowdblclick : function (_self, rowIndex, e)
                                 {
+                                
+                                    
                                     var r = _this.grid.ds.getAt(rowIndex);
                                     
                                     Pman.Dialog.XtuplePurchaseOrder.show( { pohead_id : r.data.pohead_id }, function() {
                                         _this.grid.footer.onClick('refresh');
-                                    }); 
-                                },
-                                rowclick : function (_self, rowIndex, e)
-                                {
-                                    
-                                },
-                                cellclick : function (_self, rowIndex, columnIndex, e)
-                                {
-                                    _this.rggrid.ds.load({});
+                                    });  
                                 }
                             },
                             autoExpandColumn : 'pohead_vend_id_vend_name',
                             loadMask : true,
                             trackMouseOver : true,
+                            sm : {
+                                xtype: 'RowSelectionModel',
+                                xns: Roo.grid,
+                                singleSelect : true
+                            },
                             dataSource : {
                                 xtype: 'Store',
                                 xns: Roo.data,
@@ -86,7 +137,12 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                         
                                         // only filter by type if the number is empty..
                                         if (!o.params['query[number]'].length) {
-                                            o.params.pohead_status = _this.status.getValue();
+                                            if (_this.status.getValue() != 'E') {
+                                                o.params._status = _this.status.getValue();
+                                            }
+                                        }
+                                        if (_this.status.getValue() == 'E') {
+                                            o.params['!pohead_has_error'] = 0;
                                         }
                                         
                                         
@@ -1299,7 +1355,7 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                             },
                                             select : function (combo, record, index)
                                             {
-                                                Roo.log('select');
+                                            
                                                 _this.grid.footer.onClick('first');
                                             }
                                         },
@@ -1312,16 +1368,18 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                         mode : 'local',
                                         name : 'cm_status_name',
                                         triggerAction : 'all',
-                                        value : "O",
+                                        value : "OU",
                                         valueField : 'ftype',
                                         width : 150,
                                         store : {
                                             xtype: 'SimpleStore',
                                             xns: Roo.data,
                                             data : [ 
+                                                [ 'OU', "Open And Unreleased"],
                                                 [ 'O', "Open"],
                                                 [ 'C' , "Closed"],
-                                                [ 'U', "Unreleased"] 
+                                                [ 'U', "Unreleased"],
+                                                [ 'E' , "Has Errors" ]
                                             ],
                                             fields : [  'ftype', 'fname']
                                         }
@@ -1474,6 +1532,7 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                                                 Roo.MessageBox.alert("Error", "Select a row");
                                                                 return;
                                                             }
+                                                            
                                                             if (sel.data.pohead_status == 'C') {
                                                                 Roo.MessageBox.alert("Error", "Purchase order is already closed");
                                                                 return;
@@ -1509,6 +1568,8 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                                                 Roo.MessageBox.alert("Error", "Select a row");
                                                                 return;
                                                             }
+                                                            
+                                                            
                                                             if (sel.data.pohead_status != 'O') {
                                                                 Roo.MessageBox.alert("Error", "Purchase order is not Open");
                                                                 return;
@@ -1530,8 +1591,8 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                                             
                                                         }
                                                     },
-                                                    icon : Roo.rootURL + 'images/default/tree/leaf.gif',
-                                                    text : "Unrelease Selected"
+                                                    text : "Unrelease Selected",
+                                                    icon : Roo.rootURL + 'images/default/tree/leaf.gif'
                                                 },
                                                 {
                                                     xtype: 'Item',
@@ -1544,6 +1605,7 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                                                 Roo.MessageBox.alert("Error", "Select a row");
                                                                 return;
                                                             }
+                                                            
                                                             if (sel.data.pohead_status == 'O') {
                                                                 Roo.MessageBox.alert("Error", "Purchase order is already Open");
                                                                 return;
@@ -1671,6 +1733,7 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                                                             }
                                                                         }
                                                                         
+                                                                        
                                                                         new Pman.Download({
                                                                           url : baseURL + '/Xtuple/Print',
                                                                           params :   params,
@@ -1832,8 +1895,21 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                     width : 75,
                                     renderer : function(v,x,r) { 
                                     
-                                        var f =  (Math.round(v*100) != Math.round(r.data.pohead_paid*100)) ? '<span style="color:red;font-weight:bold">{0}</span>' : '{0}';
-                                        return String.format(f,  v ? Roo.util.Format.usMoney( v) : '' ); 
+                                        Roo.log(v*1);
+                                        var f =  '<span style="{0}">{1}</span>';
+                                        
+                                        var style = '';
+                                        
+                                        if(Math.round(v*100) != Math.round(r.data.pohead_paid*100)){
+                                            style = 'color:red;font-weight:bold';
+                                        }
+                                        
+                                        if(Math.round(v*100) < Math.round(r.data.pohead_val*100)){
+                                            f = '<img class="x-grid-check-icon" src="' + Roo.BLANK_IMAGE_URL + '"/> &nbsp;' +
+                                                 '<span style="{0}">{1}</span>';
+                                        }
+                                        
+                                        return String.format(f,  style, v * 1 ? Roo.util.Format.usMoney(v) : '' ); 
                                      }
                                 },
                                 {
@@ -1875,6 +1951,7 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                     align : 'right',
                                     dataIndex : 'pohead_qty_in_transit',
                                     header : 'In Transit',
+                                    hidden : true,
                                     width : 75,
                                     renderer : function(v,x,r) {
                                          var vv = v - (1*r.data.pohead_qty_transfered_unposted) -
@@ -1888,7 +1965,7 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                     xns: Roo.grid,
                                     align : 'right',
                                     dataIndex : 'pohead_qty_recv',
-                                    header : 'Recieved',
+                                    header : 'Received',
                                     width : 75,
                                     renderer : function(v,x,r) {
                                        
@@ -1906,8 +1983,7 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                        
                                          var recv = (1*r.data.pohead_qty_recv) +
                                                (1*r.data.pohead_qty_transfered_unposted) +
-                                                 (1*r.data.pohead_qty_transfered) - 
-                                                 (1*r.data.pohead_qty_in_transit) ;
+                                                 (1*r.data.pohead_qty_transfered)  ;
                                                              
                                         
                                         if(r.data.pohead_qty_transfered_unposted * 1 > 0){
@@ -1991,7 +2067,7 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                             listeners : {
                                                 beforeload : function (_self, options)
                                                 {
-                                                    if (!_this.grid || !_this.grid.selModel.getSelectedCell()) {
+                                                    if (!_this.grid || !_this.grid.selModel.getSelected()) {
                                                          this.removeAll();
                                                          if (_this.rgrid) {
                                                             _this.rgrid.ds.removeAll();
@@ -1999,8 +2075,10 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                                         return false;
                                                     }
                                                     var r = _this.grid.selModel.getSelected();
+                                                    
+                                                     
                                                     options.params = options.params || {};
-                                                    options.params.recvgrp_pohead_id = _this.grid.selModel.getSelected().data.pohead_id;
+                                                    options.params.recvgrp_pohead_id = r.data.pohead_id;
                                                     
                                                 },
                                                 load : function (_self, records, options)
@@ -2848,6 +2926,7 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                                                 Roo.MessageBox.alert("Error", "Select a purchase order");
                                                                 return
                                                             }
+                                                            
                                                             Pman.Dialog.XtupleRecvGrp.show( {
                                                                  recvgrp_pohead_id : s.data.pohead_id ,
                                                                  recvgrp_pohead_id_pohead_number : s.data.pohead_number
@@ -2964,11 +3043,16 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                             listeners : {
                                                 beforeload : function (_self, options)
                                                 {
-                                                    if (!_this.grid || !_this.grid.selModel.getSelectedCell()) {
+                                                    if (!_this.grid || !_this.grid.selModel.getSelected()) {
                                                         return false;
                                                     }
+                                                     
                                                     var r = _this.grid.selModel.getSelected();
-                                                    options.params.poitem_pohead_id = _this.grid.selModel.getSelected().data.pohead_id;
+                                                    
+                                                    
+                                                    
+                                                    options.params.poitem_pohead_id = r.data.pohead_id;
+                                                    
                                                     var rr = _this.rggrid.selModel.getSelected();
                                                 
                                                     options.params.recvgrp_id = 0;
@@ -2977,7 +3061,7 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                                     }
                                                     
                                                     options.params._with_item  = 1;
-                                                        options.params.item_type = 'P';
+                                                    options.params.item_type = 'P';
                                                 }
                                             },
                                             remoteSort : true,