pgsql/vendaddrinfo.sql
[Pman.Xtuple] / Pman.Dialog.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.Dialog');
6
7 Pman.Dialog.XtupleItem = {
8
9     dialog : false,
10     callback:  false,
11
12     show : function(data, cb)
13     {
14         if (!this.dialog) {
15             this.create();
16         }
17
18         this.callback = cb;
19         this.data = data;
20         this.dialog.show(this.data._el);
21         if (this.form) {
22            this.form.reset();
23            this.form.setValues(data);
24            this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
25         }
26
27     },
28
29     create : function()
30     {
31         var _this = this;
32         this.dialog = Roo.factory({
33             center : {
34                 '|xns' : 'Roo',
35                 alwaysShowTabs : true,
36                 xtype : 'LayoutRegion',
37                 tabPosition : 'top',
38                 xns : Roo
39             },
40             '|xns' : 'Roo',
41             modal : true,
42             collapsible : false,
43             title : "Edit / Create item",
44             xtype : 'LayoutDialog',
45             width : 800,
46             xns : Roo,
47             closable : false,
48             resizable : false,
49             height : 550,
50             buttons : [
51                  {
52                         '|xns' : 'Roo',
53                         text : "Cancel",
54                         xtype : 'Button',
55                         xns : Roo,
56                         listeners : {
57                                 click : function (_self, e)
58                                    {
59                                        _this.dialog.hide();
60                                    }
61                         }
62                     },
63 {
64                         '|xns' : 'Roo',
65                         text : "Save",
66                         xtype : 'Button',
67                         xns : Roo,
68                         listeners : {
69                                 render : function (_self)
70                                    {
71                                        _this.saveBtn = this;
72                                    },
73                                 click : function (_self, e)
74                                    {
75                                        // do some checks?
76                                         
77                                        
78                                      //  _this.dialog.el.mask("Saving");
79                                        _this.form.doAction("submit");
80                                    
81                                    }
82                         }
83                     }
84             ],
85             listeners : {
86                 show : function (_self)
87                    {
88                         _this.dialog.layout.getRegion('center').showPanel(0);
89                    }
90             },
91             items : [
92                 {
93                     '|xns' : 'Roo',
94                     region : 'center',
95                     xtype : 'ContentPanel',
96                     title : "Detail",
97                     xns : Roo,
98                     items : [
99                         {
100                             '|xns' : 'Roo.form',
101                             url : baseURL + '/Roo/item.php',
102                             style : 'margin:10px;',
103                             method : 'POST',
104                             xtype : 'Form',
105                             labelWidth : 120,
106                             xns : Roo.form,
107                             listeners : {
108                                 actioncomplete : function(_self,action)
109                                    {
110                                        if (action.type == 'setdata') {
111                                           _this.form.findField('item_number').el.dom.readOnly = true;
112                                           _this.form.findField('item_type').disabled = true; 
113                                           
114                                           if(_this.data.item_id * 1 > 0){
115                                                
116                                                this.load({ 
117                                                    method: 'GET', 
118                                                    params: {
119                                                         '_id' : _this.data.item_id,
120                                                         '_with_itemsite' : 1,
121                                                         '_with_itemcost' : 1,
122                                                         '_with_prodcat' : 1 ,
123                                                         '_with_salesaccnt' : 1 
124                                                    }
125                                                });
126                                                return;
127                                           }
128                                           // if it's new..
129                                           _this.form.findField('item_number').el.dom.readOnly = false;
130                                           _this.form.findField('item_type').disabled = false; 
131                                           _this.form.findField('item_salesaccnt').setValue('');
132                                           
133                                           _this.form.findField('item_type').showHide();
134                                           
135                                           return;
136                                        }
137                                        if (action.type == 'load') {
138                                           _this.form.findField('item_type').showHide();
139                                            return;
140                                        }
141                                        if (action.type =='submit') {
142                                        
143                                            var id = _this.form.findField('item_id').getValue() * 1;
144                                            if (id < 1) {
145                                            
146                                                this.load({ 
147                                                    method: 'GET', 
148                                                    params: {
149                                                         '_id' : action.result.data.item_id,
150                                                         '_with_itemsite' : 1,
151                                                         '_with_itemcost' : 1,
152                                                         '_with_prodcat' : 1 ,
153                                                         '_with_salesaccnt' : 1 
154                                                    }
155                                                });
156                                                return;
157                                            }
158                                            _this.dialog.hide();
159                                        
160                                             if (_this.callback) {
161                                                _this.callback.call(_this, _this.form.getValues());
162                                             }
163                                             _this.form.reset();
164                                             return;
165                                        }
166                                    },
167                                 rendered : function (form)
168                                    {
169                                        _this.form= form;
170                                    }
171                             },
172                             items : [
173                                 {
174                                     '|xns' : 'Roo.form',
175                                     fieldLabel : 'SKU',
176                                     xtype : 'TextField',
177                                     allowBlank : false,
178                                     width : 200,
179                                     xns : Roo.form,
180                                     name : 'item_number'
181                                 },
182                                 {
183                                     '|xns' : 'Roo.form',
184                                     fieldLabel : 'Description',
185                                     xtype : 'TextField',
186                                     width : 400,
187                                     xns : Roo.form,
188                                     name : 'item_descrip1'
189                                 },
190                                 {
191                                     '|xns' : 'Roo.form',
192                                     fieldLabel : 'Description (2)',
193                                     xtype : 'TextField',
194                                     width : 400,
195                                     xns : Roo.form,
196                                     name : 'item_descrip2'
197                                 },
198                                 {
199                                     '|xns' : 'Roo.form',
200                                     xtype : 'Column',
201                                     labelWidth : 120,
202                                     xns : Roo.form,
203                                     items : [
204                                         {
205                                             store : {
206                                                 '|xns' : 'Roo.data',
207                                                 xtype : 'SimpleStore',
208                                                 data : [ 
209                                                     [ 'P', "Purchased (eg. a standard product)"],
210                                                     [ 'R' , "Reference (Non-Product)"],
211                                                     [ 'K', "Kit (made up of products)"]  
212                                                 ],
213                                                 fields : [  'ftype', 'fname'],
214                                                 xns : Roo.data
215                                             },
216                                             '|xns' : 'Roo.form',
217                                             listWidth : 200,
218                                             triggerAction : 'all',
219                                             fieldLabel : 'Type',
220                                             displayField : 'fname',
221                                             emptyText : "Select Type",
222                                             hiddenName : 'item_type',
223                                             valueField : 'ftype',
224                                             xtype : 'ComboBox',
225                                             allowBlank : false,
226                                             showHide : function() {
227                                             
228                                                 var it = this.getValue();
229                                                 
230                                                 var options = [ 
231                                                     'item_itemcost_id_itemcost_curr_id',
232                                                     'item_itemcost_id_itemcost_actcost',
233                                                     'item_itemsite_id_itemsite_reorderlevel',
234                                                     'item_itemsite_id_itemsite_leadtime',
235                                                     'item_itemsite_id_itemsite_location_id',
236                                                     'item_itemsite_id_itemsite_loccntrl',
237                                                     'item_itemsite_id_itemsite_stocked',
238                                                     'item_itemsite_id_itemsite_perishable',
239                                                     
240                                                     'item_itemsite_id_itemsite_safetystock',
241                                                     'item_itemsite_id_itemsite_controlmethod',
242                                                     'item_itemsite_id_itemsite_plancode_id',
243                                                     'item_itemsite_id_itemsite_costcat_id',
244                                                     'item_itemsite_id_itemsite_active',
245                                                     'item_itemsite_id_itemsite_sold'
246                                                     
247                                                 ];
248                                                 
249                                                 var r_req = [ 
250                                                     'item_listprice'
251                                                 ];
252                                                 
253                                                 var state = true;
254                                                 
255                                                 _this.standardCostFieldSet.show();
256                                                 _this.itemsiteFieldSet.show();
257                                             
258                                                 
259                                                 switch(it) {
260                                                     case 'K':
261                                                         state = false;
262                                             
263                                                         _this.form.findField('item_listprice').allowBlank = false;
264                                                         _this.form.findField('item_listprice').actionMode = 'fieldEl';
265                                                         _this.form.findField('item_listprice').hideMode = 'display';
266                                                         _this.form.findField('item_listprice').show();
267                                                                     
268                                                         break;
269                                                         
270                                                     case 'R': // refrence
271                                                         options = options.concat(r_req);
272                                                         state = false;
273                                                         _this.standardCostFieldSet.hide();
274                                                         break;
275                                                         
276                                                     case 'P': // purchased..
277                                                         options = options.concat(r_req);
278                                                         // must have
279                                                         break;
280                                                 }
281                                                 
282                                                 Roo.each(options, function(n) {
283                                                     var ff = _this.form.findField(n);
284                                                     ff.allowBlank = !state;
285                                                     ff.actionMode = 'fieldEl';
286                                                     ff.hideMode = 'display';
287                                                     state ? ff.show() : ff.hide(); 
288                                                     
289                                                 });
290                                                 
291                                                 
292                                                 if(!state){
293                                                     _this.standardCostFieldSet.hide();
294                                                     _this.itemsiteFieldSet.hide();
295                                             
296                                                 }
297                                                 
298                                               
299                                                        
300                                             },
301                                             editable : false,
302                                             width : 200,
303                                             xns : Roo.form,
304                                             mode : 'local',
305                                             name : 'item_type_name',
306                                             tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{fname}</b> </div>',
307                                             listeners : {
308                                                 beforeselect : function (combo, record, index)
309                                                    {
310                                                        (function() { combo.showHide(); }).defer(100);
311                                                    }
312                                             },
313                                             items : [
314
315                                             ]
316
317                                         },
318                                         {
319                                             store : {
320                                                 proxy : {
321                                                     '|xns' : 'Roo.data',
322                                                     url : baseURL + '/Roo/classcode.php',
323                                                     xtype : 'HttpProxy',
324                                                     method : 'GET',
325                                                     xns : Roo.data
326                                                 },
327                                                 reader : {
328                                                     '|xns' : 'Roo.data',
329                                                     id : 'id',
330                                                     root : 'data',
331                                                     xtype : 'JsonReader',
332                                                     xns : Roo.data,
333                                                     fields : [{"name":"id","type":"int"},{"name":"classcode_code","type":"string"}],
334                                                     totalProperty : 'total'
335                                                 },
336                                                 '|xns' : 'Roo.data',
337                                                 xtype : 'Store',
338                                                 remoteSort : true,
339                                                 sortInfo : { direction : 'ASC', field: 'id' },
340                                                 xns : Roo.data,
341                                                 listeners : {
342                                                         beforeload : function (_self, o){
343                                                                o.params = o.params || {};
344                                                                // set more here
345                                                            }
346                                                 },
347                                                 items : [
348
349                                                 ]
350
351                                             },
352                                             '|xns' : 'Roo.form',
353                                             listWidth : 400,
354                                             triggerAction : 'all',
355                                             fieldLabel : 'Class',
356                                             forceSelection : true,
357                                             selectOnFocus : true,
358                                             pageSize : 20,
359                                             displayField : 'classcode_code',
360                                             emptyText : "Select classcode",
361                                             hiddenName : 'item_classcode_id',
362                                             minChars : 2,
363                                             valueField : 'classcode_id',
364                                             xtype : 'ComboBox',
365                                             allowBlank : false,
366                                             typeAhead : true,
367                                             editable : false,
368                                             width : 200,
369                                             xns : Roo.form,
370                                             name : 'item_classcode_id_classcode_code',
371                                             qtip : "Select classcode",
372                                             queryParam : '',
373                                             tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{classcode_code}</b> </div>',
374                                             loadingText : "Searching...",
375                                             items : [
376
377                                             ]
378
379                                         },
380                                         {
381                                             store : {
382                                                 proxy : {
383                                                     '|xns' : 'Roo.data',
384                                                     url : baseURL + '/Roo/uom.php',
385                                                     xtype : 'HttpProxy',
386                                                     method : 'GET',
387                                                     xns : Roo.data
388                                                 },
389                                                 reader : {
390                                                     '|xns' : 'Roo.data',
391                                                     id : 'id',
392                                                     root : 'data',
393                                                     xtype : 'JsonReader',
394                                                     xns : Roo.data,
395                                                     fields : [
396                                                         {"name":"id","type":"int"},
397                                                         {"name":"uom_name","type":"string"},
398                                                         {"name":"uom_descrip","type":"string"},
399                                                     ],
400                                                     totalProperty : 'total'
401                                                 },
402                                                 '|xns' : 'Roo.data',
403                                                 xtype : 'Store',
404                                                 remoteSort : true,
405                                                 sortInfo : { direction : 'ASC', field: 'uom_name' },
406                                                 xns : Roo.data,
407                                                 listeners : {
408                                                         beforeload : function (_self, o){
409                                                                o.params = o.params || {};
410                                                                // set more here
411                                                            }
412                                                 },
413                                                 items : [
414
415                                                 ]
416
417                                             },
418                                             '|xns' : 'Roo.form',
419                                             listWidth : 400,
420                                             triggerAction : 'all',
421                                             fieldLabel : 'Invoice UOM',
422                                             forceSelection : true,
423                                             selectOnFocus : true,
424                                             pageSize : 20,
425                                             displayField : 'uom_descrip',
426                                             emptyText : "Select uom",
427                                             hiddenName : 'item_inv_uom_id',
428                                             minChars : 2,
429                                             valueField : 'uom_id',
430                                             xtype : 'ComboBox',
431                                             allowBlank : false,
432                                             typeAhead : true,
433                                             editable : false,
434                                             width : 200,
435                                             xns : Roo.form,
436                                             name : 'item_inv_uom_id_uom_descrip',
437                                             qtip : "Select classcode",
438                                             queryParam : '',
439                                             tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{uom_descrip}</b> </div>',
440                                             loadingText : "Searching...",
441                                             items : [
442
443                                             ]
444
445                                         },
446                                         {
447                                             store : {
448                                                 proxy : {
449                                                     '|xns' : 'Roo.data',
450                                                     url : baseURL + '/Roo/uom.php',
451                                                     method : 'GET',
452                                                     xtype : 'HttpProxy',
453                                                     xns : Roo.data
454                                                 },
455                                                 reader : {
456                                                     '|xns' : 'Roo.data',
457                                                     id : 'id',
458                                                     root : 'data',
459                                                     xtype : 'JsonReader',
460                                                     xns : Roo.data,
461                                                     fields : [
462                                                         {"name":"id","type":"int"},
463                                                         {"name":"uom_name","type":"string"},
464                                                         {"name":"uom_descrip","type":"string"},
465                                                     ],
466                                                     totalProperty : 'total'
467                                                 },
468                                                 '|xns' : 'Roo.data',
469                                                 xtype : 'Store',
470                                                 remoteSort : true,
471                                                 sortInfo : { direction : 'ASC', field: 'uom_name' },
472                                                 xns : Roo.data,
473                                                 listeners : {
474                                                         beforeload : function (_self, o){
475                                                                o.params = o.params || {};
476                                                                // set more here
477                                                            }
478                                                 },
479                                                 items : [
480
481                                                 ]
482
483                                             },
484                                             '|xns' : 'Roo.form',
485                                             listWidth : 400,
486                                             triggerAction : 'all',
487                                             fieldLabel : 'Price UOM',
488                                             forceSelection : true,
489                                             selectOnFocus : true,
490                                             pageSize : 20,
491                                             displayField : 'uom_descrip',
492                                             emptyText : "Select uom",
493                                             hiddenName : 'item_price_uom_id',
494                                             minChars : 2,
495                                             valueField : 'uom_id',
496                                             xtype : 'ComboBox',
497                                             allowBlank : false,
498                                             typeAhead : true,
499                                             editable : false,
500                                             width : 200,
501                                             xns : Roo.form,
502                                             name : 'item_price_uom_id_uom_descrip',
503                                             qtip : "Select classcode",
504                                             queryParam : '',
505                                             tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{uom_descrip}</b> </div>',
506                                             loadingText : "Searching...",
507                                             items : [
508
509                                             ]
510
511                                         },
512                                         {
513                                             '|xns' : 'Roo.form',
514                                             fieldLabel : 'Weight',
515                                             xtype : 'NumberField',
516                                             allowBlank : false,
517                                             allowDecimals : true,
518                                             decimalPrecision : 2,
519                                             width : 200,
520                                             xns : Roo.form,
521                                             name : 'item_prodweight'
522                                         },
523                                         {
524                                             '|xns' : 'Roo.form',
525                                             fieldLabel : 'Item comments',
526                                             xtype : 'TextArea',
527                                             width : 200,
528                                             xns : Roo.form,
529                                             name : 'item_comments',
530                                             height : 100
531                                         },
532                                         {
533                                             '|xns' : 'Roo.form',
534                                             fieldLabel : 'Item sold',
535                                             inputValue : true,
536                                             xtype : 'Checkbox',
537                                             valueOff : 0,
538                                             width : 75,
539                                             xns : Roo.form,
540                                             name : 'item_sold'
541                                         },
542                                         {
543                                             '|xns' : 'Roo.form',
544                                             fieldLabel : 'Item active',
545                                             inputValue : true,
546                                             xtype : 'Checkbox',
547                                             valueOff : 0,
548                                             width : 75,
549                                             xns : Roo.form,
550                                             name : 'item_active'
551                                         },
552                                         {
553                                             store : {
554                                                 proxy : {
555                                                     '|xns' : 'Roo.data',
556                                                     url : baseURL + '/Roo/prodcat.php',
557                                                     method : 'GET',
558                                                     xtype : 'HttpProxy',
559                                                     xns : Roo.data
560                                                 },
561                                                 reader : {
562                                                     '|xns' : 'Roo.data',
563                                                     id : 'id',
564                                                     root : 'data',
565                                                     xtype : 'JsonReader',
566                                                     xns : Roo.data,
567                                                     fields : [{"name":"id","type":"int"},{"name":"prodcat_code","type":"string"}],
568                                                     totalProperty : 'total'
569                                                 },
570                                                 '|xns' : 'Roo.data',
571                                                 xtype : 'Store',
572                                                 remoteSort : true,
573                                                 xns : Roo.data,
574                                                 sortInfo : { direction : 'ASC', field: 'id' },
575                                                 listeners : {
576                                                         beforeload : function (_self, o){
577                                                                o.params = o.params || {};
578                                                                // set more here
579                                                            }
580                                                 },
581                                                 items : [
582
583                                                 ]
584
585                                             },
586                                             '|xns' : 'Roo.form',
587                                             alwaysQuery : true,
588                                             listWidth : 400,
589                                             triggerAction : 'all',
590                                             fieldLabel : 'Product Category',
591                                             forceSelection : true,
592                                             selectOnFocus : true,
593                                             pageSize : 20,
594                                             displayField : 'prodcat_code',
595                                             emptyText : "Select Category",
596                                             hiddenName : 'item_prodcat_id',
597                                             minChars : 2,
598                                             valueField : 'prodcat_id',
599                                             xtype : 'ComboBox',
600                                             allowBlank : false,
601                                             typeAhead : true,
602                                             editable : false,
603                                             width : 200,
604                                             xns : Roo.form,
605                                             name : 'item_prodcat_id_prodcat_code',
606                                             qtip : "Select prodcat",
607                                             queryParam : '',
608                                             tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{prodcat_code}</b> </div>',
609                                             loadingText : "Searching...",
610                                             listeners : {
611                                                 add : function (combo)
612                                                    {
613                                                        Pman.Dialog.XtupleProdcat.show({prodcat_id : 0});
614                                                    },
615                                                 edit : function (combo, record)
616                                                    {
617                                                        var s = _this.form.findField('item_prodcat_id').getValue() * 1;
618                                                        if(s < 1){
619                                                            Roo.MessageBox.alert('Error','Please select a account assignment');
620                                                            return;
621                                                        }
622                                                        Pman.Dialog.XtupleProdcat.show({prodcat_id : s});
623                                                    }
624                                             },
625                                             items : [
626
627                                             ]
628
629                                         },
630                                         {
631                                             '|xns' : 'Roo.form',
632                                             fieldLabel : 'Sales Account',
633                                             xtype : 'DisplayField',
634                                             xns : Roo.form,
635                                             name : 'item_salesaccnt'
636                                         },
637                                         {
638                                             '|xns' : 'Roo.form',
639                                             fieldLabel : 'Item listprice',
640                                             xtype : 'NumberField',
641                                             width : 200,
642                                             xns : Roo.form,
643                                             name : 'item_listprice'
644                                         },
645                                         {
646                                             '|xns' : 'Roo.form',
647                                             xtype : 'FieldSet',
648                                             legend : "Standard Cost",
649                                             style : 'width:320px',
650                                             xns : Roo.form,
651                                             listeners : {
652                                                 render : function (_self)
653                                                    {
654                                                        _this.standardCostFieldSet = _self;
655                                                    }
656                                             },
657                                             items : [
658                                                 {
659                                                     store : {
660                                                         proxy : {
661                                                             '|xns' : 'Roo.data',
662                                                             url : baseURL + '/Roo/curr_symbol.php',
663                                                             method : 'GET',
664                                                             xtype : 'HttpProxy',
665                                                             xns : Roo.data
666                                                         },
667                                                         reader : {
668                                                             '|xns' : 'Roo.data',
669                                                             id : 'curr_id',
670                                                             root : 'data',
671                                                             xtype : 'JsonReader',
672                                                             xns : Roo.data,
673                                                             fields : [{"name":"curr_id","type":"int"},"curr_symbol"],
674                                                             totalProperty : 'total'
675                                                         },
676                                                         '|xns' : 'Roo.data',
677                                                         xtype : 'Store',
678                                                         remoteSort : true,
679                                                         sortInfo : { direction : 'ASC', field: 'curr_symbol' },
680                                                         xns : Roo.data,
681                                                         listeners : {
682                                                                 beforeload : function (_self, o){
683                                                                        o.params = o.params || {};
684                                                                        // set more here
685                                                                       
686                                                                    }
687                                                         },
688                                                         items : [
689
690                                                         ]
691
692                                                     },
693                                                     '|xns' : 'Roo.form',
694                                                     listWidth : 400,
695                                                     triggerAction : 'all',
696                                                     fieldLabel : 'Currency',
697                                                     forceSelection : true,
698                                                     selectOnFocus : true,
699                                                     pageSize : 20,
700                                                     displayField : 'curr_name',
701                                                     emptyText : "Select Currency",
702                                                     hiddenName : 'item_itemcost_id_itemcost_curr_id',
703                                                     minChars : 2,
704                                                     valueField : 'curr_id',
705                                                     xtype : 'ComboBox',
706                                                     allowBlank : false,
707                                                     typeAhead : true,
708                                                     editable : false,
709                                                     width : 200,
710                                                     xns : Roo.form,
711                                                     name : 'curr_name',
712                                                     qtip : "Select Currency",
713                                                     queryParam : 'query[curr_name]',
714                                                     tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{curr_name}</b> </div>',
715                                                     loadingText : "Searching...",
716                                                     items : [
717
718                                                     ]
719
720                                                 },
721                                                 {
722                                                     '|xns' : 'Roo.form',
723                                                     fieldLabel : 'Value',
724                                                     xtype : 'NumberField',
725                                                     allowBlank : false,
726                                                     width : 200,
727                                                     xns : Roo.form,
728                                                     name : 'item_itemcost_id_itemcost_actcost'
729                                                 }
730                                             ]
731
732                                         }
733                                     ]
734
735                                 },
736                                 {
737                                     '|xns' : 'Roo.form',
738                                     xtype : 'Column',
739                                     xns : Roo.form,
740                                     items : [
741                                         {
742                                             '|xns' : 'Roo.form',
743                                             xtype : 'FieldSet',
744                                             legend : "Itemsite Settings",
745                                             xns : Roo.form,
746                                             style : 'width:335px;',
747                                             labelWidth : 120,
748                                             listeners : {
749                                                 render : function (_self)
750                                                    {
751                                                        _this.itemsiteFieldSet = _self;
752                                                    }
753                                             },
754                                             items : [
755                                                 {
756                                                     '|xns' : 'Roo.form',
757                                                     fieldLabel : 'Reorder Level',
758                                                     xtype : 'NumberField',
759                                                     allowBlank : false,
760                                                     width : 200,
761                                                     xns : Roo.form,
762                                                     name : 'item_itemsite_id_itemsite_reorderlevel'
763                                                 },
764                                                 {
765                                                     '|xns' : 'Roo.form',
766                                                     fieldLabel : 'Stock Safety Level',
767                                                     xtype : 'NumberField',
768                                                     allowBlank : false,
769                                                     width : 200,
770                                                     xns : Roo.form,
771                                                     name : 'item_itemsite_id_itemsite_safetystock'
772                                                 },
773                                                 {
774                                                     '|xns' : 'Roo.form',
775                                                     fieldLabel : 'Lead time (Days)',
776                                                     xtype : 'NumberField',
777                                                     allowBlank : false,
778                                                     width : 200,
779                                                     xns : Roo.form,
780                                                     name : 'item_itemsite_id_itemsite_leadtime'
781                                                 },
782                                                 {
783                                                     store : {
784                                                         '|xns' : 'Roo.data',
785                                                         xtype : 'SimpleStore',
786                                                         data : [ 
787                                                             [ 'N', "None"],
788                                                             [ 'R' , "Regular"]
789                                                         ],
790                                                         fields : [  'ftype', 'fname'],
791                                                         xns : Roo.data
792                                                     },
793                                                     '|xns' : 'Roo.form',
794                                                     listWidth : 200,
795                                                     triggerAction : 'all',
796                                                     fieldLabel : 'Control Method',
797                                                     displayField : 'fname',
798                                                     hiddenName : 'item_itemsite_id_itemsite_controlmethod',
799                                                     valueField : 'ftype',
800                                                     xtype : 'ComboBox',
801                                                     allowBlank : false,
802                                                     editable : false,
803                                                     width : 200,
804                                                     xns : Roo.form,
805                                                     mode : 'local',
806                                                     name : 'item_itemsite_id_itemsite_controlmethod_name',
807                                                     tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{fname}</b> </div>',
808                                                     items : [
809
810                                                     ]
811
812                                                 },
813                                                 {
814                                                     store : {
815                                                         proxy : {
816                                                             '|xns' : 'Roo.data',
817                                                             url : baseURL + '/Roo/plancode.php',
818                                                             method : 'GET',
819                                                             xtype : 'HttpProxy',
820                                                             xns : Roo.data
821                                                         },
822                                                         reader : {
823                                                             '|xns' : 'Roo.data',
824                                                             id : 'id',
825                                                             root : 'data',
826                                                             xtype : 'JsonReader',
827                                                             xns : Roo.data,
828                                                             fields : [{"name":"id","type":"int"},{"name":"plancode_code","type":"string"}],
829                                                             totalProperty : 'total'
830                                                         },
831                                                         '|xns' : 'Roo.data',
832                                                         xtype : 'Store',
833                                                         remoteSort : true,
834                                                         xns : Roo.data,
835                                                         sortInfo : { direction : 'ASC', field: 'id' },
836                                                         listeners : {
837                                                                 beforeload : function (_self, o){
838                                                                        o.params = o.params || {};
839                                                                        // set more here
840                                                                    }
841                                                         },
842                                                         items : [
843
844                                                         ]
845
846                                                     },
847                                                     '|xns' : 'Roo.form',
848                                                     listWidth : 400,
849                                                     triggerAction : 'all',
850                                                     fieldLabel : 'Planner Code',
851                                                     forceSelection : true,
852                                                     selectOnFocus : true,
853                                                     pageSize : 20,
854                                                     displayField : 'plancode_name',
855                                                     emptyText : "Select plancode",
856                                                     hiddenName : 'item_itemsite_id_itemsite_plancode_id',
857                                                     minChars : 2,
858                                                     valueField : 'plancode_id',
859                                                     xtype : 'ComboBox',
860                                                     allowBlank : false,
861                                                     typeAhead : true,
862                                                     editable : false,
863                                                     width : 200,
864                                                     xns : Roo.form,
865                                                     name : 'plancode_name',
866                                                     qtip : "Select plancode",
867                                                     queryParam : '',
868                                                     tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{plancode_name}</b> </div>',
869                                                     loadingText : "Searching...",
870                                                     items : [
871
872                                                     ]
873
874                                                 },
875                                                 {
876                                                     store : {
877                                                         proxy : {
878                                                             '|xns' : 'Roo.data',
879                                                             url : baseURL + '/Roo/costcat.php',
880                                                             method : 'GET',
881                                                             xtype : 'HttpProxy',
882                                                             xns : Roo.data
883                                                         },
884                                                         reader : {
885                                                             '|xns' : 'Roo.data',
886                                                             id : 'id',
887                                                             root : 'data',
888                                                             xtype : 'JsonReader',
889                                                             xns : Roo.data,
890                                                             fields : [{"name":"id","type":"int"},{"name":"costcat_code","type":"string"}],
891                                                             totalProperty : 'total'
892                                                         },
893                                                         '|xns' : 'Roo.data',
894                                                         xtype : 'Store',
895                                                         remoteSort : true,
896                                                         xns : Roo.data,
897                                                         sortInfo : { direction : 'ASC', field: 'id' },
898                                                         listeners : {
899                                                                 beforeload : function (_self, o){
900                                                                        o.params = o.params || {};
901                                                                        // set more here
902                                                                    }
903                                                         },
904                                                         items : [
905
906                                                         ]
907
908                                                     },
909                                                     '|xns' : 'Roo.form',
910                                                     listWidth : 400,
911                                                     triggerAction : 'all',
912                                                     fieldLabel : 'Costcat',
913                                                     forceSelection : true,
914                                                     selectOnFocus : true,
915                                                     pageSize : 20,
916                                                     displayField : 'costcat_code',
917                                                     emptyText : "Select costcat",
918                                                     hiddenName : 'item_itemsite_id_itemsite_costcat_id',
919                                                     minChars : 2,
920                                                     valueField : 'costcat_id',
921                                                     xtype : 'ComboBox',
922                                                     allowBlank : false,
923                                                     typeAhead : true,
924                                                     editable : false,
925                                                     width : 200,
926                                                     xns : Roo.form,
927                                                     name : 'costcat_code',
928                                                     qtip : "Select costcat",
929                                                     queryParam : '',
930                                                     tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{costcat_code}</b> </div>',
931                                                     loadingText : "Searching...",
932                                                     items : [
933
934                                                     ]
935
936                                                 },
937                                                 {
938                                                     '|xns' : 'Roo.form',
939                                                     fieldLabel : 'Active',
940                                                     inputValue : true,
941                                                     xtype : 'Checkbox',
942                                                     valueOff : 0,
943                                                     width : 75,
944                                                     xns : Roo.form,
945                                                     name : 'item_itemsite_id_itemsite_active'
946                                                 },
947                                                 {
948                                                     '|xns' : 'Roo.form',
949                                                     fieldLabel : 'Sold',
950                                                     inputValue : true,
951                                                     xtype : 'Checkbox',
952                                                     valueOff : 0,
953                                                     width : 75,
954                                                     xns : Roo.form,
955                                                     name : 'item_itemsite_id_itemsite_sold'
956                                                 },
957                                                 {
958                                                     '|xns' : 'Roo.form',
959                                                     fieldLabel : 'Stocked',
960                                                     inputValue : true,
961                                                     xtype : 'Checkbox',
962                                                     valueOff : 0,
963                                                     width : 75,
964                                                     xns : Roo.form,
965                                                     name : 'item_itemsite_id_itemsite_stocked'
966                                                 },
967                                                 {
968                                                     '|xns' : 'Roo.form',
969                                                     fieldLabel : 'Perishable',
970                                                     inputValue : true,
971                                                     xtype : 'Checkbox',
972                                                     valueOff : 0,
973                                                     width : 75,
974                                                     xns : Roo.form,
975                                                     name : 'item_itemsite_id_itemsite_perishable'
976                                                 },
977                                                 {
978                                                     '|xns' : 'Roo.form',
979                                                     fieldLabel : 'Multi Location',
980                                                     inputValue : true,
981                                                     xtype : 'Checkbox',
982                                                     valueOff : 0,
983                                                     width : 100,
984                                                     xns : Roo.form,
985                                                     name : 'item_itemsite_id_itemsite_loccntrl'
986                                                 },
987                                                 {
988                                                     store : {
989                                                         proxy : {
990                                                             '|xns' : 'Roo.data',
991                                                             url : baseURL + '/Roo/location.php',
992                                                             xtype : 'HttpProxy',
993                                                             method : 'GET',
994                                                             xns : Roo.data
995                                                         },
996                                                         reader : {
997                                                             '|xns' : 'Roo.data',
998                                                             id : 'location_id',
999                                                             root : 'data',
1000                                                             xtype : 'JsonReader',
1001                                                             fields : [{"name":"location_id","type":"int"},"location_name"],
1002                                                             xns : Roo.data,
1003                                                             totalProperty : 'total'
1004                                                         },
1005                                                         '|xns' : 'Roo.data',
1006                                                         xtype : 'Store',
1007                                                         remoteSort : true,
1008                                                         sortInfo : { direction : 'ASC', field: 'location_name' },
1009                                                         xns : Roo.data,
1010                                                         listeners : {
1011                                                                 beforeload : function (_self, o){
1012                                                                        o.params = o.params || {};
1013                                                                        // set more here
1014                                                                         o.params.location_netable = 1;
1015                                                                         o.params._notinternalcompany = 1;
1016                                                                         o.params.location_restrict = 0;
1017                                                                    }
1018                                                         },
1019                                                         items : [
1020
1021                                                         ]
1022
1023                                                     },
1024                                                     '|xns' : 'Roo.form',
1025                                                     listWidth : 400,
1026                                                     triggerAction : 'all',
1027                                                     fieldLabel : 'Default Location',
1028                                                     forceSelection : true,
1029                                                     selectOnFocus : true,
1030                                                     pageSize : 200,
1031                                                     displayField : 'location_name',
1032                                                     emptyText : "Default Location",
1033                                                     hiddenName : 'item_itemsite_id_itemsite_location_id',
1034                                                     minChars : 2,
1035                                                     valueField : 'location_id',
1036                                                     xtype : 'ComboBox',
1037                                                     allowBlank : false,
1038                                                     typeAhead : false,
1039                                                     editable : true,
1040                                                     width : 200,
1041                                                     xns : Roo.form,
1042                                                     name : 'location_name',
1043                                                     qtip : "Select terms",
1044                                                     queryParam : 'query[location_name]',
1045                                                     tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{location_name}</b> </div>',
1046                                                     loadingText : "Searching...",
1047                                                     items : [
1048
1049                                                     ]
1050
1051                                                 }
1052                                             ]
1053
1054                                         }
1055                                     ]
1056
1057                                 },
1058                                 {
1059                                     '|xns' : 'Roo.form',
1060                                     xtype : 'Hidden',
1061                                     width : 75,
1062                                     xns : Roo.form,
1063                                     name : 'item_id'
1064                                 }
1065                             ]
1066
1067                         }
1068                     ]
1069
1070                 },
1071                 {
1072                     grid : {
1073                         toolbar : {
1074                             '|xns' : 'Roo',
1075                             xtype : 'Toolbar',
1076                             xns : Roo,
1077                             items : [
1078                                 {
1079                                     store : {
1080                                         proxy : {
1081                                             '|xns' : 'Roo.data',
1082                                             url : baseURL + '/Roo/item.php',
1083                                             xtype : 'HttpProxy',
1084                                             method : 'GET',
1085                                             xns : Roo.data
1086                                         },
1087                                         reader : {
1088                                             '|xns' : 'Roo.data',
1089                                             id : 'id',
1090                                             root : 'data',
1091                                             xtype : 'JsonReader',
1092                                             fields : [
1093                                                 {"name":"id","type":"int"},
1094                                                 {"name":"item_number","type":"string"}
1095                                             ],
1096                                             xns : Roo.data,
1097                                             totalProperty : 'total'
1098                                         },
1099                                         '|xns' : 'Roo.data',
1100                                         xtype : 'Store',
1101                                         remoteSort : true,
1102                                         sortInfo : { direction : 'ASC', field: 'item_number' },
1103                                         xns : Roo.data,
1104                                         listeners : {
1105                                                 beforeload : function (_self, o){
1106                                                        o.params = o.params || {};
1107                                                        
1108                                                        o.params.item_active = 1;
1109                                                        o.params['!item_type'] = 'K';
1110                                                    }
1111                                         },
1112                                         items : [
1113
1114                                         ]
1115
1116                                     },
1117                                     '|xns' : 'Roo.bootstrap',
1118                                     alwaysQuery : true,
1119                                     triggerAction : 'all',
1120                                     fieldLabel : 'Item',
1121                                     forceSelection : true,
1122                                     selectOnFocus : true,
1123                                     pageSize : 20,
1124                                     displayField : 'item_number',
1125                                     emptyText : "Select item",
1126                                     minChars : 2,
1127                                     valueField : 'id',
1128                                     xtype : 'ComboBox',
1129                                     allowBlank : true,
1130                                     typeAhead : true,
1131                                     editable : true,
1132                                     width : 200,
1133                                     xns : Roo.bootstrap,
1134                                     qtip : "Select item",
1135                                     queryParam : 'query[number_or_name]',
1136                                     tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{item_number}</b> </div>',
1137                                     loadingText : "Searching...",
1138                                     listeners : {
1139                                         render : function (_self)
1140                                            {
1141                                                _this.partsBox = _self;
1142                                            },
1143                                         select : function (combo, record, index)
1144                                            {
1145                                                var item_id = _this.form.findField('item_id').getValue() * 1;
1146                                                
1147                                                if(typeof(record) == 'undefined' || !record || record.data.id * 1 < 1 || item_id < 1){
1148                                                    return;
1149                                                }
1150                                                
1151                                                var err = false;
1152                                            
1153                                                _this.partsgrid.ds.each(function(d){
1154                                                    if(record.data.item_id == d.data.bomitem_item_id){
1155                                                        err = true;
1156                                                    }
1157                                                });
1158                                            
1159                                                if(err){
1160                                                    Roo.MessageBox.alert('Error', record.data.item_number + ' already exists!');
1161                                                    _this.partsBox.reset();
1162                                                    return;
1163                                                }
1164                                                
1165                                                new Pman.Request({
1166                                                    url : baseURL + '/Roo/bomitem.php',
1167                                                    method : 'POST',
1168                                                    params : {
1169                                                        bomitem_parent_item_id : item_id,
1170                                                        bomitem_item_id : record.data.item_id,
1171                                                        bomitem_qtyper : 1
1172                                                    }, 
1173                                                    success : function(res) {
1174                                                        _this.partsBox.reset();
1175                                                        _this.partsgrid.footer.onClick('first');
1176                                                    }
1177                                                }); 
1178                                            }
1179                                     },
1180                                     items : [
1181
1182                                     ]
1183
1184                                 },
1185                                 {
1186                                     '|xns' : 'Roo.Toolbar',
1187                                     xtype : 'Fill',
1188                                     xns : Roo.Toolbar
1189                                 },
1190                                 {
1191                                     '|xns' : 'Roo',
1192                                     text : "Remove",
1193                                     xtype : 'Button',
1194                                     cls : 'x-btn-text-icon',
1195                                     icon : rootURL + '/Pman/templates/images/trash.gif',
1196                                     xns : Roo,
1197                                     listeners : {
1198                                         click : function ()
1199                                            {
1200                                                var sel = _this.partsgrid.getSelectionModel().getSelectedCell();
1201                                                
1202                                                if(!sel || !sel.length){
1203                                                    Roo.MessageBox.alert("Error", "Please select a item from below list");
1204                                                    return;
1205                                                }
1206                                                
1207                                                var d = _this.partsgrid.ds.getAt(sel[0]);      
1208                                              
1209                                                if(d.data.bomitem_id * 1 < 1){
1210                                                    Roo.MessageBox.alert("Error", "Invaild selection");
1211                                                    return;
1212                                                }
1213                                                
1214                                                new Pman.Request({
1215                                                    url : baseURL + '/Roo/bomitem.php',
1216                                                    method : 'POST',
1217                                                    params : {
1218                                                        _delete : d.data.bomitem_id
1219                                                    }, 
1220                                                    success : function(res) {
1221                                                        _this.partsgrid.footer.onClick('first');
1222                                                    }
1223                                                }); 
1224                                               
1225                                            }
1226                                     }
1227                                 }
1228                             ]
1229
1230                         },
1231                         dataSource : {
1232                             proxy : {
1233                                 '|xns' : 'Roo.data',
1234                                 url : baseURL + '/Roo/bomitem.php',
1235                                 method : 'GET',
1236                                 xtype : 'HttpProxy',
1237                                 xns : Roo.data
1238                             },
1239                             reader : {
1240                                 '|xns' : 'Roo.data',
1241                                 id : 'bom_id',
1242                                 root : 'data',
1243                                 xtype : 'JsonReader',
1244                                 fields : [
1245                                     {
1246                                         'name': 'bomitem_id',
1247                                         'type': 'int'
1248                                     }
1249                                 ],
1250                                 xns : Roo.data,
1251                                 totalProperty : 'total'
1252                             },
1253                             '|xns' : 'Roo.data',
1254                             xtype : 'Store',
1255                             remoteSort : true,
1256                             sortInfo : { field : 'bomitem_item_id_item_name', direction: 'ASC' },
1257                             xns : Roo.data,
1258                             listeners : {
1259                                 beforeload : function (_self, o)
1260                                    {
1261                                       o.params = o.params || {};
1262                                       
1263                                       var id  = _this.form.findField('item_id').getValue() * 1;
1264                                       if(id < 1){
1265                                            return false;
1266                                       }
1267                                       
1268                                       o.params.bom_parent_item_id = id;
1269                                    }
1270                             },
1271                             items : [
1272
1273                             ]
1274
1275                         },
1276                         footer : {
1277                             '|xns' : 'Roo',
1278                             pageSize : 50,
1279                             xtype : 'PagingToolbar',
1280                             emptyMsg : "Nothing found",
1281                             xns : Roo,
1282                             displayMsg : "Displaying parts {0} - {1} of {2}",
1283                             displayInfo : true
1284                         },
1285                         '|xns' : 'Roo.grid',
1286                         autoExpandColumn : 'bomitem_item_id_item_descrip1',
1287                         xtype : 'EditorGrid',
1288                         loadMask : true,
1289                         clicksToEdit : 1,
1290                         xns : Roo.grid,
1291                         colModel : [
1292                                  {
1293                                         '|xns' : 'Roo.grid',
1294                                         xtype : 'ColumnModel',
1295                                         width : 150,
1296                                         header : 'Name',
1297                                         renderer : function(v) { return String.format('{0}', v); },
1298                                         xns : Roo.grid,
1299                                         dataIndex : 'bomitem_item_id_item_number'
1300                                     },
1301 {
1302                                         '|xns' : 'Roo.grid',
1303                                         xtype : 'ColumnModel',
1304                                         width : 150,
1305                                         header : 'Description',
1306                                         renderer : function(v) { return String.format('{0}', v); },
1307                                         xns : Roo.grid,
1308                                         dataIndex : 'bomitem_item_id_item_descrip1'
1309                                     },
1310 {
1311                                         editor : {
1312                                             field : {
1313                                                 '|xns' : 'Roo.form',
1314                                                 allowBlank : false,
1315                                                 cls : 'align-right',
1316                                                 xtype : 'NumberField',
1317                                                 decimalPrecision : 0,
1318                                                 xns : Roo.form,
1319                                                 minValue : 0
1320                                             },
1321                                             '|xns' : 'Roo.grid',
1322                                             xtype : 'GridEditor',
1323                                             xns : Roo.grid,
1324                                             items : [
1325
1326                                             ]
1327
1328                                         },
1329                                         '|xns' : 'Roo.grid',
1330                                         xtype : 'ColumnModel',
1331                                         align : 'right',
1332                                         header : 'Qty',
1333                                         width : 100,
1334                                         renderer : function(v) { return String.format('{0}', v); },
1335                                         xns : Roo.grid,
1336                                         dataIndex : 'bomitem_qtyper',
1337                                         items : [
1338
1339                                         ]
1340
1341                                     }
1342                         ],
1343                         listeners : {
1344                                 beforeedit : function (e)
1345                                    {
1346                                        if(e.field != 'bomitem_qtyper'){
1347                                            return false;
1348                                        }
1349                                        
1350                                    },
1351                                 render : function() 
1352                                    {
1353                                        _this.partsgrid = this; 
1354                                        //_this.dialog = Pman.Dialog.FILL_IN
1355                                        if (_this.partspanel.active) {
1356                                           this.footer.onClick('first');
1357                                        }
1358                                    },
1359                                 afteredit : function (e)
1360                                    {
1361                                        if(e.originalValue == e.value){
1362                                            return false;
1363                                        }
1364                                        
1365                                        
1366                                        new Pman.Request({
1367                                            method : 'POST',
1368                                            url : baseURL + '/Roo/bomitem.php',
1369                                            mask : 'Saving',
1370                                            params : {
1371                                                bomitem_id : e.record.data.bomitem_id,
1372                                                bomitem_qtyper : e.value
1373                                            },
1374                                            success : function() {
1375                                                e.record.set('bomitem_qtyper', e.value);
1376                                            }
1377                                        
1378                                        });
1379                                            
1380                                             
1381                                            
1382                                            
1383                                    }
1384                         },
1385                         items : [
1386
1387                         ]
1388
1389                     },
1390                     '|xns' : 'Roo',
1391                     region : 'center',
1392                     fitToframe : true,
1393                     background : true,
1394                     title : "Item Parts",
1395                     xtype : 'GridPanel',
1396                     fitContainer : true,
1397                     xns : Roo,
1398                     tableName : 'bomitem',
1399                     listeners : {
1400                         activate : function() {
1401                                _this.partspanel = this;
1402                                
1403                                try { if (MODULE.isBuilder) {
1404                                    return;
1405                                } } catch(e) { }
1406                                
1407                                var id = _this.form.findField('item_id').getValue() * 1;
1408                                if (id < 1) {
1409                                    Roo.MessageBox.alert("Save First", "Save the item first, before adding parts");
1410                                    _this.dialog.layout.getRegion('center').showPanel(0);
1411                                    return;
1412                                }
1413                                
1414                                var type = _this.form.findField('item_type').getValue();
1415                                
1416                                if(!type.length || type != 'K'){
1417                                    Roo.MessageBox.alert("Error", "Can't add parts to non-kit item");
1418                                    _this.dialog.layout.getRegion('center').showPanel(0);
1419                                    return;
1420                                }
1421                                
1422                                if (_this.partsgrid) {
1423                                    _this.partsgrid.footer.onClick('first');
1424                                
1425                                 }
1426                            }
1427                     },
1428                     items : [
1429
1430                     ]
1431
1432                 },
1433                 {
1434                     grid : {
1435                         dataSource : {
1436                             reader : {
1437                                 '|xns' : 'Roo.data',
1438                                 id : 'id',
1439                                 root : 'data',
1440                                 xtype : 'JsonReader',
1441                                 fields : [
1442                                     {
1443                                         'name': 'id',
1444                                         'type': 'int'
1445                                     },
1446                                     {
1447                                         'name': 'filename',
1448                                         'type': 'string'
1449                                     },
1450                                     {
1451                                         'name': 'ontable',
1452                                         'type': 'string'
1453                                     },
1454                                     {
1455                                         'name': 'onid',
1456                                         'type': 'int'
1457                                     },
1458                                     {
1459                                         'name': 'mimetype',
1460                                         'type': 'string'
1461                                     },
1462                                     {
1463                                         'name': 'width',
1464                                         'type': 'int'
1465                                     },
1466                                     {
1467                                         'name': 'height',
1468                                         'type': 'int'
1469                                     },
1470                                     {
1471                                         'name': 'filesize',
1472                                         'type': 'int'
1473                                     },
1474                                     {
1475                                         'name': 'displayorder',
1476                                         'type': 'int'
1477                                     },
1478                                     {
1479                                         'name': 'language',
1480                                         'type': 'string'
1481                                     },
1482                                     {
1483                                         'name': 'parent_image_id',
1484                                         'type': 'int'
1485                                     },
1486                                     {
1487                                         'name': 'created',
1488                                         'type': 'date',
1489                                         'dateFormat' : 'Y-m-d H:i:s'
1490                                     },
1491                                     {
1492                                         'name': 'imgtype',
1493                                         'type': 'string'
1494                                     },
1495                                     {
1496                                         'name': 'linkurl',
1497                                         'type': 'string'
1498                                     },
1499                                     {
1500                                         'name': 'descript',
1501                                         'type': 'string'
1502                                     },
1503                                     {
1504                                         'name': 'title',
1505                                         'type': 'string'
1506                                     }
1507                                 ],
1508                                 xns : Roo.data,
1509                                 totalProperty : 'total'
1510                             },
1511                             proxy : {
1512                                 '|xns' : 'Roo.data',
1513                                 url : baseURL + '/Roo/Images.php',
1514                                 method : 'GET',
1515                                 xtype : 'HttpProxy',
1516                                 xns : Roo.data
1517                             },
1518                             '|xns' : 'Roo.data',
1519                             xtype : 'Store',
1520                             remoteSort : true,
1521                             sortInfo : { field: 'created' , direction: 'DESC' },
1522                             xns : Roo.data,
1523                             listeners : {
1524                                 beforeload : function (_self, o)
1525                                    {
1526                                        o.params = o.params || {};
1527                                        
1528                                        var id = _this.form.findField('item_id').getValue();
1529                                        
1530                                        if(id * 1 < 1){
1531                                            return false;
1532                                        }
1533                                        
1534                                        o.params.onid = id;
1535                                        o.params.ontable = 'item';
1536                                        
1537                                    }
1538                             },
1539                             items : [
1540
1541                             ]
1542
1543                         },
1544                         footer : {
1545                             '|xns' : 'Roo',
1546                             pageSize : 25,
1547                             xtype : 'PagingToolbar',
1548                             emptyMsg : "No Images found",
1549                             xns : Roo,
1550                             displayInfo : true,
1551                             displayMsg : "Displaying Images  {0} - {1} of {2}"
1552                         },
1553                         toolbar : {
1554                             '|xns' : 'Roo',
1555                             xtype : 'Toolbar',
1556                             xns : Roo,
1557                             items : [
1558                                 {
1559                                     '|xns' : 'Roo.Toolbar',
1560                                     text : "Add",
1561                                     xtype : 'Button',
1562                                     cls : 'x-btn-text-icon',
1563                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
1564                                     xns : Roo.Toolbar,
1565                                     listeners : {
1566                                         click : function()
1567                                            {
1568                                                Pman.Dialog.Image.show({
1569                                                    id : 0, 
1570                                                    ontable: 'item',
1571                                                    onid: _this.form.findField('item_id').getValue() * 1,
1572                                                    imgtype : ''
1573                                                }, function(data){
1574                                                    if (!data) { return; } 
1575                                                    _this.grid.footer.onClick('first');
1576                                                }); 
1577                                            
1578                                            }
1579                                     }
1580                                 },
1581                                 {
1582                                     '|xns' : 'Roo.Toolbar',
1583                                     text : "Delete",
1584                                     xtype : 'Button',
1585                                     cls : 'x-btn-text-icon',
1586                                     icon : rootURL + '/Pman/templates/images/trash.gif',
1587                                     xns : Roo.Toolbar,
1588                                     listeners : {
1589                                         click : function()
1590                                            {
1591                                                Pman.genericDelete(_this, 'Images'); 
1592                                            }
1593                                     }
1594                                 }
1595                             ]
1596
1597                         },
1598                         '|xns' : 'Roo.grid',
1599                         autoExpandColumn : 'id',
1600                         xtype : 'Grid',
1601                         loadMask : true,
1602                         xns : Roo.grid,
1603                         colModel : [
1604                                  {
1605                                         '|xns' : 'Roo.grid',
1606                                         xtype : 'ColumnModel',
1607                                         sortable : true,
1608                                         header : 'Created',
1609                                         width : 200,
1610                                         renderer : function(v,x,r) {
1611                                                return String.format('{0}<br/><i>{1}</i><br/>{2}<br/><i>{3}x{4}</i>',
1612                                                     v.format('d/M/Y'), r.data.mimetype, r.data.filename,
1613                                             r.data.width, r.data.height
1614                                             ); 
1615                                         },
1616                                         xns : Roo.grid,
1617                                         dataIndex : 'created'
1618                                     },
1619 {
1620                                         '|xns' : 'Roo.grid',
1621                                         xtype : 'ColumnModel',
1622                                         header : 'Image',
1623                                         width : 100,
1624                                         renderer : function(v,x,r) { return String.format('<img src="{0}/Images/Thumb/100/{1}/{2}" height="100">', baseURL, v, r.data.filename); },
1625                                         xns : Roo.grid,
1626                                         dataIndex : 'id'
1627                                     }
1628                         ],
1629                         listeners : {
1630                                 rowdblclick : function (_self, rowIndex, e)
1631                                    {
1632                                      
1633                                       var s =  _self.getDataSource().getAt(rowIndex);
1634                                       new Pman.Download({
1635                                            url : baseURL + '/Images/Download/' + s.data.id
1636                                        });
1637                                       
1638                                    },
1639                                 render : function() { 
1640                                        _this.grid = this; 
1641                                    
1642                                        if (_this.panel.active) {
1643                                           this.footer.onClick('first');
1644                                        }
1645                                    }
1646                         },
1647                         items : [
1648
1649                         ]
1650
1651                     },
1652                     '|xns' : 'Roo',
1653                     fitToframe : true,
1654                     background : true,
1655                     region : 'center',
1656                     title : "Reference Files",
1657                     xtype : 'GridPanel',
1658                     fitContainer : true,
1659                     xns : Roo,
1660                     tableName : 'Images',
1661                     listeners : {
1662                         activate : function() {
1663                                _this.panel = this;
1664                                
1665                                try { if (MODULE.isBuilder) {
1666                                    return;
1667                                } } catch(e) { }
1668                                
1669                                var id = _this.form.findField('item_id').getValue() * 1;
1670                                if (id < 1) {
1671                                    Roo.MessageBox.alert("Save First", "Save the item first, before adding image");
1672                                    _this.dialog.layout.getRegion('center').showPanel(0);
1673                                    return;
1674                                }
1675                                
1676                                if (_this.grid) {
1677                                    _this.grid.footer.onClick('first');
1678                                
1679                                 }
1680                            }
1681                     },
1682                     items : [
1683
1684                     ]
1685
1686                 },
1687                 {
1688                     grid : {
1689                         dataSource : {
1690                             proxy : {
1691                                 '|xns' : 'Roo.data',
1692                                 url : baseURL + '/Roo/ipshead.php',
1693                                 xtype : 'HttpProxy',
1694                                 method : 'GET',
1695                                 xns : Roo.data
1696                             },
1697                             reader : {
1698                                 '|xns' : 'Roo.data',
1699                                 id : 'ipshead_id',
1700                                 root : 'data',
1701                                 xtype : 'JsonReader',
1702                                 fields : [
1703                                     {
1704                                         'name': 'ipshead_id',
1705                                         'type': 'int'
1706                                     },
1707                                     {
1708                                         'name': 'ipshead_name',
1709                                         'type': 'string'
1710                                     }
1711                                 ],
1712                                 xns : Roo.data,
1713                                 totalProperty : 'total'
1714                             },
1715                             '|xns' : 'Roo.data',
1716                             xtype : 'Store',
1717                             remoteSort : true,
1718                             sortInfo : { field : 'ipshead_id', direction: 'ASC' },
1719                             xns : Roo.data,
1720                             listeners : {
1721                                 beforeload : function (_self, o)
1722                                    {
1723                                       o.params = o.params || {};
1724                                       
1725                                       var id  = _this.form.findField('item_id').getValue() * 1;
1726                                       if(id < 1){
1727                                            return false;
1728                                       }
1729                                       
1730                                       o.params._with_item = id;
1731                                    }
1732                             },
1733                             items : [
1734
1735                             ]
1736
1737                         },
1738                         footer : {
1739                             '|xns' : 'Roo',
1740                             pageSize : 50,
1741                             xtype : 'PagingToolbar',
1742                             emptyMsg : "Nothing found",
1743                             xns : Roo,
1744                             displayMsg : "Displaying records {0} - {1} of {2}",
1745                             displayInfo : true
1746                         },
1747                         '|xns' : 'Roo.grid',
1748                         autoExpandColumn : 'ipshead_descrip',
1749                         xtype : 'EditorGrid',
1750                         loadMask : true,
1751                         clicksToEdit : 1,
1752                         xns : Roo.grid,
1753                         colModel : [
1754                                  {
1755                                         '|xns' : 'Roo.grid',
1756                                         xtype : 'ColumnModel',
1757                                         header : 'Name',
1758                                         width : 150,
1759                                         renderer : function(v) { return String.format('{0}', v); },
1760                                         xns : Roo.grid,
1761                                         dataIndex : 'ipshead_name'
1762                                     },
1763 {
1764                                         '|xns' : 'Roo.grid',
1765                                         xtype : 'ColumnModel',
1766                                         header : 'Description',
1767                                         width : 150,
1768                                         renderer : function(v) { return String.format('{0}', v); },
1769                                         xns : Roo.grid,
1770                                         dataIndex : 'ipshead_descrip'
1771                                     },
1772 {
1773                                         '|xns' : 'Roo.grid',
1774                                         xtype : 'ColumnModel',
1775                                         header : 'Currency',
1776                                         width : 100,
1777                                         renderer : function(v) { return String.format('{0}', v); },
1778                                         xns : Roo.grid,
1779                                         dataIndex : 'ipshead_curr_id_curr_name'
1780                                     },
1781 {
1782                                         editor : {
1783                                             field : {
1784                                                 '|xns' : 'Roo.form',
1785                                                 xtype : 'NumberField',
1786                                                 cls : 'align-right',
1787                                                 decimalPrecision : 2,
1788                                                 xns : Roo.form
1789                                             },
1790                                             '|xns' : 'Roo.grid',
1791                                             xtype : 'GridEditor',
1792                                             xns : Roo.grid,
1793                                             items : [
1794
1795                                             ]
1796
1797                                         },
1798                                         '|xns' : 'Roo.grid',
1799                                         align : 'right',
1800                                         xtype : 'ColumnModel',
1801                                         header : 'Price',
1802                                         width : 120,
1803                                         renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v*1,2)); },
1804                                         xns : Roo.grid,
1805                                         dataIndex : 'ipshead_ipsitem_price',
1806                                         items : [
1807
1808                                         ]
1809
1810                                     }
1811                         ],
1812                         listeners : {
1813                                 beforeedit : function (e)
1814                                    {
1815                                        if(e.field != 'ipshead_ipsitem_price'){
1816                                            return false;
1817                                        }
1818                                        
1819                                    },
1820                                 render : function() 
1821                                    {
1822                                        _this.lgrid = this; 
1823                                        //_this.dialog = Pman.Dialog.FILL_IN
1824                                        if (_this.lpanel.active) {
1825                                           this.footer.onClick('first');
1826                                        }
1827                                    },
1828                                 afteredit : function (e)
1829                                    {
1830                                        if(e.originalValue == e.value){
1831                                            return false;
1832                                        }
1833                                        
1834                                        var id = _this.form.findField('item_id').getValue() * 1;
1835                                        if(id < 1){
1836                                            return false;
1837                                        }
1838                                        
1839                                        new Pman.Request({
1840                                            method : 'POST',
1841                                            url : baseURL + '/Roo/ipsiteminfo',
1842                                            mask : 'Saving',
1843                                            params : {
1844                                                ipsitem_ipshead_id : e.record.data.ipshead_id,
1845                                                ipsitem_item_id : id,
1846                                                ipsitem_price : e.record.data.ipshead_ipsitem_price,
1847                                                ipsitem_id : e.record.data.ipshead_ipsitem_id
1848                                            }
1849                                        
1850                                        });
1851                                            
1852                                             
1853                                            
1854                                            
1855                                    }
1856                         },
1857                         items : [
1858
1859                         ]
1860
1861                     },
1862                     '|xns' : 'Roo',
1863                     fitToframe : true,
1864                     background : true,
1865                     region : 'center',
1866                     title : "Price List",
1867                     xtype : 'GridPanel',
1868                     fitContainer : true,
1869                     xns : Roo,
1870                     tableName : 'ipshead',
1871                     listeners : {
1872                         activate : function() {
1873                                _this.lpanel = this;
1874                                
1875                                try { if (MODULE.isBuilder) {
1876                                    return;
1877                                } } catch(e) { }
1878                                
1879                                var id = _this.form.findField('item_id').getValue() * 1;
1880                                if (id < 1) {
1881                                    Roo.MessageBox.alert("Save First", "Save the item first, before adding image");
1882                                    _this.dialog.layout.getRegion('center').showPanel(0);
1883                                    return;
1884                                }
1885                                
1886                                if (_this.lgrid) {
1887                                    _this.lgrid.footer.onClick('first');
1888                                
1889                                 }
1890                            }
1891                     },
1892                     items : [
1893
1894                     ]
1895
1896                 },
1897                 {
1898                     grid : {
1899                         dataSource : {
1900                             proxy : {
1901                                 '|xns' : 'Roo.data',
1902                                 url : baseURL + '/Roo/itemsrc.php',
1903                                 method : 'GET',
1904                                 xtype : 'HttpProxy',
1905                                 xns : Roo.data
1906                             },
1907                             reader : {
1908                                 '|xns' : 'Roo.data',
1909                                 id : 'id',
1910                                 root : 'data',
1911                                 xtype : 'JsonReader',
1912                                 xns : Roo.data,
1913                                 fields : [
1914                                     {
1915                                         'name': 'itemsrc_id',
1916                                         'type': 'int'
1917                                     },
1918                                     {
1919                                         'name': 'itemsrc_item_id',
1920                                         'type': 'int'
1921                                     },
1922                                     {
1923                                         'name': 'itemsrc_item_id',
1924                                         'type': 'int'
1925                                     },
1926                                     {
1927                                         'name': 'itemsrc_vend_id',
1928                                         'type': 'int'
1929                                     },
1930                                     {
1931                                         'name': 'itemsrc_vend_id',
1932                                         'type': 'int'
1933                                     },
1934                                     {
1935                                         'name': 'itemsrc_vend_item_number',
1936                                         'type': 'string'
1937                                     },
1938                                     {
1939                                         'name': 'itemsrc_vend_item_descrip',
1940                                         'type': 'string'
1941                                     },
1942                                     {
1943                                         'name': 'itemsrc_comments',
1944                                         'type': 'string'
1945                                     },
1946                                     {
1947                                         'name': 'itemsrc_vend_uom',
1948                                         'type': 'string'
1949                                     },
1950                                     {
1951                                         'name': 'itemsrc_invvendoruomratio',
1952                                         'type': 'float'
1953                                     },
1954                                     {
1955                                         'name': 'itemsrc_minordqty',
1956                                         'type': 'float'
1957                                     },
1958                                     {
1959                                         'name': 'itemsrc_multordqty',
1960                                         'type': 'float'
1961                                     },
1962                                     {
1963                                         'name': 'itemsrc_leadtime',
1964                                         'type': 'int'
1965                                     },
1966                                     {
1967                                         'name': 'itemsrc_ranking',
1968                                         'type': 'int'
1969                                     },
1970                                     {
1971                                         'name': 'itemsrc_active',
1972                                         'type': 'int'
1973                                     },
1974                                     {
1975                                         'name': 'itemsrc_manuf_name',
1976                                         'type': 'string'
1977                                     },
1978                                     {
1979                                         'name': 'itemsrc_manuf_item_number',
1980                                         'type': 'string'
1981                                     },
1982                                     {
1983                                         'name': 'itemsrc_manuf_item_descrip',
1984                                         'type': 'string'
1985                                     },
1986                                     {
1987                                         'name': 'itemsrc_default',
1988                                         'type': 'int'
1989                                     },
1990                                     {
1991                                         'name': 'itemsrc_upccode',
1992                                         'type': 'string'
1993                                     }
1994                                 ],
1995                                 totalProperty : 'total'
1996                             },
1997                             '|xns' : 'Roo.data',
1998                             xtype : 'Store',
1999                             remoteSort : true,
2000                             sortInfo : { field : 'itemsrc_vend_id_vend_name', direction: 'ASC' },
2001                             xns : Roo.data,
2002                             listeners : {
2003                                 update : function (_self, record, operation)
2004                                    {
2005                                        Roo.log(operation);
2006                                          Roo.log(record);
2007                                       
2008                                        if (operation != 'commit') {
2009                                            return;
2010                                        }
2011                                        if (record.data.itemsrc_vend_id * 1 < 1) {
2012                                            return; // do not save.
2013                                        }
2014                                        if (record.data.itemsrc_id * 1 < 0) {
2015                                            return; // do not save. -- updating at present...
2016                                        }
2017                                        
2018                                        var p = Roo.apply({}, record.data);
2019                                        record.set('itemsrc_id', -1);    
2020                                        
2021                                        new Pman.Request({
2022                                            url : baseURL + '/Roo/Itemsrc',
2023                                            params : p,
2024                                            method : 'POST',
2025                                            success: function(res) {
2026                                                if (record.data.itemsrc_id *1  < 1) { 
2027                                                    record.set('itemsrc_id', res.data.itemsrc_id);
2028                                                }
2029                                            }
2030                                        });
2031                                        
2032                                        
2033                                    },
2034                                 beforeload : function (_self, o)
2035                                    {
2036                                        
2037                                        var id = 1 * _this.form.findField('item_id').getValue();
2038                                        if (!id) {
2039                                            this.removeAll();
2040                                            return false;
2041                                        }
2042                                        o.params.itemsrc_item_id = id;
2043                                    }
2044                             },
2045                             items : [
2046
2047                             ]
2048
2049                         },
2050                         footer : {
2051                             '|xns' : 'Roo',
2052                             pageSize : 25,
2053                             xtype : 'PagingToolbar',
2054                             emptyMsg : "No itemsrc found",
2055                             xns : Roo,
2056                             displayInfo : true,
2057                             displayMsg : "Displaying itemsrc{0} - {1} of {2}"
2058                         },
2059                         toolbar : {
2060                             '|xns' : 'Roo',
2061                             xtype : 'Toolbar',
2062                             xns : Roo,
2063                             items : [
2064                                 {
2065                                     '|xns' : 'Roo.Toolbar',
2066                                     text : "Add",
2067                                     xtype : 'Button',
2068                                     cls : 'x-btn-text-icon',
2069                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
2070                                     xns : Roo.Toolbar,
2071                                     listeners : {
2072                                         click : function()
2073                                            {
2074                                                 
2075                                                Roo.log("add presed");
2076                                                 
2077                                                // work out last 
2078                                                var grid = _this.itemsrcgrid;
2079                                                 
2080                                                // uses form defaults or last row value.
2081                                                var nr = grid.ds.reader.newRow({
2082                                                     itemsrc_id : 0,
2083                                                     itemsrc_item_id : _this.form.findField('item_id').getValue(),
2084                                                     itemsrc_vend_id : 0,
2085                                                     itemsrc_vend_id_vend_name : '',
2086                                                     itemsrc_vend_item_number : '',
2087                                                     itemsrc_vend_item_descrip : '',
2088                                                     itemsrc_comments           : '',
2089                                                     itemsrc_vend_uom  :           'EA',
2090                                                     itemsrc_invvendoruomratio : 1.0,
2091                                                     itemsrc_minordqty        : 0,
2092                                                     itemsrc_multordqty        : 0,
2093                                                     itemsrc_leadtime         :  30,
2094                                                     itemsrc_ranking         :   0,
2095                                                     itemsrc_active          :   true,
2096                                                     itemsrc_manuf_name       :  '',
2097                                                     itemsrc_manuf_item_number : '',
2098                                                     itemsrc_manuf_item_descrip: '',
2099                                                     itemsrc_default          : true,
2100                                                     itemsrc_upccode    : ''
2101                                                                    
2102                                                });
2103                                                grid.stopEditing();
2104                                                grid.ds.insert(0, nr); 
2105                                                grid.startEditing(0, 0); // type..
2106                                            
2107                                            }
2108                                     }
2109                                 }
2110                             ]
2111
2112                         },
2113                         '|xns' : 'Roo.grid',
2114                         autoExpandColumn : 'itemsrc_comments',
2115                         xtype : 'EditorGrid',
2116                         loadMask : true,
2117                         clicksToEdit : 1,
2118                         xns : Roo.grid,
2119                         colModel : [
2120                                  {
2121                                         editor : {
2122                                             field : {
2123                                                 store : {
2124                                                     proxy : {
2125                                                         '|xns' : 'Roo.data',
2126                                                         url : baseURL + '/Roo/vendinfo.php',
2127                                                         method : 'GET',
2128                                                         xtype : 'HttpProxy',
2129                                                         xns : Roo.data
2130                                                     },
2131                                                     reader : {
2132                                                         '|xns' : 'Roo.data',
2133                                                         id : 'id',
2134                                                         root : 'data',
2135                                                         xtype : 'JsonReader',
2136                                                         xns : Roo.data,
2137                                                         fields : [{"name":"id","type":"int"},{"name":"vend_name","type":"string"}],
2138                                                         totalProperty : 'total'
2139                                                     },
2140                                                     '|xns' : 'Roo.data',
2141                                                     xtype : 'Store',
2142                                                     remoteSort : true,
2143                                                     xns : Roo.data,
2144                                                     sortInfo : { direction : 'ASC', field: 'id' },
2145                                                     listeners : {
2146                                                         beforeload : function (_self, o){
2147                                                                o.params = o.params || {};
2148                                                                // set more here
2149                                                            }
2150                                                     },
2151                                                     items : [
2152
2153                                                     ]
2154
2155                                                 },
2156                                                 '|xns' : 'Roo.form',
2157                                                 listWidth : 400,
2158                                                 triggerAction : 'all',
2159                                                 forceSelection : true,
2160                                                 selectOnFocus : true,
2161                                                 pageSize : 20,
2162                                                 displayField : 'vend_name',
2163                                                 emptyText : "Select Vendor",
2164                                                 hiddenName : 'itemsrc_vend_id',
2165                                                 minChars : 2,
2166                                                 valueField : 'vend_id',
2167                                                 xtype : 'ComboBox',
2168                                                 allowBlank : false,
2169                                                 typeAhead : true,
2170                                                 editable : true,
2171                                                 width : 300,
2172                                                 xns : Roo.form,
2173                                                 name : 'itemsrc_vend_id_vend_name',
2174                                                 qtip : "Select vendinfo",
2175                                                 queryParam : 'q[search]',
2176                                                 tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{vend_name}</b> </div>',
2177                                                 loadingText : "Searching...",
2178                                                 items : [
2179
2180                                                 ]
2181
2182                                             },
2183                                             '|xns' : 'Roo.grid',
2184                                             xtype : 'GridEditor',
2185                                             xns : Roo.grid,
2186                                             items : [
2187
2188                                             ]
2189
2190                                         },
2191                                         '|xns' : 'Roo.grid',
2192                                         xtype : 'ColumnModel',
2193                                         header : 'Vendor',
2194                                         width : 120,
2195                                         renderer : function(v,x,r) { return String.format('{0}', r.data.itemsrc_vend_id_vend_name); },
2196                                         xns : Roo.grid,
2197                                         dataIndex : 'itemsrc_vend_id',
2198                                         items : [
2199
2200                                         ]
2201
2202                                     },
2203 {
2204                                         editor : {
2205                                             field : {
2206                                                 '|xns' : 'Roo.form',
2207                                                 xtype : 'TextField',
2208                                                 xns : Roo.form
2209                                             },
2210                                             '|xns' : 'Roo.grid',
2211                                             xtype : 'GridEditor',
2212                                             xns : Roo.grid,
2213                                             items : [
2214
2215                                             ]
2216
2217                                         },
2218                                         '|xns' : 'Roo.grid',
2219                                         xtype : 'ColumnModel',
2220                                         header : 'Vendor Ref#',
2221                                         width : 100,
2222                                         renderer : function(v) { return String.format('{0}', v); },
2223                                         xns : Roo.grid,
2224                                         dataIndex : 'itemsrc_vend_item_number',
2225                                         items : [
2226
2227                                         ]
2228
2229                                     },
2230 {
2231                                         editor : {
2232                                             field : {
2233                                                 '|xns' : 'Roo.form',
2234                                                 xtype : 'TextField',
2235                                                 xns : Roo.form
2236                                             },
2237                                             '|xns' : 'Roo.grid',
2238                                             xtype : 'GridEditor',
2239                                             xns : Roo.grid,
2240                                             items : [
2241
2242                                             ]
2243
2244                                         },
2245                                         '|xns' : 'Roo.grid',
2246                                         xtype : 'ColumnModel',
2247                                         header : 'Comments',
2248                                         width : 200,
2249                                         renderer : function(v) { return String.format('{0}', v); },
2250                                         xns : Roo.grid,
2251                                         dataIndex : 'itemsrc_comments',
2252                                         items : [
2253
2254                                         ]
2255
2256                                     },
2257 {
2258                                         '|xns' : 'Roo.grid',
2259                                         xtype : 'ColumnModel',
2260                                         header : 'UOM',
2261                                         width : 50,
2262                                         renderer : function(v) { return String.format('{0}', v); },
2263                                         xns : Roo.grid,
2264                                         dataIndex : 'itemsrc_vend_uom'
2265                                     },
2266 {
2267                                         editor : {
2268                                             field : {
2269                                                 '|xns' : 'Roo.form',
2270                                                 minValue : 0,
2271                                                 xtype : 'NumberField',
2272                                                 decimalPrecision : 0,
2273                                                 xns : Roo.form
2274                                             },
2275                                             '|xns' : 'Roo.grid',
2276                                             xtype : 'GridEditor',
2277                                             xns : Roo.grid,
2278                                             items : [
2279
2280                                             ]
2281
2282                                         },
2283                                         '|xns' : 'Roo.grid',
2284                                         align : 'right',
2285                                         xtype : 'ColumnModel',
2286                                         header : 'Min Qty',
2287                                         width : 50,
2288                                         renderer : function(v) { return String.format('{0}', v); },
2289                                         xns : Roo.grid,
2290                                         dataIndex : 'itemsrc_minordqty',
2291                                         items : [
2292
2293                                         ]
2294
2295                                     },
2296 {
2297                                         editor : {
2298                                             field : {
2299                                                 '|xns' : 'Roo.form',
2300                                                 minValue : 0,
2301                                                 xtype : 'NumberField',
2302                                                 decimalPrecision : 0,
2303                                                 xns : Roo.form
2304                                             },
2305                                             '|xns' : 'Roo.grid',
2306                                             xtype : 'GridEditor',
2307                                             xns : Roo.grid,
2308                                             items : [
2309
2310                                             ]
2311
2312                                         },
2313                                         '|xns' : 'Roo.grid',
2314                                         align : 'right',
2315                                         xtype : 'ColumnModel',
2316                                         header : 'Lead time',
2317                                         width : 75,
2318                                         renderer : function(v) { return String.format('{0}', v); },
2319                                         xns : Roo.grid,
2320                                         dataIndex : 'itemsrc_leadtime',
2321                                         items : [
2322
2323                                         ]
2324
2325                                     },
2326 {
2327                                         '|xns' : 'Roo.grid',
2328                                         xtype : 'ColumnModel',
2329                                         header : 'Active',
2330                                         width : 50,
2331                                         renderer : function(v) { return String.format('{0}', v); },
2332                                         xns : Roo.grid,
2333                                         dataIndex : 'itemsrc_active'
2334                                     }
2335                         ],
2336                         listeners : {
2337                                 rowdblclick : function (_self, rowIndex, e)
2338                                    {
2339                                        if (!_this.dialog) return;
2340                                        _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
2341                                            _this.grid.footer.onClick('first');
2342                                        }); 
2343                                    },
2344                                 render : function() 
2345                                    {
2346                                        _this.itemsrcgrid = this; 
2347                                        
2348                                        if (_this.itemsrcpanel.active) {
2349                                           this.footer.onClick('first');
2350                                        }
2351                                    },
2352                                 afteredit : function (e)
2353                                    {
2354                                        e.record.commit();
2355                                    }
2356                         },
2357                         items : [
2358
2359                         ]
2360
2361                     },
2362                     '|xns' : 'Roo',
2363                     fitToframe : true,
2364                     background : true,
2365                     region : 'center',
2366                     title : "Suppliers",
2367                     xtype : 'GridPanel',
2368                     fitContainer : true,
2369                     xns : Roo,
2370                     tableName : 'itemsrc',
2371                     listeners : {
2372                         activate : function() {
2373                                _this.itemsrcpanel = this;
2374                                
2375                                try { if (MODULE.isBuilder) {
2376                                    return;
2377                                } } catch(e) { }
2378                                
2379                                var id = _this.form.findField('item_id').getValue() * 1;
2380                                if (id < 1) {
2381                                    Roo.MessageBox.alert("Save First", "Save the item first, before adding suppliers");
2382                                    _this.dialog.layout.getRegion('center').showPanel(0);
2383                                    return false;
2384                                }
2385                                
2386                                var type = _this.form.findField('item_type').getValue();
2387                                
2388                                if(type == 'K'){
2389                                    Roo.MessageBox.alert("Error", "Can't add suppliers to kit item");
2390                                    _this.dialog.layout.getRegion('center').showPanel(0);
2391                                    return false;
2392                                }
2393                                
2394                                if (_this.itemsrcgrid) {
2395                                    _this.itemsrcgrid.footer.onClick('first');
2396                                }
2397                            }
2398                     },
2399                     items : [
2400
2401                     ]
2402
2403                 },
2404                 {
2405                     grid : {
2406                         dataSource : {
2407                             proxy : {
2408                                 '|xns' : 'Roo.data',
2409                                 url : baseURL + '/Roo/events.php',
2410                                 xtype : 'HttpProxy',
2411                                 method : 'GET',
2412                                 xns : Roo.data
2413                             },
2414                             reader : {
2415                                 '|xns' : 'Roo.data',
2416                                 id : 'id',
2417                                 root : 'data',
2418                                 xtype : 'JsonReader',
2419                                 fields : [
2420                                     {
2421                                         'name': 'event_when',
2422                                         'type': 'date'
2423                                     },
2424                                     {
2425                                         'name': 'action',
2426                                         'type': 'string'
2427                                     },
2428                                     {
2429                                         'name': 'ipaddr',
2430                                         'type': 'string'
2431                                     },
2432                                     {
2433                                         'name': 'person_id_name',
2434                                         'type': 'string'
2435                                     },
2436                                     {
2437                                         'name': 'remarks',
2438                                         'type': 'string'
2439                                     }
2440                                 ],
2441                                 xns : Roo.data,
2442                                 totalProperty : 'total'
2443                             },
2444                             '|xns' : 'Roo.data',
2445                             xtype : 'Store',
2446                             remoteSort : true,
2447                             sortInfo : { field : 'event_when', direction: 'DESC' },
2448                             xns : Roo.data,
2449                             listeners : {
2450                                 beforeload : function (_self, options)
2451                                    {
2452                                        options.params = options.params || {};
2453                                        
2454                                        options.params.on_table = 'item';
2455                                        options.params.on_id = _this.form.findField('item_id').getValue();
2456                                    }
2457                             },
2458                             items : [
2459
2460                             ]
2461
2462                         },
2463                         footer : {
2464                             '|xns' : 'Roo',
2465                             pageSize : 25,
2466                             xtype : 'PagingToolbar',
2467                             emptyMsg : "No Events found",
2468                             xns : Roo,
2469                             displayMsg : "Displaying events{0} - {1} of {2}",
2470                             displayInfo : true
2471                         },
2472                         '|xns' : 'Roo.grid',
2473                         autoExpandColumn : 'remarks',
2474                         xtype : 'Grid',
2475                         loadMask : true,
2476                         xns : Roo.grid,
2477                         colModel : [
2478                                  {
2479                                         '|xns' : 'Roo.grid',
2480                                         xtype : 'ColumnModel',
2481                                         header : 'Changed',
2482                                         width : 120,
2483                                         renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y H:i:s') : ''); },
2484                                         xns : Roo.grid,
2485                                         dataIndex : 'event_when'
2486                                     },
2487 {
2488                                         '|xns' : 'Roo.grid',
2489                                         xtype : 'ColumnModel',
2490                                         header : 'Action',
2491                                         width : 200,
2492                                         renderer : function(v,x,r) { return String.format('{0} - {1}', v, r.data.on_table); },
2493                                         xns : Roo.grid,
2494                                         dataIndex : 'action'
2495                                     },
2496 {
2497                                         '|xns' : 'Roo.grid',
2498                                         xtype : 'ColumnModel',
2499                                         header : 'IP Address',
2500                                         width : 200,
2501                                         renderer : function(v) { return String.format('{0}', v); },
2502                                         xns : Roo.grid,
2503                                         dataIndex : 'ipaddr'
2504                                     },
2505 {
2506                                         '|xns' : 'Roo.grid',
2507                                         xtype : 'ColumnModel',
2508                                         header : 'Who',
2509                                         width : 75,
2510                                         renderer : function(v) { return String.format('{0}', v); },
2511                                         xns : Roo.grid,
2512                                         dataIndex : 'person_id_name'
2513                                     },
2514 {
2515                                         '|xns' : 'Roo.grid',
2516                                         xtype : 'ColumnModel',
2517                                         header : 'Notes',
2518                                         width : 200,
2519                                         renderer : function(v) { return String.format('{0}', v); },
2520                                         xns : Roo.grid,
2521                                         dataIndex : 'remarks'
2522                                     }
2523                         ],
2524                         listeners : {
2525                                 render : function() 
2526                                    {
2527                                        _this.hgrid = this; 
2528                                        if (_this.hpanel.active) {
2529                                           this.footer.onClick('first');
2530                                        }
2531                                    }
2532                         },
2533                         items : [
2534
2535                         ]
2536
2537                     },
2538                     '|xns' : 'Roo',
2539                     fitToframe : true,
2540                     background : true,
2541                     region : 'center',
2542                     title : "History",
2543                     xtype : 'GridPanel',
2544                     fitContainer : true,
2545                     xns : Roo,
2546                     tableName : 'events',
2547                     listeners : {
2548                         activate : function() {
2549                                _this.hpanel = this;
2550                                if (_this.hgrid) {
2551                                    _this.hgrid.footer.onClick('first');
2552                                }
2553                            }
2554                     },
2555                     items : [
2556
2557                     ]
2558
2559                 }
2560             ]
2561
2562         });
2563     }
2564 };