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