Fix #7123 - getting abra ready to test
[Pman.Xtuple] / Pman.Dialog.XtuplePurchaseOrder.js
index 2cb4ae9..a6c52c2 100644 (file)
@@ -62,6 +62,9 @@ Pman.Dialog.XtuplePurchaseOrder = {
                                             _this.saveBtn.show();
                                             _this.form.findField('pohead_agent_username').setValue(Pman.Login.authUser.name);
                                             _this.form.findField('pohead_orderdate').setValue(new Date());
+                                            _this.form.findField('pohead_bg_arrival_est_day').setValue(new Date());
+                                            _this.form.findField('pohead_bg_available_est_day').setValue(new Date());
+                                            _this.form.findField('pohead_bg_available_latest_day').setValue(new Date());
                                             return;
                                         }
                                         _this.dialog.setTitle("Edit Purchase Order");
@@ -703,7 +706,7 @@ Pman.Dialog.XtuplePurchaseOrder = {
                                                 Roo.MessageBox.alert("Error", "Select a cell");
                                                 return;
                                             }
-                                            _this.grid.stopEditing()
+                                            _this.grid.stopEditing();
                                             var r = _this.grid.ds.getAt(cs[0]);
                                             
                                             if(r.data.poitem_qty_received * 1 > 0){
@@ -912,6 +915,7 @@ Pman.Dialog.XtuplePurchaseOrder = {
                                     field : {
                                         xtype: 'NumberField',
                                         xns: Roo.form,
+                                        allowBlank : false,
                                         allowDecimals : false,
                                         decimalPrecision : 0,
                                         minValue : 1,
@@ -1022,6 +1026,10 @@ Pman.Dialog.XtuplePurchaseOrder = {
                                                 
                                                 o.params._with_item = 1;
                                                 
+                                            },
+                                            load : function (_self, records, options)
+                                            {
+                                                _this.gltransgrid.footer.onClick('first');
                                             }
                                         },
                                         remoteSort : true,
@@ -1215,6 +1223,13 @@ Pman.Dialog.XtuplePurchaseOrder = {
                                             width : 50,
                                             renderer : function(v,x,r) 
                                             {
+                                                
+                                            
+                                                var recv = (v- r.data.poitem_qty_returned);
+                                                if (recv !=  r.data.tx_qty) {
+                                                    return String.format('<s style="color:red;font-weight:bold">{0}</s>{1} ', recv, 
+                                                        (r.data.tx_qty *1).toFixed(0)        ) ;      
+                                                }
                                                 return String.format('{0}', (v- r.data.poitem_qty_returned)) ;  
                                                 
                                             }
@@ -1282,7 +1297,7 @@ Pman.Dialog.XtuplePurchaseOrder = {
                                                 
                                                 var s = _this.itemgrid.getSelectionModel().getSelected();
                                                 if(!s){
-                                                    Roo.MessageBox.alert('Error', 'Please select a item');
+                                                    this.removeAll();
                                                     return false;
                                                 }
                                                 
@@ -1464,11 +1479,97 @@ Pman.Dialog.XtuplePurchaseOrder = {
                                             {
                                                 xtype: 'Button',
                                                 xns: Roo.Toolbar,
-                                                text : "Varience",
+                                                text : "Apply fixes",
                                                 menu : {
                                                     xtype: 'Menu',
                                                     xns: Roo.menu,
                                                     items : [
+                                                        {
+                                                            xtype: 'Item',
+                                                            xns: Roo.menu,
+                                                            listeners : {
+                                                                click : function()
+                                                                {
+                                                                   var pohead_number = _this.form.findField('pohead_number').getValue();
+                                                                    var pohead_id = _this.form.findField('pohead_id').getValue();
+                                                                        
+                                                                    
+                                                                        new Pman.Request({
+                                                                            url : baseURL + '/Roo/pohead.php',
+                                                                            mask : 'sending',
+                                                                            method :'POST',
+                                                                            params : {
+                                                                                pohead_id : pohead_id,
+                                                                                _recv_fix : 1
+                                                                                
+                                                                            },
+                                                                            success : function(res) {
+                                                                                Roo.MessageBox.alert('Notice', 'DONE');
+                                                                            }
+                                                                        });
+                                                                    
+                                                                    
+                                                                    
+                                                                    
+                                                                    
+                                                                }
+                                                            },
+                                                            cls : 'x-btn-text-icon',
+                                                            text : "Repost goods reciept",
+                                                            icon : rootURL + '/Pman/templates/images/trash.gif'
+                                                        },
+                                                        {
+                                                            xtype: 'Separator',
+                                                            xns: Roo.menu
+                                                        },
+                                                        {
+                                                            xtype: 'Item',
+                                                            xns: Roo.menu,
+                                                            listeners : {
+                                                                click : function()
+                                                                {
+                                                                    var pohead_number = _this.form.findField('pohead_number').getValue();
+                                                                    var pohead_id = _this.form.findField('pohead_id').getValue();
+                                                                        
+                                                                    var fixit = function(){
+                                                                        new Pman.Request({
+                                                                            url : baseURL + '/Roo/pohead.php',
+                                                                            method :'POST',
+                                                                            params : {
+                                                                                pohead_id : pohead_id,
+                                                                                _unitcost : 1
+                                                                                
+                                                                            },
+                                                                            success : function(res) {
+                                                                                Roo.MessageBox.alert('Notice', 'DONE');
+                                                                            }
+                                                                        });
+                                                                    }
+                                                                    
+                                                                    Roo.MessageBox.confirm(
+                                                                        "Confirm",
+                                                                        "Are you sure to fix the unit cost of " + pohead_number + " ?",
+                                                                        function(r) {
+                                                                            if (r != 'yes') {
+                                                                                return;
+                                                                            }
+                                                                
+                                                                            fixit();
+                                                                            return;
+                                                                        }
+                                                                    ); 
+                                                                    
+                                                                    
+                                                                }
+                                                            },
+                                                            cls : 'x-btn-text-icon',
+                                                            text : "Fix Unit Cost",
+                                                            icon : rootURL + '/Pman/templates/images/trash.gif'
+                                                        },
+                                                        {
+                                                            xtype: 'Separator',
+                                                            xns: Roo.menu
+                                                        },
                                                         {
                                                             xtype: 'Item',
                                                             xns: Roo.menu,
@@ -1610,53 +1711,57 @@ Pman.Dialog.XtuplePurchaseOrder = {
                                                             cls : 'x-btn-text-icon',
                                                             text : "Delete Varinace on voucher",
                                                             icon : rootURL + '/Pman/templates/images/trash.gif'
-                                                        }
-                                                    ]
-                                                }
-                                            },
-                                            {
-                                                xtype: 'Button',
-                                                xns: Roo.Toolbar,
-                                                listeners : {
-                                                    click : function()
-                                                    {
-                                                        var pohead_number = _this.form.findField('pohead_number').getValue();
-                                                        var pohead_id = _this.form.findField('pohead_id').getValue();
-                                                            
-                                                        var fixit = function(){
-                                                            new Pman.Request({
-                                                                url : baseURL + '/Roo/pohead.php',
-                                                                method :'POST',
-                                                                params : {
-                                                                    pohead_id : pohead_id,
-                                                                    _unitcost : 1
+                                                        },
+                                                        {
+                                                            xtype: 'Separator',
+                                                            xns: Roo.menu
+                                                        },
+                                                        {
+                                                            xtype: 'Item',
+                                                            xns: Roo.menu,
+                                                            listeners : {
+                                                                click : function()
+                                                                {
+                                                                    var pohead_number = _this.form.findField('pohead_number').getValue();
+                                                                    var pohead_id = _this.form.findField('pohead_id').getValue();
+                                                                        
+                                                                    var addv = function(){
+                                                                        new Pman.Request({
+                                                                            url : baseURL + '/Roo/pohead.php',
+                                                                            method :'POST',
+                                                                            params : {
+                                                                                pohead_id : pohead_id,
+                                                                                _fix_voids : 1
+                                                                                
+                                                                            },
+                                                                            success : function(res) {
+                                                                                Roo.MessageBox.alert('Notice', 'DONE');
+                                                                            }
+                                                                        });
+                                                                    }
+                                                                    
+                                                                    Roo.MessageBox.confirm(
+                                                                        "Confirm",
+                                                                        "Are you sure to add all the fix the voids for " + pohead_number + " ?",
+                                                                        function(r) {
+                                                                            if (r != 'yes') {
+                                                                                return;
+                                                                            }
+                                                                
+                                                                            addv();
+                                                                            return;
+                                                                        }
+                                                                    ); 
+                                                                    
                                                                     
-                                                                },
-                                                                success : function(res) {
-                                                                    Roo.MessageBox.alert('Notice', 'DONE');
                                                                 }
-                                                            });
+                                                            },
+                                                            cls : 'x-btn-text-icon',
+                                                            text : "Recalculate voids",
+                                                            icon : Roo.rootURL + 'images/default/tree/leaf.gif'
                                                         }
-                                                        
-                                                        Roo.MessageBox.confirm(
-                                                            "Confirm",
-                                                            "Are you sure to fix the unit cost of " + pohead_number + " ?",
-                                                            function(r) {
-                                                                if (r != 'yes') {
-                                                                    return;
-                                                                }
-                                                    
-                                                                fixit();
-                                                                return;
-                                                            }
-                                                        ); 
-                                                        
-                                                        
-                                                    }
-                                                },
-                                                cls : 'x-btn-text-icon',
-                                                text : "Fix Unit Cost",
-                                                icon : rootURL + '/Pman/templates/images/trash.gif'
+                                                    ]
+                                                }
                                             },
                                             {
                                                 xtype: 'Button',
@@ -1731,6 +1836,20 @@ Pman.Dialog.XtuplePurchaseOrder = {
                                             width : 80,
                                             renderer : function(v) { return String.format('{0}', v); }
                                         },
+                                        {
+                                            xtype: 'ColumnModel',
+                                            xns: Roo.grid,
+                                            align : 'right',
+                                            dataIndex : 'location_name',
+                                            header : 'Location',
+                                            width : 60,
+                                            renderer : function(v,x,r) {
+                                              
+                                               
+                                                return String.format('{0}', v); 
+                                            
+                                            }
+                                        },
                                         {
                                             xtype: 'ColumnModel',
                                             xns: Roo.grid,
@@ -1854,6 +1973,10 @@ Pman.Dialog.XtuplePurchaseOrder = {
                                                     return false;
                                                 }
                                                 o.params._split_sales = _this.glsalesbtn.pressed ? 1 : 0;
+                                            },
+                                            load : function (_self, records, options)
+                                            {
+                                             _this.gltxdgrid.footer.onClick('first');
                                             }
                                         },
                                         remoteSort : true,
@@ -2163,6 +2286,57 @@ Pman.Dialog.XtuplePurchaseOrder = {
                                     },
                                     autoExpandColumn : 'gltrans_notes',
                                     loadMask : true,
+                                    toolbar : {
+                                        xtype: 'Toolbar',
+                                        xns: Roo,
+                                        items : [
+                                            {
+                                                xtype: 'Button',
+                                                xns: Roo.Toolbar,
+                                                listeners : {
+                                                    render : function (_self)
+                                                    {
+                                                        _this.glvoidshow = _self;
+                                                    },
+                                                    click : function (_self, e)
+                                                    {
+                                                        (function()  { _this.gltxgrid.footer.onClick('first'); }).defer(100);
+                                                    }
+                                                },
+                                                enableToggle : true,
+                                                pressed : true,
+                                                text : "Hide Void"
+                                            },
+                                            {
+                                                xtype: 'Fill',
+                                                xns: Roo.Toolbar
+                                            },
+                                            {
+                                                xtype: 'Button',
+                                                xns: Roo.Toolbar,
+                                                listeners : {
+                                                    click : function (_self, e)
+                                                    {
+                                                        new Pman.Request( {
+                                                            url : baseURL + '/Roo/Gltrans',
+                                                            method : 'GET',
+                                                            mask:  'sending',
+                                                            params : {
+                                                                pohead_id : _this.form.findField('pohead_id').getValue(),
+                                                                _autovoid : 1
+                                                            },
+                                                            success : function() {
+                                                                _this.gltxpanel.footer.onClick('first');
+                                                            }
+                                                                
+                                                        
+                                                        });
+                                                    }
+                                                },
+                                                text : "AutoVoid"
+                                            }
+                                        ]
+                                    },
                                     dataSource : {
                                         xtype: 'Store',
                                         xns: Roo.data,
@@ -2272,23 +2446,6 @@ Pman.Dialog.XtuplePurchaseOrder = {
                                                     }
                                                 },
                                                 text : "Download"
-                                            },
-                                            {
-                                                xtype: 'Button',
-                                                xns: Roo.Toolbar,
-                                                listeners : {
-                                                    render : function (_self)
-                                                    {
-                                                        _this.glvoidshow = _self;
-                                                    },
-                                                    click : function (_self, e)
-                                                    {
-                                                        (function()  { _this.gltxgrid.footer.onClick('first'); }).defer(100);
-                                                    }
-                                                },
-                                                enableToggle : true,
-                                                pressed : true,
-                                                text : "Hide Void"
                                             }
                                         ]
                                     },
@@ -2531,8 +2688,12 @@ Pman.Dialog.XtuplePurchaseOrder = {
                         {
                             if(_this.grid){
                                 var ar = [];
-                        
+                                var err = false;
                                 _this.grid.ds.each(function(r) {
+                                    if(r.data.poitem_unitprice < 1){
+                                        err = true;
+                                        return;
+                                    }
                                     ar.push({
                                         poitem_id : r.data.poitem_id,
                                         poitem_itemsite_id : r.data.poitem_itemsite_id,
@@ -2541,7 +2702,12 @@ Pman.Dialog.XtuplePurchaseOrder = {
                                     });
                                         
                                 });
-                                
+                         
+                                if(err){
+                                    Roo.MessageBox.alert('Error','Unit Price does not allow $0' );
+                                    return;
+                                }   
+                                       
                                 _this.form.findField('items').setValue(JSON.stringify(ar));
                             }