Pman.Tab.XtupleItem.bjs
[Pman.Xtuple] / Pman.Tab.XtupleItem.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.XtupleItem = new Roo.XComponent({
6     part     :  ["Xtuple","Item"],
7     order    : '200-Pman.Tab.XtupleItem',
8     region   : 'center',
9     parent   : 'Pman.Tab.XtupleManage',
10     name     : "Pman.Tab.XtupleItem",
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             background : true,
21             region : 'center',
22             title : "Products",
23             layout : {
24                 xtype: 'BorderLayout',
25                 xns: Roo,
26                 items : [
27                     {
28                         xtype: 'GridPanel',
29                         xns: Roo,
30                         listeners : {
31                             activate : function() {
32                                 _this.panel = this;
33                                 if (_this.grid) {
34                                     _this.grid.footer.onClick('first');
35                                 }
36                             }
37                         },
38                         background : true,
39                         fitContainer : true,
40                         fitToframe : true,
41                         region : 'center',
42                         tableName : 'item',
43                         title : "Products",
44                         grid : {
45                             xtype: 'EditorGrid',
46                             xns: Roo.grid,
47                             listeners : {
48                                 render : function() 
49                                 {
50                                     _this.grid = this; 
51                                     //_this.dialog = Pman.Dialog.FILL_IN
52                                     if (_this.panel.active) {
53                                        this.footer.onClick('first');
54                                     }
55                                 },
56                                 cellclick : function (_self, row, col, e)
57                                 {
58                                      var di = _this.grid.colModel.getDataIndex(col);
59                                      
60                                      var rec = _this.grid.ds.getAt(row);
61                                      
62                                      if(di == 'item_image_filename'){
63                                         if(!rec.data.item_image_id){
64                                             return;
65                                         }
66                                         var u = baseURL;
67                                         if(rec.data.item_image_from_hk){
68                                             u = u.split('/');
69                                             u.pop();
70                                             u = u.join('/') + '/hk.php';
71                                         }
72                                         Pman.download( {
73                                            url: u + '/Images/Download/' + rec.data.item_image_id  + '/' + rec.data.item_image_filename
74                                        });
75                                        return;
76                                      }
77                                      
78                                      if (di == 'item_active') {
79                                      
80                                         var nv = rec.data.item_active ? 0 : 1;
81                                         new Pman.Request({
82                                             mask : 'Saving',
83                                             url : baseURL + '/Roo/Item',
84                                             params : {
85                                                 item_id : rec.data.item_id,
86                                                 item_active : nv
87                                             },
88                                             success : function() {
89                                                 rec.set('item_active', nv);
90                                             }
91                                         });
92                                         return;
93                                         
94                                      
95                                      }
96                                      
97                                      if(di == 'itemsrc_active'){
98                                         if(!rec.data.itemsrc_active){
99                                             Roo.MessageBox.alert('Error','Please edit it on Xtuple tool');
100                                             return;
101                                         }
102                                         if(rec.data.itemsrc_active){
103                                             Roo.MessageBox.confirm("Confirm", "Are you sure this product is no longer purchased",
104                                                 function (res) {
105                                                     if(res!='yes') {
106                                                         return;
107                                                     }
108                                                     rec.commit();
109                                             });
110                                         }
111                                     }
112                                      
113                                      _this.locgrid.footer.onClick('first');
114                                      
115                                      
116                                      
117                                      
118                                 },
119                                 afteredit : function (e)
120                                 {
121                                     
122                                     
123                                     Roo.log(e);
124                                     new Pman.Request({
125                                         url : baseURL +'/Roo/Charass',
126                                         params : {
127                                              charass_char_id_char_name : e.field.replace(/^item_char_/,'').toUpperCase(),
128                                              charass_value : e.value,
129                                              charass_target_type : 'I',
130                                              charass_default : 1,
131                                              charass_target_id : e.record.data.item_id
132                                          },
133                                          method : 'POST'
134                                      });
135                                     
136                                     
137                                     e.record.commit();
138                                     
139                                     
140                                     
141                                 },
142                                 celldblclick : function (_self, rowIndex, columnIndex, e)
143                                 {
144                                     var s = _this.grid.ds.getAt(rowIndex);
145                                     
146                                     Pman.Dialog.XtupleItem.show( { item_id : s.data.item_id } , function() {
147                                         _this.grid.footer.onClick('first');
148                                    }); 
149                                 }
150                             },
151                             autoExpandColumn : 'item_descrip1',
152                             clicksToEdit : 1,
153                             loadMask : true,
154                             dataSource : {
155                                 xtype: 'Store',
156                                 xns: Roo.data,
157                                 listeners : {
158                                     beforeload : function (_self, o)
159                                     {
160                                       o.params._with_prodcat = 1;
161                                       o.params._with_char = 1;
162                                       o.params._with_itemsrc_active = 1;
163                                       o.params._with_last_purchase_price = 1;
164                                       o.params._with_image = 1;
165                                       var s = _this.search.getValue();
166                                       if (s.length) {
167                                         o.params['query[number_or_name]'] = s;
168                                       }
169                                       if (!_this.active.pressed) {
170                                         o.params.item_active = 1;
171                                       }
172                                       if (_this.brandSel.getValue().length) {
173                                         o.params._with_brand = _this.brandSel.getValue()
174                                       }
175                                       
176                                       o.params._with_stock_balance = 1;
177                                     },
178                                     update : function (_self, record, operation)
179                                     {
180                                         if(operation != 'commit'){
181                                             return;
182                                         }
183                                         
184                                         var nv  = record.data.itemsrc_active ? 0 : 1;
185                                         new Pman.Request({
186                                             mask : 'Saving',
187                                             url : baseURL + '/Roo/Itemsrc',
188                                             params : {
189                                                 _update_by_item : 1,
190                                                 item_id : record.data.item_id,
191                                                 itemsrc_active : nv
192                                             },
193                                             success : function(res) {
194                                                 record.set('itemsrc_active', nv);
195                                             }
196                                         });
197                                     },
198                                     load : function (_self, records, options)
199                                     {
200                                     
201                                         var cm = _this.grid.getColumnModel();
202                                         if(records.length){
203                                             cm.setColumnHeader(cm.getIndexByDataIndex('item_stock_balance'),records[0].data.default_location_name);
204                                         }
205                                     }
206                                 },
207                                 remoteSort : true,
208                                 sortInfo : { field : 'item_number', direction: 'ASC' },
209                                 proxy : {
210                                     xtype: 'HttpProxy',
211                                     xns: Roo.data,
212                                     method : 'GET',
213                                     url : baseURL + '/Roo/item.php'
214                                 },
215                                 reader : {
216                                     xtype: 'JsonReader',
217                                     xns: Roo.data,
218                                     totalProperty : 'total',
219                                     root : 'data',
220                                     id : 'id',
221                                     fields : [
222                                         {
223                                             'name': 'item_id',
224                                             'type': 'int'
225                                         },
226                                         {
227                                             'name': 'item_number',
228                                             'type': 'string'
229                                         },
230                                         {
231                                             'name': 'item_descrip1',
232                                             'type': 'string'
233                                         },
234                                         {
235                                             'name': 'item_descrip2',
236                                             'type': 'string'
237                                         },
238                                         {
239                                             'name': 'item_classcode_id',
240                                             'type': 'int'
241                                         },
242                                         {
243                                             'name': 'item_picklist',
244                                             'type': 'int'
245                                         },
246                                         {
247                                             'name': 'item_comments',
248                                             'type': 'string'
249                                         },
250                                         {
251                                             'name': 'item_sold',
252                                             'type': 'int'
253                                         },
254                                         {
255                                             'name': 'item_fractional',
256                                             'type': 'int'
257                                         },
258                                         {
259                                             'name': 'item_active',
260                                             'type': 'int'
261                                         },
262                                         {
263                                             'name': 'item_type',
264                                             'type': 'string'
265                                         },
266                                         {
267                                             'name': 'item_prodweight',
268                                             'type': 'float'
269                                         },
270                                         {
271                                             'name': 'item_packweight',
272                                             'type': 'float'
273                                         },
274                                         {
275                                             'name': 'item_prodcat_id',
276                                             'type': 'int'
277                                         },
278                                         {
279                                             'name': 'item_exclusive',
280                                             'type': 'int'
281                                         },
282                                         {
283                                             'name': 'item_listprice',
284                                             'type': 'float'
285                                         },
286                                         {
287                                             'name': 'item_config',
288                                             'type': 'int'
289                                         },
290                                         {
291                                             'name': 'item_extdescrip',
292                                             'type': 'string'
293                                         },
294                                         {
295                                             'name': 'item_upccode',
296                                             'type': 'string'
297                                         },
298                                         {
299                                             'name': 'item_maxcost',
300                                             'type': 'float'
301                                         },
302                                         {
303                                             'name': 'item_inv_uom_id',
304                                             'type': 'int'
305                                         },
306                                         {
307                                             'name': 'item_price_uom_id',
308                                             'type': 'int'
309                                         },
310                                         {
311                                             'name': 'item_warrdays',
312                                             'type': 'int'
313                                         },
314                                         {
315                                             'name': 'item_freightclass_id',
316                                             'type': 'int'
317                                         },
318                                         {
319                                             'name': 'item_tax_recoverable',
320                                             'type': 'int'
321                                         },
322                                         {
323                                             'name': 'item_price_uom_id_uom_id',
324                                             'type': 'int'
325                                         },
326                                         {
327                                             'name': 'item_price_uom_id_uom_name',
328                                             'type': 'string'
329                                         },
330                                         {
331                                             'name': 'item_price_uom_id_uom_descrip',
332                                             'type': 'string'
333                                         },
334                                         {
335                                             'name': 'item_price_uom_id_uom_item_weight',
336                                             'type': 'int'
337                                         },
338                                         {
339                                             'name': 'item_inv_uom_id_uom_id',
340                                             'type': 'int'
341                                         },
342                                         {
343                                             'name': 'item_inv_uom_id_uom_name',
344                                             'type': 'string'
345                                         },
346                                         {
347                                             'name': 'item_inv_uom_id_uom_descrip',
348                                             'type': 'string'
349                                         },
350                                         {
351                                             'name': 'item_inv_uom_id_uom_item_weight',
352                                             'type': 'int'
353                                         },
354                                         {
355                                             'name': 'item_freightclass_id_freightclass_id',
356                                             'type': 'int'
357                                         },
358                                         {
359                                             'name': 'item_freightclass_id_freightclass_code',
360                                             'type': 'string'
361                                         },
362                                         {
363                                             'name': 'item_freightclass_id_freightclass_descrip',
364                                             'type': 'string'
365                                         },
366                                         {
367                                             'name': 'item_classcode_id_classcode_id',
368                                             'type': 'int'
369                                         },
370                                         {
371                                             'name': 'item_classcode_id_classcode_code',
372                                             'type': 'string'
373                                         },
374                                         {
375                                             'name': 'item_classcode_id_classcode_descrip',
376                                             'type': 'string'
377                                         },
378                                         {
379                                             'name': 'item_classcode_id_classcode_mfg',
380                                             'type': 'int'
381                                         },
382                                         {
383                                             'name': 'item_classcode_id_classcode_creator',
384                                             'type': 'string'
385                                         },
386                                         {
387                                             'name': 'item_classcode_id_classcode_created',
388                                             'type': 'date'
389                                         },
390                                         {
391                                             'name': 'item_classcode_id_classcode_modifier',
392                                             'type': 'string'
393                                         },
394                                         {
395                                             'name': 'item_classcode_id_classcode_modified',
396                                             'type': 'date'
397                                         },
398                                         {
399                                             'name': 'item_classcode_id_classcode_type',
400                                             'type': 'string'
401                                         }
402                                     ]
403                                 }
404                             },
405                             toolbar : {
406                                 xtype: 'Toolbar',
407                                 xns: Roo,
408                                 items : [
409                                     {
410                                         xtype: 'ComboBox',
411                                         xns: Roo.form,
412                                         listeners : {
413                                             render : function (_self)
414                                             {
415                                               _this.brandSel = _self;
416                                             },
417                                             select : function (combo, record, index)
418                                             {
419                                                 _this.grid.footer.onClick('first');
420                                             }
421                                         },
422                                         allowBlank : true,
423                                         alwaysQuery : true,
424                                         displayField : 'charass_value',
425                                         editable : true,
426                                         emptyText : "Select Brand",
427                                         forceSelection : true,
428                                         listWidth : 300,
429                                         loadingText : "Searching...",
430                                         minChars : 2,
431                                         pageSize : 20,
432                                         qtip : "Select Brand",
433                                         queryParam : 'query[charass_value]',
434                                         selectOnFocus : true,
435                                         tpl : '<div class="x-grid-cell-text x-btn button"><b>{charass_value}</b> </div>',
436                                         triggerAction : 'all',
437                                         width : 150,
438                                         store : {
439                                             xtype: 'Store',
440                                             xns: Roo.data,
441                                             listeners : {
442                                                 beforeload : function (_self, o)
443                                                 {
444                                                     o.params = o.params || {};
445                                                     // staff can see all logs, other companies can only see their own.
446                                                     // look for all of the charass 's with the same type= eg. brand.
447                                                     
448                                                     o.params.charass_char_id_char_name = 'BRAND';
449                                                     o.params.charass_target_type ='I';
450                                                     o.params._distinct = 'charass_value';
451                                                         o.params._columns = 'charass_value';
452                                                 
453                                                 }
454                                             },
455                                             remoteSort : true,
456                                             sortInfo : { field : 'charass_value' , direction : 'ASC' },
457                                             proxy : {
458                                                 xtype: 'HttpProxy',
459                                                 xns: Roo.data,
460                                                 method : 'GET',
461                                                 url : baseURL + '/Roo/Charass.php'
462                                             },
463                                             reader : {
464                                                 xtype: 'JsonReader',
465                                                 xns: Roo.data,
466                                                 totalProperty : 'total',
467                                                 root : 'data',
468                                                 id : 'id',
469                                                 fields : [
470                                                     {
471                                                         'name': 'id',
472                                                         'type': 'int'
473                                                     },
474                                                     {
475                                                         'name': 'person_name',
476                                                         'type': 'string'
477                                                     },
478                                                     {
479                                                         'name': 'event_when',
480                                                         'type': 'date',
481                                                         'dateFormat': 'Y-m-d'
482                                                     },
483                                                     {
484                                                         'name': 'action',
485                                                         'type': 'string'
486                                                     },
487                                                     {
488                                                         'name': 'ipaddr',
489                                                         'type': 'string'
490                                                     },
491                                                     {
492                                                         'name': 'on_id',
493                                                         'type': 'int'
494                                                     },
495                                                     {
496                                                         'name': 'on_table',
497                                                         'type': 'string'
498                                                     },
499                                                     {
500                                                         'name': 'person_id',
501                                                         'type': 'int'
502                                                     },
503                                                     {
504                                                         'name': 'remarks',
505                                                         'type': 'string'
506                                                     },
507                                                     {
508                                                         'name': 'person_id_id',
509                                                         'type': 'int'
510                                                     },
511                                                     {
512                                                         'name': 'person_id_office_id',
513                                                         'type': 'int'
514                                                     },
515                                                     {
516                                                         'name': 'person_id_name',
517                                                         'type': 'string'
518                                                     },
519                                                     {
520                                                         'name': 'person_id_phone',
521                                                         'type': 'string'
522                                                     },
523                                                     {
524                                                         'name': 'person_id_fax',
525                                                         'type': 'string'
526                                                     },
527                                                     {
528                                                         'name': 'person_id_email',
529                                                         'type': 'string'
530                                                     },
531                                                     {
532                                                         'name': 'person_id_company_id',
533                                                         'type': 'int'
534                                                     },
535                                                     {
536                                                         'name': 'person_id_role',
537                                                         'type': 'string'
538                                                     },
539                                                     {
540                                                         'name': 'person_id_active',
541                                                         'type': 'int'
542                                                     },
543                                                     {
544                                                         'name': 'person_id_remarks',
545                                                         'type': 'string'
546                                                     },
547                                                     {
548                                                         'name': 'person_id_passwd',
549                                                         'type': 'string'
550                                                     },
551                                                     {
552                                                         'name': 'person_id_owner_id',
553                                                         'type': 'int'
554                                                     },
555                                                     {
556                                                         'name': 'person_id_lang',
557                                                         'type': 'string'
558                                                     },
559                                                     {
560                                                         'name': 'person_id_no_reset_sent',
561                                                         'type': 'int'
562                                                     },
563                                                     {
564                                                         'name': 'person_id_action_type',
565                                                         'type': 'string'
566                                                     },
567                                                     {
568                                                         'name': 'person_id_project_id',
569                                                         'type': 'int'
570                                                     },
571                                                     {
572                                                         'name': 'person_id_deleted_by',
573                                                         'type': 'int'
574                                                     },
575                                                     {
576                                                         'name': 'person_id_deleted_dt',
577                                                         'type': 'date'
578                                                     }
579                                                 ]
580                                             }
581                                         }
582                                     },
583                                     {
584                                         xtype: 'TextField',
585                                         xns: Roo.form,
586                                         listeners : {
587                                             render : function (_self)
588                                             {
589                                               _this.search = _self;
590                                             },
591                                             specialkey : function (_self, e)
592                                             {
593                                                 _this.grid.footer.onClick('first');
594                                             }
595                                         },
596                                         emptyText : "Search Product"
597                                     },
598                                     {
599                                         xtype: 'Button',
600                                         xns: Roo.Toolbar,
601                                         listeners : {
602                                             click : function (_self, e)
603                                             {
604                                             _this.grid.footer.onClick('first');
605                                             }
606                                         },
607                                         cls : 'x-btn-icon',
608                                         icon : rootURL + '/Pman/templates/images/search.gif'
609                                     },
610                                     {
611                                         xtype: 'Button',
612                                         xns: Roo.Toolbar,
613                                         listeners : {
614                                             click : function (_self, e)
615                                             {
616                                                 _this.search.setValue('');
617                                                 
618                                             
619                                                 
620                                                 _this.grid.footer.onClick('first');
621                                             }
622                                         },
623                                         cls : 'x-btn-icon',
624                                         icon : rootURL + '/Pman/templates/images/edit-clear.gif'
625                                     },
626                                     {
627                                         xtype: 'Separator',
628                                         xns: Roo.Toolbar
629                                     },
630                                     {
631                                         xtype: 'Button',
632                                         xns: Roo.Toolbar,
633                                         listeners : {
634                                             toggle : function (_self, pressed)
635                                             {
636                                             
637                                                 this.setText(pressed ? "Hide Inactive" : "Show Inactive");
638                                                 (function() { _this.grid.footer.onClick('first'); }).defer(100);
639                                             },
640                                             render : function (_self)
641                                             {
642                                                 _this.active = _self;
643                                             }
644                                         },
645                                         enableToggle : true,
646                                         text : "Show Inactive"
647                                     },
648                                     {
649                                         xtype: 'Fill',
650                                         xns: Roo.Toolbar
651                                     },
652                                     {
653                                         xtype: 'Button',
654                                         xns: Roo.Toolbar,
655                                         listeners : {
656                                             click : function()
657                                             {
658                                             
659                                                Pman.Dialog.XtupleItem.show( { item_id : 0 } , function() {
660                                                     _this.grid.footer.onClick('first');
661                                                }); 
662                                             }
663                                         },
664                                         cls : 'x-btn-text-icon',
665                                         text : "Add",
666                                         icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
667                                     },
668                                     {
669                                         xtype: 'Button',
670                                         xns: Roo.Toolbar,
671                                         listeners : {
672                                             click : function()
673                                             {
674                                                 var s = _this.grid.selModel.getSelectedCell();
675                                                 if (!s) {
676                                                     Roo.MessageBox.alert("Error", "Select a product");
677                                                     return;
678                                                 } 
679                                                 var rec = _this.grid.ds.getAt(s[0]);
680                                                 
681                                                 var params = [];
682                                                 
683                                                 Roo.MessageBox.prompt(
684                                                     "Rename SKU", 
685                                                     "Warning changing SKU names affects historical data, and should only be done if you are sure that this is ok",
686                                                     function(r,v) {
687                                                         if (r != 'ok') {
688                                                             return;
689                                                             
690                                                         }
691                                                         params = {
692                                                             _rename_sku : v,
693                                                             item_id : rec.data.item_id,
694                                                             _check : 1
695                                                         }
696                                             
697                                                         change(params);
698                                                         
699                                                         return;
700                                                             
701                                                         
702                                             
703                                                     }
704                                                 );
705                                                 
706                                                 var change = function(params){
707                                                     new Pman.Request({
708                                                         url : baseURL + '/Roo/Item',
709                                                         mask : "Renaming",
710                                                         method : 'POST',
711                                                         params : params,
712                                                         success : function(res) {
713                                                             Roo.log(res);
714                                                             _this.grid.footer.onClick('refresh');
715                                                             if(typeof(res.data) == 'string'){
716                                                                 Roo.MessageBox.alert("Notice", 'SKU has been renamed');
717                                                                 return
718                                                             }
719                                                             var offices = [];
720                                                             Roo.each(res.data, function(o){
721                                                                 offices.push(Pman.Xtuple.offices[o]);
722                                                             })
723                                                             Roo.MessageBox.alert("Notice", 'SKU has been renamed in ' + offices.join(", "));
724                                                             
725                                                         },
726                                                         failure : function(res) {
727                                                             Roo.log(res);
728                                                             try {
729                                                                 if (res.errors.confirm.length) {
730                                                                     var offices = [];
731                                                                     Roo.each(res.errors.confirm, function(o){
732                                                                         offices.push(Pman.Xtuple.offices[o]);
733                                                                     })
734                                                                     Roo.MessageBox.confirm(
735                                                                         "Confirm", 
736                                                                         " Do you want to change the name in " + offices.join(", ") + "?",
737                                                                         function(x) {
738                                                                             if (x != 'yes') {
739                                                                                 Roo.MessageBox.alert("Notice", 'SKU was not changed');
740                                                                                 return;
741                                                                             }
742                                                                             delete params['_check'];
743                                                                             params._can_change_sku = 1;
744                                                                             change(params);
745                                                                         }
746                                                                     );
747                                                                     return;
748                                                                 }
749                                                             } catch(e) { }
750                                                             Roo.MessageBox.alert("Error", res.errorMsg);
751                                                             
752                                                         }
753                                                     });
754                                                 }
755                                                
756                                             }
757                                         },
758                                         text : "Rename SKU"
759                                     },
760                                     {
761                                         xtype: 'Separator',
762                                         xns: Roo.Toolbar
763                                     },
764                                     {
765                                         xtype: 'TextItem',
766                                         xns: Roo.Toolbar,
767                                         text : "Report start :"
768                                     },
769                                     {
770                                         xtype: 'DateField',
771                                         xns: Roo.form,
772                                         listeners : {
773                                             render : function (_self)
774                                             {
775                                                 _this.dateFrom = _self;
776                                             }
777                                         },
778                                         format : 'd/M/Y',
779                                         useIso : true,
780                                         value : (function() { return (new Date()).format('Y') + '-01-01'; })()
781                                     },
782                                     {
783                                         xtype: 'ComboBox',
784                                         xns: Roo.form,
785                                         listeners : {
786                                             render : function (_self)
787                                             {
788                                               _this.datespan  = _self;
789                                             }
790                                         },
791                                         allowBlank : false,
792                                         displayField : 'fname',
793                                         editable : false,
794                                         fieldLabel : 'Status',
795                                         hiddenName : 'cm_status',
796                                         listWidth : 200,
797                                         mode : 'local',
798                                         name : 'cm_status_name',
799                                         triggerAction : 'all',
800                                         value : 12,
801                                         valueField : 'ftype',
802                                         width : 150,
803                                         store : {
804                                             xtype: 'SimpleStore',
805                                             xns: Roo.data,
806                                             data : [ 
807                                                 [ '1', "Single Month Sales"],
808                                                 [ '3', "Quarter Sales"],
809                                                 [ '6', "Half year Sales"] ,
810                                                 [ '12', "Full Year Sales"] 
811                                             ],
812                                             fields : [  'ftype', 'fname']
813                                         }
814                                     },
815                                     {
816                                         xtype: 'Button',
817                                         xns: Roo.Toolbar,
818                                         listeners : {
819                                             click : function (_self, e)
820                                             {
821                                                 if (!_this.brandSel.getValue().length) {
822                                                     Roo.MessageBox.alert("Error", "Select a brand to download");
823                                                     return;
824                                                 }
825                                             
826                                                 new Pman.Download({
827                                                     url : baseURL + '/Xtuple/Reports/SalesByCountryItemYear',
828                                                     params: { 
829                                                         date_from : _this.dateFrom.getValue(),
830                                                         brand : _this.brandSel.getValue(),
831                                                         span : _this.datespan.getValue()
832                                                     }
833                                                 });
834                                                     
835                                             
836                                             }
837                                         },
838                                         text : "Download Sales Report"
839                                     }
840                                 ]
841                             },
842                             footer : {
843                                 xtype: 'PagingToolbar',
844                                 xns: Roo,
845                                 pageSize : 25,
846                                 displayInfo : true,
847                                 displayMsg : "Displaying item{0} - {1} of {2}",
848                                 emptyMsg : "No item found",
849                                 items : [
850                                     {
851                                         xtype: 'Button',
852                                         xns: Roo.Toolbar,
853                                         text : "Tools - Upload/Download",
854                                         menu : {
855                                             xtype: 'Menu',
856                                             xns: Roo.menu,
857                                             items : [
858                                                 {
859                                                     xtype: 'Item',
860                                                     xns: Roo.menu,
861                                                     listeners : {
862                                                         click : function (_self, e)
863                                                         {
864                                                            new Pman.Download({
865                                                                 method: 'GET',
866                                                                 url : baseURL + '/Roo/item',
867                                                                 params : {
868                                                                     _costgrid : 1
869                                                                 }
870                                                            });
871                                                         }
872                                                     },
873                                                     text : "Download Standard costs"
874                                                 },
875                                                 {
876                                                     xtype: 'Item',
877                                                     xns: Roo.menu,
878                                                     listeners : {
879                                                         click : function (_self, e)
880                                                         {
881                                                         //   Roo.MessageBox.alert("Disabled", "Can you please send Alan the test file for this - there is a problem and we need to fix it before you use this again");
882                                                          //  return;
883                                                            
884                                                            Pman.Dialog.Image.show(
885                                                                {
886                                                                     _url : baseURL+'/Xtuple/Import/Products',
887                                                                     timeout : 60000
888                                                                 
889                                                                },
890                                                                function (data) {
891                                                                     var msg = [];
892                                                                    
893                                                                     if (data.updated) {
894                                                                         msg.push("Updated " + data.updated + " Products(s)");
895                                                                     }            
896                                                                     if (data.inserted) {
897                                                                         msg.push("Added " + data.inserted + " Products(s)");
898                                                                     }
899                                                                     if (data.skipped) {
900                                                                         msg.push("Skipped " + data.skipped);
901                                                                     }
902                                                                     
903                                                                     if (!msg.length) {
904                                                                         msg.push("No data changed");
905                                                                     }
906                                                                     Roo.MessageBox.alert("Notice", msg.join("\n"));
907                                                         
908                                                                }
909                                                            );
910                                                         }
911                                                     },
912                                                     text : "Upload new products and costs"
913                                                 },
914                                                 {
915                                                     xtype: 'Separator',
916                                                     xns: Roo.menu
917                                                 },
918                                                 {
919                                                     xtype: 'Item',
920                                                     xns: Roo.menu,
921                                                     listeners : {
922                                                         click : function (_self, e)
923                                                         {
924                                                           Roo.MessageBox.progress ("Syncing Stock", "Sending");
925                                                           
926                                                           var offset = 0;
927                                                           
928                                                            function runSync() {
929                                                                
930                                                                new Pman.Request( {
931                                                                     url : baseURL+'/Roo/Item',
932                                                                     method : 'GET',
933                                                                     timeout: 60000,
934                                                                     params : {
935                                                                         _syncFromHK : 1,
936                                                                         offset : offset
937                                                                     },
938                                                                     success : function(res) {
939                                                                         Roo.log(res);
940                                                                         if (!res.data.total) {
941                                                                             Roo.MessageBox.hide();
942                                                                             return;
943                                                                         }
944                                                                         offset += res.data.limit;
945                                                                         Roo.MessageBox.updateProgress ( offset  / res.data.total, "Done " + offset + '/' + res.data.total);
946                                                                         runSync();
947                                                                     }
948                                                                     
949                                                                 
950                                                                });
951                                                            }
952                                                            runSync();
953                                                         }
954                                                     },
955                                                     text : "Sync Product Data from HK",
956                                                     hidden : (function() {
957                                                     
958                                                         return baseURL.match(/hk\.php$/) ? true : false;
959                                                     })()
960                                                 },
961                                                 {
962                                                     xtype: 'Item',
963                                                     xns: Roo.menu,
964                                                     listeners : {
965                                                         click : function (_self, e)
966                                                         {
967                                                           Roo.MessageBox.progress ("Syncing Stock", "Sending");
968                                                           
969                                                           var offset = 0;
970                                                           
971                                                            
972                                                                
973                                                            new Pman.Request( {
974                                                                 url : baseURL+'/Roo/Item',
975                                                                 method : 'GET',
976                                                                 params : {
977                                                                     _syncFromHK : 1,
978                                                                     _new_only : 1
979                                                                 },
980                                                                 success : function(res) {
981                                                                     Roo.log(res);
982                                                                     
983                                                                         Roo.MessageBox.hide();
984                                                                      _this.grid.footer.onClick('refresh');
985                                                                     
986                                                                      
987                                                                 }
988                                                                 
989                                                             
990                                                            });
991                                                             
992                                                         }
993                                                     },
994                                                     text : "Sync Product from HK (New Products Only)",
995                                                     hidden : (function() {
996                                                     
997                                                         return baseURL.match(/hk\.php$/) ? true : false;
998                                                     })()
999                                                 },
1000                                                 {
1001                                                     xtype: 'Item',
1002                                                     xns: Roo.menu,
1003                                                     listeners : {
1004                                                         click : function (_self, e)
1005                                                         {
1006                                                           Roo.MessageBox.progress ("Syncing Stock", "Sending");
1007                                                           
1008                                                           var offset = 0;
1009                                                           
1010                                                            
1011                                                                
1012                                                            new Pman.Request( {
1013                                                                 url : baseURL+'/Roo/Item',
1014                                                                 method : 'GET',
1015                                                                 params : {
1016                                                                     _syncFromHK : 1,
1017                                                                     item_number : _this.search.getValue()
1018                                                                 },
1019                                                                 success : function(res) {
1020                                                                     Roo.log(res);
1021                                                                     
1022                                                                         Roo.MessageBox.hide();
1023                                                                      _this.grid.footer.onClick('refresh');
1024                                                                     
1025                                                                      
1026                                                                 }
1027                                                                 
1028                                                             
1029                                                            });
1030                                                             
1031                                                         }
1032                                                     },
1033                                                     text : "Sync Product from HK (Based on Search)",
1034                                                     hidden : (function() {
1035                                                     
1036                                                         return baseURL.match(/hk\.php$/) ? true : false;
1037                                                     })()
1038                                                 }
1039                                             ]
1040                                         }
1041                                     }
1042                                 ]
1043                             },
1044                             colModel : [
1045                                 {
1046                                     xtype: 'ColumnModel',
1047                                     xns: Roo.grid,
1048                                     dataIndex : 'item_image_id',
1049                                     header : 'Description',
1050                                     sortable : true,
1051                                     width : 150,
1052                                     renderer : function(v,x,r) { return String.format('<img src="{0}/Images/Thumb/100/{1}/{2}" height="100">', baseURL, v, r.data.item_image_filename); }
1053                                 },
1054                                 {
1055                                     xtype: 'ColumnModel',
1056                                     xns: Roo.grid,
1057                                     dataIndex : 'item_char_brand',
1058                                     header : 'Brand',
1059                                     sortable : true,
1060                                     width : 100,
1061                                     renderer : function(v) { return String.format('{0}', v); },
1062                                     editor : {
1063                                         xtype: 'GridEditor',
1064                                         xns: Roo.grid,
1065                                         field : {
1066                                             xtype: 'ComboBox',
1067                                             xns: Roo.form,
1068                                             allowBlank : true,
1069                                             alwaysQuery : true,
1070                                             displayField : 'charass_value',
1071                                             editable : true,
1072                                             forceSelection : false,
1073                                             listWidth : 300,
1074                                             loadingText : "Searching...",
1075                                             minChars : 2,
1076                                             pageSize : 20,
1077                                             qtip : "Select Brand",
1078                                             queryParam : 'query[charass_value]',
1079                                             selectOnFocus : true,
1080                                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{charass_value}</b> </div>',
1081                                             triggerAction : 'all',
1082                                             width : 150,
1083                                             store : {
1084                                                 xtype: 'Store',
1085                                                 xns: Roo.data,
1086                                                 listeners : {
1087                                                     beforeload : function (_self, o)
1088                                                     {
1089                                                         o.params = o.params || {};
1090                                                         // staff can see all logs, other companies can only see their own.
1091                                                         // look for all of the charass 's with the same type= eg. brand.
1092                                                         
1093                                                         o.params.charass_char_id_char_name = 'BRAND';
1094                                                         o.params.charass_target_type ='I';
1095                                                         o.params._distinct = 'charass_value';
1096                                                             o.params._columns = 'charass_value';
1097                                                     
1098                                                     }
1099                                                 },
1100                                                 remoteSort : true,
1101                                                 sortInfo : { field : 'charass_value' , direction : 'ASC' },
1102                                                 proxy : {
1103                                                     xtype: 'HttpProxy',
1104                                                     xns: Roo.data,
1105                                                     method : 'GET',
1106                                                     url : baseURL + '/Roo/Charass.php'
1107                                                 },
1108                                                 reader : {
1109                                                     xtype: 'JsonReader',
1110                                                     xns: Roo.data,
1111                                                     totalProperty : 'total',
1112                                                     root : 'data',
1113                                                     id : 'id',
1114                                                     fields : [
1115                                                         {
1116                                                             'name': 'id',
1117                                                             'type': 'int'
1118                                                         },
1119                                                         {
1120                                                             'name': 'person_name',
1121                                                             'type': 'string'
1122                                                         },
1123                                                         {
1124                                                             'name': 'event_when',
1125                                                             'type': 'date',
1126                                                             'dateFormat': 'Y-m-d'
1127                                                         },
1128                                                         {
1129                                                             'name': 'action',
1130                                                             'type': 'string'
1131                                                         },
1132                                                         {
1133                                                             'name': 'ipaddr',
1134                                                             'type': 'string'
1135                                                         },
1136                                                         {
1137                                                             'name': 'on_id',
1138                                                             'type': 'int'
1139                                                         },
1140                                                         {
1141                                                             'name': 'on_table',
1142                                                             'type': 'string'
1143                                                         },
1144                                                         {
1145                                                             'name': 'person_id',
1146                                                             'type': 'int'
1147                                                         },
1148                                                         {
1149                                                             'name': 'remarks',
1150                                                             'type': 'string'
1151                                                         },
1152                                                         {
1153                                                             'name': 'person_id_id',
1154                                                             'type': 'int'
1155                                                         },
1156                                                         {
1157                                                             'name': 'person_id_office_id',
1158                                                             'type': 'int'
1159                                                         },
1160                                                         {
1161                                                             'name': 'person_id_name',
1162                                                             'type': 'string'
1163                                                         },
1164                                                         {
1165                                                             'name': 'person_id_phone',
1166                                                             'type': 'string'
1167                                                         },
1168                                                         {
1169                                                             'name': 'person_id_fax',
1170                                                             'type': 'string'
1171                                                         },
1172                                                         {
1173                                                             'name': 'person_id_email',
1174                                                             'type': 'string'
1175                                                         },
1176                                                         {
1177                                                             'name': 'person_id_company_id',
1178                                                             'type': 'int'
1179                                                         },
1180                                                         {
1181                                                             'name': 'person_id_role',
1182                                                             'type': 'string'
1183                                                         },
1184                                                         {
1185                                                             'name': 'person_id_active',
1186                                                             'type': 'int'
1187                                                         },
1188                                                         {
1189                                                             'name': 'person_id_remarks',
1190                                                             'type': 'string'
1191                                                         },
1192                                                         {
1193                                                             'name': 'person_id_passwd',
1194                                                             'type': 'string'
1195                                                         },
1196                                                         {
1197                                                             'name': 'person_id_owner_id',
1198                                                             'type': 'int'
1199                                                         },
1200                                                         {
1201                                                             'name': 'person_id_lang',
1202                                                             'type': 'string'
1203                                                         },
1204                                                         {
1205                                                             'name': 'person_id_no_reset_sent',
1206                                                             'type': 'int'
1207                                                         },
1208                                                         {
1209                                                             'name': 'person_id_action_type',
1210                                                             'type': 'string'
1211                                                         },
1212                                                         {
1213                                                             'name': 'person_id_project_id',
1214                                                             'type': 'int'
1215                                                         },
1216                                                         {
1217                                                             'name': 'person_id_deleted_by',
1218                                                             'type': 'int'
1219                                                         },
1220                                                         {
1221                                                             'name': 'person_id_deleted_dt',
1222                                                             'type': 'date'
1223                                                         }
1224                                                     ]
1225                                                 }
1226                                             }
1227                                         }
1228                                     }
1229                                 },
1230                                 {
1231                                     xtype: 'ColumnModel',
1232                                     xns: Roo.grid,
1233                                     dataIndex : 'item_char_productgroup',
1234                                     header : 'Product Group',
1235                                     sortable : true,
1236                                     width : 100,
1237                                     renderer : function(v) { return String.format('{0}', v); },
1238                                     editor : {
1239                                         xtype: 'GridEditor',
1240                                         xns: Roo.grid,
1241                                         field : {
1242                                             xtype: 'ComboBox',
1243                                             xns: Roo.form,
1244                                             allowBlank : true,
1245                                             alwaysQuery : true,
1246                                             displayField : 'charass_value',
1247                                             editable : true,
1248                                             forceSelection : false,
1249                                             listWidth : 300,
1250                                             loadingText : "Searching...",
1251                                             minChars : 2,
1252                                             pageSize : 20,
1253                                             qtip : "Select Brand",
1254                                             queryParam : 'query[charass_value]',
1255                                             selectOnFocus : true,
1256                                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{charass_value}</b> </div>',
1257                                             triggerAction : 'all',
1258                                             width : 150,
1259                                             store : {
1260                                                 xtype: 'Store',
1261                                                 xns: Roo.data,
1262                                                 listeners : {
1263                                                     beforeload : function (_self, o)
1264                                                     {
1265                                                         o.params = o.params || {};
1266                                                         // staff can see all logs, other companies can only see their own.
1267                                                         // look for all of the charass 's with the same type= eg. brand.
1268                                                         
1269                                                         o.params.charass_char_id_char_name = 'PRODUCTGROUP';
1270                                                         o.params.charass_target_type ='I';
1271                                                         o.params._distinct = 'charass_value';
1272                                                             o.params._columns = 'charass_value';    
1273                                                     }
1274                                                 },
1275                                                 remoteSort : true,
1276                                                 sortInfo : { field : 'charass_value' , direction : 'ASC' },
1277                                                 proxy : {
1278                                                     xtype: 'HttpProxy',
1279                                                     xns: Roo.data,
1280                                                     method : 'GET',
1281                                                     url : baseURL + '/Roo/Charass.php'
1282                                                 },
1283                                                 reader : {
1284                                                     xtype: 'JsonReader',
1285                                                     xns: Roo.data,
1286                                                     totalProperty : 'total',
1287                                                     root : 'data',
1288                                                     id : 'id',
1289                                                     fields : [
1290                                                         {
1291                                                             'name': 'id',
1292                                                             'type': 'int'
1293                                                         },
1294                                                         {
1295                                                             'name': 'person_name',
1296                                                             'type': 'string'
1297                                                         },
1298                                                         {
1299                                                             'name': 'event_when',
1300                                                             'type': 'date',
1301                                                             'dateFormat': 'Y-m-d'
1302                                                         },
1303                                                         {
1304                                                             'name': 'action',
1305                                                             'type': 'string'
1306                                                         },
1307                                                         {
1308                                                             'name': 'ipaddr',
1309                                                             'type': 'string'
1310                                                         },
1311                                                         {
1312                                                             'name': 'on_id',
1313                                                             'type': 'int'
1314                                                         },
1315                                                         {
1316                                                             'name': 'on_table',
1317                                                             'type': 'string'
1318                                                         },
1319                                                         {
1320                                                             'name': 'person_id',
1321                                                             'type': 'int'
1322                                                         },
1323                                                         {
1324                                                             'name': 'remarks',
1325                                                             'type': 'string'
1326                                                         },
1327                                                         {
1328                                                             'name': 'person_id_id',
1329                                                             'type': 'int'
1330                                                         },
1331                                                         {
1332                                                             'name': 'person_id_office_id',
1333                                                             'type': 'int'
1334                                                         },
1335                                                         {
1336                                                             'name': 'person_id_name',
1337                                                             'type': 'string'
1338                                                         },
1339                                                         {
1340                                                             'name': 'person_id_phone',
1341                                                             'type': 'string'
1342                                                         },
1343                                                         {
1344                                                             'name': 'person_id_fax',
1345                                                             'type': 'string'
1346                                                         },
1347                                                         {
1348                                                             'name': 'person_id_email',
1349                                                             'type': 'string'
1350                                                         },
1351                                                         {
1352                                                             'name': 'person_id_company_id',
1353                                                             'type': 'int'
1354                                                         },
1355                                                         {
1356                                                             'name': 'person_id_role',
1357                                                             'type': 'string'
1358                                                         },
1359                                                         {
1360                                                             'name': 'person_id_active',
1361                                                             'type': 'int'
1362                                                         },
1363                                                         {
1364                                                             'name': 'person_id_remarks',
1365                                                             'type': 'string'
1366                                                         },
1367                                                         {
1368                                                             'name': 'person_id_passwd',
1369                                                             'type': 'string'
1370                                                         },
1371                                                         {
1372                                                             'name': 'person_id_owner_id',
1373                                                             'type': 'int'
1374                                                         },
1375                                                         {
1376                                                             'name': 'person_id_lang',
1377                                                             'type': 'string'
1378                                                         },
1379                                                         {
1380                                                             'name': 'person_id_no_reset_sent',
1381                                                             'type': 'int'
1382                                                         },
1383                                                         {
1384                                                             'name': 'person_id_action_type',
1385                                                             'type': 'string'
1386                                                         },
1387                                                         {
1388                                                             'name': 'person_id_project_id',
1389                                                             'type': 'int'
1390                                                         },
1391                                                         {
1392                                                             'name': 'person_id_deleted_by',
1393                                                             'type': 'int'
1394                                                         },
1395                                                         {
1396                                                             'name': 'person_id_deleted_dt',
1397                                                             'type': 'date'
1398                                                         }
1399                                                     ]
1400                                                 }
1401                                             }
1402                                         }
1403                                     }
1404                                 },
1405                                 {
1406                                     xtype: 'ColumnModel',
1407                                     xns: Roo.grid,
1408                                     dataIndex : 'item_number',
1409                                     header : 'Number',
1410                                     sortable : true,
1411                                     width : 100,
1412                                     renderer : function(v) { return String.format('<B>{0}</B>', v); }
1413                                 },
1414                                 {
1415                                     xtype: 'ColumnModel',
1416                                     xns: Roo.grid,
1417                                     dataIndex : 'item_char_pickface_location',
1418                                     header : 'Pickface',
1419                                     sortable : true,
1420                                     width : 100,
1421                                     renderer : function(v) { return String.format('{0}', v); },
1422                                     editor : {
1423                                         xtype: 'GridEditor',
1424                                         xns: Roo.grid,
1425                                         field : {
1426                                             xtype: 'TextField',
1427                                             xns: Roo.form
1428                                         }
1429                                     }
1430                                 },
1431                                 {
1432                                     xtype: 'ColumnModel',
1433                                     xns: Roo.grid,
1434                                     dataIndex : 'item_char_pallet_location',
1435                                     header : 'Pallet',
1436                                     sortable : true,
1437                                     width : 100,
1438                                     renderer : function(v) { return String.format('{0}', v); },
1439                                     editor : {
1440                                         xtype: 'GridEditor',
1441                                         xns: Roo.grid,
1442                                         field : {
1443                                             xtype: 'TextField',
1444                                             xns: Roo.form
1445                                         }
1446                                     }
1447                                 },
1448                                 {
1449                                     xtype: 'ColumnModel',
1450                                     xns: Roo.grid,
1451                                     dataIndex : 'item_descrip1',
1452                                     header : 'Description',
1453                                     sortable : true,
1454                                     width : 200,
1455                                     renderer : function(v) { return String.format('{0}', v); }
1456                                 },
1457                                 {
1458                                     xtype: 'ColumnModel',
1459                                     xns: Roo.grid,
1460                                     dataIndex : 'itemsrc_active',
1461                                     header : 'Purchased',
1462                                     width : 55,
1463                                     renderer : function(v) {  
1464                                         var state = v * 1 > 0 ?  '-checked' : '';
1465                                     
1466                                         return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
1467                                                     
1468                                      }
1469                                 },
1470                                 {
1471                                     xtype: 'ColumnModel',
1472                                     xns: Roo.grid,
1473                                     dataIndex : 'item_sold',
1474                                     header : 'is Sold?',
1475                                     width : 50,
1476                                     renderer : function(v) {  
1477                                         var state = v * 1 > 0 ?  '-checked' : '';
1478                                     
1479                                         return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
1480                                                     
1481                                      }
1482                                 },
1483                                 {
1484                                     xtype: 'ColumnModel',
1485                                     xns: Roo.grid,
1486                                     dataIndex : 'item_active',
1487                                     header : 'is Active?',
1488                                     width : 50,
1489                                     renderer : function(v) {  
1490                                         var state = v * 1 > 0 ?  '-checked' : '';
1491                                     
1492                                         return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
1493                                                     
1494                                      }
1495                                 },
1496                                 {
1497                                     xtype: 'ColumnModel',
1498                                     xns: Roo.grid,
1499                                     align : 'right',
1500                                     dataIndex : 'last_purchase_price',
1501                                     header : 'Last purchase price',
1502                                     width : 120,
1503                                     renderer : function(v,x,r) {
1504                                     
1505                                          return String.format('{0}{1}', r.data.last_purchase_price_curr_name, Roo.util.Format.number(v,2)) ; 
1506                                          
1507                                      }
1508                                 },
1509                                 {
1510                                     xtype: 'ColumnModel',
1511                                     xns: Roo.grid,
1512                                     dataIndex : 'item_prodcat_id_prodcat_code',
1513                                     header : 'Item prodcat',
1514                                     width : 100,
1515                                     renderer : function(v,x,r) { 
1516                                         return String.format('{0}/{1}', r.data.item_type, v); 
1517                                         }
1518                                 },
1519                                 {
1520                                     xtype: 'ColumnModel',
1521                                     xns: Roo.grid,
1522                                     align : 'right',
1523                                     dataIndex : 'item_actcost',
1524                                     header : 'Cost',
1525                                     width : 75,
1526                                     renderer : function(v,x,r) {
1527                                     
1528                                          return String.format('{0}{1}', r.data.item_curr_name, Roo.util.Format.number(v,2)) ; 
1529                                          
1530                                      }
1531                                 },
1532                                 {
1533                                     xtype: 'ColumnModel',
1534                                     xns: Roo.grid,
1535                                     align : 'right',
1536                                     dataIndex : 'item_base_cost',
1537                                     header : 'Cost (base)',
1538                                     width : 75,
1539                                     renderer : function(v,x,r) {
1540                                     
1541                                          return String.format('{0}{1}', r.data.item_base_curr, Roo.util.Format.number(v,2)) ; 
1542                                          
1543                                      }
1544                                 },
1545                                 {
1546                                     xtype: 'ColumnModel',
1547                                     xns: Roo.grid,
1548                                     align : 'right',
1549                                     dataIndex : 'item_stock_balance',
1550                                     header : 'Balance',
1551                                     width : 100,
1552                                     renderer : function(v) { return String.format('{0}', v ? parseInt( v) : ''); }
1553                                 }
1554                             ]
1555                         }
1556                     },
1557                     {
1558                         xtype: 'GridPanel',
1559                         xns: Roo,
1560                         listeners : {
1561                             activate : function() {
1562                                 _this.locpanel = this;
1563                              
1564                             }
1565                         },
1566                         background : true,
1567                         fitContainer : true,
1568                         fitToframe : true,
1569                         region : 'east',
1570                         tableName : 'itemloc',
1571                         title : "itemloc",
1572                         grid : {
1573                             xtype: 'Grid',
1574                             xns: Roo.grid,
1575                             listeners : {
1576                                 render : function() 
1577                                 {
1578                                     _this.locgrid = this; 
1579                                     //_this.dialog = Pman.Dialog.FILL_IN
1580                                     
1581                                 },
1582                                 rowdblclick : function (_self, rowIndex, e)
1583                                 {
1584                                     if (!_this.dialog) return;
1585                                     _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
1586                                         _this.grid.footer.onClick('first');
1587                                     }); 
1588                                 }
1589                             },
1590                             autoExpandColumn : 'location_name',
1591                             loadMask : true,
1592                             dataSource : {
1593                                 xtype: 'Store',
1594                                 xns: Roo.data,
1595                                 listeners : {
1596                                     beforeload : function (_self, o)
1597                                     {
1598                                         var sel = _this.grid.selModel.getSelectedCell();
1599                                         if (!sel) {
1600                                             this.removeAll();
1601                                             return false;
1602                                         }
1603                                         var rec = _this.grid.ds.getAt(sel[0]);
1604                                         o.params._stock_for_item_id = rec.data.item_id;
1605                                         //o.params['!itemloc_qty'] = 0;
1606                                         
1607                                         
1608                                     }
1609                                 },
1610                                 remoteSort : true,
1611                                 sortInfo : { field : 'location_name', direction: 'ASC' },
1612                                 proxy : {
1613                                     xtype: 'HttpProxy',
1614                                     xns: Roo.data,
1615                                     method : 'GET',
1616                                     url : baseURL + '/Roo/location.php'
1617                                 },
1618                                 reader : {
1619                                     xtype: 'JsonReader',
1620                                     xns: Roo.data,
1621                                     totalProperty : 'total',
1622                                     root : 'data',
1623                                     id : 'id',
1624                                     fields : [
1625                                         {
1626                                             'name': 'itemloc_id',
1627                                             'type': 'int'
1628                                         },
1629                                         {
1630                                             'name': 'itemloc_itemsite_id',
1631                                             'type': 'int'
1632                                         },
1633                                         {
1634                                             'name': 'itemloc_location_id',
1635                                             'type': 'int'
1636                                         },
1637                                         {
1638                                             'name': 'itemloc_qty',
1639                                             'type': 'float'
1640                                         },
1641                                         {
1642                                             'name': 'itemloc_expiration',
1643                                             'type': 'date',
1644                                             'dateFormat': 'Y-m-d'
1645                                         },
1646                                         {
1647                                             'name': 'itemloc_consolflag',
1648                                             'type': 'int'
1649                                         },
1650                                         {
1651                                             'name': 'itemloc_ls_id',
1652                                             'type': 'int'
1653                                         },
1654                                         {
1655                                             'name': 'itemloc_warrpurc',
1656                                             'type': 'date',
1657                                             'dateFormat': 'Y-m-d'
1658                                         }
1659                                     ]
1660                                 }
1661                             },
1662                             footer : {
1663                                 xtype: 'PagingToolbar',
1664                                 xns: Roo,
1665                                 pageSize : 25,
1666                                 displayInfo : true,
1667                                 displayMsg : "Displaying itemloc{0} - {1} of {2}",
1668                                 emptyMsg : "No itemloc found"
1669                             },
1670                             colModel : [
1671                                 {
1672                                     xtype: 'ColumnModel',
1673                                     xns: Roo.grid,
1674                                     dataIndex : 'location_name',
1675                                     header : 'Location',
1676                                     width : 75,
1677                                     renderer : function(v) { return String.format('{0}', v); }
1678                                 },
1679                                 {
1680                                     xtype: 'ColumnModel',
1681                                     xns: Roo.grid,
1682                                     dataIndex : 'itemloc_realqty',
1683                                     header : 'Itemloc qty',
1684                                     width : 75,
1685                                     renderer : function(v) { return String.format('{0}', v*1 ? (v*1).toFixed(0) : ''); }
1686                                 }
1687                             ]
1688                         }
1689                     }
1690                 ],
1691                 center : {
1692                     xtype: 'LayoutRegion',
1693                     xns: Roo
1694                 },
1695                 east : {
1696                     xtype: 'LayoutRegion',
1697                     xns: Roo,
1698                     split : true,
1699                     width : 200
1700                 }
1701             }
1702         };
1703     }
1704 });