Pman.Dialog.XtupleItem.bjs
[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                     title : "Detail",
96                     xtype : 'ContentPanel',
97                     xns : Roo,
98                     items : [
99                         {
100                             '|xns' : 'Roo.form',
101                             url : baseURL + '/Roo/item.php',
102                             method : 'POST',
103                             style : 'margin:10px;',
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                                                 _this.form.findField('_update_related').setValue(1);
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                                                     _this.form.findField('_update_related').setValue(0);
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                                                     method : 'GET',
324                                                     xtype : 'HttpProxy',
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                                                     method : 'GET',
386                                                     xtype : 'HttpProxy',
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                                                     xtype : 'HttpProxy',
452                                                     method : 'GET',
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                                                     xtype : 'HttpProxy',
558                                                     method : 'GET',
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                                                             xtype : 'HttpProxy',
664                                                             method : 'GET',
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                                                             xtype : 'HttpProxy',
819                                                             method : 'GET',
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                                                             xtype : 'HttpProxy',
881                                                             method : 'GET',
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                                                             method : 'GET',
993                                                             xtype : 'HttpProxy',
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                                     xns : Roo.form,
1062                                     width : 75,
1063                                     name : 'item_id'
1064                                 },
1065                                 {
1066                                     '|xns' : 'Roo.form',
1067                                     value : 1,
1068                                     xtype : 'Hidden',
1069                                     width : 75,
1070                                     xns : Roo.form,
1071                                     name : '_update_related'
1072                                 }
1073                             ]
1074
1075                         }
1076                     ]
1077
1078                 },
1079                 {
1080                     grid : {
1081                         toolbar : {
1082                             '|xns' : 'Roo',
1083                             xtype : 'Toolbar',
1084                             xns : Roo,
1085                             items : [
1086                                 {
1087                                     store : {
1088                                         proxy : {
1089                                             '|xns' : 'Roo.data',
1090                                             url : baseURL + '/Roo/item.php',
1091                                             method : 'GET',
1092                                             xtype : 'HttpProxy',
1093                                             xns : Roo.data
1094                                         },
1095                                         reader : {
1096                                             '|xns' : 'Roo.data',
1097                                             id : 'id',
1098                                             root : 'data',
1099                                             xtype : 'JsonReader',
1100                                             fields : [
1101                                                 {"name":"id","type":"int"},
1102                                                 {"name":"item_number","type":"string"}
1103                                             ],
1104                                             xns : Roo.data,
1105                                             totalProperty : 'total'
1106                                         },
1107                                         '|xns' : 'Roo.data',
1108                                         xtype : 'Store',
1109                                         remoteSort : true,
1110                                         sortInfo : { direction : 'ASC', field: 'item_number' },
1111                                         xns : Roo.data,
1112                                         listeners : {
1113                                                 beforeload : function (_self, o){
1114                                                        o.params = o.params || {};
1115                                                        
1116                                                        o.params.item_active = 1;
1117                                                        o.params['!item_type'] = 'K';
1118                                                    }
1119                                         },
1120                                         items : [
1121
1122                                         ]
1123
1124                                     },
1125                                     '|xns' : 'Roo.bootstrap',
1126                                     alwaysQuery : true,
1127                                     triggerAction : 'all',
1128                                     fieldLabel : 'Item',
1129                                     forceSelection : true,
1130                                     selectOnFocus : true,
1131                                     pageSize : 20,
1132                                     displayField : 'item_number',
1133                                     emptyText : "Select item",
1134                                     minChars : 2,
1135                                     valueField : 'id',
1136                                     xtype : 'ComboBox',
1137                                     allowBlank : true,
1138                                     typeAhead : true,
1139                                     editable : true,
1140                                     width : 200,
1141                                     xns : Roo.bootstrap,
1142                                     qtip : "Select item",
1143                                     queryParam : 'query[number_or_name]',
1144                                     tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{item_number}</b> </div>',
1145                                     loadingText : "Searching...",
1146                                     listeners : {
1147                                         render : function (_self)
1148                                            {
1149                                                _this.partsBox = _self;
1150                                            },
1151                                         select : function (combo, record, index)
1152                                            {
1153                                                var item_id = _this.form.findField('item_id').getValue() * 1;
1154                                                
1155                                                if(typeof(record) == 'undefined' || !record || record.data.id * 1 < 1 || item_id < 1){
1156                                                    return;
1157                                                }
1158                                                
1159                                                var err = false;
1160                                            
1161                                                _this.partsgrid.ds.each(function(d){
1162                                                    if(record.data.item_id == d.data.bomitem_item_id){
1163                                                        err = true;
1164                                                    }
1165                                                });
1166                                            
1167                                                if(err){
1168                                                    Roo.MessageBox.alert('Error', record.data.item_number + ' already exists!');
1169                                                    _this.partsBox.reset();
1170                                                    return;
1171                                                }
1172                                                
1173                                                new Pman.Request({
1174                                                    url : baseURL + '/Roo/bomitem.php',
1175                                                    method : 'POST',
1176                                                    params : {
1177                                                        bomitem_parent_item_id : item_id,
1178                                                        bomitem_item_id : record.data.item_id
1179                                                    }, 
1180                                                    success : function(res) {
1181                                                        _this.partsBox.reset();
1182                                                        _this.partsgrid.footer.onClick('first');
1183                                                    }
1184                                                }); 
1185                                            }
1186                                     },
1187                                     items : [
1188
1189                                     ]
1190
1191                                 },
1192                                 {
1193                                     '|xns' : 'Roo.Toolbar',
1194                                     xtype : 'Fill',
1195                                     xns : Roo.Toolbar
1196                                 },
1197                                 {
1198                                     '|xns' : 'Roo',
1199                                     text : "Remove",
1200                                     xtype : 'Button',
1201                                     cls : 'x-btn-text-icon',
1202                                     icon : rootURL + '/Pman/templates/images/trash.gif',
1203                                     xns : Roo,
1204                                     listeners : {
1205                                         click : function ()
1206                                            {
1207                                                var sel = _this.partsgrid.getSelectionModel().getSelectedCell();
1208                                                
1209                                                if(!sel || !sel.length){
1210                                                    Roo.MessageBox.alert("Error", "Please select a item from below list");
1211                                                    return;
1212                                                }
1213                                                
1214                                                var d = _this.partsgrid.ds.getAt(sel[0]);      
1215                                              
1216                                                if(d.data.bomitem_id * 1 < 1){
1217                                                    Roo.MessageBox.alert("Error", "Invaild selection");
1218                                                    return;
1219                                                }
1220                                                
1221                                                new Pman.Request({
1222                                                    url : baseURL + '/Roo/bomitem.php',
1223                                                    method : 'POST',
1224                                                    params : {
1225                                                        _delete : d.data.bomitem_id
1226                                                    }, 
1227                                                    success : function(res) {
1228                                                        _this.partsgrid.footer.onClick('first');
1229                                                    }
1230                                                }); 
1231                                               
1232                                            }
1233                                     }
1234                                 }
1235                             ]
1236
1237                         },
1238                         dataSource : {
1239                             proxy : {
1240                                 '|xns' : 'Roo.data',
1241                                 url : baseURL + '/Roo/bomitem.php',
1242                                 xtype : 'HttpProxy',
1243                                 method : 'GET',
1244                                 xns : Roo.data
1245                             },
1246                             reader : {
1247                                 '|xns' : 'Roo.data',
1248                                 id : 'bom_id',
1249                                 root : 'data',
1250                                 xtype : 'JsonReader',
1251                                 fields : [
1252                                     {
1253                                         'name': 'bomitem_id',
1254                                         'type': 'int'
1255                                     }
1256                                 ],
1257                                 xns : Roo.data,
1258                                 totalProperty : 'total'
1259                             },
1260                             '|xns' : 'Roo.data',
1261                             xtype : 'Store',
1262                             remoteSort : true,
1263                             sortInfo : { field : 'bomitem_item_id_item_name', direction: 'ASC' },
1264                             xns : Roo.data,
1265                             listeners : {
1266                                 beforeload : function (_self, o)
1267                                    {
1268                                       o.params = o.params || {};
1269                                       
1270                                       var id  = _this.form.findField('item_id').getValue() * 1;
1271                                       if(id < 1){
1272                                            return false;
1273                                       }
1274                                       
1275                                       o.params.bom_parent_item_id = id;
1276                                    }
1277                             },
1278                             items : [
1279
1280                             ]
1281
1282                         },
1283                         footer : {
1284                             '|xns' : 'Roo',
1285                             pageSize : 50,
1286                             xtype : 'PagingToolbar',
1287                             emptyMsg : "Nothing found",
1288                             xns : Roo,
1289                             displayMsg : "Displaying parts {0} - {1} of {2}",
1290                             displayInfo : true
1291                         },
1292                         '|xns' : 'Roo.grid',
1293                         autoExpandColumn : 'bomitem_item_id_item_descrip1',
1294                         xtype : 'EditorGrid',
1295                         loadMask : true,
1296                         clicksToEdit : 1,
1297                         xns : Roo.grid,
1298                         colModel : [
1299                                  {
1300                                         '|xns' : 'Roo.grid',
1301                                         xtype : 'ColumnModel',
1302                                         header : 'Name',
1303                                         width : 150,
1304                                         renderer : function(v) { return String.format('{0}', v); },
1305                                         xns : Roo.grid,
1306                                         dataIndex : 'bomitem_item_id_item_number'
1307                                     },
1308 {
1309                                         '|xns' : 'Roo.grid',
1310                                         xtype : 'ColumnModel',
1311                                         header : 'Description',
1312                                         width : 150,
1313                                         renderer : function(v) { return String.format('{0}', v); },
1314                                         xns : Roo.grid,
1315                                         dataIndex : 'bomitem_item_id_item_descrip1'
1316                                     },
1317 {
1318                                         editor : {
1319                                             field : {
1320                                                 '|xns' : 'Roo.form',
1321                                                 allowBlank : false,
1322                                                 cls : 'align-right',
1323                                                 xtype : 'NumberField',
1324                                                 decimalPrecision : 0,
1325                                                 xns : Roo.form,
1326                                                 minValue : 0
1327                                             },
1328                                             '|xns' : 'Roo.grid',
1329                                             xtype : 'GridEditor',
1330                                             xns : Roo.grid,
1331                                             items : [
1332
1333                                             ]
1334
1335                                         },
1336                                         '|xns' : 'Roo.grid',
1337                                         xtype : 'ColumnModel',
1338                                         align : 'right',
1339                                         header : 'Qty',
1340                                         width : 100,
1341                                         renderer : function(v) { return String.format('{0}', v); },
1342                                         xns : Roo.grid,
1343                                         dataIndex : 'bomitem_qtyper',
1344                                         items : [
1345
1346                                         ]
1347
1348                                     }
1349                         ],
1350                         listeners : {
1351                                 beforeedit : function (e)
1352                                    {
1353                                        if(e.field != 'bomitem_qtyper'){
1354                                            return false;
1355                                        }
1356                                        
1357                                    },
1358                                 render : function() 
1359                                    {
1360                                        _this.partsgrid = this; 
1361                                        //_this.dialog = Pman.Dialog.FILL_IN
1362                                        if (_this.partspanel.active) {
1363                                           this.footer.onClick('first');
1364                                        }
1365                                    },
1366                                 afteredit : function (e)
1367                                    {
1368                                        if(e.originalValue == e.value){
1369                                            return false;
1370                                        }
1371                                        
1372                                        
1373                                        new Pman.Request({
1374                                            method : 'POST',
1375                                            url : baseURL + '/Roo/bomitem.php',
1376                                            mask : 'Saving',
1377                                            params : {
1378                                                bomitem_id : e.record.data.bomitem_id,
1379                                                bomitem_qtyper : e.value
1380                                            },
1381                                            success : function() {
1382                                                e.record.set('bomitem_qtyper', e.value);
1383                                            }
1384                                        
1385                                        });
1386                                            
1387                                             
1388                                            
1389                                            
1390                                    }
1391                         },
1392                         items : [
1393
1394                         ]
1395
1396                     },
1397                     '|xns' : 'Roo',
1398                     region : 'center',
1399                     fitToframe : true,
1400                     background : true,
1401                     title : "Item Parts",
1402                     xtype : 'GridPanel',
1403                     fitContainer : true,
1404                     xns : Roo,
1405                     tableName : 'bomitem',
1406                     listeners : {
1407                         activate : function() {
1408                                _this.partspanel = this;
1409                                
1410                                try { if (MODULE.isBuilder) {
1411                                    return;
1412                                } } catch(e) { }
1413                                
1414                                var id = _this.form.findField('item_id').getValue() * 1;
1415                                if (id < 1) {
1416                                    Roo.MessageBox.alert("Save First", "Save the item first, before adding parts");
1417                                    _this.dialog.layout.getRegion('center').showPanel(0);
1418                                    return;
1419                                }
1420                                
1421                                var type = _this.form.findField('item_type').getValue();
1422                                
1423                                if(!type.length || type != 'K'){
1424                                    Roo.MessageBox.alert("Error", "Can't add parts to non-kit item");
1425                                    _this.dialog.layout.getRegion('center').showPanel(0);
1426                                    return;
1427                                }
1428                                
1429                                if (_this.partsgrid) {
1430                                    _this.partsgrid.footer.onClick('first');
1431                                
1432                                 }
1433                            }
1434                     },
1435                     items : [
1436
1437                     ]
1438
1439                 },
1440                 {
1441                     grid : {
1442                         dataSource : {
1443                             reader : {
1444                                 '|xns' : 'Roo.data',
1445                                 id : 'id',
1446                                 root : 'data',
1447                                 xtype : 'JsonReader',
1448                                 fields : [
1449                                     {
1450                                         'name': 'id',
1451                                         'type': 'int'
1452                                     },
1453                                     {
1454                                         'name': 'filename',
1455                                         'type': 'string'
1456                                     },
1457                                     {
1458                                         'name': 'ontable',
1459                                         'type': 'string'
1460                                     },
1461                                     {
1462                                         'name': 'onid',
1463                                         'type': 'int'
1464                                     },
1465                                     {
1466                                         'name': 'mimetype',
1467                                         'type': 'string'
1468                                     },
1469                                     {
1470                                         'name': 'width',
1471                                         'type': 'int'
1472                                     },
1473                                     {
1474                                         'name': 'height',
1475                                         'type': 'int'
1476                                     },
1477                                     {
1478                                         'name': 'filesize',
1479                                         'type': 'int'
1480                                     },
1481                                     {
1482                                         'name': 'displayorder',
1483                                         'type': 'int'
1484                                     },
1485                                     {
1486                                         'name': 'language',
1487                                         'type': 'string'
1488                                     },
1489                                     {
1490                                         'name': 'parent_image_id',
1491                                         'type': 'int'
1492                                     },
1493                                     {
1494                                         'name': 'created',
1495                                         'type': 'date',
1496                                         'dateFormat' : 'Y-m-d H:i:s'
1497                                     },
1498                                     {
1499                                         'name': 'imgtype',
1500                                         'type': 'string'
1501                                     },
1502                                     {
1503                                         'name': 'linkurl',
1504                                         'type': 'string'
1505                                     },
1506                                     {
1507                                         'name': 'descript',
1508                                         'type': 'string'
1509                                     },
1510                                     {
1511                                         'name': 'title',
1512                                         'type': 'string'
1513                                     }
1514                                 ],
1515                                 xns : Roo.data,
1516                                 totalProperty : 'total'
1517                             },
1518                             proxy : {
1519                                 '|xns' : 'Roo.data',
1520                                 url : baseURL + '/Roo/Images.php',
1521                                 xtype : 'HttpProxy',
1522                                 method : 'GET',
1523                                 xns : Roo.data
1524                             },
1525                             '|xns' : 'Roo.data',
1526                             xtype : 'Store',
1527                             remoteSort : true,
1528                             sortInfo : { field: 'created' , direction: 'DESC' },
1529                             xns : Roo.data,
1530                             listeners : {
1531                                 beforeload : function (_self, o)
1532                                    {
1533                                        o.params = o.params || {};
1534                                        
1535                                        var id = _this.form.findField('item_id').getValue();
1536                                        
1537                                        if(id * 1 < 1){
1538                                            return false;
1539                                        }
1540                                        
1541                                        o.params.onid = id;
1542                                        o.params.ontable = 'item';
1543                                        
1544                                    }
1545                             },
1546                             items : [
1547
1548                             ]
1549
1550                         },
1551                         footer : {
1552                             '|xns' : 'Roo',
1553                             pageSize : 25,
1554                             xtype : 'PagingToolbar',
1555                             emptyMsg : "No Images found",
1556                             xns : Roo,
1557                             displayInfo : true,
1558                             displayMsg : "Displaying Images  {0} - {1} of {2}"
1559                         },
1560                         toolbar : {
1561                             '|xns' : 'Roo',
1562                             xtype : 'Toolbar',
1563                             xns : Roo,
1564                             items : [
1565                                 {
1566                                     '|xns' : 'Roo.Toolbar',
1567                                     text : "Add",
1568                                     xtype : 'Button',
1569                                     cls : 'x-btn-text-icon',
1570                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
1571                                     xns : Roo.Toolbar,
1572                                     listeners : {
1573                                         click : function()
1574                                            {
1575                                                Pman.Dialog.Image.show({
1576                                                    id : 0, 
1577                                                    ontable: 'item',
1578                                                    onid: _this.form.findField('item_id').getValue() * 1,
1579                                                    imgtype : ''
1580                                                }, function(data){
1581                                                    if (!data) { return; } 
1582                                                    _this.grid.footer.onClick('first');
1583                                                }); 
1584                                            
1585                                            }
1586                                     }
1587                                 },
1588                                 {
1589                                     '|xns' : 'Roo.Toolbar',
1590                                     text : "Delete",
1591                                     xtype : 'Button',
1592                                     cls : 'x-btn-text-icon',
1593                                     icon : rootURL + '/Pman/templates/images/trash.gif',
1594                                     xns : Roo.Toolbar,
1595                                     listeners : {
1596                                         click : function()
1597                                            {
1598                                                Pman.genericDelete(_this, 'Images'); 
1599                                            }
1600                                     }
1601                                 }
1602                             ]
1603
1604                         },
1605                         '|xns' : 'Roo.grid',
1606                         autoExpandColumn : 'id',
1607                         xtype : 'Grid',
1608                         loadMask : true,
1609                         xns : Roo.grid,
1610                         colModel : [
1611                                  {
1612                                         '|xns' : 'Roo.grid',
1613                                         xtype : 'ColumnModel',
1614                                         sortable : true,
1615                                         header : 'Created',
1616                                         width : 200,
1617                                         renderer : function(v,x,r) {
1618                                                return String.format('{0}<br/><i>{1}</i><br/>{2}<br/><i>{3}x{4}</i>',
1619                                                     v.format('d/M/Y'), r.data.mimetype, r.data.filename,
1620                                             r.data.width, r.data.height
1621                                             ); 
1622                                         },
1623                                         xns : Roo.grid,
1624                                         dataIndex : 'created'
1625                                     },
1626 {
1627                                         '|xns' : 'Roo.grid',
1628                                         xtype : 'ColumnModel',
1629                                         width : 100,
1630                                         header : 'Image',
1631                                         renderer : function(v,x,r) { return String.format('<img src="{0}/Images/Thumb/100/{1}/{2}" height="100">', baseURL, v, r.data.filename); },
1632                                         xns : Roo.grid,
1633                                         dataIndex : 'id'
1634                                     }
1635                         ],
1636                         listeners : {
1637                                 rowdblclick : function (_self, rowIndex, e)
1638                                    {
1639                                      
1640                                       var s =  _self.getDataSource().getAt(rowIndex);
1641                                       new Pman.Download({
1642                                            url : baseURL + '/Images/Download/' + s.data.id
1643                                        });
1644                                       
1645                                    },
1646                                 render : function() { 
1647                                        _this.grid = this; 
1648                                    
1649                                        if (_this.panel.active) {
1650                                           this.footer.onClick('first');
1651                                        }
1652                                    }
1653                         },
1654                         items : [
1655
1656                         ]
1657
1658                     },
1659                     '|xns' : 'Roo',
1660                     fitToframe : true,
1661                     background : true,
1662                     region : 'center',
1663                     title : "Reference Files",
1664                     xtype : 'GridPanel',
1665                     fitContainer : true,
1666                     xns : Roo,
1667                     tableName : 'Images',
1668                     listeners : {
1669                         activate : function() {
1670                                _this.panel = this;
1671                                
1672                                try { if (MODULE.isBuilder) {
1673                                    return;
1674                                } } catch(e) { }
1675                                
1676                                var id = _this.form.findField('item_id').getValue() * 1;
1677                                if (id < 1) {
1678                                    Roo.MessageBox.alert("Save First", "Save the item first, before adding image");
1679                                    _this.dialog.layout.getRegion('center').showPanel(0);
1680                                    return;
1681                                }
1682                                
1683                                if (_this.grid) {
1684                                    _this.grid.footer.onClick('first');
1685                                
1686                                 }
1687                            }
1688                     },
1689                     items : [
1690
1691                     ]
1692
1693                 },
1694                 {
1695                     grid : {
1696                         dataSource : {
1697                             proxy : {
1698                                 '|xns' : 'Roo.data',
1699                                 url : baseURL + '/Roo/ipshead.php',
1700                                 method : 'GET',
1701                                 xtype : 'HttpProxy',
1702                                 xns : Roo.data
1703                             },
1704                             reader : {
1705                                 '|xns' : 'Roo.data',
1706                                 id : 'ipshead_id',
1707                                 root : 'data',
1708                                 xtype : 'JsonReader',
1709                                 fields : [
1710                                     {
1711                                         'name': 'ipshead_id',
1712                                         'type': 'int'
1713                                     },
1714                                     {
1715                                         'name': 'ipshead_name',
1716                                         'type': 'string'
1717                                     }
1718                                 ],
1719                                 xns : Roo.data,
1720                                 totalProperty : 'total'
1721                             },
1722                             '|xns' : 'Roo.data',
1723                             xtype : 'Store',
1724                             remoteSort : true,
1725                             sortInfo : { field : 'ipshead_id', direction: 'ASC' },
1726                             xns : Roo.data,
1727                             listeners : {
1728                                 beforeload : function (_self, o)
1729                                    {
1730                                       o.params = o.params || {};
1731                                       
1732                                       var id  = _this.form.findField('item_id').getValue() * 1;
1733                                       if(id < 1){
1734                                            return false;
1735                                       }
1736                                       
1737                                       o.params._with_item = id;
1738                                    }
1739                             },
1740                             items : [
1741
1742                             ]
1743
1744                         },
1745                         footer : {
1746                             '|xns' : 'Roo',
1747                             pageSize : 50,
1748                             xtype : 'PagingToolbar',
1749                             emptyMsg : "Nothing found",
1750                             xns : Roo,
1751                             displayMsg : "Displaying records {0} - {1} of {2}",
1752                             displayInfo : true
1753                         },
1754                         '|xns' : 'Roo.grid',
1755                         autoExpandColumn : 'ipshead_descrip',
1756                         xtype : 'EditorGrid',
1757                         loadMask : true,
1758                         clicksToEdit : 1,
1759                         xns : Roo.grid,
1760                         colModel : [
1761                                  {
1762                                         '|xns' : 'Roo.grid',
1763                                         xtype : 'ColumnModel',
1764                                         width : 150,
1765                                         header : 'Name',
1766                                         renderer : function(v) { return String.format('{0}', v); },
1767                                         xns : Roo.grid,
1768                                         dataIndex : 'ipshead_name'
1769                                     },
1770 {
1771                                         '|xns' : 'Roo.grid',
1772                                         xtype : 'ColumnModel',
1773                                         width : 150,
1774                                         header : 'Description',
1775                                         renderer : function(v) { return String.format('{0}', v); },
1776                                         xns : Roo.grid,
1777                                         dataIndex : 'ipshead_descrip'
1778                                     },
1779 {
1780                                         '|xns' : 'Roo.grid',
1781                                         xtype : 'ColumnModel',
1782                                         width : 100,
1783                                         header : 'Currency',
1784                                         renderer : function(v) { return String.format('{0}', v); },
1785                                         xns : Roo.grid,
1786                                         dataIndex : 'ipshead_curr_id_curr_name'
1787                                     },
1788 {
1789                                         editor : {
1790                                             field : {
1791                                                 '|xns' : 'Roo.form',
1792                                                 xtype : 'NumberField',
1793                                                 cls : 'align-right',
1794                                                 decimalPrecision : 2,
1795                                                 xns : Roo.form
1796                                             },
1797                                             '|xns' : 'Roo.grid',
1798                                             xtype : 'GridEditor',
1799                                             xns : Roo.grid,
1800                                             items : [
1801
1802                                             ]
1803
1804                                         },
1805                                         '|xns' : 'Roo.grid',
1806                                         align : 'right',
1807                                         xtype : 'ColumnModel',
1808                                         header : 'Price',
1809                                         width : 120,
1810                                         renderer : function(v) { return String.format('{0}', Roo.util.Format.number(v*1,2)); },
1811                                         xns : Roo.grid,
1812                                         dataIndex : 'ipshead_ipsitem_price',
1813                                         items : [
1814
1815                                         ]
1816
1817                                     }
1818                         ],
1819                         listeners : {
1820                                 beforeedit : function (e)
1821                                    {
1822                                        if(e.field != 'ipshead_ipsitem_price'){
1823                                            return false;
1824                                        }
1825                                        
1826                                    },
1827                                 render : function() 
1828                                    {
1829                                        _this.lgrid = this; 
1830                                        //_this.dialog = Pman.Dialog.FILL_IN
1831                                        if (_this.lpanel.active) {
1832                                           this.footer.onClick('first');
1833                                        }
1834                                    },
1835                                 afteredit : function (e)
1836                                    {
1837                                        if(e.originalValue == e.value){
1838                                            return false;
1839                                        }
1840                                        
1841                                        var id = _this.form.findField('item_id').getValue() * 1;
1842                                        if(id < 1){
1843                                            return false;
1844                                        }
1845                                        
1846                                        new Pman.Request({
1847                                            method : 'POST',
1848                                            url : baseURL + '/Roo/ipsiteminfo',
1849                                            mask : 'Saving',
1850                                            params : {
1851                                                ipsitem_ipshead_id : e.record.data.ipshead_id,
1852                                                ipsitem_item_id : id,
1853                                                ipsitem_price : e.record.data.ipshead_ipsitem_price,
1854                                                ipsitem_id : e.record.data.ipshead_ipsitem_id
1855                                            }
1856                                        
1857                                        });
1858                                            
1859                                             
1860                                            
1861                                            
1862                                    }
1863                         },
1864                         items : [
1865
1866                         ]
1867
1868                     },
1869                     '|xns' : 'Roo',
1870                     fitToframe : true,
1871                     background : true,
1872                     region : 'center',
1873                     title : "Price List",
1874                     xtype : 'GridPanel',
1875                     fitContainer : true,
1876                     xns : Roo,
1877                     tableName : 'ipshead',
1878                     listeners : {
1879                         activate : function() {
1880                                _this.lpanel = this;
1881                                
1882                                try { if (MODULE.isBuilder) {
1883                                    return;
1884                                } } catch(e) { }
1885                                
1886                                var id = _this.form.findField('item_id').getValue() * 1;
1887                                if (id < 1) {
1888                                    Roo.MessageBox.alert("Save First", "Save the item first, before adding image");
1889                                    _this.dialog.layout.getRegion('center').showPanel(0);
1890                                    return;
1891                                }
1892                                
1893                                if (_this.lgrid) {
1894                                    _this.lgrid.footer.onClick('first');
1895                                
1896                                 }
1897                            }
1898                     },
1899                     items : [
1900
1901                     ]
1902
1903                 },
1904                 {
1905                     grid : {
1906                         dataSource : {
1907                             proxy : {
1908                                 '|xns' : 'Roo.data',
1909                                 url : baseURL + '/Roo/itemsrc.php',
1910                                 xtype : 'HttpProxy',
1911                                 method : 'GET',
1912                                 xns : Roo.data
1913                             },
1914                             reader : {
1915                                 '|xns' : 'Roo.data',
1916                                 id : 'id',
1917                                 root : 'data',
1918                                 xtype : 'JsonReader',
1919                                 xns : Roo.data,
1920                                 fields : [
1921                                     {
1922                                         'name': 'itemsrc_id',
1923                                         'type': 'int'
1924                                     },
1925                                     {
1926                                         'name': 'itemsrc_item_id',
1927                                         'type': 'int'
1928                                     },
1929                                     {
1930                                         'name': 'itemsrc_item_id',
1931                                         'type': 'int'
1932                                     },
1933                                     {
1934                                         'name': 'itemsrc_vend_id',
1935                                         'type': 'int'
1936                                     },
1937                                     {
1938                                         'name': 'itemsrc_vend_id',
1939                                         'type': 'int'
1940                                     },
1941                                     {
1942                                         'name': 'itemsrc_vend_item_number',
1943                                         'type': 'string'
1944                                     },
1945                                     {
1946                                         'name': 'itemsrc_vend_item_descrip',
1947                                         'type': 'string'
1948                                     },
1949                                     {
1950                                         'name': 'itemsrc_comments',
1951                                         'type': 'string'
1952                                     },
1953                                     {
1954                                         'name': 'itemsrc_vend_uom',
1955                                         'type': 'string'
1956                                     },
1957                                     {
1958                                         'name': 'itemsrc_invvendoruomratio',
1959                                         'type': 'float'
1960                                     },
1961                                     {
1962                                         'name': 'itemsrc_minordqty',
1963                                         'type': 'float'
1964                                     },
1965                                     {
1966                                         'name': 'itemsrc_multordqty',
1967                                         'type': 'float'
1968                                     },
1969                                     {
1970                                         'name': 'itemsrc_leadtime',
1971                                         'type': 'int'
1972                                     },
1973                                     {
1974                                         'name': 'itemsrc_ranking',
1975                                         'type': 'int'
1976                                     },
1977                                     {
1978                                         'name': 'itemsrc_active',
1979                                         'type': 'int'
1980                                     },
1981                                     {
1982                                         'name': 'itemsrc_manuf_name',
1983                                         'type': 'string'
1984                                     },
1985                                     {
1986                                         'name': 'itemsrc_manuf_item_number',
1987                                         'type': 'string'
1988                                     },
1989                                     {
1990                                         'name': 'itemsrc_manuf_item_descrip',
1991                                         'type': 'string'
1992                                     },
1993                                     {
1994                                         'name': 'itemsrc_default',
1995                                         'type': 'int'
1996                                     },
1997                                     {
1998                                         'name': 'itemsrc_upccode',
1999                                         'type': 'string'
2000                                     }
2001                                 ],
2002                                 totalProperty : 'total'
2003                             },
2004                             '|xns' : 'Roo.data',
2005                             xtype : 'Store',
2006                             remoteSort : true,
2007                             sortInfo : { field : 'itemsrc_vend_id_vend_name', direction: 'ASC' },
2008                             xns : Roo.data,
2009                             listeners : {
2010                                 update : function (_self, record, operation)
2011                                    {
2012                                        Roo.log(operation);
2013                                          Roo.log(record);
2014                                       
2015                                        if (operation != 'commit') {
2016                                            return;
2017                                        }
2018                                        if (record.data.itemsrc_vend_id * 1 < 1) {
2019                                            return; // do not save.
2020                                        }
2021                                        if (record.data.itemsrc_id * 1 < 0) {
2022                                            return; // do not save. -- updating at present...
2023                                        }
2024                                        
2025                                        var p = Roo.apply({}, record.data);
2026                                        record.set('itemsrc_id', -1);    
2027                                        
2028                                        new Pman.Request({
2029                                            url : baseURL + '/Roo/Itemsrc',
2030                                            params : p,
2031                                            method : 'POST',
2032                                            success: function(res) {
2033                                                if (record.data.itemsrc_id *1  < 1) { 
2034                                                    record.set('itemsrc_id', res.data.itemsrc_id);
2035                                                }
2036                                            }
2037                                        });
2038                                        
2039                                        
2040                                    },
2041                                 beforeload : function (_self, o)
2042                                    {
2043                                        
2044                                        var id = 1 * _this.form.findField('item_id').getValue();
2045                                        if (!id) {
2046                                            this.removeAll();
2047                                            return false;
2048                                        }
2049                                        o.params.itemsrc_item_id = id;
2050                                    }
2051                             },
2052                             items : [
2053
2054                             ]
2055
2056                         },
2057                         footer : {
2058                             '|xns' : 'Roo',
2059                             pageSize : 25,
2060                             xtype : 'PagingToolbar',
2061                             emptyMsg : "No itemsrc found",
2062                             xns : Roo,
2063                             displayInfo : true,
2064                             displayMsg : "Displaying itemsrc{0} - {1} of {2}"
2065                         },
2066                         toolbar : {
2067                             '|xns' : 'Roo',
2068                             xtype : 'Toolbar',
2069                             xns : Roo,
2070                             items : [
2071                                 {
2072                                     '|xns' : 'Roo.Toolbar',
2073                                     text : "Add",
2074                                     xtype : 'Button',
2075                                     cls : 'x-btn-text-icon',
2076                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
2077                                     xns : Roo.Toolbar,
2078                                     listeners : {
2079                                         click : function()
2080                                            {
2081                                                 
2082                                                Roo.log("add presed");
2083                                                 
2084                                                // work out last 
2085                                                var grid = _this.itemsrcgrid;
2086                                                 
2087                                                // uses form defaults or last row value.
2088                                                var nr = grid.ds.reader.newRow({
2089                                                     itemsrc_id : 0,
2090                                                     itemsrc_item_id : _this.form.findField('item_id').getValue(),
2091                                                     itemsrc_vend_id : 0,
2092                                                     itemsrc_vend_id_vend_name : '',
2093                                                     itemsrc_vend_item_number : '',
2094                                                     itemsrc_vend_item_descrip : '',
2095                                                     itemsrc_comments           : '',
2096                                                     itemsrc_vend_uom  :           'EA',
2097                                                     itemsrc_invvendoruomratio : 1.0,
2098                                                     itemsrc_minordqty        : 0,
2099                                                     itemsrc_multordqty        : 0,
2100                                                     itemsrc_leadtime         :  30,
2101                                                     itemsrc_ranking         :   0,
2102                                                     itemsrc_active          :   true,
2103                                                     itemsrc_manuf_name       :  '',
2104                                                     itemsrc_manuf_item_number : '',
2105                                                     itemsrc_manuf_item_descrip: '',
2106                                                     itemsrc_default          : true,
2107                                                     itemsrc_upccode    : ''
2108                                                                    
2109                                                });
2110                                                grid.stopEditing();
2111                                                grid.ds.insert(0, nr); 
2112                                                grid.startEditing(0, 0); // type..
2113                                            
2114                                            }
2115                                     }
2116                                 }
2117                             ]
2118
2119                         },
2120                         '|xns' : 'Roo.grid',
2121                         autoExpandColumn : 'itemsrc_comments',
2122                         xtype : 'EditorGrid',
2123                         loadMask : true,
2124                         clicksToEdit : 1,
2125                         xns : Roo.grid,
2126                         colModel : [
2127                                  {
2128                                         editor : {
2129                                             field : {
2130                                                 store : {
2131                                                     proxy : {
2132                                                         '|xns' : 'Roo.data',
2133                                                         url : baseURL + '/Roo/vendinfo.php',
2134                                                         xtype : 'HttpProxy',
2135                                                         method : 'GET',
2136                                                         xns : Roo.data
2137                                                     },
2138                                                     reader : {
2139                                                         '|xns' : 'Roo.data',
2140                                                         id : 'id',
2141                                                         root : 'data',
2142                                                         xtype : 'JsonReader',
2143                                                         xns : Roo.data,
2144                                                         fields : [{"name":"id","type":"int"},{"name":"vend_name","type":"string"}],
2145                                                         totalProperty : 'total'
2146                                                     },
2147                                                     '|xns' : 'Roo.data',
2148                                                     xtype : 'Store',
2149                                                     remoteSort : true,
2150                                                     xns : Roo.data,
2151                                                     sortInfo : { direction : 'ASC', field: 'id' },
2152                                                     listeners : {
2153                                                         beforeload : function (_self, o){
2154                                                                o.params = o.params || {};
2155                                                                // set more here
2156                                                            }
2157                                                     },
2158                                                     items : [
2159
2160                                                     ]
2161
2162                                                 },
2163                                                 '|xns' : 'Roo.form',
2164                                                 listWidth : 400,
2165                                                 triggerAction : 'all',
2166                                                 forceSelection : true,
2167                                                 selectOnFocus : true,
2168                                                 pageSize : 20,
2169                                                 displayField : 'vend_name',
2170                                                 emptyText : "Select Vendor",
2171                                                 hiddenName : 'itemsrc_vend_id',
2172                                                 minChars : 2,
2173                                                 valueField : 'vend_id',
2174                                                 xtype : 'ComboBox',
2175                                                 allowBlank : false,
2176                                                 typeAhead : true,
2177                                                 editable : true,
2178                                                 width : 300,
2179                                                 xns : Roo.form,
2180                                                 name : 'itemsrc_vend_id_vend_name',
2181                                                 qtip : "Select vendinfo",
2182                                                 queryParam : 'q[search]',
2183                                                 tpl : '<div class=\"x-grid-cell-text x-btn button\"><b>{vend_name}</b> </div>',
2184                                                 loadingText : "Searching...",
2185                                                 items : [
2186
2187                                                 ]
2188
2189                                             },
2190                                             '|xns' : 'Roo.grid',
2191                                             xtype : 'GridEditor',
2192                                             xns : Roo.grid,
2193                                             items : [
2194
2195                                             ]
2196
2197                                         },
2198                                         '|xns' : 'Roo.grid',
2199                                         xtype : 'ColumnModel',
2200                                         width : 120,
2201                                         header : 'Vendor',
2202                                         renderer : function(v,x,r) { return String.format('{0}', r.data.itemsrc_vend_id_vend_name); },
2203                                         xns : Roo.grid,
2204                                         dataIndex : 'itemsrc_vend_id',
2205                                         items : [
2206
2207                                         ]
2208
2209                                     },
2210 {
2211                                         editor : {
2212                                             field : {
2213                                                 '|xns' : 'Roo.form',
2214                                                 xtype : 'TextField',
2215                                                 xns : Roo.form
2216                                             },
2217                                             '|xns' : 'Roo.grid',
2218                                             xtype : 'GridEditor',
2219                                             xns : Roo.grid,
2220                                             items : [
2221
2222                                             ]
2223
2224                                         },
2225                                         '|xns' : 'Roo.grid',
2226                                         xtype : 'ColumnModel',
2227                                         width : 100,
2228                                         header : 'Vendor Ref#',
2229                                         renderer : function(v) { return String.format('{0}', v); },
2230                                         xns : Roo.grid,
2231                                         dataIndex : 'itemsrc_vend_item_number',
2232                                         items : [
2233
2234                                         ]
2235
2236                                     },
2237 {
2238                                         editor : {
2239                                             field : {
2240                                                 '|xns' : 'Roo.form',
2241                                                 xtype : 'TextField',
2242                                                 xns : Roo.form
2243                                             },
2244                                             '|xns' : 'Roo.grid',
2245                                             xtype : 'GridEditor',
2246                                             xns : Roo.grid,
2247                                             items : [
2248
2249                                             ]
2250
2251                                         },
2252                                         '|xns' : 'Roo.grid',
2253                                         xtype : 'ColumnModel',
2254                                         width : 200,
2255                                         header : 'Comments',
2256                                         renderer : function(v) { return String.format('{0}', v); },
2257                                         xns : Roo.grid,
2258                                         dataIndex : 'itemsrc_comments',
2259                                         items : [
2260
2261                                         ]
2262
2263                                     },
2264 {
2265                                         '|xns' : 'Roo.grid',
2266                                         xtype : 'ColumnModel',
2267                                         width : 50,
2268                                         header : 'UOM',
2269                                         renderer : function(v) { return String.format('{0}', v); },
2270                                         xns : Roo.grid,
2271                                         dataIndex : 'itemsrc_vend_uom'
2272                                     },
2273 {
2274                                         editor : {
2275                                             field : {
2276                                                 '|xns' : 'Roo.form',
2277                                                 minValue : 0,
2278                                                 xtype : 'NumberField',
2279                                                 decimalPrecision : 0,
2280                                                 xns : Roo.form
2281                                             },
2282                                             '|xns' : 'Roo.grid',
2283                                             xtype : 'GridEditor',
2284                                             xns : Roo.grid,
2285                                             items : [
2286
2287                                             ]
2288
2289                                         },
2290                                         '|xns' : 'Roo.grid',
2291                                         align : 'right',
2292                                         xtype : 'ColumnModel',
2293                                         header : 'Min Qty',
2294                                         width : 50,
2295                                         renderer : function(v) { return String.format('{0}', v); },
2296                                         xns : Roo.grid,
2297                                         dataIndex : 'itemsrc_minordqty',
2298                                         items : [
2299
2300                                         ]
2301
2302                                     },
2303 {
2304                                         editor : {
2305                                             field : {
2306                                                 '|xns' : 'Roo.form',
2307                                                 minValue : 0,
2308                                                 xtype : 'NumberField',
2309                                                 decimalPrecision : 0,
2310                                                 xns : Roo.form
2311                                             },
2312                                             '|xns' : 'Roo.grid',
2313                                             xtype : 'GridEditor',
2314                                             xns : Roo.grid,
2315                                             items : [
2316
2317                                             ]
2318
2319                                         },
2320                                         '|xns' : 'Roo.grid',
2321                                         align : 'right',
2322                                         xtype : 'ColumnModel',
2323                                         header : 'Lead time',
2324                                         width : 75,
2325                                         renderer : function(v) { return String.format('{0}', v); },
2326                                         xns : Roo.grid,
2327                                         dataIndex : 'itemsrc_leadtime',
2328                                         items : [
2329
2330                                         ]
2331
2332                                     },
2333 {
2334                                         '|xns' : 'Roo.grid',
2335                                         xtype : 'ColumnModel',
2336                                         width : 50,
2337                                         header : 'Active',
2338                                         renderer : function(v) { return String.format('{0}', v); },
2339                                         xns : Roo.grid,
2340                                         dataIndex : 'itemsrc_active'
2341                                     }
2342                         ],
2343                         listeners : {
2344                                 rowdblclick : function (_self, rowIndex, e)
2345                                    {
2346                                        if (!_this.dialog) return;
2347                                        _this.dialog.show( this.getDataSource().getAt(rowIndex).data, function() {
2348                                            _this.grid.footer.onClick('first');
2349                                        }); 
2350                                    },
2351                                 render : function() 
2352                                    {
2353                                        _this.itemsrcgrid = this; 
2354                                        
2355                                        if (_this.itemsrcpanel.active) {
2356                                           this.footer.onClick('first');
2357                                        }
2358                                    },
2359                                 afteredit : function (e)
2360                                    {
2361                                        e.record.commit();
2362                                    }
2363                         },
2364                         items : [
2365
2366                         ]
2367
2368                     },
2369                     '|xns' : 'Roo',
2370                     fitToframe : true,
2371                     background : true,
2372                     region : 'center',
2373                     title : "Suppliers",
2374                     xtype : 'GridPanel',
2375                     fitContainer : true,
2376                     xns : Roo,
2377                     tableName : 'itemsrc',
2378                     listeners : {
2379                         activate : function() {
2380                                _this.itemsrcpanel = this;
2381                                
2382                                try { if (MODULE.isBuilder) {
2383                                    return;
2384                                } } catch(e) { }
2385                                
2386                                var id = _this.form.findField('item_id').getValue() * 1;
2387                                if (id < 1) {
2388                                    Roo.MessageBox.alert("Save First", "Save the item first, before adding suppliers");
2389                                    _this.dialog.layout.getRegion('center').showPanel(0);
2390                                    return false;
2391                                }
2392                                
2393                                var type = _this.form.findField('item_type').getValue();
2394                                
2395                                if(type == 'K'){
2396                                    Roo.MessageBox.alert("Error", "Can't add suppliers to kit item");
2397                                    _this.dialog.layout.getRegion('center').showPanel(0);
2398                                    return false;
2399                                }
2400                                
2401                                if (_this.itemsrcgrid) {
2402                                    _this.itemsrcgrid.footer.onClick('first');
2403                                }
2404                            }
2405                     },
2406                     items : [
2407
2408                     ]
2409
2410                 },
2411                 {
2412                     grid : {
2413                         dataSource : {
2414                             proxy : {
2415                                 '|xns' : 'Roo.data',
2416                                 url : baseURL + '/Roo/events.php',
2417                                 method : 'GET',
2418                                 xtype : 'HttpProxy',
2419                                 xns : Roo.data
2420                             },
2421                             reader : {
2422                                 '|xns' : 'Roo.data',
2423                                 id : 'id',
2424                                 root : 'data',
2425                                 xtype : 'JsonReader',
2426                                 fields : [
2427                                     {
2428                                         'name': 'event_when',
2429                                         'type': 'date'
2430                                     },
2431                                     {
2432                                         'name': 'action',
2433                                         'type': 'string'
2434                                     },
2435                                     {
2436                                         'name': 'ipaddr',
2437                                         'type': 'string'
2438                                     },
2439                                     {
2440                                         'name': 'person_id_name',
2441                                         'type': 'string'
2442                                     },
2443                                     {
2444                                         'name': 'remarks',
2445                                         'type': 'string'
2446                                     }
2447                                 ],
2448                                 xns : Roo.data,
2449                                 totalProperty : 'total'
2450                             },
2451                             '|xns' : 'Roo.data',
2452                             xtype : 'Store',
2453                             remoteSort : true,
2454                             sortInfo : { field : 'event_when', direction: 'DESC' },
2455                             xns : Roo.data,
2456                             listeners : {
2457                                 beforeload : function (_self, options)
2458                                    {
2459                                        options.params = options.params || {};
2460                                        
2461                                        options.params.on_table = 'item';
2462                                        options.params.on_id = _this.form.findField('item_id').getValue();
2463                                    }
2464                             },
2465                             items : [
2466
2467                             ]
2468
2469                         },
2470                         footer : {
2471                             '|xns' : 'Roo',
2472                             pageSize : 25,
2473                             xtype : 'PagingToolbar',
2474                             emptyMsg : "No Events found",
2475                             xns : Roo,
2476                             displayMsg : "Displaying events{0} - {1} of {2}",
2477                             displayInfo : true
2478                         },
2479                         '|xns' : 'Roo.grid',
2480                         autoExpandColumn : 'remarks',
2481                         xtype : 'Grid',
2482                         loadMask : true,
2483                         xns : Roo.grid,
2484                         colModel : [
2485                                  {
2486                                         '|xns' : 'Roo.grid',
2487                                         xtype : 'ColumnModel',
2488                                         width : 120,
2489                                         header : 'Changed',
2490                                         renderer : function(v) { return String.format('{0}', v ? v.format('d/M/Y H:i:s') : ''); },
2491                                         xns : Roo.grid,
2492                                         dataIndex : 'event_when'
2493                                     },
2494 {
2495                                         '|xns' : 'Roo.grid',
2496                                         xtype : 'ColumnModel',
2497                                         width : 200,
2498                                         header : 'Action',
2499                                         renderer : function(v,x,r) { return String.format('{0} - {1}', v, r.data.on_table); },
2500                                         xns : Roo.grid,
2501                                         dataIndex : 'action'
2502                                     },
2503 {
2504                                         '|xns' : 'Roo.grid',
2505                                         xtype : 'ColumnModel',
2506                                         width : 200,
2507                                         header : 'IP Address',
2508                                         renderer : function(v) { return String.format('{0}', v); },
2509                                         xns : Roo.grid,
2510                                         dataIndex : 'ipaddr'
2511                                     },
2512 {
2513                                         '|xns' : 'Roo.grid',
2514                                         xtype : 'ColumnModel',
2515                                         width : 75,
2516                                         header : 'Who',
2517                                         renderer : function(v) { return String.format('{0}', v); },
2518                                         xns : Roo.grid,
2519                                         dataIndex : 'person_id_name'
2520                                     },
2521 {
2522                                         '|xns' : 'Roo.grid',
2523                                         xtype : 'ColumnModel',
2524                                         width : 200,
2525                                         header : 'Notes',
2526                                         renderer : function(v) { return String.format('{0}', v); },
2527                                         xns : Roo.grid,
2528                                         dataIndex : 'remarks'
2529                                     }
2530                         ],
2531                         listeners : {
2532                                 render : function() 
2533                                    {
2534                                        _this.hgrid = this; 
2535                                        if (_this.hpanel.active) {
2536                                           this.footer.onClick('first');
2537                                        }
2538                                    }
2539                         },
2540                         items : [
2541
2542                         ]
2543
2544                     },
2545                     '|xns' : 'Roo',
2546                     fitToframe : true,
2547                     background : true,
2548                     region : 'center',
2549                     title : "History",
2550                     xtype : 'GridPanel',
2551                     fitContainer : true,
2552                     xns : Roo,
2553                     tableName : 'events',
2554                     listeners : {
2555                         activate : function() {
2556                                _this.hpanel = this;
2557                                if (_this.hgrid) {
2558                                    _this.hgrid.footer.onClick('first');
2559                                }
2560                            }
2561                     },
2562                     items : [
2563
2564                     ]
2565
2566                 }
2567             ]
2568
2569         });
2570     }
2571 };