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