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