Pman.Tab.XtuplePriceLists.bjs
[Pman.Xtuple] / Pman.Tab.XtuplePriceLists.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Pman.Tab.XtuplePriceLists = new Roo.XComponent({
6     part     :  ["Xtuple","PriceLists"],
7     order    : '001-Pman.Tab.XtuplePriceLists',
8     region   : 'center',
9     parent   : 'Pman.Tab.XtupleManage',
10     name     : "Pman.Tab.XtuplePriceLists",
11     disabled : false, 
12     permname : '', 
13     _tree : function()
14     {
15         var _this = this;
16         var MODULE = this;
17         return {
18             xtype: 'NestedLayoutPanel',
19             xns: Roo,
20             background : true,
21             fitContainer : true,
22             fitToFrame : true,
23             region : 'center',
24             title : "Price List",
25             layout : {
26                 xtype: 'BorderLayout',
27                 xns: Roo,
28                 items : [
29                     {
30                         xtype: 'GridPanel',
31                         xns: Roo,
32                         listeners : {
33                             activate : function() {
34                                 _this.panel = this;
35                                 if (_this.grid) {
36                                     _this.grid.footer.onClick('first');
37                                 }
38                             }
39                         },
40                         background : true,
41                         fitContainer : true,
42                         fitToframe : true,
43                         region : 'center',
44                         tableName : 'ipshead',
45                         title : "Price Lists",
46                         grid : {
47                             xtype: 'Grid',
48                             xns: Roo.grid,
49                             listeners : {
50                                 render : function() 
51                                 {
52                                     _this.grid = this; 
53                                     _this.dialog = Pman.Dialog.XtuplePriceList
54                                     if (_this.panel.active) {
55                                        this.footer.onClick('first');
56                                     }
57                                 },
58                                 rowdblclick : function (_self, rowIndex, e)
59                                 {
60                                     if (!_this.dialog) return;
61                                     _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
62                                         _this.grid.footer.onClick('first');
63                                     }); 
64                                     
65                                 }
66                             },
67                             autoExpandColumn : 'ipshead_descrip',
68                             loadMask : true,
69                             sm : {
70                                 xtype: 'RowSelectionModel',
71                                 xns: Roo.grid,
72                                 singleSelect : true
73                             },
74                             dataSource : {
75                                 xtype: 'Store',
76                                 xns: Roo.data,
77                                 remoteSort : true,
78                                 sortInfo : { field : 'ipshead_name', direction: 'ASC' },
79                                 proxy : {
80                                     xtype: 'HttpProxy',
81                                     xns: Roo.data,
82                                     method : 'GET',
83                                     url : baseURL + '/Roo/ipshead.php'
84                                 },
85                                 reader : {
86                                     xtype: 'JsonReader',
87                                     xns: Roo.data,
88                                     totalProperty : 'total',
89                                     root : 'data',
90                                     id : 'id',
91                                     fields : [
92                                         {
93                                             'name': 'ipshead_id',
94                                             'type': 'int'
95                                         },
96                                         {
97                                             'name': 'ipshead_name',
98                                             'type': 'string'
99                                         },
100                                         {
101                                             'name': 'ipshead_descrip',
102                                             'type': 'string'
103                                         },
104                                         {
105                                             'name': 'ipshead_effective',
106                                             'type': 'date',
107                                             'dateFormat': 'Y-m-d'
108                                         },
109                                         {
110                                             'name': 'ipshead_expires',
111                                             'type': 'date',
112                                             'dateFormat': 'Y-m-d'
113                                         },
114                                         {
115                                             'name': 'ipshead_curr_id',
116                                             'type': 'int'
117                                         },
118                                         {
119                                             'name': 'ipshead_updated',
120                                             'type': 'date',
121                                             'dateFormat': 'Y-m-d'
122                                         },
123                                         {
124                                             'name': 'ipshead_curr_id_curr_id',
125                                             'type': 'int'
126                                         },
127                                         {
128                                             'name': 'ipshead_curr_id_curr_base',
129                                             'type': 'int'
130                                         },
131                                         {
132                                             'name': 'ipshead_curr_id_curr_name',
133                                             'type': 'string'
134                                         },
135                                         {
136                                             'name': 'ipshead_curr_id_curr_symbol',
137                                             'type': 'string'
138                                         },
139                                         {
140                                             'name': 'ipshead_curr_id_curr_abbr',
141                                             'type': 'string'
142                                         }
143                                     ]
144                                 }
145                             },
146                             footer : {
147                                 xtype: 'PagingToolbar',
148                                 xns: Roo,
149                                 displayInfo : true,
150                                 displayMsg : "Displaying ipshead{0} - {1} of {2}",
151                                 emptyMsg : "No ipshead found",
152                                 pageSize : 25
153                             },
154                             toolbar : {
155                                 xtype: 'Toolbar',
156                                 xns: Roo,
157                                 items : [
158                                     {
159                                         xtype: 'Button',
160                                         xns: Roo.Toolbar,
161                                         listeners : {
162                                             click : function (_self, e)
163                                             {
164                                                new Pman.Download({
165                                                     method: 'GET',
166                                                     url : baseURL + '/Roo/Ipsiteminfo',
167                                                     params : {
168                                                         _pricegrid : 1
169                                                     }
170                                                });
171                                             }
172                                         },
173                                         text : "Download Price Matrix"
174                                     },
175                                     {
176                                         xtype: 'Button',
177                                         xns: Roo.Toolbar,
178                                         listeners : {
179                                             click : function (_self, e)
180                                             {
181                                                Pman.Dialog.Image.show(
182                                                    {
183                                                         _url : baseURL+'/Xtuple/Pricing'
184                                                     
185                                                    },
186                                                    function (data) {
187                                                         var msg = [];
188                                                         if (data.deleted) {
189                                                             msg.push("Deleted " + data.deleted + " Price(s)");
190                                                         }
191                                                         if (data.updated) {
192                                                             msg.push("Updated " + data.updated + " Price(s)");
193                                                         }            
194                                                         if (data.inserted) {
195                                                             msg.push("Added " + data.inserted + " Price(s)");
196                                                         }
197                                                         if (!msg.length) {
198                                                             msg.push("No data changed");
199                                                         }
200                                                         Roo.MessageBox.alert("Notice", msg.join("\n"));
201                                             
202                                                    }
203                                                );
204                                             }
205                                         },
206                                         text : "Upload Price Matrix"
207                                     },
208                                     {
209                                         xtype: 'Fill',
210                                         xns: Roo.Toolbar
211                                     },
212                                     {
213                                         xtype: 'Button',
214                                         xns: Roo.Toolbar,
215                                         text : "Add",
216                                         cls : 'x-btn-text-icon',
217                                         icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
218                                         listeners : {
219                                             click : function()
220                                             {
221                                                 if (!_this.dialog) return;
222                                                 _this.dialog.show( { id : 0 } , function() {
223                                                     _this.grid.footer.onClick('first');
224                                                }); 
225                                             }
226                                         }
227                                     },
228                                     {
229                                         xtype: 'Button',
230                                         xns: Roo.Toolbar,
231                                         text : "Delete",
232                                         cls : 'x-btn-text-icon',
233                                         icon : rootURL + '/Pman/templates/images/trash.gif',
234                                         listeners : {
235                                             click : function()
236                                             {
237                                                  Pman.genericDelete(_this, 'ipshead'); 
238                                             }
239                                         }
240                                     }
241                                 ]
242                             },
243                             colModel : [
244                                 {
245                                     xtype: 'ColumnModel',
246                                     xns: Roo.grid,
247                                     dataIndex : 'ipshead_curr_id_curr_name',
248                                     header : 'Ipshead curr',
249                                     sortable : true,
250                                     width : 75,
251                                     renderer : function(v) { return String.format('{0}', v); }
252                                 },
253                                 {
254                                     xtype: 'ColumnModel',
255                                     xns: Roo.grid,
256                                     dataIndex : 'ipshead_name',
257                                     header : 'Ipshead name',
258                                     sortable : true,
259                                     width : 200,
260                                     renderer : function(v) { return String.format('{0}', v); }
261                                 },
262                                 {
263                                     xtype: 'ColumnModel',
264                                     xns: Roo.grid,
265                                     header : 'Ipshead descrip',
266                                     width : 200,
267                                     dataIndex : 'ipshead_descrip',
268                                     renderer : function(v) { return String.format('{0}', v); }
269                                 },
270                                 {
271                                     xtype: 'ColumnModel',
272                                     xns: Roo.grid,
273                                     header : 'Ipshead effective',
274                                     width : 75,
275                                     dataIndex : 'ipshead_effective',
276                                     renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }
277                                 },
278                                 {
279                                     xtype: 'ColumnModel',
280                                     xns: Roo.grid,
281                                     dataIndex : 'ipshead_expires',
282                                     header : 'Ipshead expires',
283                                     width : 75,
284                                     renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }
285                                 },
286                                 {
287                                     xtype: 'ColumnModel',
288                                     xns: Roo.grid,
289                                     header : 'Ipshead updated',
290                                     width : 75,
291                                     dataIndex : 'ipshead_updated',
292                                     renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y') : ''); }
293                                 }
294                             ]
295                         }
296                     },
297                     {
298                         xtype: 'GridPanel',
299                         xns: Roo,
300                         listeners : {
301                             activate : function() {
302                                 _this.ipanel = this;
303                                 if (_this.igrid) {
304                                    // _this.igrid.footer.onClick('first');
305                                 }
306                             }
307                         },
308                         background : true,
309                         fitContainer : true,
310                         fitToframe : true,
311                         region : 'east',
312                         tableName : 'item',
313                         title : "Products",
314                         grid : {
315                             xtype: 'EditorGrid',
316                             xns: Roo.grid,
317                             listeners : {
318                                 render : function() 
319                                 {
320                                     _this.igrid = this; 
321                                     //_this.dialog = Pman.Dialog.FILL_IN
322                                     if (_this.ipanel.active) {
323                                        //this.footer.onClick('first');
324                                     }
325                                 },
326                                 cellclick : function (_self, row, col, e)
327                                 {
328                                      var di = _this.grid.colModel.getDataIndex(col);
329                                      
330                                      var rec = _this.grid.ds.getAt(row);
331                                      
332                                      if(di == 'item_image_filename'){
333                                         if(!rec.data.item_image_id){
334                                             return;
335                                         }
336                                         var u = baseURL;
337                                         if(rec.data.item_image_from_hk){
338                                             u = u.split('/');
339                                             u.pop();
340                                             u = u.join('/') + '/hk.php';
341                                         }
342                                         Pman.download( {
343                                            url: u + '/Images/Download/' + rec.data.item_image_id  + '/' + rec.data.item_image_filename
344                                        });
345                                        return;
346                                      }
347                                      
348                                      if (di == 'item_active') {
349                                      
350                                         var nv = rec.data.item_active ? 0 : 1;
351                                         new Pman.Request({
352                                             mask : 'Saving',
353                                             url : baseURL + '/Roo/Item',
354                                             params : {
355                                                 item_id : rec.data.item_id,
356                                                 item_active : nv
357                                             },
358                                             success : function() {
359                                                 rec.set('item_active', nv);
360                                             }
361                                         });
362                                         return;
363                                         
364                                      
365                                      }
366                                      
367                                      if(di == 'itemsrc_active'){
368                                         if(!rec.data.itemsrc_active){
369                                             Roo.MessageBox.alert('Error','Please edit it on Xtuple tool');
370                                             return;
371                                         }
372                                         if(rec.data.itemsrc_active){
373                                             Roo.MessageBox.confirm("Confirm", "Are you sure this product is no longer purchased",
374                                                 function (res) {
375                                                     if(res!='yes') {
376                                                         return;
377                                                     }
378                                                     rec.commit();
379                                             });
380                                         }
381                                     }
382                                      
383                                      _this.locgrid.footer.onClick('first');
384                                      
385                                      
386                                      
387                                      
388                                 },
389                                 afteredit : function (e)
390                                 {
391                                     
392                                     
393                                     Roo.log(e);
394                                     new Pman.Request({
395                                         url : baseURL +'/Roo/Charass',
396                                         params : {
397                                              charass_char_id_char_name : e.field.replace(/^item_char_/,'').toUpperCase(),
398                                              charass_value : e.value,
399                                              charass_target_type : 'I',
400                                              charass_default : 1,
401                                              charass_target_id : e.record.data.item_id
402                                          },
403                                          method : 'POST'
404                                      });
405                                     
406                                     
407                                     e.record.commit();
408                                     
409                                     
410                                     
411                                 },
412                                 rowdblclick : function (_self, rowIndex, e)
413                                 {
414                                     if (!_this.dialog) return;
415                                     _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
416                                         _this.grid.footer.onClick('first');
417                                     }); 
418                                 }
419                             },
420                             autoExpandColumn : 'item_descrip1',
421                             clicksToEdit : 1,
422                             loadMask : true,
423                             dataSource : {
424                                 xtype: 'Store',
425                                 xns: Roo.data,
426                                 listeners : {
427                                     beforeload : function (_self, o)
428                                     {
429                                         o.params = o.params || {}
430                                         
431                                         var p = _this.grid.getSelectionModel().getSelected();
432                                         
433                                         if(!p || p.ipshead_id * 1 < 1){
434                                             this.ds.removeAll();
435                                             return;
436                                         }
437                                         
438                                         o.params.item_active = 1;
439                                     
440                                     },
441                                     update : function (_self, record, operation)
442                                     {
443                                         if(operation != 'commit'){
444                                             return;
445                                         }
446                                         
447                                         var nv  = record.data.itemsrc_active ? 0 : 1;
448                                         new Pman.Request({
449                                             mask : 'Saving',
450                                             url : baseURL + '/Roo/Itemsrc',
451                                             params : {
452                                                 _update_by_item : 1,
453                                                 item_id : record.data.item_id,
454                                                 itemsrc_active : nv
455                                             },
456                                             success : function(res) {
457                                                 record.set('itemsrc_active', nv);
458                                             }
459                                         });
460                                     }
461                                 },
462                                 remoteSort : true,
463                                 sortInfo : { field : 'item_number', direction: 'ASC' },
464                                 proxy : {
465                                     xtype: 'HttpProxy',
466                                     xns: Roo.data,
467                                     method : 'GET',
468                                     url : baseURL + '/Roo/item.php'
469                                 },
470                                 reader : {
471                                     xtype: 'JsonReader',
472                                     xns: Roo.data,
473                                     totalProperty : 'total',
474                                     root : 'data',
475                                     id : 'id',
476                                     fields : [
477                                         {
478                                             'name': 'item_id',
479                                             'type': 'int'
480                                         },
481                                         {
482                                             'name': 'item_number',
483                                             'type': 'string'
484                                         },
485                                         {
486                                             'name': 'item_descrip1',
487                                             'type': 'string'
488                                         },
489                                         {
490                                             'name': 'item_descrip2',
491                                             'type': 'string'
492                                         },
493                                         {
494                                             'name': 'item_classcode_id',
495                                             'type': 'int'
496                                         },
497                                         {
498                                             'name': 'item_picklist',
499                                             'type': 'int'
500                                         },
501                                         {
502                                             'name': 'item_comments',
503                                             'type': 'string'
504                                         },
505                                         {
506                                             'name': 'item_sold',
507                                             'type': 'int'
508                                         },
509                                         {
510                                             'name': 'item_fractional',
511                                             'type': 'int'
512                                         },
513                                         {
514                                             'name': 'item_active',
515                                             'type': 'int'
516                                         },
517                                         {
518                                             'name': 'item_type',
519                                             'type': 'string'
520                                         },
521                                         {
522                                             'name': 'item_prodweight',
523                                             'type': 'float'
524                                         },
525                                         {
526                                             'name': 'item_packweight',
527                                             'type': 'float'
528                                         },
529                                         {
530                                             'name': 'item_prodcat_id',
531                                             'type': 'int'
532                                         },
533                                         {
534                                             'name': 'item_exclusive',
535                                             'type': 'int'
536                                         },
537                                         {
538                                             'name': 'item_listprice',
539                                             'type': 'float'
540                                         },
541                                         {
542                                             'name': 'item_config',
543                                             'type': 'int'
544                                         },
545                                         {
546                                             'name': 'item_extdescrip',
547                                             'type': 'string'
548                                         },
549                                         {
550                                             'name': 'item_upccode',
551                                             'type': 'string'
552                                         },
553                                         {
554                                             'name': 'item_maxcost',
555                                             'type': 'float'
556                                         },
557                                         {
558                                             'name': 'item_inv_uom_id',
559                                             'type': 'int'
560                                         },
561                                         {
562                                             'name': 'item_price_uom_id',
563                                             'type': 'int'
564                                         },
565                                         {
566                                             'name': 'item_warrdays',
567                                             'type': 'int'
568                                         },
569                                         {
570                                             'name': 'item_freightclass_id',
571                                             'type': 'int'
572                                         },
573                                         {
574                                             'name': 'item_tax_recoverable',
575                                             'type': 'int'
576                                         },
577                                         {
578                                             'name': 'item_price_uom_id_uom_id',
579                                             'type': 'int'
580                                         },
581                                         {
582                                             'name': 'item_price_uom_id_uom_name',
583                                             'type': 'string'
584                                         },
585                                         {
586                                             'name': 'item_price_uom_id_uom_descrip',
587                                             'type': 'string'
588                                         },
589                                         {
590                                             'name': 'item_price_uom_id_uom_item_weight',
591                                             'type': 'int'
592                                         },
593                                         {
594                                             'name': 'item_inv_uom_id_uom_id',
595                                             'type': 'int'
596                                         },
597                                         {
598                                             'name': 'item_inv_uom_id_uom_name',
599                                             'type': 'string'
600                                         },
601                                         {
602                                             'name': 'item_inv_uom_id_uom_descrip',
603                                             'type': 'string'
604                                         },
605                                         {
606                                             'name': 'item_inv_uom_id_uom_item_weight',
607                                             'type': 'int'
608                                         },
609                                         {
610                                             'name': 'item_freightclass_id_freightclass_id',
611                                             'type': 'int'
612                                         },
613                                         {
614                                             'name': 'item_freightclass_id_freightclass_code',
615                                             'type': 'string'
616                                         },
617                                         {
618                                             'name': 'item_freightclass_id_freightclass_descrip',
619                                             'type': 'string'
620                                         },
621                                         {
622                                             'name': 'item_classcode_id_classcode_id',
623                                             'type': 'int'
624                                         },
625                                         {
626                                             'name': 'item_classcode_id_classcode_code',
627                                             'type': 'string'
628                                         },
629                                         {
630                                             'name': 'item_classcode_id_classcode_descrip',
631                                             'type': 'string'
632                                         },
633                                         {
634                                             'name': 'item_classcode_id_classcode_mfg',
635                                             'type': 'int'
636                                         },
637                                         {
638                                             'name': 'item_classcode_id_classcode_creator',
639                                             'type': 'string'
640                                         },
641                                         {
642                                             'name': 'item_classcode_id_classcode_created',
643                                             'type': 'date'
644                                         },
645                                         {
646                                             'name': 'item_classcode_id_classcode_modifier',
647                                             'type': 'string'
648                                         },
649                                         {
650                                             'name': 'item_classcode_id_classcode_modified',
651                                             'type': 'date'
652                                         },
653                                         {
654                                             'name': 'item_classcode_id_classcode_type',
655                                             'type': 'string'
656                                         }
657                                     ]
658                                 }
659                             },
660                             footer : {
661                                 xtype: 'PagingToolbar',
662                                 xns: Roo,
663                                 displayInfo : true,
664                                 displayMsg : "Displaying item{0} - {1} of {2}",
665                                 emptyMsg : "No item found",
666                                 pageSize : 25,
667                                 items : [
668                                     {
669                                         xtype: 'Button',
670                                         xns: Roo.Toolbar,
671                                         listeners : {
672                                             click : function (_self, e)
673                                             {
674                                                new Pman.Download({
675                                                     method: 'GET',
676                                                     url : baseURL + '/Roo/item',
677                                                     params : {
678                                                         _costgrid : 1
679                                                     }
680                                                });
681                                             }
682                                         },
683                                         text : "Download Standard costs"
684                                     },
685                                     {
686                                         xtype: 'Button',
687                                         xns: Roo.Toolbar,
688                                         listeners : {
689                                             click : function (_self, e)
690                                             {
691                                                Pman.Dialog.Image.show(
692                                                    {
693                                                         _url : baseURL+'/Xtuple/Import/Products'
694                                                     
695                                                    },
696                                                    function (data) {
697                                                         var msg = [];
698                                                        
699                                                         if (data.updated) {
700                                                             msg.push("Updated " + data.updated + " Products(s)");
701                                                         }            
702                                                         if (data.inserted) {
703                                                             msg.push("Added " + data.inserted + " Products(s)");
704                                                         }
705                                                         if (data.skipped) {
706                                                             msg.push("Skipped " + data.skipped);
707                                                         }
708                                                         
709                                                         if (!msg.length) {
710                                                             msg.push("No data changed");
711                                                         }
712                                                         Roo.MessageBox.alert("Notice", msg.join("\n"));
713                                             
714                                                    }
715                                                );
716                                             }
717                                         },
718                                         text : "Upload new products and costs"
719                                     },
720                                     {
721                                         xtype: 'Button',
722                                         xns: Roo.Toolbar,
723                                         listeners : {
724                                             click : function (_self, e)
725                                             {
726                                                 
727                                                 var sel = _this.grid.selModel.getSelectedCell();
728                                                 if (!sel) {
729                                                     Roo.MessageBox.alert("Error", "Select a row");
730                                                     return;
731                                                 }
732                                                 
733                                                 var rec = _this.grid.ds.getAt(sel[0]);
734                                                 if(rec.data.item_id * 1 < 1){
735                                                     return;
736                                                 }
737                                                 
738                                                 Pman.Dialog.Image.show({
739                                                         id : rec.data.item_image_id ? rec.data.item_image_id : 0,
740                                                         onid : rec.data.item_id,
741                                                         ontable : 'Item'
742                                                     }, function(data) {
743                                                         if (data) {
744                                                             _this.grid.footer.onClick('first');
745                                                             
746                                                     }
747                                                     
748                                                 });
749                                             }
750                                         },
751                                         text : "Upload an image"
752                                     },
753                                     {
754                                         xtype: 'Button',
755                                         xns: Roo.Toolbar,
756                                         listeners : {
757                                             click : function (_self, e)
758                                             {
759                                               Roo.MessageBox.progress ("Syncing Stock", "Sending");
760                                               
761                                               var offset = 0;
762                                               
763                                                function runSync() {
764                                                    
765                                                    new Pman.Request( {
766                                                         url : baseURL+'/Roo/Item',
767                                                         method : 'GET',
768                                                         params : {
769                                                             _syncFromHK : 1,
770                                                             offset : offset
771                                                         },
772                                                         success : function(res) {
773                                                             Roo.log(res);
774                                                             if (!res.data.total) {
775                                                                 Roo.MessageBox.hide();
776                                                                 return;
777                                                             }
778                                                             offset += res.data.limit;
779                                                             Roo.MessageBox.updateProgress ( offset  / res.data.total, "Done " + offset + '/' + res.data.total);
780                                                             runSync();
781                                                         }
782                                                         
783                                                     
784                                                    });
785                                                }
786                                                runSync();
787                                             }
788                                         },
789                                         text : "Sync Product Data from HK",
790                                         hidden : (function() {
791                                         
792                                             return baseURL.match(/hk\.php$/) ? true : false;
793                                         })()
794                                     }
795                                 ]
796                             },
797                             colModel : [
798                                 {
799                                     xtype: 'ColumnModel',
800                                     xns: Roo.grid,
801                                     dataIndex : 'item_char_brand',
802                                     header : 'Brand',
803                                     sortable : true,
804                                     width : 100,
805                                     renderer : function(v) { return String.format('{0}', v); },
806                                     editor : {
807                                         xtype: 'GridEditor',
808                                         xns: Roo.grid,
809                                         field : {
810                                             xtype: 'ComboBox',
811                                             xns: Roo.form,
812                                             allowBlank : true,
813                                             alwaysQuery : true,
814                                             displayField : 'charass_value',
815                                             editable : true,
816                                             forceSelection : false,
817                                             listWidth : 300,
818                                             loadingText : "Searching...",
819                                             minChars : 2,
820                                             pageSize : 20,
821                                             qtip : "Select Brand",
822                                             queryParam : 'query[charass_value]',
823                                             selectOnFocus : true,
824                                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{charass_value}</b> </div>',
825                                             triggerAction : 'all',
826                                             width : 150,
827                                             store : {
828                                                 xtype: 'Store',
829                                                 xns: Roo.data,
830                                                 listeners : {
831                                                     beforeload : function (_self, o)
832                                                     {
833                                                         o.params = o.params || {};
834                                                         // staff can see all logs, other companies can only see their own.
835                                                         // look for all of the charass 's with the same type= eg. brand.
836                                                         
837                                                         o.params.charass_char_id_char_name = 'BRAND';
838                                                         o.params.charass_target_type ='I';
839                                                         o.params._distinct = 'charass_value';
840                                                             o.params._columns = 'charass_value';
841                                                     
842                                                     }
843                                                 },
844                                                 remoteSort : true,
845                                                 sortInfo : { field : 'charass_value' , direction : 'ASC' },
846                                                 proxy : {
847                                                     xtype: 'HttpProxy',
848                                                     xns: Roo.data,
849                                                     method : 'GET',
850                                                     url : baseURL + '/Roo/Charass.php'
851                                                 },
852                                                 reader : {
853                                                     xtype: 'JsonReader',
854                                                     xns: Roo.data,
855                                                     totalProperty : 'total',
856                                                     root : 'data',
857                                                     id : 'id',
858                                                     fields : [
859                                                         {
860                                                             'name': 'id',
861                                                             'type': 'int'
862                                                         },
863                                                         {
864                                                             'name': 'person_name',
865                                                             'type': 'string'
866                                                         },
867                                                         {
868                                                             'name': 'event_when',
869                                                             'type': 'date',
870                                                             'dateFormat': 'Y-m-d'
871                                                         },
872                                                         {
873                                                             'name': 'action',
874                                                             'type': 'string'
875                                                         },
876                                                         {
877                                                             'name': 'ipaddr',
878                                                             'type': 'string'
879                                                         },
880                                                         {
881                                                             'name': 'on_id',
882                                                             'type': 'int'
883                                                         },
884                                                         {
885                                                             'name': 'on_table',
886                                                             'type': 'string'
887                                                         },
888                                                         {
889                                                             'name': 'person_id',
890                                                             'type': 'int'
891                                                         },
892                                                         {
893                                                             'name': 'remarks',
894                                                             'type': 'string'
895                                                         },
896                                                         {
897                                                             'name': 'person_id_id',
898                                                             'type': 'int'
899                                                         },
900                                                         {
901                                                             'name': 'person_id_office_id',
902                                                             'type': 'int'
903                                                         },
904                                                         {
905                                                             'name': 'person_id_name',
906                                                             'type': 'string'
907                                                         },
908                                                         {
909                                                             'name': 'person_id_phone',
910                                                             'type': 'string'
911                                                         },
912                                                         {
913                                                             'name': 'person_id_fax',
914                                                             'type': 'string'
915                                                         },
916                                                         {
917                                                             'name': 'person_id_email',
918                                                             'type': 'string'
919                                                         },
920                                                         {
921                                                             'name': 'person_id_company_id',
922                                                             'type': 'int'
923                                                         },
924                                                         {
925                                                             'name': 'person_id_role',
926                                                             'type': 'string'
927                                                         },
928                                                         {
929                                                             'name': 'person_id_active',
930                                                             'type': 'int'
931                                                         },
932                                                         {
933                                                             'name': 'person_id_remarks',
934                                                             'type': 'string'
935                                                         },
936                                                         {
937                                                             'name': 'person_id_passwd',
938                                                             'type': 'string'
939                                                         },
940                                                         {
941                                                             'name': 'person_id_owner_id',
942                                                             'type': 'int'
943                                                         },
944                                                         {
945                                                             'name': 'person_id_lang',
946                                                             'type': 'string'
947                                                         },
948                                                         {
949                                                             'name': 'person_id_no_reset_sent',
950                                                             'type': 'int'
951                                                         },
952                                                         {
953                                                             'name': 'person_id_action_type',
954                                                             'type': 'string'
955                                                         },
956                                                         {
957                                                             'name': 'person_id_project_id',
958                                                             'type': 'int'
959                                                         },
960                                                         {
961                                                             'name': 'person_id_deleted_by',
962                                                             'type': 'int'
963                                                         },
964                                                         {
965                                                             'name': 'person_id_deleted_dt',
966                                                             'type': 'date'
967                                                         }
968                                                     ]
969                                                 }
970                                             }
971                                         }
972                                     }
973                                 },
974                                 {
975                                     xtype: 'ColumnModel',
976                                     xns: Roo.grid,
977                                     dataIndex : 'item_char_productgroup',
978                                     header : 'Product Group',
979                                     width : 100,
980                                     renderer : function(v) { return String.format('{0}', v); },
981                                     editor : {
982                                         xtype: 'GridEditor',
983                                         xns: Roo.grid,
984                                         field : {
985                                             xtype: 'ComboBox',
986                                             xns: Roo.form,
987                                             allowBlank : true,
988                                             alwaysQuery : true,
989                                             displayField : 'charass_value',
990                                             editable : true,
991                                             forceSelection : false,
992                                             listWidth : 300,
993                                             loadingText : "Searching...",
994                                             minChars : 2,
995                                             pageSize : 20,
996                                             qtip : "Select Brand",
997                                             queryParam : 'query[charass_value]',
998                                             selectOnFocus : true,
999                                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{charass_value}</b> </div>',
1000                                             triggerAction : 'all',
1001                                             width : 150,
1002                                             store : {
1003                                                 xtype: 'Store',
1004                                                 xns: Roo.data,
1005                                                 listeners : {
1006                                                     beforeload : function (_self, o)
1007                                                     {
1008                                                         o.params = o.params || {};
1009                                                         // staff can see all logs, other companies can only see their own.
1010                                                         // look for all of the charass 's with the same type= eg. brand.
1011                                                         
1012                                                         o.params.charass_char_id_char_name = 'PRODUCTGROUP';
1013                                                         o.params.charass_target_type ='I';
1014                                                         o.params._distinct = 'charass_value';
1015                                                             o.params._columns = 'charass_value';    
1016                                                     }
1017                                                 },
1018                                                 remoteSort : true,
1019                                                 sortInfo : { field : 'charass_value' , direction : 'ASC' },
1020                                                 proxy : {
1021                                                     xtype: 'HttpProxy',
1022                                                     xns: Roo.data,
1023                                                     method : 'GET',
1024                                                     url : baseURL + '/Roo/Charass.php'
1025                                                 },
1026                                                 reader : {
1027                                                     xtype: 'JsonReader',
1028                                                     xns: Roo.data,
1029                                                     totalProperty : 'total',
1030                                                     root : 'data',
1031                                                     id : 'id',
1032                                                     fields : [
1033                                                         {
1034                                                             'name': 'id',
1035                                                             'type': 'int'
1036                                                         },
1037                                                         {
1038                                                             'name': 'person_name',
1039                                                             'type': 'string'
1040                                                         },
1041                                                         {
1042                                                             'name': 'event_when',
1043                                                             'type': 'date',
1044                                                             'dateFormat': 'Y-m-d'
1045                                                         },
1046                                                         {
1047                                                             'name': 'action',
1048                                                             'type': 'string'
1049                                                         },
1050                                                         {
1051                                                             'name': 'ipaddr',
1052                                                             'type': 'string'
1053                                                         },
1054                                                         {
1055                                                             'name': 'on_id',
1056                                                             'type': 'int'
1057                                                         },
1058                                                         {
1059                                                             'name': 'on_table',
1060                                                             'type': 'string'
1061                                                         },
1062                                                         {
1063                                                             'name': 'person_id',
1064                                                             'type': 'int'
1065                                                         },
1066                                                         {
1067                                                             'name': 'remarks',
1068                                                             'type': 'string'
1069                                                         },
1070                                                         {
1071                                                             'name': 'person_id_id',
1072                                                             'type': 'int'
1073                                                         },
1074                                                         {
1075                                                             'name': 'person_id_office_id',
1076                                                             'type': 'int'
1077                                                         },
1078                                                         {
1079                                                             'name': 'person_id_name',
1080                                                             'type': 'string'
1081                                                         },
1082                                                         {
1083                                                             'name': 'person_id_phone',
1084                                                             'type': 'string'
1085                                                         },
1086                                                         {
1087                                                             'name': 'person_id_fax',
1088                                                             'type': 'string'
1089                                                         },
1090                                                         {
1091                                                             'name': 'person_id_email',
1092                                                             'type': 'string'
1093                                                         },
1094                                                         {
1095                                                             'name': 'person_id_company_id',
1096                                                             'type': 'int'
1097                                                         },
1098                                                         {
1099                                                             'name': 'person_id_role',
1100                                                             'type': 'string'
1101                                                         },
1102                                                         {
1103                                                             'name': 'person_id_active',
1104                                                             'type': 'int'
1105                                                         },
1106                                                         {
1107                                                             'name': 'person_id_remarks',
1108                                                             'type': 'string'
1109                                                         },
1110                                                         {
1111                                                             'name': 'person_id_passwd',
1112                                                             'type': 'string'
1113                                                         },
1114                                                         {
1115                                                             'name': 'person_id_owner_id',
1116                                                             'type': 'int'
1117                                                         },
1118                                                         {
1119                                                             'name': 'person_id_lang',
1120                                                             'type': 'string'
1121                                                         },
1122                                                         {
1123                                                             'name': 'person_id_no_reset_sent',
1124                                                             'type': 'int'
1125                                                         },
1126                                                         {
1127                                                             'name': 'person_id_action_type',
1128                                                             'type': 'string'
1129                                                         },
1130                                                         {
1131                                                             'name': 'person_id_project_id',
1132                                                             'type': 'int'
1133                                                         },
1134                                                         {
1135                                                             'name': 'person_id_deleted_by',
1136                                                             'type': 'int'
1137                                                         },
1138                                                         {
1139                                                             'name': 'person_id_deleted_dt',
1140                                                             'type': 'date'
1141                                                         }
1142                                                     ]
1143                                                 }
1144                                             }
1145                                         }
1146                                     }
1147                                 },
1148                                 {
1149                                     xtype: 'ColumnModel',
1150                                     xns: Roo.grid,
1151                                     dataIndex : 'item_number',
1152                                     header : 'Number',
1153                                     width : 100,
1154                                     renderer : function(v) { return String.format('{0}', v); }
1155                                 },
1156                                 {
1157                                     xtype: 'ColumnModel',
1158                                     xns: Roo.grid,
1159                                     dataIndex : 'item_descrip1',
1160                                     header : 'Description',
1161                                     width : 200,
1162                                     renderer : function(v) { return String.format('{0}', v); }
1163                                 },
1164                                 {
1165                                     xtype: 'ColumnModel',
1166                                     xns: Roo.grid,
1167                                     dataIndex : 'itemsrc_active',
1168                                     header : 'Purchased',
1169                                     width : 75,
1170                                     renderer : function(v) {  
1171                                         var state = v * 1 > 0 ?  '-checked' : '';
1172                                     
1173                                         return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
1174                                                     
1175                                      }
1176                                 },
1177                                 {
1178                                     xtype: 'ColumnModel',
1179                                     xns: Roo.grid,
1180                                     dataIndex : 'item_sold',
1181                                     header : 'is Sold?',
1182                                     width : 75,
1183                                     renderer : function(v) {  
1184                                         var state = v * 1 > 0 ?  '-checked' : '';
1185                                     
1186                                         return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
1187                                                     
1188                                      }
1189                                 },
1190                                 {
1191                                     xtype: 'ColumnModel',
1192                                     xns: Roo.grid,
1193                                     dataIndex : 'item_active',
1194                                     header : 'is Active?',
1195                                     width : 75,
1196                                     renderer : function(v) {  
1197                                         var state = v * 1 > 0 ?  '-checked' : '';
1198                                     
1199                                         return '<img class="x-grid-check-icon' + state + '" src="' + Roo.BLANK_IMAGE_URL + '"/>';
1200                                                     
1201                                      }
1202                                 },
1203                                 {
1204                                     xtype: 'ColumnModel',
1205                                     xns: Roo.grid,
1206                                     dataIndex : 'last_purchase_price',
1207                                     header : 'Last purchase price',
1208                                     width : 120,
1209                                     renderer : function(v,x,r) {
1210                                     
1211                                          return String.format('{0}{1}', r.data.last_purchase_price_curr_name, Roo.util.Format.number(v,2)) ; 
1212                                          
1213                                      }
1214                                 },
1215                                 {
1216                                     xtype: 'ColumnModel',
1217                                     xns: Roo.grid,
1218                                     dataIndex : 'item_type',
1219                                     header : 'Item type',
1220                                     width : 100,
1221                                     renderer : function(v) { return String.format('{0}', v); }
1222                                 },
1223                                 {
1224                                     xtype: 'ColumnModel',
1225                                     xns: Roo.grid,
1226                                     dataIndex : 'item_prodcat_id_prodcat_code',
1227                                     header : 'Item prodcat',
1228                                     width : 100,
1229                                     renderer : function(v) { return String.format('{0}', v); }
1230                                 },
1231                                 {
1232                                     xtype: 'ColumnModel',
1233                                     xns: Roo.grid,
1234                                     align : 'right',
1235                                     dataIndex : 'item_actcost',
1236                                     header : 'Cost',
1237                                     width : 75,
1238                                     renderer : function(v,x,r) {
1239                                     
1240                                          return String.format('{0}{1}', r.data.item_curr_name, Roo.util.Format.number(v,2)) ; 
1241                                          
1242                                      }
1243                                 },
1244                                 {
1245                                     xtype: 'ColumnModel',
1246                                     xns: Roo.grid,
1247                                     align : 'right',
1248                                     dataIndex : 'item_base_cost',
1249                                     header : 'Cost (base)',
1250                                     width : 75,
1251                                     renderer : function(v,x,r) {
1252                                     
1253                                          return String.format('{0}{1}', r.data.item_base_curr, Roo.util.Format.number(v,2)) ; 
1254                                          
1255                                      }
1256                                 }
1257                             ]
1258                         }
1259                     }
1260                 ],
1261                 center : {
1262                     xtype: 'LayoutRegion',
1263                     xns: Roo
1264                 },
1265                 east : {
1266                     xtype: 'LayoutRegion',
1267                     xns: Roo,
1268                     split : true,
1269                     width : 200
1270                 }
1271             }
1272         };
1273     }
1274 });