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