Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Pman.Tab.XtuplePurchaseRecv.js
index a000795..20399e9 100644 (file)
@@ -53,17 +53,67 @@ 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)
-                                {
-                                    _this.rggrid.ds.load({});
+                                    });  
                                 }
                             },
                             autoExpandColumn : 'pohead_vend_id_vend_name',
@@ -87,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;
                                         }
                                         
                                         
@@ -1300,7 +1355,7 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                             },
                                             select : function (combo, record, index)
                                             {
-                                                Roo.log('select');
+                                            
                                                 _this.grid.footer.onClick('first');
                                             }
                                         },
@@ -1313,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']
                                         }
@@ -1475,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;
@@ -1510,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;
@@ -1531,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',
@@ -1545,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;
@@ -1588,9 +1649,13 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                             render : function (_self)
                                             {
                                                 _this.reportSince = _self;
+                                                
+                                                this.setValue((new Date()).add(Date.MONTH, -1)) ; //.format('Y-m-d');
                                             }
                                         },
-                                        useIso : true
+                                        format : 'd/M/Y',
+                                        useIso : true,
+                                        width : 100
                                     },
                                     {
                                         xtype: 'Button',
@@ -1668,6 +1733,7 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                                                             }
                                                                         }
                                                                         
+                                                                        
                                                                         new Pman.Download({
                                                                           url : baseURL + '/Xtuple/Print',
                                                                           params :   params,
@@ -1692,7 +1758,60 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                                             {
                                                                 xtype: 'Item',
                                                                 xns: Roo.menu,
+                                                                listeners : {
+                                                                    click : function (_self, e)
+                                                                    {
+                                                                        var dt = Date.parseDate( _this.reportSince.getValue(), 'Y-m-d');
+                                                                        
+                                                                        var params = {
+                                                                            '_group' : 'recvgrp',
+                                                                            '_name' : 'byorder',
+                                                                            'limit' : 99999,
+                                                                            'startDate:text' : dt.format('Y-m-d'),
+                                                                            'endDate:text' : dt.add(Date.MONTH,1).format('Y-m-d'),
+                                                                            'csvTitles' : '*',
+                                                                            'csvCols' : '*'
+                                                                        };
+                                                                        
+                                                                        new Pman.Download({\r
+                                                                          url : baseURL + '/Roo/Metasql',\r
+                                                                          params :   params,\r
+                                                                          method : 'GET'\r
+                                                                        });\r
+                                                                        Roo.MessageBox.alert("Notice", "Report will download shortly");\r
+                                                                        \r
+                                                                    }
+                                                                },
                                                                 text : "For 1 month"
+                                                            },
+                                                            {
+                                                                xtype: 'Item',
+                                                                xns: Roo.menu,
+                                                                listeners : {
+                                                                    click : function (_self, e)
+                                                                    {
+                                                                        var dt = Date.parseDate( _this.reportSince.getValue(), 'Y-m-d');
+                                                                        
+                                                                        var params = {
+                                                                            '_group' : 'recvgrp',
+                                                                            '_name' : 'byorder',
+                                                                            'limit' : 99999,
+                                                                            'startDate:text' : dt.format('Y-m-d'),
+                                                                            'endDate:text' : dt.add(Date.YEAR,1).format('Y-m-d'),
+                                                                            'csvTitles' : '*',
+                                                                            'csvCols' : '*'
+                                                                        };
+                                                                        
+                                                                        new Pman.Download({\r
+                                                                          url : baseURL + '/Roo/Metasql',\r
+                                                                          params :   params,\r
+                                                                          method : 'GET'\r
+                                                                        });\r
+                                                                        Roo.MessageBox.alert("Notice", "Report will download shortly");\r
+                                                                        \r
+                                                                    }
+                                                                },
+                                                                text : "For 1 year"
                                                             }
                                                         ]
                                                     }
@@ -1776,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) : '' ); 
                                      }
                                 },
                                 {
@@ -1819,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) -
@@ -1832,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) {
                                        
@@ -1850,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){
@@ -1943,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)
@@ -2792,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
@@ -2911,8 +3046,13 @@ Pman.Tab.XtuplePurchaseRecv = new Roo.XComponent({
                                                     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;
@@ -2921,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,