UpdateDatabase.php
[Pman.Xtuple] / Pman.Tab.XtupleStock.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Roo.namespace('Pman.Tab');
6
7 Pman.Tab.XtupleStock = new Roo.XComponent({
8     part     :  ["Xtuple", "Stock" ],
9     order    : '001-Pman.Tab.XtupleStock',
10     region   : 'center',
11     parent   : 'Pman.Tab.XtupleManage',
12     name     : "Pman.Tab.XtupleStock",
13     disabled : false, 
14     permname : '', 
15     _tree : function()
16     {
17         var _this = this;
18         var MODULE = this;
19         return {
20             layout : {
21                 center : {
22                     '|xns' : 'Roo',
23                     xtype : 'LayoutRegion',
24                     xns : Roo
25                 },
26                 east : {
27                     '|xns' : 'Roo',
28                     title : "Stock",
29                     xtype : 'LayoutRegion',
30                     width : 250,
31                     xns : Roo,
32                     split : true
33                 },
34                 '|xns' : 'Roo',
35                 xtype : 'BorderLayout',
36                 xns : Roo,
37                 items : [
38                         {
39                         grid : {
40                             sm : {
41                                 '|xns' : 'Roo.grid',
42                                 xtype : 'RowSelectionModel',
43                                 xns : Roo.grid,
44                                 listeners : {
45                                         selectionchange : function (_self)
46                                            {
47                                               
48                                               // _this.toppanel.layout.getRegion('east').expand();
49                                            }
50                                 }
51                             },
52                             dataSource : {
53                                 proxy : {
54                                     '|xns' : 'Roo.data',
55                                     url : baseURL + '/Roo/location.php',
56                                     xtype : 'HttpProxy',
57                                     method : 'GET',
58                                     xns : Roo.data
59                                 },
60                                 reader : {
61                                     '|xns' : 'Roo.data',
62                                     id : 'id',
63                                     root : 'data',
64                                     xtype : 'JsonReader',
65                                     xns : Roo.data,
66                                     fields : [
67                                         {
68                                             'name': 'location_id',
69                                             'type': 'int'
70                                         },
71                                         {
72                                             'name': 'location_warehous_id',
73                                             'type': 'int'
74                                         },
75                                         {
76                                             'name': 'location_name',
77                                             'type': 'string'
78                                         },
79                                         {
80                                             'name': 'location_descrip',
81                                             'type': 'string'
82                                         },
83                                         {
84                                             'name': 'location_restrict',
85                                             'type': 'int'
86                                         },
87                                         {
88                                             'name': 'location_netable',
89                                             'type': 'int'
90                                         },
91                                         {
92                                             'name': 'location_whsezone_id',
93                                             'type': 'int'
94                                         },
95                                         {
96                                             'name': 'location_aisle',
97                                             'type': 'string'
98                                         },
99                                         {
100                                             'name': 'location_rack',
101                                             'type': 'string'
102                                         },
103                                         {
104                                             'name': 'location_bin',
105                                             'type': 'string'
106                                         }
107                                     ],
108                                     totalProperty : 'total'
109                                 },
110                                 '|xns' : 'Roo.data',
111                                 xtype : 'Store',
112                                 remoteSort : true,
113                                 sortInfo : { field : 'location_name', direction: 'ASC' },
114                                 xns : Roo.data,
115                                 listeners : {
116                                         beforeload : function (_self, o)
117                                            {
118                                              
119                                                o.params._as_of = _this.dateTo.getValue();
120                                            
121                                                if (!o.params._as_of.length) {
122                                                    return false;
123                                                }
124                                                o.params._with_stock_and_value = 1;
125                                                
126                                                o.params._viewType = _this.viewType.getValue();
127                                            },
128                                         load : function (_self, records, options)
129                                            {
130                                                // build index.
131                                                
132                                                var dt = Date.parseDate(_this.dateTo.getValue(), 'Y-m-d');
133                                                var maxd = Date.parseDate('2012-11-01', 'Y-m-d');
134                                                
135                                                if (!records.length) {
136                                                    return;
137                                                }
138                                                
139                                                var map = {};
140                                                
141                                                Roo.each(records, function(r) {
142                                                    map[r.data.location_id] = r;
143                                                    r.set('location_qty',undefined);
144                                                    r.set('location_qty_neg', undefined);
145                                                    r.set('location_value', undefined);
146                                                
147                                                });
148                                                var pqty = 0;
149                                                var nqty = 0;
150                                                var tval = 0.0;
151                                                 var overlaydata  =  function (type, data) {
152                                                        Roo.each(data, function(r) {
153                                                            var rec= map[r.location_id];
154                                                            
155                                                            //switch(type) { 
156                                                                //case 'netsuite':
157                                                                    rec.set('location_netsuite_stock', r.location_netsuite_stock);
158                                                                    rec.set('location_netsuite_stock_neg', r.location_netsuite_stock_neg);                        
159                                                               //     break;
160                                                             //   case 'dragon':
161                                                                    rec.set('location_qty', r.location_qty);
162                                                                    pqty += r.location_qty *1;                        
163                                                                    rec.set('location_qty_neg', r.location_qty_neg);
164                                                                    nqty += r.location_qty_neg  *1;
165                                                                    rec.set('location_value', r.location_value);
166                                                                    tval += r.location_value * 1.0;
167                                                              //      break;
168                                                                
169                                                                
170                                                            //}
171                                                        })
172                                                            
173                                                            
174                                             
175                                                 };
176                                                
177                                                var i = 0; 
178                                                
179                                                var loadoverlay = function(type) {
180                                                
181                                                     
182                                                    new Pman.Request({
183                                                        method : 'GET',
184                                                        //mask : 'Loading ' + type + ' stock levels (takes around 30s)',
185                                                        timeout: 60000,
186                                                        url : baseURL + '/Roo/Location',
187                                                        params  : {
188                                                            _as_of : _this.dateTo.getValue(),
189                                                            _with_stock_and_value : 'both',
190                                                            location_id : records[i++].data.location_id 
191                                                        },
192                                                        success : function( res ) {
193                                                            
194                                                            overlaydata(type, res.data);
195                                                        
196                                                            if (i >=  records.length) {
197                                                                 _this.grid.footer.displayEl.update(String.format("Total: pos={0} neg={1} eq={2} val={3}", 
198                                                                    Roo.util.Format.number(pqty,0), 
199                                                                    Roo.util.Format.number(nqty,0), 
200                                                                    Roo.util.Format.number(pqty+nqty,0), 
201                                                                    Roo.util.Format.number(tval,0)
202                                                                    ));
203                                                                return;
204                                                            }                
205                                                           loadoverlay(type);
206                                                            //if (type == 'dragon' && dt < maxd  ) {
207                                                            //    loadoverlay('netsuite');
208                                                           // } else {
209                                                            //
210                                                           // }
211                                                            
212                                                        
213                                                        },
214                                                        failure : function( ) {
215                                                            Roo.MessageBox.alert('Error' , 'Loading data failed, try again');
216                                                        }
217                                                    });
218                                                
219                                                };
220                                                
221                                                 loadoverlay('dragon');
222                                                
223                                                
224                                            }
225                                 },
226                                 items : [
227
228                                 ]
229
230                             },
231                             footer : {
232                                 '|xns' : 'Roo',
233                                 pageSize : 999,
234                                 xtype : 'PagingToolbar',
235                                 emptyMsg : "No location found",
236                                 xns : Roo,
237                                 displayMsg : "Displaying location{0} - {1} of {2}",
238                                 displayInfo : true,
239                                 items : [
240                                         {
241                                         '|xns' : 'Roo.Toolbar',
242                                         text : "Sync Stock Balances",
243                                         hidden : true,
244                                         xtype : 'Button',
245                                         xns : Roo.Toolbar,
246                                         listeners : {
247                                                 click : function (_self, e)
248                                                    {
249                                                      Roo.MessageBox.progress ("Syncing Balances", "Sending");
250                                                      
251                                                      var offset = 0;
252                                                      
253                                                       function runSync() {
254                                                           
255                                                           new Pman.Request( {
256                                                                url : baseURL+'/Roo/Locbal',
257                                                                method : 'GET',
258                                                                params : {
259                                                                    _sync : 1,
260                                                                    offset : offset
261                                                                },
262                                                                success : function(res) {
263                                                                   // Roo.log(res);
264                                                                    if (!res.data.total) {
265                                                                        Roo.MessageBox.hide();
266                                                                        return;
267                                                                    }
268                                                                    offset += res.data.limit;
269                                                                    Roo.MessageBox.updateProgress ( offset  / res.data.total, "Done " + offset + '/' + res.data.total);
270                                                                    runSync();
271                                                                }
272                                                                 
273                                                           });
274                                                       }
275                                                       runSync();
276                                                    }
277                                         }
278                                     },
279                                         {
280                                         menu : {
281                                             '|xns' : 'Roo.menu',
282                                             xtype : 'Menu',
283                                             xns : Roo.menu,
284                                             items : [
285                                                 {
286                                                     '|xns' : 'Roo.menu',
287                                                     text : "Transfer to Fix +ve number",
288                                                     xtype : 'Item',
289                                                     xns : Roo.menu,
290                                                     listeners : {
291                                                         click : function (_self, e)
292                                                            {
293                                                                var l = _this.grid.selModel ? _this.grid.selModel.getSelected() : false;
294                                                                if (!l) {
295                                                                    Roo.MessageBox.alert("Error", "Select location");
296                                                                    return;
297                                                                }
298                                                                
299                                                                Pman.Dialog.XtupleTransfer.show({
300                                                                    id : 0,
301                                                                    _ns_autofill : 1,
302                                                                    invhist_transfer_to : l.data.location_id,
303                                                                    invhist_transfer_to_location_descrip : l.data.location_descrip,
304                                                                    
305                                                                    invhist_transfer_transdate : _this.dateTo.getValue(),
306                                                                    invhist_transfer_arrivaldate  : _this.dateTo.getValue()
307                                                                
308                                                                    
309                                                                }, function() { _this.grid.ds.load({}); }
310                                                                );
311                                                                
312                                                                
313                                                            }
314                                                     }
315                                                 },
316                                                 {
317                                                     '|xns' : 'Roo.menu',
318                                                     text : "Transfer to Fix -ve number",
319                                                     xtype : 'Item',
320                                                     xns : Roo.menu,
321                                                     listeners : {
322                                                         click : function (_self, e)
323                                                            {
324                                                                var l = _this.grid.selModel ? _this.grid.selModel.getSelected() : false;
325                                                                if (!l) {
326                                                                    Roo.MessageBox.alert("Error", "Select location");
327                                                                    return;
328                                                                }
329                                                                
330                                                                Pman.Dialog.XtupleTransfer.show({
331                                                                    id : 0,
332                                                                    _ns_autofill : -1,
333                                                                    invhist_transfer_from : l.data.location_id,
334                                                                    invhist_transfer_from_location_descrip : l.data.location_descrip,
335                                                                    
336                                                                    invhist_transfer_transdate : _this.dateTo.getValue(),
337                                                                    invhist_transfer_arrivaldate  : _this.dateTo.getValue()
338                                                                
339                                                                    
340                                                                }, function() { _this.grid.ds.load({}); }
341                                                                );
342                                                                
343                                                                
344                                                            }
345                                                     }
346                                                 }
347                                             ]
348
349                                         },
350                                         '|xns' : 'Roo.Toolbar',
351                                         text : "Upload new products and costs",
352                                         hidden : true,
353                                         xtype : 'Button',
354                                         xns : Roo.Toolbar,
355                                         listeners : {
356                                                 click : function (_self, e)
357                                                    {
358                                                       Pman.Dialog.Image.show(
359                                                           {
360                                                                _url : baseURL+'/Xtuple/Import/Products'
361                                                            
362                                                           },
363                                                           function (data) {
364                                                                var msg = [];
365                                                               
366                                                                if (data.updated) {
367                                                                    msg.push("Updated " + data.updated + " Products(s)");
368                                                                }            
369                                                                if (data.inserted) {
370                                                                    msg.push("Added " + data.inserted + " Products(s)");
371                                                                }
372                                                                if (data.skipped) {
373                                                                    msg.push("Skipped " + data.skipped);
374                                                                }
375                                                                
376                                                                if (!msg.length) {
377                                                                    msg.push("No data changed");
378                                                                }
379                                                                Roo.MessageBox.alert("Notice", msg.join("\n"));
380                                                    
381                                                           }
382                                                       );
383                                                    }
384                                         },
385                                         items : [
386
387                                         ]
388
389                                     }
390                                 ]
391
392                             },
393                             toolbar : {
394                                 '|xns' : 'Roo',
395                                 xtype : 'Toolbar',
396                                 xns : Roo,
397                                 items : [
398                                         {
399                                         '|xns' : 'Roo.Toolbar',
400                                         text : "As of:",
401                                         xtype : 'TextItem',
402                                         xns : Roo.Toolbar
403                                     },
404                                         {
405                                         '|xns' : 'Roo.form',
406                                         format : 'd/M/Y',
407                                         useIso : 1,
408                                         xtype : 'DateField',
409                                         width : 120,
410                                         xns : Roo.form,
411                                         listeners : {
412                                                 render : function (_self)
413                                                    {
414                                                        _this.dateTo = _self;
415                                                    },
416                                                 select : function (combo, date)
417                                                    {
418                                                      _this.grid.footer.onClick('first');
419                                                    }
420                                         }
421                                     },
422                                         {
423                                         store : {
424                                             '|xns' : 'Roo.data',
425                                             xtype : 'SimpleStore',
426                                             data : [ ['local', "Local"],[ 'remote' , "Remote"],[ 'disabled', "Disabled"] ],
427                                             fields : [  'ftype', 'fname'],
428                                             xns : Roo.data
429                                         },
430                                         '|xns' : 'Roo.form',
431                                         listWidth : 200,
432                                         triggerAction : 'all',
433                                         fieldLabel : 'Status',
434                                         displayField : 'fname',
435                                         hiddenName : 'loctype',
436                                         value : "local",
437                                         valueField : 'ftype',
438                                         xtype : 'ComboBox',
439                                         allowBlank : false,
440                                         editable : false,
441                                         width : 100,
442                                         xns : Roo.form,
443                                         mode : 'local',
444                                         name : 'loctype_name',
445                                         listeners : {
446                                                 render : function (_self)
447                                                    {
448                                                        _this.viewType = _self;
449                                                    },
450                                                 select : function (combo, record, index)
451                                                    {
452                                                        _this.grid.footer.onClick('first');
453                                                    }
454                                         },
455                                         items : [
456
457                                         ]
458
459                                     },
460                                         {
461                                         '|xns' : 'Roo.Toolbar',
462                                         xtype : 'Fill',
463                                         xns : Roo.Toolbar
464                                     },
465                                         {
466                                         '|xns' : 'Roo.Toolbar',
467                                         text : "Add",
468                                         xtype : 'Button',
469                                         cls : 'x-btn-text-icon',
470                                         icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
471                                         xns : Roo.Toolbar,
472                                         listeners : {
473                                                 click : function()
474                                                    {
475                                                        // work out last 
476                                                        Pman.Dialog.XtupleLocation.show( { }, function() {
477                                                            _this.grid.footer.onClick('first');
478                                                        }); 
479                                                    },
480                                                 render : function (_self)
481                                                    {
482                                                        _this.addItemBtn = _self;
483                                                    }
484                                         }
485                                     },
486                                         {
487                                         menu : {
488                                             '|xns' : 'Roo.menu',
489                                             xtype : 'Menu',
490                                             xns : Roo.menu,
491                                             items : [
492                                                 {
493                                                     '|xns' : 'Roo.menu',
494                                                     text : "Summary of Stock in all Locatoins",
495                                                     xtype : 'Item',
496                                                     xns : Roo.menu,
497                                                     listeners : {
498                                                         click : function (_self, e)
499                                                            {
500                                                            
501                                                                var ret= [];
502                                                                var hr = [];
503                                                                var cols = [];
504                                                                Roo.each( _this.grid.colModel.config, function(h) {
505                                                                    hr.push(h.header);
506                                                                    cols.push(h.dataIndex);
507                                                                });
508                                                                ret.push(hr);
509                                                                _this.grid.ds.each(function(rec) {
510                                                                    hr = [];
511                                                                    for(var i =0;i<cols.length;i++) {
512                                                                        hr.push(rec.get(cols[i]));
513                                                                    }
514                                                                    ret.push(hr);
515                                                                });
516                                                               
517                                                                   new Pman.Download({
518                                                                        url : baseURL + '/Core/JsonToExcel',
519                                                                        method : 'POST',
520                                                                        params : {
521                                                                            _json : Roo.encode(ret) 
522                                                                        }
523                                                                    });
524                                                                 
525                                                            }
526                                                     }
527                                                 },
528                                                 {
529                                                     '|xns' : 'Roo.menu',
530                                                     xtype : 'Separator',
531                                                     xns : Roo.menu
532                                                 },
533                                                 {
534                                                     '|xns' : 'Roo.menu',
535                                                     text : "All Stock in all locations (active)",
536                                                     xtype : 'Item',
537                                                     xns : Roo.menu,
538                                                     listeners : {
539                                                         click : function (_self, e)
540                                                            {
541                                                             
542                                                                
543                                                            
544                                                                   new Pman.Download({
545                                                                        url : baseURL + '/Roo/Invdetail',
546                                                                        method : 'GET',
547                                                                        timeout: 60000,
548                                                                        params : {
549                                                                            _summary_at_date : _this.dateTo.getValue(),
550                                                                            'csvCols[0]' : 'location_name',               
551                                                                            'csvCols[1]' :  'item_number',
552                                                                            'csvCols[2]' :  'item_descrip1',                
553                                                                            'csvCols[3]' : 'stock_qty',
554                                                                            'csvCols[4]' : 'stdcost_value',
555                                                                            'csvCols[5]' : 'fifo_value',                                
556                                                                            'csvTitles[0]' :'Location',                
557                                                                            'csvTitles[1]' :  'Item Number',
558                                                                            'csvTitles[2]' :  'Item Description',                
559                                                                            'csvTitles[3]' : 'Qty', 
560                                                                            'csvTitles[4]' : 'Std Cost Valued',
561                                                                            'csvTitles[5]' : 'FIFO Value',                                
562                                                                            'sort' : 'location_name,item_number',
563                                                                            'dir' : 'ASC',  
564                                                                            _with_empty_stock : 1,      
565                                                                            limit : 99999
566                                                                                       
567                                                                        }
568                                                                    });
569                                                                    Roo.MessageBox.alert("Notice", "Report will download shortly (around 30s)");
570                                                                 
571                                                            }
572                                                     }
573                                                 },
574                                                 {
575                                                     '|xns' : 'Roo.menu',
576                                                     text : "Stock at Selected Location (inc. empty)",
577                                                     xtype : 'Item',
578                                                     xns : Roo.menu,
579                                                     listeners : {
580                                                         click : function (_self, e)
581                                                            {
582                                                                var p = {
583                                                                        'csvCols[0]' : 'itemsite_item_id_item_number',
584                                                                        'csvCols[1]' : 'item_brand_name',
585                                                                        'csvCols[2]' : 'itemsite_item_id_item_descrip1',
586                                                                        'csvCols[3]' : 'itemsite_qty_before',
587                                                                        'csvCols[4]' : 'itemsite_sold_atdate'  ,
588                                                                        'csvCols[5]' : 'itemsite_qty',          
589                                                                        'csvCols[6]' : 'itemsite_sold_after',   
590                                                                        'csvCols[7]' : 'last_transaction',
591                                                                        'csvCols[8]' : 'customer_price_each',                           
592                                                                        'csvCols[9]' : 'customer_total_value',                                    
593                                                                        'csvCols[10]' : 'itemsite_value',
594                                                                        'csvCols[11]' : 'item_last_purchase_price',
595                                                                        
596                                                                        'csvTitles[0]' : 'SKU',
597                                                                        'csvTitles[1]' : 'Brand'  ,
598                                                                        'csvTitles[2]' : 'Description',            
599                                                                        'csvTitles[3]' : 'Qty Before'  , 
600                                                                        'csvTitles[4]' : 'Total Sold'  , 
601                                                                        'csvTitles[5]' : 'Qty'  , 
602                                                                        'csvTitles[6]' : 'Sold After'  , 
603                                                                        'csvTitles[7]' : 'Last Transaction'  ,
604                                                                        'csvTitles[8]' : 'Customer unit price'  ,
605                                                                        'csvTitles[9]' : 'Customer Total Value'  ,
606                                                                        'csvTitles[10]' : 'FIFO value'  ,
607                                                                        'csvTitles[11]' : 'Last Purchase Price'  ,       
608                                                            
609                                                            
610                                                                        
611                                                                        
612                                                                        'sort' : 'itemsite_item_id_item_number',
613                                                                        'dir' : 'ASC',        
614                                                                        limit : 9999
615                                                                };
616                                                                 var l = _this.grid.selModel ? _this.grid.selModel.getSelected() : false;
617                                                                if (!l) {
618                                                                    Roo.MessageBox.alert("Error", "Select location");
619                                                                    return;
620                                                                }
621                                                                p.location_id = l.data.location_id;
622                                                                p._as_of = _this.dateTo.getValue();
623                                                                p._with_stock_and_value = 1;
624                                                                p._viewtype = 1;
625                                                                p._with_brand = 1;
626                                                                p._with_last_purchase_price = 1;
627                                                                p._with_qty_detail = 1;
628                                                                
629                                                                    new Pman.Download({
630                                                                        url : baseURL + '/Roo/itemsite',
631                                                                        timeout : 60000,
632                                                                        
633                                                                        method : 'GET',
634                                                                        params : p
635                                                            
636                                                                    
637                                                                    });
638                                                                    Roo.MessageBox.alert("Notice", "Report will download shortly");
639                                                            }
640                                                     }
641                                                 },
642                                                 {
643                                                     '|xns' : 'Roo.menu',
644                                                     xtype : 'Separator',
645                                                     xns : Roo.menu
646                                                 },
647                                                 {
648                                                     '|xns' : 'Roo.menu',
649                                                     text : "Stock at Selected Location (inc. empty) with Adjustment details",
650                                                     xtype : 'Item',
651                                                     xns : Roo.menu,
652                                                     listeners : {
653                                                         click : function (_self, e)
654                                                            {
655                                                                 
656                                                                 var p = {
657                                                                    _group : 'itemsite',
658                                                                    _name : 'stockatlocation',
659                                                                    csvCols : '*',
660                                                                    limit : 99999
661                                                                 };
662                                                                 var l = _this.grid.selModel ? _this.grid.selModel.getSelected() : false;
663                                                                if (!l) {
664                                                                    Roo.MessageBox.alert("Error", "Select location");
665                                                                    return;
666                                                                }
667                                                                p['location_id:number'] = l.data.location_id;
668                                                                p['as_of:text'] = _this.dateTo.getValue();
669                                                                
670                                                                    new Pman.Download({
671                                                                        url : baseURL + '/Roo/Metasql',
672                                                                        newWindow : 1,
673                                                                        timeout : 60000,
674                                                                        
675                                                                        method : 'GET',
676                                                                        params : p
677                                                            
678                                                                    
679                                                                    });
680                                                                    Roo.MessageBox.alert("Notice", "Report will download shortly");
681                                                            }
682                                                     }
683                                                 }
684                                             ]
685
686                                         },
687                                         '|xns' : 'Roo.Toolbar',
688                                         text : "Download Reports",
689                                         xtype : 'Button',
690                                         xns : Roo.Toolbar,
691                                         items : [
692
693                                         ]
694
695                                     }
696                                 ]
697
698                             },
699                             '|xns' : 'Roo.grid',
700                             autoExpandColumn : 'location_name',
701                             xtype : 'Grid',
702                             loadMask : true,
703                             xns : Roo.grid,
704                             colModel : [
705                                  {
706                                         '|xns' : 'Roo.grid',
707                                         xtype : 'ColumnModel',
708                                         header : 'Active',
709                                         width : 50,
710                                         renderer : function(v) {  
711                                             var state = v * 1 > 0 ?  '' :  '-checked' ;
712                                         
713                                             return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
714                                                         
715                                          },
716                                         xns : Roo.grid,
717                                         dataIndex : 'location_restrict'
718                                     },
719 {
720                                         '|xns' : 'Roo.grid',
721                                         xtype : 'ColumnModel',
722                                         header : 'Name',
723                                         width : 200,
724                                         renderer : function(v) { return String.format('{0}', v); },
725                                         xns : Roo.grid,
726                                         dataIndex : 'location_name'
727                                     },
728 {
729                                         '|xns' : 'Roo.grid',
730                                         xtype : 'ColumnModel',
731                                         header : 'Description',
732                                         width : 200,
733                                         renderer : function(v) { return String.format('{0}', v); },
734                                         xns : Roo.grid,
735                                         dataIndex : 'location_descrip'
736                                     },
737 {
738                                         '|xns' : 'Roo.grid',
739                                         xtype : 'ColumnModel',
740                                         header : 'Customer',
741                                         width : 200,
742                                         renderer : function(v,x,r) { 
743                                         
744                                             if (!r.data.location_cust_id_char_internalcompany.length) {
745                                                return String.format('{0}', v); 
746                                             }
747                                            return String.format('<span style="color:red">[Internal Company : {0}] {1} </span>', 
748                                                 r.data.location_cust_id_char_internalcompany,        v); 
749                                             
750                                         },
751                                         xns : Roo.grid,
752                                         dataIndex : 'location_cust_id_cust_name'
753                                     },
754 {
755                                         '|xns' : 'Roo.grid',
756                                         align : 'right',
757                                         xtype : 'ColumnModel',
758                                         header : 'Qty',
759                                         width : 75,
760                                         renderer : function(v,x,r) { return  typeof(v) == 'undefined' ? '...' : String.format('{0} ', (v*1).toFixed(0) ); },
761                                         xns : Roo.grid,
762                                         dataIndex : 'location_qty'
763                                     },
764 {
765                                         '|xns' : 'Roo.grid',
766                                         align : 'right',
767                                         xtype : 'ColumnModel',
768                                         header : 'Missing TX',
769                                         width : 75,
770                                         renderer : function(v,x,r) { 
771                                             if ( typeof(v) == 'undefined') {
772                                                 return '';
773                                             }
774                                             if (v == 0) {
775                                                 return '';
776                                             }
777                                             
778                                             return String.format('<span style="color:red;">{0}</span>', (v*1).toFixed(0) ); 
779                                         },
780                                         xns : Roo.grid,
781                                         dataIndex : 'location_qty_neg'
782                                     },
783 {
784                                         '|xns' : 'Roo.grid',
785                                         align : 'right',
786                                         xtype : 'ColumnModel',
787                                         header : 'Est. Net Qty',
788                                         width : 75,
789                                         renderer : function(v,x,r) { 
790                                             
791                                             return typeof(v) == 'undefined' ? '...' : 
792                                                 String.format('{0}', ((v*1) + (r.data.location_qty_neg*1)).toFixed(0) ); 
793                                         },
794                                         xns : Roo.grid,
795                                         dataIndex : 'location_qty'
796                                     },
797 {
798                                         '|xns' : 'Roo.grid',
799                                         align : 'right',
800                                         hidden : true,
801                                         xtype : 'ColumnModel',
802                                         header : 'NS Qty',
803                                         width : 75,
804                                         renderer : function(v,x,r) {
805                                             var f= '{0}';
806                                             if ((r.data.location_qty) *1 != (v*1)) {
807                                                 f = '<span style="color:red;font-weight:bold">{0}</span>';
808                                             }
809                                              return typeof(v) == 'undefined' ? '...' : String.format(f, (v*1).toFixed(0) );
810                                              
811                                           },
812                                         xns : Roo.grid,
813                                         dataIndex : 'location_netsuite_stock'
814                                     },
815 {
816                                         '|xns' : 'Roo.grid',
817                                         align : 'right',
818                                         hidden : true,
819                                         xtype : 'ColumnModel',
820                                         header : 'NS -ve Qty',
821                                         width : 75,
822                                         renderer : function(v,x,r) {     
823                                             var f= '{0}';
824                                             if ((r.data.location_qty_neg) *1 != (v*1)) {
825                                                 f = '<span style="color:red;font-weight:bold">{0}</span>';
826                                             }
827                                              return typeof(v) == 'undefined' ? '...' : String.format(f, (v*1).toFixed(0) ); 
828                                          },
829                                         xns : Roo.grid,
830                                         dataIndex : 'location_netsuite_stock_neg'
831                                     },
832 {
833                                         '|xns' : 'Roo.grid',
834                                         align : 'right',
835                                         xtype : 'ColumnModel',
836                                         header : 'Value',
837                                         width : 200,
838                                         renderer : function(v) { return typeof(v) == 'undefined' ? '...' :  Roo.util.Format.usMoney(  v); },
839                                         xns : Roo.grid,
840                                         dataIndex : 'location_value'
841                                     }
842                             ],
843                             listeners : {
844                                 rowdblclick : function (_self, rowIndex, e)
845                                    {
846                                        
847                                        Pman.Dialog.XtupleLocation.show( this.getDataSource().getAt(rowIndex).data, function() {
848                                            _this.grid.footer.onClick('first');
849                                        }); 
850                                    },
851                                 cellclick : function (_self, rowIndex, col, e)
852                                    {
853                                       
854                                        var ix = this.colModel.getDataIndex(col);
855                                        var rec = _this.grid.ds.getAt(rowIndex);
856                                      
857                                      
858                                         
859                                         if (ix == 'location_restrict') {
860                                         
861                                            var nv = rec.data.location_restrict  ? 0 : 1;
862                                            new Pman.Request({
863                                                mask : 'Saving',
864                                                url : baseURL + '/Roo/Location',
865                                                params : {
866                                                    location_id : rec.data.location_id,
867                                                    location_restrict : nv
868                                                },
869                                                success : function() {
870                                                    rec.set('location_restrict', nv);
871                                                }
872                                            });
873                                            return;
874                                            
875                                         
876                                         }
877                                      
878                                      
879                                      
880                                      
881                                         _this.itemgrid.viewtype = 1;
882                                        
883                                        
884                                         if ('location_qty_neg' == ix || 'location_netsuite_stock_neg' == ix ) {
885                                                 _this.itemgrid.viewtype = -1;
886                                         }
887                                         if ('location_netsuite_stock' == ix || 'location_netsuite_stock_neg' == ix ) {
888                                                 _this.itemgrid.viewtype *= 2;
889                                         }
890                                            
891                                            (function() { _this.itemgrid.footer.onClick('first'); }).defer(100);
892                                            
893                                            
894                                            
895                                            
896                                              
897                                            
898                                            
899                                            
900                                            
901                                            
902                                            
903                                            
904                                            
905                                            
906                                            
907                                            
908                                    },
909                                 render : function() 
910                                    {
911                                        _this.grid = this; 
912                                        //_this.dialog = Pman.Dialog.FILL_IN
913                                        if (_this.panel.active) {
914                                           this.footer.onClick('first');
915                                        }
916                                    }
917                             },
918                             items : [
919
920                             ]
921
922                         },
923                         '|xns' : 'Roo',
924                         fitToframe : true,
925                         background : true,
926                         region : 'center',
927                         title : "location",
928                         xtype : 'GridPanel',
929                         fitContainer : true,
930                         xns : Roo,
931                         tableName : 'location',
932                         listeners : {
933                                 activate : function() {
934                                        _this.panel = this;
935                                        if (_this.grid) {
936                                            _this.grid.footer.onClick('first');
937                                        }
938                                    }
939                         },
940                         items : [
941
942                         ]
943
944                     },
945                         {
946                         grid : {
947                             dataSource : {
948                                 proxy : {
949                                     '|xns' : 'Roo.data',
950                                     url : baseURL + '/Roo/itemsite.php',
951                                     method : 'GET',
952                                     xtype : 'HttpProxy',
953                                     timeout : 120000,
954                                     xns : Roo.data
955                                 },
956                                 reader : {
957                                     '|xns' : 'Roo.data',
958                                     id : 'id',
959                                     root : 'data',
960                                     xtype : 'JsonReader',
961                                     xns : Roo.data,
962                                     fields : [
963                                         {
964                                             'name': 'itemloc_id',
965                                             'type': 'int'
966                                         },
967                                         {
968                                             'name': 'itemloc_itemsite_id',
969                                             'type': 'int'
970                                         },
971                                         {
972                                             'name': 'itemloc_location_id',
973                                             'type': 'int'
974                                         },
975                                         {
976                                             'name': 'itemloc_qty',
977                                             'type': 'float'
978                                         },
979                                         {
980                                             'name': 'itemloc_expiration',
981                                             'type': 'date',
982                                             'dateFormat': 'Y-m-d'
983                                         },
984                                         {
985                                             'name': 'itemloc_consolflag',
986                                             'type': 'int'
987                                         },
988                                         {
989                                             'name': 'itemloc_ls_id',
990                                             'type': 'int'
991                                         },
992                                         {
993                                             'name': 'itemloc_warrpurc',
994                                             'type': 'date',
995                                             'dateFormat': 'Y-m-d'
996                                         }
997                                     ],
998                                     totalProperty : 'total'
999                                 },
1000                                 '|xns' : 'Roo.data',
1001                                 xtype : 'Store',
1002                                 remoteSort : true,
1003                                 sortInfo : { field : 'itemsite_item_id_item_number', direction: 'ASC' },
1004                                 xns : Roo.data,
1005                                 listeners : {
1006                                         beforeload : function (_self, o)
1007                                            {
1008                                                var l = _this.grid.selModel ? _this.grid.selModel.getSelected() : false;
1009                                                if (!l) {
1010                                                    return false;
1011                                                }
1012                                                o.params.location_id = l.data.location_id;
1013                                                o.params._as_of = _this.dateTo.getValue();
1014                                                o.params._with_stock_and_value = 1;
1015                                                o.params._viewtype =  _this.itemgrid.viewtype;
1016                                            }
1017                                 },
1018                                 items : [
1019
1020                                 ]
1021
1022                             },
1023                             footer : {
1024                                 '|xns' : 'Roo',
1025                                 pageSize : 25,
1026                                 xtype : 'PagingToolbar',
1027                                 emptyMsg : "No itemloc found",
1028                                 xns : Roo,
1029                                 displayMsg : "{0} - {1} of {2}",
1030                                 displayInfo : true
1031                             },
1032                             '|xns' : 'Roo.grid',
1033                             autoExpandColumn : 'itemsite_item_id_item_number',
1034                             xtype : 'Grid',
1035                             loadMask : true,
1036                             xns : Roo.grid,
1037                             colModel : [
1038                                  {
1039                                         '|xns' : 'Roo.grid',
1040                                         xtype : 'ColumnModel',
1041                                         header : 'Item',
1042                                         width : 75,
1043                                         renderer : function(v) { return String.format('{0}', v); },
1044                                         xns : Roo.grid,
1045                                         dataIndex : 'itemsite_item_id_item_number'
1046                                     },
1047 {
1048                                         '|xns' : 'Roo.grid',
1049                                         align : 'right',
1050                                         xtype : 'ColumnModel',
1051                                         header : 'Qty',
1052                                         width : 55,
1053                                         renderer : function(v) { return String.format('{0}', (v*1).toFixed(0)); },
1054                                         xns : Roo.grid,
1055                                         dataIndex : 'itemsite_qty'
1056                                     },
1057 {
1058                                         '|xns' : 'Roo.grid',
1059                                         align : 'right',
1060                                         hidden : true,
1061                                         xtype : 'ColumnModel',
1062                                         header : 'NS Qty',
1063                                         width : 50,
1064                                         renderer : function(v,x,r) {     
1065                                             var f= '<span style="color:blue;text-decoration:underline;cursor:pointer;">{0}</span>';
1066                                             if ((r.data.itemsite_qty) *1 != (v*1)) {
1067                                                 f = '<span style="color:red;font-weight:bold;text-decoration:underline;cursor:pointer;">{0}</span>';
1068                                             }
1069                                             return String.format(f, (v*1).toFixed(0) ); 
1070                                         },
1071                                         xns : Roo.grid,
1072                                         dataIndex : 'netsuite_qty'
1073                                     },
1074 {
1075                                         '|xns' : 'Roo.grid',
1076                                         align : 'right',
1077                                         xtype : 'ColumnModel',
1078                                         header : 'Value',
1079                                         width : 75,
1080                                         renderer : function(v) { return Roo.util.Format.usMoney(v); },
1081                                         xns : Roo.grid,
1082                                         dataIndex : 'itemsite_value'
1083                                     }
1084                             ],
1085                             listeners : {
1086                                 rowdblclick : function (_self, rowIndex, e)
1087                                    {  
1088                                        var rec =this.getDataSource().getAt(rowIndex);
1089                                    
1090                                        var loc = _this.grid.selModel.getSelected();
1091                                      
1092                                        var dt = _this.dateTo.getValue();
1093                                        
1094                                      Pman.Dialog.XtupleInvHistory.show({
1095                                            itemsite_item_id_item_number   : rec.data.itemsite_item_id_item_number,
1096                                      
1097                                            location_name : loc.data.location_name,
1098                                            location_descrip : loc.data.location_descrip,
1099                                            
1100                                            invhist_transdate :  typeof(dt) == 'string' ? dt : dt.format('Y-m-d')
1101                                        }); 
1102                                        
1103                                       
1104                                    
1105                                    },
1106                                 cellclick : function (_self, row, col, e)
1107                                    {
1108                                    
1109                                       if ('netsuite_qty' == this.colModel.getDataIndex(col)) {
1110                                            var d = this.ds.getAt(row); 
1111                                            var loc = _this.grid.selModel.getSelected();
1112                                     
1113                                           new Pman.Download({
1114                                                url: baseURL + '/Xtuple/NetsuiteFix/StockCheck',
1115                                                params : {
1116                                                    item_id : d.data.itemsite_item_id,
1117                                                    location_id : loc.data.location_id
1118                                                }
1119                                               
1120                                            
1121                                            });
1122                                        }
1123                                    },
1124                                 render : function() 
1125                                    {
1126                                        _this.itemgrid = this; 
1127                                        //_this.dialog = Pman.Dialog.FILL_IN
1128                                        if (_this.itempanel.active) {
1129                                          // this.footer.onClick('first');
1130                                        }
1131                                    }
1132                             },
1133                             items : [
1134
1135                             ]
1136
1137                         },
1138                         '|xns' : 'Roo',
1139                         fitToframe : true,
1140                         background : true,
1141                         region : 'east',
1142                         title : "itemloc",
1143                         xtype : 'GridPanel',
1144                         fitContainer : true,
1145                         xns : Roo,
1146                         tableName : 'itemloc',
1147                         listeners : {
1148                                 activate : function() {
1149                                        _this.itempanel = this;
1150                                        if (_this.itemgrid) {
1151                                           // _this.itemgrid.footer.onClick('first');
1152                                        }
1153                                    }
1154                         },
1155                         items : [
1156
1157                         ]
1158
1159                     }
1160                 ]
1161
1162             },
1163             '|xns' : 'Roo',
1164             background : true,
1165             region : 'center',
1166             title : "Locations /Stock ",
1167             xtype : 'NestedLayoutPanel',
1168             xns : Roo,
1169             listeners : {
1170                 render : function (_self)
1171                    {
1172                     _this.toppanel = _self;
1173                    }
1174             },
1175             items : [
1176
1177             ]
1178
1179         };    }
1180 });